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 | |
9 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
10 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
11 #include "base/bind.h" | 9 #include "base/bind.h" |
12 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
13 #include "base/command_line.h" | 11 #include "base/command_line.h" |
14 #include "base/logging.h" | 12 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
18 #include "cc/layers/layer.h" | 16 #include "cc/layers/layer.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (window == view_->window_) | 345 if (window == view_->window_) |
348 view_->AddedToRootWindow(); | 346 view_->AddedToRootWindow(); |
349 } | 347 } |
350 | 348 |
351 void OnWindowRemovingFromRootWindow(aura::Window* window, | 349 void OnWindowRemovingFromRootWindow(aura::Window* window, |
352 aura::Window* new_root) override { | 350 aura::Window* new_root) override { |
353 if (window == view_->window_) | 351 if (window == view_->window_) |
354 view_->RemovingFromRootWindow(); | 352 view_->RemovingFromRootWindow(); |
355 } | 353 } |
356 | 354 |
357 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override { | |
358 view_->ParentHierarchyChanged(); | |
359 } | |
360 | |
361 private: | 355 private: |
362 RenderWidgetHostViewAura* view_; | 356 RenderWidgetHostViewAura* view_; |
363 | 357 |
364 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 358 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
365 }; | 359 }; |
366 | 360 |
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 | |
415 //////////////////////////////////////////////////////////////////////////////// | 361 //////////////////////////////////////////////////////////////////////////////// |
416 // RenderWidgetHostViewAura, public: | 362 // RenderWidgetHostViewAura, public: |
417 | 363 |
418 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, | 364 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
419 bool is_guest_view_hack) | 365 bool is_guest_view_hack) |
420 : host_(RenderWidgetHostImpl::From(host)), | 366 : host_(RenderWidgetHostImpl::From(host)), |
421 window_(new aura::Window(this)), | 367 window_(new aura::Window(this)), |
422 delegated_frame_host_(new DelegatedFrameHost(this)), | 368 delegated_frame_host_(new DelegatedFrameHost(this)), |
423 in_shutdown_(false), | 369 in_shutdown_(false), |
424 in_bounds_changed_(false), | 370 in_bounds_changed_(false), |
(...skipping 17 matching lines...) Expand all Loading... |
442 showing_context_menu_(false), | 388 showing_context_menu_(false), |
443 #endif | 389 #endif |
444 has_snapped_to_boundary_(false), | 390 has_snapped_to_boundary_(false), |
445 touch_editing_client_(NULL), | 391 touch_editing_client_(NULL), |
446 is_guest_view_hack_(is_guest_view_hack), | 392 is_guest_view_hack_(is_guest_view_hack), |
447 weak_ptr_factory_(this) { | 393 weak_ptr_factory_(this) { |
448 if (!is_guest_view_hack_) | 394 if (!is_guest_view_hack_) |
449 host_->SetView(this); | 395 host_->SetView(this); |
450 | 396 |
451 window_observer_.reset(new WindowObserver(this)); | 397 window_observer_.reset(new WindowObserver(this)); |
452 | |
453 aura::client::SetTooltipText(window_, &tooltip_); | 398 aura::client::SetTooltipText(window_, &tooltip_); |
454 aura::client::SetActivationDelegate(window_, this); | 399 aura::client::SetActivationDelegate(window_, this); |
455 aura::client::SetFocusChangeObserver(window_, this); | 400 aura::client::SetFocusChangeObserver(window_, this); |
456 window_->set_layer_owner_delegate(delegated_frame_host_.get()); | 401 window_->set_layer_owner_delegate(delegated_frame_host_.get()); |
457 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 402 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
458 | 403 |
459 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> | 404 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> |
460 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 405 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
461 SetOverscrollControllerEnabled(overscroll_enabled); | 406 SetOverscrollControllerEnabled(overscroll_enabled); |
462 } | 407 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 ui::EF_RIGHT_MOUSE_BUTTON; | 727 ui::EF_RIGHT_MOUSE_BUTTON; |
783 return (event->flags() & kAllowedButtons) != 0; | 728 return (event->flags() & kAllowedButtons) != 0; |
784 } | 729 } |
785 default: | 730 default: |
786 break; | 731 break; |
787 } | 732 } |
788 #endif | 733 #endif |
789 return true; | 734 return true; |
790 } | 735 } |
791 | 736 |
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 | |
808 void RenderWidgetHostViewAura::MovePluginWindows( | 737 void RenderWidgetHostViewAura::MovePluginWindows( |
809 const std::vector<WebPluginGeometry>& plugin_window_moves) { | 738 const std::vector<WebPluginGeometry>& plugin_window_moves) { |
810 #if defined(OS_WIN) | 739 #if defined(OS_WIN) |
811 // We need to clip the rectangle to the tab's viewport, otherwise we will draw | 740 // We need to clip the rectangle to the tab's viewport, otherwise we will draw |
812 // over the browser UI. | 741 // over the browser UI. |
813 if (!window_->GetRootWindow()) { | 742 if (!window_->GetRootWindow()) { |
814 DCHECK(plugin_window_moves.empty()); | 743 DCHECK(plugin_window_moves.empty()); |
815 return; | 744 return; |
816 } | 745 } |
817 HWND parent = window_->GetHost()->GetAcceleratedWidget(); | 746 HWND parent = window_->GetHost()->GetAcceleratedWidget(); |
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2764 | 2693 |
2765 //////////////////////////////////////////////////////////////////////////////// | 2694 //////////////////////////////////////////////////////////////////////////////// |
2766 // RenderWidgetHostViewBase, public: | 2695 // RenderWidgetHostViewBase, public: |
2767 | 2696 |
2768 // static | 2697 // static |
2769 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2698 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2770 GetScreenInfoForWindow(results, NULL); | 2699 GetScreenInfoForWindow(results, NULL); |
2771 } | 2700 } |
2772 | 2701 |
2773 } // namespace content | 2702 } // namespace content |
OLD | NEW |