Changeset 180974 in webkit
- Timestamp:
- Mar 3, 2015 5:36:51 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r180966 r180974 1 2015-03-03 Brent Fulgham <bfulgham@apple.com> 2 3 Move scroll animating functions from ScrollAnimator to ScrollController 4 https://bugs.webkit.org/show_bug.cgi?id=142102 5 <rdar://problem/20007161> 6 7 Reviewed by Simon Fraser. 8 9 Add a new test that confirms that rubberband snap animations work properly when combined 10 with text zooming. 11 12 * platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt: Added. 13 * platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html: Added. 14 1 15 2015-03-03 Commit Queue <commit-queue@webkit.org> 2 16 -
trunk/Source/WebCore/ChangeLog
r180966 r180974 1 2015-03-03 Brent Fulgham <bfulgham@apple.com> 2 3 Move scroll animating functions from ScrollAnimator to ScrollController 4 https://bugs.webkit.org/show_bug.cgi?id=142102 5 <rdar://problem/20007161> 6 7 Reviewed by Simon Fraser. 8 9 Tested by platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html. 10 11 Do some refactoring of the various scrolling classes: 12 1. Consolidate animation times to RunLoop::Timer instead of a combination of WebCore::Timer 13 and CFRunLoopTimers. Do this for Scroll Snap Point and Rubberband animations. 14 2. Move ScrollController from platform/mac to platform/cocoa to enable sharing with iOS. 15 3. Move code from ScrollAnimator{Mac} -> ScrollController. 16 4. Rename scrollOffsetInAxis -> scrollOffsetOnAxis 17 5. Rename immediateScrollInAxis -> immediateScrollOnAxis 18 19 * WebCore.xcodeproj/project.pbxproj: Move ScrollController to 'platform/cocoa' 20 * page/mac/EventHandlerMac.mm: Make sure the scroll controller is notified of end-of-scroll 21 events, just as is done for the "event not handled" case in EventHandler.cpp. 22 (WebCore::EventHandler::platformCompleteWheelEvent): 23 * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h: Remove timer and some delegate 24 methods, now that ScrollController is controlling this state. 25 * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm: 26 (WebCore::ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac): We no longer 27 need to clean up the CFRunLoopTimer. 28 (WebCore::ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer): Make sure scroll 29 state is updated after rubber band snap. 30 (WebCore::ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis): Add temporary stub needed 31 until Bug1973 is completed.). 32 (WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis): Ditto. 33 (WebCore::ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer): Deleted. 34 * platform/ScrollAnimator.cpp: 35 (WebCore::ScrollAnimator::ScrollAnimator): 36 (WebCore::ScrollAnimator::processWheelEventForScrollSnap): Just call the ScrollController method. 37 (WebCore::ScrollAnimator::handleWheelEvent): Ditto. 38 (WebCore::ScrollAnimator::updateScrollAnimatorsAndTimers): Ditto. 39 (WebCore::ScrollAnimator::scrollOffsetOnAxis): Renamed from scrollOffsetInAxis. 40 (WebCore::ScrollAnimator::immediateScrollOnAxis): Renamed from immediateScrollInAxis. 41 (WebCore::ScrollAnimator::scrollOffsetInAxis): Deleted. 42 (WebCore::ScrollAnimator::immediateScrollInAxis): Deleted. 43 (WebCore::ScrollAnimator::startScrollSnapTimer): Deleted. 44 (WebCore::ScrollAnimator::stopScrollSnapTimer): Deleted. 45 (WebCore::ScrollAnimator::horizontalScrollSnapTimerFired): Deleted. 46 (WebCore::ScrollAnimator::verticalScrollSnapTimerFired): Deleted. 47 * platform/ScrollAnimator.h: 48 * platform/cocoa/ScrollController.h: Copied from platform/mac/ScrollController.h. 49 (WebCore::ScrollControllerClient::startSnapRubberbandTimer): 50 (WebCore::ScrollControllerClient::stopSnapRubberbandTimer): 51 (WebCore::ScrollControllerClient::startScrollSnapTimer): 52 (WebCore::ScrollControllerClient::stopScrollSnapTimer): 53 * platform/cocoa/ScrollController.mm: Copied from platform/mac/ScrollController.mm. 54 (WebCore::ScrollController::ScrollController): Update to initialize new timers. 55 (WebCore::ScrollController::handleWheelEvent): Update to handle Scroll Snap Point events. 56 (WebCore::ScrollController::startSnapRubberbandTimer): Added. 57 (WebCore::ScrollController::stopSnapRubberbandTimer): Manage animation timers locally, do not 58 require client to maintain timers. 59 (WebCore::ScrollController::snapRubberBand): Ditto. 60 (WebCore::ScrollController::processWheelEventForScrollSnap): Added. (Moved from ScrollAnimatorMac) 61 (WebCore::ScrollController::updateScrollAnimatorsAndTimers): Ditto. Also updated to use RunLoop::Timer. 62 (WebCore::ScrollController::startScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer. 63 (WebCore::ScrollController::stopScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer. 64 (WebCore::ScrollController::horizontalScrollSnapTimerFired): Ditto. 65 (WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto. 66 (WebCore::ScrollController::scrollOffsetOnAxis): Moved from ScrollAnimatorMac. 67 (WebCore::ScrollController::immediateScrollOnAxis): Ditto. 68 * platform/mac/AxisScrollSnapAnimator.h: Rename methods from 'InAxis' to 'OnAxis' 69 * platform/mac/AxisScrollSnapAnimator.mm: 70 (WebCore::AxisScrollSnapAnimator::handleWheelEvent): Update for 'InAxis' to 'OnAxis' renaming. 71 (WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate): Ditto. 72 (WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): Ditto. 73 (WebCore::AxisScrollSnapAnimator::computeSnapDelta): Ditto. 74 (WebCore::AxisScrollSnapAnimator::computeGlideDelta): Ditto. 75 * platform/mac/ScrollAnimatorMac.h: 76 * platform/mac/ScrollAnimatorMac.mm: 77 (WebCore::ScrollAnimatorMac::ScrollAnimatorMac): Remove unused Rubberband timers (now that this is 78 controlled in the ScrollController) 79 (WebCore::ScrollAnimatorMac::startSnapRubberbandTimer): Deleted. 80 (WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer): Deleted. 81 (WebCore::ScrollAnimatorMac::snapRubberBandTimerFired): Deleted. 82 * platform/mac/ScrollController.h: Removed. 83 * platform/mac/ScrollController.mm: Removed. 84 1 85 2015-03-03 Commit Queue <commit-queue@webkit.org> 2 86 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r180915 r180974 16588 16588 BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */, 16589 16589 BCEF869E0E844E9D00A85CD5 /* ScrollbarThemeMac.mm */, 16590 1AA84F03143BA7BD0051D153 /* ScrollController.h */,16591 1AA84F02143BA7BD0051D153 /* ScrollController.mm */,16592 16590 9353676A09AED88B00D35CD6 /* ScrollViewMac.mm */, 16593 16591 077AF14118F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h */, … … 18699 18697 1A0409DB1A4360B5009E47F3 /* MachSendRight.h */, 18700 18698 ADB6B29718FB90240081963E /* MemoryPressureHandlerCocoa.mm */, 18699 1AA84F03143BA7BD0051D153 /* ScrollController.h */, 18700 1AA84F02143BA7BD0051D153 /* ScrollController.mm */, 18701 18701 5D5975B119635F1100D00878 /* SystemVersion.h */, 18702 18702 5D5975B219635F1100D00878 /* SystemVersion.mm */, -
trunk/Source/WebCore/page/mac/EventHandlerMac.mm
r180915 r180974 962 962 bool didHandleEvent = view ? view->wheelEvent(wheelEvent) : false; 963 963 m_isHandlingWheelEvent = false; 964 965 #if ENABLE(CSS_SCROLL_SNAP) 966 if (scrollableArea) 967 platformNotifySnapIfNecessary(wheelEvent, *scrollableArea); 968 #endif 969 964 970 return didHandleEvent; 965 971 } -
trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h
r180915 r180974 1 1 /* 2 * Copyright (C) 2012 Apple Inc. All rights reserved.2 * Copyright (C) 2012, 2014-2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 52 52 53 53 // ScrollController member functions. 54 virtual bool allowsHorizontalStretching(const PlatformWheelEvent&) override; 55 virtual bool allowsVerticalStretching(const PlatformWheelEvent&) override; 56 virtual IntSize stretchAmount() override; 57 virtual bool pinnedInDirection(const FloatSize&) override; 58 virtual bool canScrollHorizontally() override; 59 virtual bool canScrollVertically() override; 60 virtual bool shouldRubberBandInDirection(ScrollDirection) override; 61 virtual IntPoint absoluteScrollPosition() override; 62 virtual void immediateScrollBy(const FloatSize&) override; 63 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override; 64 virtual void startSnapRubberbandTimer() override; 65 virtual void stopSnapRubberbandTimer() override; 66 virtual void adjustScrollPositionToBoundsIfNecessary() override; 54 bool allowsHorizontalStretching(const PlatformWheelEvent&) override; 55 bool allowsVerticalStretching(const PlatformWheelEvent&) override; 56 IntSize stretchAmount() override; 57 bool pinnedInDirection(const FloatSize&) override; 58 bool canScrollHorizontally() override; 59 bool canScrollVertically() override; 60 bool shouldRubberBandInDirection(ScrollDirection) override; 61 IntPoint absoluteScrollPosition() override; 62 void immediateScrollBy(const FloatSize&) override; 63 void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override; 64 void stopSnapRubberbandTimer() override; 65 void adjustScrollPositionToBoundsIfNecessary() override; 67 66 68 virtualFloatPoint scrollPosition() const override;69 v irtual void setScrollPosition(const FloatPoint&) override;70 v irtual void setScrollPositionWithoutContentEdgeConstraints(const FloatPoint&) override;67 FloatPoint scrollPosition() const override; 68 void setScrollPosition(const FloatPoint&) override; 69 void setScrollPositionWithoutContentEdgeConstraints(const FloatPoint&) override; 71 70 72 v irtual void updateLayersAfterViewportChange(const FloatRect& fixedPositionRect, double scale) override;71 void updateLayersAfterViewportChange(const FloatRect& fixedPositionRect, double scale) override; 73 72 74 v irtual void setScrollLayerPosition(const FloatPoint&) override;73 void setScrollLayerPosition(const FloatPoint&) override; 75 74 76 virtualFloatPoint minimumScrollPosition() const override;77 virtualFloatPoint maximumScrollPosition() const override;75 FloatPoint minimumScrollPosition() const override; 76 FloatPoint maximumScrollPosition() const override; 78 77 79 78 void updateMainFramePinState(const FloatPoint& scrollPosition); … … 81 80 bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis); 82 81 82 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 83 LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override; 84 void immediateScrollOnAxis(ScrollEventAxis, float delta) override; 85 #endif 86 83 87 void logExposedUnfilledArea(); 84 88 85 89 ScrollController m_scrollController; 86 RetainPtr<CFRunLoopTimerRef> m_snapRubberbandTimer;87 90 88 91 RetainPtr<CALayer> m_scrollLayer; -
trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm
r180915 r180974 1 1 /* 2 * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2012, 2014-2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 67 67 ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac() 68 68 { 69 if (m_snapRubberbandTimer)70 CFRunLoopTimerInvalidate(m_snapRubberbandTimer.get());71 69 } 72 70 … … 297 295 } 298 296 299 void ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer()300 {301 ASSERT(!m_snapRubberbandTimer);302 303 CFTimeInterval timerInterval = 1.0 / 60.0;304 305 m_snapRubberbandTimer = adoptCF(CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + timerInterval, timerInterval, 0, 0, ^(CFRunLoopTimerRef) {306 m_scrollController.snapRubberBandTimerFired();307 }));308 CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_snapRubberbandTimer.get(), kCFRunLoopDefaultMode);309 }310 311 297 void ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer() 312 298 { 313 if (!m_snapRubberbandTimer)314 return;315 316 299 scrollingTree().setMainFrameIsRubberBanding(false); 317 300 318 301 // Since the rubberband timer has stopped, totalContentsSizeForRubberBand can be synchronized with totalContentsSize. 319 302 setTotalContentsSizeForRubberBand(totalContentsSize()); 320 321 CFRunLoopTimerInvalidate(m_snapRubberbandTimer.get());322 m_snapRubberbandTimer = nullptr;323 303 } 324 304 … … 541 521 } 542 522 523 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 524 LayoutUnit ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis(ScrollEventAxis) 525 { 526 // Temporary stub until http://webkit.org/b/141973. 527 return 0; 528 } 529 530 void ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis(ScrollEventAxis, float) 531 { 532 // Temporary stub until http://webkit.org/b/141973. 533 } 534 #endif 535 543 536 } // namespace WebCore 544 537 -
trunk/Source/WebCore/platform/ScrollAnimator.cpp
r180915 r180974 50 50 ScrollAnimator::ScrollAnimator(ScrollableArea& scrollableArea) 51 51 : m_scrollableArea(scrollableArea) 52 #if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC) 53 , m_scrollController(this) 54 #endif 52 55 , m_currentPosX(0) 53 56 , m_currentPosY(0) … … 82 85 83 86 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 84 voidScrollAnimator::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)87 bool ScrollAnimator::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent) 85 88 { 86 if (m_verticalScrollSnapAnimator) 87 m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent); 88 if (m_horizontalScrollSnapAnimator) 89 m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent); 89 return m_scrollController.processWheelEventForScrollSnap(wheelEvent); 90 90 } 91 91 #endif … … 94 94 { 95 95 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 96 if (m_verticalScrollSnapAnimator) { 97 m_verticalScrollSnapAnimator->handleWheelEvent(e); 98 if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(e)) 99 return false; 100 } 101 if (m_horizontalScrollSnapAnimator) { 102 m_horizontalScrollSnapAnimator->handleWheelEvent(e); 103 if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(e)) 104 return false; 105 } 96 if (!m_scrollController.processWheelEventForScrollSnap(e)) 97 return false; 106 98 #endif 107 99 #if PLATFORM(COCOA) … … 184 176 void ScrollAnimator::updateScrollAnimatorsAndTimers() 185 177 { 186 // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated. 187 if (m_scrollableArea.horizontalSnapOffsets()) { 188 m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal); 189 m_horizontalScrollSnapTimer = std::make_unique<Timer>(*this, &ScrollAnimator::horizontalScrollSnapTimerFired); 190 } else if (m_horizontalScrollSnapAnimator) { 191 m_horizontalScrollSnapAnimator = nullptr; 192 m_horizontalScrollSnapTimer = nullptr; 193 } 194 if (m_scrollableArea.verticalSnapOffsets()) { 195 m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical); 196 m_verticalScrollSnapTimer = std::make_unique<Timer>(*this, &ScrollAnimator::verticalScrollSnapTimerFired); 197 } else if (m_verticalScrollSnapAnimator) { 198 m_verticalScrollSnapAnimator = nullptr; 199 m_verticalScrollSnapTimer = nullptr; 200 } 178 m_scrollController.updateScrollAnimatorsAndTimers(m_scrollableArea); 201 179 } 202 180 203 LayoutUnit ScrollAnimator::scrollOffset InAxis(ScrollEventAxis axis)181 LayoutUnit ScrollAnimator::scrollOffsetOnAxis(ScrollEventAxis axis) 204 182 { 205 FloatPoint currentPosition = this->currentPosition(); 206 return axis == ScrollEventAxis::Horizontal ? currentPosition.x() : currentPosition.y(); 183 return axis == ScrollEventAxis::Horizontal ? m_currentPosX : m_currentPosY; 207 184 } 208 185 209 void ScrollAnimator::immediateScroll InAxis(ScrollEventAxis axis, float delta)186 void ScrollAnimator::immediateScrollOnAxis(ScrollEventAxis axis, float delta) 210 187 { 211 188 FloatPoint currentPosition = this->currentPosition(); … … 215 192 scrollToOffsetWithoutAnimation(FloatPoint(currentPosition.x(), currentPosition.y() + delta)); 216 193 } 217 218 void ScrollAnimator::startScrollSnapTimer(ScrollEventAxis axis)219 {220 Timer* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get();221 if (!scrollSnapTimer->isActive())222 scrollSnapTimer->startRepeating(1.0 / 60.0);223 }224 225 void ScrollAnimator::stopScrollSnapTimer(ScrollEventAxis axis)226 {227 Timer* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get();228 if (scrollSnapTimer->isActive())229 scrollSnapTimer->stop();230 }231 232 void ScrollAnimator::horizontalScrollSnapTimerFired()233 {234 m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate();235 }236 237 void ScrollAnimator::verticalScrollSnapTimerFired()238 {239 m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate();240 }241 194 #endif 242 195 -
trunk/Source/WebCore/platform/ScrollAnimator.h
r180915 r180974 34 34 35 35 #include "FloatSize.h" 36 #include "LayoutUnit.h" 36 37 #include "PlatformWheelEvent.h" 37 38 #include "ScrollTypes.h" … … 39 40 #include <wtf/Forward.h> 40 41 41 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 42 #include "AxisScrollSnapAnimator.h" 43 #include "Timer.h" 42 #if (ENABLE(RUBBER_BANDING) || ENABLE(CSS_SCROLL_SNAP)) && PLATFORM(MAC) 43 #include "ScrollController.h" 44 44 #endif 45 45 … … 51 51 class Scrollbar; 52 52 53 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)54 class ScrollAnimator : p ublic AxisScrollSnapAnimatorClient {53 #if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC) 54 class ScrollAnimator : private ScrollControllerClient { 55 55 #else 56 56 class ScrollAnimator { … … 119 119 120 120 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 121 voidprocessWheelEventForScrollSnap(const PlatformWheelEvent&);121 bool processWheelEventForScrollSnap(const PlatformWheelEvent&); 122 122 void updateScrollAnimatorsAndTimers(); 123 virtual LayoutUnit scrollOffsetInAxis(ScrollEventAxis) override; 124 virtual void immediateScrollInAxis(ScrollEventAxis, float delta) override; 125 virtual void startScrollSnapTimer(ScrollEventAxis) override; 126 virtual void stopScrollSnapTimer(ScrollEventAxis) override; 123 LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override; 124 void immediateScrollOnAxis(ScrollEventAxis, float delta) override; 127 125 #endif 128 126 … … 130 128 virtual void notifyPositionChanged(const FloatSize& delta); 131 129 132 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 133 // Trivial wrappers around the actual update loop in AxisScrollSnapAnimator, since WebCore Timer requires a Timer argument. 134 void horizontalScrollSnapTimerFired(); 135 void verticalScrollSnapTimerFired(); 130 ScrollableArea& m_scrollableArea; 131 #if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC) 132 ScrollController m_scrollController; 136 133 #endif 137 138 ScrollableArea& m_scrollableArea;139 134 float m_currentPosX; // We avoid using a FloatPoint in order to reduce 140 135 float m_currentPosY; // subclass code complexity. 141 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)142 std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator;143 std::unique_ptr<Timer> m_horizontalScrollSnapTimer;144 // FIXME: Find a way to consolidate both timers into one variable.145 std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator;146 std::unique_ptr<Timer> m_verticalScrollSnapTimer;147 #endif148 136 }; 149 137 -
trunk/Source/WebCore/platform/cocoa/ScrollController.h
r180935 r180974 1 1 /* 2 * Copyright (C) 2011 Apple Inc. All rights reserved.2 * Copyright (C) 2011, 2014-2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 33 33 #include "ScrollTypes.h" 34 34 #include <wtf/Noncopyable.h> 35 #include <wtf/RunLoop.h> 36 37 #if ENABLE(CSS_SCROLL_SNAP) 38 #include "AxisScrollSnapAnimator.h" 39 #endif 35 40 36 41 namespace WebCore { 37 42 38 43 class PlatformWheelEvent; 44 class ScrollableArea; 39 45 40 46 class ScrollControllerClient { … … 56 62 virtual void immediateScrollBy(const FloatSize&) = 0; 57 63 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) = 0; 58 virtual void startSnapRubberbandTimer() = 0; 59 virtual void stopSnapRubberbandTimer() = 0; 64 virtual void startSnapRubberbandTimer() 65 { 66 // Override to perform client-specific snap start logic 67 } 60 68 69 virtual void stopSnapRubberbandTimer() 70 { 71 // Override to perform client-specific snap end logic 72 } 73 61 74 // If the current scroll position is within the overhang area, this function will cause 62 75 // the page to scroll to the nearest boundary point. 63 76 virtual void adjustScrollPositionToBoundsIfNecessary() = 0; 77 78 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 79 virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0; 80 virtual void immediateScrollOnAxis(ScrollEventAxis, float delta) = 0; 81 virtual void startScrollSnapTimer(ScrollEventAxis) 82 { 83 // Override to perform client-specific scroll snap point start logic 84 } 85 86 virtual void stopScrollSnapTimer(ScrollEventAxis) 87 { 88 // Override to perform client-specific scroll snap point end logic 89 90 } 91 #endif 64 92 }; 65 93 94 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 95 class ScrollController : public AxisScrollSnapAnimatorClient { 96 #else 66 97 class ScrollController { 98 #endif 67 99 WTF_MAKE_NONCOPYABLE(ScrollController); 68 100 … … 71 103 72 104 bool handleWheelEvent(const PlatformWheelEvent&); 73 void snapRubberBandTimerFired();74 105 75 106 bool isRubberBandInProgress() const; 76 107 108 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 109 bool processWheelEventForScrollSnap(const PlatformWheelEvent&); 110 void updateScrollAnimatorsAndTimers(const ScrollableArea&); 111 #endif 112 77 113 private: 114 void startSnapRubberbandTimer(); 78 115 void stopSnapRubberbandTimer(); 79 116 void snapRubberBand(); 117 void snapRubberBandTimerFired(); 80 118 81 119 bool shouldRubberBandInHorizontalDirection(const PlatformWheelEvent&); 82 120 121 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 122 void horizontalScrollSnapTimerFired(); 123 void verticalScrollSnapTimerFired(); 124 void startScrollSnapTimer(ScrollEventAxis) override; 125 void stopScrollSnapTimer(ScrollEventAxis) override; 126 127 LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override; 128 void immediateScrollOnAxis(ScrollEventAxis, float delta) override; 129 #endif 130 83 131 ScrollControllerClient* m_client; 84 85 bool m_inScrollGesture;86 bool m_momentumScrollInProgress;87 bool m_ignoreMomentumScrolls;88 132 89 133 CFTimeInterval m_lastMomentumScrollTimestamp; … … 97 141 FloatPoint m_origOrigin; 98 142 FloatSize m_origVelocity; 143 RunLoop::Timer<ScrollController> m_snapRubberbandTimer; 99 144 145 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 146 // FIXME: Find a way to consolidate both timers into one variable. 147 std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator; 148 std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator; 149 RunLoop::Timer<ScrollController> m_horizontalScrollSnapTimer; 150 RunLoop::Timer<ScrollController> m_verticalScrollSnapTimer; 151 #endif 152 153 bool m_inScrollGesture; 154 bool m_momentumScrollInProgress; 155 bool m_ignoreMomentumScrolls; 100 156 bool m_snapRubberbandTimerIsActive; 101 157 }; -
trunk/Source/WebCore/platform/cocoa/ScrollController.mm
r180935 r180974 32 32 #include <sys/time.h> 33 33 34 #if ENABLE(CSS_SCROLL_SNAP) 35 #include "AxisScrollSnapAnimator.h" 36 #include "ScrollableArea.h" 37 #endif 38 34 39 #if ENABLE(RUBBER_BANDING) 35 40 … … 92 97 ScrollController::ScrollController(ScrollControllerClient* client) 93 98 : m_client(client) 99 , m_lastMomentumScrollTimestamp(0) 100 , m_startTime(0) 101 , m_snapRubberbandTimer(RunLoop::current(), this, &ScrollController::snapRubberBandTimerFired) 102 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 103 , m_horizontalScrollSnapTimer(RunLoop::current(), this, &ScrollController::horizontalScrollSnapTimerFired) 104 , m_verticalScrollSnapTimer(RunLoop::current(), this, &ScrollController::verticalScrollSnapTimerFired) 105 #endif 94 106 , m_inScrollGesture(false) 95 107 , m_momentumScrollInProgress(false) 96 108 , m_ignoreMomentumScrolls(false) 97 , m_lastMomentumScrollTimestamp(0)98 , m_startTime(0)99 109 , m_snapRubberbandTimerIsActive(false) 100 110 { … … 103 113 bool ScrollController::handleWheelEvent(const PlatformWheelEvent& wheelEvent) 104 114 { 115 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 116 if (!processWheelEventForScrollSnap(wheelEvent)) 117 return false; 118 #endif 105 119 if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) { 106 120 // First, check if we should rubber-band at all. … … 366 380 } 367 381 382 void ScrollController::startSnapRubberbandTimer() 383 { 384 m_client->startSnapRubberbandTimer(); 385 m_snapRubberbandTimer.startRepeating(1.0 / 60.0); 386 } 387 368 388 void ScrollController::stopSnapRubberbandTimer() 369 389 { 370 390 m_client->stopSnapRubberbandTimer(); 391 m_snapRubberbandTimer.stop(); 371 392 m_snapRubberbandTimerIsActive = false; 372 393 } … … 388 409 m_origVelocity = FloatSize(); 389 410 390 m_client->startSnapRubberbandTimer();411 startSnapRubberbandTimer(); 391 412 m_snapRubberbandTimerIsActive = true; 392 413 } … … 402 423 } 403 424 425 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 426 bool ScrollController::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent) 427 { 428 if (m_verticalScrollSnapAnimator) { 429 m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent); 430 if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent)) 431 return false; 432 } 433 if (m_horizontalScrollSnapAnimator) { 434 m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent); 435 if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent)) 436 return false; 437 } 438 439 return true; 440 } 441 442 void ScrollController::updateScrollAnimatorsAndTimers(const ScrollableArea& scrollableArea) 443 { 444 // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated. 445 if (scrollableArea.horizontalSnapOffsets()) 446 m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal); 447 else if (m_horizontalScrollSnapAnimator) 448 m_horizontalScrollSnapAnimator = nullptr; 449 450 if (scrollableArea.verticalSnapOffsets()) 451 m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical); 452 else if (m_verticalScrollSnapAnimator) 453 m_verticalScrollSnapAnimator = nullptr; 454 } 455 456 void ScrollController::startScrollSnapTimer(ScrollEventAxis axis) 457 { 458 RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer; 459 if (!scrollSnapTimer.isActive()) 460 scrollSnapTimer.startRepeating(1.0 / 60.0); 461 } 462 463 void ScrollController::stopScrollSnapTimer(ScrollEventAxis axis) 464 { 465 RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer; 466 scrollSnapTimer.stop(); 467 } 468 469 void ScrollController::horizontalScrollSnapTimerFired() 470 { 471 if (m_horizontalScrollSnapAnimator) 472 m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate(); 473 } 474 475 void ScrollController::verticalScrollSnapTimerFired() 476 { 477 if (m_verticalScrollSnapAnimator) 478 m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate(); 479 } 480 481 LayoutUnit ScrollController::scrollOffsetOnAxis(ScrollEventAxis axis) 482 { 483 return m_client->scrollOffsetOnAxis(axis); 484 } 485 486 void ScrollController::immediateScrollOnAxis(ScrollEventAxis axis, float delta) 487 { 488 m_client->immediateScrollOnAxis(axis, delta); 489 } 490 #endif 491 404 492 } // namespace WebCore 405 493 -
trunk/Source/WebCore/platform/mac/AxisScrollSnapAnimator.h
r180915 r180974 58 58 59 59 public: 60 virtual LayoutUnit scrollOffset InAxis(ScrollEventAxis) = 0;61 virtual void immediateScroll InAxis(ScrollEventAxis, float velocity) = 0;60 virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0; 61 virtual void immediateScrollOnAxis(ScrollEventAxis, float velocity) = 0; 62 62 virtual void startScrollSnapTimer(ScrollEventAxis) = 0; 63 63 virtual void stopScrollSnapTimer(ScrollEventAxis) = 0; -
trunk/Source/WebCore/platform/mac/AxisScrollSnapAnimator.mm
r180915 r180974 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 118 118 endScrollSnapAnimation(ScrollSnapState::UserInteraction); 119 119 pushInitialWheelDelta(wheelDelta); 120 m_beginTrackingWheelDeltaOffset = m_client->scrollOffset InAxis(m_axis);120 m_beginTrackingWheelDeltaOffset = m_client->scrollOffsetOnAxis(m_axis); 121 121 break; 122 122 … … 154 154 float delta = m_currentState == ScrollSnapState::Snapping ? computeSnapDelta() : computeGlideDelta(); 155 155 if (delta) 156 m_client->immediateScroll InAxis(m_axis, delta);156 m_client->immediateScrollOnAxis(m_axis, delta); 157 157 else 158 158 endScrollSnapAnimation(ScrollSnapState::DestinationReached); … … 162 162 { 163 163 ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping); 164 LayoutUnit offset = m_client->scrollOffset InAxis(m_axis);164 LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis); 165 165 float initialWheelDelta = newState == ScrollSnapState::Gliding ? averageInitialWheelDelta() : 0; 166 166 LayoutUnit projectedScrollDestination = newState == ScrollSnapState::Gliding ? m_beginTrackingWheelDeltaOffset + LayoutUnit(projectedInertialScrollDistance(initialWheelDelta)) : offset; … … 204 204 float AxisScrollSnapAnimator::computeSnapDelta() const 205 205 { 206 LayoutUnit offset = m_client->scrollOffset InAxis(m_axis);206 LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis); 207 207 bool canComputeSnap = (m_initialOffset <= offset && offset < m_targetOffset) || (m_targetOffset < offset && offset <= m_initialOffset); 208 208 if (m_currentState != ScrollSnapState::Snapping || !canComputeSnap) … … 238 238 float AxisScrollSnapAnimator::computeGlideDelta() const 239 239 { 240 LayoutUnit offset = m_client->scrollOffset InAxis(m_axis);240 LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis); 241 241 bool canComputeGlide = (m_initialOffset <= offset && offset < m_targetOffset) || (m_targetOffset < offset && offset <= m_initialOffset); 242 242 if (m_currentState != ScrollSnapState::Gliding || !canComputeGlide) -
trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h
r180915 r180974 33 33 #include "FloatSize.h" 34 34 #include "ScrollAnimator.h" 35 #include "ScrollController.h"36 35 #include "Timer.h" 37 36 #include <wtf/RetainPtr.h> … … 43 42 typedef id ScrollbarPainterController; 44 43 45 #if !ENABLE(RUBBER_BANDING)46 class ScrollControllerClient { };47 #endif48 49 44 namespace WebCore { 50 45 51 46 class Scrollbar; 52 47 53 class ScrollAnimatorMac : public ScrollAnimator , private ScrollControllerClient{48 class ScrollAnimatorMac : public ScrollAnimator { 54 49 55 50 public: … … 151 146 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override; 152 147 virtual void immediateScrollBy(const FloatSize&) override; 153 virtual void startSnapRubberbandTimer() override;154 virtual void stopSnapRubberbandTimer() override;155 148 virtual void adjustScrollPositionToBoundsIfNecessary() override; 156 149 157 150 bool pinnedInDirection(float deltaX, float deltaY); 158 void snapRubberBandTimerFired();159 151 160 152 bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis); 161 162 ScrollController m_scrollController;163 Timer m_snapRubberBandTimer;164 153 #endif 165 154 -
trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm
r180915 r180974 644 644 , m_initialScrollbarPaintTimer(*this, &ScrollAnimatorMac::initialScrollbarPaintTimerFired) 645 645 , m_sendContentAreaScrolledTimer(*this, &ScrollAnimatorMac::sendContentAreaScrolledTimerFired) 646 #if ENABLE(RUBBER_BANDING)647 , m_scrollController(this)648 , m_snapRubberBandTimer(*this, &ScrollAnimatorMac::snapRubberBandTimerFired)649 #endif650 646 , m_haveScrolledSincePageLoad(false) 651 647 , m_needsScrollerStyleUpdate(false) … … 1271 1267 notifyPositionChanged(adjustedDelta); 1272 1268 } 1273 1274 void ScrollAnimatorMac::startSnapRubberbandTimer()1275 {1276 m_snapRubberBandTimer.startRepeating(1.0 / 60.0);1277 }1278 1279 void ScrollAnimatorMac::stopSnapRubberbandTimer()1280 {1281 m_snapRubberBandTimer.stop();1282 }1283 1284 void ScrollAnimatorMac::snapRubberBandTimerFired()1285 {1286 m_scrollController.snapRubberBandTimerFired();1287 }1288 1269 #endif 1289 1270
Note: See TracChangeset
for help on using the changeset viewer.