| Index: content/browser/web_contents/aura/constrained_windows_observer.cc
|
| diff --git a/content/browser/web_contents/aura/constrained_windows_observer.cc b/content/browser/web_contents/aura/constrained_windows_observer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..aef45451965f5f08be6d7230a94f6d9e3e753b67
|
| --- /dev/null
|
| +++ b/content/browser/web_contents/aura/constrained_windows_observer.cc
|
| @@ -0,0 +1,118 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/web_contents/aura/constrained_windows_observer.h"
|
| +
|
| +#include "content/browser/renderer_host/render_view_host_factory.h"
|
| +#include "content/browser/renderer_host/render_widget_host_view_aura.h"
|
| +#include "content/browser/renderer_host/render_widget_host_view_aura.h"
|
| +#include "content/browser/web_contents/web_contents_impl.h"
|
| +#include "content/browser/web_contents/web_contents_view_aura.h"
|
| +#include "content/public/browser/render_widget_host.h"
|
| +#include "ui/aura/window.h"
|
| +
|
| +namespace content {
|
| +namespace {
|
| +
|
| +RenderWidgetHostViewAura* ToRenderWidgetHostViewAura(
|
| + RenderWidgetHostView* view) {
|
| + if (!view || RenderViewHostFactory::has_factory())
|
| + return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests.
|
| + RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>(
|
| + view->GetRenderWidgetHost()->GetProcess());
|
| + if (process->IsGuest())
|
| + return NULL;
|
| + return static_cast<RenderWidgetHostViewAura*>(view);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ConstrainedWindowsObserver::ConstrainedWindowsObserver(
|
| + WebContentsViewAura* view)
|
| + : view_(view),
|
| + parent_(NULL) {
|
| + view_->window_->AddObserver(this);
|
| +}
|
| +
|
| +ConstrainedWindowsObserver::~ConstrainedWindowsObserver() {
|
| + if (parent_) {
|
| + const aura::Window::Windows& children = parent_->children();
|
| + for (size_t i = 0; i < children.size(); ++i)
|
| + children[i]->RemoveObserver(this);
|
| + }
|
| +}
|
| +
|
| +void ConstrainedWindowsObserver::OnWindowAdded(aura::Window* new_window) {
|
| + if (new_window->parent() != parent_)
|
| + return;
|
| +
|
| + new_window->AddObserver(this);
|
| + UpdateConstrainedWindows(NULL);
|
| +}
|
| +
|
| +void ConstrainedWindowsObserver::OnWillRemoveWindow(aura::Window* window) {
|
| + if (window->parent() == parent_ && window != view_->window_) {
|
| + window->RemoveObserver(this);
|
| + UpdateConstrainedWindows(window);
|
| + }
|
| +}
|
| +
|
| +void ConstrainedWindowsObserver::OnWindowVisibilityChanged(
|
| + aura::Window* window,
|
| + bool visible) {
|
| + if (window->parent() == parent_ && window != view_->window_)
|
| + UpdateConstrainedWindows(NULL);
|
| +}
|
| +
|
| +void ConstrainedWindowsObserver::OnWindowParentChanged(aura::Window* window,
|
| + aura::Window* parent) {
|
| + if (window != view_->window_)
|
| + return;
|
| + if (parent_)
|
| + parent_->RemoveObserver(this);
|
| + 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>());
|
| + }
|
| +
|
| + parent_ = parent;
|
| + if (parent)
|
| + parent->AddObserver(this);
|
| +}
|
| +
|
| +void ConstrainedWindowsObserver::OnWindowBoundsChanged(
|
| + aura::Window* window,
|
| + const gfx::Rect& old_bounds,
|
| + const gfx::Rect& new_bounds) {
|
| + if (window != parent_ || window != view_->window_)
|
| + UpdateConstrainedWindows(NULL);
|
| +}
|
| +
|
| +void ConstrainedWindowsObserver::UpdateConstrainedWindows(
|
| + aura::Window* exclude) {
|
| + RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
|
| + view_->web_contents_->GetRenderWidgetHostView());
|
| + if (!view)
|
| + return;
|
| +
|
| + std::vector<gfx::Rect> constrained_windows;
|
| + 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());
|
| + }
|
| + }
|
| +
|
| + // view->UpdateConstrainedWindowRects(constrained_windows);
|
| +}
|
| +
|
| +} // namespace content
|
|
|