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

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

Issue 1496693005: Update RootFrameViewport::userScroll to distribute scrolls between viewports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 : m_scrollableArea(scrollableArea) 43 : m_scrollableArea(scrollableArea)
44 , m_currentPosX(0) 44 , m_currentPosX(0)
45 , m_currentPosY(0) 45 , m_currentPosY(0)
46 { 46 {
47 } 47 }
48 48
49 ScrollAnimatorBase::~ScrollAnimatorBase() 49 ScrollAnimatorBase::~ScrollAnimatorBase()
50 { 50 {
51 } 51 }
52 52
53 float ScrollAnimatorBase::computeDeltaToConsume(ScrollbarOrientation orientation , float pixelDelta) const
54 {
55 float currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m_ currentPosY;
56 float newPos = clampScrollPosition(orientation, currentPos + pixelDelta);
57 return (currentPos == newPos) ? 0.0f : (newPos - currentPos);
58 }
59
53 ScrollResultOneDimensional ScrollAnimatorBase::userScroll(ScrollbarOrientation o rientation, ScrollGranularity, float step, float delta) 60 ScrollResultOneDimensional ScrollAnimatorBase::userScroll(ScrollbarOrientation o rientation, ScrollGranularity, float step, float delta)
54 { 61 {
55 float& currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m _currentPosY; 62 float& currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m _currentPosY;
56 float newPos = clampScrollPosition(orientation, currentPos + step * delta); 63 float usedPixelDelta = computeDeltaToConsume(orientation, step * delta);
64 float newPos = currentPos + usedPixelDelta;
57 if (currentPos == newPos) 65 if (currentPos == newPos)
58 return ScrollResultOneDimensional(false, delta); 66 return ScrollResultOneDimensional(false, delta);
59 67
60 float usedDelta = (newPos - currentPos) / step;
61 currentPos = newPos; 68 currentPos = newPos;
62 69
63 notifyPositionChanged(); 70 notifyPositionChanged();
64 71
65 return ScrollResultOneDimensional(true, delta - usedDelta); 72 return ScrollResultOneDimensional(true, delta - (usedPixelDelta / step));
66 } 73 }
67 74
68 void ScrollAnimatorBase::scrollToOffsetWithoutAnimation(const FloatPoint& offset ) 75 void ScrollAnimatorBase::scrollToOffsetWithoutAnimation(const FloatPoint& offset )
69 { 76 {
70 m_currentPosX = offset.x(); 77 m_currentPosX = offset.x();
71 m_currentPosY = offset.y(); 78 m_currentPosY = offset.y();
72 notifyPositionChanged(); 79 notifyPositionChanged();
73 } 80 }
74 81
75 void ScrollAnimatorBase::setCurrentPosition(const FloatPoint& position) 82 void ScrollAnimatorBase::setCurrentPosition(const FloatPoint& position)
76 { 83 {
77 m_currentPosX = position.x(); 84 m_currentPosX = position.x();
78 m_currentPosY = position.y(); 85 m_currentPosY = position.y();
79 } 86 }
80 87
81 FloatPoint ScrollAnimatorBase::currentPosition() const 88 FloatPoint ScrollAnimatorBase::currentPosition() const
82 { 89 {
83 return FloatPoint(m_currentPosX, m_currentPosY); 90 return FloatPoint(m_currentPosX, m_currentPosY);
84 } 91 }
85 92
86 void ScrollAnimatorBase::notifyPositionChanged() 93 void ScrollAnimatorBase::notifyPositionChanged()
87 { 94 {
88 m_scrollableArea->scrollPositionChanged(DoublePoint(m_currentPosX, m_current PosY), UserScroll); 95 m_scrollableArea->scrollPositionChanged(DoublePoint(m_currentPosX, m_current PosY), UserScroll);
89 } 96 }
90 97
91 float ScrollAnimatorBase::clampScrollPosition(ScrollbarOrientation orientation, float pos) 98 float ScrollAnimatorBase::clampScrollPosition(ScrollbarOrientation orientation, float pos) const
92 { 99 {
93 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); 100 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation);
94 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); 101 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation);
95 return std::max(std::min(pos, maxScrollPos), minScrollPos); 102 return std::max(std::min(pos, maxScrollPos), minScrollPos);
96 } 103 }
97 104
98 DEFINE_TRACE(ScrollAnimatorBase) 105 DEFINE_TRACE(ScrollAnimatorBase)
99 { 106 {
100 visitor->trace(m_scrollableArea); 107 visitor->trace(m_scrollableArea);
101 } 108 }
102 109
103 } // namespace blink 110 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698