Changeset 217971 in webkit
- Timestamp:
- Jun 9, 2017 1:58:30 AM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 19 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r217969 r217971 1 2017-06-09 Adrien Plazas <aplazas@igalia.com> 2 3 [GTK] Add kinetic scrolling 4 https://bugs.webkit.org/show_bug.cgi?id=155750 5 6 Reviewed by Carlos Garcia Campos. 7 8 Patch by Adrien Plazas and Yusuke Suzuki. 9 10 Add the ScrollAnimationKinetic scrolling animation allowing to perform momentum scrolling; it is based on GTK+'s 11 GtkKineticScrolling type. 12 13 Add the notion of phase, momentum phase and swipe velocity to PlatformWheelEvent. 14 15 Depending on whether the scrolling ended normally or triggered a swipe, the scroll animator will either compute 16 the swipe velocity from the previous scrolling events or use the one from the swipe gesture to initiate the 17 momentum scrolling. 18 19 * PlatformGTK.cmake: 20 * platform/PlatformWheelEvent.h: 21 (WebCore::PlatformWheelEvent::setHasPreciseScrollingDeltas): 22 (WebCore::PlatformWheelEvent::phase): 23 (WebCore::PlatformWheelEvent::momentumPhase): 24 (WebCore::PlatformWheelEvent::isTransitioningToMomentumScroll): 25 * platform/ScrollAnimation.h: 26 (WebCore::ScrollAnimation::scroll): 27 (WebCore::ScrollAnimation::updateVisibleLengths): 28 (WebCore::ScrollAnimation::setCurrentPosition): 29 * platform/ScrollAnimationKinetic.cpp: Added. 30 (WebCore::ScrollAnimationKinetic::PerAxisData::PerAxisData): 31 (WebCore::ScrollAnimationKinetic::PerAxisData::animateScroll): 32 (WebCore::ScrollAnimationKinetic::ScrollAnimationKinetic): 33 (WebCore::ScrollAnimationKinetic::~ScrollAnimationKinetic): 34 (WebCore::ScrollAnimationKinetic::stop): 35 (WebCore::ScrollAnimationKinetic::start): 36 (WebCore::ScrollAnimationKinetic::animationTimerFired): 37 * platform/ScrollAnimationKinetic.h: Copied from Source/WebCore/platform/ScrollAnimation.h. 38 * platform/gtk/PlatformWheelEventGtk.cpp: 39 (WebCore::PlatformWheelEvent::PlatformWheelEvent): 40 (WebCore::PlatformWheelEvent::swipeVelocity): 41 * platform/gtk/ScrollAnimatorGtk.cpp: 42 (WebCore::ScrollAnimatorGtk::ScrollAnimatorGtk): 43 (WebCore::ScrollAnimatorGtk::ensureSmoothScrollingAnimation): 44 (WebCore::ScrollAnimatorGtk::scroll): 45 (WebCore::ScrollAnimatorGtk::scrollToOffsetWithoutAnimation): 46 (WebCore::ScrollAnimatorGtk::computeVelocity): 47 (WebCore::ScrollAnimatorGtk::handleWheelEvent): 48 (WebCore::ScrollAnimatorGtk::willEndLiveResize): 49 (WebCore::ScrollAnimatorGtk::updatePosition): 50 (WebCore::ScrollAnimatorGtk::didAddVerticalScrollbar): 51 (WebCore::ScrollAnimatorGtk::didAddHorizontalScrollbar): 52 * platform/gtk/ScrollAnimatorGtk.h: 53 1 54 2017-06-09 Zan Dobersek <zdobersek@igalia.com> 2 55 -
trunk/Source/WebCore/PlatformGTK.cmake
r217877 r217971 64 64 65 65 platform/KillRingNone.cpp 66 platform/ScrollAnimationKinetic.cpp 66 67 platform/StaticPasteboard.cpp 67 68 platform/UserAgentQuirks.cpp -
trunk/Source/WebCore/platform/PlatformWheelEvent.h
r212484 r217971 49 49 }; 50 50 51 #if PLATFORM(COCOA) 51 #if PLATFORM(COCOA) || PLATFORM(GTK) 52 52 53 53 enum PlatformWheelEventPhase : uint8_t { … … 118 118 #if PLATFORM(GTK) 119 119 explicit PlatformWheelEvent(GdkEventScroll*); 120 FloatPoint swipeVelocity() const; 120 121 #endif 121 122 … … 123 124 bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; } 124 125 void setHasPreciseScrollingDeltas(bool hasPreciseScrollingDeltas) { m_hasPreciseScrollingDeltas = hasPreciseScrollingDeltas; } 125 PlatformWheelEventPhase phase() const { return m_phase; }126 PlatformWheelEventPhase momentumPhase() const { return m_momentumPhase; }127 126 unsigned scrollCount() const { return m_scrollCount; } 128 127 float unacceleratedScrollingDeltaX() const { return m_unacceleratedScrollingDeltaX; } … … 132 131 bool shouldResetLatching() const; 133 132 bool isEndOfMomentumScroll() const; 133 #else 134 bool useLatchedEventElement() const { return false; } 135 #endif 136 137 #if PLATFORM(COCOA) || PLATFORM(GTK) 138 PlatformWheelEventPhase phase() const { return m_phase; } 139 PlatformWheelEventPhase momentumPhase() const { return m_momentumPhase; } 134 140 bool isEndOfNonMomentumScroll() const; 135 141 bool isTransitioningToMomentumScroll() const; 136 #else137 bool useLatchedEventElement() const { return false; }138 142 #endif 139 143 … … 156 160 FloatSize m_scrollingVelocity; 157 161 162 #if PLATFORM(COCOA) || PLATFORM(GTK) 163 PlatformWheelEventPhase m_phase { PlatformWheelEventPhaseNone }; 164 PlatformWheelEventPhase m_momentumPhase { PlatformWheelEventPhaseNone }; 165 #endif 158 166 #if PLATFORM(COCOA) 159 167 bool m_hasPreciseScrollingDeltas { false }; 160 PlatformWheelEventPhase m_phase { PlatformWheelEventPhaseNone };161 PlatformWheelEventPhase m_momentumPhase { PlatformWheelEventPhaseNone };162 168 unsigned m_scrollCount { 0 }; 163 169 float m_unacceleratedScrollingDeltaX { 0 }; … … 192 198 } 193 199 200 #endif 201 202 #if PLATFORM(COCOA) || PLATFORM(GTK) 203 194 204 inline bool PlatformWheelEvent::isEndOfNonMomentumScroll() const 195 205 { … … 201 211 return m_phase == PlatformWheelEventPhaseNone && m_momentumPhase == PlatformWheelEventPhaseBegan; 202 212 } 203 204 213 #endif 205 214 -
trunk/Source/WebCore/platform/ScrollAnimation.h
r196238 r217971 37 37 public: 38 38 virtual ~ScrollAnimation() { }; 39 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier) = 0;39 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float /* step */, float /* multiplier */) { return true; }; 40 40 virtual void stop() = 0; 41 virtual void updateVisibleLengths() = 0;42 virtual void setCurrentPosition(const FloatPoint&) = 0;41 virtual void updateVisibleLengths() { }; 42 virtual void setCurrentPosition(const FloatPoint&) { }; 43 43 virtual void serviceAnimation() { }; 44 44 -
trunk/Source/WebCore/platform/ScrollAnimationKinetic.h
r217970 r217971 24 24 */ 25 25 26 #ifndef ScrollAnimation_h 27 #define ScrollAnimation_h 26 #pragma once 28 27 29 #include "ScrollTypes.h" 28 #include "FloatPoint.h" 29 #include "ScrollAnimation.h" 30 #include "Timer.h" 31 32 #include <wtf/Optional.h> 30 33 31 34 namespace WebCore { 32 35 33 class FloatPoint;34 36 class ScrollableArea; 35 37 36 class ScrollAnimation { 38 class ScrollAnimationKinetic final: public ScrollAnimation { 39 private: 40 class PerAxisData { 41 public: 42 PerAxisData(double lower, double upper, double initialPosition, double initialVelocity); 43 44 double position() { return m_position; } 45 46 bool animateScroll(Seconds timeDelta); 47 48 private: 49 double m_lower { 0 }; 50 double m_upper { 0 }; 51 52 double m_coef1 { 0 }; 53 double m_coef2 { 0 }; 54 55 Seconds m_elapsedTime; 56 double m_position { 0 }; 57 double m_velocity { 0 }; 58 }; 59 37 60 public: 38 virtual ~ScrollAnimation() { }; 39 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier) = 0; 40 virtual void stop() = 0; 41 virtual void updateVisibleLengths() = 0; 42 virtual void setCurrentPosition(const FloatPoint&) = 0; 43 virtual void serviceAnimation() { }; 61 ScrollAnimationKinetic(ScrollableArea&, std::function<void(FloatPoint&&)>&& notifyPositionChangedFunction); 62 virtual ~ScrollAnimationKinetic(); 44 63 45 protected: 46 ScrollAnimation(ScrollableArea& scrollableArea) 47 : m_scrollableArea(scrollableArea) 48 { 49 } 64 void start(const FloatPoint& initialPosition, const FloatPoint& velocity, bool mayHScroll, bool mayVScroll); 50 65 51 ScrollableArea& m_scrollableArea; 66 private: 67 void stop() override; 68 void animationTimerFired(); 69 70 std::function<void(FloatPoint&&)> m_notifyPositionChangedFunction; 71 72 std::optional<PerAxisData> m_horizontalData; 73 std::optional<PerAxisData> m_verticalData; 74 75 MonotonicTime m_startTime; 76 Timer m_animationTimer; 77 FloatPoint m_position; 52 78 }; 53 79 54 80 } // namespace WebCore 55 56 #endif // ScrollAnimation_h -
trunk/Source/WebCore/platform/gtk/PlatformWheelEventGtk.cpp
r212205 r217971 29 29 #include "PlatformWheelEvent.h" 30 30 31 #include "FloatPoint.h" 31 32 #include "PlatformKeyboardEvent.h" 32 33 #include "Scrollbar.h" … … 86 87 m_wheelTicksY = m_deltaY; 87 88 89 #ifndef GTK_API_VERSION_2 90 #if GTK_CHECK_VERSION(3, 20, 0) 91 m_phase = event->is_stop ? 92 PlatformWheelEventPhaseEnded : 93 PlatformWheelEventPhaseChanged; 94 #else 95 m_phase = event->direction == GDK_SCROLL_SMOOTH && !m_deltaX && !m_deltaY ? 96 PlatformWheelEventPhaseEnded : 97 PlatformWheelEventPhaseChanged; 98 #endif 99 #else 100 m_phase = PlatformWheelEventPhaseChanged; 101 #endif // GTK_API_VERSION_2 102 88 103 m_position = IntPoint(static_cast<int>(event->x), static_cast<int>(event->y)); 89 104 m_globalPosition = IntPoint(static_cast<int>(event->x_root), static_cast<int>(event->y_root)); … … 96 111 } 97 112 113 FloatPoint PlatformWheelEvent::swipeVelocity() const 114 { 115 // The swiping velocity is stored in the deltas of the event declaring it. 116 return isTransitioningToMomentumScroll() ? FloatPoint(m_wheelTicksX, m_wheelTicksY) : FloatPoint(); 98 117 } 118 119 } -
trunk/Source/WebCore/platform/gtk/ScrollAnimatorGtk.cpp
r215173 r217971 32 32 #include "ScrollAnimatorGtk.h" 33 33 34 #include "ScrollAnimationKinetic.h" 34 35 #include "ScrollAnimationSmooth.h" 35 36 #include "ScrollableArea.h" … … 41 42 static const Seconds overflowScrollbarsAnimationDuration { 1_s }; 42 43 static const Seconds overflowScrollbarsAnimationHideDelay { 2_s }; 44 static const Seconds scrollCaptureThreshold { 150_ms }; 43 45 44 46 std::unique_ptr<ScrollAnimator> ScrollAnimator::create(ScrollableArea& scrollableArea) … … 51 53 , m_overlayScrollbarAnimationTimer(*this, &ScrollAnimatorGtk::overlayScrollbarAnimationTimerFired) 52 54 { 55 m_kineticAnimation = std::make_unique<ScrollAnimationKinetic>(m_scrollableArea, [this](FloatPoint&& position) { 56 #if ENABLE(SMOOTH_SCROLLING) 57 if (m_smoothAnimation) 58 m_smoothAnimation->setCurrentPosition(position); 59 #endif 60 updatePosition(WTFMove(position)); 61 }); 62 53 63 #if ENABLE(SMOOTH_SCROLLING) 54 64 if (scrollableArea.scrollAnimatorEnabled()) … … 64 74 void ScrollAnimatorGtk::ensureSmoothScrollingAnimation() 65 75 { 66 if (m_animation) 67 return; 68 69 m_animation = std::make_unique<ScrollAnimationSmooth>(m_scrollableArea, m_currentPosition, [this](FloatPoint&& position) { 70 FloatSize delta = position - m_currentPosition; 71 m_currentPosition = WTFMove(position); 72 notifyPositionChanged(delta); 76 if (m_smoothAnimation) 77 return; 78 79 m_smoothAnimation = std::make_unique<ScrollAnimationSmooth>(m_scrollableArea, m_currentPosition, [this](FloatPoint&& position) { 80 updatePosition(WTFMove(position)); 73 81 }); 74 82 } 75 83 #endif 84 85 #if ENABLE(SMOOTH_SCROLLING) 76 86 bool ScrollAnimatorGtk::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier) 77 87 { … … 80 90 81 91 ensureSmoothScrollingAnimation(); 82 return m_animation->scroll(orientation, granularity, step, multiplier); 83 } 92 return m_smoothAnimation->scroll(orientation, granularity, step, multiplier); 93 } 94 #endif 84 95 85 96 void ScrollAnimatorGtk::scrollToOffsetWithoutAnimation(const FloatPoint& offset) 86 97 { 87 98 FloatPoint position = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin())); 88 if (m_animation) 89 m_animation->setCurrentPosition(position); 90 99 m_kineticAnimation->stop(); 100 m_scrollHistory.clear(); 101 102 #if ENABLE(SMOOTH_SCROLLING) 103 if (m_smoothAnimation) 104 m_smoothAnimation->setCurrentPosition(position); 105 #endif 106 107 updatePosition(WTFMove(position)); 108 } 109 110 FloatPoint ScrollAnimatorGtk::computeVelocity() 111 { 112 if (m_scrollHistory.isEmpty()) 113 return { }; 114 115 double first = m_scrollHistory[0].timestamp(); 116 double last = m_scrollHistory.rbegin()->timestamp(); 117 118 if (last == first) 119 return { }; 120 121 FloatPoint accumDelta; 122 for (const auto& scrollEvent : m_scrollHistory) 123 accumDelta += FloatPoint(scrollEvent.deltaX(), scrollEvent.deltaY()); 124 125 m_scrollHistory.clear(); 126 127 return FloatPoint(accumDelta.x() * -1000 / (last - first), accumDelta.y() * -1000 / (last - first)); 128 } 129 130 bool ScrollAnimatorGtk::handleWheelEvent(const PlatformWheelEvent& event) 131 { 132 m_kineticAnimation->stop(); 133 134 m_scrollHistory.removeAllMatching([&event] (PlatformWheelEvent& otherEvent) -> bool { 135 return Seconds::fromMilliseconds(event.timestamp() - otherEvent.timestamp()) > scrollCaptureThreshold; 136 }); 137 138 if (event.isEndOfNonMomentumScroll()) { 139 // We don't need to add the event to the history as its delta will be (0, 0). 140 static_cast<ScrollAnimationKinetic*>(m_kineticAnimation.get())->start(m_currentPosition, computeVelocity(), m_scrollableArea.horizontalScrollbar(), m_scrollableArea.verticalScrollbar()); 141 return true; 142 } 143 if (event.isTransitioningToMomentumScroll()) { 144 m_scrollHistory.clear(); 145 static_cast<ScrollAnimationKinetic*>(m_kineticAnimation.get())->start(m_currentPosition, event.swipeVelocity(), m_scrollableArea.horizontalScrollbar(), m_scrollableArea.verticalScrollbar()); 146 return true; 147 } 148 149 m_scrollHistory.append(event); 150 151 return ScrollAnimator::handleWheelEvent(event); 152 } 153 154 void ScrollAnimatorGtk::willEndLiveResize() 155 { 156 m_kineticAnimation->updateVisibleLengths(); 157 158 #if ENABLE(SMOOTH_SCROLLING) 159 if (m_smoothAnimation) 160 m_smoothAnimation->updateVisibleLengths(); 161 #endif 162 } 163 164 void ScrollAnimatorGtk::updatePosition(FloatPoint&& position) 165 { 91 166 FloatSize delta = position - m_currentPosition; 92 m_currentPosition = position;167 m_currentPosition = WTFMove(position); 93 168 notifyPositionChanged(delta); 94 169 } 95 170 96 void ScrollAnimatorGtk::willEndLiveResize()97 {98 if (m_animation)99 m_animation->updateVisibleLengths();100 }101 #endif102 103 171 void ScrollAnimatorGtk::didAddVerticalScrollbar(Scrollbar* scrollbar) 104 172 { 105 #if ENABLE(SMOOTH_SCROLLING) 106 if (m_animation) 107 m_animation->updateVisibleLengths(); 173 m_kineticAnimation->updateVisibleLengths(); 174 175 #if ENABLE(SMOOTH_SCROLLING) 176 if (m_smoothAnimation) 177 m_smoothAnimation->updateVisibleLengths(); 108 178 #endif 109 179 if (!scrollbar->isOverlayScrollbar()) … … 118 188 void ScrollAnimatorGtk::didAddHorizontalScrollbar(Scrollbar* scrollbar) 119 189 { 120 #if ENABLE(SMOOTH_SCROLLING) 121 if (m_animation) 122 m_animation->updateVisibleLengths(); 190 m_kineticAnimation->updateVisibleLengths(); 191 192 #if ENABLE(SMOOTH_SCROLLING) 193 if (m_smoothAnimation) 194 m_smoothAnimation->updateVisibleLengths(); 123 195 #endif 124 196 if (!scrollbar->isOverlayScrollbar()) -
trunk/Source/WebCore/platform/gtk/ScrollAnimatorGtk.h
r215173 r217971 47 47 #if ENABLE(SMOOTH_SCROLLING) 48 48 bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier) override; 49 #endif 49 50 void scrollToOffsetWithoutAnimation(const FloatPoint&) override; 50 51 void willEndLiveResize() override; 51 #endif 52 53 bool handleWheelEvent(const PlatformWheelEvent&) override; 52 54 53 55 void didAddVerticalScrollbar(Scrollbar*) override; … … 64 66 void lockOverlayScrollbarStateToHidden(bool) override; 65 67 68 void updatePosition(FloatPoint&&); 69 66 70 void overlayScrollbarAnimationTimerFired(); 67 71 void showOverlayScrollbars(); … … 69 73 void updateOverlayScrollbarsOpacity(); 70 74 75 FloatPoint computeVelocity(); 76 71 77 #if ENABLE(SMOOTH_SCROLLING) 72 78 void ensureSmoothScrollingAnimation(); 73 79 74 std::unique_ptr<ScrollAnimation> m_ animation;80 std::unique_ptr<ScrollAnimation> m_smoothAnimation; 75 81 #endif 82 std::unique_ptr<ScrollAnimation> m_kineticAnimation; 83 Vector<PlatformWheelEvent> m_scrollHistory; 76 84 Scrollbar* m_horizontalOverlayScrollbar { nullptr }; 77 85 Scrollbar* m_verticalOverlayScrollbar { nullptr }; -
trunk/Source/WebKit2/ChangeLog
r217967 r217971 1 2017-06-09 Adrien Plazas <aplazas@igalia.com> 2 3 [GTK] Add kinetic scrolling 4 https://bugs.webkit.org/show_bug.cgi?id=155750 5 6 Reviewed by Carlos Garcia Campos. 7 8 Patch by Adrien Plazas and Yusuke Suzuki. 9 10 Add the notion of phase and momentum phase to WebWheelEvent. 11 12 Make WebWheelEvent manage the 'is_stop' attribute of GdkEventScroll to create the corresponding WebWheelEvent 13 with the correct phases and deltas. 14 15 Make GestureController manage swipes to create the corresponding WebWheelEvent with the correct phases and 16 deltas. 17 18 * Shared/NativeWebWheelEvent.h: 19 * Shared/WebEvent.h: 20 * Shared/WebEventConversion.cpp: 21 (WebKit::WebKit2PlatformWheelEvent::WebKit2PlatformWheelEvent): 22 * Shared/WebWheelEvent.cpp: 23 (WebKit::WebWheelEvent::WebWheelEvent): 24 (WebKit::WebWheelEvent::encode): 25 (WebKit::WebWheelEvent::decode): 26 * Shared/gtk/NativeWebWheelEventGtk.cpp: 27 (WebKit::NativeWebWheelEvent::NativeWebWheelEvent): 28 * Shared/gtk/WebEventFactory.cpp: 29 (WebKit::WebEventFactory::createWebWheelEvent): 30 * Shared/gtk/WebEventFactory.h: 31 * UIProcess/WebPageProxy.cpp: 32 (WebKit::WebPageProxy::handleWheelEvent): 33 (WebKit::WebPageProxy::shouldProcessWheelEventNow): 34 * UIProcess/WebPageProxy.h: 35 * UIProcess/gtk/GestureController.cpp: 36 (WebKit::GestureController::GestureController): 37 (WebKit::GestureController::handleEvent): 38 (WebKit::GestureController::isProcessingGestures): 39 (WebKit::createScrollEvent): 40 (WebKit::GestureController::DragGesture::startDrag): 41 (WebKit::GestureController::DragGesture::handleDrag): 42 (WebKit::GestureController::DragGesture::begin): 43 (WebKit::GestureController::DragGesture::end): 44 (WebKit::GestureController::SwipeGesture::startMomentumScroll): 45 (WebKit::GestureController::SwipeGesture::swipe): 46 (WebKit::GestureController::SwipeGesture::SwipeGesture): 47 * UIProcess/gtk/GestureController.h: 48 1 49 2017-06-09 Jer Noble <jer.noble@apple.com> 2 50 -
trunk/Source/WebKit2/Shared/NativeWebWheelEvent.h
r216497 r217971 52 52 NativeWebWheelEvent(const NativeWebWheelEvent&); 53 53 NativeWebWheelEvent(GdkEvent*); 54 NativeWebWheelEvent(GdkEvent*, WebWheelEvent::Phase, WebWheelEvent::Phase momentumPhase); 54 55 #elif PLATFORM(WPE) 55 56 NativeWebWheelEvent(struct wpe_input_axis_event*, float deviceScaleFactor); -
trunk/Source/WebKit2/Shared/WebEvent.h
r210668 r217971 184 184 }; 185 185 186 #if PLATFORM(COCOA) 186 #if PLATFORM(COCOA) || PLATFORM(GTK) 187 187 enum Phase { 188 188 PhaseNone = 0, … … 201 201 #if PLATFORM(COCOA) 202 202 WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, bool directionInvertedFromDevice, Phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, Modifiers, double timestamp); 203 #elif PLATFORM(GTK) 204 WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Phase, Phase momentumPhase, Granularity, Modifiers, double timestamp); 203 205 #endif 204 206 … … 209 211 Granularity granularity() const { return static_cast<Granularity>(m_granularity); } 210 212 bool directionInvertedFromDevice() const { return m_directionInvertedFromDevice; } 211 #if PLATFORM(COCOA) 213 #if PLATFORM(COCOA) || PLATFORM(GTK) 212 214 Phase phase() const { return static_cast<Phase>(m_phase); } 213 215 Phase momentumPhase() const { return static_cast<Phase>(m_momentumPhase); } 216 #endif 217 #if PLATFORM(COCOA) 214 218 bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; } 215 219 uint32_t scrollCount() const { return m_scrollCount; } … … 229 233 uint32_t m_granularity; // Granularity 230 234 bool m_directionInvertedFromDevice; 235 #if PLATFORM(COCOA) || PLATFORM(GTK) 236 uint32_t m_phase { Phase::PhaseNone }; 237 uint32_t m_momentumPhase { Phase::PhaseNone }; 238 #endif 231 239 #if PLATFORM(COCOA) 232 uint32_t m_phase; // Phase233 uint32_t m_momentumPhase; // Phase234 240 bool m_hasPreciseScrollingDeltas; 235 241 uint32_t m_scrollCount; -
trunk/Source/WebKit2/Shared/WebEventConversion.cpp
r215790 r217971 156 156 m_granularity = (webEvent.granularity() == WebWheelEvent::ScrollByPageWheelEvent) ? WebCore::ScrollByPageWheelEvent : WebCore::ScrollByPixelWheelEvent; 157 157 m_directionInvertedFromDevice = webEvent.directionInvertedFromDevice(); 158 #if PLATFORM(COCOA) 158 #if PLATFORM(COCOA) || PLATFORM(GTK) 159 159 m_phase = static_cast<WebCore::PlatformWheelEventPhase>(webEvent.phase()); 160 160 m_momentumPhase = static_cast<WebCore::PlatformWheelEventPhase>(webEvent.momentumPhase()); 161 #endif 162 #if PLATFORM(COCOA) 161 163 m_hasPreciseScrollingDeltas = webEvent.hasPreciseScrollingDeltas(); 162 164 m_scrollCount = webEvent.scrollCount(); -
trunk/Source/WebKit2/Shared/WebWheelEvent.cpp
r204743 r217971 67 67 ASSERT(isWheelEventType(type)); 68 68 } 69 #elif PLATFORM(GTK) 70 WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Phase phase, Phase momentumPhase, Granularity granularity, Modifiers modifiers, double timestamp) 71 : WebEvent(type, modifiers, timestamp) 72 , m_position(position) 73 , m_globalPosition(globalPosition) 74 , m_delta(delta) 75 , m_wheelTicks(wheelTicks) 76 , m_granularity(granularity) 77 , m_directionInvertedFromDevice(false) 78 , m_phase(phase) 79 , m_momentumPhase(momentumPhase) 80 { 81 ASSERT(isWheelEventType(type)); 82 } 69 83 #endif 70 84 … … 79 93 encoder << m_granularity; 80 94 encoder << m_directionInvertedFromDevice; 81 #if PLATFORM(COCOA) 95 #if PLATFORM(COCOA) || PLATFORM(GTK) 82 96 encoder << m_phase; 83 97 encoder << m_momentumPhase; 98 #endif 99 #if PLATFORM(COCOA) 84 100 encoder << m_hasPreciseScrollingDeltas; 85 101 encoder << m_scrollCount; … … 104 120 if (!decoder.decode(t.m_directionInvertedFromDevice)) 105 121 return false; 106 #if PLATFORM(COCOA) 122 #if PLATFORM(COCOA) || PLATFORM(GTK) 107 123 if (!decoder.decode(t.m_phase)) 108 124 return false; 109 125 if (!decoder.decode(t.m_momentumPhase)) 110 126 return false; 127 #endif 128 #if PLATFORM(COCOA) 111 129 if (!decoder.decode(t.m_hasPreciseScrollingDeltas)) 112 130 return false; -
trunk/Source/WebKit2/Shared/gtk/NativeWebWheelEventGtk.cpp
r85856 r217971 38 38 } 39 39 40 NativeWebWheelEvent::NativeWebWheelEvent(GdkEvent* event, WebWheelEvent::Phase phase, WebWheelEvent::Phase momentumPhase) 41 : WebWheelEvent(WebEventFactory::createWebWheelEvent(event, phase, momentumPhase)) 42 , m_nativeEvent(gdk_event_copy(event)) 43 { 44 } 45 40 46 NativeWebWheelEvent::NativeWebWheelEvent(const NativeWebWheelEvent& event) 41 : WebWheelEvent(WebEventFactory::createWebWheelEvent(event.nativeEvent() ))47 : WebWheelEvent(WebEventFactory::createWebWheelEvent(event.nativeEvent(), event.phase(), event.momentumPhase())) 42 48 , m_nativeEvent(gdk_event_copy(event.nativeEvent())) 43 49 { -
trunk/Source/WebKit2/Shared/gtk/WebEventFactory.cpp
r212205 r217971 146 146 WebWheelEvent WebEventFactory::createWebWheelEvent(const GdkEvent* event) 147 147 { 148 #ifndef GTK_API_VERSION_2 149 #if GTK_CHECK_VERSION(3, 20, 0) 150 WebWheelEvent::Phase phase = gdk_event_is_scroll_stop_event(event) ? 151 WebWheelEvent::Phase::PhaseEnded : 152 WebWheelEvent::Phase::PhaseChanged; 153 #else 154 double deltaX, deltaY; 155 gdk_event_get_scroll_deltas(event, &deltaX, &deltaY); 156 WebWheelEvent::Phase phase = event->scroll.direction == GDK_SCROLL_SMOOTH && !deltaX && !deltaY ? 157 WebWheelEvent::Phase::PhaseEnded : 158 WebWheelEvent::Phase::PhaseChanged; 159 #endif 160 #else 161 WebWheelEvent::Phase phase = WebWheelEvent::Phase::PhaseChanged; 162 #endif // GTK_API_VERSION_2 163 164 return createWebWheelEvent(event, phase, WebWheelEvent::Phase::PhaseNone); 165 } 166 167 WebWheelEvent WebEventFactory::createWebWheelEvent(const GdkEvent* event, WebWheelEvent::Phase phase, WebWheelEvent::Phase momentumPhase) 168 { 148 169 double x, y, xRoot, yRoot; 149 170 gdk_event_get_coords(event, &x, &y); … … 182 203 183 204 return WebWheelEvent(WebEvent::Wheel, 184 IntPoint(x, y), 185 IntPoint(xRoot, yRoot), 186 delta, 187 wheelTicks, 188 WebWheelEvent::ScrollByPixelWheelEvent, 189 modifiersForEvent(event), 190 gdk_event_get_time(event)); 205 IntPoint(x, y), 206 IntPoint(xRoot, yRoot), 207 delta, 208 wheelTicks, 209 phase, 210 momentumPhase, 211 WebWheelEvent::ScrollByPixelWheelEvent, 212 modifiersForEvent(event), 213 gdk_event_get_time(event)); 191 214 } 192 215 -
trunk/Source/WebKit2/Shared/gtk/WebEventFactory.h
r190987 r217971 39 39 static WebMouseEvent createWebMouseEvent(const GdkEvent*, int); 40 40 static WebWheelEvent createWebWheelEvent(const GdkEvent*); 41 static WebWheelEvent createWebWheelEvent(const GdkEvent*, WebWheelEvent::Phase, WebWheelEvent::Phase momentumPhase); 41 42 static WebKeyboardEvent createWebKeyboardEvent(const GdkEvent*, const WebCore::CompositionResults&, Vector<String>&& commands); 42 43 #if ENABLE(TOUCH_EVENTS) -
trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp
r217951 r217971 1887 1887 if (!m_currentlyProcessedWheelEvents.isEmpty()) { 1888 1888 m_wheelEventQueue.append(event); 1889 if ( m_wheelEventQueue.size() < wheelEventQueueSizeThreshold)1889 if (!shouldProcessWheelEventNow(event)) 1890 1890 return; 1891 1891 // The queue has too many wheel events, so push a new event. … … 1926 1926 // event will dispatch to a non-main thread, which always responds. 1927 1927 m_process->isResponsive(nullptr); 1928 } 1929 1930 bool WebPageProxy::shouldProcessWheelEventNow(const WebWheelEvent& event) const 1931 { 1932 #if PLATFORM(GTK) 1933 // Don't queue events representing a non-trivial scrolling phase to 1934 // avoid having them trapped in the queue, potentially preventing a 1935 // scrolling session to beginning or end correctly. 1936 // This is only needed by platforms whose WebWheelEvent has this phase 1937 // information (Cocoa and GTK+) but Cocoa was fine without it. 1938 if (event.phase() == WebWheelEvent::Phase::PhaseNone 1939 || event.phase() == WebWheelEvent::Phase::PhaseChanged 1940 || event.momentumPhase() == WebWheelEvent::Phase::PhaseNone 1941 || event.momentumPhase() == WebWheelEvent::Phase::PhaseChanged) 1942 return true; 1943 #else 1944 UNUSED_PARAM(event); 1945 #endif 1946 if (m_wheelEventQueue.size() >= wheelEventQueueSizeThreshold) 1947 return true; 1948 return false; 1928 1949 } 1929 1950 -
trunk/Source/WebKit2/UIProcess/WebPageProxy.h
r217951 r217971 1558 1558 void processNextQueuedWheelEvent(); 1559 1559 void sendWheelEvent(const WebWheelEvent&); 1560 bool shouldProcessWheelEventNow(const WebWheelEvent&) const; 1560 1561 1561 1562 #if ENABLE(TOUCH_EVENTS) -
trunk/Source/WebKit2/UIProcess/gtk/GestureController.cpp
r215173 r217971 42 42 GestureController::GestureController(WebPageProxy& page) 43 43 : m_dragGesture(page) 44 , m_swipeGesture(page) 44 45 , m_zoomGesture(page) 45 46 { … … 50 51 bool wasProcessingGestures = isProcessingGestures(); 51 52 m_dragGesture.handleEvent(event); 53 m_swipeGesture.handleEvent(event); 52 54 m_zoomGesture.handleEvent(event); 53 55 return event->type == GDK_TOUCH_END ? wasProcessingGestures : isProcessingGestures(); … … 56 58 bool GestureController::isProcessingGestures() const 57 59 { 58 return m_dragGesture.isActive() || m_ zoomGesture.isActive();60 return m_dragGesture.isActive() || m_swipeGesture.isActive() || m_zoomGesture.isActive(); 59 61 } 60 62 … … 76 78 } 77 79 78 void GestureController::DragGesture::handleDrag(const GdkEvent* event, double x, double y) 79 { 80 ASSERT(m_inDrag); 80 static GUniquePtr<GdkEvent> createScrollEvent(const GdkEvent* event, double x, double y, double deltaX, double deltaY, gboolean isStop) 81 { 81 82 GUniquePtr<GdkEvent> scrollEvent(gdk_event_new(GDK_SCROLL)); 82 83 scrollEvent->scroll.time = event->touch.time; 83 scrollEvent->scroll.x = m_start.x();84 scrollEvent->scroll.y = m_start.y();84 scrollEvent->scroll.x = x; 85 scrollEvent->scroll.y = y; 85 86 scrollEvent->scroll.x_root = event->touch.x_root; 86 87 scrollEvent->scroll.y_root = event->touch.y_root; 87 88 scrollEvent->scroll.direction = GDK_SCROLL_SMOOTH; 88 scrollEvent->scroll.delta_x = (m_offset.x() - x) / Scrollbar::pixelsPerLineStep();89 scrollEvent->scroll.delta_y = (m_offset.y() - y) / Scrollbar::pixelsPerLineStep();89 scrollEvent->scroll.delta_x = deltaX; 90 scrollEvent->scroll.delta_y = deltaY; 90 91 scrollEvent->scroll.state = event->touch.state; 91 m_page.handleWheelEvent(NativeWebWheelEvent(scrollEvent.get())); 92 #if GTK_CHECK_VERSION(3, 20, 0) 93 scrollEvent->scroll.is_stop = isStop; 94 #endif 95 return scrollEvent; 96 } 97 98 void GestureController::DragGesture::startDrag(const GdkEvent* event) 99 { 100 ASSERT(!m_inDrag); 101 GUniquePtr<GdkEvent> scrollEvent = createScrollEvent(event, m_start.x(), m_start.y(), 0, 0, FALSE); 102 m_page.handleWheelEvent(NativeWebWheelEvent(scrollEvent.get(), WebWheelEvent::Phase::PhaseBegan, WebWheelEvent::Phase::PhaseNone)); 103 } 104 105 void GestureController::DragGesture::handleDrag(const GdkEvent* event, double x, double y) 106 { 107 ASSERT(m_inDrag); 108 GUniquePtr<GdkEvent> scrollEvent = createScrollEvent(event, 109 m_start.x(), m_start.y(), 110 (m_offset.x() - x) / Scrollbar::pixelsPerLineStep(), 111 (m_offset.y() - y) / Scrollbar::pixelsPerLineStep(), 112 FALSE); 113 m_page.handleWheelEvent(NativeWebWheelEvent(scrollEvent.get(), WebWheelEvent::Phase::PhaseChanged, WebWheelEvent::Phase::PhaseNone)); 92 114 } 93 115 … … 129 151 g_object_get(gtk_widget_get_settings(widget), "gtk-long-press-time", &delay, nullptr); 130 152 dragGesture->m_longPressTimeout.startOneShot(1_ms * delay); 153 dragGesture->startDrag(gtk_gesture_get_last_event(gesture, sequence)); 131 154 } 132 155 … … 150 173 { 151 174 dragGesture->m_longPressTimeout.stop(); 175 if (!gtk_gesture_handles_sequence(gesture, sequence)) { 176 gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED); 177 return; 178 } 152 179 if (!dragGesture->m_inDrag) { 153 180 dragGesture->handleTap(gtk_gesture_get_last_event(gesture, sequence)); 154 181 gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED); 155 } else if (!gtk_gesture_handles_sequence(gesture, sequence)) 156 gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED); 182 } 157 183 } 158 184 … … 171 197 g_signal_connect_swapped(m_gesture.get(), "drag-update", G_CALLBACK(update), this); 172 198 g_signal_connect_swapped(m_gesture.get(), "end", G_CALLBACK(end), this); 199 } 200 201 void GestureController::SwipeGesture::startMomentumScroll(const GdkEvent* event, double velocityX, double velocityY) 202 { 203 GUniquePtr<GdkEvent> scrollEvent = createScrollEvent(event, event->touch.x, event->touch.y, velocityX, velocityY, TRUE); 204 m_page.handleWheelEvent(NativeWebWheelEvent(scrollEvent.get(), WebWheelEvent::Phase::PhaseNone, WebWheelEvent::Phase::PhaseBegan)); 205 } 206 207 void GestureController::SwipeGesture::swipe(SwipeGesture* swipeGesture, double velocityX, double velocityY, GtkGesture* gesture) 208 { 209 GdkEventSequence* sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(gesture)); 210 if (!gtk_gesture_handles_sequence(gesture, sequence)) 211 return; 212 213 gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED); 214 215 swipeGesture->startMomentumScroll(gtk_gesture_get_last_event(gesture, sequence), velocityX, velocityY); 216 } 217 218 GestureController::SwipeGesture::SwipeGesture(WebPageProxy& page) 219 : Gesture(gtk_gesture_swipe_new(page.viewWidget()), page) 220 { 221 gtk_gesture_single_set_touch_only(GTK_GESTURE_SINGLE(m_gesture.get()), TRUE); 222 g_signal_connect_swapped(m_gesture.get(), "swipe", G_CALLBACK(swipe), this); 173 223 } 174 224 -
trunk/Source/WebKit2/UIProcess/gtk/GestureController.h
r202611 r217971 68 68 69 69 private: 70 // Notify that a drag started, allowing to stop kinetic deceleration. 71 void startDrag(const GdkEvent*); 70 72 void handleDrag(const GdkEvent*, double x, double y); 71 73 void handleTap(const GdkEvent*); … … 81 83 GRefPtr<GtkGesture> m_longPress; 82 84 bool m_inDrag; 85 }; 86 87 class SwipeGesture final : public Gesture { 88 public: 89 SwipeGesture(WebPageProxy&); 90 91 private: 92 void startMomentumScroll(const GdkEvent*, double velocityX, double velocityY); 93 94 static void swipe(SwipeGesture*, double velocityX, double velocityY, GtkGesture*); 83 95 }; 84 96 … … 102 114 103 115 DragGesture m_dragGesture; 116 SwipeGesture m_swipeGesture; 104 117 ZoomGesture m_zoomGesture; 105 118 };
Note: See TracChangeset
for help on using the changeset viewer.