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

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: New design with window|wrapper in OWA 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 return; 721 return;
794 } 722 }
795 if (value == "2") { 723 if (value == "2") {
796 navigation_overlay_.reset(); 724 navigation_overlay_.reset();
797 if (!gesture_nav_simple_) 725 if (!gesture_nav_simple_)
798 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_)); 726 gesture_nav_simple_.reset(new GestureNavSimple(web_contents_));
799 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get()); 727 view->overscroll_controller()->set_delegate(gesture_nav_simple_.get());
800 return; 728 return;
801 } 729 }
802 view->overscroll_controller()->set_delegate(this); 730 view->overscroll_controller()->set_delegate(this);
803 if (!navigation_overlay_) 731 LOG(ERROR) << "Installing OCD";
804 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 732 if (!overscroll_window_animation_) {
mfomitchev 2015/03/06 01:36:43 Can we do the same thing for overscroll_window_ani
Nina 2015/03/09 15:54:53 Done.
805 } 733 overscroll_window_animation_.reset(
806 734 new OverscrollWindowAnimation());
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(&current_overscroll_gesture_,
815 current_overscroll_gesture_);
816 scoped_ptr<aura::Window> reset_window(overscroll_window_.release());
817 } 735 }
818 736 if (!navigation_overlay_) {
819 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( 737 navigation_overlay_.reset(
820 web_contents_, 738 new OverscrollNavigationOverlay(web_contents_,
821 current_overscroll_gesture_); 739 overscroll_window_animation_.get(),
822 overscroll_window_.reset(new aura::Window(overscroll_delegate)); 740 window_.get()));
823 overscroll_window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 741 overscroll_window_animation_->set_delegate(navigation_overlay_.get());
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 } 742 }
840 743 LOG(ERROR) << "Installing overscroll window animation controller";
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 } 744 }
854 745
855 void WebContentsViewAura::PrepareContentWindowForOverscroll() { 746 void WebContentsViewAura::PrepareContentWindowForOverscroll() {
856 StopObservingImplicitAnimations();
857 aura::Window* content = GetContentNativeView(); 747 aura::Window* content = GetContentNativeView();
858 content->layer()->GetAnimator()->AbortAllAnimations(); 748 content->layer()->GetAnimator()->AbortAllAnimations();
859 content->SetTransform(gfx::Transform()); 749 content->SetTransform(gfx::Transform());
860 content->layer()->SetLayerBrightness(0.f); 750 content->layer()->SetLayerBrightness(0.f);
861 } 751 }
862 752
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 }
884 }
885
886 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) { 753 void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) {
887 if (!web_contents_->GetRenderWidgetHostView()) 754 if (!web_contents_->GetRenderWidgetHostView())
888 return; 755 return;
889 756
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", 757 UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated",
896 current_overscroll_gesture_, OVERSCROLL_COUNT); 758 current_overscroll_gesture_, OVERSCROLL_COUNT);
897 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>(
898 overscroll_window_->delegate());
899 delegate->stop_forwarding_events();
900 759
901 completed_overscroll_gesture_ = mode; 760 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 } 761 }
976 762
977 void WebContentsViewAura::AttachTouchEditableToRenderView() { 763 void WebContentsViewAura::AttachTouchEditableToRenderView() {
978 if (!touch_editable_) 764 if (!touch_editable_)
979 return; 765 return;
980 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( 766 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura(
981 web_contents_->GetRenderWidgetHostView()); 767 web_contents_->GetRenderWidgetHostView());
982 touch_editable_->AttachToView(rwhva); 768 touch_editable_->AttachToView(rwhva);
983 } 769 }
984 770
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 DCHECK(RenderViewHostFactory::has_factory()); 909 DCHECK(RenderViewHostFactory::has_factory());
1124 return static_cast<RenderWidgetHostViewBase*>( 910 return static_cast<RenderWidgetHostViewBase*>(
1125 render_widget_host->GetView()); 911 render_widget_host->GetView());
1126 } 912 }
1127 913
1128 RenderWidgetHostViewAura* view = 914 RenderWidgetHostViewAura* view =
1129 new RenderWidgetHostViewAura(render_widget_host, is_guest_view_hack); 915 new RenderWidgetHostViewAura(render_widget_host, is_guest_view_hack);
1130 view->InitAsChild(NULL); 916 view->InitAsChild(NULL);
1131 GetNativeView()->AddChild(view->GetNativeView()); 917 GetNativeView()->AddChild(view->GetNativeView());
1132 918
1133 if (navigation_overlay_.get() && navigation_overlay_->has_window()) {
1134 navigation_overlay_->StartObserving();
1135 }
1136
1137 RenderWidgetHostImpl* host_impl = 919 RenderWidgetHostImpl* host_impl =
1138 RenderWidgetHostImpl::From(render_widget_host); 920 RenderWidgetHostImpl::From(render_widget_host);
1139 921
1140 if (!host_impl->is_hidden()) 922 if (!host_impl->is_hidden())
1141 view->Show(); 923 view->Show();
1142 924
1143 // We listen to drag drop events in the newly created view's window. 925 // We listen to drag drop events in the newly created view's window.
1144 aura::client::SetDragDropDelegate(view->GetNativeView(), this); 926 aura::client::SetDragDropDelegate(view->GetNativeView(), this);
1145 927
1146 if (view->overscroll_controller() && 928 if (view->overscroll_controller() &&
(...skipping 12 matching lines...) Expand all
1159 } 941 }
1160 942
1161 void WebContentsViewAura::SetPageTitle(const base::string16& title) { 943 void WebContentsViewAura::SetPageTitle(const base::string16& title) {
1162 window_->SetTitle(title); 944 window_->SetTitle(title);
1163 } 945 }
1164 946
1165 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { 947 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) {
1166 } 948 }
1167 949
1168 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { 950 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) {
1169 if (navigation_overlay_.get() && navigation_overlay_->has_window())
1170 navigation_overlay_->StartObserving();
1171 AttachTouchEditableToRenderView(); 951 AttachTouchEditableToRenderView();
1172 } 952 }
1173 953
1174 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { 954 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) {
1175 RenderWidgetHostViewAura* view = 955 RenderWidgetHostViewAura* view =
1176 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView()); 956 ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView());
1177 if (view) { 957 if (view) {
1178 view->SetOverscrollControllerEnabled(enabled); 958 view->SetOverscrollControllerEnabled(enabled);
1179 if (enabled) 959 if (enabled)
1180 InstallOverscrollControllerDelegate(view); 960 InstallOverscrollControllerDelegate(view);
1181 } 961 }
1182 962
1183 if (!enabled) 963 if (!enabled)
1184 navigation_overlay_.reset(); 964 navigation_overlay_.reset();
mfomitchev 2015/03/06 01:36:43 reset OWA here as well
Nina 2015/03/09 15:54:53 Done.
1185 else if (!navigation_overlay_) 965 // TODO maybe we can delete this code, as it should be applied in
1186 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 966 // InstallOverscrollControllerDelegate?
967 LOG(ERROR) << "Installing OCD";
968 if (!overscroll_window_animation_) {
mfomitchev 2015/03/06 01:36:43 remove this if
Nina 2015/03/09 15:54:53 Done.
969 overscroll_window_animation_.reset(
970 new OverscrollWindowAnimation());
971 } else if (!navigation_overlay_) {
972 navigation_overlay_.reset(
mfomitchev 2015/03/06 01:36:43 Create OWA here as well
Nina 2015/03/09 15:54:53 I rewrote this. OWA is now created on overscroll u
mfomitchev 2015/03/10 19:25:59 Hmm.. I don't really like that we are initializing
Nina 2015/03/12 22:21:28 Done.
973 new OverscrollNavigationOverlay(web_contents_,
974 overscroll_window_animation_.get(),
975 window_.get()));
976 overscroll_window_animation_->set_delegate(navigation_overlay_.get());
977 }
1187 } 978 }
1188 979
1189 //////////////////////////////////////////////////////////////////////////////// 980 ////////////////////////////////////////////////////////////////////////////////
1190 // WebContentsViewAura, RenderViewHostDelegateView implementation: 981 // WebContentsViewAura, RenderViewHostDelegateView implementation:
1191 982
1192 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host, 983 void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host,
1193 const ContextMenuParams& params) { 984 const ContextMenuParams& params) {
1194 if (touch_editable_) { 985 if (touch_editable_) {
1195 touch_editable_->EndTouchEditing(false); 986 touch_editable_->EndTouchEditing(false);
1196 } 987 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 if (!rwhv || !rwhv->IsShowing()) 1088 if (!rwhv || !rwhv->IsShowing())
1298 return gfx::Rect(); 1089 return gfx::Rect();
1299 1090
1300 return rwhv->GetViewBounds(); 1091 return rwhv->GetViewBounds();
1301 } 1092 }
1302 1093
1303 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) { 1094 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) {
1304 if (current_overscroll_gesture_ == OVERSCROLL_NONE) 1095 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
1305 return false; 1096 return false;
1306 1097
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 || 1098 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
1312 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { 1099 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
1313 OverscrollUpdateForWebContentsDelegate(translate.y()); 1100 OverscrollUpdateForWebContentsDelegate(delta_y);
1314 } else { 1101 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 } 1102 }
1320 1103 // Only horizontal overscrolls participate in the navigation gesture.
mfomitchev 2015/03/06 01:36:43 shouldn't this be inside else like it was before?
Nina 2015/03/09 15:54:53 We have a return on the other if, no need for an e
1321 return !translate.IsZero(); 1104 if (!overscroll_window_animation_)
mfomitchev 2015/03/06 01:36:43 Is this even possible? Previous flow ddidn't accou
Nina 2015/03/09 15:54:53 TBH I don't know as I didn't look much at the code
mfomitchev 2015/03/10 19:25:59 I think overscroll events won't go to WCVA in the
Nina 2015/03/12 22:21:28 Acknowledged.
1105 return false;
1106 return overscroll_window_animation_->OnOverscrollUpdate(delta_x, delta_y);
1322 } 1107 }
1323 1108
1324 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) { 1109 void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) {
1325 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT); 1110 UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT);
1111 LOG(ERROR) << "OVERSCROLL COMPLETE";
1326 if (web_contents_->GetDelegate() && 1112 if (web_contents_->GetDelegate() &&
1327 IsScrollEndEffectEnabled() && 1113 IsScrollEndEffectEnabled() &&
1328 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) { 1114 (mode == OVERSCROLL_NORTH || mode == OVERSCROLL_SOUTH)) {
1329 web_contents_->GetDelegate()->OverscrollComplete(); 1115 web_contents_->GetDelegate()->OverscrollComplete();
1330 } 1116 }
1331 NavigationControllerImpl& controller = web_contents_->GetController(); 1117 CompleteOverscrollNavigation(mode);
1332 if (ShouldNavigateForward(controller, mode) ||
1333 ShouldNavigateBack(controller, mode)) {
1334 CompleteOverscrollNavigation(mode);
1335 return;
1336 }
1337
1338 ResetOverscrollTransform();
1339 } 1118 }
1340 1119
1341 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode, 1120 void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode,
1342 OverscrollMode new_mode) { 1121 OverscrollMode new_mode) {
1122 LOG(ERROR) << "Overscroll mode change";
1343 // Reset any in-progress overscroll animation first. 1123 // Reset any in-progress overscroll animation first.
1344 ResetOverscrollTransform(); 1124 // ResetOverscrollTransform();
1345 1125
1346 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH) 1126 if (old_mode == OVERSCROLL_NORTH || old_mode == OVERSCROLL_SOUTH)
1347 OverscrollUpdateForWebContentsDelegate(0); 1127 OverscrollUpdateForWebContentsDelegate(0);
1348 1128
1349 if (new_mode != OVERSCROLL_NONE && touch_editable_) 1129 if (new_mode != OVERSCROLL_NONE && touch_editable_)
1350 touch_editable_->OverscrollStarted(); 1130 touch_editable_->OverscrollStarted();
1351 1131
1132 overscroll_window_animation_->set_live_window(GetContentNativeView());
mfomitchev 2015/03/05 23:37:06 Calling this every time the mode changes seems exc
Nina 2015/03/09 15:54:53 Yes, but it was necessary. I changed it so that we
1352 if (new_mode == OVERSCROLL_NONE || 1133 if (new_mode == OVERSCROLL_NONE ||
1353 !GetContentNativeView() || 1134 !GetContentNativeView() ||
1354 ((new_mode == OVERSCROLL_EAST || new_mode == OVERSCROLL_WEST) && 1135 ((new_mode == OVERSCROLL_EAST || new_mode == OVERSCROLL_WEST) &&
1355 navigation_overlay_.get() && navigation_overlay_->has_window())) { 1136 overscroll_window_animation_ &&
1137 overscroll_window_animation_->is_active())) {
1356 current_overscroll_gesture_ = OVERSCROLL_NONE; 1138 current_overscroll_gesture_ = OVERSCROLL_NONE;
1139 overscroll_window_animation_->OnOverscrollModeChange(old_mode,
1140 OVERSCROLL_NONE);
1357 } else { 1141 } else {
1358 aura::Window* target = GetWindowToAnimateForOverscroll(); 1142 current_overscroll_gesture_ = new_mode;
1359 if (target) { 1143 if (overscroll_window_animation_)
1360 StopObservingImplicitAnimations(); 1144 overscroll_window_animation_->OnOverscrollModeChange(old_mode, new_mode);
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(); 1145 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);
mfomitchev 2015/03/06 01:36:43 Looks like we lost this histogram
Nina 2015/03/09 15:54:53 Brought back
1373 } 1146 }
1374 completed_overscroll_gesture_ = OVERSCROLL_NONE; 1147 completed_overscroll_gesture_ = OVERSCROLL_NONE;
1375 } 1148 }
1376 1149
1377 //////////////////////////////////////////////////////////////////////////////// 1150 ////////////////////////////////////////////////////////////////////////////////
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: 1151 // WebContentsViewAura, aura::WindowDelegate implementation:
1408 1152
1409 gfx::Size WebContentsViewAura::GetMinimumSize() const { 1153 gfx::Size WebContentsViewAura::GetMinimumSize() const {
1410 return gfx::Size(); 1154 return gfx::Size();
1411 } 1155 }
1412 1156
1413 gfx::Size WebContentsViewAura::GetMaximumSize() const { 1157 gfx::Size WebContentsViewAura::GetMaximumSize() const {
1414 return gfx::Size(); 1158 return gfx::Size();
1415 } 1159 }
1416 1160
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 float device_scale_factor) { 1217 float device_scale_factor) {
1474 } 1218 }
1475 1219
1476 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) { 1220 void WebContentsViewAura::OnWindowDestroying(aura::Window* window) {
1477 // This means the destructor is going to be called soon. If there is an 1221 // 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), 1222 // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL),
1479 // then destroying it in the WebContentsViewAura destructor can trigger other 1223 // then destroying it in the WebContentsViewAura destructor can trigger other
1480 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So 1224 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So
1481 // destroy the overscroll window here. 1225 // destroy the overscroll window here.
1482 navigation_overlay_.reset(); 1226 navigation_overlay_.reset();
1483 overscroll_window_.reset(); 1227 overscroll_window_animation_.reset();
1484 } 1228 }
1485 1229
1486 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { 1230 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) {
1487 } 1231 }
1488 1232
1489 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1233 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1490 } 1234 }
1491 1235
1492 bool WebContentsViewAura::HasHitTestMask() const { 1236 bool WebContentsViewAura::HasHitTestMask() const {
1493 return false; 1237 return false;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 if (visible) { 1379 if (visible) {
1636 if (!web_contents_->should_normally_be_visible()) 1380 if (!web_contents_->should_normally_be_visible())
1637 web_contents_->WasShown(); 1381 web_contents_->WasShown();
1638 } else { 1382 } else {
1639 if (web_contents_->should_normally_be_visible()) 1383 if (web_contents_->should_normally_be_visible())
1640 web_contents_->WasHidden(); 1384 web_contents_->WasHidden();
1641 } 1385 }
1642 } 1386 }
1643 1387
1644 } // namespace content 1388 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698