Changeset 94797 in webkit
- Timestamp:
- Sep 8, 2011 2:11:44 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r94783 r94797 1 2011-09-08 Varun Jain <varunjain@google.com> 2 3 Implement double tap detection in GestureRecognizerChromium 4 https://bugs.webkit.org/show_bug.cgi?id=67709 5 6 Reviewed by Dimitri Glazkov. 7 8 * Source/WebCore/page/EventHandler.cpp: 9 * Source/WebCore/platform/PlatformGestureEvent.h: 10 1 11 2011-09-08 Ulan Degenbaev <ulan@chromium.org> 2 12 -
trunk/Source/WebCore/page/EventHandler.cpp
r94772 r94797 2222 2222 return true; 2223 2223 } 2224 case PlatformGestureEvent::DoubleTapType: 2225 break; 2224 2226 case PlatformGestureEvent::ScrollUpdateType: { 2225 2227 const float tickDivisor = (float)WheelEvent::tickMultiplier; -
trunk/Source/WebCore/platform/PlatformGestureEvent.h
r94772 r94797 41 41 TapType, 42 42 TapDownType, 43 DoubleTapType, 43 44 }; 44 45 -
trunk/Source/WebCore/platform/chromium/GestureRecognizerChromium.cpp
r94772 r94797 63 63 addEdgeFunction(Scroll, FirstFinger, Released, false, &GestureRecognizerChromium::scrollEnd); 64 64 addEdgeFunction(Scroll, FirstFinger, Cancelled, false, &GestureRecognizerChromium::scrollEnd); 65 66 addEdgeFunction(FirstClickReceived, FirstFinger, Pressed, false, &GestureRecognizerChromium::touchDown); 67 addEdgeFunction(PendingDoubleClick, FirstFinger, Cancelled, false, &GestureRecognizerChromium::noGesture); 68 addEdgeFunction(PendingDoubleClick, FirstFinger, Released, false, &GestureRecognizerChromium::doubleClick); 69 addEdgeFunction(PendingDoubleClick, FirstFinger, Moved, false, &GestureRecognizerChromium::maybeDoubleClick); 70 addEdgeFunction(PendingDoubleClick, FirstFinger, Stationary, false, &GestureRecognizerChromium::maybeDoubleClick); 65 71 } 66 72 … … 87 93 } 88 94 95 bool GestureRecognizerChromium::isInSecondClickTimeWindow() 96 { 97 double duration(m_lastTouchTime - m_lastClickTime); 98 return duration >= minimumTouchDownDurationInSecondsForClick && duration < maximumTouchDownDurationInSecondsForClick; 99 } 100 89 101 bool GestureRecognizerChromium::isInsideManhattanSquare(const PlatformTouchPoint& point) 90 102 { … … 101 113 { 102 114 gestures->append(PlatformGestureEvent(PlatformGestureEvent::TapType, m_firstTouchPosition, m_firstTouchScreenPosition, m_lastTouchTime, 0.f, 0.f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey)); 115 } 116 117 void GestureRecognizerChromium::appendDoubleClickGestureEvent(const PlatformTouchPoint& touchPoint, Gestures gestures) 118 { 119 gestures->append(PlatformGestureEvent(PlatformGestureEvent::DoubleTapType, m_firstTouchPosition, m_firstTouchScreenPosition, m_lastTouchTime, 0.f, 0.f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey)); 103 120 } 104 121 … … 143 160 void GestureRecognizerChromium::updateValues(const double touchTime, const PlatformTouchPoint& touchPoint) 144 161 { 162 if (state() == FirstClickReceived) { 163 m_firstTouchTime = touchTime; 164 m_lastClickTime = m_lastTouchTime; 165 } 145 166 m_lastTouchTime = touchTime; 146 167 if (state() == NoGesture) { … … 165 186 bool GestureRecognizerChromium::touchDown(const PlatformTouchPoint& touchPoint, Gestures gestures) 166 187 { 188 ASSERT(state() == NoGesture || state() == FirstClickReceived); 189 appendTapDownGestureEvent(touchPoint, gestures); 190 if (state() == FirstClickReceived && isInSecondClickTimeWindow() && isInsideManhattanSquare(touchPoint)) { 191 setState(PendingDoubleClick); 192 return false; 193 } 167 194 setState(PendingSyntheticClick); 168 appendTapDownGestureEvent(touchPoint, gestures);169 195 return false; 170 196 } … … 178 204 } 179 205 180 bool GestureRecognizerChromium::noGesture(const PlatformTouchPoint&, Gestures) 181 { 182 reset(); 183 return false; 184 } 185 186 bool GestureRecognizerChromium::click(const PlatformTouchPoint& point, Gestures gestures) 206 bool GestureRecognizerChromium::doubleClick(const PlatformTouchPoint& point, Gestures gestures) 187 207 { 188 208 if (isInClickTimeWindow() && isInsideManhattanSquare(point)) { 189 209 setState(NoGesture); 210 appendDoubleClickGestureEvent(point, gestures); 211 return true; 212 } 213 return noGesture(point, gestures); 214 } 215 216 bool GestureRecognizerChromium::maybeDoubleClick(const PlatformTouchPoint& point, Gestures gestures) 217 { 218 ASSERT(state() == GestureRecognizerChromium::PendingDoubleClick); 219 if (point.state() == PlatformTouchPoint::TouchMoved && !isInsideManhattanSquare(point)) 220 return noGesture(point, gestures); 221 return false; 222 } 223 224 bool GestureRecognizerChromium::noGesture(const PlatformTouchPoint&, Gestures) 225 { 226 reset(); 227 return false; 228 } 229 230 bool GestureRecognizerChromium::click(const PlatformTouchPoint& point, Gestures gestures) 231 { 232 if (isInClickTimeWindow() && isInsideManhattanSquare(point)) { 233 setState(FirstClickReceived); 190 234 appendClickGestureEvent(point, gestures); 191 235 return true; -
trunk/Source/WebCore/platform/chromium/GestureRecognizerChromium.h
r94772 r94797 49 49 NoGesture, 50 50 PendingSyntheticClick, 51 Scroll 51 Scroll, 52 FirstClickReceived, 53 PendingDoubleClick, 52 54 }; 53 55 … … 69 71 void appendTapDownGestureEvent(const PlatformTouchPoint&, Gestures); 70 72 void appendClickGestureEvent(const PlatformTouchPoint&, Gestures); 73 void appendDoubleClickGestureEvent(const PlatformTouchPoint&, Gestures); 71 74 void appendScrollGestureBegin(const PlatformTouchPoint&, Gestures); 72 75 void appendScrollGestureEnd(const PlatformTouchPoint&, Gestures); 73 76 void appendScrollGestureUpdate(const PlatformTouchPoint&, Gestures); 74 77 bool isInClickTimeWindow(); 78 bool isInSecondClickTimeWindow(); 75 79 bool isInsideManhattanSquare(const PlatformTouchPoint&); 76 80 void setState(State value) { m_state = value; } … … 84 88 bool scrollEnd(const PlatformTouchPoint&, Gestures); 85 89 90 bool doubleClick(const PlatformTouchPoint&, Gestures); 91 bool maybeDoubleClick(const PlatformTouchPoint&, Gestures); 92 86 93 WTF::HashMap<int, GestureTransitionFunction> m_edgeFunctions; 87 94 IntPoint m_firstTouchPosition; … … 90 97 State m_state; 91 98 double m_lastTouchTime; 99 double m_lastClickTime; 92 100 93 101 bool m_ctrlKey; -
trunk/Source/WebCore/platform/chromium/PopupContainer.cpp
r94772 r94797 307 307 return true; 308 308 } 309 case PlatformGestureEvent::DoubleTapType: 310 break; 309 311 case PlatformGestureEvent::ScrollUpdateType: { 310 312 PlatformWheelEvent syntheticWheelEvent(gestureEvent.position(), gestureEvent.globalPosition(), gestureEvent.deltaX(), gestureEvent.deltaY(), gestureEvent.deltaX() / 120.0f, gestureEvent.deltaY() / 120.0f, ScrollByPixelWheelEvent, /* isAccepted */ false, gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.metaKey()); -
trunk/Source/WebKit/chromium/tests/InnerGestureRecognizerTest.cpp
r94772 r94797 37 37 using namespace WebCore; 38 38 39 40 39 class InspectableGestureRecognizerChromium : public WebCore::GestureRecognizerChromium { 41 40 public: … … 158 157 }; 159 158 159 void SimulateAndTestFirstClick(InspectableGestureRecognizerChromium& gm) 160 { 161 ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state()); 162 163 BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed); 164 BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press); 165 OwnPtr<Vector<WebCore::PlatformGestureEvent> > gestureStart(gm.processTouchEventForGestures(pressEvent, false)); 166 ASSERT_EQ((unsigned int)1, gestureStart->size()); 167 ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type()); 168 ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state()); 169 170 BuildablePlatformTouchPoint release(10, 16, PlatformTouchPoint::TouchReleased); 171 BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release); 172 gm.setFirstTouchTime(gm.firstTouchTime() - 0.01); 173 OwnPtr<Vector<WebCore::PlatformGestureEvent> > gestureEnd(gm.processTouchEventForGestures(releaseEvent, false)); 174 ASSERT_EQ((unsigned int)1, gestureEnd->size()); 175 ASSERT_EQ(PlatformGestureEvent::TapType, (*gestureEnd)[0].type()); 176 } 177 160 178 typedef OwnPtr<Vector<WebCore::PlatformGestureEvent> > Gestures; 161 179 … … 283 301 ASSERT_EQ(3.0, gm.firstTouchTime()); 284 302 ASSERT_EQ(0.0, gm.lastTouchTime() - gm.firstTouchTime()); 303 } 304 305 TEST_F(GestureRecognizerTest, doubleTapGestureTest) 306 { 307 InspectableGestureRecognizerChromium gm; 308 SimulateAndTestFirstClick(gm); 309 ASSERT_EQ(GestureRecognizerChromium::FirstClickReceived, gm.state()); 310 311 BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed); 312 BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press); 313 gm.setLastTouchTime(gm.lastTouchTime() - 0.01); 314 Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false)); 315 ASSERT_EQ((unsigned int)1, gestureStart->size()); 316 ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type()); 317 ASSERT_EQ(GestureRecognizerChromium::PendingDoubleClick, gm.state()); 318 319 BuildablePlatformTouchPoint move(10, 16, PlatformTouchPoint::TouchMoved); 320 BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move); 321 Gestures gestureMove(gm.processTouchEventForGestures(moveEvent, false)); 322 ASSERT_EQ((unsigned int)0, gestureMove->size()); 323 ASSERT_EQ(GestureRecognizerChromium::PendingDoubleClick, gm.state()); 324 325 BuildablePlatformTouchPoint release(10, 16, PlatformTouchPoint::TouchReleased); 326 BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release); 327 gm.setFirstTouchTime(gm.firstTouchTime() - 0.01); 328 Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false)); 329 ASSERT_EQ((unsigned int)1, gestureEnd->size()); 330 ASSERT_EQ(PlatformGestureEvent::DoubleTapType, (*gestureEnd)[0].type()); 331 ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state()); 332 } 333 334 TEST_F(GestureRecognizerTest, doubleTapGestureIncompleteTest) 335 { 336 InspectableGestureRecognizerChromium gm; 337 SimulateAndTestFirstClick(gm); 338 ASSERT_EQ(GestureRecognizerChromium::FirstClickReceived, gm.state()); 339 340 BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed); 341 BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press); 342 gm.setLastTouchTime(gm.lastTouchTime() - 0.01); 343 Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false)); 344 ASSERT_EQ((unsigned int)1, gestureStart->size()); 345 ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type()); 346 ASSERT_EQ(GestureRecognizerChromium::PendingDoubleClick, gm.state()); 347 348 BuildablePlatformTouchPoint move(10, 50, PlatformTouchPoint::TouchMoved); 349 BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move); 350 Gestures gestureMove(gm.processTouchEventForGestures(moveEvent, false)); 351 ASSERT_EQ((unsigned int)0, gestureMove->size()); 352 ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state()); 353 354 BuildablePlatformTouchPoint release(10, 50, PlatformTouchPoint::TouchReleased); 355 BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release); 356 gm.setFirstTouchTime(gm.firstTouchTime() - 0.01); 357 Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false)); 358 ASSERT_EQ((unsigned int)0, gestureEnd->size()); 359 ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state()); 285 360 } 286 361 … … 339 414 ASSERT_EQ((unsigned int)1, gestureEnd->size()); 340 415 ASSERT_EQ(PlatformGestureEvent::TapType, (*gestureEnd)[0].type()); 341 ASSERT_EQ(GestureRecognizerChromium:: NoGesture, gm.state());416 ASSERT_EQ(GestureRecognizerChromium::FirstClickReceived, gm.state()); 342 417 } 343 418
Note: See TracChangeset
for help on using the changeset viewer.