Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 | 329 |
| 330 // We have to implement the WindowObserver interface on a separate object | 330 // We have to implement the WindowObserver interface on a separate object |
| 331 // because clang doesn't like implementing multiple interfaces that have | 331 // because clang doesn't like implementing multiple interfaces that have |
| 332 // methods with the same name. This object is owned by the | 332 // methods with the same name. This object is owned by the |
| 333 // RenderWidgetHostViewAura. | 333 // RenderWidgetHostViewAura. |
| 334 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver { | 334 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver { |
| 335 public: | 335 public: |
| 336 explicit WindowObserver(RenderWidgetHostViewAura* view) | 336 explicit WindowObserver(RenderWidgetHostViewAura* view) |
| 337 : view_(view) { | 337 : view_(view), |
| 338 view_ancestor_(nullptr) { | |
| 338 view_->window_->AddObserver(this); | 339 view_->window_->AddObserver(this); |
| 339 } | 340 } |
| 340 | 341 |
| 341 ~WindowObserver() override { view_->window_->RemoveObserver(this); } | 342 ~WindowObserver() override { |
| 343 if (view_ancestor_) | |
| 344 view_ancestor_->RemoveObserver(this); | |
| 345 view_->window_->RemoveObserver(this); | |
| 346 } | |
| 342 | 347 |
| 343 // Overridden from aura::WindowObserver: | 348 // Overridden from aura::WindowObserver: |
| 344 void OnWindowAddedToRootWindow(aura::Window* window) override { | 349 void OnWindowAddedToRootWindow(aura::Window* window) override { |
| 345 if (window == view_->window_) | 350 if (window == view_->window_) { |
| 351 if (window->parent() && window->parent()->parent()) { | |
| 352 // We observe the ancestor for bounds changes and snap the RWHVA | |
| 353 // instance to pixel boundaries. Reason for doing this is there are | |
| 354 // cases like the fast resize code path for bookmarks where in the | |
| 355 // parent of RWHVA which is WCV has its bounds changed before the | |
| 356 // bookmark is hidden. This results in it reporting the old bounds | |
| 357 // which includes the bookmark. Eventually when it does get the correct | |
| 358 // bounds after the bar is hidden, the layer ignores the bounds changed | |
| 359 // call as the bounds are the same. To work around this we observe the | |
| 360 // parent of WCV for bounds changed notifications and snap when we | |
| 361 // receive them. | |
| 362 view_ancestor_ = window->parent()->parent(); | |
| 363 view_ancestor_->AddObserver(this); | |
|
sky
2015/04/08 20:13:09
Don't you want to know when the bounds of any ance
ananta
2015/04/08 21:08:20
Done.
| |
| 364 } | |
| 346 view_->AddedToRootWindow(); | 365 view_->AddedToRootWindow(); |
| 366 } | |
| 347 } | 367 } |
| 348 | 368 |
| 349 void OnWindowRemovingFromRootWindow(aura::Window* window, | 369 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 350 aura::Window* new_root) override { | 370 aura::Window* new_root) override { |
| 351 if (window == view_->window_) | 371 if (window == view_->window_) { |
| 372 if (view_ancestor_) { | |
| 373 view_ancestor_->RemoveObserver(this); | |
| 374 view_ancestor_ = nullptr; | |
| 375 } | |
| 352 view_->RemovingFromRootWindow(); | 376 view_->RemovingFromRootWindow(); |
| 377 } | |
| 378 } | |
| 379 | |
| 380 void OnWindowBoundsChanged(aura::Window* window, | |
| 381 const gfx::Rect& old_bounds, | |
| 382 const gfx::Rect& new_bounds) override { | |
| 383 if (window == view_ancestor_) | |
| 384 view_->HandleParentBoundsChanged(); | |
| 353 } | 385 } |
| 354 | 386 |
| 355 private: | 387 private: |
| 356 RenderWidgetHostViewAura* view_; | 388 RenderWidgetHostViewAura* view_; |
| 389 aura::Window* view_ancestor_; | |
| 357 | 390 |
| 358 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 391 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
| 359 }; | 392 }; |
| 360 | 393 |
| 361 //////////////////////////////////////////////////////////////////////////////// | 394 //////////////////////////////////////////////////////////////////////////////// |
| 362 // RenderWidgetHostViewAura, public: | 395 // RenderWidgetHostViewAura, public: |
| 363 | 396 |
| 364 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, | 397 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
| 365 bool is_guest_view_hack) | 398 bool is_guest_view_hack) |
| 366 : host_(RenderWidgetHostImpl::From(host)), | 399 : host_(RenderWidgetHostImpl::From(host)), |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 ui::EF_RIGHT_MOUSE_BUTTON; | 760 ui::EF_RIGHT_MOUSE_BUTTON; |
| 728 return (event->flags() & kAllowedButtons) != 0; | 761 return (event->flags() & kAllowedButtons) != 0; |
| 729 } | 762 } |
| 730 default: | 763 default: |
| 731 break; | 764 break; |
| 732 } | 765 } |
| 733 #endif | 766 #endif |
| 734 return true; | 767 return true; |
| 735 } | 768 } |
| 736 | 769 |
| 770 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { | |
| 771 SnapToPhysicalPixelBoundary(); | |
| 772 #if defined(OS_WIN) | |
| 773 if (legacy_render_widget_host_HWND_) { | |
| 774 legacy_render_widget_host_HWND_->SetBounds( | |
| 775 window_->GetBoundsInRootWindow()); | |
| 776 } | |
| 777 #endif | |
| 778 } | |
| 779 | |
| 737 void RenderWidgetHostViewAura::MovePluginWindows( | 780 void RenderWidgetHostViewAura::MovePluginWindows( |
| 738 const std::vector<WebPluginGeometry>& plugin_window_moves) { | 781 const std::vector<WebPluginGeometry>& plugin_window_moves) { |
| 739 #if defined(OS_WIN) | 782 #if defined(OS_WIN) |
| 740 // We need to clip the rectangle to the tab's viewport, otherwise we will draw | 783 // We need to clip the rectangle to the tab's viewport, otherwise we will draw |
| 741 // over the browser UI. | 784 // over the browser UI. |
| 742 if (!window_->GetRootWindow()) { | 785 if (!window_->GetRootWindow()) { |
| 743 DCHECK(plugin_window_moves.empty()); | 786 DCHECK(plugin_window_moves.empty()); |
| 744 return; | 787 return; |
| 745 } | 788 } |
| 746 HWND parent = window_->GetHost()->GetAcceleratedWidget(); | 789 HWND parent = window_->GetHost()->GetAcceleratedWidget(); |
| (...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2693 | 2736 |
| 2694 //////////////////////////////////////////////////////////////////////////////// | 2737 //////////////////////////////////////////////////////////////////////////////// |
| 2695 // RenderWidgetHostViewBase, public: | 2738 // RenderWidgetHostViewBase, public: |
| 2696 | 2739 |
| 2697 // static | 2740 // static |
| 2698 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2741 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2699 GetScreenInfoForWindow(results, NULL); | 2742 GetScreenInfoForWindow(results, NULL); |
| 2700 } | 2743 } |
| 2701 | 2744 |
| 2702 } // namespace content | 2745 } // namespace content |
| OLD | NEW |