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

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: Fixed some bugs related to back and forth 2nd case navigation Created 5 years, 9 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 17 matching lines...) Expand all
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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 // The parent window that hosts the constrained windows. We cache the old host 652 // The parent window that hosts the constrained windows. We cache the old host
725 // view so that we can unregister when it's not the parent anymore. 653 // view so that we can unregister when it's not the parent anymore.
726 aura::Window* host_window_; 654 aura::Window* host_window_;
727 655
728 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 656 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
729 }; 657 };
730 658
731 //////////////////////////////////////////////////////////////////////////////// 659 ////////////////////////////////////////////////////////////////////////////////
732 // WebContentsViewAura, public: 660 // WebContentsViewAura, public:
733 661
734 WebContentsViewAura::WebContentsViewAura( 662 WebContentsViewAura::WebContentsViewAura(WebContentsImpl* web_contents,
735 WebContentsImpl* web_contents, 663 WebContentsViewDelegate* delegate)
736 WebContentsViewDelegate* delegate)
737 : web_contents_(web_contents), 664 : web_contents_(web_contents),
738 delegate_(delegate), 665 delegate_(delegate),
739 current_drag_op_(blink::WebDragOperationNone), 666 current_drag_op_(blink::WebDragOperationNone),
740 drag_dest_delegate_(NULL), 667 drag_dest_delegate_(NULL),
741 current_rvh_for_drag_(NULL), 668 current_rvh_for_drag_(NULL),
742 overscroll_change_brightness_(false),
743 current_overscroll_gesture_(OVERSCROLL_NONE), 669 current_overscroll_gesture_(OVERSCROLL_NONE),
744 completed_overscroll_gesture_(OVERSCROLL_NONE), 670 completed_overscroll_gesture_(OVERSCROLL_NONE),
671 navigation_overlay_(nullptr),
672 overscroll_window_animation_(nullptr),
745 touch_editable_(TouchEditableImplAura::Create()), 673 touch_editable_(TouchEditableImplAura::Create()),
746 is_or_was_visible_(false) { 674 is_or_was_visible_(false) {
747 } 675 }
748 676
749 //////////////////////////////////////////////////////////////////////////////// 677 ////////////////////////////////////////////////////////////////////////////////
750 // WebContentsViewAura, private: 678 // WebContentsViewAura, private:
751 679
752 WebContentsViewAura::~WebContentsViewAura() { 680 WebContentsViewAura::~WebContentsViewAura() {
753 if (!window_) 681 if (!window_)
754 return; 682 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(), 717 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(),
790 screen_loc.x(), screen_loc.y(), ops); 718 screen_loc.x(), screen_loc.y(), ops);
791 } 719 }
792 720
793 void WebContentsViewAura::InstallOverscrollControllerDelegate( 721 void WebContentsViewAura::InstallOverscrollControllerDelegate(
794 RenderWidgetHostViewAura* view) { 722 RenderWidgetHostViewAura* view) {
795 const std::string value = base::CommandLine::ForCurrentProcess()-> 723 const std::string value = base::CommandLine::ForCurrentProcess()->
796 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); 724 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation);
797 if (value == "0") { 725 if (value == "0") {
798 navigation_overlay_.reset(); 726 navigation_overlay_.reset();
727 overscroll_window_animation_ = nullptr;
799 return; 728 return;
800 } 729 }
801 if (value == "2") { 730 if (value == "2") {
802 navigation_overlay_.reset(); 731 navigation_overlay_.reset();
803 if (!gesture_nav_simple_) 732 if (!gesture_nav_simple_)
804 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_)); 733 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_));
805 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get()); 734 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get());
806 return; 735 return;
807 } 736 }
808 view->overscroll_controller()->set_delegate(this); 737 view->overscroll_controller()->set_delegate(this);
809 if (!navigation_overlay_) 738 if (!navigation_overlay_) {
810 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 739 navigation_overlay_.reset(
811 } 740 new OverscrollNavigationOverlay(web_contents_, window_.get()));
812 741 overscroll_window_animation_ = navigation_overlay_->owa();
mfomitchev 2015/03/16 22:28:02 I think we need to handle the possibility of overs
Nina 2015/03/17 14:27:07 If the overscroll is disabled, navigation_overlay_
813 void WebContentsViewAura::PrepareOverscrollWindow() {
814 // If there is an existing |overscroll_window_| which is in the middle of an
815 // animation, then destroying the window here causes the animation to be
816 // completed immediately, which triggers |OnImplicitAnimationsCompleted()|
817 // callback, and that tries to reset |overscroll_window_| again, causing a
818 // double-free. So use a temporary variable here.
819 if (overscroll_window_) {
820 base::AutoReset<OverscrollMode> reset_state(&current_overscroll_gesture_,
821 current_overscroll_gesture_);
822 scoped_ptr<aura::Window> reset_window(overscroll_window_.release());
823 }
824
825 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate(
826 web_contents_,
827 current_overscroll_gesture_);
828 overscroll_window_.reset(new aura::Window(overscroll_delegate));
829 overscroll_window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
830 overscroll_window_->SetTransparent(true);
831 overscroll_window_->Init(aura::WINDOW_LAYER_TEXTURED);
832 overscroll_window_->layer()->SetMasksToBounds(false);
833 overscroll_window_->SetName("OverscrollOverlay");
834
835 overscroll_change_brightness_ = overscroll_delegate->has_image();
836 window_->AddChild(overscroll_window_.get());
837
838 gfx::Rect bounds = gfx::Rect(window_->bounds().size());
839 if (ShouldNavigateForward(web_contents_->GetController(),
840 current_overscroll_gesture_)) {
841 // The overlay will be sliding in from the right edge towards the left in
842 // non-RTL, or sliding in from the left edge towards the right in RTL.
843 // So position the overlay window accordingly.
844 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0);
845 }
846
847 aura::Window* animate_window = GetWindowToAnimateForOverscroll();
848 if (animate_window == overscroll_window_)
849 window_->StackChildAbove(overscroll_window_.get(), GetContentNativeView());
850 else
851 window_->StackChildBelow(overscroll_window_.get(), GetContentNativeView());
852
853 UpdateOverscrollWindowBrightness(0.f);
854
855 overscroll_window_->SetBounds(bounds);
856 overscroll_window_->Show();
857
858 overscroll_shadow_.reset(new ShadowLayerDelegate(animate_window->layer()));
859 }
860
861 void WebContentsViewAura::PrepareContentWindowForOverscroll() {
862 StopObservingImplicitAnimations();
863 aura::Window* content = GetContentNativeView();
864 content->layer()->GetAnimator()->AbortAllAnimations();
865 content->SetTransform(gfx::Transform());
866 content->layer()->SetLayerBrightness(0.f);
867 }
868
869 void WebContentsViewAura::ResetOverscrollTransform() {
870 if (!web_contents_->GetRenderWidgetHostView())
871 return;
872 aura::Window* target = GetWindowToAnimateForOverscroll();
873 if (!target)
874 return;
875 {
876 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator());
877 settings.SetPreemptionStrategy(
878 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
879 settings.SetTweenType(gfx::Tween::EASE_OUT);
880 settings.AddObserver(this);
881 target->SetTransform(gfx::Transform());
882 }
883 {
884 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator());
885 settings.SetPreemptionStrategy(
886 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
887 settings.SetTweenType(gfx::Tween::EASE_OUT);
888 UpdateOverscrollWindowBrightness(0.f);
889 } 742 }
890 } 743 }
891 744
892 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) { 745 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) {
893 if (!web_contents_->GetRenderWidgetHostView()) 746 if (!web_contents_->GetRenderWidgetHostView())
894 return; 747 return;
895 748
896 // Animate out the current view first. Navigate to the requested history at
897 // the end of the animation.
898 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
899 return;
900
901 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated", 749 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated",
902 current_overscroll_gesture_, OVERSCROLL_COUNT); 750 current_overscroll_gesture_, OVERSCROLL_COUNT);
903 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>(
904 overscroll_window_->delegate());
905 delegate->stop_forwarding_events();
906 751
907 completed_overscroll_gesture_ = mode; 752 overscroll_window_animation_->OnOverscrollComplete(mode);
908 aura::Window* target = GetWindowToAnimateForOverscroll();
909 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator());
910 settings.SetPreemptionStrategy(
911 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
912 settings.SetTweenType(gfx::Tween::EASE_OUT);
913 settings.AddObserver(this);
914 gfx::Transform transform;
915 int content_width =
916 web_contents_->GetRenderWidgetHostView()->GetViewBounds().width();
917 float translate_x = static_cast<float>(mode == OVERSCROLL_WEST ?
918 -content_width : content_width);
919 transform.Translate(translate_x, 0);
920 target->SetTransform(transform);
921 UpdateOverscrollWindowBrightness(translate_x);
922 }
923
924 aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() {
925 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
926 return NULL;
927
928 return ShouldNavigateForward(web_contents_->GetController(),
929 current_overscroll_gesture_) ?
930 overscroll_window_.get() : GetContentNativeView();
931 }
932
933 gfx::Vector2dF WebContentsViewAura::GetTranslationForOverscroll(float delta_x,
934 float delta_y) {
935 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
936 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
937 return gfx::Vector2dF(0, delta_y);
938 }
939 // For horizontal overscroll, scroll freely if a navigation is possible. Do a
940 // resistive scroll otherwise.
941 const NavigationControllerImpl& controller = web_contents_->GetController();
942 const gfx::Rect& bounds = GetViewBounds();
943 const float bounds_width = static_cast<float>(bounds.width());
944 if (ShouldNavigateForward(controller, current_overscroll_gesture_))
945 return gfx::Vector2dF(std::max(-bounds_width, delta_x), 0);
946 else if (ShouldNavigateBack(controller, current_overscroll_gesture_))
947 return gfx::Vector2dF(std::min(bounds_width, delta_x), 0);
948 return gfx::Vector2dF();
949 }
950
951 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() {
952 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>(
953 overscroll_window_->delegate());
954 overscroll_window_->SchedulePaintInRect(
955 gfx::Rect(overscroll_window_->bounds().size()));
956 overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size()));
957 overscroll_window_->SetTransform(gfx::Transform());
958 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(),
959 delegate);
960 navigation_overlay_->StartObserving();
961 }
962
963 void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) {
964 if (!overscroll_change_brightness_)
965 return;
966
967 const float kBrightnessMin = -.1f;
968 const float kBrightnessMax = -.01f;
969
970 float ratio = fabs(delta_x) / GetViewBounds().width();
971 ratio = std::min(1.f, ratio);
972 if (base::i18n::IsRTL())
973 ratio = 1.f - ratio;
974 float brightness = current_overscroll_gesture_ == OVERSCROLL_WEST ?
975 kBrightnessMin + ratio * (kBrightnessMax - kBrightnessMin) :
976 kBrightnessMax - ratio * (kBrightnessMax - kBrightnessMin);
977 brightness = std::max(kBrightnessMin, brightness);
978 brightness = std::min(kBrightnessMax, brightness);
979 aura::Window* window = GetWindowToAnimateForOverscroll();
980 window->layer()->SetLayerBrightness(brightness);
981 } 753 }
982 754
983 void WebContentsViewAura::AttachTouchEditableToRenderView() { 755 void WebContentsViewAura::AttachTouchEditableToRenderView() {
984 if (!touch_editable_) 756 if (!touch_editable_)
985 return; 757 return;
986 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( 758 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura(
987 web_contents_->GetRenderWidgetHostView()); 759 web_contents_->GetRenderWidgetHostView());
988 touch_editable_->AttachToView(rwhva); 760 touch_editable_->AttachToView(rwhva);
989 } 761 }
990 762
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 DCHECK(RenderViewHostFactory::has_factory()); 901 DCHECK(RenderViewHostFactory::has_factory());
1130 return static_cast<RenderWidgetHostViewBase*>( 902 return static_cast<RenderWidgetHostViewBase*>(
1131 render_widget_host->GetView()); 903 render_widget_host->GetView());
1132 } 904 }
1133 905
1134 RenderWidgetHostViewAura* view = 906 RenderWidgetHostViewAura* view =
1135 new RenderWidgetHostViewAura(render_widget_host, is_guest_view_hack); 907 new RenderWidgetHostViewAura(render_widget_host, is_guest_view_hack);
1136 view->InitAsChild(NULL); 908 view->InitAsChild(NULL);
1137 GetNativeView()->AddChild(view->GetNativeView()); 909 GetNativeView()->AddChild(view->GetNativeView());
1138 910
1139 if (navigation_overlay_.get() && navigation_overlay_->has_window()) {
1140 navigation_overlay_->StartObserving();
1141 }
1142
1143 RenderWidgetHostImpl* host_impl = 911 RenderWidgetHostImpl* host_impl =
1144 RenderWidgetHostImpl::From(render_widget_host); 912 RenderWidgetHostImpl::From(render_widget_host);
1145 913
1146 if (!host_impl->is_hidden()) 914 if (!host_impl->is_hidden())
1147 view->Show(); 915 view->Show();
1148 916
1149 // We listen to drag drop events in the newly created view's window. 917 // We listen to drag drop events in the newly created view's window.
1150 aura::client::SetDragDropDelegate(view->GetNativeView(), this); 918 aura::client::SetDragDropDelegate(view->GetNativeView(), this);
1151 919
1152 if (view->overscroll_controller() && 920 if (view->overscroll_controller() &&
(...skipping 12 matching lines...) Expand all
1165 } 933 }
1166 934
1167 void WebContentsViewAura::SetPageTitle(const base::string16& title) { 935 void WebContentsViewAura::SetPageTitle(const base::string16& title) {
1168 window_->SetTitle(title); 936 window_->SetTitle(title);
1169 } 937 }
1170 938
1171 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { 939 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) {
1172 } 940 }
1173 941
1174 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { 942 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) {
1175 if (navigation_overlay_.get() && navigation_overlay_->has_window())
1176 navigation_overlay_->StartObserving();
1177 AttachTouchEditableToRenderView(); 943 AttachTouchEditableToRenderView();
1178 } 944 }
1179 945
1180 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { 946 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) {
1181 RenderWidgetHostViewAura* view = 947 RenderWidgetHostViewAura* view =
1182 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView()); 948 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView());
1183 if (view) { 949 if (view) {
1184 view->SetOverscrollControllerEnabled(enabled); 950 view->SetOverscrollControllerEnabled(enabled);
1185 if (enabled) 951 if (enabled)
1186 InstallOverscrollControllerDelegate(view); 952 InstallOverscrollControllerDelegate(view);
1187 } 953 }
1188 954
1189 if (!enabled) 955 if (!enabled) {
1190 navigation_overlay_.reset(); 956 navigation_overlay_.reset();
1191 else if (!navigation_overlay_) 957 overscroll_window_animation_ = nullptr;
1192 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 958 }
959 if (!navigation_overlay_) {
960 navigation_overlay_.reset(
961 new OverscrollNavigationOverlay(web_contents_, window_.get()));
962 overscroll_window_animation_ = navigation_overlay_->owa();
963 }
1193 } 964 }
1194 965
1195 //////////////////////////////////////////////////////////////////////////////// 966 ////////////////////////////////////////////////////////////////////////////////
1196 // WebContentsViewAura, RenderViewHostDelegateView implementation: 967 // WebContentsViewAura, RenderViewHostDelegateView implementation:
1197 968
1198 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host, 969 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host,
1199 const ContextMenuParams& params) { 970 const ContextMenuParams& params) {
1200 if (touch_editable_) { 971 if (touch_editable_) {
1201 touch_editable_->EndTouchEditing(false); 972 touch_editable_->EndTouchEditing(false);
1202 } 973 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 if (!rwhv || !rwhv->IsShowing()) 1074 if (!rwhv || !rwhv->IsShowing())
1304 return gfx::Rect(); 1075 return gfx::Rect();
1305 1076
1306 return rwhv->GetViewBounds(); 1077 return rwhv->GetViewBounds();
1307 } 1078 }
1308 1079
1309 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) { 1080 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) {
1310 if (current_overscroll_gesture_ == OVERSCROLL_NONE) 1081 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
1311 return false; 1082 return false;
1312 1083
1313 aura::Window* target = GetWindowToAnimateForOverscroll();
1314 gfx::Vector2dF translate = GetTranslationForOverscroll(delta_x, delta_y);
1315 gfx::Transform transform;
1316
1317 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || 1084 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
1318 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { 1085 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
1319 OverscrollUpdateForWebContentsDelegate(translate.y()); 1086 OverscrollUpdateForWebContentsDelegate(delta_y);
1320 } else { 1087 return delta_y != 0;
1321 // Only horizontal overscrolls participate in the navigation gesture.
1322 transform.Translate(translate.x(), translate.y());
1323 target->SetTransform(transform);
1324 UpdateOverscrollWindowBrightness(delta_x);
1325 } 1088 }
1326 1089 return overscroll_window_animation_->OnOverscrollUpdate(delta_x, delta_y);
1327 return !translate.IsZero();
1328 } 1090 }
1329 1091
1330 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) { 1092 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) {
1331 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT); 1093 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT);
1332 if (web_contents_->GetDelegate() && 1094 if (web_contents_->GetDelegate() &&
1333 IsScrollEndEffectEnabled() && 1095 IsScrollEndEffectEnabled() &&
1334 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) { 1096 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) {
1335 web_contents_->GetDelegate()->OverscrollComplete(); 1097 web_contents_->GetDelegate()->OverscrollComplete();
1336 } 1098 }
1337 NavigationControllerImpl& controller = web_contents_->GetController(); 1099 CompleteOverscrollNavigation(mode);
1338 if (ShouldNavigateForward(controller, mode) ||
1339 ShouldNavigateBack(controller, mode)) {
1340 CompleteOverscrollNavigation(mode);
1341 return;
1342 }
1343
1344 ResetOverscrollTransform();
1345 } 1100 }
1346 1101
1347 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode, 1102 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode,
1348 OverscrollMode new_mode) { 1103 OverscrollMode new_mode) {
1349 // Reset any in-progress overscroll animation first.
1350 ResetOverscrollTransform();
1351
1352 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH) 1104 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH)
1353 OverscrollUpdateForWebContentsDelegate(0); 1105 OverscrollUpdateForWebContentsDelegate(0);
1354 1106
1355 if (new_mode != OVERSCROLL_NONE && touch_editable_) 1107 if (new_mode != OVERSCROLL_NONE && touch_editable_)
1356 touch_editable_->OverscrollStarted(); 1108 touch_editable_->OverscrollStarted();
1357 1109
1358 if (new_mode == OVERSCROLL_NONE || 1110 if (current_overscroll_gesture_ == OVERSCROLL_NONE &&
1359 !GetContentNativeView() || 1111 new_mode != OVERSCROLL_NONE) {
1360 ((new_mode == OVERSCROLL_EAST || new_mode == OVERSCROLL_WEST) &&
1361 navigation_overlay_.get() && navigation_overlay_->has_window())) {
1362 current_overscroll_gesture_ = OVERSCROLL_NONE;
1363 } else {
1364 aura::Window* target = GetWindowToAnimateForOverscroll();
1365 if (target) {
1366 StopObservingImplicitAnimations();
1367 target->layer()->GetAnimator()->AbortAllAnimations();
1368 }
1369 // Cleanup state of the content window first, because that can reset the
1370 // value of |current_overscroll_gesture_|.
1371 PrepareContentWindowForOverscroll();
1372
1373 current_overscroll_gesture_ = new_mode;
1374 if (current_overscroll_gesture_ == OVERSCROLL_EAST ||
1375 current_overscroll_gesture_ == OVERSCROLL_WEST)
1376 PrepareOverscrollWindow();
1377
1378 UMA_HISTOGRAM_ENUMERATION("Overscroll.Started", new_mode, OVERSCROLL_COUNT); 1112 UMA_HISTOGRAM_ENUMERATION("Overscroll.Started", new_mode, OVERSCROLL_COUNT);
1379 } 1113 }
1114 current_overscroll_gesture_ = new_mode;
1115 overscroll_window_animation_->OnOverscrollModeChange(old_mode, new_mode);
1380 completed_overscroll_gesture_ = OVERSCROLL_NONE; 1116 completed_overscroll_gesture_ = OVERSCROLL_NONE;
1381 } 1117 }
1382 1118
1383 //////////////////////////////////////////////////////////////////////////////// 1119 ////////////////////////////////////////////////////////////////////////////////
1384 // WebContentsViewAura, ui::ImplicitAnimationObserver implementation:
1385
1386 void WebContentsViewAura::OnImplicitAnimationsCompleted() {
1387 overscroll_shadow_.reset();
1388
1389 if (ShouldNavigateForward(web_contents_->GetController(),
1390 completed_overscroll_gesture_)) {
1391 web_contents_->GetController().GoForward();
1392 PrepareOverscrollNavigationOverlay();
1393 } else if (ShouldNavigateBack(web_contents_->GetController(),
1394 completed_overscroll_gesture_)) {
1395 web_contents_->GetController().GoBack();
1396 PrepareOverscrollNavigationOverlay();
1397 } else {
1398 if (touch_editable_)
1399 touch_editable_->OverscrollCompleted();
1400 }
1401
1402 aura::Window* content = GetContentNativeView();
1403 if (content) {
1404 content->SetTransform(gfx::Transform());
1405 content->layer()->SetLayerBrightness(0.f);
1406 }
1407 current_overscroll_gesture_ = OVERSCROLL_NONE;
1408 completed_overscroll_gesture_ = OVERSCROLL_NONE;
1409 overscroll_window_.reset();
1410 }
1411
1412 ////////////////////////////////////////////////////////////////////////////////
1413 // WebContentsViewAura, aura::WindowDelegate implementation: 1120 // WebContentsViewAura, aura::WindowDelegate implementation:
1414 1121
1415 gfx::Size WebContentsViewAura::GetMinimumSize() const { 1122 gfx::Size WebContentsViewAura::GetMinimumSize() const {
1416 return gfx::Size(); 1123 return gfx::Size();
1417 } 1124 }
1418 1125
1419 gfx::Size WebContentsViewAura::GetMaximumSize() const { 1126 gfx::Size WebContentsViewAura::GetMaximumSize() const {
1420 return gfx::Size(); 1127 return gfx::Size();
1421 } 1128 }
1422 1129
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 float device_scale_factor) { 1186 float device_scale_factor) {
1480 } 1187 }
1481 1188
1482 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) { 1189 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) {
1483 // This means the destructor is going to be called soon. If there is an 1190 // This means the destructor is going to be called soon. If there is an
1484 // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL), 1191 // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL),
1485 // then destroying it in the WebContentsViewAura destructor can trigger other 1192 // then destroying it in the WebContentsViewAura destructor can trigger other
1486 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So 1193 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So
1487 // destroy the overscroll window here. 1194 // destroy the overscroll window here.
1488 navigation_overlay_.reset(); 1195 navigation_overlay_.reset();
1489 overscroll_window_.reset(); 1196 overscroll_window_animation_ = nullptr;
1490 } 1197 }
1491 1198
1492 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { 1199 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) {
1493 } 1200 }
1494 1201
1495 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1202 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1496 } 1203 }
1497 1204
1498 bool WebContentsViewAura::HasHitTestMask() const { 1205 bool WebContentsViewAura::HasHitTestMask() const {
1499 return false; 1206 return false;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 if (visible) { 1348 if (visible) {
1642 if (!web_contents_->should_normally_be_visible()) 1349 if (!web_contents_->should_normally_be_visible())
1643 web_contents_->WasShown(); 1350 web_contents_->WasShown();
1644 } else { 1351 } else {
1645 if (web_contents_->should_normally_be_visible()) 1352 if (web_contents_->should_normally_be_visible())
1646 web_contents_->WasHidden(); 1353 web_contents_->WasHidden();
1647 } 1354 }
1648 } 1355 }
1649 1356
1650 } // namespace content 1357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698