Changeset 241952 in webkit
- Timestamp:
- Feb 22, 2019 10:46:25 AM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r241950 r241952 1 2019-02-22 Alexander Mikhaylenko <exalm7659@gmail.com> 2 3 [GTK] Navigation gesture improvements 4 https://bugs.webkit.org/show_bug.cgi?id=194943 5 6 Reviewed by Michael Catanzaro. 7 8 Cancel the gesture if progress is less than 0.5 and velocity is not high enough. 9 10 Allow to continue the gesture during animation. Introduce finished state to be used 11 when showing snapshot after the animation ends. 12 13 Fix duration calculation, also slow it down so that the initial velocity matches 14 what it was during the gesture. 15 16 * UIProcess/ViewGestureController.h: Add shouldCancel() and State::Finishing to SwipeProgressTracker. 17 * UIProcess/gtk/ViewGestureControllerGtk.cpp: 18 (WebKit::ViewGestureController::SwipeProgressTracker::handleEvent): 19 Fix velocity calculation, allow scrolling during State::Animating. 20 (WebKit::ViewGestureController::SwipeProgressTracker::shouldCancel): Added. 21 (WebKit::ViewGestureController::SwipeProgressTracker::startAnimation): Use shouldCancel() and fix duration calculation. 22 (WebKit::ViewGestureController::SwipeProgressTracker::endAnimation): Set state to State::Finishing when the animation ends. 23 1 24 2019-02-22 Chris Dumez <cdumez@apple.com> 2 25 -
trunk/Source/WebKit/UIProcess/ViewGestureController.h
r241224 r241952 375 375 Pending, 376 376 Scrolling, 377 Animating 377 Animating, 378 Finishing 378 379 }; 380 381 bool shouldCancel(); 379 382 380 383 void startAnimation(); -
trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp
r241224 r241952 36 36 static const Seconds swipeMaxAnimationDuration = 400_ms; 37 37 38 // This is derivative of the easing function at t=0 39 static const double swipeAnimationDurationMultiplier = 3; 40 41 static const double swipeCancelArea = 0.5; 42 static const double swipeCancelVelocityThreshold = 0.001; 43 38 44 static const double swipeOverlayShadowOpacity = 0.06; 39 45 static const double swipeOverlayDimmingOpacity = 0.12; … … 136 142 bool ViewGestureController::SwipeProgressTracker::handleEvent(GdkEventScroll* event) 137 143 { 144 // Don't allow scrolling while the next page is loading 145 if (m_state == State::Finishing) 146 return true; 147 148 // Stop current animation, if any 149 if (m_state == State::Animating) { 150 GtkWidget* widget = m_webPageProxy.viewWidget(); 151 gtk_widget_remove_tick_callback(widget, m_tickCallbackID); 152 m_tickCallbackID = 0; 153 154 m_cancelled = false; 155 m_state = State::Pending; 156 } 157 138 158 if (m_state == State::Pending) { 139 159 m_viewGestureController.beginSwipeGesture(m_targetItem.get(), m_direction); … … 141 161 } 142 162 143 // Don't allow scrolling during animation144 if (m_state == State::Animating)145 return true;146 147 163 if (m_state != State::Scrolling) 148 164 return false; … … 153 169 } 154 170 171 double deltaX = -event->delta_x / Scrollbar::pixelsPerLineStep(); 172 155 173 Seconds time = Seconds::fromMilliseconds(event->time); 156 m_velocity = -event->delta_x / (time - m_prevTime).milliseconds(); 174 if (time != m_prevTime) 175 m_velocity = deltaX / (time - m_prevTime).milliseconds(); 157 176 158 177 m_prevTime = time; 159 m_progress -= event->delta_x / Scrollbar::pixelsPerLineStep();178 m_progress += deltaX; 160 179 161 180 bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction); … … 169 188 } 170 189 190 bool ViewGestureController::SwipeProgressTracker::shouldCancel() 191 { 192 bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction); 193 194 if (swipingLeft && m_velocity < 0) 195 return true; 196 197 if (!swipingLeft && m_velocity > 0) 198 return true; 199 200 return (abs(m_progress) < swipeCancelArea && abs(m_velocity) < swipeCancelVelocityThreshold); 201 } 202 171 203 void ViewGestureController::SwipeProgressTracker::startAnimation() 172 204 { 173 bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction); 174 m_cancelled = swipingLeft ? (m_velocity <= 0) : (m_velocity >= 0); 205 m_cancelled = shouldCancel(); 175 206 176 207 m_state = State::Animating; … … 181 212 m_endProgress = 0; 182 213 else 183 m_endProgress = swipingLeft ? 1 : -1; 184 185 Seconds duration = Seconds::fromMilliseconds(std::abs((m_progress - m_endProgress) / m_velocity) * Scrollbar::pixelsPerLineStep()); 186 duration = std::min(std::max(duration, swipeMinAnimationDuration), swipeMaxAnimationDuration); 214 m_endProgress = m_viewGestureController.isPhysicallySwipingLeft(m_direction) ? 1 : -1; 215 216 Seconds duration = swipeMaxAnimationDuration; 217 if ((m_endProgress - m_progress) * m_velocity > 0) { 218 duration = Seconds::fromMilliseconds(std::abs((m_progress - m_endProgress) / m_velocity * swipeAnimationDurationMultiplier)); 219 duration = clampTo<WTF::Seconds>(duration, swipeMinAnimationDuration, swipeMaxAnimationDuration); 220 } 187 221 188 222 GtkWidget* widget = m_webPageProxy.viewWidget(); … … 227 261 void ViewGestureController::SwipeProgressTracker::endAnimation() 228 262 { 263 m_state = State::Finishing; 229 264 m_viewGestureController.endSwipeGesture(m_targetItem.get(), m_cancelled); 230 265 }
Note: See TracChangeset
for help on using the changeset viewer.