Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 54623007: Make code path for bounds changes getting to renderer less brittle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved observer into content/browser/web_contents/aura and added tests Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 25 matching lines...) Expand all
36 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
37 #include "content/public/common/drop_data.h" 37 #include "content/public/common/drop_data.h"
38 #include "net/base/net_util.h" 38 #include "net/base/net_util.h"
39 #include "third_party/WebKit/public/web/WebInputEvent.h" 39 #include "third_party/WebKit/public/web/WebInputEvent.h"
40 #include "ui/aura/client/aura_constants.h" 40 #include "ui/aura/client/aura_constants.h"
41 #include "ui/aura/client/drag_drop_client.h" 41 #include "ui/aura/client/drag_drop_client.h"
42 #include "ui/aura/client/drag_drop_delegate.h" 42 #include "ui/aura/client/drag_drop_delegate.h"
43 #include "ui/aura/client/window_tree_client.h" 43 #include "ui/aura/client/window_tree_client.h"
44 #include "ui/aura/env.h" 44 #include "ui/aura/env.h"
45 #include "ui/aura/root_window.h" 45 #include "ui/aura/root_window.h"
46 #include "ui/aura/root_window_observer.h"
47 #include "ui/aura/window.h" 46 #include "ui/aura/window.h"
48 #include "ui/aura/window_observer.h"
49 #include "ui/base/clipboard/clipboard.h" 47 #include "ui/base/clipboard/clipboard.h"
50 #include "ui/base/clipboard/custom_data_helper.h" 48 #include "ui/base/clipboard/custom_data_helper.h"
51 #include "ui/base/dragdrop/drag_drop_types.h" 49 #include "ui/base/dragdrop/drag_drop_types.h"
52 #include "ui/base/dragdrop/drag_utils.h" 50 #include "ui/base/dragdrop/drag_utils.h"
53 #include "ui/base/dragdrop/drop_target_event.h" 51 #include "ui/base/dragdrop/drop_target_event.h"
54 #include "ui/base/dragdrop/os_exchange_data.h" 52 #include "ui/base/dragdrop/os_exchange_data.h"
55 #include "ui/base/hit_test.h" 53 #include "ui/base/hit_test.h"
56 #include "ui/compositor/layer.h" 54 #include "ui/compositor/layer.h"
57 #include "ui/compositor/scoped_layer_animation_settings.h" 55 #include "ui/compositor/scoped_layer_animation_settings.h"
58 #include "ui/events/event.h" 56 #include "ui/events/event.h"
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 ImageLayerDelegate layer_delegate_; 639 ImageLayerDelegate layer_delegate_;
642 640
643 // During tests, the aura windows don't get any paint updates. So the overlay 641 // During tests, the aura windows don't get any paint updates. So the overlay
644 // container keeps waiting for a paint update it never receives, causing a 642 // container keeps waiting for a paint update it never receives, causing a
645 // timeout. So during tests, disable the wait for paint updates. 643 // timeout. So during tests, disable the wait for paint updates.
646 bool need_paint_update_; 644 bool need_paint_update_;
647 645
648 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); 646 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
649 }; 647 };
650 648
651 class WebContentsViewAura::WindowObserver
652 : public aura::WindowObserver, public aura::RootWindowObserver {
653 public:
654 explicit WindowObserver(WebContentsViewAura* view)
655 : view_(view),
656 parent_(NULL) {
657 view_->window_->AddObserver(this);
658 }
659
660 virtual ~WindowObserver() {
661 view_->window_->RemoveObserver(this);
662 if (view_->window_->GetDispatcher())
663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this);
664 if (parent_)
665 parent_->RemoveObserver(this);
666 }
667
668 // Overridden from aura::WindowObserver:
669 virtual void OnWindowParentChanged(aura::Window* window,
670 aura::Window* parent) OVERRIDE {
671 if (window == parent_)
672 return;
673 if (parent_)
674 parent_->RemoveObserver(this);
675 parent_ = parent;
676 if (parent)
677 parent->AddObserver(this);
678 }
679
680 virtual void OnWindowBoundsChanged(aura::Window* window,
681 const gfx::Rect& old_bounds,
682 const gfx::Rect& new_bounds) OVERRIDE {
683 SendScreenRects();
684 if (view_->touch_editable_)
685 view_->touch_editable_->UpdateEditingController();
686 }
687
688 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
689 if (window != parent_)
690 window->GetDispatcher()->AddRootWindowObserver(this);
691 }
692
693 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE {
694 if (window != parent_)
695 window->GetDispatcher()->RemoveRootWindowObserver(this);
696 }
697
698 // Overridden RootWindowObserver:
699 virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
700 const gfx::Point& new_origin) OVERRIDE {
701 // This is for the desktop case (i.e. Aura desktop).
702 SendScreenRects();
703 }
704
705 private:
706 void SendScreenRects() {
707 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())->
708 SendScreenRects();
709 }
710
711 WebContentsViewAura* view_;
712
713 // We cache the old parent so that we can unregister when it's not the parent
714 // anymore.
715 aura::Window* parent_;
716
717 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
718 };
719
720 #if defined(OS_WIN) 649 #if defined(OS_WIN)
721 // Constrained windows are added as children of the WebContent's view which may 650 // Constrained windows are added as children of the WebContent's view which may
722 // overlap with windowed NPAPI plugins. In that case, tell the RWHV so that it 651 // overlap with windowed NPAPI plugins. In that case, tell the RWHV so that it
723 // can update the plugins' cutout rects accordingly. 652 // can update the plugins' cutout rects accordingly.
724 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver, 653 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver,
725 public WebContentsObserver { 654 public WebContentsObserver {
726 public: 655 public:
727 explicit ChildWindowObserver(WebContentsViewAura* view) 656 explicit ChildWindowObserver(WebContentsViewAura* view)
728 : WebContentsObserver(view->web_contents_), 657 : WebContentsObserver(view->web_contents_),
729 view_(view), 658 view_(view),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 touch_editable_(TouchEditableImplAura::Create()) { 753 touch_editable_(TouchEditableImplAura::Create()) {
825 } 754 }
826 755
827 //////////////////////////////////////////////////////////////////////////////// 756 ////////////////////////////////////////////////////////////////////////////////
828 // WebContentsViewAura, private: 757 // WebContentsViewAura, private:
829 758
830 WebContentsViewAura::~WebContentsViewAura() { 759 WebContentsViewAura::~WebContentsViewAura() {
831 if (!window_) 760 if (!window_)
832 return; 761 return;
833 762
834 window_observer_.reset(); 763 bounds_observer_.reset();
835 #if defined(OS_WIN) 764 #if defined(OS_WIN)
836 child_window_observer_.reset(); 765 child_window_observer_.reset();
837 #endif 766 #endif
838 // Window needs a valid delegate during its destructor, so we explicitly 767 // Window needs a valid delegate during its destructor, so we explicitly
839 // delete it here. 768 // delete it here.
840 window_.reset(); 769 window_.reset();
841 } 770 }
842 771
843 void WebContentsViewAura::SetupOverlayWindowForTesting() { 772 void WebContentsViewAura::SetupOverlayWindowForTesting() {
844 if (navigation_overlay_) 773 if (navigation_overlay_)
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 // explicitly add this WebContentsViewAura to their tree after they create 1086 // explicitly add this WebContentsViewAura to their tree after they create
1158 // us. 1087 // us.
1159 if (root_window) { 1088 if (root_window) {
1160 aura::client::ParentWindowWithContext( 1089 aura::client::ParentWindowWithContext(
1161 window_.get(), root_window, root_window->GetBoundsInScreen()); 1090 window_.get(), root_window, root_window->GetBoundsInScreen());
1162 } 1091 }
1163 } 1092 }
1164 window_->layer()->SetMasksToBounds(true); 1093 window_->layer()->SetMasksToBounds(true);
1165 window_->SetName("WebContentsViewAura"); 1094 window_->SetName("WebContentsViewAura");
1166 1095
1167 window_observer_.reset(new WindowObserver(this)); 1096 bounds_observer_.reset(new NativeViewScreenBoundsObserver());
1097 bounds_observer_->Init(this);
1168 #if defined(OS_WIN) 1098 #if defined(OS_WIN)
1169 child_window_observer_.reset(new ChildWindowObserver(this)); 1099 child_window_observer_.reset(new ChildWindowObserver(this));
1170 #endif 1100 #endif
1171 1101
1172 // delegate_->GetDragDestDelegate() creates a new delegate on every call. 1102 // delegate_->GetDragDestDelegate() creates a new delegate on every call.
1173 // Hence, we save a reference to it locally. Similar model is used on other 1103 // Hence, we save a reference to it locally. Similar model is used on other
1174 // platforms as well. 1104 // platforms as well.
1175 if (delegate_) 1105 if (delegate_)
1176 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); 1106 drag_dest_delegate_ = delegate_->GetDragDestDelegate();
1177 } 1107 }
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 web_contents_->GetRenderViewHost()->DragTargetDrop( 1575 web_contents_->GetRenderViewHost()->DragTargetDrop(
1646 event.location(), 1576 event.location(),
1647 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1577 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1648 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1578 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1649 if (drag_dest_delegate_) 1579 if (drag_dest_delegate_)
1650 drag_dest_delegate_->OnDrop(); 1580 drag_dest_delegate_->OnDrop();
1651 current_drop_data_.reset(); 1581 current_drop_data_.reset();
1652 return current_drag_op_; 1582 return current_drag_op_;
1653 } 1583 }
1654 1584
1585 ////////////////////////////////////////////////////////////////////////////////
1586 // WebContentsViewAura, WebContentsViewAuraWindowObserverDelgate implementation:
1587
1588 aura::Window* WebContentsViewAura::GetDelegateWindow() {
1589 return window_.get();
1590 }
1591
1592 void WebContentsViewAura::AddDelegateWindowObserver(
1593 aura::WindowObserver* observer) {
1594 window_->AddObserver(observer);
1595 }
1596
1597 void WebContentsViewAura::RemoveDelegateWindowObserver(
1598 aura::WindowObserver* observer) {
1599 window_->RemoveObserver(observer);
1600 }
1601
1602 void WebContentsViewAura::RemoveRootWindowObserver(
1603 aura::RootWindowObserver* observer) {
1604 if (window_->GetDispatcher())
1605 window_->GetDispatcher()->RemoveRootWindowObserver(observer);
1606 }
1607
1608 void WebContentsViewAura::AddRootWindowObserver(
1609 aura::RootWindowObserver* observer) {
1610 if (window_->GetDispatcher())
1611 window_->GetDispatcher()->AddRootWindowObserver(observer);
1612 }
1613
1614 void WebContentsViewAura::OnScreenPositionChanged() {
1615 RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())->
1616 SendScreenRects();
1617 }
1618
1619 void WebContentsViewAura::OnScreenBoundsChanged() {
1620 RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())->
1621 SendScreenRects();
1622 if (touch_editable_)
1623 touch_editable_->UpdateEditingController();
1624 }
1625
1655 } // namespace content 1626 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698