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/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 12 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
13 #include "content/browser/download/drag_download_util.h" | 13 #include "content/browser/download/drag_download_util.h" |
14 #include "content/browser/frame_host/interstitial_page_impl.h" | 14 #include "content/browser/frame_host/interstitial_page_impl.h" |
15 #include "content/browser/frame_host/navigation_entry_impl.h" | 15 #include "content/browser/frame_host/navigation_entry_impl.h" |
16 #include "content/browser/renderer_host/dip_util.h" | 16 #include "content/browser/renderer_host/dip_util.h" |
17 #include "content/browser/renderer_host/overscroll_controller.h" | 17 #include "content/browser/renderer_host/overscroll_controller.h" |
18 #include "content/browser/renderer_host/render_view_host_factory.h" | 18 #include "content/browser/renderer_host/render_view_host_factory.h" |
19 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
20 #include "content/browser/renderer_host/render_widget_host_impl.h" | 20 #include "content/browser/renderer_host/render_widget_host_impl.h" |
21 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 21 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
22 #include "content/browser/renderer_host/web_input_event_aura.h" | 22 #include "content/browser/renderer_host/web_input_event_aura.h" |
23 #include "content/browser/web_contents/aura/gesture_nav_simple.h" | 23 #include "content/browser/web_contents/aura/gesture_nav_simple.h" |
24 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" | 24 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" |
25 #include "content/browser/web_contents/aura/shadow_layer_delegate.h" | 25 #include "content/browser/web_contents/aura/overscroll_window_animation.h" |
26 #include "content/browser/web_contents/aura/window_slider.h" | 26 #include "content/browser/web_contents/aura/window_slider.h" |
27 #include "content/browser/web_contents/touch_editable_impl_aura.h" | 27 #include "content/browser/web_contents/touch_editable_impl_aura.h" |
28 #include "content/browser/web_contents/web_contents_impl.h" | 28 #include "content/browser/web_contents/web_contents_impl.h" |
29 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
30 #include "content/public/browser/notification_observer.h" | 30 #include "content/public/browser/notification_observer.h" |
31 #include "content/public/browser/notification_registrar.h" | 31 #include "content/public/browser/notification_registrar.h" |
32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
33 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
34 #include "content/public/browser/overscroll_configuration.h" | 34 #include "content/public/browser/overscroll_configuration.h" |
35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
53 #include "ui/aura/window_tree_host_observer.h" | 53 #include "ui/aura/window_tree_host_observer.h" |
54 #include "ui/aura_extra/image_window_delegate.h" | 54 #include "ui/aura_extra/image_window_delegate.h" |
55 #include "ui/base/clipboard/clipboard.h" | 55 #include "ui/base/clipboard/clipboard.h" |
56 #include "ui/base/clipboard/custom_data_helper.h" | 56 #include "ui/base/clipboard/custom_data_helper.h" |
57 #include "ui/base/dragdrop/drag_drop_types.h" | 57 #include "ui/base/dragdrop/drag_drop_types.h" |
58 #include "ui/base/dragdrop/drag_utils.h" | 58 #include "ui/base/dragdrop/drag_utils.h" |
59 #include "ui/base/dragdrop/drop_target_event.h" | 59 #include "ui/base/dragdrop/drop_target_event.h" |
60 #include "ui/base/dragdrop/os_exchange_data.h" | 60 #include "ui/base/dragdrop/os_exchange_data.h" |
61 #include "ui/base/hit_test.h" | 61 #include "ui/base/hit_test.h" |
62 #include "ui/compositor/layer.h" | 62 #include "ui/compositor/layer.h" |
63 #include "ui/compositor/scoped_layer_animation_settings.h" | |
64 #include "ui/events/event.h" | 63 #include "ui/events/event.h" |
65 #include "ui/events/event_utils.h" | 64 #include "ui/events/event_utils.h" |
66 #include "ui/gfx/canvas.h" | 65 #include "ui/gfx/canvas.h" |
67 #include "ui/gfx/image/image.h" | 66 #include "ui/gfx/image/image.h" |
68 #include "ui/gfx/image/image_png_rep.h" | 67 #include "ui/gfx/image/image_png_rep.h" |
69 #include "ui/gfx/image/image_skia.h" | 68 #include "ui/gfx/image/image_skia.h" |
70 #include "ui/gfx/screen.h" | 69 #include "ui/gfx/screen.h" |
71 #include "ui/wm/public/drag_drop_client.h" | 70 #include "ui/wm/public/drag_drop_client.h" |
72 #include "ui/wm/public/drag_drop_delegate.h" | 71 #include "ui/wm/public/drag_drop_delegate.h" |
73 | 72 |
74 namespace content { | 73 namespace content { |
75 WebContentsView* CreateWebContentsView( | 74 WebContentsView* CreateWebContentsView( |
76 WebContentsImpl* web_contents, | 75 WebContentsImpl* web_contents, |
77 WebContentsViewDelegate* delegate, | 76 WebContentsViewDelegate* delegate, |
78 RenderViewHostDelegateView** render_view_host_delegate_view) { | 77 RenderViewHostDelegateView** render_view_host_delegate_view) { |
79 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 78 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
80 *render_view_host_delegate_view = rv; | 79 *render_view_host_delegate_view = rv; |
81 return rv; | 80 return rv; |
82 } | 81 } |
83 | 82 |
84 namespace { | 83 namespace { |
85 | 84 |
86 bool IsScrollEndEffectEnabled() { | 85 bool IsScrollEndEffectEnabled() { |
87 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 86 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
88 switches::kScrollEndEffect) == "1"; | 87 switches::kScrollEndEffect) == "1"; |
89 } | 88 } |
90 | 89 |
91 bool ShouldNavigateForward(const NavigationController& controller, | |
92 OverscrollMode mode) { | |
93 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && | |
94 controller.CanGoForward(); | |
95 } | |
96 | |
97 bool ShouldNavigateBack(const NavigationController& controller, | |
98 OverscrollMode mode) { | |
99 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && | |
100 controller.CanGoBack(); | |
101 } | |
102 | |
103 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( | 90 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( |
104 RenderWidgetHostView* view) { | 91 RenderWidgetHostView* view) { |
105 if (!view || RenderViewHostFactory::has_factory()) | 92 if (!view || RenderViewHostFactory::has_factory()) |
106 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. | 93 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. |
107 | 94 |
108 RenderViewHost* rvh = RenderViewHost::From(view->GetRenderWidgetHost()); | 95 RenderViewHost* rvh = RenderViewHost::From(view->GetRenderWidgetHost()); |
109 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 96 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
110 rvh ? WebContents::FromRenderViewHost(rvh) : NULL); | 97 rvh ? WebContents::FromRenderViewHost(rvh) : NULL); |
111 if (BrowserPluginGuest::IsGuest(web_contents)) | 98 if (BrowserPluginGuest::IsGuest(web_contents)) |
112 return NULL; | 99 return NULL; |
113 return static_cast<RenderWidgetHostViewAura*>(view); | 100 return static_cast<RenderWidgetHostViewAura*>(view); |
114 } | 101 } |
115 | 102 |
116 // The window delegate for the overscroll window. This redirects trackpad events | |
117 // to the web-contents window. The delegate destroys itself when the window is | |
118 // destroyed. | |
119 class OverscrollWindowDelegate : public aura_extra::ImageWindowDelegate { | |
120 public: | |
121 OverscrollWindowDelegate(WebContentsImpl* web_contents, | |
122 OverscrollMode overscroll_mode) | |
123 : web_contents_(web_contents), | |
124 forward_events_(true) { | |
125 const NavigationControllerImpl& controller = web_contents->GetController(); | |
126 const NavigationEntryImpl* entry = NULL; | |
127 if (ShouldNavigateForward(controller, overscroll_mode)) { | |
128 entry = controller.GetEntryAtOffset(1); | |
129 } else if (ShouldNavigateBack(controller, overscroll_mode)) { | |
130 entry = controller.GetEntryAtOffset(-1); | |
131 } | |
132 | |
133 gfx::Image image; | |
134 if (entry && entry->screenshot().get()) { | |
135 std::vector<gfx::ImagePNGRep> image_reps; | |
136 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); | |
137 image = gfx::Image(image_reps); | |
138 } | |
139 SetImage(image); | |
140 } | |
141 | |
142 void stop_forwarding_events() { forward_events_ = false; } | |
143 | |
144 private: | |
145 ~OverscrollWindowDelegate() override {} | |
146 | |
147 aura::Window* web_contents_window() { | |
148 return web_contents_->GetView()->GetContentNativeView(); | |
149 } | |
150 | |
151 // Overridden from ui::EventHandler. | |
152 void OnScrollEvent(ui::ScrollEvent* event) override { | |
153 if (forward_events_ && web_contents_window()) | |
154 web_contents_window()->delegate()->OnScrollEvent(event); | |
155 } | |
156 | |
157 void OnGestureEvent(ui::GestureEvent* event) override { | |
158 if (forward_events_ && web_contents_window()) | |
159 web_contents_window()->delegate()->OnGestureEvent(event); | |
160 } | |
161 | |
162 WebContentsImpl* web_contents_; | |
163 | |
164 // The window is displayed both during the gesture, and after the gesture | |
165 // while the navigation is in progress. During the gesture, it is necessary to | |
166 // forward input events to the content page (e.g. when the overscroll window | |
167 // slides under the cursor and starts receiving scroll events). However, once | |
168 // the gesture is complete, and the window is being displayed as an overlay | |
169 // window during navigation, events should not be forwarded anymore. | |
170 bool forward_events_; | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate); | |
173 }; | |
174 | |
175 // Listens to all mouse drag events during a drag and drop and sends them to | 103 // Listens to all mouse drag events during a drag and drop and sends them to |
176 // the renderer. | 104 // the renderer. |
177 class WebDragSourceAura : public NotificationObserver { | 105 class WebDragSourceAura : public NotificationObserver { |
178 public: | 106 public: |
179 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) | 107 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) |
180 : window_(window), | 108 : window_(window), |
181 contents_(contents) { | 109 contents_(contents) { |
182 registrar_.Add(this, | 110 registrar_.Add(this, |
183 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 111 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
184 Source<WebContents>(contents)); | 112 Source<WebContents>(contents)); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 // The parent window that hosts the constrained windows. We cache the old host | 646 // The parent window that hosts the constrained windows. We cache the old host |
719 // view so that we can unregister when it's not the parent anymore. | 647 // view so that we can unregister when it's not the parent anymore. |
720 aura::Window* host_window_; | 648 aura::Window* host_window_; |
721 | 649 |
722 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 650 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
723 }; | 651 }; |
724 | 652 |
725 //////////////////////////////////////////////////////////////////////////////// | 653 //////////////////////////////////////////////////////////////////////////////// |
726 // WebContentsViewAura, public: | 654 // WebContentsViewAura, public: |
727 | 655 |
728 WebContentsViewAura::WebContentsViewAura( | 656 WebContentsViewAura::WebContentsViewAura(WebContentsImpl* web_contents, |
729 WebContentsImpl* web_contents, | 657 WebContentsViewDelegate* delegate) |
730 WebContentsViewDelegate* delegate) | |
731 : web_contents_(web_contents), | 658 : web_contents_(web_contents), |
732 delegate_(delegate), | 659 delegate_(delegate), |
733 current_drag_op_(blink::WebDragOperationNone), | 660 current_drag_op_(blink::WebDragOperationNone), |
734 drag_dest_delegate_(NULL), | 661 drag_dest_delegate_(NULL), |
735 current_rvh_for_drag_(NULL), | 662 current_rvh_for_drag_(NULL), |
736 overscroll_change_brightness_(false), | |
737 current_overscroll_gesture_(OVERSCROLL_NONE), | 663 current_overscroll_gesture_(OVERSCROLL_NONE), |
738 completed_overscroll_gesture_(OVERSCROLL_NONE), | 664 completed_overscroll_gesture_(OVERSCROLL_NONE), |
665 navigation_overlay_(nullptr), | |
666 overscroll_window_animation_(nullptr), | |
739 touch_editable_(TouchEditableImplAura::Create()), | 667 touch_editable_(TouchEditableImplAura::Create()), |
740 is_or_was_visible_(false) { | 668 is_or_was_visible_(false) { |
741 } | 669 } |
742 | 670 |
743 //////////////////////////////////////////////////////////////////////////////// | 671 //////////////////////////////////////////////////////////////////////////////// |
744 // WebContentsViewAura, private: | 672 // WebContentsViewAura, private: |
745 | 673 |
746 WebContentsViewAura::~WebContentsViewAura() { | 674 WebContentsViewAura::~WebContentsViewAura() { |
747 if (!window_) | 675 if (!window_) |
748 return; | 676 return; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
783 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(), | 711 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(), |
784 screen_loc.x(), screen_loc.y(), ops); | 712 screen_loc.x(), screen_loc.y(), ops); |
785 } | 713 } |
786 | 714 |
787 void WebContentsViewAura::InstallOverscrollControllerDelegate( | 715 void WebContentsViewAura::InstallOverscrollControllerDelegate( |
788 RenderWidgetHostViewAura* view) { | 716 RenderWidgetHostViewAura* view) { |
789 const std::string value = base::CommandLine::ForCurrentProcess()-> | 717 const std::string value = base::CommandLine::ForCurrentProcess()-> |
790 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); | 718 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); |
791 if (value == "0") { | 719 if (value == "0") { |
792 navigation_overlay_.reset(); | 720 navigation_overlay_.reset(); |
721 overscroll_window_animation_.reset(); | |
793 return; | 722 return; |
794 } | 723 } |
795 if (value == "2") { | 724 if (value == "2") { |
796 navigation_overlay_.reset(); | 725 navigation_overlay_.reset(); |
mfomitchev
2015/03/10 19:26:00
overscroll_window_animation_.reset()
Nina
2015/03/12 22:21:29
Not needed anymore.
| |
797 if (!gesture_nav_simple_) | 726 if (!gesture_nav_simple_) |
798 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_)); | 727 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_)); |
799 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get()); | 728 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get()); |
800 return; | 729 return; |
801 } | 730 } |
802 view->overscroll_controller()->set_delegate(this); | 731 view->overscroll_controller()->set_delegate(this); |
803 if (!navigation_overlay_) | 732 if (!navigation_overlay_) { |
804 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); | 733 navigation_overlay_.reset( |
805 } | 734 new OverscrollNavigationOverlay(web_contents_, window_.get())); |
806 | |
807 void WebContentsViewAura::PrepareOverscrollWindow() { | |
808 // If there is an existing |overscroll_window_| which is in the middle of an | |
809 // animation, then destroying the window here causes the animation to be | |
810 // completed immediately, which triggers |OnImplicitAnimationsCompleted()| | |
811 // callback, and that tries to reset |overscroll_window_| again, causing a | |
812 // double-free. So use a temporary variable here. | |
813 if (overscroll_window_) { | |
814 base::AutoReset<OverscrollMode> reset_state(¤t_overscroll_gesture_, | |
815 current_overscroll_gesture_); | |
816 scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); | |
817 } | |
818 | |
819 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( | |
820 web_contents_, | |
821 current_overscroll_gesture_); | |
822 overscroll_window_.reset(new aura::Window(overscroll_delegate)); | |
823 overscroll_window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | |
824 overscroll_window_->SetTransparent(true); | |
825 overscroll_window_->Init(aura::WINDOW_LAYER_TEXTURED); | |
826 overscroll_window_->layer()->SetMasksToBounds(false); | |
827 overscroll_window_->SetName("OverscrollOverlay"); | |
828 | |
829 overscroll_change_brightness_ = overscroll_delegate->has_image(); | |
830 window_->AddChild(overscroll_window_.get()); | |
831 | |
832 gfx::Rect bounds = gfx::Rect(window_->bounds().size()); | |
833 if (ShouldNavigateForward(web_contents_->GetController(), | |
834 current_overscroll_gesture_)) { | |
835 // The overlay will be sliding in from the right edge towards the left in | |
836 // non-RTL, or sliding in from the left edge towards the right in RTL. | |
837 // So position the overlay window accordingly. | |
838 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0); | |
839 } | |
840 | |
841 aura::Window* animate_window = GetWindowToAnimateForOverscroll(); | |
842 if (animate_window == overscroll_window_) | |
843 window_->StackChildAbove(overscroll_window_.get(), GetContentNativeView()); | |
844 else | |
845 window_->StackChildBelow(overscroll_window_.get(), GetContentNativeView()); | |
846 | |
847 UpdateOverscrollWindowBrightness(0.f); | |
848 | |
849 overscroll_window_->SetBounds(bounds); | |
850 overscroll_window_->Show(); | |
851 | |
852 overscroll_shadow_.reset(new ShadowLayerDelegate(animate_window->layer())); | |
853 } | |
854 | |
855 void WebContentsViewAura::PrepareContentWindowForOverscroll() { | |
856 StopObservingImplicitAnimations(); | |
857 aura::Window* content = GetContentNativeView(); | |
858 content->layer()->GetAnimator()->AbortAllAnimations(); | |
859 content->SetTransform(gfx::Transform()); | |
860 content->layer()->SetLayerBrightness(0.f); | |
861 } | |
862 | |
863 void WebContentsViewAura::ResetOverscrollTransform() { | |
864 if (!web_contents_->GetRenderWidgetHostView()) | |
865 return; | |
866 aura::Window* target = GetWindowToAnimateForOverscroll(); | |
867 if (!target) | |
868 return; | |
869 { | |
870 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator()); | |
871 settings.SetPreemptionStrategy( | |
872 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
873 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
874 settings.AddObserver(this); | |
875 target->SetTransform(gfx::Transform()); | |
876 } | |
877 { | |
878 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator()); | |
879 settings.SetPreemptionStrategy( | |
880 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
881 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
882 UpdateOverscrollWindowBrightness(0.f); | |
883 } | 735 } |
884 } | 736 } |
885 | 737 |
886 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) { | 738 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) { |
887 if (!web_contents_->GetRenderWidgetHostView()) | 739 if (!web_contents_->GetRenderWidgetHostView()) |
888 return; | 740 return; |
889 | 741 |
890 // Animate out the current view first. Navigate to the requested history at | |
891 // the end of the animation. | |
892 if (current_overscroll_gesture_ == OVERSCROLL_NONE) | |
893 return; | |
894 | |
895 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated", | 742 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated", |
896 current_overscroll_gesture_, OVERSCROLL_COUNT); | 743 current_overscroll_gesture_, OVERSCROLL_COUNT); |
897 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( | |
898 overscroll_window_->delegate()); | |
899 delegate->stop_forwarding_events(); | |
900 | 744 |
901 completed_overscroll_gesture_ = mode; | 745 overscroll_window_animation_->OnOverscrollComplete(mode); |
902 aura::Window* target = GetWindowToAnimateForOverscroll(); | |
903 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator()); | |
904 settings.SetPreemptionStrategy( | |
905 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
906 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
907 settings.AddObserver(this); | |
908 gfx::Transform transform; | |
909 int content_width = | |
910 web_contents_->GetRenderWidgetHostView()->GetViewBounds().width(); | |
911 float translate_x = static_cast<float>(mode == OVERSCROLL_WEST ? | |
912 -content_width : content_width); | |
913 transform.Translate(translate_x, 0); | |
914 target->SetTransform(transform); | |
915 UpdateOverscrollWindowBrightness(translate_x); | |
916 } | |
917 | |
918 aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() { | |
919 if (current_overscroll_gesture_ == OVERSCROLL_NONE) | |
920 return NULL; | |
921 | |
922 return ShouldNavigateForward(web_contents_->GetController(), | |
923 current_overscroll_gesture_) ? | |
924 overscroll_window_.get() : GetContentNativeView(); | |
925 } | |
926 | |
927 gfx::Vector2dF WebContentsViewAura::GetTranslationForOverscroll(float delta_x, | |
928 float delta_y) { | |
929 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || | |
930 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { | |
931 return gfx::Vector2dF(0, delta_y); | |
932 } | |
933 // For horizontal overscroll, scroll freely if a navigation is possible. Do a | |
934 // resistive scroll otherwise. | |
935 const NavigationControllerImpl& controller = web_contents_->GetController(); | |
936 const gfx::Rect& bounds = GetViewBounds(); | |
937 const float bounds_width = static_cast<float>(bounds.width()); | |
938 if (ShouldNavigateForward(controller, current_overscroll_gesture_)) | |
939 return gfx::Vector2dF(std::max(-bounds_width, delta_x), 0); | |
940 else if (ShouldNavigateBack(controller, current_overscroll_gesture_)) | |
941 return gfx::Vector2dF(std::min(bounds_width, delta_x), 0); | |
942 return gfx::Vector2dF(); | |
943 } | |
944 | |
945 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() { | |
946 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( | |
947 overscroll_window_->delegate()); | |
948 overscroll_window_->SchedulePaintInRect( | |
949 gfx::Rect(overscroll_window_->bounds().size())); | |
950 overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size())); | |
951 overscroll_window_->SetTransform(gfx::Transform()); | |
952 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(), | |
953 delegate); | |
954 navigation_overlay_->StartObserving(); | |
955 } | |
956 | |
957 void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) { | |
958 if (!overscroll_change_brightness_) | |
959 return; | |
960 | |
961 const float kBrightnessMin = -.1f; | |
962 const float kBrightnessMax = -.01f; | |
963 | |
964 float ratio = fabs(delta_x) / GetViewBounds().width(); | |
965 ratio = std::min(1.f, ratio); | |
966 if (base::i18n::IsRTL()) | |
967 ratio = 1.f - ratio; | |
968 float brightness = current_overscroll_gesture_ == OVERSCROLL_WEST ? | |
969 kBrightnessMin + ratio * (kBrightnessMax - kBrightnessMin) : | |
970 kBrightnessMax - ratio * (kBrightnessMax - kBrightnessMin); | |
971 brightness = std::max(kBrightnessMin, brightness); | |
972 brightness = std::min(kBrightnessMax, brightness); | |
973 aura::Window* window = GetWindowToAnimateForOverscroll(); | |
974 window->layer()->SetLayerBrightness(brightness); | |
975 } | 746 } |
976 | 747 |
977 void WebContentsViewAura::AttachTouchEditableToRenderView() { | 748 void WebContentsViewAura::AttachTouchEditableToRenderView() { |
978 if (!touch_editable_) | 749 if (!touch_editable_) |
979 return; | 750 return; |
980 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( | 751 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( |
981 web_contents_->GetRenderWidgetHostView()); | 752 web_contents_->GetRenderWidgetHostView()); |
982 touch_editable_->AttachToView(rwhva); | 753 touch_editable_->AttachToView(rwhva); |
983 } | 754 } |
984 | 755 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 DCHECK(RenderViewHostFactory::has_factory()); | 894 DCHECK(RenderViewHostFactory::has_factory()); |
1124 return static_cast<RenderWidgetHostViewBase*>( | 895 return static_cast<RenderWidgetHostViewBase*>( |
1125 render_widget_host->GetView()); | 896 render_widget_host->GetView()); |
1126 } | 897 } |
1127 | 898 |
1128 RenderWidgetHostViewAura* view = | 899 RenderWidgetHostViewAura* view = |
1129 new RenderWidgetHostViewAura(render_widget_host, is_guest_view_hack); | 900 new RenderWidgetHostViewAura(render_widget_host, is_guest_view_hack); |
1130 view->InitAsChild(NULL); | 901 view->InitAsChild(NULL); |
1131 GetNativeView()->AddChild(view->GetNativeView()); | 902 GetNativeView()->AddChild(view->GetNativeView()); |
1132 | 903 |
1133 if (navigation_overlay_.get() && navigation_overlay_->has_window()) { | |
1134 navigation_overlay_->StartObserving(); | |
1135 } | |
1136 | |
1137 RenderWidgetHostImpl* host_impl = | 904 RenderWidgetHostImpl* host_impl = |
1138 RenderWidgetHostImpl::From(render_widget_host); | 905 RenderWidgetHostImpl::From(render_widget_host); |
1139 | 906 |
1140 if (!host_impl->is_hidden()) | 907 if (!host_impl->is_hidden()) |
1141 view->Show(); | 908 view->Show(); |
1142 | 909 |
1143 // We listen to drag drop events in the newly created view's window. | 910 // We listen to drag drop events in the newly created view's window. |
1144 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 911 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
1145 | 912 |
1146 if (view->overscroll_controller() && | 913 if (view->overscroll_controller() && |
(...skipping 12 matching lines...) Expand all Loading... | |
1159 } | 926 } |
1160 | 927 |
1161 void WebContentsViewAura::SetPageTitle(const base::string16& title) { | 928 void WebContentsViewAura::SetPageTitle(const base::string16& title) { |
1162 window_->SetTitle(title); | 929 window_->SetTitle(title); |
1163 } | 930 } |
1164 | 931 |
1165 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 932 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
1166 } | 933 } |
1167 | 934 |
1168 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 935 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
1169 if (navigation_overlay_.get() && navigation_overlay_->has_window()) | |
1170 navigation_overlay_->StartObserving(); | |
1171 AttachTouchEditableToRenderView(); | 936 AttachTouchEditableToRenderView(); |
1172 } | 937 } |
1173 | 938 |
1174 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { | 939 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { |
1175 RenderWidgetHostViewAura* view = | 940 RenderWidgetHostViewAura* view = |
1176 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView()); | 941 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView()); |
1177 if (view) { | 942 if (view) { |
1178 view->SetOverscrollControllerEnabled(enabled); | 943 view->SetOverscrollControllerEnabled(enabled); |
1179 if (enabled) | 944 if (enabled) |
1180 InstallOverscrollControllerDelegate(view); | 945 InstallOverscrollControllerDelegate(view); |
1181 } | 946 } |
1182 | 947 |
1183 if (!enabled) | 948 if (!enabled) { |
1184 navigation_overlay_.reset(); | 949 navigation_overlay_.reset(); |
1185 else if (!navigation_overlay_) | 950 overscroll_window_animation_.reset(); |
1186 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); | 951 } |
952 if (!navigation_overlay_) { | |
953 navigation_overlay_.reset( | |
954 new OverscrollNavigationOverlay(web_contents_, window_.get())); | |
955 } | |
1187 } | 956 } |
1188 | 957 |
1189 //////////////////////////////////////////////////////////////////////////////// | 958 //////////////////////////////////////////////////////////////////////////////// |
1190 // WebContentsViewAura, RenderViewHostDelegateView implementation: | 959 // WebContentsViewAura, RenderViewHostDelegateView implementation: |
1191 | 960 |
1192 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host, | 961 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host, |
1193 const ContextMenuParams& params) { | 962 const ContextMenuParams& params) { |
1194 if (touch_editable_) { | 963 if (touch_editable_) { |
1195 touch_editable_->EndTouchEditing(false); | 964 touch_editable_->EndTouchEditing(false); |
1196 } | 965 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1297 if (!rwhv || !rwhv->IsShowing()) | 1066 if (!rwhv || !rwhv->IsShowing()) |
1298 return gfx::Rect(); | 1067 return gfx::Rect(); |
1299 | 1068 |
1300 return rwhv->GetViewBounds(); | 1069 return rwhv->GetViewBounds(); |
1301 } | 1070 } |
1302 | 1071 |
1303 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) { | 1072 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) { |
1304 if (current_overscroll_gesture_ == OVERSCROLL_NONE) | 1073 if (current_overscroll_gesture_ == OVERSCROLL_NONE) |
1305 return false; | 1074 return false; |
1306 | 1075 |
1307 aura::Window* target = GetWindowToAnimateForOverscroll(); | |
1308 gfx::Vector2dF translate = GetTranslationForOverscroll(delta_x, delta_y); | |
1309 gfx::Transform transform; | |
1310 | |
1311 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || | 1076 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || |
1312 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { | 1077 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { |
1313 OverscrollUpdateForWebContentsDelegate(translate.y()); | 1078 OverscrollUpdateForWebContentsDelegate(delta_y); |
1314 } else { | 1079 return delta_y != 0; |
1315 // Only horizontal overscrolls participate in the navigation gesture. | |
1316 transform.Translate(translate.x(), translate.y()); | |
1317 target->SetTransform(transform); | |
1318 UpdateOverscrollWindowBrightness(delta_x); | |
1319 } | 1080 } |
1320 | 1081 return overscroll_window_animation_->OnOverscrollUpdate(delta_x, delta_y); |
1321 return !translate.IsZero(); | |
1322 } | 1082 } |
1323 | 1083 |
1324 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) { | 1084 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) { |
1325 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT); | 1085 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT); |
1086 LOG(ERROR) << "OVERSCROLL COMPLETE"; | |
1326 if (web_contents_->GetDelegate() && | 1087 if (web_contents_->GetDelegate() && |
1327 IsScrollEndEffectEnabled() && | 1088 IsScrollEndEffectEnabled() && |
1328 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) { | 1089 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) { |
1329 web_contents_->GetDelegate()->OverscrollComplete(); | 1090 web_contents_->GetDelegate()->OverscrollComplete(); |
1330 } | 1091 } |
1331 NavigationControllerImpl& controller = web_contents_->GetController(); | 1092 CompleteOverscrollNavigation(mode); |
1332 if (ShouldNavigateForward(controller, mode) || | |
1333 ShouldNavigateBack(controller, mode)) { | |
1334 CompleteOverscrollNavigation(mode); | |
1335 return; | |
1336 } | |
1337 | |
1338 ResetOverscrollTransform(); | |
1339 } | 1093 } |
1340 | 1094 |
1341 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode, | 1095 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode, |
1342 OverscrollMode new_mode) { | 1096 OverscrollMode new_mode) { |
1343 // Reset any in-progress overscroll animation first. | 1097 LOG(ERROR) << "Overscroll mode change"; |
1344 ResetOverscrollTransform(); | |
1345 | |
1346 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH) | 1098 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH) |
1347 OverscrollUpdateForWebContentsDelegate(0); | 1099 OverscrollUpdateForWebContentsDelegate(0); |
1348 | 1100 |
1349 if (new_mode != OVERSCROLL_NONE && touch_editable_) | 1101 if (new_mode != OVERSCROLL_NONE && touch_editable_) |
1350 touch_editable_->OverscrollStarted(); | 1102 touch_editable_->OverscrollStarted(); |
1351 | 1103 |
1352 if (new_mode == OVERSCROLL_NONE || | 1104 if (current_overscroll_gesture_ == OVERSCROLL_NONE && |
1353 !GetContentNativeView() || | 1105 new_mode != OVERSCROLL_NONE) { |
1354 ((new_mode == OVERSCROLL_EAST || new_mode == OVERSCROLL_WEST) && | |
1355 navigation_overlay_.get() && navigation_overlay_->has_window())) { | |
1356 current_overscroll_gesture_ = OVERSCROLL_NONE; | |
1357 } else { | |
1358 aura::Window* target = GetWindowToAnimateForOverscroll(); | |
1359 if (target) { | |
1360 StopObservingImplicitAnimations(); | |
1361 target->layer()->GetAnimator()->AbortAllAnimations(); | |
1362 } | |
1363 // Cleanup state of the content window first, because that can reset the | |
1364 // value of |current_overscroll_gesture_|. | |
1365 PrepareContentWindowForOverscroll(); | |
1366 | |
1367 current_overscroll_gesture_ = new_mode; | |
1368 if (current_overscroll_gesture_ == OVERSCROLL_EAST || | |
1369 current_overscroll_gesture_ == OVERSCROLL_WEST) | |
1370 PrepareOverscrollWindow(); | |
1371 | |
1372 UMA_HISTOGRAM_ENUMERATION("Overscroll.Started", new_mode, OVERSCROLL_COUNT); | 1106 UMA_HISTOGRAM_ENUMERATION("Overscroll.Started", new_mode, OVERSCROLL_COUNT); |
1373 } | 1107 } |
1108 current_overscroll_gesture_ = new_mode; | |
1109 if (!overscroll_window_animation_) { | |
1110 overscroll_window_animation_.reset( | |
1111 new OverscrollWindowAnimation(navigation_overlay_.get(), | |
1112 web_contents_)); | |
1113 } | |
1114 overscroll_window_animation_->OnOverscrollModeChange(old_mode, new_mode); | |
1374 completed_overscroll_gesture_ = OVERSCROLL_NONE; | 1115 completed_overscroll_gesture_ = OVERSCROLL_NONE; |
1375 } | 1116 } |
1376 | 1117 |
1377 //////////////////////////////////////////////////////////////////////////////// | 1118 //////////////////////////////////////////////////////////////////////////////// |
1378 // WebContentsViewAura, ui::ImplicitAnimationObserver implementation: | |
1379 | |
1380 void WebContentsViewAura::OnImplicitAnimationsCompleted() { | |
1381 overscroll_shadow_.reset(); | |
1382 | |
1383 if (ShouldNavigateForward(web_contents_->GetController(), | |
1384 completed_overscroll_gesture_)) { | |
1385 web_contents_->GetController().GoForward(); | |
1386 PrepareOverscrollNavigationOverlay(); | |
1387 } else if (ShouldNavigateBack(web_contents_->GetController(), | |
1388 completed_overscroll_gesture_)) { | |
1389 web_contents_->GetController().GoBack(); | |
1390 PrepareOverscrollNavigationOverlay(); | |
1391 } else { | |
1392 if (touch_editable_) | |
1393 touch_editable_->OverscrollCompleted(); | |
1394 } | |
1395 | |
1396 aura::Window* content = GetContentNativeView(); | |
1397 if (content) { | |
1398 content->SetTransform(gfx::Transform()); | |
1399 content->layer()->SetLayerBrightness(0.f); | |
1400 } | |
1401 current_overscroll_gesture_ = OVERSCROLL_NONE; | |
1402 completed_overscroll_gesture_ = OVERSCROLL_NONE; | |
1403 overscroll_window_.reset(); | |
1404 } | |
1405 | |
1406 //////////////////////////////////////////////////////////////////////////////// | |
1407 // WebContentsViewAura, aura::WindowDelegate implementation: | 1119 // WebContentsViewAura, aura::WindowDelegate implementation: |
1408 | 1120 |
1409 gfx::Size WebContentsViewAura::GetMinimumSize() const { | 1121 gfx::Size WebContentsViewAura::GetMinimumSize() const { |
1410 return gfx::Size(); | 1122 return gfx::Size(); |
1411 } | 1123 } |
1412 | 1124 |
1413 gfx::Size WebContentsViewAura::GetMaximumSize() const { | 1125 gfx::Size WebContentsViewAura::GetMaximumSize() const { |
1414 return gfx::Size(); | 1126 return gfx::Size(); |
1415 } | 1127 } |
1416 | 1128 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1473 float device_scale_factor) { | 1185 float device_scale_factor) { |
1474 } | 1186 } |
1475 | 1187 |
1476 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) { | 1188 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) { |
1477 // This means the destructor is going to be called soon. If there is an | 1189 // This means the destructor is going to be called soon. If there is an |
1478 // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL), | 1190 // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL), |
1479 // then destroying it in the WebContentsViewAura destructor can trigger other | 1191 // then destroying it in the WebContentsViewAura destructor can trigger other |
1480 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So | 1192 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So |
1481 // destroy the overscroll window here. | 1193 // destroy the overscroll window here. |
1482 navigation_overlay_.reset(); | 1194 navigation_overlay_.reset(); |
1483 overscroll_window_.reset(); | 1195 overscroll_window_animation_.reset(); |
1484 } | 1196 } |
1485 | 1197 |
1486 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { | 1198 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { |
1487 } | 1199 } |
1488 | 1200 |
1489 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { | 1201 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { |
1490 } | 1202 } |
1491 | 1203 |
1492 bool WebContentsViewAura::HasHitTestMask() const { | 1204 bool WebContentsViewAura::HasHitTestMask() const { |
1493 return false; | 1205 return false; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1635 if (visible) { | 1347 if (visible) { |
1636 if (!web_contents_->should_normally_be_visible()) | 1348 if (!web_contents_->should_normally_be_visible()) |
1637 web_contents_->WasShown(); | 1349 web_contents_->WasShown(); |
1638 } else { | 1350 } else { |
1639 if (web_contents_->should_normally_be_visible()) | 1351 if (web_contents_->should_normally_be_visible()) |
1640 web_contents_->WasHidden(); | 1352 web_contents_->WasHidden(); |
1641 } | 1353 } |
1642 } | 1354 } |
1643 | 1355 |
1644 } // namespace content | 1356 } // namespace content |
OLD | NEW |