| 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 <set> |
| 8 |
| 7 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 16 #include "cc/layers/layer.h" | 18 #include "cc/layers/layer.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (window == view_->window_) | 347 if (window == view_->window_) |
| 346 view_->AddedToRootWindow(); | 348 view_->AddedToRootWindow(); |
| 347 } | 349 } |
| 348 | 350 |
| 349 void OnWindowRemovingFromRootWindow(aura::Window* window, | 351 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 350 aura::Window* new_root) override { | 352 aura::Window* new_root) override { |
| 351 if (window == view_->window_) | 353 if (window == view_->window_) |
| 352 view_->RemovingFromRootWindow(); | 354 view_->RemovingFromRootWindow(); |
| 353 } | 355 } |
| 354 | 356 |
| 357 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override { |
| 358 view_->ParentHierarchyChanged(); |
| 359 } |
| 360 |
| 355 private: | 361 private: |
| 356 RenderWidgetHostViewAura* view_; | 362 RenderWidgetHostViewAura* view_; |
| 357 | 363 |
| 358 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 364 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
| 359 }; | 365 }; |
| 360 | 366 |
| 367 // This class provides functionality to observe the ancestors of the RWHVA for |
| 368 // bounds changes. This is done to snap the RWHVA window to a pixel boundary, |
| 369 // which could change when the bounds relative to the root changes. |
| 370 // An example where this happens is below:- |
| 371 // The fast resize code path for bookmarks where in the parent of RWHVA which |
| 372 // is WCV has its bounds changed before the bookmark is hidden. This results in |
| 373 // the traditional bounds change notification for the WCV reporting the old |
| 374 // bounds as the bookmark is still around. Observing all the ancestors of the |
| 375 // RWHVA window enables us to know when the bounds of the window relative to |
| 376 // root changes and allows us to snap accordingly. |
| 377 class RenderWidgetHostViewAura::WindowAncestorObserver |
| 378 : public aura::WindowObserver { |
| 379 public: |
| 380 explicit WindowAncestorObserver(RenderWidgetHostViewAura* view) |
| 381 : view_(view) { |
| 382 aura::Window* parent = view_->window_->parent(); |
| 383 while (parent) { |
| 384 parent->AddObserver(this); |
| 385 ancestors_.insert(parent); |
| 386 parent = parent->parent(); |
| 387 } |
| 388 } |
| 389 |
| 390 ~WindowAncestorObserver() override { |
| 391 RemoveAncestorObservers(); |
| 392 } |
| 393 |
| 394 void OnWindowBoundsChanged(aura::Window* window, |
| 395 const gfx::Rect& old_bounds, |
| 396 const gfx::Rect& new_bounds) override { |
| 397 DCHECK(ancestors_.find(window) != ancestors_.end()); |
| 398 if (new_bounds.origin() != old_bounds.origin()) |
| 399 view_->HandleParentBoundsChanged(); |
| 400 } |
| 401 |
| 402 private: |
| 403 void RemoveAncestorObservers() { |
| 404 for (auto ancestor : ancestors_) |
| 405 ancestor->RemoveObserver(this); |
| 406 ancestors_.clear(); |
| 407 } |
| 408 |
| 409 RenderWidgetHostViewAura* view_; |
| 410 std::set<aura::Window*> ancestors_; |
| 411 |
| 412 DISALLOW_COPY_AND_ASSIGN(WindowAncestorObserver); |
| 413 }; |
| 414 |
| 361 //////////////////////////////////////////////////////////////////////////////// | 415 //////////////////////////////////////////////////////////////////////////////// |
| 362 // RenderWidgetHostViewAura, public: | 416 // RenderWidgetHostViewAura, public: |
| 363 | 417 |
| 364 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, | 418 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
| 365 bool is_guest_view_hack) | 419 bool is_guest_view_hack) |
| 366 : host_(RenderWidgetHostImpl::From(host)), | 420 : host_(RenderWidgetHostImpl::From(host)), |
| 367 window_(new aura::Window(this)), | 421 window_(new aura::Window(this)), |
| 368 delegated_frame_host_(new DelegatedFrameHost(this)), | 422 delegated_frame_host_(new DelegatedFrameHost(this)), |
| 369 in_shutdown_(false), | 423 in_shutdown_(false), |
| 370 in_bounds_changed_(false), | 424 in_bounds_changed_(false), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 388 showing_context_menu_(false), | 442 showing_context_menu_(false), |
| 389 #endif | 443 #endif |
| 390 has_snapped_to_boundary_(false), | 444 has_snapped_to_boundary_(false), |
| 391 touch_editing_client_(NULL), | 445 touch_editing_client_(NULL), |
| 392 is_guest_view_hack_(is_guest_view_hack), | 446 is_guest_view_hack_(is_guest_view_hack), |
| 393 weak_ptr_factory_(this) { | 447 weak_ptr_factory_(this) { |
| 394 if (!is_guest_view_hack_) | 448 if (!is_guest_view_hack_) |
| 395 host_->SetView(this); | 449 host_->SetView(this); |
| 396 | 450 |
| 397 window_observer_.reset(new WindowObserver(this)); | 451 window_observer_.reset(new WindowObserver(this)); |
| 452 |
| 398 aura::client::SetTooltipText(window_, &tooltip_); | 453 aura::client::SetTooltipText(window_, &tooltip_); |
| 399 aura::client::SetActivationDelegate(window_, this); | 454 aura::client::SetActivationDelegate(window_, this); |
| 400 aura::client::SetFocusChangeObserver(window_, this); | 455 aura::client::SetFocusChangeObserver(window_, this); |
| 401 window_->set_layer_owner_delegate(delegated_frame_host_.get()); | 456 window_->set_layer_owner_delegate(delegated_frame_host_.get()); |
| 402 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 457 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
| 403 | 458 |
| 404 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> | 459 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> |
| 405 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 460 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
| 406 SetOverscrollControllerEnabled(overscroll_enabled); | 461 SetOverscrollControllerEnabled(overscroll_enabled); |
| 407 } | 462 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 ui::EF_RIGHT_MOUSE_BUTTON; | 782 ui::EF_RIGHT_MOUSE_BUTTON; |
| 728 return (event->flags() & kAllowedButtons) != 0; | 783 return (event->flags() & kAllowedButtons) != 0; |
| 729 } | 784 } |
| 730 default: | 785 default: |
| 731 break; | 786 break; |
| 732 } | 787 } |
| 733 #endif | 788 #endif |
| 734 return true; | 789 return true; |
| 735 } | 790 } |
| 736 | 791 |
| 792 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { |
| 793 SnapToPhysicalPixelBoundary(); |
| 794 #if defined(OS_WIN) |
| 795 if (legacy_render_widget_host_HWND_) { |
| 796 legacy_render_widget_host_HWND_->SetBounds( |
| 797 window_->GetBoundsInRootWindow()); |
| 798 } |
| 799 #endif |
| 800 } |
| 801 |
| 802 void RenderWidgetHostViewAura::ParentHierarchyChanged() { |
| 803 ancestor_window_observer_.reset(new WindowAncestorObserver(this)); |
| 804 // Snap when we receive a hierarchy changed. http://crbug.com/388908. |
| 805 HandleParentBoundsChanged(); |
| 806 } |
| 807 |
| 737 void RenderWidgetHostViewAura::MovePluginWindows( | 808 void RenderWidgetHostViewAura::MovePluginWindows( |
| 738 const std::vector<WebPluginGeometry>& plugin_window_moves) { | 809 const std::vector<WebPluginGeometry>& plugin_window_moves) { |
| 739 #if defined(OS_WIN) | 810 #if defined(OS_WIN) |
| 740 // We need to clip the rectangle to the tab's viewport, otherwise we will draw | 811 // We need to clip the rectangle to the tab's viewport, otherwise we will draw |
| 741 // over the browser UI. | 812 // over the browser UI. |
| 742 if (!window_->GetRootWindow()) { | 813 if (!window_->GetRootWindow()) { |
| 743 DCHECK(plugin_window_moves.empty()); | 814 DCHECK(plugin_window_moves.empty()); |
| 744 return; | 815 return; |
| 745 } | 816 } |
| 746 HWND parent = window_->GetHost()->GetAcceleratedWidget(); | 817 HWND parent = window_->GetHost()->GetAcceleratedWidget(); |
| (...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2693 | 2764 |
| 2694 //////////////////////////////////////////////////////////////////////////////// | 2765 //////////////////////////////////////////////////////////////////////////////// |
| 2695 // RenderWidgetHostViewBase, public: | 2766 // RenderWidgetHostViewBase, public: |
| 2696 | 2767 |
| 2697 // static | 2768 // static |
| 2698 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2769 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2699 GetScreenInfoForWindow(results, NULL); | 2770 GetScreenInfoForWindow(results, NULL); |
| 2700 } | 2771 } |
| 2701 | 2772 |
| 2702 } // namespace content | 2773 } // namespace content |
| OLD | NEW |