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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 if (window == view_->window_) | 353 if (window == view_->window_) |
352 view_->RemovingFromRootWindow(); | 354 view_->RemovingFromRootWindow(); |
353 } | 355 } |
354 | 356 |
355 private: | 357 private: |
356 RenderWidgetHostViewAura* view_; | 358 RenderWidgetHostViewAura* view_; |
357 | 359 |
358 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 360 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
359 }; | 361 }; |
360 | 362 |
363 // This class provides functionality to observe the ancestors of the RWHVA | |
364 // window for bounds changes and snap the RWHVA instance to pixel boundaries. | |
365 // Reason for doing this is there are cases like the fast resize code path for | |
366 // bookmarks where in the parent of RWHVA which is WCV has its bounds changed | |
367 // before the bookmark is hidden. This results in it reporting the old bounds | |
368 // which includes the bookmark. Eventually when it does get the correct bounds | |
369 // after the bar is hidden, the layer ignores the bounds changed call as the | |
370 // bounds are the same. To work around this we observe the | |
371 // ancestors of the RWHVA window for bounds changed notifications and snap when | |
372 // we receive them. | |
373 class RenderWidgetHostViewAura::WindowAncestorObserver | |
374 : public aura::WindowObserver { | |
375 public: | |
376 explicit WindowAncestorObserver(RenderWidgetHostViewAura* view) | |
377 : view_(view) { | |
378 view_->window_->AddObserver(this); | |
379 } | |
380 | |
381 ~WindowAncestorObserver() override { | |
382 RemoveAncestorObservers(); | |
383 view_->window_->RemoveObserver(this); | |
384 } | |
385 | |
386 // Overridden from aura::WindowObserver: | |
387 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override { | |
388 if (!params.target->Contains(view_->window_) || !params.new_parent) | |
sky
2015/04/09 23:44:38
I'm wondering if you could simplify things like th
ananta
2015/04/10 00:36:52
Done. I added the hierarchy changed function in th
| |
389 return; | |
390 | |
391 if (params.old_parent) | |
392 StopObservingAncestor(params.old_parent); | |
393 | |
394 // To ensure that we get notified for bounds changed notifications for all | |
395 // ancestors for the view window, we walk the ancestor hierarchy starting | |
396 // with the new parent and add observers for all ancestors we have not | |
397 // seen. | |
398 aura::Window* parent = params.new_parent; | |
399 while (parent) { | |
400 if (ancestor_observer_tracker_.find(parent) == | |
401 ancestor_observer_tracker_.end()) { | |
402 parent->AddObserver(this); | |
403 ancestor_observer_tracker_.insert(parent); | |
404 } | |
405 parent = parent->parent(); | |
406 } | |
407 view_->HandleParentBoundsChanged(); | |
408 } | |
409 | |
410 void OnWindowBoundsChanged(aura::Window* window, | |
411 const gfx::Rect& old_bounds, | |
412 const gfx::Rect& new_bounds) override { | |
413 if (ancestor_observer_tracker_.find(window) != | |
sky
2015/04/09 23:44:38
This should be a DCHECK.
ananta
2015/04/10 00:36:52
Done.
| |
414 ancestor_observer_tracker_.end()) { | |
415 view_->HandleParentBoundsChanged(); | |
sky
2015/04/09 23:44:38
Don't you only care about this if the origin chang
ananta
2015/04/10 00:36:52
Yes. Added a check for origin change.
| |
416 } | |
417 } | |
418 | |
419 void OnWindowDestroyed(aura::Window* window) override { | |
420 StopObservingAncestor(window); | |
421 } | |
422 | |
423 private: | |
424 void RemoveAncestorObservers() { | |
425 for (auto ancestor_observer_iterator : ancestor_observer_tracker_) | |
sky
2015/04/09 23:44:38
ancestor_observer_iterator is a misleading name he
ananta
2015/04/10 00:36:52
changed to ancestor
| |
426 ancestor_observer_iterator->RemoveObserver(this); | |
427 ancestor_observer_tracker_.clear(); | |
428 } | |
429 | |
430 void StopObservingAncestor(aura::Window* ancestor) { | |
431 std::set<aura::Window*>::iterator index = | |
sky
2015/04/09 23:44:38
index->iter
ananta
2015/04/10 00:36:52
Function has been removed.
| |
432 ancestor_observer_tracker_.find(ancestor); | |
433 if (index != ancestor_observer_tracker_.end()) { | |
434 (*index)->RemoveObserver(this); | |
435 ancestor_observer_tracker_.erase(index); | |
436 } | |
437 } | |
438 | |
439 RenderWidgetHostViewAura* view_; | |
440 std::set<aura::Window*> ancestor_observer_tracker_; | |
441 | |
442 DISALLOW_COPY_AND_ASSIGN(WindowAncestorObserver); | |
443 }; | |
444 | |
361 //////////////////////////////////////////////////////////////////////////////// | 445 //////////////////////////////////////////////////////////////////////////////// |
362 // RenderWidgetHostViewAura, public: | 446 // RenderWidgetHostViewAura, public: |
363 | 447 |
364 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, | 448 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
365 bool is_guest_view_hack) | 449 bool is_guest_view_hack) |
366 : host_(RenderWidgetHostImpl::From(host)), | 450 : host_(RenderWidgetHostImpl::From(host)), |
367 window_(new aura::Window(this)), | 451 window_(new aura::Window(this)), |
368 delegated_frame_host_(new DelegatedFrameHost(this)), | 452 delegated_frame_host_(new DelegatedFrameHost(this)), |
369 in_shutdown_(false), | 453 in_shutdown_(false), |
370 in_bounds_changed_(false), | 454 in_bounds_changed_(false), |
(...skipping 17 matching lines...) Expand all Loading... | |
388 showing_context_menu_(false), | 472 showing_context_menu_(false), |
389 #endif | 473 #endif |
390 has_snapped_to_boundary_(false), | 474 has_snapped_to_boundary_(false), |
391 touch_editing_client_(NULL), | 475 touch_editing_client_(NULL), |
392 is_guest_view_hack_(is_guest_view_hack), | 476 is_guest_view_hack_(is_guest_view_hack), |
393 weak_ptr_factory_(this) { | 477 weak_ptr_factory_(this) { |
394 if (!is_guest_view_hack_) | 478 if (!is_guest_view_hack_) |
395 host_->SetView(this); | 479 host_->SetView(this); |
396 | 480 |
397 window_observer_.reset(new WindowObserver(this)); | 481 window_observer_.reset(new WindowObserver(this)); |
482 ancestor_window_observer_.reset(new WindowAncestorObserver(this)); | |
483 | |
398 aura::client::SetTooltipText(window_, &tooltip_); | 484 aura::client::SetTooltipText(window_, &tooltip_); |
399 aura::client::SetActivationDelegate(window_, this); | 485 aura::client::SetActivationDelegate(window_, this); |
400 aura::client::SetFocusChangeObserver(window_, this); | 486 aura::client::SetFocusChangeObserver(window_, this); |
401 window_->set_layer_owner_delegate(delegated_frame_host_.get()); | 487 window_->set_layer_owner_delegate(delegated_frame_host_.get()); |
402 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 488 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
403 | 489 |
404 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> | 490 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> |
405 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 491 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
406 SetOverscrollControllerEnabled(overscroll_enabled); | 492 SetOverscrollControllerEnabled(overscroll_enabled); |
407 } | 493 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 ui::EF_RIGHT_MOUSE_BUTTON; | 813 ui::EF_RIGHT_MOUSE_BUTTON; |
728 return (event->flags() & kAllowedButtons) != 0; | 814 return (event->flags() & kAllowedButtons) != 0; |
729 } | 815 } |
730 default: | 816 default: |
731 break; | 817 break; |
732 } | 818 } |
733 #endif | 819 #endif |
734 return true; | 820 return true; |
735 } | 821 } |
736 | 822 |
823 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { | |
824 SnapToPhysicalPixelBoundary(); | |
825 #if defined(OS_WIN) | |
826 if (legacy_render_widget_host_HWND_) { | |
827 legacy_render_widget_host_HWND_->SetBounds( | |
828 window_->GetBoundsInRootWindow()); | |
829 } | |
830 #endif | |
831 } | |
832 | |
737 void RenderWidgetHostViewAura::MovePluginWindows( | 833 void RenderWidgetHostViewAura::MovePluginWindows( |
738 const std::vector<WebPluginGeometry>& plugin_window_moves) { | 834 const std::vector<WebPluginGeometry>& plugin_window_moves) { |
739 #if defined(OS_WIN) | 835 #if defined(OS_WIN) |
740 // We need to clip the rectangle to the tab's viewport, otherwise we will draw | 836 // We need to clip the rectangle to the tab's viewport, otherwise we will draw |
741 // over the browser UI. | 837 // over the browser UI. |
742 if (!window_->GetRootWindow()) { | 838 if (!window_->GetRootWindow()) { |
743 DCHECK(plugin_window_moves.empty()); | 839 DCHECK(plugin_window_moves.empty()); |
744 return; | 840 return; |
745 } | 841 } |
746 HWND parent = window_->GetHost()->GetAcceleratedWidget(); | 842 HWND parent = window_->GetHost()->GetAcceleratedWidget(); |
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2693 | 2789 |
2694 //////////////////////////////////////////////////////////////////////////////// | 2790 //////////////////////////////////////////////////////////////////////////////// |
2695 // RenderWidgetHostViewBase, public: | 2791 // RenderWidgetHostViewBase, public: |
2696 | 2792 |
2697 // static | 2793 // static |
2698 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2794 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2699 GetScreenInfoForWindow(results, NULL); | 2795 GetScreenInfoForWindow(results, NULL); |
2700 } | 2796 } |
2701 | 2797 |
2702 } // namespace content | 2798 } // namespace content |
OLD | NEW |