Changeset 180902 in webkit
- Timestamp:
- Mar 2, 2015 3:49:24 PM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r180901 r180902 1 2015-03-02 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 No change in functionality. 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::scrollOffsetOnAxis): Add temporary stub needed 29 until Bug 141973 is completed.). 30 (WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis): Ditto. 31 (WebCore::ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer): Deleted. 32 (WebCore::ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer): Deleted. 33 * platform/ScrollAnimator.cpp: 34 (WebCore::ScrollAnimator::ScrollAnimator): 35 (WebCore::ScrollAnimator::processWheelEventForScrollSnap): Just call the ScrollController method. 36 (WebCore::ScrollAnimator::handleWheelEvent): Ditto. 37 (WebCore::ScrollAnimator::updateScrollAnimatorsAndTimers): Ditto. 38 (WebCore::ScrollAnimator::scrollOffsetOnAxis): Renamed from scrollOffsetInAxis. 39 (WebCore::ScrollAnimator::scrollOffsetInAxis): Deleted. 40 (WebCore::ScrollAnimator::immediateScrollOnAxis): Renamed from immediateScrollInAxis. 41 (WebCore::ScrollAnimator::immediateScrollInAxis): Deleted. 42 (WebCore::ScrollAnimator::startScrollSnapTimer): Deleted. 43 (WebCore::ScrollAnimator::stopScrollSnapTimer): Deleted. 44 (WebCore::ScrollAnimator::horizontalScrollSnapTimerFired): Deleted. 45 (WebCore::ScrollAnimator::verticalScrollSnapTimerFired): Deleted. 46 * platform/ScrollAnimator.h: 47 * platform/cocoa/ScrollController.h: Copied from platform/mac/ScrollController.h. 48 * platform/cocoa/ScrollController.mm: Copied from platform/mac/ScrollController.mm. 49 (WebCore::ScrollController::ScrollController): Update to initialize new timers. 50 (WebCore::ScrollController::handleWheelEvent): Update to handle Scroll Snap Point events. 51 (WebCore::ScrollController::startSnapRubberbandTimer): Added. 52 (WebCore::ScrollController::stopSnapRubberbandTimer): Manage animation timers locally, do not 53 require client to maintain timers. 54 (WebCore::ScrollController::snapRubberBand): Ditto. 55 (WebCore::ScrollController::processWheelEventForScrollSnap): Added. (Moved from ScrollAnimatorMac) 56 (WebCore::ScrollController::updateScrollAnimatorsAndTimers): Ditto. Also updated to use RunLoop::Timer. 57 (WebCore::ScrollController::startScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer. 58 (WebCore::ScrollController::stopScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer. 59 (WebCore::ScrollController::horizontalScrollSnapTimerFired): Ditto. 60 (WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto. 61 (WebCore::ScrollController::scrollOffsetOnAxis): Moved from ScrollAnimatorMac. 62 (WebCore::ScrollController::immediateScrollOnAxis): Ditto. 63 * platform/mac/AxisScrollSnapAnimator.h: Rename methods from 'InAxis' to 'OnAxis' 64 * platform/mac/AxisScrollSnapAnimator.mm: Ditto. 65 * platform/mac/ScrollAnimatorMac.h: 66 * platform/mac/ScrollAnimatorMac.mm: 67 (WebCore::ScrollAnimatorMac::ScrollAnimatorMac): Remove unused Rubberband timers (now that this is 68 controlled in the ScrollController) 69 (WebCore::ScrollAnimatorMac::startSnapRubberbandTimer): Deleted. 70 (WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer): Deleted. 71 (WebCore::ScrollAnimatorMac::snapRubberBandTimerFired): Deleted. 72 * platform/mac/ScrollController.h: Removed. 73 * platform/mac/ScrollController.mm: Removed. 74 1 75 2015-03-02 Mark Lam <mark.lam@apple.com> 2 76 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r180798 r180902 787 787 1A927FD41416A15B003A83C8 /* nptypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD11416A15B003A83C8 /* nptypes.h */; settings = {ATTRIBUTES = (Private, ); }; }; 788 788 1A98956B0AA78F80005EF5EF /* URLCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A98956A0AA78F80005EF5EF /* URLCF.cpp */; }; 789 1AA84F04143BA7BD0051D153 /* ScrollController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA84F02143BA7BD0051D153 /* ScrollController.mm */; };790 1AA84F05143BA7BD0051D153 /* ScrollController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA84F03143BA7BD0051D153 /* ScrollController.h */; settings = {ATTRIBUTES = (Private, ); }; };791 789 1AA8799011CBE846003C664F /* PluginStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA8798F11CBE846003C664F /* PluginStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; }; 792 790 1AAADDA314DB409F00AF64B3 /* ScrollingTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AAADDA114DB409F00AF64B3 /* ScrollingTree.cpp */; }; … … 2446 2444 7A93868518DCC14500B8263D /* VTTScanner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A93868218DCC14500B8263D /* VTTScanner.cpp */; }; 2447 2445 7A93868618DCC14500B8263D /* VTTScanner.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A93868318DCC14500B8263D /* VTTScanner.h */; }; 2446 7A9ADFF31AA1163800D2733C /* ScrollController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AFFA4111AA1039D00F0125B /* ScrollController.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2447 7A9ADFF41AA1163B00D2733C /* ScrollController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFA4121AA1039D00F0125B /* ScrollController.mm */; }; 2448 2448 7AA3A699194A64E7001CBD24 /* TileController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AA3A695194A64E7001CBD24 /* TileController.cpp */; }; 2449 2449 7AA3A69A194A64E7001CBD24 /* TileController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AA3A696194A64E7001CBD24 /* TileController.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 7810 7810 1A927FD11416A15B003A83C8 /* nptypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nptypes.h; sourceTree = "<group>"; }; 7811 7811 1A98956A0AA78F80005EF5EF /* URLCF.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = URLCF.cpp; sourceTree = "<group>"; }; 7812 1AA84F02143BA7BD0051D153 /* ScrollController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollController.mm; sourceTree = "<group>"; };7813 1AA84F03143BA7BD0051D153 /* ScrollController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollController.h; sourceTree = "<group>"; };7814 7812 1AA8798F11CBE846003C664F /* PluginStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginStrategy.h; sourceTree = "<group>"; }; 7815 7813 1AAADDA114DB409F00AF64B3 /* ScrollingTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingTree.cpp; sourceTree = "<group>"; }; … … 9668 9666 7AF9B20A18CFB5F300C64BEF /* JSVTTRegionList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSVTTRegionList.cpp; sourceTree = "<group>"; }; 9669 9667 7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSVTTRegionList.h; sourceTree = "<group>"; }; 9668 7AFFA4111AA1039D00F0125B /* ScrollController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollController.h; sourceTree = "<group>"; }; 9669 7AFFA4121AA1039D00F0125B /* ScrollController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollController.mm; sourceTree = "<group>"; }; 9670 9670 7C2BDD3B17C7F98B0038FF15 /* JSDOMGlobalObjectTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMGlobalObjectTask.cpp; sourceTree = "<group>"; }; 9671 9671 7C2BDD3C17C7F98B0038FF15 /* JSDOMGlobalObjectTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMGlobalObjectTask.h; sourceTree = "<group>"; }; … … 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 7AFFA4111AA1039D00F0125B /* ScrollController.h */, 18700 7AFFA4121AA1039D00F0125B /* ScrollController.mm */, 18701 18701 5D5975B119635F1100D00878 /* SystemVersion.h */, 18702 18702 5D5975B219635F1100D00878 /* SystemVersion.mm */, … … 24649 24649 A871D4580A127CBC00B12A68 /* HTMLParamElement.h in Headers */, 24650 24650 93E2A307123E9DC0009FE12A /* HTMLParserIdioms.h in Headers */, 24651 7A9ADFF31AA1163800D2733C /* ScrollController.h in Headers */, 24651 24652 973F418A169B95FF0006BF60 /* HTMLParserOptions.h in Headers */, 24652 24653 977B3871122883E900B81FF8 /* HTMLParserScheduler.h in Headers */, … … 26102 26103 0FE71406142170B800DB33BA /* ScrollbarThemeMock.h in Headers */, 26103 26104 5D925B680F64D4DD00B847F0 /* ScrollBehavior.h in Headers */, 26104 1AA84F05143BA7BD0051D153 /* ScrollController.h in Headers */,26105 26105 0F605AED15F94848004DF0C0 /* ScrollingConstraints.h in Headers */, 26106 26106 1AF62EE814DA22A70041556C /* ScrollingCoordinator.h in Headers */, … … 27497 27497 E1FE13641834351100892F13 /* CryptoDigestMac.cpp in Sources */, 27498 27498 E157A8E418173A3A009F821D /* CryptoKey.cpp in Sources */, 27499 7A9ADFF41AA1163B00D2733C /* ScrollController.mm in Sources */, 27499 27500 E125F84D1824289D00D84CD9 /* CryptoKeyAES.cpp in Sources */, 27500 27501 E125F863182C303A00D84CD9 /* CryptoKeyDataOctetSequence.cpp in Sources */, … … 29509 29510 0FE71405142170B800DB33BA /* ScrollbarThemeMock.cpp in Sources */, 29510 29511 5D925B670F64D4DD00B847F0 /* ScrollBehavior.cpp in Sources */, 29511 1AA84F04143BA7BD0051D153 /* ScrollController.mm in Sources */,29512 29512 0F605AEC15F94848004DF0C0 /* ScrollingConstraints.cpp in Sources */, 29513 29513 1AF62EE714DA22A70041556C /* ScrollingCoordinator.cpp in Sources */, -
trunk/Source/WebCore/page/mac/EventHandlerMac.mm
r180426 r180902 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
r180447 r180902 62 62 virtual void immediateScrollBy(const FloatSize&) override; 63 63 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override; 64 virtual void startSnapRubberbandTimer() override;65 virtual void stopSnapRubberbandTimer() override;66 64 virtual void adjustScrollPositionToBoundsIfNecessary() override; 67 65 … … 81 79 bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis); 82 80 81 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 82 LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override; 83 void immediateScrollOnAxis(ScrollEventAxis, float delta) override; 84 #endif 85 83 86 void logExposedUnfilledArea(); 84 87 85 88 ScrollController m_scrollController; 86 RetainPtr<CFRunLoopTimerRef> m_snapRubberbandTimer;87 89 88 90 RetainPtr<CALayer> m_scrollLayer; -
trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm
r180447 r180902 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 void ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer()312 {313 if (!m_snapRubberbandTimer)314 return;315 316 scrollingTree().setMainFrameIsRubberBanding(false);317 318 // Since the rubberband timer has stopped, totalContentsSizeForRubberBand can be synchronized with totalContentsSize.319 setTotalContentsSizeForRubberBand(totalContentsSize());320 321 CFRunLoopTimerInvalidate(m_snapRubberbandTimer.get());322 m_snapRubberbandTimer = nullptr;323 }324 325 297 void ScrollingTreeFrameScrollingNodeMac::adjustScrollPositionToBoundsIfNecessary() 326 298 { … … 541 513 } 542 514 515 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 516 LayoutUnit ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis(ScrollEventAxis) 517 { 518 // Temporary stub until http://webkit.org/b/141973. 519 return 0; 520 } 521 522 void ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis(ScrollEventAxis, float) 523 { 524 // Temporary stub until http://webkit.org/b/141973. 525 } 526 #endif 527 543 528 } // namespace WebCore 544 529 -
trunk/Source/WebCore/platform/ScrollAnimator.cpp
r180873 r180902 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 m_scrollController.processWheelEventForScrollSnap(e); 106 97 #endif 107 98 #if PLATFORM(COCOA) … … 184 175 void ScrollAnimator::updateScrollAnimatorsAndTimers() 185 176 { 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 } 177 m_scrollController.updateScrollAnimatorsAndTimers(m_scrollableArea); 201 178 } 202 179 203 LayoutUnit ScrollAnimator::scrollOffset InAxis(ScrollEventAxis axis)180 LayoutUnit ScrollAnimator::scrollOffsetOnAxis(ScrollEventAxis axis) 204 181 { 205 FloatPoint currentPosition = this->currentPosition(); 206 return axis == ScrollEventAxis::Horizontal ? currentPosition.x() : currentPosition.y(); 182 return axis == ScrollEventAxis::Horizontal ? m_currentPosX : m_currentPosY; 207 183 } 208 184 209 void ScrollAnimator::immediateScroll InAxis(ScrollEventAxis axis, float delta)185 void ScrollAnimator::immediateScrollOnAxis(ScrollEventAxis axis, float delta) 210 186 { 211 187 FloatPoint currentPosition = this->currentPosition(); … … 215 191 scrollToOffsetWithoutAnimation(FloatPoint(currentPosition.x(), currentPosition.y() + delta)); 216 192 } 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 193 #endif 242 194 -
trunk/Source/WebCore/platform/ScrollAnimator.h
r180873 r180902 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 void processWheelEventForScrollSnap(const PlatformWheelEvent&); 121 bool processWheelEventForScrollSnap(const PlatformWheelEvent&); 122 122 123 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; 124 LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override; 125 void immediateScrollOnAxis(ScrollEventAxis, float delta) override; 127 126 #endif 128 127 … … 130 129 virtual void notifyPositionChanged(const FloatSize& delta); 131 130 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(); 131 ScrollableArea& m_scrollableArea; 132 #if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC) 133 ScrollController m_scrollController; 136 134 #endif 137 138 ScrollableArea& m_scrollableArea;139 135 float m_currentPosX; // We avoid using a FloatPoint in order to reduce 140 136 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 137 }; 149 138 -
trunk/Source/WebCore/platform/cocoa/ScrollController.h
r180702 r180902 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;60 64 61 65 // If the current scroll position is within the overhang area, this function will cause 62 66 // the page to scroll to the nearest boundary point. 63 67 virtual void adjustScrollPositionToBoundsIfNecessary() = 0; 68 69 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 70 virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0; 71 virtual void immediateScrollOnAxis(ScrollEventAxis, float delta) = 0; 72 #endif 64 73 }; 65 74 75 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 76 class ScrollController : public AxisScrollSnapAnimatorClient { 77 #else 66 78 class ScrollController { 79 #endif 67 80 WTF_MAKE_NONCOPYABLE(ScrollController); 68 81 … … 71 84 72 85 bool handleWheelEvent(const PlatformWheelEvent&); 73 void snapRubberBandTimerFired();74 86 75 87 bool isRubberBandInProgress() const; 76 88 89 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 90 bool processWheelEventForScrollSnap(const PlatformWheelEvent&); 91 void updateScrollAnimatorsAndTimers(const ScrollableArea&); 92 #endif 93 77 94 private: 95 void startSnapRubberbandTimer(); 78 96 void stopSnapRubberbandTimer(); 79 97 void snapRubberBand(); 98 void snapRubberBandTimerFired(); 80 99 81 100 bool shouldRubberBandInHorizontalDirection(const PlatformWheelEvent&); 82 101 102 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 103 void horizontalScrollSnapTimerFired(); 104 void verticalScrollSnapTimerFired(); 105 void startScrollSnapTimer(ScrollEventAxis); 106 void stopScrollSnapTimer(ScrollEventAxis); 107 108 LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override; 109 void immediateScrollOnAxis(ScrollEventAxis, float delta) override; 110 #endif 111 83 112 ScrollControllerClient* m_client; 84 85 bool m_inScrollGesture;86 bool m_momentumScrollInProgress;87 bool m_ignoreMomentumScrolls;88 113 89 114 CFTimeInterval m_lastMomentumScrollTimestamp; … … 97 122 FloatPoint m_origOrigin; 98 123 FloatSize m_origVelocity; 124 RunLoop::Timer<ScrollController> m_snapRubberbandTimer; 125 126 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 127 // FIXME: Find a way to consolidate both timers into one variable. 128 std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator; 129 std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator; 130 RunLoop::Timer<ScrollController> m_horizontalScrollSnapTimer; 131 RunLoop::Timer<ScrollController> m_verticalScrollSnapTimer; 132 #endif 99 133 134 bool m_inScrollGesture; 135 bool m_momentumScrollInProgress; 136 bool m_ignoreMomentumScrolls; 100 137 bool m_snapRubberbandTimerIsActive; 101 138 }; -
trunk/Source/WebCore/platform/cocoa/ScrollController.mm
r180702 r180902 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_snapRubberbandTimer.startRepeating(1.0 / 60.0); 385 } 386 368 387 void ScrollController::stopSnapRubberbandTimer() 369 388 { 370 m_ client->stopSnapRubberbandTimer();389 m_snapRubberbandTimer.stop(); 371 390 m_snapRubberbandTimerIsActive = false; 372 391 } … … 388 407 m_origVelocity = FloatSize(); 389 408 390 m_client->startSnapRubberbandTimer();409 startSnapRubberbandTimer(); 391 410 m_snapRubberbandTimerIsActive = true; 392 411 } … … 402 421 } 403 422 423 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) 424 bool ScrollController::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent) 425 { 426 if (m_verticalScrollSnapAnimator) { 427 m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent); 428 if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent)) 429 return false; 430 } 431 if (m_horizontalScrollSnapAnimator) { 432 m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent); 433 if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent)) 434 return false; 435 } 436 437 return true; 438 } 439 440 void ScrollController::updateScrollAnimatorsAndTimers(const ScrollableArea& scrollableArea) 441 { 442 // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated. 443 if (scrollableArea.horizontalSnapOffsets()) 444 m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal); 445 else if (m_horizontalScrollSnapAnimator) 446 m_horizontalScrollSnapAnimator = nullptr; 447 448 if (scrollableArea.verticalSnapOffsets()) 449 m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical); 450 else if (m_verticalScrollSnapAnimator) 451 m_verticalScrollSnapAnimator = nullptr; 452 } 453 454 void ScrollController::startScrollSnapTimer(ScrollEventAxis axis) 455 { 456 RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer; 457 if (!scrollSnapTimer.isActive()) 458 scrollSnapTimer.startRepeating(1.0 / 60.0); 459 } 460 461 void ScrollController::stopScrollSnapTimer(ScrollEventAxis axis) 462 { 463 RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer; 464 scrollSnapTimer.stop(); 465 } 466 467 void ScrollController::horizontalScrollSnapTimerFired() 468 { 469 if (m_horizontalScrollSnapAnimator) 470 m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate(); 471 } 472 473 void ScrollController::verticalScrollSnapTimerFired() 474 { 475 if (m_verticalScrollSnapAnimator) 476 m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate(); 477 } 478 479 LayoutUnit ScrollController::scrollOffsetOnAxis(ScrollEventAxis axis) 480 { 481 return m_client->scrollOffsetOnAxis(axis); 482 } 483 484 void ScrollController::immediateScrollOnAxis(ScrollEventAxis axis, float delta) 485 { 486 m_client->immediateScrollOnAxis(axis, delta); 487 } 488 #endif 489 404 490 } // namespace WebCore 405 491 -
trunk/Source/WebCore/platform/mac/AxisScrollSnapAnimator.h
r173894 r180902 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
r179324 r180902 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
r180474 r180902 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
r180873 r180902 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.