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 25 matching lines...) Expand all Loading... | |
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 Loading... | |
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 #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 | |
674 } | |
675 | |
676 // Overridden from aura::WindowObserver: | |
677 #if defined(OS_WIN) | |
678 // Constrained windows are added as children of the parent's parent's view | |
rharrison
2013/11/20 16:40:55
jam, are the views that are of concern here being
| |
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. The test for this is | |
683 // PrintPreviewTest.WindowedNPAPIPluginHidden. | |
684 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { | |
685 if (new_window->parent() != parent_) | |
686 return; | |
687 | |
688 new_window->AddObserver(this); | |
689 UpdateConstrainedWindows(NULL); | |
690 } | |
691 | |
692 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { | |
693 if (window->parent() == parent_ && window != view_->window_) { | |
694 window->RemoveObserver(this); | |
695 UpdateConstrainedWindows(window); | |
696 } | |
697 } | |
698 | |
699 virtual void OnWindowVisibilityChanged(aura::Window* window, | |
700 bool visible) OVERRIDE { | |
701 if (window->parent() == parent_ && window != view_->window_) | |
702 UpdateConstrainedWindows(NULL); | |
703 } | |
704 #endif | |
705 | |
706 virtual void OnWindowParentChanged(aura::Window* window, | |
707 aura::Window* parent) OVERRIDE { | |
708 if (window != view_->window_) | |
709 return; | |
710 if (parent_) | |
711 parent_->RemoveObserver(this); | |
712 | |
713 #if defined(OS_WIN) | |
714 if (parent_) { | |
715 const aura::Window::Windows& children = parent_->children(); | |
716 for (size_t i = 0; i < children.size(); ++i) | |
717 children[i]->RemoveObserver(this); | |
718 | |
719 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | |
720 view_->web_contents_->GetRenderWidgetHostView()); | |
721 if (view) | |
722 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); | |
723 } | |
724 #endif | |
725 | |
726 parent_ = parent; | |
727 if (parent) { | |
728 parent->AddObserver(this); | |
729 #if defined(OS_WIN) | |
730 const aura::Window::Windows& children = parent_->children(); | |
731 for (size_t i = 0; i < children.size(); ++i) { | |
732 if (children[i] != view_->window_) | |
733 children[i]->AddObserver(this); | |
734 } | |
735 #endif | |
736 } | |
737 } | |
738 | |
739 virtual void OnWindowBoundsChanged(aura::Window* window, | |
740 const gfx::Rect& old_bounds, | |
741 const gfx::Rect& new_bounds) OVERRIDE { | |
742 if (window == parent_ || window == view_->window_) { | |
743 SendScreenRects(); | |
744 if (view_->touch_editable_) | |
745 view_->touch_editable_->UpdateEditingController(); | |
746 #if defined(OS_WIN) | |
747 } else { | |
748 UpdateConstrainedWindows(NULL); | |
749 #endif | |
750 } | |
751 } | |
752 | |
753 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | |
754 if (window == view_->window_) | |
755 window->GetDispatcher()->AddRootWindowObserver(this); | |
756 } | |
757 | |
758 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { | |
759 if (window == view_->window_) | |
760 window->GetDispatcher()->RemoveRootWindowObserver(this); | |
761 } | |
762 | |
763 // Overridden RootWindowObserver: | |
764 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, | |
765 const gfx::Point& new_origin) OVERRIDE { | |
766 TRACE_EVENT1("ui", | |
767 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved", | |
768 "new_origin", new_origin.ToString()); | |
769 | |
770 // This is for the desktop case (i.e. Aura desktop). | |
771 SendScreenRects(); | |
772 } | |
773 | |
774 private: | |
775 void SendScreenRects() { | |
776 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> | |
777 SendScreenRects(); | |
778 } | |
779 | |
780 #if defined(OS_WIN) | |
781 void UpdateConstrainedWindows(aura::Window* exclude) { | |
782 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | |
783 view_->web_contents_->GetRenderWidgetHostView()); | |
784 if (!view) | |
785 return; | |
786 | |
787 std::vector<gfx::Rect> constrained_windows; | |
788 const aura::Window::Windows& children = parent_->children(); | |
789 for (size_t i = 0; i < children.size(); ++i) { | |
790 if (children[i] != view_->window_ && | |
791 children[i] != exclude && | |
792 children[i]->IsVisible()) { | |
793 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); | |
794 } | |
795 } | |
796 | |
797 view->UpdateConstrainedWindowRects(constrained_windows); | |
798 } | |
799 #endif | |
800 | |
801 WebContentsViewAura* view_; | |
802 | |
803 // We cache the old parent so that we can unregister when it's not the parent | |
804 // anymore. | |
805 aura::Window* parent_; | |
806 | |
807 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | |
808 }; | |
809 | |
810 //////////////////////////////////////////////////////////////////////////////// | 649 //////////////////////////////////////////////////////////////////////////////// |
811 // WebContentsViewAura, public: | 650 // WebContentsViewAura, public: |
812 | 651 |
813 WebContentsViewAura::WebContentsViewAura( | 652 WebContentsViewAura::WebContentsViewAura( |
814 WebContentsImpl* web_contents, | 653 WebContentsImpl* web_contents, |
815 WebContentsViewDelegate* delegate) | 654 WebContentsViewDelegate* delegate) |
816 : web_contents_(web_contents), | 655 : web_contents_(web_contents), |
817 delegate_(delegate), | 656 delegate_(delegate), |
818 current_drag_op_(blink::WebDragOperationNone), | 657 current_drag_op_(blink::WebDragOperationNone), |
819 drag_dest_delegate_(NULL), | 658 drag_dest_delegate_(NULL), |
820 current_rvh_for_drag_(NULL), | 659 current_rvh_for_drag_(NULL), |
821 overscroll_change_brightness_(false), | 660 overscroll_change_brightness_(false), |
822 current_overscroll_gesture_(OVERSCROLL_NONE), | 661 current_overscroll_gesture_(OVERSCROLL_NONE), |
823 completed_overscroll_gesture_(OVERSCROLL_NONE), | 662 completed_overscroll_gesture_(OVERSCROLL_NONE), |
824 touch_editable_(TouchEditableImplAura::Create()) { | 663 touch_editable_(TouchEditableImplAura::Create()) { |
825 } | 664 } |
826 | 665 |
827 //////////////////////////////////////////////////////////////////////////////// | 666 //////////////////////////////////////////////////////////////////////////////// |
828 // WebContentsViewAura, private: | 667 // WebContentsViewAura, private: |
829 | 668 |
830 WebContentsViewAura::~WebContentsViewAura() { | 669 WebContentsViewAura::~WebContentsViewAura() { |
831 if (!window_) | 670 if (!window_) |
832 return; | 671 return; |
833 | 672 |
834 window_observer_.reset(); | 673 bounds_observer_.reset(); |
835 | 674 |
836 // Window needs a valid delegate during its destructor, so we explicitly | 675 // Window needs a valid delegate during its destructor, so we explicitly |
837 // delete it here. | 676 // delete it here. |
838 window_.reset(); | 677 window_.reset(); |
839 } | 678 } |
840 | 679 |
841 void WebContentsViewAura::SetupOverlayWindowForTesting() { | 680 void WebContentsViewAura::SetupOverlayWindowForTesting() { |
842 if (navigation_overlay_) | 681 if (navigation_overlay_) |
843 navigation_overlay_->SetupForTesting(); | 682 navigation_overlay_->SetupForTesting(); |
844 } | 683 } |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 // explicitly add this WebContentsViewAura to their tree after they create | 994 // explicitly add this WebContentsViewAura to their tree after they create |
1156 // us. | 995 // us. |
1157 if (root_window) { | 996 if (root_window) { |
1158 aura::client::ParentWindowWithContext( | 997 aura::client::ParentWindowWithContext( |
1159 window_.get(), root_window, root_window->GetBoundsInScreen()); | 998 window_.get(), root_window, root_window->GetBoundsInScreen()); |
1160 } | 999 } |
1161 } | 1000 } |
1162 window_->layer()->SetMasksToBounds(true); | 1001 window_->layer()->SetMasksToBounds(true); |
1163 window_->SetName("WebContentsViewAura"); | 1002 window_->SetName("WebContentsViewAura"); |
1164 | 1003 |
1165 window_observer_.reset(new WindowObserver(this)); | 1004 bounds_observer_.reset(new NativeViewScreenBoundsObserver(this, |
1005 window_.get())); | |
1006 | |
1007 #if defined(OS_WIN) | |
1008 constrained_observer_.reset(new ConstrainedWindowsObserver(this)); | |
1009 #endif | |
1166 | 1010 |
1167 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1011 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
1168 // Hence, we save a reference to it locally. Similar model is used on other | 1012 // Hence, we save a reference to it locally. Similar model is used on other |
1169 // platforms as well. | 1013 // platforms as well. |
1170 if (delegate_) | 1014 if (delegate_) |
1171 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1015 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
1172 } | 1016 } |
1173 | 1017 |
1174 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( | 1018 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( |
1175 RenderWidgetHost* render_widget_host) { | 1019 RenderWidgetHost* render_widget_host) { |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 web_contents_->GetRenderViewHost()->DragTargetDrop( | 1484 web_contents_->GetRenderViewHost()->DragTargetDrop( |
1641 event.location(), | 1485 event.location(), |
1642 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1486 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1643 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1487 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1644 if (drag_dest_delegate_) | 1488 if (drag_dest_delegate_) |
1645 drag_dest_delegate_->OnDrop(); | 1489 drag_dest_delegate_->OnDrop(); |
1646 current_drop_data_.reset(); | 1490 current_drop_data_.reset(); |
1647 return current_drag_op_; | 1491 return current_drag_op_; |
1648 } | 1492 } |
1649 | 1493 |
1494 //////////////////////////////////////////////////////////////////////////////// | |
1495 // WebContentsViewAura, NativeViewScreenBoundsObserverDelegate implementation: | |
1496 | |
1497 void WebContentsViewAura::OnScreenPositionChanged() { | |
1498 RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())-> | |
1499 SendScreenRects(); | |
1500 } | |
1501 | |
1502 void WebContentsViewAura::OnScreenBoundsChanged() { | |
1503 RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())-> | |
1504 SendScreenRects(); | |
1505 if (touch_editable_) | |
1506 touch_editable_->UpdateEditingController(); | |
1507 } | |
1508 | |
1650 } // namespace content | 1509 } // namespace content |
OLD | NEW |