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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Following suggestions by Mikhail, rewritten OWA to use a delegate interface (to be implemented) Created 5 years, 10 months 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
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/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 18 matching lines...) Expand all
54 #include "ui/aura/window_tree_host_observer.h" 54 #include "ui/aura/window_tree_host_observer.h"
55 #include "ui/aura_extra/image_window_delegate.h" 55 #include "ui/aura_extra/image_window_delegate.h"
56 #include "ui/base/clipboard/clipboard.h" 56 #include "ui/base/clipboard/clipboard.h"
57 #include "ui/base/clipboard/custom_data_helper.h" 57 #include "ui/base/clipboard/custom_data_helper.h"
58 #include "ui/base/dragdrop/drag_drop_types.h" 58 #include "ui/base/dragdrop/drag_drop_types.h"
59 #include "ui/base/dragdrop/drag_utils.h" 59 #include "ui/base/dragdrop/drag_utils.h"
60 #include "ui/base/dragdrop/drop_target_event.h" 60 #include "ui/base/dragdrop/drop_target_event.h"
61 #include "ui/base/dragdrop/os_exchange_data.h" 61 #include "ui/base/dragdrop/os_exchange_data.h"
62 #include "ui/base/hit_test.h" 62 #include "ui/base/hit_test.h"
63 #include "ui/compositor/layer.h" 63 #include "ui/compositor/layer.h"
64 #include "ui/compositor/scoped_layer_animation_settings.h"
65 #include "ui/events/event.h" 64 #include "ui/events/event.h"
66 #include "ui/events/event_utils.h" 65 #include "ui/events/event_utils.h"
67 #include "ui/gfx/canvas.h" 66 #include "ui/gfx/canvas.h"
68 #include "ui/gfx/image/image.h" 67 #include "ui/gfx/image/image.h"
69 #include "ui/gfx/image/image_png_rep.h" 68 #include "ui/gfx/image/image_png_rep.h"
70 #include "ui/gfx/image/image_skia.h" 69 #include "ui/gfx/image/image_skia.h"
71 #include "ui/gfx/screen.h" 70 #include "ui/gfx/screen.h"
72 #include "ui/wm/public/drag_drop_client.h" 71 #include "ui/wm/public/drag_drop_client.h"
73 #include "ui/wm/public/drag_drop_delegate.h" 72 #include "ui/wm/public/drag_drop_delegate.h"
74 73
75 namespace content { 74 namespace content {
76 WebContentsView* CreateWebContentsView( 75 WebContentsView* CreateWebContentsView(
77 WebContentsImpl* web_contents, 76 WebContentsImpl* web_contents,
78 WebContentsViewDelegate* delegate, 77 WebContentsViewDelegate* delegate,
79 RenderViewHostDelegateView** render_view_host_delegate_view) { 78 RenderViewHostDelegateView** render_view_host_delegate_view) {
80 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); 79 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate);
81 *render_view_host_delegate_view = rv; 80 *render_view_host_delegate_view = rv;
82 return rv; 81 return rv;
83 } 82 }
84 83
85 namespace { 84 namespace {
86 85
87 bool IsScrollEndEffectEnabled() { 86 bool IsScrollEndEffectEnabled() {
88 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 87 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
89 switches::kScrollEndEffect) == "1"; 88 switches::kScrollEndEffect) == "1";
90 } 89 }
91 90
92 bool ShouldNavigateForward(const NavigationController& controller,
93 OverscrollMode mode) {
94 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) &&
95 controller.CanGoForward();
96 }
97
98 bool ShouldNavigateBack(const NavigationController& controller,
99 OverscrollMode mode) {
100 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) &&
101 controller.CanGoBack();
102 }
103
104 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( 91 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura(
105 RenderWidgetHostView* view) { 92 RenderWidgetHostView* view) {
106 if (!view || RenderViewHostFactory::has_factory()) 93 if (!view || RenderViewHostFactory::has_factory())
107 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. 94 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests.
108 95
109 RenderViewHost* rvh = RenderViewHost::From(view->GetRenderWidgetHost()); 96 RenderViewHost* rvh = RenderViewHost::From(view->GetRenderWidgetHost());
110 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 97 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
111 rvh ? WebContents::FromRenderViewHost(rvh) : NULL); 98 rvh ? WebContents::FromRenderViewHost(rvh) : NULL);
112 if (BrowserPluginGuest::IsGuest(web_contents)) 99 if (BrowserPluginGuest::IsGuest(web_contents))
113 return NULL; 100 return NULL;
114 return static_cast<RenderWidgetHostViewAura*>(view); 101 return static_cast<RenderWidgetHostViewAura*>(view);
115 } 102 }
116 103
117 // The window delegate for the overscroll window. This redirects trackpad events
118 // to the web-contents window. The delegate destroys itself when the window is
119 // destroyed.
120 class OverscrollWindowDelegate : public aura_extra::ImageWindowDelegate {
121 public:
122 OverscrollWindowDelegate(WebContentsImpl* web_contents,
123 OverscrollMode overscroll_mode)
124 : web_contents_(web_contents),
125 forward_events_(true) {
126 const NavigationControllerImpl& controller = web_contents->GetController();
127 const NavigationEntryImpl* entry = NULL;
128 if (ShouldNavigateForward(controller, overscroll_mode)) {
129 entry = NavigationEntryImpl::FromNavigationEntry(
130 controller.GetEntryAtOffset(1));
131 } else if (ShouldNavigateBack(controller, overscroll_mode)) {
132 entry = NavigationEntryImpl::FromNavigationEntry(
133 controller.GetEntryAtOffset(-1));
134 }
135
136 gfx::Image image;
137 if (entry && entry->screenshot().get()) {
138 std::vector<gfx::ImagePNGRep> image_reps;
139 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f));
140 image = gfx::Image(image_reps);
141 }
142 SetImage(image);
143 }
144
145 void stop_forwarding_events() { forward_events_ = false; }
146
147 private:
148 ~OverscrollWindowDelegate() override {}
149
150 aura::Window* web_contents_window() {
151 return web_contents_->GetView()->GetContentNativeView();
152 }
153
154 // Overridden from ui::EventHandler.
155 void OnScrollEvent(ui::ScrollEvent* event) override {
156 if (forward_events_ && web_contents_window())
157 web_contents_window()->delegate()->OnScrollEvent(event);
158 }
159
160 void OnGestureEvent(ui::GestureEvent* event) override {
161 if (forward_events_ && web_contents_window())
162 web_contents_window()->delegate()->OnGestureEvent(event);
163 }
164
165 WebContentsImpl* web_contents_;
166
167 // The window is displayed both during the gesture, and after the gesture
168 // while the navigation is in progress. During the gesture, it is necessary to
169 // forward input events to the content page (e.g. when the overscroll window
170 // slides under the cursor and starts receiving scroll events). However, once
171 // the gesture is complete, and the window is being displayed as an overlay
172 // window during navigation, events should not be forwarded anymore.
173 bool forward_events_;
174
175 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate);
176 };
177
178 // Listens to all mouse drag events during a drag and drop and sends them to 104 // Listens to all mouse drag events during a drag and drop and sends them to
179 // the renderer. 105 // the renderer.
180 class WebDragSourceAura : public NotificationObserver { 106 class WebDragSourceAura : public NotificationObserver {
181 public: 107 public:
182 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) 108 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents)
183 : window_(window), 109 : window_(window),
184 contents_(contents) { 110 contents_(contents) {
185 registrar_.Add(this, 111 registrar_.Add(this,
186 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 112 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
187 Source<WebContents>(contents)); 113 Source<WebContents>(contents));
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 // The parent window that hosts the constrained windows. We cache the old host 647 // The parent window that hosts the constrained windows. We cache the old host
722 // view so that we can unregister when it's not the parent anymore. 648 // view so that we can unregister when it's not the parent anymore.
723 aura::Window* host_window_; 649 aura::Window* host_window_;
724 650
725 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 651 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
726 }; 652 };
727 653
728 //////////////////////////////////////////////////////////////////////////////// 654 ////////////////////////////////////////////////////////////////////////////////
729 // WebContentsViewAura, public: 655 // WebContentsViewAura, public:
730 656
731 WebContentsViewAura::WebContentsViewAura( 657 WebContentsViewAura::WebContentsViewAura(WebContentsImpl* web_contents,
732 WebContentsImpl* web_contents, 658 WebContentsViewDelegate* delegate)
733 WebContentsViewDelegate* delegate)
734 : web_contents_(web_contents), 659 : web_contents_(web_contents),
735 delegate_(delegate), 660 delegate_(delegate),
736 current_drag_op_(blink::WebDragOperationNone), 661 current_drag_op_(blink::WebDragOperationNone),
737 drag_dest_delegate_(NULL), 662 drag_dest_delegate_(NULL),
738 current_rvh_for_drag_(NULL), 663 current_rvh_for_drag_(NULL),
739 overscroll_change_brightness_(false),
740 current_overscroll_gesture_(OVERSCROLL_NONE), 664 current_overscroll_gesture_(OVERSCROLL_NONE),
741 completed_overscroll_gesture_(OVERSCROLL_NONE), 665 completed_overscroll_gesture_(OVERSCROLL_NONE),
742 touch_editable_(TouchEditableImplAura::Create()), 666 touch_editable_(TouchEditableImplAura::Create()),
743 is_or_was_visible_(false) { 667 is_or_was_visible_(false),
668 overscroll_window_animation_(nullptr) {
744 } 669 }
745 670
746 //////////////////////////////////////////////////////////////////////////////// 671 ////////////////////////////////////////////////////////////////////////////////
747 // WebContentsViewAura, private: 672 // WebContentsViewAura, private:
748 673
749 WebContentsViewAura::~WebContentsViewAura() { 674 WebContentsViewAura::~WebContentsViewAura() {
750 if (!window_) 675 if (!window_)
751 return; 676 return;
752 677
753 window_observer_.reset(); 678 window_observer_.reset();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 722 }
798 if (value == "2") { 723 if (value == "2") {
799 navigation_overlay_.reset(); 724 navigation_overlay_.reset();
800 if (!gesture_nav_simple_) 725 if (!gesture_nav_simple_)
801 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_)); 726 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_));
802 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get()); 727 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get());
803 return; 728 return;
804 } 729 }
805 view->overscroll_controller()->set_delegate(this); 730 view->overscroll_controller()->set_delegate(this);
806 if (!navigation_overlay_) 731 if (!navigation_overlay_)
807 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 732 navigation_overlay_.reset(
808 } 733 new OverscrollNavigationOverlay(web_contents_, this, window_.get()));
809 734 LOG(ERROR) << "Installing overscroll window animation controller";
810 void WebContentsViewAura::PrepareOverscrollWindow() { 735 if (!overscroll_window_animation_) {
811 // If there is an existing |overscroll_window_| which is in the middle of an 736 overscroll_window_animation_.reset(new OverscrollWindowAnimation(
812 // animation, then destroying the window here causes the animation to be 737 navigation_overlay_.get()));
813 // completed immediately, which triggers |OnImplicitAnimationsCompleted()|
814 // callback, and that tries to reset |overscroll_window_| again, causing a
815 // double-free. So use a temporary variable here.
816 if (overscroll_window_) {
817 base::AutoReset<OverscrollMode> reset_state(&current_overscroll_gesture_,
818 current_overscroll_gesture_);
819 scoped_ptr<aura::Window> reset_window(overscroll_window_.release());
820 } 738 }
821
822 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate(
823 web_contents_,
824 current_overscroll_gesture_);
825 overscroll_window_.reset(new aura::Window(overscroll_delegate));
826 overscroll_window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
827 overscroll_window_->SetTransparent(true);
828 overscroll_window_->Init(aura::WINDOW_LAYER_TEXTURED);
829 overscroll_window_->layer()->SetMasksToBounds(false);
830 overscroll_window_->SetName("OverscrollOverlay");
831
832 overscroll_change_brightness_ = overscroll_delegate->has_image();
833 window_->AddChild(overscroll_window_.get());
834
835 gfx::Rect bounds = gfx::Rect(window_->bounds().size());
836 if (ShouldNavigateForward(web_contents_->GetController(),
837 current_overscroll_gesture_)) {
838 // The overlay will be sliding in from the right edge towards the left in
839 // non-RTL, or sliding in from the left edge towards the right in RTL.
840 // So position the overlay window accordingly.
841 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0);
842 }
843
844 aura::Window* animate_window = GetWindowToAnimateForOverscroll();
845 if (animate_window == overscroll_window_)
846 window_->StackChildAbove(overscroll_window_.get(), GetContentNativeView());
847 else
848 window_->StackChildBelow(overscroll_window_.get(), GetContentNativeView());
849
850 UpdateOverscrollWindowBrightness(0.f);
851
852 overscroll_window_->SetBounds(bounds);
853 overscroll_window_->Show();
854
855 overscroll_shadow_.reset(new ShadowLayerDelegate(animate_window->layer()));
856 } 739 }
857 740
858 void WebContentsViewAura::PrepareContentWindowForOverscroll() { 741 void WebContentsViewAura::PrepareContentWindowForOverscroll() {
859 StopObservingImplicitAnimations();
860 aura::Window* content = GetContentNativeView(); 742 aura::Window* content = GetContentNativeView();
861 content->layer()->GetAnimator()->AbortAllAnimations(); 743 content->layer()->GetAnimator()->AbortAllAnimations();
862 content->SetTransform(gfx::Transform()); 744 content->SetTransform(gfx::Transform());
863 content->layer()->SetLayerBrightness(0.f); 745 content->layer()->SetLayerBrightness(0.f);
864 } 746 }
865 747
866 void WebContentsViewAura::ResetOverscrollTransform() {
867 if (!web_contents_->GetRenderWidgetHostView())
868 return;
869 aura::Window* target = GetWindowToAnimateForOverscroll();
870 if (!target)
871 return;
872 {
873 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator());
874 settings.SetPreemptionStrategy(
875 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
876 settings.SetTweenType(gfx::Tween::EASE_OUT);
877 settings.AddObserver(this);
878 target->SetTransform(gfx::Transform());
879 }
880 {
881 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator());
882 settings.SetPreemptionStrategy(
883 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
884 settings.SetTweenType(gfx::Tween::EASE_OUT);
885 UpdateOverscrollWindowBrightness(0.f);
886 }
887 }
888
889 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) { 748 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) {
890 if (!web_contents_->GetRenderWidgetHostView()) 749 if (!web_contents_->GetRenderWidgetHostView())
891 return; 750 return;
892 751
893 // Animate out the current view first. Navigate to the requested history at 752 // Animate out the current view first. Navigate to the requested history at
894 // the end of the animation. 753 // the end of the animation.
754 // TODO maybe the following line is redundant?
895 if (current_overscroll_gesture_ == OVERSCROLL_NONE) 755 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
896 return; 756 return;
897 757
898 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated", 758 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated",
899 current_overscroll_gesture_, OVERSCROLL_COUNT); 759 current_overscroll_gesture_, OVERSCROLL_COUNT);
900 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>(
901 overscroll_window_->delegate());
902 delegate->stop_forwarding_events();
903 760
904 completed_overscroll_gesture_ = mode; 761 overscroll_window_animation_->OnOverscrollComplete(mode);
905 aura::Window* target = GetWindowToAnimateForOverscroll();
906 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator());
907 settings.SetPreemptionStrategy(
908 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
909 settings.SetTweenType(gfx::Tween::EASE_OUT);
910 settings.AddObserver(this);
911 gfx::Transform transform;
912 int content_width =
913 web_contents_->GetRenderWidgetHostView()->GetViewBounds().width();
914 float translate_x = static_cast<float>(mode == OVERSCROLL_WEST ?
915 -content_width : content_width);
916 transform.Translate(translate_x, 0);
917 target->SetTransform(transform);
918 UpdateOverscrollWindowBrightness(translate_x);
919 }
920
921 aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() {
922 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
923 return NULL;
924
925 return ShouldNavigateForward(web_contents_->GetController(),
926 current_overscroll_gesture_) ?
927 overscroll_window_.get() : GetContentNativeView();
928 }
929
930 gfx::Vector2dF WebContentsViewAura::GetTranslationForOverscroll(float delta_x,
931 float delta_y) {
932 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
933 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
934 return gfx::Vector2dF(0, delta_y);
935 }
936 // For horizontal overscroll, scroll freely if a navigation is possible. Do a
937 // resistive scroll otherwise.
938 const NavigationControllerImpl& controller = web_contents_->GetController();
939 const gfx::Rect& bounds = GetViewBounds();
940 const float bounds_width = static_cast<float>(bounds.width());
941 if (ShouldNavigateForward(controller, current_overscroll_gesture_))
942 return gfx::Vector2dF(std::max(-bounds_width, delta_x), 0);
943 else if (ShouldNavigateBack(controller, current_overscroll_gesture_))
944 return gfx::Vector2dF(std::min(bounds_width, delta_x), 0);
945 return gfx::Vector2dF();
946 } 762 }
947 763
948 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() { 764 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() {
949 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( 765 LOG(ERROR) << "Preparing overscroll navigation overlay";
950 overscroll_window_->delegate());
951 overscroll_window_->SchedulePaintInRect(
952 gfx::Rect(overscroll_window_->bounds().size()));
953 overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size()));
954 overscroll_window_->SetTransform(gfx::Transform());
955 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(),
956 delegate);
957 navigation_overlay_->StartObserving(); 766 navigation_overlay_->StartObserving();
958 } 767 }
959 768
960 void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) {
961 if (!overscroll_change_brightness_)
962 return;
963
964 const float kBrightnessMin = -.1f;
965 const float kBrightnessMax = -.01f;
966
967 float ratio = fabs(delta_x) / GetViewBounds().width();
968 ratio = std::min(1.f, ratio);
969 if (base::i18n::IsRTL())
970 ratio = 1.f - ratio;
971 float brightness = current_overscroll_gesture_ == OVERSCROLL_WEST ?
972 kBrightnessMin + ratio * (kBrightnessMax - kBrightnessMin) :
973 kBrightnessMax - ratio * (kBrightnessMax - kBrightnessMin);
974 brightness = std::max(kBrightnessMin, brightness);
975 brightness = std::min(kBrightnessMax, brightness);
976 aura::Window* window = GetWindowToAnimateForOverscroll();
977 window->layer()->SetLayerBrightness(brightness);
978 }
979
980 void WebContentsViewAura::AttachTouchEditableToRenderView() { 769 void WebContentsViewAura::AttachTouchEditableToRenderView() {
981 if (!touch_editable_) 770 if (!touch_editable_)
982 return; 771 return;
983 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( 772 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura(
984 web_contents_->GetRenderWidgetHostView()); 773 web_contents_->GetRenderWidgetHostView());
985 touch_editable_->AttachToView(rwhva); 774 touch_editable_->AttachToView(rwhva);
986 } 775 }
987 776
988 void WebContentsViewAura::OverscrollUpdateForWebContentsDelegate( 777 void WebContentsViewAura::OverscrollUpdateForWebContentsDelegate(
989 float delta_y) { 778 float delta_y) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView()); 968 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView());
1180 if (view) { 969 if (view) {
1181 view->SetOverscrollControllerEnabled(enabled); 970 view->SetOverscrollControllerEnabled(enabled);
1182 if (enabled) 971 if (enabled)
1183 InstallOverscrollControllerDelegate(view); 972 InstallOverscrollControllerDelegate(view);
1184 } 973 }
1185 974
1186 if (!enabled) 975 if (!enabled)
1187 navigation_overlay_.reset(); 976 navigation_overlay_.reset();
1188 else if (!navigation_overlay_) 977 else if (!navigation_overlay_)
1189 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 978 navigation_overlay_.reset(
979 new OverscrollNavigationOverlay(web_contents_, this, window_.get()));
1190 } 980 }
1191 981
1192 //////////////////////////////////////////////////////////////////////////////// 982 ////////////////////////////////////////////////////////////////////////////////
1193 // WebContentsViewAura, RenderViewHostDelegateView implementation: 983 // WebContentsViewAura, RenderViewHostDelegateView implementation:
1194 984
1195 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host, 985 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host,
1196 const ContextMenuParams& params) { 986 const ContextMenuParams& params) {
1197 if (touch_editable_) { 987 if (touch_editable_) {
1198 touch_editable_->EndTouchEditing(false); 988 touch_editable_->EndTouchEditing(false);
1199 } 989 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 if (!rwhv || !rwhv->IsShowing()) 1097 if (!rwhv || !rwhv->IsShowing())
1308 return gfx::Rect(); 1098 return gfx::Rect();
1309 1099
1310 return rwhv->GetViewBounds(); 1100 return rwhv->GetViewBounds();
1311 } 1101 }
1312 1102
1313 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) { 1103 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) {
1314 if (current_overscroll_gesture_ == OVERSCROLL_NONE) 1104 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
1315 return false; 1105 return false;
1316 1106
1317 aura::Window* target = GetWindowToAnimateForOverscroll();
1318 gfx::Vector2dF translate = GetTranslationForOverscroll(delta_x, delta_y);
1319 gfx::Transform transform;
1320
1321 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || 1107 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
1322 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { 1108 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
1323 OverscrollUpdateForWebContentsDelegate(translate.y()); 1109 OverscrollUpdateForWebContentsDelegate(delta_y);
1324 } else { 1110 return delta_y != 0;
1325 // Only horizontal overscrolls participate in the navigation gesture.
1326 transform.Translate(translate.x(), translate.y());
1327 target->SetTransform(transform);
1328 UpdateOverscrollWindowBrightness(delta_x);
1329 } 1111 }
1330 1112 // Only horizontal overscrolls participate in the navigation gesture.
1331 return !translate.IsZero(); 1113 if (!overscroll_window_animation_)
1114 return false;
1115 return overscroll_window_animation_->OnOverscrollUpdate(delta_x, delta_y);
1332 } 1116 }
1333 1117
1334 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) { 1118 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) {
1335 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT); 1119 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT);
1120 LOG(ERROR) << "OVERSCROLL COMPLETE";
1336 if (web_contents_->GetDelegate() && 1121 if (web_contents_->GetDelegate() &&
1337 IsScrollEndEffectEnabled() && 1122 IsScrollEndEffectEnabled() &&
1338 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) { 1123 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) {
1339 web_contents_->GetDelegate()->OverscrollComplete(); 1124 web_contents_->GetDelegate()->OverscrollComplete();
1340 } 1125 }
1341 NavigationControllerImpl& controller = web_contents_->GetController(); 1126 OverscrollWindowAnimation::Direction direction =
1342 if (ShouldNavigateForward(controller, mode) || 1127 navigation_overlay_->GetNavigationDirection();
1343 ShouldNavigateBack(controller, mode)) { 1128 // TODO maybe this is irrelevant?
1344 CompleteOverscrollNavigation(mode); 1129 if (direction == OverscrollWindowAnimation::NONE)
1345 return; 1130 return;
1346 }
1347 1131
1348 ResetOverscrollTransform(); 1132 CompleteOverscrollNavigation(mode);
1133 // TODO uncomment these lines.
1134 if (direction == OverscrollWindowAnimation::FORWARD)
1135 web_contents_->GetController().GoForward();
1136 else
1137 web_contents_->GetController().GoBack();
1138 PrepareOverscrollNavigationOverlay();
1349 } 1139 }
1350 1140
1351 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode, 1141 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode,
1352 OverscrollMode new_mode) { 1142 OverscrollMode new_mode) {
1143 LOG(ERROR) << "Overscroll mode change";
1353 // Reset any in-progress overscroll animation first. 1144 // Reset any in-progress overscroll animation first.
1354 ResetOverscrollTransform(); 1145 // ResetOverscrollTransform();
1355 1146
1356 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH) 1147 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH)
1357 OverscrollUpdateForWebContentsDelegate(0); 1148 OverscrollUpdateForWebContentsDelegate(0);
1358 1149
1359 if (new_mode != OVERSCROLL_NONE && touch_editable_) 1150 if (new_mode != OVERSCROLL_NONE && touch_editable_)
1360 touch_editable_->OverscrollStarted(); 1151 touch_editable_->OverscrollStarted();
1361 1152
1362 if (new_mode == OVERSCROLL_NONE || 1153 if (new_mode == OVERSCROLL_NONE ||
1363 !GetContentNativeView() || 1154 !GetContentNativeView() ||
1364 ((new_mode == OVERSCROLL_EAST || new_mode == OVERSCROLL_WEST) && 1155 ((new_mode == OVERSCROLL_EAST || new_mode == OVERSCROLL_WEST) &&
1365 navigation_overlay_.get() && navigation_overlay_->has_window())) { 1156 navigation_overlay_.get() && navigation_overlay_->has_window())) {
1157 // TODO maybe I want to not set directly OVERSCROLL_NONE in the following
1158 // statement?
1366 current_overscroll_gesture_ = OVERSCROLL_NONE; 1159 current_overscroll_gesture_ = OVERSCROLL_NONE;
1160 overscroll_window_animation_->OnOverscrollModeChange(old_mode,
1161 OVERSCROLL_NONE);
1367 } else { 1162 } else {
1368 aura::Window* target = GetWindowToAnimateForOverscroll(); 1163 current_overscroll_gesture_ = new_mode;
1369 if (target) { 1164 if (overscroll_window_animation_)
1370 StopObservingImplicitAnimations(); 1165 overscroll_window_animation_->OnOverscrollModeChange(old_mode, new_mode);
1371 target->layer()->GetAnimator()->AbortAllAnimations(); 1166 PrepareContentWindowForOverscroll();
1372 } 1167 }
1168 /*
1169 } else {
1170 if (overscroll_window_animation_)
1171 overscroll_window_animation_->AbortAllAnimations();
1172
1373 // Cleanup state of the content window first, because that can reset the 1173 // Cleanup state of the content window first, because that can reset the
1374 // value of |current_overscroll_gesture_|. 1174 // value of |current_overscroll_gesture_|.
1375 PrepareContentWindowForOverscroll();
1376 1175
1377 current_overscroll_gesture_ = new_mode; 1176 current_overscroll_gesture_ = new_mode;
1378 if (current_overscroll_gesture_ == OVERSCROLL_EAST || 1177 if (ShouldNavigateBack(web_contents_->GetController(),
1379 current_overscroll_gesture_ == OVERSCROLL_WEST) 1178 current_overscroll_gesture_) ||
1380 PrepareOverscrollWindow(); 1179 ShouldNavigateForward(web_contents_->GetController(),
1180 current_overscroll_gesture_)) {
1181 LOG(ERROR) << "Preparing overscroll window";
1182 //PrepareOverscrollWindow();
1183 }
1381 1184
1382 UMA_HISTOGRAM_ENUMERATION("Overscroll.Started", new_mode, OVERSCROLL_COUNT); 1185 UMA_HISTOGRAM_ENUMERATION("Overscroll.Started", new_mode, OVERSCROLL_COUNT);
1383 } 1186 }*/
1384 completed_overscroll_gesture_ = OVERSCROLL_NONE; 1187 completed_overscroll_gesture_ = OVERSCROLL_NONE;
1385 } 1188 }
1386 1189
1387 //////////////////////////////////////////////////////////////////////////////// 1190 ////////////////////////////////////////////////////////////////////////////////
1388 // WebContentsViewAura, ui::ImplicitAnimationObserver implementation:
1389
1390 void WebContentsViewAura::OnImplicitAnimationsCompleted() {
1391 overscroll_shadow_.reset();
1392
1393 if (ShouldNavigateForward(web_contents_->GetController(),
1394 completed_overscroll_gesture_)) {
1395 web_contents_->GetController().GoForward();
1396 PrepareOverscrollNavigationOverlay();
1397 } else if (ShouldNavigateBack(web_contents_->GetController(),
1398 completed_overscroll_gesture_)) {
1399 web_contents_->GetController().GoBack();
1400 PrepareOverscrollNavigationOverlay();
1401 } else {
1402 if (touch_editable_)
1403 touch_editable_->OverscrollCompleted();
1404 }
1405
1406 aura::Window* content = GetContentNativeView();
1407 if (content) {
1408 content->SetTransform(gfx::Transform());
1409 content->layer()->SetLayerBrightness(0.f);
1410 }
1411 current_overscroll_gesture_ = OVERSCROLL_NONE;
1412 completed_overscroll_gesture_ = OVERSCROLL_NONE;
1413 overscroll_window_.reset();
1414 }
1415
1416 ////////////////////////////////////////////////////////////////////////////////
1417 // WebContentsViewAura, aura::WindowDelegate implementation: 1191 // WebContentsViewAura, aura::WindowDelegate implementation:
1418 1192
1419 gfx::Size WebContentsViewAura::GetMinimumSize() const { 1193 gfx::Size WebContentsViewAura::GetMinimumSize() const {
1420 return gfx::Size(); 1194 return gfx::Size();
1421 } 1195 }
1422 1196
1423 gfx::Size WebContentsViewAura::GetMaximumSize() const { 1197 gfx::Size WebContentsViewAura::GetMaximumSize() const {
1424 return gfx::Size(); 1198 return gfx::Size();
1425 } 1199 }
1426 1200
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 void WebContentsViewAura::OnCaptureLost() { 1250 void WebContentsViewAura::OnCaptureLost() {
1477 } 1251 }
1478 1252
1479 void WebContentsViewAura::OnPaint(gfx::Canvas* canvas) { 1253 void WebContentsViewAura::OnPaint(gfx::Canvas* canvas) {
1480 } 1254 }
1481 1255
1482 void WebContentsViewAura::OnDeviceScaleFactorChanged( 1256 void WebContentsViewAura::OnDeviceScaleFactorChanged(
1483 float device_scale_factor) { 1257 float device_scale_factor) {
1484 } 1258 }
1485 1259
1260 // TODO move this to overscroll window animation.
1486 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) { 1261 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) {
1487 // This means the destructor is going to be called soon. If there is an 1262 // This means the destructor is going to be called soon. If there is an
1488 // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL), 1263 // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL),
1489 // then destroying it in the WebContentsViewAura destructor can trigger other 1264 // then destroying it in the WebContentsViewAura destructor can trigger other
1490 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So 1265 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So
1491 // destroy the overscroll window here. 1266 // destroy the overscroll window here.
1492 navigation_overlay_.reset(); 1267 navigation_overlay_.reset();
1493 overscroll_window_.reset(); 1268 LOG(ERROR) << "Window destroyed, resetting overscroll window animation";
1269 overscroll_window_animation_.reset();
1494 } 1270 }
1495 1271
1496 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { 1272 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) {
1497 } 1273 }
1498 1274
1499 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1275 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1500 } 1276 }
1501 1277
1502 bool WebContentsViewAura::HasHitTestMask() const { 1278 bool WebContentsViewAura::HasHitTestMask() const {
1503 return false; 1279 return false;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 if (visible) { 1421 if (visible) {
1646 if (!web_contents_->should_normally_be_visible()) 1422 if (!web_contents_->should_normally_be_visible())
1647 web_contents_->WasShown(); 1423 web_contents_->WasShown();
1648 } else { 1424 } else {
1649 if (web_contents_->should_normally_be_visible()) 1425 if (web_contents_->should_normally_be_visible())
1650 web_contents_->WasHidden(); 1426 web_contents_->WasHidden();
1651 } 1427 }
1652 } 1428 }
1653 1429
1654 } // namespace content 1430 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698