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

Side by Side Diff: Source/platform/scroll/ScrollAnimator.cpp

Issue 1195803003: Report accurate Overscroll on handleWheel. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed review comments and added testcase. Created 5 years, 5 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
« no previous file with comments | « Source/core/input/EventHandler.cpp ('k') | Source/web/WebSettingsImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 float deltaY = canScrollY ? e.deltaY() : 0; 85 float deltaY = canScrollY ? e.deltaY() : 0;
86 86
87 ScrollResult result; 87 ScrollResult result;
88 88
89 #if !OS(MACOSX) 89 #if !OS(MACOSX)
90 ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrec isePixel : ScrollByPixel; 90 ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrec isePixel : ScrollByPixel;
91 #else 91 #else
92 ScrollGranularity granularity = ScrollByPixel; 92 ScrollGranularity granularity = ScrollByPixel;
93 #endif 93 #endif
94 94
95 IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() - m_scrollableArea->scrollPosition(); 95 IntPoint currentPos = m_scrollableArea->scrollPosition();
bokan 2015/06/25 14:54:35 Sorry, I (slightly) misled you before. We can't ju
MuVen 2015/06/25 17:05:35 Done.
96 IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scro llableArea->minimumScrollPosition(); 96 if (deltaY) {
97 if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) 97 if (e.granularity() == ScrollByPageWheelEvent) {
98 || (deltaX > 0 && maxBackwardScrollDelta.width() > 0)) 98 bool negative = deltaY < 0;
99 result.didScrollX = true; 99 deltaY = m_scrollableArea->pageStep(VerticalScrollbar);
100 if ((deltaY < 0 && maxForwardScrollDelta.height() > 0) 100 if (negative)
101 || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) 101 deltaY = -deltaY;
102 result.didScrollY = true;
103 if (result.didScroll()) {
104 if (deltaY) {
105 if (e.granularity() == ScrollByPageWheelEvent) {
106 bool negative = deltaY < 0;
107 deltaY = m_scrollableArea->pageStep(VerticalScrollbar);
108 if (negative)
109 deltaY = -deltaY;
110 }
111
112 ScrollResultOneDimensional resultY = userScroll(
113 VerticalScrollbar, granularity, m_scrollableArea->pixelStep(Vert icalScrollbar), -deltaY);
114
115 if (e.granularity() != ScrollByPageWheelEvent) {
116 if (resultY.didScroll)
117 result.unusedScrollDeltaY = -resultY.unusedScrollDelta;
118 else
119 result.unusedScrollDeltaY = deltaY;
120 }
121 } 102 }
122 103
123 if (deltaX) { 104 ScrollResultOneDimensional resultY = userScroll(
124 if (e.granularity() == ScrollByPageWheelEvent) { 105 VerticalScrollbar, granularity, m_scrollableArea->pixelStep(Vertical Scrollbar), -deltaY);
125 bool negative = deltaX < 0;
126 deltaX = m_scrollableArea->pageStep(HorizontalScrollbar);
127 if (negative)
128 deltaX = -deltaX;
129 }
130 106
131 ScrollResultOneDimensional resultX = userScroll( 107 if (e.granularity() != ScrollByPageWheelEvent) {
132 HorizontalScrollbar, granularity, m_scrollableArea->pixelStep(Ho rizontalScrollbar), -deltaX); 108 if (resultY.didScroll)
133 109 result.unusedScrollDeltaY = -resultY.unusedScrollDelta;
134 if (e.granularity() != ScrollByPageWheelEvent) { 110 else
135 if (resultX.didScroll) 111 result.unusedScrollDeltaY = deltaY;
136 result.unusedScrollDeltaX = -resultX.unusedScrollDelta;
137 else
138 result.unusedScrollDeltaX = deltaX;
139 }
140 } 112 }
141 } 113 }
142 114
115 if (deltaX) {
116 if (e.granularity() == ScrollByPageWheelEvent) {
117 bool negative = deltaX < 0;
118 deltaX = m_scrollableArea->pageStep(HorizontalScrollbar);
119 if (negative)
120 deltaX = -deltaX;
121 }
122
123 ScrollResultOneDimensional resultX = userScroll(
124 HorizontalScrollbar, granularity, m_scrollableArea->pixelStep(Horizo ntalScrollbar), -deltaX);
125
126 if (e.granularity() != ScrollByPageWheelEvent) {
127 if (resultX.didScroll)
128 result.unusedScrollDeltaX = -resultX.unusedScrollDelta;
129 else
130 result.unusedScrollDeltaX = deltaX;
131 }
132 }
133
134 IntPoint newPos = m_scrollableArea->scrollPosition();
135 result.didScrollX = newPos.x() != currentPos.x();
136 result.didScrollY = newPos.y() != currentPos.y();
143 return result; 137 return result;
144 } 138 }
145 139
146 void ScrollAnimator::setCurrentPosition(const FloatPoint& position) 140 void ScrollAnimator::setCurrentPosition(const FloatPoint& position)
147 { 141 {
148 m_currentPosX = position.x(); 142 m_currentPosX = position.x();
149 m_currentPosY = position.y(); 143 m_currentPosY = position.y();
150 } 144 }
151 145
152 FloatPoint ScrollAnimator::currentPosition() const 146 FloatPoint ScrollAnimator::currentPosition() const
153 { 147 {
154 return FloatPoint(m_currentPosX, m_currentPosY); 148 return FloatPoint(m_currentPosX, m_currentPosY);
155 } 149 }
156 150
157 void ScrollAnimator::notifyPositionChanged() 151 void ScrollAnimator::notifyPositionChanged()
158 { 152 {
159 m_scrollableArea->scrollPositionChanged(DoublePoint(m_currentPosX, m_current PosY), UserScroll); 153 m_scrollableArea->scrollPositionChanged(DoublePoint(m_currentPosX, m_current PosY), UserScroll);
160 } 154 }
161 155
162 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa t pos) 156 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa t pos)
163 { 157 {
164 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); 158 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation);
165 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); 159 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation);
166 return std::max(std::min(pos, maxScrollPos), minScrollPos); 160 return std::max(std::min(pos, maxScrollPos), minScrollPos);
167 } 161 }
168 162
169 } // namespace blink 163 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/input/EventHandler.cpp ('k') | Source/web/WebSettingsImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698