Chromium Code Reviews| Index: content/browser/web_contents/web_contents_view_aura.cc |
| diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc |
| index 3f520db8d6efc07e5558fa6a1d2e21adfa794c28..4a824c76a7ef7bdf916efd9523804c978ed3a0e8 100644 |
| --- a/content/browser/web_contents/web_contents_view_aura.cc |
| +++ b/content/browser/web_contents/web_contents_view_aura.cc |
| @@ -4,6 +4,8 @@ |
| #include "content/browser/web_contents/web_contents_view_aura.h" |
| +#include <algorithm> |
| + |
| #include "base/auto_reset.h" |
| #include "base/command_line.h" |
| #include "base/metrics/histogram.h" |
| @@ -43,9 +45,7 @@ |
| #include "ui/aura/client/window_tree_client.h" |
| #include "ui/aura/env.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/clipboard.h" |
| #include "ui/base/clipboard/custom_data_helper.h" |
| #include "ui/base/dragdrop/drag_drop_types.h" |
| @@ -417,6 +417,111 @@ class ImageLayerDelegate : public ui::LayerDelegate { |
| } // namespace |
| +WebContentsViewAuraWindowObserver::WebContentsViewAuraWindowObserver( |
| + WebContentsViewAuraWindowObserverDelegate* delegate) |
| + : delegate_(delegate) { |
| + DCHECK(delegate); |
| + delegate_->AddDelegateWindowObserver(this); |
| + std::set<aura::Window*> ancestors = GenerateAncestors( |
| + delegate_->GetDelegateWindow()); |
| + AddToObserved(ancestors); |
| +} |
| + |
| +WebContentsViewAuraWindowObserver::~WebContentsViewAuraWindowObserver() { |
| + RemoveFromObserved(observed_); |
| + delegate_->RemoveRootWindowObserver(this); |
| + delegate_->RemoveDelegateWindowObserver(this); |
| +} |
| + |
| +void WebContentsViewAuraWindowObserver::OnWindowParentChanged( |
| + aura::Window* window, |
| + aura::Window* parent) { |
| + std::set<aura::Window*> ancestors = GenerateAncestors( |
| + delegate_->GetDelegateWindow()); |
| + std::set<aura::Window*> difference; |
| + std::set_difference( |
| + observed_.begin(), |
| + observed_.end(), |
| + ancestors.begin(), |
| + ancestors.end(), |
| + std::inserter(difference, difference.end())); |
| + RemoveFromObserved(difference); |
| + |
| + difference.clear(); |
| + std::set_difference( |
| + ancestors.begin(), |
| + ancestors.end(), |
| + observed_.begin(), |
| + observed_.end(), |
| + std::inserter(difference, difference.end())); |
| + AddToObserved(difference); |
| +} |
| + |
| +void WebContentsViewAuraWindowObserver::OnWindowBoundsChanged |
| +(aura::Window* window, |
| + const gfx::Rect& old_bounds, |
| + const gfx::Rect& new_bounds) { |
| + delegate_->SendScreenRects(); |
| + delegate_->UpdateEditingController(); |
| +} |
| + |
| +void WebContentsViewAuraWindowObserver::OnWindowAddedToRootWindow( |
| + aura::Window* window) { |
| + if (window == delegate_->GetDelegateWindow()) |
| + delegate_->AddRootWindowObserver(this); |
| +} |
| + |
| +void WebContentsViewAuraWindowObserver::OnWindowRemovingFromRootWindow( |
| + aura::Window* window) { |
| + if (window == delegate_->GetDelegateWindow()) |
| + delegate_->RemoveRootWindowObserver(this); |
| +} |
| + |
| +void WebContentsViewAuraWindowObserver::OnRootWindowHostMoved( |
| + const aura::RootWindow* root, |
| + const gfx::Point& new_origin) { |
| + // This is for the desktop case (i.e. Aura desktop). |
| + delegate_->SendScreenRects(); |
| +} |
| + |
| +std::set<aura::Window*> WebContentsViewAuraWindowObserver::GenerateAncestors( |
| + aura::Window* window) { |
| + std::set<aura::Window*> ret_val; |
| + while (window->parent()) { |
| + ret_val.insert(window->parent()); |
| + window = window->parent(); |
| + } |
| + return ret_val; |
| +} |
| + |
| +void WebContentsViewAuraWindowObserver::AddToObserved( |
| + const std::set<aura::Window*>& windows) { |
| + for (std::set<aura::Window*>::iterator iter = windows.begin(); |
| + iter != windows.end(); |
| + ++iter) { |
| + if (observed_.end() == observed_.find(*iter)) { |
| + (*iter)->AddObserver(this); |
| + observed_.insert(*iter); |
| + } |
| + } |
| +} |
| + |
| +void WebContentsViewAuraWindowObserver::RemoveFromObserved( |
| + const std::set<aura::Window*>& windows) { |
| + // Since windows can possibly be observer_ we cannot blindly iterate and |
| + // delete, since that breaks the iterators. |
| + for (std::set<aura::Window*>::iterator iter = windows.begin(); |
| + iter != windows.end();) { |
| + std::set<aura::Window*>::iterator next = iter; |
| + next++; |
| + if (observed_.end() != observed_.find(*iter)) { |
| + (*iter)->RemoveObserver(this); |
| + observed_.erase(*iter); |
| + } |
| + iter = next; |
| + } |
| +} |
| + |
| // When a history navigation is triggered at the end of an overscroll |
| // navigation, it is necessary to show the history-screenshot until the page is |
| // done navigating and painting. This class accomplishes this by showing the |
| @@ -648,75 +753,6 @@ class OverscrollNavigationOverlay : |
| DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); |
| }; |
| -class WebContentsViewAura::WindowObserver |
| - : public aura::WindowObserver, public aura::RootWindowObserver { |
| - public: |
| - explicit WindowObserver(WebContentsViewAura* view) |
| - : view_(view), |
| - parent_(NULL) { |
| - view_->window_->AddObserver(this); |
| - } |
| - |
| - virtual ~WindowObserver() { |
| - view_->window_->RemoveObserver(this); |
| - if (view_->window_->GetDispatcher()) |
| - view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); |
| - if (parent_) |
| - parent_->RemoveObserver(this); |
| - } |
| - |
| - // Overridden from aura::WindowObserver: |
| - virtual void OnWindowParentChanged(aura::Window* window, |
| - aura::Window* parent) OVERRIDE { |
| - if (window == parent_) |
| - return; |
| - 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) OVERRIDE { |
| - SendScreenRects(); |
| - if (view_->touch_editable_) |
| - view_->touch_editable_->UpdateEditingController(); |
| - } |
| - |
| - virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
| - if (window != parent_) |
| - window->GetDispatcher()->AddRootWindowObserver(this); |
| - } |
| - |
| - virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { |
| - if (window != parent_) |
| - window->GetDispatcher()->RemoveRootWindowObserver(this); |
| - } |
| - |
| - // Overridden RootWindowObserver: |
| - virtual void OnRootWindowHostMoved(const aura::RootWindow* root, |
| - const gfx::Point& new_origin) OVERRIDE { |
| - // This is for the desktop case (i.e. Aura desktop). |
| - SendScreenRects(); |
| - } |
| - |
| - private: |
| - void SendScreenRects() { |
| - RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> |
| - 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); |
| -}; |
| - |
| #if defined(OS_WIN) |
| // Constrained windows are added as children of the WebContent's view which may |
| // overlap with windowed NPAPI plugins. In that case, tell the RWHV so that it |
| @@ -1164,7 +1200,7 @@ void WebContentsViewAura::CreateView( |
| window_->layer()->SetMasksToBounds(true); |
| window_->SetName("WebContentsViewAura"); |
| - window_observer_.reset(new WindowObserver(this)); |
| + window_observer_.reset(new WebContentsViewAuraWindowObserver(this)); |
|
sadrul
2013/11/06 20:24:06
I was thinking of something more like a NativeView
|
| #if defined(OS_WIN) |
| child_window_observer_.reset(new ChildWindowObserver(this)); |
| #endif |
| @@ -1652,4 +1688,43 @@ int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { |
| return current_drag_op_; |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// WebContentsViewAura, WebContentsViewAuraWindowObserverDelgate implementation: |
| + |
| +aura::Window* WebContentsViewAura::GetDelegateWindow() { |
| + return window_.get(); |
| +} |
| + |
| +void WebContentsViewAura::AddDelegateWindowObserver( |
| + aura::WindowObserver* observer) { |
| + window_->AddObserver(observer); |
| +} |
| + |
| +void WebContentsViewAura::RemoveDelegateWindowObserver( |
| + aura::WindowObserver* observer) { |
| + window_->RemoveObserver(observer); |
| +} |
| + |
| +void WebContentsViewAura::RemoveRootWindowObserver( |
| + aura::RootWindowObserver* observer) { |
| + if (window_->GetDispatcher()) |
| + window_->GetDispatcher()->RemoveRootWindowObserver(observer); |
| +} |
| + |
| +void WebContentsViewAura::AddRootWindowObserver( |
| + aura::RootWindowObserver* observer) { |
| + if (window_->GetDispatcher()) |
| + window_->GetDispatcher()->AddRootWindowObserver(observer); |
| +} |
| + |
| +void WebContentsViewAura::UpdateEditingController() { |
| + if (touch_editable_) |
| + touch_editable_->UpdateEditingController(); |
| +} |
| + |
| +void WebContentsViewAura::SendScreenRects() { |
| + RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())-> |
| + SendScreenRects(); |
| +} |
| + |
| } // namespace content |