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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollAnimatorBase.cpp

Issue 1738243002: Removed main-thread one dimensional scrolling paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@removeStepFromUserScroll
Patch Set: Rebase Created 4 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 /* 1 /*
2 * Copyright (c) 2010, Google Inc. All rights reserved. 2 * Copyright (c) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 #include "platform/RuntimeEnabledFeatures.h" 33 #include "platform/RuntimeEnabledFeatures.h"
34 #include "platform/geometry/FloatPoint.h" 34 #include "platform/geometry/FloatPoint.h"
35 #include "platform/scroll/ScrollableArea.h" 35 #include "platform/scroll/ScrollableArea.h"
36 #include "wtf/MathExtras.h" 36 #include "wtf/MathExtras.h"
37 #include "wtf/PassOwnPtr.h" 37 #include "wtf/PassOwnPtr.h"
38 38
39 namespace blink { 39 namespace blink {
40 40
41 ScrollAnimatorBase::ScrollAnimatorBase(ScrollableArea* scrollableArea) 41 ScrollAnimatorBase::ScrollAnimatorBase(ScrollableArea* scrollableArea)
42 : m_scrollableArea(scrollableArea) 42 : m_scrollableArea(scrollableArea)
43 , m_currentPosX(0)
44 , m_currentPosY(0)
45 { 43 {
46 } 44 }
47 45
48 ScrollAnimatorBase::~ScrollAnimatorBase() 46 ScrollAnimatorBase::~ScrollAnimatorBase()
49 { 47 {
50 } 48 }
51 49
52 float ScrollAnimatorBase::computeDeltaToConsume(ScrollbarOrientation orientation , float pixelDelta) const 50 FloatSize ScrollAnimatorBase::computeDeltaToConsume(const FloatSize& delta) cons t
53 { 51 {
54 float currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m_ currentPosY; 52 FloatPoint newPos = toFloatPoint(m_scrollableArea->clampScrollPosition(m_cur rentPos + delta));
55 float newPos = clampScrollPosition(orientation, currentPos + pixelDelta); 53 return newPos - m_currentPos;
56 return (currentPos == newPos) ? 0.0f : (newPos - currentPos);
57 } 54 }
58 55
59 ScrollResultOneDimensional ScrollAnimatorBase::userScroll(ScrollbarOrientation o rientation, ScrollGranularity, float delta) 56 ScrollResult ScrollAnimatorBase::userScroll(ScrollGranularity, const FloatSize& delta)
60 { 57 {
61 float& currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m _currentPosY; 58 FloatSize consumedDelta = computeDeltaToConsume(delta);
62 float usedDelta = computeDeltaToConsume(orientation, delta); 59 FloatPoint newPos = m_currentPos + consumedDelta;
63 float newPos = currentPos + usedDelta; 60 if (m_currentPos == newPos)
64 if (currentPos == newPos) 61 return ScrollResult(false, false, delta.width(), delta.height());
65 return ScrollResultOneDimensional(false, delta);
66 62
67 currentPos = newPos; 63 m_currentPos = newPos;
68 64
69 notifyPositionChanged(); 65 notifyPositionChanged();
70 66
71 return ScrollResultOneDimensional(true, delta - usedDelta); 67 return ScrollResult(
68 consumedDelta.width(),
69 consumedDelta.height(),
70 delta.width() - consumedDelta.width(),
71 delta.height() - consumedDelta.height());
72 } 72 }
73 73
74 void ScrollAnimatorBase::scrollToOffsetWithoutAnimation(const FloatPoint& offset ) 74 void ScrollAnimatorBase::scrollToOffsetWithoutAnimation(const FloatPoint& offset )
75 { 75 {
76 m_currentPosX = offset.x(); 76 m_currentPos = offset;
77 m_currentPosY = offset.y();
78 notifyPositionChanged(); 77 notifyPositionChanged();
79 } 78 }
80 79
81 void ScrollAnimatorBase::setCurrentPosition(const FloatPoint& position) 80 void ScrollAnimatorBase::setCurrentPosition(const FloatPoint& position)
82 { 81 {
83 m_currentPosX = position.x(); 82 m_currentPos = position;
84 m_currentPosY = position.y();
85 } 83 }
86 84
87 FloatPoint ScrollAnimatorBase::currentPosition() const 85 FloatPoint ScrollAnimatorBase::currentPosition() const
88 { 86 {
89 return FloatPoint(m_currentPosX, m_currentPosY); 87 return m_currentPos;
90 } 88 }
91 89
92 void ScrollAnimatorBase::notifyPositionChanged() 90 void ScrollAnimatorBase::notifyPositionChanged()
93 { 91 {
94 m_scrollableArea->scrollPositionChanged(DoublePoint(m_currentPosX, m_current PosY), UserScroll); 92 m_scrollableArea->scrollPositionChanged(m_currentPos, UserScroll);
95 }
96
97 float ScrollAnimatorBase::clampScrollPosition(ScrollbarOrientation orientation, float pos) const
98 {
99 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation);
100 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation);
101 return clampTo(pos, minScrollPos, maxScrollPos);
102 } 93 }
103 94
104 DEFINE_TRACE(ScrollAnimatorBase) 95 DEFINE_TRACE(ScrollAnimatorBase)
105 { 96 {
106 visitor->trace(m_scrollableArea); 97 visitor->trace(m_scrollableArea);
107 ScrollAnimatorCompositorCoordinator::trace(visitor); 98 ScrollAnimatorCompositorCoordinator::trace(visitor);
108 } 99 }
109 100
110 } // namespace blink 101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698