Changeset 173894 in webkit
- Timestamp:
- Sep 23, 2014 3:16:25 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r173893 r173894 1 2014-09-22 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Implement snapping behavior for Mac overflow scrolling 4 https://bugs.webkit.org/show_bug.cgi?id=135774 5 6 Reviewed by Beth Dakin. 7 8 Hooks into AxisScrollSnapAnimator to implement overflow scroll snapping on Mac. 9 10 We need to find a way to test this! 11 12 * dom/Element.cpp: 13 (WebCore::Element::dispatchWheelEvent): 14 * page/EventHandler.cpp: 15 (WebCore::handleWheelEventInAppropriateEnclosingBoxForSingleAxis): 16 * platform/ScrollAnimator.cpp: 17 (WebCore::ScrollAnimator::handleWheelEvent): 18 (WebCore::ScrollAnimator::updateScrollAnimatorsAndTimers): 19 (WebCore::ScrollAnimator::scrollOffsetInAxis): 20 (WebCore::ScrollAnimator::immediateScrollInAxis): 21 (WebCore::ScrollAnimator::startScrollSnapTimer): 22 (WebCore::ScrollAnimator::stopScrollSnapTimer): 23 (WebCore::ScrollAnimator::horizontalScrollSnapTimerFired): 24 (WebCore::ScrollAnimator::verticalScrollSnapTimerFired): 25 * platform/ScrollAnimator.h: 26 * platform/mac/AxisScrollSnapAnimator.h: 27 * platform/mac/AxisScrollSnapAnimator.mm: 28 (WebCore::AxisScrollSnapAnimator::AxisScrollSnapAnimator): 29 (WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): 30 (WebCore::AxisScrollSnapAnimator::endScrollSnapAnimation): 31 (WebCore::AxisScrollSnapAnimator::initializeGlideParameters): 32 * rendering/RenderLayer.cpp: 33 (WebCore::RenderLayer::updateScrollInfoAfterLayout): 34 1 35 2014-09-23 Chris Dumez <cdumez@apple.com> 2 36 -
trunk/Source/WebCore/platform/ScrollAnimator.cpp
r172182 r173894 83 83 bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) 84 84 { 85 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 86 if (m_verticalScrollSnapAnimator) { 87 m_verticalScrollSnapAnimator->handleWheelEvent(e); 88 if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(e)) 89 return false; 90 } 91 if (m_horizontalScrollSnapAnimator) { 92 m_horizontalScrollSnapAnimator->handleWheelEvent(e); 93 if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(e)) 94 return false; 95 } 96 #endif 85 97 #if PLATFORM(COCOA) 86 98 // Events in the PlatformWheelEventPhaseMayBegin phase have no deltas, and therefore never passes through the scroll handling logic below. … … 159 171 } 160 172 173 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 174 void ScrollAnimator::updateScrollAnimatorsAndTimers() 175 { 176 // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated. 177 if (m_scrollableArea->horizontalSnapOffsets()) { 178 m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea->horizontalSnapOffsets(), ScrollEventAxis::Horizontal); 179 m_horizontalScrollSnapTimer = std::make_unique<Timer<ScrollAnimator>>(this, &ScrollAnimator::horizontalScrollSnapTimerFired); 180 } else if (m_horizontalScrollSnapAnimator) { 181 m_horizontalScrollSnapAnimator = nullptr; 182 m_horizontalScrollSnapTimer = nullptr; 183 } 184 if (m_scrollableArea->verticalSnapOffsets()) { 185 m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea->verticalSnapOffsets(), ScrollEventAxis::Vertical); 186 m_verticalScrollSnapTimer = std::make_unique<Timer<ScrollAnimator>>(this, &ScrollAnimator::verticalScrollSnapTimerFired); 187 } else if (m_verticalScrollSnapAnimator) { 188 m_verticalScrollSnapAnimator = nullptr; 189 m_verticalScrollSnapTimer = nullptr; 190 } 191 } 192 193 LayoutUnit ScrollAnimator::scrollOffsetInAxis(ScrollEventAxis axis) 194 { 195 FloatPoint currentPosition = this->currentPosition(); 196 return axis == ScrollEventAxis::Horizontal ? currentPosition.x() : currentPosition.y(); 197 } 198 199 void ScrollAnimator::immediateScrollInAxis(ScrollEventAxis axis, float delta) 200 { 201 FloatPoint currentPosition = this->currentPosition(); 202 if (axis == ScrollEventAxis::Horizontal) 203 scrollToOffsetWithoutAnimation(FloatPoint(currentPosition.x() + delta, currentPosition.y())); 204 else 205 scrollToOffsetWithoutAnimation(FloatPoint(currentPosition.x(), currentPosition.y() + delta)); 206 } 207 208 void ScrollAnimator::startScrollSnapTimer(ScrollEventAxis axis) 209 { 210 Timer<ScrollAnimator>* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get(); 211 if (!scrollSnapTimer->isActive()) 212 scrollSnapTimer->startRepeating(1.0 / 60.0); 213 } 214 215 void ScrollAnimator::stopScrollSnapTimer(ScrollEventAxis axis) 216 { 217 Timer<ScrollAnimator>* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get(); 218 if (scrollSnapTimer->isActive()) 219 scrollSnapTimer->stop(); 220 } 221 222 void ScrollAnimator::horizontalScrollSnapTimerFired(Timer<ScrollAnimator>&) 223 { 224 m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate(); 225 } 226 227 void ScrollAnimator::verticalScrollSnapTimerFired(Timer<ScrollAnimator>&) 228 { 229 m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate(); 230 } 231 #endif 232 161 233 } // namespace WebCore -
trunk/Source/WebCore/platform/ScrollAnimator.h
r163657 r173894 38 38 #include <wtf/Forward.h> 39 39 40 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 41 #include "AxisScrollSnapAnimator.h" 42 #include "Timer.h" 43 #endif 44 40 45 namespace WebCore { 41 46 … … 45 50 class Scrollbar; 46 51 52 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 53 class ScrollAnimator : public AxisScrollSnapAnimatorClient { 54 #else 47 55 class ScrollAnimator { 56 #endif 48 57 WTF_MAKE_FAST_ALLOCATED; 49 58 public: … … 107 116 virtual bool isRubberBandInProgress() const { return false; } 108 117 118 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 119 void updateScrollAnimatorsAndTimers(); 120 virtual LayoutUnit scrollOffsetInAxis(ScrollEventAxis) override; 121 virtual void immediateScrollInAxis(ScrollEventAxis, float delta) override; 122 virtual void startScrollSnapTimer(ScrollEventAxis) override; 123 virtual void stopScrollSnapTimer(ScrollEventAxis) override; 124 #endif 125 109 126 protected: 110 127 explicit ScrollAnimator(ScrollableArea*); … … 112 129 virtual void notifyPositionChanged(const FloatSize& delta); 113 130 131 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 132 // Trivial wrappers around the actual update loop in AxisScrollSnapAnimator, since WebCore Timer requires a Timer argument. 133 void horizontalScrollSnapTimerFired(Timer<ScrollAnimator>&); 134 void verticalScrollSnapTimerFired(Timer<ScrollAnimator>&); 135 #endif 136 114 137 ScrollableArea* m_scrollableArea; 115 138 float m_currentPosX; // We avoid using a FloatPoint in order to reduce 116 139 float m_currentPosY; // subclass code complexity. 140 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 141 std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator; 142 std::unique_ptr<Timer<ScrollAnimator>> m_horizontalScrollSnapTimer; 143 // FIXME: Find a way to consolidate both timers into one variable. 144 std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator; 145 std::unique_ptr<Timer<ScrollAnimator>> m_verticalScrollSnapTimer; 146 #endif 117 147 }; 118 148 -
trunk/Source/WebCore/platform/mac/AxisScrollSnapAnimator.h
r172659 r173894 60 60 virtual LayoutUnit scrollOffsetInAxis(ScrollEventAxis) = 0; 61 61 virtual void immediateScrollInAxis(ScrollEventAxis, float velocity) = 0; 62 virtual void startScrollSnapTimer( ) = 0;63 virtual void stopScrollSnapTimer( ) = 0;62 virtual void startScrollSnapTimer(ScrollEventAxis) = 0; 63 virtual void stopScrollSnapTimer(ScrollEventAxis) = 0; 64 64 }; 65 65 66 66 class AxisScrollSnapAnimator { 67 67 public: 68 AxisScrollSnapAnimator(AxisScrollSnapAnimatorClient*, Vector<LayoutUnit>* snapOffsets, ScrollEventAxis);68 AxisScrollSnapAnimator(AxisScrollSnapAnimatorClient*, const Vector<LayoutUnit>* snapOffsets, ScrollEventAxis); 69 69 void handleWheelEvent(const PlatformWheelEvent&); 70 70 bool shouldOverrideWheelEvent(const PlatformWheelEvent&) const; … … 86 86 87 87 AxisScrollSnapAnimatorClient* m_client; 88 Vector<LayoutUnit>* m_snapOffsets;88 const Vector<LayoutUnit>* m_snapOffsets; 89 89 ScrollEventAxis m_axis; 90 90 // Used to track both snapping and gliding behaviors. -
trunk/Source/WebCore/platform/mac/AxisScrollSnapAnimator.mm
r172659 r173894 83 83 } 84 84 85 AxisScrollSnapAnimator::AxisScrollSnapAnimator(AxisScrollSnapAnimatorClient* client, Vector<LayoutUnit>* snapOffsets, ScrollEventAxis axis)85 AxisScrollSnapAnimator::AxisScrollSnapAnimator(AxisScrollSnapAnimatorClient* client, const Vector<LayoutUnit>* snapOffsets, ScrollEventAxis axis) 86 86 : m_client(client) 87 87 , m_snapOffsets(snapOffsets) … … 185 185 clearInitialWheelDeltaWindow(); 186 186 } 187 m_client->startScrollSnapTimer( );187 m_client->startScrollSnapTimer(m_axis); 188 188 } 189 189 … … 195 195 196 196 m_currentState = newState; 197 m_client->stopScrollSnapTimer( );197 m_client->stopScrollSnapTimer(m_axis); 198 198 } 199 199 -
trunk/Source/WebCore/rendering/RenderLayer.cpp
r173865 r173894 3383 3383 // https://bugs.webkit.org/show_bug.cgi?id=135964 3384 3384 updateSnapOffsets(); 3385 #if PLATFORM(MAC) 3386 if (existingScrollAnimator()) 3387 scrollAnimator()->updateScrollAnimatorsAndTimers(); 3388 #endif 3385 3389 #endif 3386 3390 }
Note: See TracChangeset
for help on using the changeset viewer.