| 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 353da78864c40635ea53147d97a438323e815ceb..e761f51758b0878561eda374afbc2d0e14275645 100644
|
| --- a/content/browser/web_contents/web_contents_view_aura.cc
|
| +++ b/content/browser/web_contents/web_contents_view_aura.cc
|
| @@ -43,9 +43,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"
|
| @@ -648,239 +646,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);
|
| -
|
| -#if defined(OS_WIN)
|
| - if (view_->window_->GetRootWindow())
|
| - view_->window_->GetRootWindow()->AddObserver(this);
|
| -#endif
|
| - }
|
| -
|
| - virtual ~WindowObserver() {
|
| - view_->window_->RemoveObserver(this);
|
| - if (view_->window_->GetDispatcher())
|
| - view_->window_->GetDispatcher()->RemoveRootWindowObserver(this);
|
| - if (parent_)
|
| - parent_->RemoveObserver(this);
|
| -
|
| -#if defined(OS_WIN)
|
| - if (parent_) {
|
| - const aura::Window::Windows& children = parent_->children();
|
| - for (size_t i = 0; i < children.size(); ++i)
|
| - children[i]->RemoveObserver(this);
|
| - }
|
| -
|
| - aura::Window* root_window = view_->window_->GetRootWindow();
|
| - if (root_window) {
|
| - root_window->RemoveObserver(this);
|
| - const aura::Window::Windows& root_children = root_window->children();
|
| - for (size_t i = 0; i < root_children.size(); ++i)
|
| - root_children[i]->RemoveObserver(this);
|
| - }
|
| -#endif
|
| - }
|
| -
|
| - // Overridden from aura::WindowObserver:
|
| -#if defined(OS_WIN)
|
| - // Constrained windows are added as children of the parent's parent's view
|
| - // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV
|
| - // so that it can update the plugins' cutout rects accordingly.
|
| - // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is
|
| - // going to be deprecated in a year, this is ok for now. The test for this is
|
| - // PrintPreviewTest.WindowedNPAPIPluginHidden.
|
| - virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE {
|
| - if (new_window == view_->window_)
|
| - return;
|
| -
|
| - if (new_window == parent_)
|
| - return; // This happens if the parent moves to the root window.
|
| -
|
| - // Observe sibling windows of the WebContents, or children of the root
|
| - // window.
|
| - if (new_window->parent() == parent_ ||
|
| - new_window->parent() == view_->window_->GetRootWindow()) {
|
| - new_window->AddObserver(this);
|
| - UpdateConstrainedWindows(NULL);
|
| - }
|
| - }
|
| -
|
| - virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE {
|
| - if (window == view_->window_)
|
| - return;
|
| -
|
| - window->RemoveObserver(this);
|
| - UpdateConstrainedWindows(window);
|
| - }
|
| -
|
| - virtual void OnWindowVisibilityChanged(aura::Window* window,
|
| - bool visible) OVERRIDE {
|
| - if (window == view_->window_)
|
| - return;
|
| -
|
| - if (window->parent() == parent_ ||
|
| - window->parent() == view_->window_->GetRootWindow()) {
|
| - UpdateConstrainedWindows(NULL);
|
| - }
|
| - }
|
| -#endif
|
| -
|
| - virtual void OnWindowParentChanged(aura::Window* window,
|
| - aura::Window* parent) OVERRIDE {
|
| - if (window != view_->window_)
|
| - return;
|
| - if (parent_)
|
| - parent_->RemoveObserver(this);
|
| -
|
| -#if defined(OS_WIN)
|
| - if (parent_) {
|
| - const aura::Window::Windows& children = parent_->children();
|
| - for (size_t i = 0; i < children.size(); ++i)
|
| - children[i]->RemoveObserver(this);
|
| -
|
| - RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
|
| - view_->web_contents_->GetRenderWidgetHostView());
|
| - if (view)
|
| - view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>());
|
| - }
|
| -
|
| - // When we get parented to the root window, the code below will watch the
|
| - // parent, aka root window. Since we already watch the root window on
|
| - // Windows, unregister first so that the debug check doesn't fire.
|
| - if (parent && parent == window->GetRootWindow())
|
| - parent->RemoveObserver(this);
|
| -
|
| - // We need to undo the above if we were parented to the root window and then
|
| - // got parented to another window. At that point, the code before the ifdef
|
| - // would have stopped watching the root window.
|
| - if (window->GetRootWindow() &&
|
| - parent != window->GetRootWindow() &&
|
| - !window->GetRootWindow()->HasObserver(this)) {
|
| - window->GetRootWindow()->AddObserver(this);
|
| - }
|
| -#endif
|
| -
|
| - parent_ = parent;
|
| - if (parent) {
|
| - parent->AddObserver(this);
|
| -#if defined(OS_WIN)
|
| - if (parent != window->GetRootWindow()) {
|
| - const aura::Window::Windows& children = parent->children();
|
| - for (size_t i = 0; i < children.size(); ++i) {
|
| - if (children[i] != view_->window_)
|
| - children[i]->AddObserver(this);
|
| - }
|
| - }
|
| -#endif
|
| - }
|
| - }
|
| -
|
| - virtual void OnWindowBoundsChanged(aura::Window* window,
|
| - const gfx::Rect& old_bounds,
|
| - const gfx::Rect& new_bounds) OVERRIDE {
|
| - if (window == parent_ || window == view_->window_) {
|
| - SendScreenRects();
|
| - if (view_->touch_editable_)
|
| - view_->touch_editable_->UpdateEditingController();
|
| -#if defined(OS_WIN)
|
| - } else {
|
| - UpdateConstrainedWindows(NULL);
|
| -#endif
|
| - }
|
| - }
|
| -
|
| - virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
|
| - if (window == view_->window_) {
|
| - window->GetDispatcher()->AddRootWindowObserver(this);
|
| -#if defined(OS_WIN)
|
| - if (!window->GetRootWindow()->HasObserver(this))
|
| - window->GetRootWindow()->AddObserver(this);
|
| -#endif
|
| - }
|
| - }
|
| -
|
| - virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE {
|
| - if (window == view_->window_) {
|
| - window->GetDispatcher()->RemoveRootWindowObserver(this);
|
| -#if defined(OS_WIN)
|
| - window->GetRootWindow()->RemoveObserver(this);
|
| -
|
| - const aura::Window::Windows& root_children =
|
| - window->GetRootWindow()->children();
|
| - for (size_t i = 0; i < root_children.size(); ++i) {
|
| - if (root_children[i] != view_->window_ && root_children[i] != parent_)
|
| - root_children[i]->RemoveObserver(this);
|
| - }
|
| -#endif
|
| - }
|
| - }
|
| -
|
| - // Overridden RootWindowObserver:
|
| - virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
|
| - const gfx::Point& new_origin) OVERRIDE {
|
| - TRACE_EVENT1("ui",
|
| - "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved",
|
| - "new_origin", new_origin.ToString());
|
| -
|
| - // This is for the desktop case (i.e. Aura desktop).
|
| - SendScreenRects();
|
| - }
|
| -
|
| - private:
|
| - void SendScreenRects() {
|
| - RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())->
|
| - SendScreenRects();
|
| - }
|
| -
|
| -#if defined(OS_WIN)
|
| - void UpdateConstrainedWindows(aura::Window* exclude) {
|
| - RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
|
| - view_->web_contents_->GetRenderWidgetHostView());
|
| - if (!view)
|
| - return;
|
| -
|
| - std::vector<gfx::Rect> constrained_windows;
|
| - if (parent_) {
|
| - const aura::Window::Windows& children = parent_->children();
|
| - for (size_t i = 0; i < children.size(); ++i) {
|
| - if (children[i] != view_->window_ &&
|
| - children[i] != exclude &&
|
| - children[i]->IsVisible()) {
|
| - constrained_windows.push_back(children[i]->GetBoundsInRootWindow());
|
| - }
|
| - }
|
| - }
|
| -
|
| - aura::Window* root_window = view_->window_->GetRootWindow();
|
| - const aura::Window::Windows& root_children = root_window->children();
|
| - if (root_window) {
|
| - for (size_t i = 0; i < root_children.size(); ++i) {
|
| - if (root_children[i]->IsVisible() &&
|
| - !root_children[i]->Contains(view_->window_.get())) {
|
| - constrained_windows.push_back(
|
| - root_children[i]->GetBoundsInRootWindow());
|
| - }
|
| - }
|
| - }
|
| -
|
| - view->UpdateConstrainedWindowRects(constrained_windows);
|
| - }
|
| -#endif
|
| -
|
| - 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:
|
|
|
| @@ -905,7 +670,10 @@ WebContentsViewAura::~WebContentsViewAura() {
|
| if (!window_)
|
| return;
|
|
|
| - window_observer_.reset();
|
| + bounds_observer_.reset();
|
| +#if defined(OS_WIN)
|
| + constrained_observer_.reset();
|
| +#endif
|
|
|
| // Window needs a valid delegate during its destructor, so we explicitly
|
| // delete it here.
|
| @@ -1236,13 +1004,18 @@ void WebContentsViewAura::CreateView(
|
| window_->layer()->SetMasksToBounds(true);
|
| window_->SetName("WebContentsViewAura");
|
|
|
| - // WindowObserver is not interesting and is problematic for Browser Plugin
|
| + // The observers are not interesting and is problematic for Browser Plugin
|
| // guests.
|
| - // The use cases for WindowObserver do not apply to Browser Plugins:
|
| + // The use cases for the observers do not apply to Browser Plugins:
|
| // 1) guests do not support NPAPI plugins.
|
| // 2) guests' window bounds are supposed to come from its embedder.
|
| - if (!web_contents_->GetRenderProcessHost()->IsGuest())
|
| - window_observer_.reset(new WindowObserver(this));
|
| + if (!web_contents_->GetRenderProcessHost()->IsGuest()) {
|
| + bounds_observer_.reset(new NativeViewScreenBoundsObserver(this,
|
| + window_.get()));
|
| +#if defined(OS_WIN)
|
| + constrained_observer_.reset(new ConstrainedWindowsObserver(this));
|
| +#endif
|
| + }
|
|
|
| // delegate_->GetDragDestDelegate() creates a new delegate on every call.
|
| // Hence, we save a reference to it locally. Similar model is used on other
|
| @@ -1727,4 +1500,19 @@ int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) {
|
| return current_drag_op_;
|
| }
|
|
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// WebContentsViewAura, NativeViewScreenBoundsObserverDelegate implementation:
|
| +
|
| +void WebContentsViewAura::OnScreenPositionChanged() {
|
| + RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())->
|
| + SendScreenRects();
|
| +}
|
| +
|
| +void WebContentsViewAura::OnScreenBoundsChanged() {
|
| + RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())->
|
| + SendScreenRects();
|
| + if (touch_editable_)
|
| + touch_editable_->UpdateEditingController();
|
| +}
|
| +
|
| } // namespace content
|
|
|