Changeset 280492 in webkit
- Timestamp:
- Jul 30, 2021, 1:26:51 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 10 edited
-
ChangeLog (modified) (1 diff)
-
Sources.txt (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (4 diffs)
-
dom/Node.cpp (modified) (1 diff)
-
page/EventHandler.cpp (modified) (6 diffs)
-
page/EventHandler.h (modified) (1 diff)
-
platform/KeyboardScrollingAnimator.cpp (added)
-
platform/KeyboardScrollingAnimator.h (added)
-
platform/ScrollAnimator.cpp (modified) (3 diffs)
-
platform/ScrollAnimator.h (modified) (4 diffs)
-
platform/ScrollController.cpp (modified) (5 diffs)
-
platform/ScrollController.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r280491 r280492 1 2021-07-30 Dana Estra <destra@apple.com> 2 3 Add key-driven smooth scrolling to macOS 4 https://bugs.webkit.org/show_bug.cgi?id=228009 5 6 Reviewed by Tim Horton. 7 8 Cause keyboard scroll event to trigger start of smooth scroll animation, using same physics implementation as iOS smooth scrolling. 9 10 No tests yet. 11 12 * WebCore.xcodeproj/project.pbxproj: 13 * dom/Node.cpp: 14 (WebCore::Node::defaultEventHandler): 15 * page/EventHandler.cpp: 16 (WebCore::EventHandler::defaultKeyboardEventHandler): 17 (WebCore::EventHandler::scrollDistance): 18 (WebCore::EventHandler::stopKeyboardScrolling): 19 (WebCore::EventHandler::startKeyboardScrolling): 20 * platform/KeyboardScrollingAnimator.cpp: Added. 21 * platform/KeyboardScrollingAnimator.h: Added. 22 * platform/ScrollAnimator.cpp: 23 (WebCore::ScrollAnimator::startAnimationCallback): 24 * platform/ScrollAnimator.h: 25 * platform/ScrollController.cpp: 26 (WebCore::ScrollController::animationCallback): 27 (WebCore::ScrollController::startOrStopAnimationCallbacks): 28 (WebCore::ScrollController::beginKeyboardScrolling): 29 (WebCore::ScrollController::stopKeyboardScrolling): 30 (WebCore::ScrollController::setIsAnimatingKeyboardScrolling): 31 (WebCore::ScrollController::updateKeyboardScrollingAnimatingState): 32 * platform/ScrollController.h: 33 (WebCore::ScrollControllerClient::updateKeyboardScrollPosition): 34 1 35 2021-07-30 Chris Dumez <cdumez@apple.com> 2 36 -
trunk/Source/WebCore/Sources.txt
r280467 r280492 1746 1746 platform/FileStream.cpp 1747 1747 platform/FrameRateMonitor.cpp 1748 platform/KeyboardScrollingAnimator.cpp 1748 1749 platform/LayoutUnit.cpp 1749 1750 platform/LegacySchemeRegistry.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r280467 r280492 674 674 1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; }; 675 675 1FC40FBA1655CCB90040F29E /* SubimageCacheWithTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FC40FB71655C5910040F29E /* SubimageCacheWithTimer.h */; }; 676 1FD992F826AA24F90088E596 /* KeyboardScrollingAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FD992F626AA24F80088E596 /* KeyboardScrollingAnimator.h */; settings = {ATTRIBUTES = (Private, ); }; }; 676 677 20D629271253690B00081543 /* InspectorInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 20D629251253690B00081543 /* InspectorInstrumentation.h */; }; 677 678 225A16B50D5C11E900090295 /* WebEventRegion.h in Headers */ = {isa = PBXBuildFile; fileRef = 225A16B30D5C11E900090295 /* WebEventRegion.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 7014 7015 1FC40FB71655C5910040F29E /* SubimageCacheWithTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SubimageCacheWithTimer.h; sourceTree = "<group>"; }; 7015 7016 1FC40FB81655C5910040F29E /* SubimageCacheWithTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SubimageCacheWithTimer.cpp; sourceTree = "<group>"; }; 7017 1FD992F626AA24F80088E596 /* KeyboardScrollingAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyboardScrollingAnimator.h; sourceTree = "<group>"; }; 7018 1FD992F926AA254D0088E596 /* KeyboardScrollingAnimator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyboardScrollingAnimator.cpp; sourceTree = "<group>"; }; 7016 7019 20D629241253690B00081543 /* InspectorInstrumentation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorInstrumentation.cpp; sourceTree = "<group>"; }; 7017 7020 20D629251253690B00081543 /* InspectorInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorInstrumentation.h; sourceTree = "<group>"; }; … … 27553 27556 A8748BDF12CBF2DC001FBA41 /* HashTools.h */, 27554 27557 BC3BC29B0E91AB0F00835588 /* HostWindow.h */, 27558 1FD992F926AA254D0088E596 /* KeyboardScrollingAnimator.cpp */, 27559 1FD992F626AA24F80088E596 /* KeyboardScrollingAnimator.h */, 27555 27560 1AE00D57182DAC8D00087DD7 /* KeyedCoding.h */, 27556 27561 E15FF7D418C9553800FE4C87 /* KeypressCommand.h */, … … 33334 33339 85031B440A44EFC700F992E0 /* KeyboardEvent.h in Headers */, 33335 33340 1F020AEF26780FCE0000809A /* KeyboardScroll.h in Headers */, 33341 1FD992F826AA24F90088E596 /* KeyboardScrollingAnimator.h in Headers */, 33336 33342 1AE00D59182DAC8D00087DD7 /* KeyedCoding.h in Headers */, 33337 33343 517A63C51B74318F00E7DCDC /* KeyedDecoderCF.h in Headers */, -
trunk/Source/WebCore/dom/Node.cpp
r280174 r280492 2433 2433 return; 2434 2434 const AtomString& eventType = event.type(); 2435 if (eventType == eventNames().keydownEvent || eventType == eventNames().keypressEvent ) {2435 if (eventType == eventNames().keydownEvent || eventType == eventNames().keypressEvent || eventType == eventNames().keyupEvent) { 2436 2436 if (is<KeyboardEvent>(event)) { 2437 2437 if (Frame* frame = document().frame()) -
trunk/Source/WebCore/page/EventHandler.cpp
r280190 r280492 69 69 #include "InspectorInstrumentation.h" 70 70 #include "KeyboardEvent.h" 71 #include "KeyboardScroll .h"71 #include "KeyboardScrollingAnimator.h" 72 72 #include "Logging.h" 73 73 #include "MouseEvent.h" … … 3804 3804 defaultSpaceEventHandler(event); 3805 3805 } 3806 if (event.type() == eventNames().keyupEvent) { 3807 m_frame.editor().handleKeyboardEvent(event); 3808 if (event.defaultHandled()) 3809 return; 3810 stopKeyboardScrolling(); 3811 } 3806 3812 } 3807 3813 … … 4198 4204 return; 4199 4205 4200 bool defaultHandled = m_frame.settings().eventHandlerDrivenSmoothKeyboardScrollingEnabled() ? handleKeyboardScrolling(event) : view->logicalScroll(direction, ScrollByPage);4206 bool defaultHandled = m_frame.settings().eventHandlerDrivenSmoothKeyboardScrollingEnabled() ? startKeyboardScrolling(event) : view->logicalScroll(direction, ScrollByPage); 4201 4207 if (defaultHandled) 4202 4208 event.setDefaultHandled(); … … 4238 4244 return m_frame.view()->horizontalScrollbar(); 4239 4245 }(); 4240 4246 4241 4247 switch (granularity) { 4242 4248 case ScrollGranularity::ScrollByLine: … … 4253 4259 } 4254 4260 4255 bool EventHandler::handleKeyboardScrolling(KeyboardEvent& event)4261 void EventHandler::stopKeyboardScrolling() 4256 4262 { 4257 4263 Ref protectedFrame = m_frame; 4258 // FIXME (bug 227459): This logic does not account for writing-mode. 4259 4260 enum class Key : uint8_t { LeftArrow, RightArrow, UpArrow, DownArrow, Space }; 4261 4262 Key key; 4263 if (event.keyIdentifier() == "Left") 4264 key = Key::LeftArrow; 4265 else if (event.keyIdentifier() == "Right") 4266 key = Key::RightArrow; 4267 else if (event.keyIdentifier() == "Up") 4268 key = Key::UpArrow; 4269 else if (event.keyIdentifier() == "Down") 4270 key = Key::DownArrow; 4271 else if (event.charCode() == ' ') 4272 key = Key::Space; 4273 else 4274 return false; 4275 4276 auto granularity = [&] { 4277 switch (key) { 4278 case Key::LeftArrow: 4279 case Key::RightArrow: 4280 return event.altKey() ? ScrollGranularity::ScrollByPage : ScrollGranularity::ScrollByLine; 4281 case Key::UpArrow: 4282 case Key::DownArrow: 4283 if (event.metaKey()) 4284 return ScrollGranularity::ScrollByDocument; 4285 if (event.altKey()) 4286 return ScrollGranularity::ScrollByPage; 4287 return ScrollGranularity::ScrollByLine; 4288 case Key::Space: 4289 return ScrollGranularity::ScrollByPage; 4290 }; 4291 RELEASE_ASSERT_NOT_REACHED(); 4292 }(); 4293 4294 auto direction = [&] { 4295 switch (key) { 4296 case Key::LeftArrow: 4297 return ScrollDirection::ScrollLeft; 4298 case Key::RightArrow: 4299 return ScrollDirection::ScrollRight; 4300 case Key::UpArrow: 4301 return ScrollDirection::ScrollUp; 4302 case Key::DownArrow: 4303 return ScrollDirection::ScrollDown; 4304 case Key::Space: 4305 return event.shiftKey() ? ScrollDirection::ScrollUp : ScrollDirection::ScrollDown; 4306 } 4307 RELEASE_ASSERT_NOT_REACHED(); 4308 }(); 4309 4310 return EventHandler::scrollRecursively(direction, granularity, nullptr); 4264 FrameView* view = m_frame.view(); 4265 4266 KeyboardScrollingAnimator* animator = view->scrollAnimator().keyboardScrollingAnimator(); 4267 4268 if (animator) 4269 animator->handleKeyUpEvent(); 4270 } 4271 4272 bool EventHandler::startKeyboardScrolling(KeyboardEvent& event) 4273 { 4274 Ref protectedFrame = m_frame; 4275 FrameView* view = m_frame.view(); 4276 4277 KeyboardScrollingAnimator* animator = view->scrollAnimator().keyboardScrollingAnimator(); 4278 4279 if (animator) 4280 return animator->beginKeyboardScrollGesture(event); 4281 4282 return false; 4311 4283 } 4312 4284 … … 4317 4289 if (!isSpatialNavigationEnabled(&m_frame)) { 4318 4290 if (m_frame.settings().eventHandlerDrivenSmoothKeyboardScrollingEnabled()) 4319 handleKeyboardScrolling(event);4291 startKeyboardScrolling(event); 4320 4292 return; 4321 4293 } -
trunk/Source/WebCore/page/EventHandler.h
r280190 r280492 378 378 379 379 float scrollDistance(ScrollDirection, ScrollGranularity); 380 bool handleKeyboardScrolling(KeyboardEvent&); 380 bool startKeyboardScrolling(KeyboardEvent&); 381 void stopKeyboardScrolling(); 381 382 382 383 #if ENABLE(DRAG_SUPPORT) -
trunk/Source/WebCore/platform/ScrollAnimator.cpp
r280171 r280492 34 34 35 35 #include "FloatPoint.h" 36 #include "KeyboardScrollingAnimator.h" 36 37 #include "LayoutSize.h" 37 38 #include "PlatformWheelEvent.h" … … 68 69 m_scrollableArea.setScrollBehaviorStatus(ScrollBehaviorStatus::NotInAnimation); 69 70 })) 71 , m_keyboardScrollingAnimator(makeUnique<KeyboardScrollingAnimator>(*this, m_scrollController)) 70 72 { 71 73 } … … 333 335 if (m_scrollControllerAnimationTimer.isActive()) 334 336 return; 335 337 336 338 m_scrollControllerAnimationTimer.startRepeating(1_s / 60.); 337 339 } -
trunk/Source/WebCore/platform/ScrollAnimator.h
r280171 r280492 35 35 #include "PlatformWheelEvent.h" 36 36 #include "ScrollController.h" 37 #include "ScrollTypes.h"38 37 #include "Timer.h" 39 38 #include "WheelEventTestMonitor.h" … … 44 43 45 44 class FloatPoint; 45 class KeyboardScrollingAnimator; 46 46 class PlatformTouchEvent; 47 47 class ScrollAnimation; … … 81 81 82 82 virtual bool handleWheelEvent(const PlatformWheelEvent&); 83 84 KeyboardScrollingAnimator *keyboardScrollingAnimator() const override { return m_keyboardScrollingAnimator.get(); } 83 85 84 86 #if ENABLE(TOUCH_EVENTS) … … 179 181 180 182 std::unique_ptr<ScrollAnimation> m_scrollAnimation; 183 std::unique_ptr<KeyboardScrollingAnimator> m_keyboardScrollingAnimator; 181 184 }; 182 185 -
trunk/Source/WebCore/platform/ScrollController.cpp
r280171 r280492 27 27 #include "ScrollController.h" 28 28 29 #include "KeyboardScrollingAnimator.h" 29 30 #include "LayoutSize.h" 30 31 #include "Logging.h" … … 44 45 void ScrollController::animationCallback(MonotonicTime currentTime) 45 46 { 46 LOG_WITH_STREAM(Scrolling, stream << "ScrollController " << this << " animationCallback: isAnimatingRubberBand " << m_isAnimatingRubberBand << " isAnimatingScrollSnap " << m_isAnimatingScrollSnap );47 LOG_WITH_STREAM(Scrolling, stream << "ScrollController " << this << " animationCallback: isAnimatingRubberBand " << m_isAnimatingRubberBand << " isAnimatingScrollSnap " << m_isAnimatingScrollSnap << "isAnimatingKeyboardScrolling" << m_isAnimatingKeyboardScrolling); 47 48 48 49 updateScrollSnapAnimatingState(currentTime); 49 50 updateRubberBandAnimatingState(currentTime); 51 updateKeyboardScrollingAnimatingState(currentTime); 50 52 } 51 53 52 54 void ScrollController::startOrStopAnimationCallbacks() 53 55 { 54 bool needsCallbacks = m_isAnimatingRubberBand || m_isAnimatingScrollSnap ;56 bool needsCallbacks = m_isAnimatingRubberBand || m_isAnimatingScrollSnap || m_isAnimatingKeyboardScrolling; 55 57 if (needsCallbacks == m_isRunningAnimatingCallback) 56 58 return; … … 66 68 } 67 69 70 void ScrollController::beginKeyboardScrolling() 71 { 72 setIsAnimatingKeyboardScrolling(true); 73 } 74 75 void ScrollController::stopKeyboardScrolling() 76 { 77 setIsAnimatingKeyboardScrolling(false); 78 } 79 68 80 void ScrollController::setIsAnimatingRubberBand(bool isAnimatingRubberBand) 69 81 { … … 81 93 82 94 m_isAnimatingScrollSnap = isAnimatingScrollSnap; 95 startOrStopAnimationCallbacks(); 96 } 97 98 void ScrollController::setIsAnimatingKeyboardScrolling(bool isAnimatingKeyboardScrolling) 99 { 100 if (isAnimatingKeyboardScrolling == m_isAnimatingKeyboardScrolling) 101 return; 102 103 m_isAnimatingKeyboardScrolling = isAnimatingKeyboardScrolling; 83 104 startOrStopAnimationCallbacks(); 84 105 } … … 199 220 200 221 } 222 223 void ScrollController::updateKeyboardScrollingAnimatingState(MonotonicTime currentTime) 224 { 225 if (!m_isAnimatingKeyboardScrolling) 226 return; 227 228 m_client.keyboardScrollingAnimator()->updateKeyboardScrollPosition(currentTime); 229 } 230 201 231 // Currently, only Mac supports momentum srolling-based scrollsnapping and rubber banding 202 232 // so all of these methods are a noop on non-Mac platforms. -
trunk/Source/WebCore/platform/ScrollController.h
r280171 r280492 39 39 namespace WebCore { 40 40 41 class KeyboardScrollingAnimator; 41 42 class LayoutSize; 42 43 class PlatformWheelEvent; … … 72 73 virtual void startAnimationCallback(ScrollController&) = 0; 73 74 virtual void stopAnimationCallback(ScrollController&) = 0; 75 76 virtual void updateKeyboardScrollPosition(MonotonicTime) { } 77 virtual KeyboardScrollingAnimator *keyboardScrollingAnimator() const { return nullptr; } 74 78 75 79 #if ENABLE(RUBBER_BANDING) … … 122 126 void stopAllTimers(); 123 127 void scrollPositionChanged(); 128 129 void beginKeyboardScrolling(); 130 void stopKeyboardScrolling(); 124 131 125 132 // Should be called periodically by the client. Started by startAnimationCallback(), stopped by stopAnimationCallback(). … … 164 171 void updateScrollSnapAnimatingState(MonotonicTime); 165 172 void updateRubberBandAnimatingState(MonotonicTime); 166 173 void updateKeyboardScrollingAnimatingState(MonotonicTime); 174 167 175 void setIsAnimatingRubberBand(bool); 168 176 void setIsAnimatingScrollSnap(bool); 177 void setIsAnimatingKeyboardScrolling(bool); 169 178 170 179 #if PLATFORM(MAC) … … 200 209 bool m_isAnimatingRubberBand { false }; 201 210 bool m_isAnimatingScrollSnap { false }; 211 bool m_isAnimatingKeyboardScrolling { false }; 202 212 203 213 #if PLATFORM(MAC)
Note:
See TracChangeset
for help on using the changeset viewer.