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

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

Issue 16982005: Allow objects without scrollbars to be scrollable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Mac Build Fix Created 7 years, 6 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) 69 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset)
70 { 70 {
71 FloatSize delta = FloatSize(offset.x() - m_currentPosX, offset.y() - m_curre ntPosY); 71 FloatSize delta = FloatSize(offset.x() - m_currentPosX, offset.y() - m_curre ntPosY);
72 m_currentPosX = offset.x(); 72 m_currentPosX = offset.x();
73 m_currentPosY = offset.y(); 73 m_currentPosY = offset.y();
74 notifyPositionChanged(delta); 74 notifyPositionChanged(delta);
75 } 75 }
76 76
77 bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) 77 bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e)
78 { 78 {
79 Scrollbar* horizontalScrollbar = m_scrollableArea->horizontalScrollbar(); 79 bool canScrollX = m_scrollableArea->isHorizontallyScrollable();
80 Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar(); 80 bool canScrollY = m_scrollableArea->isVerticallyScrollable();
81 81
82 // Accept the event if we have a scrollbar in that direction and can still 82 // Accept the event if we are scrollable in that direction and can still
83 // scroll any further. 83 // scroll any further.
84 float deltaX = horizontalScrollbar ? e.deltaX() : 0; 84 float deltaX = canScrollX ? e.deltaX() : 0;
85 float deltaY = verticalScrollbar ? e.deltaY() : 0; 85 float deltaY = canScrollY ? e.deltaY() : 0;
86 86
87 bool handled = false; 87 bool handled = false;
88 88
89 #if !OS(DARWIN) 89 #if !OS(DARWIN)
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 IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() - m_scrollableArea->scrollPosition();
96 IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scro llableArea->minimumScrollPosition(); 96 IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scro llableArea->minimumScrollPosition();
97 if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) 97 if ((deltaX < 0 && maxForwardScrollDelta.width() > 0)
98 || (deltaX > 0 && maxBackwardScrollDelta.width() > 0) 98 || (deltaX > 0 && maxBackwardScrollDelta.width() > 0)
99 || (deltaY < 0 && maxForwardScrollDelta.height() > 0) 99 || (deltaY < 0 && maxForwardScrollDelta.height() > 0)
100 || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { 100 || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) {
101 handled = true; 101 handled = true;
102 102
103 if (deltaY) { 103 if (deltaY) {
104 if (e.granularity() == ScrollByPageWheelEvent) { 104 if (e.granularity() == ScrollByPageWheelEvent) {
105 bool negative = deltaY < 0; 105 bool negative = deltaY < 0;
106 deltaY = max(max(static_cast<float>(m_scrollableArea->visibleHei ght()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollab leArea->visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f); 106 deltaY = max(max(static_cast<float>(m_scrollableArea->visibleHei ght()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollab leArea->visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f);
107 if (negative) 107 if (negative)
108 deltaY = -deltaY; 108 deltaY = -deltaY;
109 } 109 }
110 scroll(VerticalScrollbar, granularity, verticalScrollbar->pixelStep( ), -deltaY); 110
111 float step = 1;
112 Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar() ;
113 if (verticalScrollbar)
114 step = verticalScrollbar->pixelStep();
115
116 scroll(VerticalScrollbar, granularity, step, -deltaY);
111 } 117 }
112 118
113 if (deltaX) { 119 if (deltaX) {
114 if (e.granularity() == ScrollByPageWheelEvent) { 120 if (e.granularity() == ScrollByPageWheelEvent) {
115 bool negative = deltaX < 0; 121 bool negative = deltaX < 0;
116 deltaX = max(max(static_cast<float>(m_scrollableArea->visibleWid th()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollabl eArea->visibleWidth() - Scrollbar::maxOverlapBetweenPages())), 1.0f); 122 deltaX = max(max(static_cast<float>(m_scrollableArea->visibleWid th()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollabl eArea->visibleWidth() - Scrollbar::maxOverlapBetweenPages())), 1.0f);
117 if (negative) 123 if (negative)
118 deltaX = -deltaX; 124 deltaX = -deltaX;
119 } 125 }
120 scroll(HorizontalScrollbar, granularity, horizontalScrollbar->pixelS tep(), -deltaX); 126
127 float step = 1;
128 Scrollbar* horizontalScrollbar = m_scrollableArea->horizontalScrollb ar();
129 if (horizontalScrollbar)
130 step = horizontalScrollbar->pixelStep();
131
132 scroll(HorizontalScrollbar, granularity, step, -deltaX);
121 } 133 }
122 } 134 }
123 return handled; 135 return handled;
124 } 136 }
125 137
126 void ScrollAnimator::setCurrentPosition(const FloatPoint& position) 138 void ScrollAnimator::setCurrentPosition(const FloatPoint& position)
127 { 139 {
128 m_currentPosX = position.x(); 140 m_currentPosX = position.x();
129 m_currentPosY = position.y(); 141 m_currentPosY = position.y();
130 } 142 }
(...skipping 10 matching lines...) Expand all
141 } 153 }
142 154
143 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa t pos) 155 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa t pos)
144 { 156 {
145 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); 157 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation);
146 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); 158 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation);
147 return std::max(std::min(pos, maxScrollPos), minScrollPos); 159 return std::max(std::min(pos, maxScrollPos), minScrollPos);
148 } 160 }
149 161
150 } // namespace WebCore 162 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698