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

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

Issue 645223003: Change overscroll functions to pass floats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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"
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 completed_overscroll_gesture_ = mode; 905 completed_overscroll_gesture_ = mode;
906 aura::Window* target = GetWindowToAnimateForOverscroll(); 906 aura::Window* target = GetWindowToAnimateForOverscroll();
907 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator()); 907 ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator());
908 settings.SetPreemptionStrategy( 908 settings.SetPreemptionStrategy(
909 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 909 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
910 settings.SetTweenType(gfx::Tween::EASE_OUT); 910 settings.SetTweenType(gfx::Tween::EASE_OUT);
911 settings.AddObserver(this); 911 settings.AddObserver(this);
912 gfx::Transform transform; 912 gfx::Transform transform;
913 int content_width = 913 int content_width =
914 web_contents_->GetRenderWidgetHostView()->GetViewBounds().width(); 914 web_contents_->GetRenderWidgetHostView()->GetViewBounds().width();
915 int translate_x = mode == OVERSCROLL_WEST ? -content_width : content_width; 915 float translate_x = static_cast<float>(mode == OVERSCROLL_WEST ?
916 -content_width : content_width);
Peter Kasting 2014/10/11 00:11:06 Technically, this change isn't part of the rest of
916 transform.Translate(translate_x, 0); 917 transform.Translate(translate_x, 0);
917 target->SetTransform(transform); 918 target->SetTransform(transform);
918 UpdateOverscrollWindowBrightness(translate_x); 919 UpdateOverscrollWindowBrightness(translate_x);
919 } 920 }
920 921
921 aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() { 922 aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() {
922 if (current_overscroll_gesture_ == OVERSCROLL_NONE) 923 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
923 return NULL; 924 return NULL;
924 925
925 return ShouldNavigateForward(web_contents_->GetController(), 926 return ShouldNavigateForward(web_contents_->GetController(),
926 current_overscroll_gesture_) ? 927 current_overscroll_gesture_) ?
927 overscroll_window_.get() : GetContentNativeView(); 928 overscroll_window_.get() : GetContentNativeView();
928 } 929 }
929 930
930 gfx::Vector2d WebContentsViewAura::GetTranslationForOverscroll(int delta_x, 931 gfx::Vector2dF WebContentsViewAura::GetTranslationForOverscroll(float delta_x,
931 int delta_y) { 932 float delta_y) {
932 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || 933 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
933 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { 934 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
934 return gfx::Vector2d(0, delta_y); 935 return gfx::Vector2dF(0, delta_y);
935 } 936 }
936 // For horizontal overscroll, scroll freely if a navigation is possible. Do a 937 // For horizontal overscroll, scroll freely if a navigation is possible. Do a
937 // resistive scroll otherwise. 938 // resistive scroll otherwise.
938 const NavigationControllerImpl& controller = web_contents_->GetController(); 939 const NavigationControllerImpl& controller = web_contents_->GetController();
939 const gfx::Rect& bounds = GetViewBounds(); 940 const gfx::Rect& bounds = GetViewBounds();
941 const float bounds_width = static_cast<float>(bounds.width());
940 if (ShouldNavigateForward(controller, current_overscroll_gesture_)) 942 if (ShouldNavigateForward(controller, current_overscroll_gesture_))
941 return gfx::Vector2d(std::max(-bounds.width(), delta_x), 0); 943 return gfx::Vector2dF(std::max(-bounds_width, delta_x), 0);
942 else if (ShouldNavigateBack(controller, current_overscroll_gesture_)) 944 else if (ShouldNavigateBack(controller, current_overscroll_gesture_))
943 return gfx::Vector2d(std::min(bounds.width(), delta_x), 0); 945 return gfx::Vector2dF(std::min(bounds_width, delta_x), 0);
944 return gfx::Vector2d(); 946 return gfx::Vector2dF();
945 } 947 }
946 948
947 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() { 949 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() {
948 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( 950 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>(
949 overscroll_window_->delegate()); 951 overscroll_window_->delegate());
950 overscroll_window_->SchedulePaintInRect( 952 overscroll_window_->SchedulePaintInRect(
951 gfx::Rect(overscroll_window_->bounds().size())); 953 gfx::Rect(overscroll_window_->bounds().size()));
952 overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size())); 954 overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size()));
953 overscroll_window_->SetTransform(gfx::Transform()); 955 overscroll_window_->SetTransform(gfx::Transform());
954 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(), 956 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(),
(...skipping 22 matching lines...) Expand all
977 } 979 }
978 980
979 void WebContentsViewAura::AttachTouchEditableToRenderView() { 981 void WebContentsViewAura::AttachTouchEditableToRenderView() {
980 if (!touch_editable_) 982 if (!touch_editable_)
981 return; 983 return;
982 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( 984 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura(
983 web_contents_->GetRenderWidgetHostView()); 985 web_contents_->GetRenderWidgetHostView());
984 touch_editable_->AttachToView(rwhva); 986 touch_editable_->AttachToView(rwhva);
985 } 987 }
986 988
987 void WebContentsViewAura::OverscrollUpdateForWebContentsDelegate(int delta_y) { 989 void WebContentsViewAura::OverscrollUpdateForWebContentsDelegate(
990 float delta_y) {
988 if (web_contents_->GetDelegate() && IsScrollEndEffectEnabled()) 991 if (web_contents_->GetDelegate() && IsScrollEndEffectEnabled())
989 web_contents_->GetDelegate()->OverscrollUpdate(delta_y); 992 web_contents_->GetDelegate()->OverscrollUpdate(delta_y);
990 } 993 }
991 994
992 //////////////////////////////////////////////////////////////////////////////// 995 ////////////////////////////////////////////////////////////////////////////////
993 // WebContentsViewAura, WebContentsView implementation: 996 // WebContentsViewAura, WebContentsView implementation:
994 997
995 gfx::NativeView WebContentsViewAura::GetNativeView() const { 998 gfx::NativeView WebContentsViewAura::GetNativeView() const {
996 return window_.get(); 999 return window_.get();
997 } 1000 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 return gfx::Rect(); 1298 return gfx::Rect();
1296 1299
1297 return rwhv->GetViewBounds(); 1300 return rwhv->GetViewBounds();
1298 } 1301 }
1299 1302
1300 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) { 1303 bool WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) {
1301 if (current_overscroll_gesture_ == OVERSCROLL_NONE) 1304 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
1302 return false; 1305 return false;
1303 1306
1304 aura::Window* target = GetWindowToAnimateForOverscroll(); 1307 aura::Window* target = GetWindowToAnimateForOverscroll();
1305 gfx::Vector2d translate = GetTranslationForOverscroll(delta_x, delta_y); 1308 gfx::Vector2dF translate = GetTranslationForOverscroll(delta_x, delta_y);
1306 gfx::Transform transform; 1309 gfx::Transform transform;
1307 1310
1308 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || 1311 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
1309 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { 1312 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
1310 OverscrollUpdateForWebContentsDelegate(translate.y()); 1313 OverscrollUpdateForWebContentsDelegate(translate.y());
1311 } else { 1314 } else {
1312 // Only horizontal overscrolls participate in the navigation gesture. 1315 // Only horizontal overscrolls participate in the navigation gesture.
1313 transform.Translate(translate.x(), translate.y()); 1316 transform.Translate(translate.x(), translate.y());
1314 target->SetTransform(transform); 1317 target->SetTransform(transform);
1315 UpdateOverscrollWindowBrightness(delta_x); 1318 UpdateOverscrollWindowBrightness(delta_x);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 if (visible) { 1631 if (visible) {
1629 if (!web_contents_->should_normally_be_visible()) 1632 if (!web_contents_->should_normally_be_visible())
1630 web_contents_->WasShown(); 1633 web_contents_->WasShown();
1631 } else { 1634 } else {
1632 if (web_contents_->should_normally_be_visible()) 1635 if (web_contents_->should_normally_be_visible())
1633 web_contents_->WasHidden(); 1636 web_contents_->WasHidden();
1634 } 1637 }
1635 } 1638 }
1636 1639
1637 } // namespace content 1640 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698