diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index dca7ba4f3eb..00c661c22b2 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -6,6 +6,8 @@ #include "content/public/browser/web_contents_view.h" #include "ui/gfx/win/hwnd_util.h" +#include "ui/views/controls/webview/webview.h" +#include "ui/views/view.h" namespace brightray { @@ -15,6 +17,41 @@ const int kWindowInset = 100; } +class ContainerView : public views::View { + public: + explicit ContainerView(InspectableWebContentsViewWin* web_contents_view) + : container_view_created_(false), + web_view_(new views::WebView(NULL)), + web_contents_view_(web_contents_view) { + web_view_->SetWebContents( + web_contents_view_->inspectable_web_contents()->GetWebContents()); + } + + private: + // views::View: + virtual void Layout() OVERRIDE { + web_view_->SetBounds(0, 0, width(), height()); + } + + virtual void ViewHierarchyChanged( + const ViewHierarchyChangedDetails& details) OVERRIDE { + View::ViewHierarchyChanged(details); + // We're not using child == this because a Widget may not be + // available when this is added to the hierarchy. + if (details.is_add && GetWidget() && !container_view_created_) { + container_view_created_ = true; + AddChildView(web_view_); + } + } + + // True if the container view has already been created, or false otherwise. + bool container_view_created_; + + views::WebView* web_view_; + + InspectableWebContentsViewWin* web_contents_view_; +}; + InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewWin(inspectable_web_contents); @@ -22,7 +59,8 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsViewWin::InspectableWebContentsViewWin( InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents) { + : inspectable_web_contents_(inspectable_web_contents), + container_(new ContainerView(this)) { } InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { @@ -30,6 +68,10 @@ InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { DestroyWindow(devtools_window_->hwnd()); } +views::View* InspectableWebContentsViewWin::GetView() const { + return container_; +} + gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { auto web_contents = inspectable_web_contents_->GetWebContents(); return web_contents->GetView()->GetNativeView(); diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 55b09b2d3e4..382a0f46029 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -6,8 +6,13 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" +namespace views { +class View; +} + namespace brightray { +class ContainerView; class DevToolsWindow; class InspectableWebContentsImpl; @@ -17,6 +22,8 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewWin(); + views::View* GetView() const; + virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; @@ -31,6 +38,8 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + ContainerView* container_; + base::WeakPtr devtools_window_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin);