| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/web_contents/aura/constrained_windows_observer.h" |
| 6 |
| 7 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 8 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" |
| 11 #include "content/browser/web_contents/web_contents_view_aura.h" |
| 12 #include "content/public/browser/render_widget_host.h" |
| 13 #include "ui/aura/window.h" |
| 14 |
| 15 namespace content { |
| 16 namespace { |
| 17 |
| 18 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( |
| 19 RenderWidgetHostView* view) { |
| 20 if (!view || RenderViewHostFactory::has_factory()) |
| 21 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. |
| 22 RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>( |
| 23 view->GetRenderWidgetHost()->GetProcess()); |
| 24 if (process->IsGuest()) |
| 25 return NULL; |
| 26 return static_cast<RenderWidgetHostViewAura*>(view); |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 ConstrainedWindowsObserver::ConstrainedWindowsObserver( |
| 32 WebContentsViewAura* view) |
| 33 : view_(view), |
| 34 parent_(NULL) { |
| 35 view_->window_->AddObserver(this); |
| 36 } |
| 37 |
| 38 ConstrainedWindowsObserver::~ConstrainedWindowsObserver() { |
| 39 if (parent_) { |
| 40 const aura::Window::Windows& children = parent_->children(); |
| 41 for (size_t i = 0; i < children.size(); ++i) |
| 42 children[i]->RemoveObserver(this); |
| 43 } |
| 44 } |
| 45 |
| 46 void ConstrainedWindowsObserver::OnWindowAdded(aura::Window* new_window) { |
| 47 if (new_window->parent() != parent_) |
| 48 return; |
| 49 |
| 50 new_window->AddObserver(this); |
| 51 UpdateConstrainedWindows(NULL); |
| 52 } |
| 53 |
| 54 void ConstrainedWindowsObserver::OnWillRemoveWindow(aura::Window* window) { |
| 55 if (window->parent() == parent_ && window != view_->window_) { |
| 56 window->RemoveObserver(this); |
| 57 UpdateConstrainedWindows(window); |
| 58 } |
| 59 } |
| 60 |
| 61 void ConstrainedWindowsObserver::OnWindowVisibilityChanged( |
| 62 aura::Window* window, |
| 63 bool visible) { |
| 64 if (window->parent() == parent_ && window != view_->window_) |
| 65 UpdateConstrainedWindows(NULL); |
| 66 } |
| 67 |
| 68 void ConstrainedWindowsObserver::OnWindowParentChanged(aura::Window* window, |
| 69 aura::Window* parent) { |
| 70 if (window != view_->window_) |
| 71 return; |
| 72 if (parent_) |
| 73 parent_->RemoveObserver(this); |
| 74 if (parent_) { |
| 75 const aura::Window::Windows& children = parent_->children(); |
| 76 for (size_t i = 0; i < children.size(); ++i) |
| 77 children[i]->RemoveObserver(this); |
| 78 |
| 79 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( |
| 80 view_->web_contents_->GetRenderWidgetHostView()); |
| 81 if (view) |
| 82 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); |
| 83 } |
| 84 |
| 85 parent_ = parent; |
| 86 if (parent) |
| 87 parent->AddObserver(this); |
| 88 } |
| 89 |
| 90 void ConstrainedWindowsObserver::OnWindowBoundsChanged( |
| 91 aura::Window* window, |
| 92 const gfx::Rect& old_bounds, |
| 93 const gfx::Rect& new_bounds) { |
| 94 if (window != parent_ || window != view_->window_) |
| 95 UpdateConstrainedWindows(NULL); |
| 96 } |
| 97 |
| 98 void ConstrainedWindowsObserver::UpdateConstrainedWindows( |
| 99 aura::Window* exclude) { |
| 100 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( |
| 101 view_->web_contents_->GetRenderWidgetHostView()); |
| 102 if (!view) |
| 103 return; |
| 104 |
| 105 std::vector<gfx::Rect> constrained_windows; |
| 106 const aura::Window::Windows& children = parent_->children(); |
| 107 for (size_t i = 0; i < children.size(); ++i) { |
| 108 if (children[i] != view_->window_ && |
| 109 children[i] != exclude && |
| 110 children[i]->IsVisible()) { |
| 111 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); |
| 112 } |
| 113 } |
| 114 |
| 115 // view->UpdateConstrainedWindowRects(constrained_windows); |
| 116 } |
| 117 |
| 118 } // namespace content |
| OLD | NEW |