Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1394)

Side by Side Diff: Source/core/page/EventHandler.cpp

Issue 499433003: Fix tap target consistency with link highlighting and hover/active (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix scrollbar case Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/events/touch/gesture/tap-target-matches-active-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 2203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 if (gestureEvent.altKey()) 2214 if (gestureEvent.altKey())
2215 modifierFlags |= PlatformEvent::AltKey; 2215 modifierFlags |= PlatformEvent::AltKey;
2216 if (gestureEvent.ctrlKey()) 2216 if (gestureEvent.ctrlKey())
2217 modifierFlags |= PlatformEvent::CtrlKey; 2217 modifierFlags |= PlatformEvent::CtrlKey;
2218 if (gestureEvent.metaKey()) 2218 if (gestureEvent.metaKey())
2219 modifierFlags |= PlatformEvent::MetaKey; 2219 modifierFlags |= PlatformEvent::MetaKey;
2220 if (gestureEvent.shiftKey()) 2220 if (gestureEvent.shiftKey())
2221 modifierFlags |= PlatformEvent::ShiftKey; 2221 modifierFlags |= PlatformEvent::ShiftKey;
2222 PlatformEvent::Modifiers modifiers = static_cast<PlatformEvent::Modifiers>(m odifierFlags); 2222 PlatformEvent::Modifiers modifiers = static_cast<PlatformEvent::Modifiers>(m odifierFlags);
2223 2223
2224 HitTestResult currentHitTest = targetedEvent.hitTestResult();
2225
2224 // We use the adjusted position so the application isn't surprised to see a event with 2226 // We use the adjusted position so the application isn't surprised to see a event with
2225 // co-ordinates outside the target's bounds. 2227 // co-ordinates outside the target's bounds.
2226 IntPoint adjustedPoint = m_frame->view()->windowToContents(gestureEvent.posi tion()); 2228 IntPoint adjustedPoint = m_frame->view()->windowToContents(gestureEvent.posi tion());
2227 2229
2228 // Do a new hit-test at the (adjusted) gesture co-ordinates. This is necessa ry because
2229 // touch adjustment sometimes returns a different node than what hit testing would return
2230 // for the same point.
2231 // FIXME: Fix touch adjustment to avoid the need for a redundant hit test. h ttp://crbug.com/398914
2232 HitTestResult newHitTest = hitTestResultInFrame(m_frame, adjustedPoint, HitT estRequest::ReadOnly);
2233
2234 PlatformMouseEvent fakeMouseMove(adjustedPoint, gestureEvent.globalPosition( ), 2230 PlatformMouseEvent fakeMouseMove(adjustedPoint, gestureEvent.globalPosition( ),
2235 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0, 2231 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0,
2236 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2232 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2237 dispatchMouseEvent(EventTypeNames::mousemove, newHitTest.targetNode(), 0, fa keMouseMove, true); 2233 dispatchMouseEvent(EventTypeNames::mousemove, currentHitTest.innerNode(), 0, fakeMouseMove, true);
2238 2234
2239 // Do a new hit-test in case the mousemove event changed the DOM. 2235 // Do a new hit-test in case the mousemove event changed the DOM.
2236 // Note that if the original hit test wasn't over an element (eg. was over a scrollbar) we
2237 // don't want to re-hit-test because it may be in the wrong frame (and there 's no way the page
2238 // could have seen the event anyway).
2240 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2239 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2241 newHitTest = hitTestResultInFrame(m_frame, adjustedPoint, HitTestRequest::Re adOnly); 2240 if (currentHitTest.innerNode())
2242 m_clickNode = newHitTest.targetNode(); 2241 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, HitTestReq uest::ReadOnly);
2242 m_clickNode = currentHitTest.innerNode();
2243 if (m_clickNode && m_clickNode->isTextNode()) 2243 if (m_clickNode && m_clickNode->isTextNode())
2244 m_clickNode = NodeRenderingTraversal::parent(m_clickNode.get()); 2244 m_clickNode = NodeRenderingTraversal::parent(m_clickNode.get());
2245 2245
2246 PlatformMouseEvent fakeMouseDown(adjustedPoint, gestureEvent.globalPosition( ), 2246 PlatformMouseEvent fakeMouseDown(adjustedPoint, gestureEvent.globalPosition( ),
2247 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(), 2247 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(),
2248 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2248 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2249 bool swallowMouseDownEvent = !dispatchMouseEvent(EventTypeNames::mousedown, newHitTest.targetNode(), gestureEvent.tapCount(), fakeMouseDown, true); 2249 bool swallowMouseDownEvent = !dispatchMouseEvent(EventTypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown, true);
2250 if (!swallowMouseDownEvent) 2250 if (!swallowMouseDownEvent)
2251 swallowMouseDownEvent = handleMouseFocus(fakeMouseDown); 2251 swallowMouseDownEvent = handleMouseFocus(fakeMouseDown);
2252 if (!swallowMouseDownEvent) 2252 if (!swallowMouseDownEvent)
2253 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, newHitTest)); 2253 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest));
2254 2254
2255 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2255 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2256 newHitTest = hitTestResultInFrame(m_frame, adjustedPoint, HitTestRequest::Re adOnly); 2256 if (currentHitTest.innerNode())
2257 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, HitTestReq uest::ReadOnly);
2257 PlatformMouseEvent fakeMouseUp(adjustedPoint, gestureEvent.globalPosition(), 2258 PlatformMouseEvent fakeMouseUp(adjustedPoint, gestureEvent.globalPosition(),
2258 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(), 2259 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(),
2259 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2260 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2260 bool swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, newH itTest.targetNode(), gestureEvent.tapCount(), fakeMouseUp, false); 2261 bool swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, curr entHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp, false);
2261 2262
2262 bool swallowClickEvent = false; 2263 bool swallowClickEvent = false;
2263 if (m_clickNode) { 2264 if (m_clickNode) {
2264 if (newHitTest.targetNode()) { 2265 if (currentHitTest.innerNode()) {
2265 Node* clickTargetNode = newHitTest.targetNode()->commonAncestor(*m_c lickNode, parentForClickEvent); 2266 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent);
2266 swallowClickEvent = !dispatchMouseEvent(EventTypeNames::click, click TargetNode, gestureEvent.tapCount(), fakeMouseUp, true); 2267 swallowClickEvent = !dispatchMouseEvent(EventTypeNames::click, click TargetNode, gestureEvent.tapCount(), fakeMouseUp, true);
2267 } 2268 }
2268 m_clickNode = nullptr; 2269 m_clickNode = nullptr;
2269 } 2270 }
2270 2271
2271 if (!swallowMouseUpEvent) 2272 if (!swallowMouseUpEvent)
2272 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, newHitTest)); 2273 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest));
2273 2274
2274 return swallowMouseDownEvent | swallowMouseUpEvent | swallowClickEvent; 2275 return swallowMouseDownEvent | swallowMouseUpEvent | swallowClickEvent;
2275 } 2276 }
2276 2277
2277 bool EventHandler::handleGestureLongPress(const GestureEventWithHitTestResults& targetedEvent) 2278 bool EventHandler::handleGestureLongPress(const GestureEventWithHitTestResults& targetedEvent)
2278 { 2279 {
2279 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2280 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2280 IntPoint adjustedPoint = gestureEvent.position(); 2281 IntPoint adjustedPoint = gestureEvent.position();
2281 2282
2282 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the 2283 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2589 if (FrameView* view = m_frame->view()) { 2590 if (FrameView* view = m_frame->view()) {
2590 hitTestResult.setScrollbar(view->scrollbarAtPoint(gestureEvent.posit ion())); 2591 hitTestResult.setScrollbar(view->scrollbarAtPoint(gestureEvent.posit ion()));
2591 } 2592 }
2592 } 2593 }
2593 2594
2594 // Adjust the location of the gesture to the most likely nearby node, as app ropriate for the 2595 // Adjust the location of the gesture to the most likely nearby node, as app ropriate for the
2595 // type of event. 2596 // type of event.
2596 PlatformGestureEvent adjustedEvent = gestureEvent; 2597 PlatformGestureEvent adjustedEvent = gestureEvent;
2597 applyTouchAdjustment(&adjustedEvent, &hitTestResult); 2598 applyTouchAdjustment(&adjustedEvent, &hitTestResult);
2598 2599
2600 // Do a new hit-test at the (adjusted) gesture co-ordinates. This is necessa ry because
2601 // rect-based hit testing and touch adjustment sometimes return a different node than
2602 // what a point-based hit test would return for the same point.
2603 // FIXME: Fix touch adjustment to avoid the need for a redundant hit test. h ttp://crbug.com/398914
2604 if (shouldApplyTouchAdjustment(gestureEvent)) {
2605 LocalFrame* hitFrame = hitTestResult.innerNodeFrame();
2606 if (!hitFrame)
2607 hitFrame = m_frame;
2608 hitTestResult = hitTestResultInFrame(hitFrame, hitFrame->view()->windowT oContents(adjustedEvent.position()), hitType | HitTestRequest::ReadOnly);
2609 // FIXME: HitTest entry points should really check for main frame scroll bars themselves.
2610 if (!hitTestResult.scrollbar()) {
2611 if (FrameView* view = m_frame->view()) {
2612 hitTestResult.setScrollbar(view->scrollbarAtPoint(gestureEvent.p osition()));
2613 }
2614 }
2615 }
2616
2599 // Now apply hover/active state to the final target. 2617 // Now apply hover/active state to the final target.
2600 // FIXME: This is supposed to send mouseenter/mouseleave events, but doesn't because we 2618 // FIXME: This is supposed to send mouseenter/mouseleave events, but doesn't because we
2601 // aren't passing a PlatformMouseEvent. 2619 // aren't passing a PlatformMouseEvent.
2602 HitTestRequest request(hitType | HitTestRequest::AllowChildFrameContent); 2620 HitTestRequest request(hitType | HitTestRequest::AllowChildFrameContent);
2603 if (!request.readOnly()) 2621 if (!request.readOnly())
2604 m_frame->document()->updateHoverActiveState(request, hitTestResult.inner Element()); 2622 m_frame->document()->updateHoverActiveState(request, hitTestResult.inner Element());
2605 2623
2606 if (shouldKeepActiveForMinInterval) { 2624 if (shouldKeepActiveForMinInterval) {
2607 m_lastDeferredTapElement = hitTestResult.innerElement(); 2625 m_lastDeferredTapElement = hitTestResult.innerElement();
2608 m_activeIntervalTimer.startOneShot(minimumActiveInterval - activeInterva l, FROM_HERE); 2626 m_activeIntervalTimer.startOneShot(minimumActiveInterval - activeInterva l, FROM_HERE);
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
3863 unsigned EventHandler::accessKeyModifiers() 3881 unsigned EventHandler::accessKeyModifiers()
3864 { 3882 {
3865 #if OS(MACOSX) 3883 #if OS(MACOSX)
3866 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3884 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3867 #else 3885 #else
3868 return PlatformEvent::AltKey; 3886 return PlatformEvent::AltKey;
3869 #endif 3887 #endif
3870 } 3888 }
3871 3889
3872 } // namespace blink 3890 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/events/touch/gesture/tap-target-matches-active-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698