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