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

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: Experimenting with single observer design Created 7 years 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
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(OS_WIN)
660 if (view_->window_->GetRootWindow())
661 view_->window_->GetRootWindow()->AddObserver(this);
662 #endif
663 }
664
665 virtual ~WindowObserver() {
666 view_->window_->RemoveObserver(this);
667 if (view_->window_->GetDispatcher())
668 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this);
669 if (parent_)
670 parent_->RemoveObserver(this);
671
672 #if defined(OS_WIN)
673 if (parent_) {
674 const aura::Window::Windows& children = parent_->children();
675 for (size_t i = 0; i < children.size(); ++i)
676 children[i]->RemoveObserver(this);
677 }
678
679 aura::Window* root_window = view_->window_->GetRootWindow();
680 if (root_window) {
681 root_window->RemoveObserver(this);
682 const aura::Window::Windows& root_children = root_window->children();
683 for (size_t i = 0; i < root_children.size(); ++i)
684 root_children[i]->RemoveObserver(this);
685 }
686 #endif
687 }
688
689 // Overridden from aura::WindowObserver:
690 #if defined(OS_WIN)
691 // Constrained windows are added as children of the parent's parent's view
692 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV
693 // so that it can update the plugins' cutout rects accordingly.
694 // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is
695 // going to be deprecated in a year, this is ok for now. The test for this is
696 // PrintPreviewTest.WindowedNPAPIPluginHidden.
697 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE {
698 if (new_window == view_->window_)
699 return;
700
701 if (new_window == parent_)
702 return; // This happens if the parent moves to the root window.
703
704 // Observe sibling windows of the WebContents, or children of the root
705 // window.
706 if (new_window->parent() == parent_ ||
707 new_window->parent() == view_->window_->GetRootWindow()) {
708 new_window->AddObserver(this);
709 UpdateConstrainedWindows(NULL);
710 }
711 }
712
713 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE {
714 if (window == view_->window_)
715 return;
716
717 window->RemoveObserver(this);
718 UpdateConstrainedWindows(window);
719 }
720
721 virtual void OnWindowVisibilityChanged(aura::Window* window,
722 bool visible) OVERRIDE {
723 if (window == view_->window_)
724 return;
725
726 if (window->parent() == parent_ ||
727 window->parent() == view_->window_->GetRootWindow()) {
728 UpdateConstrainedWindows(NULL);
729 }
730 }
731 #endif
732
733 virtual void OnWindowParentChanged(aura::Window* window,
734 aura::Window* parent) OVERRIDE {
735 if (window != view_->window_)
736 return;
737 if (parent_)
738 parent_->RemoveObserver(this);
739
740 #if defined(OS_WIN)
741 if (parent_) {
742 const aura::Window::Windows& children = parent_->children();
743 for (size_t i = 0; i < children.size(); ++i)
744 children[i]->RemoveObserver(this);
745
746 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
747 view_->web_contents_->GetRenderWidgetHostView());
748 if (view)
749 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>());
750 }
751
752 // When we get parented to the root window, the code below will watch the
753 // parent, aka root window. Since we already watch the root window on
754 // Windows, unregister first so that the debug check doesn't fire.
755 if (parent && parent == window->GetRootWindow())
756 parent->RemoveObserver(this);
757
758 // We need to undo the above if we were parented to the root window and then
759 // got parented to another window. At that point, the code before the ifdef
760 // would have stopped watching the root window.
761 if (window->GetRootWindow() &&
762 parent != window->GetRootWindow() &&
763 !window->GetRootWindow()->HasObserver(this)) {
764 window->GetRootWindow()->AddObserver(this);
765 }
766 #endif
767
768 parent_ = parent;
769 if (parent) {
770 parent->AddObserver(this);
771 #if defined(OS_WIN)
772 if (parent != window->GetRootWindow()) {
773 const aura::Window::Windows& children = parent->children();
774 for (size_t i = 0; i < children.size(); ++i) {
775 if (children[i] != view_->window_)
776 children[i]->AddObserver(this);
777 }
778 }
779 #endif
780 }
781 }
782
783 virtual void OnWindowBoundsChanged(aura::Window* window,
784 const gfx::Rect& old_bounds,
785 const gfx::Rect& new_bounds) OVERRIDE {
786 if (window == parent_ || window == view_->window_) {
787 SendScreenRects();
788 if (view_->touch_editable_)
789 view_->touch_editable_->UpdateEditingController();
790 #if defined(OS_WIN)
791 } else {
792 UpdateConstrainedWindows(NULL);
793 #endif
794 }
795 }
796
797 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
798 if (window == view_->window_) {
799 window->GetDispatcher()->AddRootWindowObserver(this);
800 #if defined(OS_WIN)
801 if (!window->GetRootWindow()->HasObserver(this))
802 window->GetRootWindow()->AddObserver(this);
803 #endif
804 }
805 }
806
807 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE {
808 if (window == view_->window_) {
809 window->GetDispatcher()->RemoveRootWindowObserver(this);
810 #if defined(OS_WIN)
811 window->GetRootWindow()->RemoveObserver(this);
812
813 const aura::Window::Windows& root_children =
814 window->GetRootWindow()->children();
815 for (size_t i = 0; i < root_children.size(); ++i) {
816 if (root_children[i] != view_->window_ && root_children[i] != parent_)
817 root_children[i]->RemoveObserver(this);
818 }
819 #endif
820 }
821 }
822
823 // Overridden RootWindowObserver:
824 virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
825 const gfx::Point& new_origin) OVERRIDE {
826 TRACE_EVENT1("ui",
827 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved",
828 "new_origin", new_origin.ToString());
829
830 // This is for the desktop case (i.e. Aura desktop).
831 SendScreenRects();
832 }
833
834 private:
835 void SendScreenRects() {
836 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())->
837 SendScreenRects();
838 }
839
840 #if defined(OS_WIN)
841 void UpdateConstrainedWindows(aura::Window* exclude) {
842 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
843 view_->web_contents_->GetRenderWidgetHostView());
844 if (!view)
845 return;
846
847 std::vector<gfx::Rect> constrained_windows;
848 if (parent_) {
849 const aura::Window::Windows& children = parent_->children();
850 for (size_t i = 0; i < children.size(); ++i) {
851 if (children[i] != view_->window_ &&
852 children[i] != exclude &&
853 children[i]->IsVisible()) {
854 constrained_windows.push_back(children[i]->GetBoundsInRootWindow());
855 }
856 }
857 }
858
859 aura::Window* root_window = view_->window_->GetRootWindow();
860 const aura::Window::Windows& root_children = root_window->children();
861 if (root_window) {
862 for (size_t i = 0; i < root_children.size(); ++i) {
863 if (root_children[i]->IsVisible() &&
864 !root_children[i]->Contains(view_->window_.get())) {
865 constrained_windows.push_back(
866 root_children[i]->GetBoundsInRootWindow());
867 }
868 }
869 }
870
871 view->UpdateConstrainedWindowRects(constrained_windows);
872 }
873 #endif
874
875 WebContentsViewAura* view_;
876
877 // We cache the old parent so that we can unregister when it's not the parent
878 // anymore.
879 aura::Window* parent_;
880
881 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
882 };
883
884 //////////////////////////////////////////////////////////////////////////////// 649 ////////////////////////////////////////////////////////////////////////////////
885 // WebContentsViewAura, public: 650 // WebContentsViewAura, public:
886 651
887 WebContentsViewAura::WebContentsViewAura( 652 WebContentsViewAura::WebContentsViewAura(
888 WebContentsImpl* web_contents, 653 WebContentsImpl* web_contents,
889 WebContentsViewDelegate* delegate) 654 WebContentsViewDelegate* delegate)
890 : web_contents_(web_contents), 655 : web_contents_(web_contents),
891 delegate_(delegate), 656 delegate_(delegate),
892 current_drag_op_(blink::WebDragOperationNone), 657 current_drag_op_(blink::WebDragOperationNone),
893 drag_dest_delegate_(NULL), 658 drag_dest_delegate_(NULL),
894 current_rvh_for_drag_(NULL), 659 current_rvh_for_drag_(NULL),
895 overscroll_change_brightness_(false), 660 overscroll_change_brightness_(false),
896 current_overscroll_gesture_(OVERSCROLL_NONE), 661 current_overscroll_gesture_(OVERSCROLL_NONE),
897 completed_overscroll_gesture_(OVERSCROLL_NONE), 662 completed_overscroll_gesture_(OVERSCROLL_NONE),
898 touch_editable_(TouchEditableImplAura::Create()) { 663 touch_editable_(TouchEditableImplAura::Create()) {
899 } 664 }
900 665
901 //////////////////////////////////////////////////////////////////////////////// 666 ////////////////////////////////////////////////////////////////////////////////
902 // WebContentsViewAura, private: 667 // WebContentsViewAura, private:
903 668
904 WebContentsViewAura::~WebContentsViewAura() { 669 WebContentsViewAura::~WebContentsViewAura() {
905 if (!window_) 670 if (!window_)
906 return; 671 return;
907 672
908 window_observer_.reset(); 673 bounds_observer_.reset();
674 #if defined(OS_WIN)
675 constrained_observer_.reset();
676 #endif
909 677
910 // Window needs a valid delegate during its destructor, so we explicitly 678 // Window needs a valid delegate during its destructor, so we explicitly
911 // delete it here. 679 // delete it here.
912 window_.reset(); 680 window_.reset();
913 } 681 }
914 682
915 void WebContentsViewAura::SetupOverlayWindowForTesting() { 683 void WebContentsViewAura::SetupOverlayWindowForTesting() {
916 if (navigation_overlay_) 684 if (navigation_overlay_)
917 navigation_overlay_->SetupForTesting(); 685 navigation_overlay_->SetupForTesting();
918 } 686 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 // explicitly add this WebContentsViewAura to their tree after they create 997 // explicitly add this WebContentsViewAura to their tree after they create
1230 // us. 998 // us.
1231 if (root_window) { 999 if (root_window) {
1232 aura::client::ParentWindowWithContext( 1000 aura::client::ParentWindowWithContext(
1233 window_.get(), root_window, root_window->GetBoundsInScreen()); 1001 window_.get(), root_window, root_window->GetBoundsInScreen());
1234 } 1002 }
1235 } 1003 }
1236 window_->layer()->SetMasksToBounds(true); 1004 window_->layer()->SetMasksToBounds(true);
1237 window_->SetName("WebContentsViewAura"); 1005 window_->SetName("WebContentsViewAura");
1238 1006
1239 // WindowObserver is not interesting and is problematic for Browser Plugin 1007 // The observers are not interesting and is problematic for Browser Plugin
1240 // guests. 1008 // guests.
1241 // The use cases for WindowObserver do not apply to Browser Plugins: 1009 // The use cases for the observers do not apply to Browser Plugins:
1242 // 1) guests do not support NPAPI plugins. 1010 // 1) guests do not support NPAPI plugins.
1243 // 2) guests' window bounds are supposed to come from its embedder. 1011 // 2) guests' window bounds are supposed to come from its embedder.
1244 if (!web_contents_->GetRenderProcessHost()->IsGuest()) 1012 if (!web_contents_->GetRenderProcessHost()->IsGuest()) {
1245 window_observer_.reset(new WindowObserver(this)); 1013 bounds_observer_.reset(new NativeViewScreenBoundsObserver(this,
1014 window_.get()));
1015 #if defined(OS_WIN)
1016 constrained_observer_.reset(new ConstrainedWindowsObserver(this));
1017 #endif
1018 }
1246 1019
1247 // delegate_->GetDragDestDelegate() creates a new delegate on every call. 1020 // delegate_->GetDragDestDelegate() creates a new delegate on every call.
1248 // Hence, we save a reference to it locally. Similar model is used on other 1021 // Hence, we save a reference to it locally. Similar model is used on other
1249 // platforms as well. 1022 // platforms as well.
1250 if (delegate_) 1023 if (delegate_)
1251 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); 1024 drag_dest_delegate_ = delegate_->GetDragDestDelegate();
1252 } 1025 }
1253 1026
1254 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( 1027 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget(
1255 RenderWidgetHost* render_widget_host) { 1028 RenderWidgetHost* render_widget_host) {
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 web_contents_->GetRenderViewHost()->DragTargetDrop( 1493 web_contents_->GetRenderViewHost()->DragTargetDrop(
1721 event.location(), 1494 event.location(),
1722 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1495 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1723 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1496 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1724 if (drag_dest_delegate_) 1497 if (drag_dest_delegate_)
1725 drag_dest_delegate_->OnDrop(); 1498 drag_dest_delegate_->OnDrop();
1726 current_drop_data_.reset(); 1499 current_drop_data_.reset();
1727 return current_drag_op_; 1500 return current_drag_op_;
1728 } 1501 }
1729 1502
1503 ////////////////////////////////////////////////////////////////////////////////
1504 // WebContentsViewAura, NativeViewScreenBoundsObserverDelegate implementation:
1505
1506 void WebContentsViewAura::OnScreenPositionChanged() {
1507 RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())->
1508 SendScreenRects();
1509 }
1510
1511 void WebContentsViewAura::OnScreenBoundsChanged() {
1512 RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())->
1513 SendScreenRects();
1514 if (touch_editable_)
1515 touch_editable_->UpdateEditingController();
1516 }
1517
1730 } // namespace content 1518 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698