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

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: nits 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
« no previous file with comments | « Source/core/events/WheelEvent.cpp ('k') | Source/platform/PlatformEvent.h » ('j') | 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 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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 } 2226 }
2225 2227
2226 bool EventHandler::handleGestureTap(const GestureEventWithHitTestResults& target edEvent) 2228 bool EventHandler::handleGestureTap(const GestureEventWithHitTestResults& target edEvent)
2227 { 2229 {
2228 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2230 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2229 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2231 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2230 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type()); 2232 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type());
2231 2233
2232 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 2234 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
2233 2235
2234 unsigned modifierFlags = 0;
2235 if (gestureEvent.altKey())
2236 modifierFlags |= PlatformEvent::AltKey;
2237 if (gestureEvent.ctrlKey())
2238 modifierFlags |= PlatformEvent::CtrlKey;
2239 if (gestureEvent.metaKey())
2240 modifierFlags |= PlatformEvent::MetaKey;
2241 if (gestureEvent.shiftKey())
2242 modifierFlags |= PlatformEvent::ShiftKey;
2243 PlatformEvent::Modifiers modifiers = static_cast<PlatformEvent::Modifiers>(m odifierFlags);
2244
2245 HitTestResult currentHitTest = targetedEvent.hitTestResult(); 2236 HitTestResult currentHitTest = targetedEvent.hitTestResult();
2246 2237
2247 // We use the adjusted position so the application isn't surprised to see a event with 2238 // We use the adjusted position so the application isn't surprised to see a event with
2248 // co-ordinates outside the target's bounds. 2239 // co-ordinates outside the target's bounds.
2249 IntPoint adjustedPoint = m_frame->view()->windowToContents(gestureEvent.posi tion()); 2240 IntPoint adjustedPoint = m_frame->view()->windowToContents(gestureEvent.posi tion());
2250 2241
2242 unsigned modifiers = gestureEvent.modifiers();
2251 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.globa lPosition(), 2243 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.globa lPosition(),
2252 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0, 2244 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0,
2253 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2245 static_cast<PlatformEvent::Modifiers>(modifiers),
2246 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2254 dispatchMouseEvent(EventTypeNames::mousemove, currentHitTest.innerNode(), 0, fakeMouseMove, true); 2247 dispatchMouseEvent(EventTypeNames::mousemove, currentHitTest.innerNode(), 0, fakeMouseMove, true);
2255 2248
2256 // Do a new hit-test in case the mousemove event changed the DOM. 2249 // Do a new hit-test in case the mousemove event changed the DOM.
2257 // Note that if the original hit test wasn't over an element (eg. was over a scrollbar) we 2250 // Note that if the original hit test wasn't over an element (eg. was over a scrollbar) we
2258 // don't want to re-hit-test because it may be in the wrong frame (and there 's no way the page 2251 // don't want to re-hit-test because it may be in the wrong frame (and there 's no way the page
2259 // could have seen the event anyway). 2252 // could have seen the event anyway).
2260 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2253 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2261 if (currentHitTest.innerNode()) 2254 if (currentHitTest.innerNode())
2262 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType); 2255 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType);
2263 m_clickNode = currentHitTest.innerNode(); 2256 m_clickNode = currentHitTest.innerNode();
2264 if (m_clickNode && m_clickNode->isTextNode()) 2257 if (m_clickNode && m_clickNode->isTextNode())
2265 m_clickNode = NodeRenderingTraversal::parent(*m_clickNode); 2258 m_clickNode = NodeRenderingTraversal::parent(*m_clickNode);
2266 2259
2267 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(), 2260 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(),
2268 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(), 2261 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(),
2269 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2262 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::LeftBut tonDown),
2263 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2270 bool swallowMouseDownEvent = !dispatchMouseEvent(EventTypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown, true); 2264 bool swallowMouseDownEvent = !dispatchMouseEvent(EventTypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown, true);
2271 if (!swallowMouseDownEvent) 2265 if (!swallowMouseDownEvent)
2272 swallowMouseDownEvent = handleMouseFocus(MouseEventWithHitTestResults(fa keMouseDown, currentHitTest)); 2266 swallowMouseDownEvent = handleMouseFocus(MouseEventWithHitTestResults(fa keMouseDown, currentHitTest));
2273 if (!swallowMouseDownEvent) { 2267 if (!swallowMouseDownEvent) {
2274 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest)); 2268 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest));
2275 // m_selectionInitiationState is initialized after dispatching mousedown event. 2269 // m_selectionInitiationState is initialized after dispatching mousedown event.
2276 m_selectionInitiationState = HaveNotStartedSelection; 2270 m_selectionInitiationState = HaveNotStartedSelection;
2277 } 2271 }
2278 2272
2279 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2273 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2280 if (currentHitTest.innerNode()) 2274 if (currentHitTest.innerNode())
2281 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType); 2275 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType);
2282 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(), 2276 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(),
2283 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(), 2277 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(),
2284 modifiers, PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2278 static_cast<PlatformEvent::Modifiers>(modifiers),
2279 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2285 bool swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, curr entHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp, false); 2280 bool swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, curr entHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp, false);
2286 2281
2287 bool swallowClickEvent = false; 2282 bool swallowClickEvent = false;
2288 if (m_clickNode) { 2283 if (m_clickNode) {
2289 if (currentHitTest.innerNode()) { 2284 if (currentHitTest.innerNode()) {
2290 // Updates distribution because a mouseup (or mousedown) event liste ner can make the 2285 // Updates distribution because a mouseup (or mousedown) event liste ner can make the
2291 // tree dirty at dispatchMouseEvent() invocation above. 2286 // tree dirty at dispatchMouseEvent() invocation above.
2292 // Unless distribution is updated, commonAncestor would hit ASSERT. 2287 // Unless distribution is updated, commonAncestor would hit ASSERT.
2293 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated 2288 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated
2294 // because commonAncestor() will exit early if their documents are d ifferent. 2289 // because commonAncestor() will exit early if their documents are d ifferent.
2295 m_clickNode->document().updateDistributionForNodeIfNeeded(m_clickNod e.get()); 2290 m_clickNode->document().updateDistributionForNodeIfNeeded(m_clickNod e.get());
2296 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent); 2291 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent);
2297 swallowClickEvent = !dispatchMouseEvent(EventTypeNames::click, click TargetNode, gestureEvent.tapCount(), fakeMouseUp, true); 2292 swallowClickEvent = !dispatchMouseEvent(EventTypeNames::click, click TargetNode, gestureEvent.tapCount(), fakeMouseUp, true);
2298 } 2293 }
2299 m_clickNode = nullptr; 2294 m_clickNode = nullptr;
2300 } 2295 }
2301 2296
2302 if (!swallowMouseUpEvent) 2297 if (!swallowMouseUpEvent)
2303 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest)); 2298 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest));
2304 2299
2305 return swallowMouseDownEvent | swallowMouseUpEvent | swallowClickEvent; 2300 return swallowMouseDownEvent | swallowMouseUpEvent | swallowClickEvent;
2306 } 2301 }
2307 2302
2308 bool EventHandler::handleGestureLongPress(const GestureEventWithHitTestResults& targetedEvent) 2303 bool EventHandler::handleGestureLongPress(const GestureEventWithHitTestResults& targetedEvent)
2309 { 2304 {
2310 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2305 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2311 IntPoint adjustedPoint = gestureEvent.position(); 2306 IntPoint adjustedPoint = gestureEvent.position();
2312 2307
2308 unsigned modifiers = gestureEvent.modifiers();
2309
2313 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the 2310 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the
2314 // supplied HitTestResult), but that will require some overhaul of the touch drag-and-drop code 2311 // supplied HitTestResult), but that will require some overhaul of the touch drag-and-drop code
2315 // and LongPress is such a special scenario that it's unlikely to matter muc h in practice. 2312 // and LongPress is such a special scenario that it's unlikely to matter muc h in practice.
2316 2313
2317 m_longTapShouldInvokeContextMenu = false; 2314 m_longTapShouldInvokeContextMenu = false;
2318 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_ frame->view()) { 2315 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_ frame->view()) {
2319 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MousePressed, 1, 2316 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MousePressed, 1,
2320 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey (), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); 2317 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown),
2318 PlatformMouseEvent::FromTouch, WTF::currentTime());
2321 m_mouseDown = mouseDownEvent; 2319 m_mouseDown = mouseDownEvent;
2322 2320
2323 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MouseMoved, 1, 2321 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MouseMoved, 1,
2324 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey (), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); 2322 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown),
2323 PlatformMouseEvent::FromTouch, WTF::currentTime());
2325 HitTestRequest request(HitTestRequest::ReadOnly); 2324 HitTestRequest request(HitTestRequest::ReadOnly);
2326 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE vent); 2325 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE vent);
2327 m_mouseDownMayStartDrag = true; 2326 m_mouseDownMayStartDrag = true;
2328 dragState().m_dragSrc = nullptr; 2327 dragState().m_dragSrc = nullptr;
2329 m_mouseDownPos = m_frame->view()->windowToContents(mouseDragEvent.positi on()); 2328 m_mouseDownPos = m_frame->view()->windowToContents(mouseDragEvent.positi on());
2330 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2329 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2331 if (handleDrag(mev, DragInitiator::Touch)) { 2330 if (handleDrag(mev, DragInitiator::Touch)) {
2332 m_longTapShouldInvokeContextMenu = true; 2331 m_longTapShouldInvokeContextMenu = true;
2333 return true; 2332 return true;
2334 } 2333 }
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 #endif 2819 #endif
2821 2820
2822 PlatformMouseEvent mouseEvent(position, globalPosition, RightButton, eventTy pe, 1, false, false, false, false, PlatformMouseEvent::RealOrIndistinguishable, WTF::currentTime()); 2821 PlatformMouseEvent mouseEvent(position, globalPosition, RightButton, eventTy pe, 1, false, false, false, false, PlatformMouseEvent::RealOrIndistinguishable, WTF::currentTime());
2823 2822
2824 handleMousePressEvent(mouseEvent); 2823 handleMousePressEvent(mouseEvent);
2825 return sendContextMenuEvent(mouseEvent); 2824 return sendContextMenuEvent(mouseEvent);
2826 } 2825 }
2827 2826
2828 bool EventHandler::sendContextMenuEventForGesture(const GestureEventWithHitTestR esults& targetedEvent) 2827 bool EventHandler::sendContextMenuEventForGesture(const GestureEventWithHitTestR esults& targetedEvent)
2829 { 2828 {
2829 unsigned modifiers = targetedEvent.event().modifiers();
2830 PlatformEvent::Type eventType = PlatformEvent::MousePressed; 2830 PlatformEvent::Type eventType = PlatformEvent::MousePressed;
2831 2831
2832 if (m_frame->settings()->showContextMenuOnMouseUp()) 2832 if (m_frame->settings()->showContextMenuOnMouseUp())
2833 eventType = PlatformEvent::MouseReleased; 2833 eventType = PlatformEvent::MouseReleased;
2834 else
2835 modifiers |= PlatformEvent::RightButtonDown;
2834 2836
2835 PlatformMouseEvent mouseEvent(targetedEvent.event().position(), targetedEven t.event().globalPosition(), RightButton, eventType, 1, false, false, false, fals e, PlatformMouseEvent::FromTouch, WTF::currentTime()); 2837 PlatformMouseEvent mouseEvent(targetedEvent.event().position(), targetedEven t.event().globalPosition(), RightButton, eventType, 1,
2838 static_cast<PlatformEvent::Modifiers>(modifiers),
2839 PlatformMouseEvent::FromTouch, WTF::currentTime());
2836 // To simulate right-click behavior, we send a right mouse down and then 2840 // To simulate right-click behavior, we send a right mouse down and then
2837 // context menu event. 2841 // context menu event.
2838 // FIXME: Send HitTestResults to avoid redundant hit tests. 2842 // FIXME: Send HitTestResults to avoid redundant hit tests.
2839 handleMousePressEvent(mouseEvent); 2843 handleMousePressEvent(mouseEvent);
2840 return sendContextMenuEvent(mouseEvent); 2844 return sendContextMenuEvent(mouseEvent);
2841 // We do not need to send a corresponding mouse release because in case of 2845 // We do not need to send a corresponding mouse release because in case of
2842 // right-click, the context menu takes capture and consumes all events. 2846 // right-click, the context menu takes capture and consumes all events.
2843 } 2847 }
2844 2848
2845 void EventHandler::scheduleHoverStateUpdate() 2849 void EventHandler::scheduleHoverStateUpdate()
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
3861 unsigned EventHandler::accessKeyModifiers() 3865 unsigned EventHandler::accessKeyModifiers()
3862 { 3866 {
3863 #if OS(MACOSX) 3867 #if OS(MACOSX)
3864 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3868 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3865 #else 3869 #else
3866 return PlatformEvent::AltKey; 3870 return PlatformEvent::AltKey;
3867 #endif 3871 #endif
3868 } 3872 }
3869 3873
3870 } // namespace blink 3874 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/events/WheelEvent.cpp ('k') | Source/platform/PlatformEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698