From de7892cd6e66fcb39e41ea8ae32d9546c21cf47c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 5 Nov 2013 10:29:53 +0800 Subject: [PATCH 1/4] Add API to get whether the devtools is opened. --- brightray/browser/inspectable_web_contents.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 4 ++++ brightray/browser/inspectable_web_contents_impl.h | 1 + brightray/browser/inspectable_web_contents_view.h | 1 + brightray/browser/inspectable_web_contents_view_mac.h | 1 + brightray/browser/inspectable_web_contents_view_mac.mm | 4 ++++ brightray/browser/mac/bry_inspectable_web_contents_view.mm | 6 +++++- .../browser/mac/bry_inspectable_web_contents_view_private.h | 3 ++- brightray/browser/win/inspectable_web_contents_view_win.cc | 4 ++++ brightray/browser/win/inspectable_web_contents_view_win.h | 1 + 10 files changed, 24 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 9c381ae7403..04ba87bf0df 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -22,6 +22,7 @@ class InspectableWebContents { virtual content::WebContents* GetWebContents() const = 0; virtual void ShowDevTools() = 0; + virtual bool IsDevToolsOpened() = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index e3cefbe180c..0b194e70e61 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -96,6 +96,10 @@ void InspectableWebContentsImpl::ShowDevTools() { view_->ShowDevTools(); } +bool InspectableWebContentsImpl::IsDevToolsOpened() { + return devtools_web_contents_ && view_->IsDevToolsOpened(); +} + void InspectableWebContentsImpl::UpdateFrontendDockSide() { auto javascript = base::StringPrintf( "InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str()); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 804d8dccfe2..f0a55f5dac5 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -41,6 +41,7 @@ class InspectableWebContentsImpl : virtual content::WebContents* GetWebContents() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index eed32f34919..ff71bac783b 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -13,6 +13,7 @@ class InspectableWebContentsView { virtual void ShowDevTools() = 0; virtual void CloseDevTools() = 0; + virtual bool IsDevToolsOpened() = 0; virtual bool SetDockSide(const std::string& side) = 0; }; diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index f31149f570b..4390db290f8 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -19,6 +19,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index c9cc215591c..adde9b05033 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -29,6 +29,10 @@ void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; } +bool InspectableWebContentsViewMac::IsDevToolsOpened() { + return [view_ isDevToolsVisible]; +} + bool InspectableWebContentsViewMac::SetDockSide(const std::string& side) { return [view_ setDockSide:side]; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 24987e5c1c5..813d4fb6732 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -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 \ No newline at end of file +@end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h index ef8c50cc8b6..943ef93e312 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h @@ -8,6 +8,7 @@ class InspectableWebContentsViewMac; - (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac *)inspectableWebContentsView; - (void)setDevToolsVisible:(BOOL)visible; +- (BOOL)isDevToolsVisible; - (BOOL)setDockSide:(const std::string&)side; -@end \ No newline at end of file +@end diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 49135713194..d1530d1cee9 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -57,6 +57,10 @@ void InspectableWebContentsViewWin::CloseDevTools() { SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } +bool InspectableWebContentsViewWin::IsDevToolsOpened() { + return devtools_window_; +} + bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { return false; } diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 534f4997284..f79ce30bf3d 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -20,6 +20,7 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { From a8c59110942c3d48c33a6f77e56380fc2146ca9a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Dec 2013 23:11:29 -0800 Subject: [PATCH 2/4] Implement IsDevToolsOpened for Linux. --- .../linux/inspectable_web_contents_view_linux.cc | 15 +++++++++++++++ .../linux/inspectable_web_contents_view_linux.h | 1 + 2 files changed, 16 insertions(+) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index cbe8e4e9c34..54f54cadabe 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -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,10 @@ void InspectableWebContentsViewLinux::CloseDevTools() { } } +bool InspectableWebContentsViewLinux::IsDevToolsOpened() { + return devtools_window_ && IsWidgetAncestryVisible(devtools_window_); +} + bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { DLOG(INFO) << "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index c6605b3939f..79ab6f731d5 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -18,6 +18,7 @@ class InspectableWebContentsViewLinux : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { From 7a5415a3b781ae1314c769b4040a7373012fb8dd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Dec 2013 13:27:22 +0000 Subject: [PATCH 3/4] Fix IsDevToolsOpened when devtools is attched to pane on Linux. --- .../browser/linux/inspectable_web_contents_view_linux.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 54f54cadabe..365a053e770 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -167,7 +167,10 @@ void InspectableWebContentsViewLinux::CloseDevTools() { } bool InspectableWebContentsViewLinux::IsDevToolsOpened() { - return devtools_window_ && IsWidgetAncestryVisible(devtools_window_); + 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) { From b080e5c52d6c068d58315793794b9831b74e7c69 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Dec 2013 04:34:44 -0800 Subject: [PATCH 4/4] Rename IsDevToolsOpened to IsDevToolsViewShowing. --- brightray/browser/inspectable_web_contents.h | 2 +- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- brightray/browser/inspectable_web_contents_impl.h | 2 +- brightray/browser/inspectable_web_contents_view.h | 2 +- brightray/browser/inspectable_web_contents_view_mac.h | 2 +- brightray/browser/inspectable_web_contents_view_mac.mm | 2 +- .../browser/linux/inspectable_web_contents_view_linux.cc | 2 +- brightray/browser/linux/inspectable_web_contents_view_linux.h | 2 +- brightray/browser/win/inspectable_web_contents_view_win.cc | 2 +- brightray/browser/win/inspectable_web_contents_view_win.h | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 04ba87bf0df..49a50bc5079 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -22,7 +22,7 @@ class InspectableWebContents { virtual content::WebContents* GetWebContents() const = 0; virtual void ShowDevTools() = 0; - virtual bool IsDevToolsOpened() = 0; + virtual bool IsDevToolsViewShowing() = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 0b194e70e61..e972e568735 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -96,8 +96,8 @@ void InspectableWebContentsImpl::ShowDevTools() { view_->ShowDevTools(); } -bool InspectableWebContentsImpl::IsDevToolsOpened() { - return devtools_web_contents_ && view_->IsDevToolsOpened(); +bool InspectableWebContentsImpl::IsDevToolsViewShowing() { + return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } void InspectableWebContentsImpl::UpdateFrontendDockSide() { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index f0a55f5dac5..53023204dd1 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -41,7 +41,7 @@ class InspectableWebContentsImpl : virtual content::WebContents* GetWebContents() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index ff71bac783b..87274805f8e 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -13,7 +13,7 @@ class InspectableWebContentsView { virtual void ShowDevTools() = 0; virtual void CloseDevTools() = 0; - virtual bool IsDevToolsOpened() = 0; + virtual bool IsDevToolsViewShowing() = 0; virtual bool SetDockSide(const std::string& side) = 0; }; diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 4390db290f8..86cc7822178 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -19,7 +19,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index adde9b05033..95ed74f2dbd 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -29,7 +29,7 @@ void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; } -bool InspectableWebContentsViewMac::IsDevToolsOpened() { +bool InspectableWebContentsViewMac::IsDevToolsViewShowing() { return [view_ isDevToolsVisible]; } diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 365a053e770..58d7507fb43 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -166,7 +166,7 @@ void InspectableWebContentsViewLinux::CloseDevTools() { } } -bool InspectableWebContentsViewLinux::IsDevToolsOpened() { +bool InspectableWebContentsViewLinux::IsDevToolsViewShowing() { auto devtools_web_contents = inspectable_web_contents()->devtools_web_contents(); GtkWidget* devtools = devtools_web_contents->GetView()->GetNativeView(); diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index 79ab6f731d5..0a802239005 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -18,7 +18,7 @@ class InspectableWebContentsViewLinux : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index d1530d1cee9..dca7ba4f3eb 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -57,7 +57,7 @@ void InspectableWebContentsViewWin::CloseDevTools() { SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } -bool InspectableWebContentsViewWin::IsDevToolsOpened() { +bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { return devtools_window_; } diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index f79ce30bf3d..55b09b2d3e4 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -20,7 +20,7 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() {