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/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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 parent_(NULL) { | 656 parent_(NULL) { |
657 view_->window_->AddObserver(this); | 657 view_->window_->AddObserver(this); |
658 } | 658 } |
659 | 659 |
660 virtual ~WindowObserver() { | 660 virtual ~WindowObserver() { |
661 view_->window_->RemoveObserver(this); | 661 view_->window_->RemoveObserver(this); |
662 if (view_->window_->GetDispatcher()) | 662 if (view_->window_->GetDispatcher()) |
663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); | 663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); |
664 if (parent_) | 664 if (parent_) |
665 parent_->RemoveObserver(this); | 665 parent_->RemoveObserver(this); |
666 | |
667 #if defined(OS_WIN) | |
668 if (parent_) { | |
669 const aura::Window::Windows& children = parent_->children(); | |
670 for (size_t i = 0; i < children.size(); ++i) | |
671 children[i]->RemoveObserver(this); | |
672 } | |
673 #endif | |
666 } | 674 } |
667 | 675 |
668 // Overridden from aura::WindowObserver: | 676 // Overridden from aura::WindowObserver: |
677 #if defined(OS_WIN) | |
678 // Constrained windows are added as children of the parent's parent's view | |
Ben Goodger (Google)
2013/10/30 23:23:43
I'm not sure you want to state this assumption so
jam
2013/10/31 00:07:04
yeah i realize this is a layering violation. ideal
| |
679 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV | |
680 // so that it can update the plugins' cutout rects accordingly. | |
681 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { | |
682 if (new_window->parent() != parent_) | |
683 return; | |
684 | |
685 new_window->AddObserver(this); | |
686 UpdateConstrainedWindows(NULL); | |
687 } | |
688 | |
689 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { | |
690 if (window->parent() == parent_ && window != view_->window_) { | |
691 window->RemoveObserver(this); | |
692 UpdateConstrainedWindows(window); | |
693 } | |
694 } | |
695 | |
696 virtual void OnWindowVisibilityChanged(aura::Window* window, | |
697 bool visible) OVERRIDE { | |
698 if (window->parent() == parent_ && window != view_->window_) | |
699 UpdateConstrainedWindows(NULL); | |
700 } | |
701 #endif | |
702 | |
669 virtual void OnWindowParentChanged(aura::Window* window, | 703 virtual void OnWindowParentChanged(aura::Window* window, |
670 aura::Window* parent) OVERRIDE { | 704 aura::Window* parent) OVERRIDE { |
671 if (window == parent_) | 705 if (window != view_->window_) |
672 return; | 706 return; |
673 if (parent_) | 707 if (parent_) |
674 parent_->RemoveObserver(this); | 708 parent_->RemoveObserver(this); |
709 | |
710 #if defined(OS_WIN) | |
711 if (parent_) { | |
712 const aura::Window::Windows& children = parent_->children(); | |
713 for (size_t i = 0; i < children.size(); ++i) | |
714 children[i]->RemoveObserver(this); | |
715 | |
716 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | |
717 view_->web_contents_->GetRenderWidgetHostView()); | |
718 if (view) | |
719 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); | |
720 } | |
721 #endif | |
722 | |
675 parent_ = parent; | 723 parent_ = parent; |
676 if (parent) | 724 if (parent) |
677 parent->AddObserver(this); | 725 parent->AddObserver(this); |
678 } | 726 } |
679 | 727 |
680 virtual void OnWindowBoundsChanged(aura::Window* window, | 728 virtual void OnWindowBoundsChanged(aura::Window* window, |
681 const gfx::Rect& old_bounds, | 729 const gfx::Rect& old_bounds, |
682 const gfx::Rect& new_bounds) OVERRIDE { | 730 const gfx::Rect& new_bounds) OVERRIDE { |
683 SendScreenRects(); | 731 if (window == parent_ || window == view_->window_) { |
684 if (view_->touch_editable_) | 732 SendScreenRects(); |
685 view_->touch_editable_->UpdateEditingController(); | 733 if (view_->touch_editable_) |
734 view_->touch_editable_->UpdateEditingController(); | |
735 } else { | |
736 UpdateConstrainedWindows(NULL); | |
737 } | |
686 } | 738 } |
687 | 739 |
688 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | 740 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
689 if (window != parent_) | 741 if (window == view_->window_) |
690 window->GetDispatcher()->AddRootWindowObserver(this); | 742 window->GetDispatcher()->AddRootWindowObserver(this); |
691 } | 743 } |
692 | 744 |
693 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { | 745 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { |
694 if (window != parent_) | 746 if (window == view_->window_) |
695 window->GetDispatcher()->RemoveRootWindowObserver(this); | 747 window->GetDispatcher()->RemoveRootWindowObserver(this); |
696 } | 748 } |
697 | 749 |
698 // Overridden RootWindowObserver: | 750 // Overridden RootWindowObserver: |
699 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, | 751 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, |
700 const gfx::Point& new_origin) OVERRIDE { | 752 const gfx::Point& new_origin) OVERRIDE { |
701 // This is for the desktop case (i.e. Aura desktop). | 753 // This is for the desktop case (i.e. Aura desktop). |
702 SendScreenRects(); | 754 SendScreenRects(); |
703 } | 755 } |
704 | 756 |
705 private: | 757 private: |
706 void SendScreenRects() { | 758 void SendScreenRects() { |
707 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> | 759 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> |
708 SendScreenRects(); | 760 SendScreenRects(); |
709 } | 761 } |
710 | 762 |
763 #if defined(OS_WIN) | |
764 void UpdateConstrainedWindows(aura::Window* exclude) { | |
765 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | |
766 view_->web_contents_->GetRenderWidgetHostView()); | |
767 if (!view) | |
768 return; | |
769 | |
770 std::vector<gfx::Rect> constrained_windows; | |
771 const aura::Window::Windows& children = parent_->children(); | |
772 for (size_t i = 0; i < children.size(); ++i) { | |
773 if (children[i] != view_->window_ && | |
774 children[i] != exclude && | |
775 children[i]->IsVisible()) { | |
776 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); | |
777 } | |
778 } | |
779 | |
780 view->UpdateConstrainedWindowRects(constrained_windows); | |
781 } | |
782 #endif | |
783 | |
711 WebContentsViewAura* view_; | 784 WebContentsViewAura* view_; |
712 | 785 |
713 // We cache the old parent so that we can unregister when it's not the parent | 786 // We cache the old parent so that we can unregister when it's not the parent |
714 // anymore. | 787 // anymore. |
715 aura::Window* parent_; | 788 aura::Window* parent_; |
716 | 789 |
717 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 790 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
718 }; | 791 }; |
719 | 792 |
720 #if defined(OS_WIN) | |
721 // 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 | |
723 // can update the plugins' cutout rects accordingly. | |
724 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver, | |
725 public WebContentsObserver { | |
726 public: | |
727 explicit ChildWindowObserver(WebContentsViewAura* view) | |
728 : WebContentsObserver(view->web_contents_), | |
729 view_(view), | |
730 web_contents_destroyed_(false) { | |
731 view_->window_->AddObserver(this); | |
732 } | |
733 | |
734 virtual ~ChildWindowObserver() { | |
735 view_->window_->RemoveObserver(this); | |
736 const aura::Window::Windows& children = view_->window_->children(); | |
737 for (size_t i = 0; i < children.size(); ++i) | |
738 children[i]->RemoveObserver(this); | |
739 } | |
740 | |
741 // Overridden from aura::WindowObserver: | |
742 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { | |
743 // If new child windows are added to the WebContent's view, tell the RWHV. | |
744 // We also start watching them to know when their size is updated. Of | |
745 // course, ignore the shadow window that contains the RWHV and child windows | |
746 // of the child windows that we are watching. | |
747 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | |
748 view_->web_contents_->GetRenderWidgetHostView()); | |
749 aura::Window* content_window = view ? view->GetNativeView() : NULL; | |
750 if (new_window->parent() == view_->window_ && | |
751 new_window != content_window) { | |
752 new_window->AddObserver(this); | |
753 UpdateConstrainedWindows(NULL); | |
754 } | |
755 } | |
756 | |
757 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { | |
758 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | |
759 view_->web_contents_->GetRenderWidgetHostView()); | |
760 aura::Window* content_window = view ? view->GetNativeView() : NULL; | |
761 if (window->parent() == view_->window_ && | |
762 window != content_window) { | |
763 window->RemoveObserver(this); | |
764 UpdateConstrainedWindows(window); | |
765 } | |
766 } | |
767 | |
768 virtual void OnWindowBoundsChanged(aura::Window* window, | |
769 const gfx::Rect& old_bounds, | |
770 const gfx::Rect& new_bounds) OVERRIDE { | |
771 if (window->parent() == view_->window_ && | |
772 window != view_->GetContentNativeView()) { | |
773 UpdateConstrainedWindows(NULL); | |
774 } | |
775 } | |
776 | |
777 // Overridden from WebContentsObserver: | |
778 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { | |
779 web_contents_destroyed_ = true; | |
780 } | |
781 | |
782 private: | |
783 void UpdateConstrainedWindows(aura::Window* exclude) { | |
784 if (web_contents_destroyed_) | |
785 return; | |
786 | |
787 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | |
788 view_->web_contents_->GetRenderWidgetHostView()); | |
789 if (!view) | |
790 return; | |
791 | |
792 std::vector<gfx::Rect> constrained_windows; | |
793 const aura::Window::Windows& children = view_->window_->children(); | |
794 aura::Window* content = view_->GetContentNativeView(); | |
795 for (size_t i = 0; i < children.size(); ++i) { | |
796 if (children[i] != content && children[i] != exclude) | |
797 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); | |
798 } | |
799 | |
800 view->UpdateConstrainedWindowRects(constrained_windows); | |
801 } | |
802 | |
803 WebContentsViewAura* view_; | |
804 bool web_contents_destroyed_; | |
805 | |
806 DISALLOW_COPY_AND_ASSIGN(ChildWindowObserver); | |
807 }; | |
808 #endif | |
809 | |
810 //////////////////////////////////////////////////////////////////////////////// | 793 //////////////////////////////////////////////////////////////////////////////// |
811 // WebContentsViewAura, public: | 794 // WebContentsViewAura, public: |
812 | 795 |
813 WebContentsViewAura::WebContentsViewAura( | 796 WebContentsViewAura::WebContentsViewAura( |
814 WebContentsImpl* web_contents, | 797 WebContentsImpl* web_contents, |
815 WebContentsViewDelegate* delegate) | 798 WebContentsViewDelegate* delegate) |
816 : web_contents_(web_contents), | 799 : web_contents_(web_contents), |
817 delegate_(delegate), | 800 delegate_(delegate), |
818 current_drag_op_(WebKit::WebDragOperationNone), | 801 current_drag_op_(WebKit::WebDragOperationNone), |
819 drag_dest_delegate_(NULL), | 802 drag_dest_delegate_(NULL), |
820 current_rvh_for_drag_(NULL), | 803 current_rvh_for_drag_(NULL), |
821 overscroll_change_brightness_(false), | 804 overscroll_change_brightness_(false), |
822 current_overscroll_gesture_(OVERSCROLL_NONE), | 805 current_overscroll_gesture_(OVERSCROLL_NONE), |
823 completed_overscroll_gesture_(OVERSCROLL_NONE), | 806 completed_overscroll_gesture_(OVERSCROLL_NONE), |
824 touch_editable_(TouchEditableImplAura::Create()) { | 807 touch_editable_(TouchEditableImplAura::Create()) { |
825 } | 808 } |
826 | 809 |
827 //////////////////////////////////////////////////////////////////////////////// | 810 //////////////////////////////////////////////////////////////////////////////// |
828 // WebContentsViewAura, private: | 811 // WebContentsViewAura, private: |
829 | 812 |
830 WebContentsViewAura::~WebContentsViewAura() { | 813 WebContentsViewAura::~WebContentsViewAura() { |
831 if (!window_) | 814 if (!window_) |
832 return; | 815 return; |
833 | 816 |
834 window_observer_.reset(); | 817 window_observer_.reset(); |
835 #if defined(OS_WIN) | 818 |
836 child_window_observer_.reset(); | |
837 #endif | |
838 // Window needs a valid delegate during its destructor, so we explicitly | 819 // Window needs a valid delegate during its destructor, so we explicitly |
839 // delete it here. | 820 // delete it here. |
840 window_.reset(); | 821 window_.reset(); |
841 } | 822 } |
842 | 823 |
843 void WebContentsViewAura::SetupOverlayWindowForTesting() { | 824 void WebContentsViewAura::SetupOverlayWindowForTesting() { |
844 if (navigation_overlay_) | 825 if (navigation_overlay_) |
845 navigation_overlay_->SetupForTesting(); | 826 navigation_overlay_->SetupForTesting(); |
846 } | 827 } |
847 | 828 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1158 // us. | 1139 // us. |
1159 if (root_window) { | 1140 if (root_window) { |
1160 aura::client::ParentWindowWithContext( | 1141 aura::client::ParentWindowWithContext( |
1161 window_.get(), root_window, root_window->GetBoundsInScreen()); | 1142 window_.get(), root_window, root_window->GetBoundsInScreen()); |
1162 } | 1143 } |
1163 } | 1144 } |
1164 window_->layer()->SetMasksToBounds(true); | 1145 window_->layer()->SetMasksToBounds(true); |
1165 window_->SetName("WebContentsViewAura"); | 1146 window_->SetName("WebContentsViewAura"); |
1166 | 1147 |
1167 window_observer_.reset(new WindowObserver(this)); | 1148 window_observer_.reset(new WindowObserver(this)); |
1168 #if defined(OS_WIN) | |
1169 child_window_observer_.reset(new ChildWindowObserver(this)); | |
1170 #endif | |
1171 | 1149 |
1172 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1150 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
1173 // Hence, we save a reference to it locally. Similar model is used on other | 1151 // Hence, we save a reference to it locally. Similar model is used on other |
1174 // platforms as well. | 1152 // platforms as well. |
1175 if (delegate_) | 1153 if (delegate_) |
1176 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1154 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
1177 } | 1155 } |
1178 | 1156 |
1179 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( | 1157 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( |
1180 RenderWidgetHost* render_widget_host) { | 1158 RenderWidgetHost* render_widget_host) { |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1646 event.location(), | 1624 event.location(), |
1647 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1625 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1648 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1626 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1649 if (drag_dest_delegate_) | 1627 if (drag_dest_delegate_) |
1650 drag_dest_delegate_->OnDrop(); | 1628 drag_dest_delegate_->OnDrop(); |
1651 current_drop_data_.reset(); | 1629 current_drop_data_.reset(); |
1652 return current_drag_op_; | 1630 return current_drag_op_; |
1653 } | 1631 } |
1654 | 1632 |
1655 } // namespace content | 1633 } // namespace content |
OLD | NEW |