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

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

Issue 727593003: Implement MouseEvent buttons attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: should be 0 in contextmenu event Created 6 years 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
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 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 1627
1628 1628
1629 bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTa rget, const PlatformMouseEvent& event, DataTransfer* dataTransfer) 1629 bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTa rget, const PlatformMouseEvent& event, DataTransfer* dataTransfer)
1630 { 1630 {
1631 FrameView* view = m_frame->view(); 1631 FrameView* view = m_frame->view();
1632 1632
1633 // FIXME: We might want to dispatch a dragleave even if the view is gone. 1633 // FIXME: We might want to dispatch a dragleave even if the view is gone.
1634 if (!view) 1634 if (!view)
1635 return false; 1635 return false;
1636 1636
1637 // FIXME: The drag event have to support for |buttons| attribute because
1638 // the event is derived from mouse event. Please see crbug.com/276941.
1637 RefPtrWillBeRawPtr<MouseEvent> me = MouseEvent::create(eventType, 1639 RefPtrWillBeRawPtr<MouseEvent> me = MouseEvent::create(eventType,
1638 true, true, m_frame->document()->domWindow(), 1640 true, true, m_frame->document()->domWindow(),
1639 0, event.globalPosition().x(), event.globalPosition().y(), event.positio n().x(), event.position().y(), 1641 0, event.globalPosition().x(), event.globalPosition().y(), event.positio n().x(), event.position().y(),
1640 event.movementDelta().x(), event.movementDelta().y(), 1642 event.movementDelta().x(), event.movementDelta().y(),
1641 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), 1643 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(),
1642 0, nullptr, dataTransfer); 1644 0, 0, nullptr, dataTransfer);
1643 1645
1644 dragTarget->dispatchEvent(me.get(), IGNORE_EXCEPTION); 1646 dragTarget->dispatchEvent(me.get(), IGNORE_EXCEPTION);
1645 return me->defaultPrevented(); 1647 return me->defaultPrevented();
1646 } 1648 }
1647 1649
1648 static bool targetIsFrame(Node* target, LocalFrame*& frame) 1650 static bool targetIsFrame(Node* target, LocalFrame*& frame)
1649 { 1651 {
1650 if (!isHTMLFrameElementBase(target)) 1652 if (!isHTMLFrameElementBase(target))
1651 return false; 1653 return false;
1652 1654
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 case PlatformEvent::GesturePinchBegin: 2219 case PlatformEvent::GesturePinchBegin:
2218 case PlatformEvent::GesturePinchEnd: 2220 case PlatformEvent::GesturePinchEnd:
2219 case PlatformEvent::GesturePinchUpdate: 2221 case PlatformEvent::GesturePinchUpdate:
2220 return false; 2222 return false;
2221 default: 2223 default:
2222 ASSERT_NOT_REACHED(); 2224 ASSERT_NOT_REACHED();
2223 return false; 2225 return false;
2224 } 2226 }
2225 } 2227 }
2226 2228
2229 static PlatformEvent::Modifiers platformModifiersFrom(unsigned modifierFlags)
Rick Byers 2014/11/28 17:36:02 nit: this function is simple enough you should jus
zino 2014/12/03 15:47:15 Done.
2230 {
2231 return static_cast<PlatformEvent::Modifiers>(modifierFlags);
2232 }
2233
2234 static unsigned modifierFlagsFrom(const PlatformGestureEvent& event)
Rick Byers 2014/11/28 17:36:02 Isn't this function pretty much equivalent to just
zino 2014/12/03 15:47:15 Yep.. you're right :) Thanks. Done.
2235 {
2236 unsigned modifierFlags = 0;
2237
2238 if (event.altKey())
2239 modifierFlags |= PlatformEvent::AltKey;
2240 if (event.ctrlKey())
2241 modifierFlags |= PlatformEvent::CtrlKey;
2242 if (event.metaKey())
2243 modifierFlags |= PlatformEvent::MetaKey;
2244 if (event.shiftKey())
2245 modifierFlags |= PlatformEvent::ShiftKey;
2246
2247 return modifierFlags;
2248 }
2249
2227 bool EventHandler::handleGestureTap(const GestureEventWithHitTestResults& target edEvent) 2250 bool EventHandler::handleGestureTap(const GestureEventWithHitTestResults& target edEvent)
2228 { 2251 {
2229 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2252 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2230 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2253 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2231 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type()); 2254 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type());
2232 2255
2233 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 2256 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
2234 2257
2235 unsigned modifierFlags = 0; 2258 unsigned modifierFlags = modifierFlagsFrom(gestureEvent);
2236 if (gestureEvent.altKey())
2237 modifierFlags |= PlatformEvent::AltKey;
2238 if (gestureEvent.ctrlKey())
2239 modifierFlags |= PlatformEvent::CtrlKey;
2240 if (gestureEvent.metaKey())
2241 modifierFlags |= PlatformEvent::MetaKey;
2242 if (gestureEvent.shiftKey())
2243 modifierFlags |= PlatformEvent::ShiftKey;
2244 PlatformEvent::Modifiers modifiers = static_cast<PlatformEvent::Modifiers>(m odifierFlags);
2245 2259
2246 HitTestResult currentHitTest = targetedEvent.hitTestResult(); 2260 HitTestResult currentHitTest = targetedEvent.hitTestResult();
2247 2261
2248 // We use the adjusted position so the application isn't surprised to see a event with 2262 // We use the adjusted position so the application isn't surprised to see a event with
2249 // co-ordinates outside the target's bounds. 2263 // co-ordinates outside the target's bounds.
2250 IntPoint adjustedPoint = m_frame->view()->windowToContents(gestureEvent.posi tion()); 2264 IntPoint adjustedPoint = m_frame->view()->windowToContents(gestureEvent.posi tion());
2251 2265
2252 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.globa lPosition(), 2266 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.globa lPosition(),
2253 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0, 2267 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0,
2254 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2268 platformModifiersFrom(modifierFlags),
2269 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2255 dispatchMouseEvent(EventTypeNames::mousemove, currentHitTest.innerNode(), 0, fakeMouseMove, true); 2270 dispatchMouseEvent(EventTypeNames::mousemove, currentHitTest.innerNode(), 0, fakeMouseMove, true);
2256 2271
2257 // Do a new hit-test in case the mousemove event changed the DOM. 2272 // Do a new hit-test in case the mousemove event changed the DOM.
2258 // Note that if the original hit test wasn't over an element (eg. was over a scrollbar) we 2273 // Note that if the original hit test wasn't over an element (eg. was over a scrollbar) we
2259 // don't want to re-hit-test because it may be in the wrong frame (and there 's no way the page 2274 // don't want to re-hit-test because it may be in the wrong frame (and there 's no way the page
2260 // could have seen the event anyway). 2275 // could have seen the event anyway).
2261 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2276 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2262 if (currentHitTest.innerNode()) 2277 if (currentHitTest.innerNode())
2263 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType); 2278 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType);
2264 m_clickNode = currentHitTest.innerNode(); 2279 m_clickNode = currentHitTest.innerNode();
2265 if (m_clickNode && m_clickNode->isTextNode()) 2280 if (m_clickNode && m_clickNode->isTextNode())
2266 m_clickNode = NodeRenderingTraversal::parent(*m_clickNode); 2281 m_clickNode = NodeRenderingTraversal::parent(*m_clickNode);
2267 2282
2268 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(), 2283 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(),
2269 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(), 2284 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(),
2270 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2285 platformModifiersFrom(modifierFlags | PlatformEvent::LeftButtonDown),
2286 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2271 bool swallowMouseDownEvent = !dispatchMouseEvent(EventTypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown, true); 2287 bool swallowMouseDownEvent = !dispatchMouseEvent(EventTypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown, true);
2272 if (!swallowMouseDownEvent) 2288 if (!swallowMouseDownEvent)
2273 swallowMouseDownEvent = handleMouseFocus(MouseEventWithHitTestResults(fa keMouseDown, currentHitTest)); 2289 swallowMouseDownEvent = handleMouseFocus(MouseEventWithHitTestResults(fa keMouseDown, currentHitTest));
2274 if (!swallowMouseDownEvent) { 2290 if (!swallowMouseDownEvent) {
2275 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest)); 2291 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest));
2276 // m_selectionInitiationState is initialized after dispatching mousedown event. 2292 // m_selectionInitiationState is initialized after dispatching mousedown event.
2277 m_selectionInitiationState = HaveNotStartedSelection; 2293 m_selectionInitiationState = HaveNotStartedSelection;
2278 } 2294 }
2279 2295
2280 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2296 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2281 if (currentHitTest.innerNode()) 2297 if (currentHitTest.innerNode())
2282 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType); 2298 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType);
2283 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(), 2299 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(),
2284 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(), 2300 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(),
2285 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2301 platformModifiersFrom(modifierFlags),
2302 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2286 bool swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, curr entHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp, false); 2303 bool swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, curr entHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp, false);
2287 2304
2288 bool swallowClickEvent = false; 2305 bool swallowClickEvent = false;
2289 if (m_clickNode) { 2306 if (m_clickNode) {
2290 if (currentHitTest.innerNode()) { 2307 if (currentHitTest.innerNode()) {
2291 // Updates distribution because a mouseup (or mousedown) event liste ner can make the 2308 // Updates distribution because a mouseup (or mousedown) event liste ner can make the
2292 // tree dirty at dispatchMouseEvent() invocation above. 2309 // tree dirty at dispatchMouseEvent() invocation above.
2293 // Unless distribution is updated, commonAncestor would hit ASSERT. 2310 // Unless distribution is updated, commonAncestor would hit ASSERT.
2294 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated 2311 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated
2295 // because commonAncestor() will exit early if their documents are d ifferent. 2312 // because commonAncestor() will exit early if their documents are d ifferent.
2296 m_clickNode->document().updateDistributionForNodeIfNeeded(m_clickNod e.get()); 2313 m_clickNode->document().updateDistributionForNodeIfNeeded(m_clickNod e.get());
2297 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent); 2314 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent);
2298 swallowClickEvent = !dispatchMouseEvent(EventTypeNames::click, click TargetNode, gestureEvent.tapCount(), fakeMouseUp, true); 2315 swallowClickEvent = !dispatchMouseEvent(EventTypeNames::click, click TargetNode, gestureEvent.tapCount(), fakeMouseUp, true);
2299 } 2316 }
2300 m_clickNode = nullptr; 2317 m_clickNode = nullptr;
2301 } 2318 }
2302 2319
2303 if (!swallowMouseUpEvent) 2320 if (!swallowMouseUpEvent)
2304 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest)); 2321 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest));
2305 2322
2306 return swallowMouseDownEvent | swallowMouseUpEvent | swallowClickEvent; 2323 return swallowMouseDownEvent | swallowMouseUpEvent | swallowClickEvent;
2307 } 2324 }
2308 2325
2309 bool EventHandler::handleGestureLongPress(const GestureEventWithHitTestResults& targetedEvent) 2326 bool EventHandler::handleGestureLongPress(const GestureEventWithHitTestResults& targetedEvent)
2310 { 2327 {
2311 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2328 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2312 IntPoint adjustedPoint = gestureEvent.position(); 2329 IntPoint adjustedPoint = gestureEvent.position();
2313 2330
2331 unsigned modifierFlags = modifierFlagsFrom(gestureEvent);
2332
2314 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the 2333 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the
2315 // supplied HitTestResult), but that will require some overhaul of the touch drag-and-drop code 2334 // supplied HitTestResult), but that will require some overhaul of the touch drag-and-drop code
2316 // and LongPress is such a special scenario that it's unlikely to matter muc h in practice. 2335 // and LongPress is such a special scenario that it's unlikely to matter muc h in practice.
2317 2336
2318 m_longTapShouldInvokeContextMenu = false; 2337 m_longTapShouldInvokeContextMenu = false;
2319 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_ frame->view()) { 2338 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_ frame->view()) {
2320 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MousePressed, 1, 2339 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MousePressed, 1,
2321 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey (), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); 2340 platformModifiersFrom(modifierFlags | PlatformEvent::LeftButtonDown) ,
2341 PlatformMouseEvent::FromTouch, WTF::currentTime());
2322 m_mouseDown = mouseDownEvent; 2342 m_mouseDown = mouseDownEvent;
2323 2343
2324 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MouseMoved, 1, 2344 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MouseMoved, 1,
2325 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey (), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); 2345 platformModifiersFrom(modifierFlags | PlatformEvent::LeftButtonDown) ,
2346 PlatformMouseEvent::FromTouch, WTF::currentTime());
2326 HitTestRequest request(HitTestRequest::ReadOnly); 2347 HitTestRequest request(HitTestRequest::ReadOnly);
2327 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE vent); 2348 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE vent);
2328 m_mouseDownMayStartDrag = true; 2349 m_mouseDownMayStartDrag = true;
2329 dragState().m_dragSrc = nullptr; 2350 dragState().m_dragSrc = nullptr;
2330 m_mouseDownPos = m_frame->view()->windowToContents(mouseDragEvent.positi on()); 2351 m_mouseDownPos = m_frame->view()->windowToContents(mouseDragEvent.positi on());
2331 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2352 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2332 if (handleDrag(mev, DragInitiator::Touch)) { 2353 if (handleDrag(mev, DragInitiator::Touch)) {
2333 m_longTapShouldInvokeContextMenu = true; 2354 m_longTapShouldInvokeContextMenu = true;
2334 return true; 2355 return true;
2335 } 2356 }
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 2845
2825 handleMousePressEvent(mouseEvent); 2846 handleMousePressEvent(mouseEvent);
2826 return sendContextMenuEvent(mouseEvent); 2847 return sendContextMenuEvent(mouseEvent);
2827 } 2848 }
2828 2849
2829 bool EventHandler::sendContextMenuEventForGesture(const GestureEventWithHitTestR esults& targetedEvent) 2850 bool EventHandler::sendContextMenuEventForGesture(const GestureEventWithHitTestR esults& targetedEvent)
2830 { 2851 {
2831 #if OS(WIN) 2852 #if OS(WIN)
2832 PlatformEvent::Type eventType = PlatformEvent::MouseReleased; 2853 PlatformEvent::Type eventType = PlatformEvent::MouseReleased;
2833 #else 2854 #else
2834 PlatformEvent::Type eventType = PlatformEvent::MousePressed; 2855 PlatformEvent::Type eventType = PlatformEvent::MousePressed;
Rick Byers 2014/11/28 17:36:02 Looks like I was wrong and this OS behavior differ
zino 2014/12/03 15:47:15 Thank you for your guide. As you know, these works
2835 #endif 2856 #endif
2836 2857
2837 PlatformMouseEvent mouseEvent(targetedEvent.event().position(), targetedEven t.event().globalPosition(), RightButton, eventType, 1, false, false, false, fals e, PlatformMouseEvent::FromTouch, WTF::currentTime()); 2858 PlatformMouseEvent mouseEvent(targetedEvent.event().position(), targetedEven t.event().globalPosition(), RightButton, eventType, 1,
2859 platformModifiersFrom(modifierFlagsFrom(targetedEvent.event())),
2860 PlatformMouseEvent::FromTouch, WTF::currentTime());
2838 // To simulate right-click behavior, we send a right mouse down and then 2861 // To simulate right-click behavior, we send a right mouse down and then
2839 // context menu event. 2862 // context menu event.
2840 // FIXME: Send HitTestResults to avoid redundant hit tests. 2863 // FIXME: Send HitTestResults to avoid redundant hit tests.
2841 handleMousePressEvent(mouseEvent); 2864 handleMousePressEvent(mouseEvent);
2842 return sendContextMenuEvent(mouseEvent); 2865 return sendContextMenuEvent(mouseEvent);
2843 // We do not need to send a corresponding mouse release because in case of 2866 // We do not need to send a corresponding mouse release because in case of
2844 // right-click, the context menu takes capture and consumes all events. 2867 // right-click, the context menu takes capture and consumes all events.
2845 } 2868 }
2846 2869
2847 void EventHandler::scheduleHoverStateUpdate() 2870 void EventHandler::scheduleHoverStateUpdate()
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
3863 unsigned EventHandler::accessKeyModifiers() 3886 unsigned EventHandler::accessKeyModifiers()
3864 { 3887 {
3865 #if OS(MACOSX) 3888 #if OS(MACOSX)
3866 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3889 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3867 #else 3890 #else
3868 return PlatformEvent::AltKey; 3891 return PlatformEvent::AltKey;
3869 #endif 3892 #endif
3870 } 3893 }
3871 3894
3872 } // namespace blink 3895 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698