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

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

Issue 1601303003: Fix smooth scroll overshooting when mouse held down in scrollbar track. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 if (!theme().paint(*this, context, cullRect)) 175 if (!theme().paint(*this, context, cullRect))
176 Widget::paint(context, cullRect); 176 Widget::paint(context, cullRect);
177 } 177 }
178 178
179 void Scrollbar::autoscrollTimerFired(Timer<Scrollbar>*) 179 void Scrollbar::autoscrollTimerFired(Timer<Scrollbar>*)
180 { 180 {
181 autoscrollPressedPart(theme().autoscrollTimerDelay()); 181 autoscrollPressedPart(theme().autoscrollTimerDelay());
182 } 182 }
183 183
184 static bool thumbUnderMouse(Scrollbar& scrollbar) 184 bool Scrollbar::thumbWillBeUnderMouse() const
185 { 185 {
186 int thumbPos = scrollbar.theme().trackPosition(scrollbar) + scrollbar.theme( ).thumbPosition(scrollbar); 186 int thumbPos = theme().trackPosition(*this) + theme().thumbPosition(*this, s crollableAreaTargetPos());
187 int thumbLength = scrollbar.theme().thumbLength(scrollbar); 187 int thumbLength = theme().thumbLength(*this);
188 return scrollbar.pressedPos() >= thumbPos && scrollbar.pressedPos() < thumbP os + thumbLength; 188 return pressedPos() >= thumbPos && pressedPos() < thumbPos + thumbLength;
189 } 189 }
190 190
191 void Scrollbar::autoscrollPressedPart(double delay) 191 void Scrollbar::autoscrollPressedPart(double delay)
192 { 192 {
193 // Don't do anything for the thumb or if nothing was pressed. 193 // Don't do anything for the thumb or if nothing was pressed.
194 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart) 194 if (m_pressedPart == ThumbPart || m_pressedPart == NoPart)
195 return; 195 return;
196 196
197 // Handle the track. 197 // Handle the track.
198 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(*this)) { 198 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbWillBeUnderMouse()) {
199 setHoveredPart(ThumbPart); 199 setHoveredPart(ThumbPart);
200 return; 200 return;
201 } 201 }
202 202
203 // Handle the arrows and track. 203 // Handle the arrows and track.
204 if (m_scrollableArea && m_scrollableArea->userScroll(pressedPartScrollDirect ionPhysical(), pressedPartScrollGranularity()).didScroll) 204 if (m_scrollableArea && m_scrollableArea->userScroll(pressedPartScrollDirect ionPhysical(), pressedPartScrollGranularity()).didScroll)
205 startTimerIfNeeded(delay); 205 startTimerIfNeeded(delay);
206 } 206 }
207 207
208 void Scrollbar::startTimerIfNeeded(double delay) 208 void Scrollbar::startTimerIfNeeded(double delay)
209 { 209 {
210 // Don't do anything for the thumb. 210 // Don't do anything for the thumb.
211 if (m_pressedPart == ThumbPart) 211 if (m_pressedPart == ThumbPart)
212 return; 212 return;
213 213
214 // Handle the track. We halt track scrolling once the thumb is level 214 // Handle the track. We halt track scrolling once the thumb is level
215 // with us. 215 // with us.
216 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse(*this)) { 216 if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbWillBeUnderMouse()) {
217 setHoveredPart(ThumbPart); 217 setHoveredPart(ThumbPart);
218 return; 218 return;
219 } 219 }
220 220
221 // We can't scroll if we've hit the beginning or end. 221 // We can't scroll if we've hit the beginning or end.
222 ScrollDirectionPhysical dir = pressedPartScrollDirectionPhysical(); 222 ScrollDirectionPhysical dir = pressedPartScrollDirectionPhysical();
223 if (dir == ScrollUp || dir == ScrollLeft) { 223 if (dir == ScrollUp || dir == ScrollLeft) {
224 if (m_currentPos == 0) 224 if (m_currentPos == 0)
225 return; 225 return;
226 } else { 226 } else {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 { 555 {
556 if (!m_scrollableArea) 556 if (!m_scrollableArea)
557 return 0; 557 return 0;
558 558
559 if (m_orientation == HorizontalScrollbar) 559 if (m_orientation == HorizontalScrollbar)
560 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x(); 560 return m_scrollableArea->scrollPosition().x() - m_scrollableArea->minimu mScrollPosition().x();
561 561
562 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y(); 562 return m_scrollableArea->scrollPosition().y() - m_scrollableArea->minimumScr ollPosition().y();
563 } 563 }
564 564
565 float Scrollbar::scrollableAreaTargetPos() const
566 {
567 if (!m_scrollableArea)
568 return 0;
569
570 if (m_orientation == HorizontalScrollbar)
571 return m_scrollableArea->scrollAnimator().desiredTargetPosition().x() - m_scrollableArea->minimumScrollPosition().x();
572
573 return m_scrollableArea->scrollAnimator().desiredTargetPosition().y() - m_sc rollableArea->minimumScrollPosition().y();
574 }
575
565 void Scrollbar::setNeedsPaintInvalidation(ScrollbarPart invalidParts) 576 void Scrollbar::setNeedsPaintInvalidation(ScrollbarPart invalidParts)
566 { 577 {
567 if (m_theme.shouldRepaintAllPartsOnInvalidation()) 578 if (m_theme.shouldRepaintAllPartsOnInvalidation())
568 invalidParts = AllParts; 579 invalidParts = AllParts;
569 if (invalidParts & ~ThumbPart) 580 if (invalidParts & ~ThumbPart)
570 m_trackNeedsRepaint = true; 581 m_trackNeedsRepaint = true;
571 if (invalidParts & ThumbPart) 582 if (invalidParts & ThumbPart)
572 m_thumbNeedsRepaint = true; 583 m_thumbNeedsRepaint = true;
573 if (m_scrollableArea) 584 if (m_scrollableArea)
574 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); 585 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation());
575 } 586 }
576 587
577 } // namespace blink 588 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698