Merge pull request #42 from brightray/devtools-is-opened

Add API to get whether the devtools is opened.
This commit is contained in:
Adam Roben 2013-12-10 18:39:47 -08:00
commit 64b487a8d5
12 changed files with 43 additions and 2 deletions

View file

@ -22,6 +22,7 @@ class InspectableWebContents {
virtual content::WebContents* GetWebContents() const = 0;
virtual void ShowDevTools() = 0;
virtual bool IsDevToolsViewShowing() = 0;
};
} // namespace brightray

View file

@ -96,6 +96,10 @@ void InspectableWebContentsImpl::ShowDevTools() {
view_->ShowDevTools();
}
bool InspectableWebContentsImpl::IsDevToolsViewShowing() {
return devtools_web_contents_ && view_->IsDevToolsViewShowing();
}
void InspectableWebContentsImpl::UpdateFrontendDockSide() {
auto javascript = base::StringPrintf(
"InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str());

View file

@ -41,6 +41,7 @@ class InspectableWebContentsImpl :
virtual content::WebContents* GetWebContents() const OVERRIDE;
virtual void ShowDevTools() OVERRIDE;
virtual bool IsDevToolsViewShowing() OVERRIDE;
content::WebContents* devtools_web_contents() {
return devtools_web_contents_.get();

View file

@ -13,6 +13,7 @@ class InspectableWebContentsView {
virtual void ShowDevTools() = 0;
virtual void CloseDevTools() = 0;
virtual bool IsDevToolsViewShowing() = 0;
virtual bool SetDockSide(const std::string& side) = 0;
};

View file

@ -19,6 +19,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView {
virtual gfx::NativeView GetNativeView() const OVERRIDE;
virtual void ShowDevTools() OVERRIDE;
virtual void CloseDevTools() OVERRIDE;
virtual bool IsDevToolsViewShowing() OVERRIDE;
virtual bool SetDockSide(const std::string& side) OVERRIDE;
InspectableWebContentsImpl* inspectable_web_contents() {

View file

@ -29,6 +29,10 @@ void InspectableWebContentsViewMac::CloseDevTools() {
[view_ setDevToolsVisible:NO];
}
bool InspectableWebContentsViewMac::IsDevToolsViewShowing() {
return [view_ isDevToolsVisible];
}
bool InspectableWebContentsViewMac::SetDockSide(const std::string& side) {
return [view_ setDockSide:side];
}

View file

@ -10,6 +10,17 @@
namespace brightray {
namespace {
bool IsWidgetAncestryVisible(GtkWidget* widget) {
GtkWidget* parent = widget;
while (parent && gtk_widget_get_visible(parent))
parent = gtk_widget_get_parent(parent);
return !parent;
}
}
InspectableWebContentsView* CreateInspectableContentsView(
InspectableWebContentsImpl* inspectable_web_contents) {
return new InspectableWebContentsViewLinux(inspectable_web_contents);
@ -155,6 +166,13 @@ void InspectableWebContentsViewLinux::CloseDevTools() {
}
}
bool InspectableWebContentsViewLinux::IsDevToolsViewShowing() {
auto devtools_web_contents =
inspectable_web_contents()->devtools_web_contents();
GtkWidget* devtools = devtools_web_contents->GetView()->GetNativeView();
return IsWidgetAncestryVisible(devtools);
}
bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) {
DLOG(INFO) <<
"InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\"";

View file

@ -18,6 +18,7 @@ class InspectableWebContentsViewLinux : public InspectableWebContentsView {
virtual gfx::NativeView GetNativeView() const OVERRIDE;
virtual void ShowDevTools() OVERRIDE;
virtual void CloseDevTools() OVERRIDE;
virtual bool IsDevToolsViewShowing() OVERRIDE;
virtual bool SetDockSide(const std::string& side) OVERRIDE;
InspectableWebContentsImpl* inspectable_web_contents() {

View file

@ -112,6 +112,10 @@ void SetActive(content::WebContents* web_contents, bool active) {
[_private->splitView adjustSubviews];
}
- (BOOL)isDevToolsVisible {
return _private->visible;
}
- (BOOL)setDockSide:(const std::string&)side {
if (side == "right") {
_private->splitView.vertical = YES;
@ -221,4 +225,4 @@ void SetActive(content::WebContents* web_contents, bool active) {
@end
@implementation BRYInspectableWebContentsViewPrivate
@end
@end

View file

@ -8,6 +8,7 @@ class InspectableWebContentsViewMac;
- (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac *)inspectableWebContentsView;
- (void)setDevToolsVisible:(BOOL)visible;
- (BOOL)isDevToolsVisible;
- (BOOL)setDockSide:(const std::string&)side;
@end
@end

View file

@ -57,6 +57,10 @@ void InspectableWebContentsViewWin::CloseDevTools() {
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
}
bool InspectableWebContentsViewWin::IsDevToolsViewShowing() {
return devtools_window_;
}
bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) {
return false;
}

View file

@ -20,6 +20,7 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView {
virtual gfx::NativeView GetNativeView() const OVERRIDE;
virtual void ShowDevTools() OVERRIDE;
virtual void CloseDevTools() OVERRIDE;
virtual bool IsDevToolsViewShowing() OVERRIDE;
virtual bool SetDockSide(const std::string& side) OVERRIDE;
InspectableWebContentsImpl* inspectable_web_contents() {