Chromium Code Reviews| Index: content/browser/web_contents/web_contents_view_aura.cc |
| =================================================================== |
| --- content/browser/web_contents/web_contents_view_aura.cc (revision 168290) |
| +++ content/browser/web_contents/web_contents_view_aura.cc (working copy) |
| @@ -7,6 +7,7 @@ |
| #include "base/utf_string_conversions.h" |
| #include "content/browser/renderer_host/dip_util.h" |
| #include "content/browser/renderer_host/render_view_host_factory.h" |
| +#include "content/browser/renderer_host/render_widget_host_impl.h" |
| #include "content/browser/web_contents/interstitial_page_impl.h" |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/public/browser/notification_observer.h" |
| @@ -24,7 +25,9 @@ |
| #include "ui/aura/client/drag_drop_client.h" |
| #include "ui/aura/client/drag_drop_delegate.h" |
| #include "ui/aura/root_window.h" |
| +#include "ui/aura/root_window_observer.h" |
| #include "ui/aura/window.h" |
| +#include "ui/aura/window_observer.h" |
| #include "ui/base/clipboard/custom_data_helper.h" |
| #include "ui/base/dragdrop/drag_drop_types.h" |
| #include "ui/base/dragdrop/os_exchange_data.h" |
| @@ -231,7 +234,66 @@ |
| } // namespace |
| +class WebContentsViewAura::WindowObserver |
| + : public aura::WindowObserver, public aura::RootWindowObserver { |
| + public: |
| + explicit WindowObserver(WebContentsViewAura* view) |
| + : view_(view), parent_(NULL) {} |
|
sky
2012/11/19 15:04:54
nit: each param on its own line.
jam
2012/11/19 18:53:06
the style guide says it's ok to put them on one li
sky
2012/11/19 22:45:24
But this is 2 lines, right? The second example sho
jam
2012/11/20 01:08:01
ah, I misunderstood that comment to mean that if a
|
| + virtual ~WindowObserver() { |
| + if (parent_) |
| + parent_->RemoveObserver(this); |
| + } |
| + // Overridden from aura::WindowObserver: |
| + virtual void OnWindowParentChanged(aura::Window* window, |
| + aura::Window* parent) OVERRIDE { |
| + if (parent_) |
| + parent_->RemoveObserver(this); |
| + parent_ = parent; |
| + if (parent) |
| + parent->AddObserver(this); |
| + } |
| + |
| + virtual void OnWindowBoundsChanged(aura::Window* window, |
| + const gfx::Rect& old_bounds, |
| + const gfx::Rect& new_bounds) { |
| + // This is for the Ash case. |
| + SendScreenRects(); |
| + } |
| + |
| + virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
| + window->GetRootWindow()->AddRootWindowObserver(this); |
| + } |
| + |
| + virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { |
| + window->GetRootWindow()->RemoveRootWindowObserver(this); |
| + } |
| + |
| + // Overridden RootWindowObserver: |
| + virtual void OnRootWindowMoved(const aura::RootWindow* root, |
| + const gfx::Point& new_origin) OVERRIDE { |
| + // This is for the desktop case (i.e. Aura desktop). |
| + SendScreenRects(); |
| + } |
| + |
| + private: |
| + void SendScreenRects() { |
| + if (!view_->view_) |
| + return; |
| + RenderWidgetHostImpl::From(view_->view_->GetRenderWidgetHost())-> |
| + SendScreenRects(); |
| + } |
| + |
| + WebContentsViewAura* view_; |
| + |
| + // We cache the old parent so that we can unregister when it's not the parent |
| + // anymore. |
| + aura::Window* parent_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
| +}; |
| + |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // WebContentsViewAura, public: |
| @@ -250,6 +312,10 @@ |
| // WebContentsViewAura, private: |
| WebContentsViewAura::~WebContentsViewAura() { |
| + if (!window_) |
| + return; |
| + |
| + window_->RemoveObserver(window_observer_.get()); |
| // Window needs a valid delegate during its destructor, so we explicitly |
| // delete it here. |
| window_.reset(); |
| @@ -293,6 +359,9 @@ |
| window_->layer()->SetMasksToBounds(true); |
| window_->SetName("WebContentsViewAura"); |
| + window_observer_.reset(new WindowObserver(this)); |
| + window_->AddObserver(window_observer_.get()); |
| + |
| // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
| // Hence, we save a reference to it locally. Similar model is used on other |
| // platforms as well. |
| @@ -312,8 +381,7 @@ |
| return render_widget_host->GetView(); |
| } |
| - view_ = RenderWidgetHostView::CreateViewForWidget( |
| - render_widget_host); |
| + view_ = RenderWidgetHostView::CreateViewForWidget(render_widget_host); |
| view_->InitAsChild(NULL); |
| GetNativeView()->AddChild(view_->GetNativeView()); |
| view_->Show(); |