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

Side by Side Diff: third_party/WebKit/Source/core/input/EventHandler.cpp

Issue 1654653002: Canvas2d: Implement rerouting event by hit region's control. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "core/events/TextEvent.h" 49 #include "core/events/TextEvent.h"
50 #include "core/events/TouchEvent.h" 50 #include "core/events/TouchEvent.h"
51 #include "core/events/WheelEvent.h" 51 #include "core/events/WheelEvent.h"
52 #include "core/fetch/ImageResource.h" 52 #include "core/fetch/ImageResource.h"
53 #include "core/frame/EventHandlerRegistry.h" 53 #include "core/frame/EventHandlerRegistry.h"
54 #include "core/frame/FrameHost.h" 54 #include "core/frame/FrameHost.h"
55 #include "core/frame/FrameView.h" 55 #include "core/frame/FrameView.h"
56 #include "core/frame/LocalFrame.h" 56 #include "core/frame/LocalFrame.h"
57 #include "core/frame/Settings.h" 57 #include "core/frame/Settings.h"
58 #include "core/frame/VisualViewport.h" 58 #include "core/frame/VisualViewport.h"
59 #include "core/html/HTMLCanvasElement.h"
59 #include "core/html/HTMLDialogElement.h" 60 #include "core/html/HTMLDialogElement.h"
60 #include "core/html/HTMLFrameElementBase.h" 61 #include "core/html/HTMLFrameElementBase.h"
61 #include "core/html/HTMLFrameSetElement.h" 62 #include "core/html/HTMLFrameSetElement.h"
62 #include "core/html/HTMLInputElement.h" 63 #include "core/html/HTMLInputElement.h"
63 #include "core/input/InputDeviceCapabilities.h" 64 #include "core/input/InputDeviceCapabilities.h"
64 #include "core/input/TouchActionUtil.h" 65 #include "core/input/TouchActionUtil.h"
65 #include "core/layout/HitTestRequest.h" 66 #include "core/layout/HitTestRequest.h"
66 #include "core/layout/HitTestResult.h" 67 #include "core/layout/HitTestResult.h"
67 #include "core/layout/LayoutPart.h" 68 #include "core/layout/LayoutPart.h"
68 #include "core/layout/LayoutTextControlSingleLine.h" 69 #include "core/layout/LayoutTextControlSingleLine.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 visitor->trace(m_capturingMouseEventsNode); 359 visitor->trace(m_capturingMouseEventsNode);
359 visitor->trace(m_nodeUnderMouse); 360 visitor->trace(m_nodeUnderMouse);
360 visitor->trace(m_lastMouseMoveEventSubframe); 361 visitor->trace(m_lastMouseMoveEventSubframe);
361 visitor->trace(m_lastScrollbarUnderMouse); 362 visitor->trace(m_lastScrollbarUnderMouse);
362 visitor->trace(m_clickNode); 363 visitor->trace(m_clickNode);
363 visitor->trace(m_dragTarget); 364 visitor->trace(m_dragTarget);
364 visitor->trace(m_frameSetBeingResized); 365 visitor->trace(m_frameSetBeingResized);
365 visitor->trace(m_previousWheelScrolledNode); 366 visitor->trace(m_previousWheelScrolledNode);
366 visitor->trace(m_scrollbarHandlingScrollGesture); 367 visitor->trace(m_scrollbarHandlingScrollGesture);
367 visitor->trace(m_targetForTouchID); 368 visitor->trace(m_targetForTouchID);
369 visitor->trace(m_regionForTouchID);
368 visitor->trace(m_touchSequenceDocument); 370 visitor->trace(m_touchSequenceDocument);
369 visitor->trace(m_scrollGestureHandlingNode); 371 visitor->trace(m_scrollGestureHandlingNode);
370 visitor->trace(m_previousGestureScrolledNode); 372 visitor->trace(m_previousGestureScrolledNode);
371 visitor->trace(m_lastDeferredTapElement); 373 visitor->trace(m_lastDeferredTapElement);
372 visitor->trace(m_selectionController); 374 visitor->trace(m_selectionController);
373 #endif 375 #endif
374 } 376 }
375 377
376 DragState& EventHandler::dragState() 378 DragState& EventHandler::dragState()
377 { 379 {
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 if (m_clickCount > 0 && !contextMenuEvent && mev.innerNode() && m_clickNode && mev.innerNode()->canParticipateInFlatTree() && m_clickNode->canParticipateInF latTree()) { 1378 if (m_clickCount > 0 && !contextMenuEvent && mev.innerNode() && m_clickNode && mev.innerNode()->canParticipateInFlatTree() && m_clickNode->canParticipateInF latTree()) {
1377 // Updates distribution because a 'mouseup' event listener can make the 1379 // Updates distribution because a 'mouseup' event listener can make the
1378 // tree dirty at dispatchMouseEvent() invocation above. 1380 // tree dirty at dispatchMouseEvent() invocation above.
1379 // Unless distribution is updated, commonAncestor would hit ASSERT. 1381 // Unless distribution is updated, commonAncestor would hit ASSERT.
1380 // Both m_clickNode and mev.innerNode() don't need to be updated 1382 // Both m_clickNode and mev.innerNode() don't need to be updated
1381 // because commonAncestor() will exit early if their documents are diffe rent. 1383 // because commonAncestor() will exit early if their documents are diffe rent.
1382 m_clickNode->updateDistribution(); 1384 m_clickNode->updateDistribution();
1383 if (Node* clickTargetNode = mev.innerNode()->commonAncestor( 1385 if (Node* clickTargetNode = mev.innerNode()->commonAncestor(
1384 *m_clickNode, parentForClickEvent)) { 1386 *m_clickNode, parentForClickEvent)) {
1385 1387
1388 if (isHTMLCanvasElement(clickTargetNode)) {
1389 LayoutPoint documentPoint = contentPointFromRootFrame(m_frame, m ouseEvent.position());
1390 std::pair<Element*, String> regionInfo = toHTMLCanvasElement(cli ckTargetNode)->getControlAndIdIfHitRegionExists(documentPoint);
1391 if (regionInfo.first)
1392 clickTargetNode = regionInfo.first;
1393 const_cast<PlatformMouseEvent&>(mouseEvent).setRegion(regionInfo .second);
Rick Byers 2016/02/23 20:26:08 It's unfortunate to need to rely on a const_cast h
zino 2016/03/08 12:33:48 I couldn't find the part that you mentioned "That
Rick Byers 2016/03/08 15:57:34 This code: return MouseEventWithHitTestResults(
Rick Byers 2016/03/10 21:36:28 This looks really great now, thanks! I love how y
1394 }
1395
1386 // Dispatch mouseup directly w/o calling updateMouseEventTargetNode 1396 // Dispatch mouseup directly w/o calling updateMouseEventTargetNode
1387 // because the mouseup dispatch above has already updated it 1397 // because the mouseup dispatch above has already updated it
1388 // correctly. Moreover, clickTargetNode is different from 1398 // correctly. Moreover, clickTargetNode is different from
1389 // mev.innerNode at drag-release. 1399 // mev.innerNode at drag-release.
1390 if (clickTargetNode->dispatchMouseEvent(mouseEvent, 1400 if (clickTargetNode->dispatchMouseEvent(mouseEvent,
1391 EventTypeNames::click, m_clickCount)) { 1401 EventTypeNames::click, m_clickCount)) {
1392 clickEventResult = WebInputEventResult::HandledApplication; 1402 clickEventResult = WebInputEventResult::HandledApplication;
1393 } 1403 }
1394 } 1404 }
1395 } 1405 }
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 // The mouse has moved between layers. 1652 // The mouse has moved between layers.
1643 if (ScrollableArea* scrollableAreaForNodeUnderMouse = associatedScrollab leArea(layerForNodeUnderMouse)) 1653 if (ScrollableArea* scrollableAreaForNodeUnderMouse = associatedScrollab leArea(layerForNodeUnderMouse))
1644 scrollableAreaForNodeUnderMouse->mouseEnteredContentArea(); 1654 scrollableAreaForNodeUnderMouse->mouseEnteredContentArea();
1645 } 1655 }
1646 1656
1647 if (lastNodeUnderMouse && lastNodeUnderMouse->document() != m_frame->documen t()) { 1657 if (lastNodeUnderMouse && lastNodeUnderMouse->document() != m_frame->documen t()) {
1648 lastNodeUnderMouse = nullptr; 1658 lastNodeUnderMouse = nullptr;
1649 m_lastScrollbarUnderMouse = nullptr; 1659 m_lastScrollbarUnderMouse = nullptr;
1650 } 1660 }
1651 1661
1662 if (isHTMLCanvasElement(m_nodeUnderMouse)) {
1663 LayoutPoint documentPoint = contentPointFromRootFrame(m_frame, mouseEven t.position());
1664 std::pair<Element*, String> regionInfo = toHTMLCanvasElement(m_nodeUnder Mouse)->getControlAndIdIfHitRegionExists(documentPoint);
1665 if (regionInfo.first)
1666 m_nodeUnderMouse = regionInfo.first;
1667 const_cast<PlatformMouseEvent&>(mouseEvent).setRegion(regionInfo.second) ;
1668 }
1669
1652 if (lastNodeUnderMouse != m_nodeUnderMouse) 1670 if (lastNodeUnderMouse != m_nodeUnderMouse)
1653 sendNodeTransitionEvents(lastNodeUnderMouse.get(), m_nodeUnderMouse.get( ), mouseEvent); 1671 sendNodeTransitionEvents(lastNodeUnderMouse.get(), m_nodeUnderMouse.get( ), mouseEvent);
1654 } 1672 }
1655 1673
1656 WebInputEventResult EventHandler::dispatchPointerEvent(EventTarget* target, Pass RefPtrWillBeRawPtr<PointerEvent> pointerEvent) 1674 WebInputEventResult EventHandler::dispatchPointerEvent(EventTarget* target, Pass RefPtrWillBeRawPtr<PointerEvent> pointerEvent)
1657 { 1675 {
1658 if (!RuntimeEnabledFeatures::pointerEventEnabled()) 1676 if (!RuntimeEnabledFeatures::pointerEventEnabled())
1659 return WebInputEventResult::NotHandled; 1677 return WebInputEventResult::NotHandled;
1660 1678
1661 bool dispatchResult = target->dispatchEvent(pointerEvent.get()); 1679 bool dispatchResult = target->dispatchEvent(pointerEvent.get());
(...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3843 continue; 3861 continue;
3844 3862
3845 RefPtrWillBeRawPtr<Touch> touch = Touch::create( 3863 RefPtrWillBeRawPtr<Touch> touch = Touch::create(
3846 touchInfo.targetFrame.get(), 3864 touchInfo.targetFrame.get(),
3847 touchInfo.touchTarget.get(), 3865 touchInfo.touchTarget.get(),
3848 point.id(), 3866 point.id(),
3849 point.screenPos(), 3867 point.screenPos(),
3850 touchInfo.adjustedPagePoint, 3868 touchInfo.adjustedPagePoint,
3851 touchInfo.adjustedRadius, 3869 touchInfo.adjustedRadius,
3852 point.rotationAngle(), 3870 point.rotationAngle(),
3853 point.force()); 3871 point.force(),
3872 touchInfo.region);
3854 3873
3855 // Ensure this target's touch list exists, even if it ends up empty, so 3874 // Ensure this target's touch list exists, even if it ends up empty, so
3856 // it can always be passed to TouchEvent::Create below. 3875 // it can always be passed to TouchEvent::Create below.
3857 TargetTouchesHeapMap::iterator targetTouchesIterator = touchesByTarget.f ind(touchInfo.touchTarget.get()); 3876 TargetTouchesHeapMap::iterator targetTouchesIterator = touchesByTarget.f ind(touchInfo.touchTarget.get());
3858 if (targetTouchesIterator == touchesByTarget.end()) { 3877 if (targetTouchesIterator == touchesByTarget.end()) {
3859 touchesByTarget.set(touchInfo.touchTarget.get(), TouchList::create() ); 3878 touchesByTarget.set(touchInfo.touchTarget.get(), TouchList::create() );
3860 targetTouchesIterator = touchesByTarget.find(touchInfo.touchTarget.g et()); 3879 targetTouchesIterator = touchesByTarget.find(touchInfo.touchTarget.g et());
3861 } 3880 }
3862 3881
3863 // touches and targetTouches should only contain information about 3882 // touches and targetTouches should only contain information about
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3970 LayoutPoint framePoint = roundedLayoutPoint(m_touchSequenceDocum ent->frame()->view()->rootFrameToContents(point.pos())); 3989 LayoutPoint framePoint = roundedLayoutPoint(m_touchSequenceDocum ent->frame()->view()->rootFrameToContents(point.pos()));
3971 result = hitTestResultInFrame(m_touchSequenceDocument->frame(), framePoint, hitType); 3990 result = hitTestResultInFrame(m_touchSequenceDocument->frame(), framePoint, hitType);
3972 } else { 3991 } else {
3973 continue; 3992 continue;
3974 } 3993 }
3975 3994
3976 Node* node = result.innerNode(); 3995 Node* node = result.innerNode();
3977 if (!node) 3996 if (!node)
3978 continue; 3997 continue;
3979 3998
3999 if (isHTMLCanvasElement(node)) {
4000 std::pair<Element*, String> regionInfo = toHTMLCanvasElement(nod e)->getControlAndIdIfHitRegionExists(result.pointInInnerNodeFrame());
4001 if (regionInfo.first)
4002 node = regionInfo.first;
4003 m_regionForTouchID.set(point.id(), regionInfo.second);
4004 }
4005
3980 // Touch events should not go to text nodes 4006 // Touch events should not go to text nodes
3981 if (node->isTextNode()) 4007 if (node->isTextNode())
3982 node = FlatTreeTraversal::parent(*node); 4008 node = FlatTreeTraversal::parent(*node);
3983 4009
3984 if (!m_touchSequenceDocument) { 4010 if (!m_touchSequenceDocument) {
3985 // Keep track of which document should receive all touch events 4011 // Keep track of which document should receive all touch events
3986 // in the active sequence. This must be a single document to 4012 // in the active sequence. This must be a single document to
3987 // ensure we don't leak Nodes between documents. 4013 // ensure we don't leak Nodes between documents.
3988 m_touchSequenceDocument = &(result.innerNode()->document()); 4014 m_touchSequenceDocument = &(result.innerNode()->document());
3989 ASSERT(m_touchSequenceDocument->frame()->view()); 4015 ASSERT(m_touchSequenceDocument->frame()->view());
(...skipping 26 matching lines...) Expand all
4016 return WebInputEventResult::NotHandled; 4042 return WebInputEventResult::NotHandled;
4017 } 4043 }
4018 4044
4019 // Compute and store the common info used by both PointerEvent and TouchEven t. 4045 // Compute and store the common info used by both PointerEvent and TouchEven t.
4020 WillBeHeapVector<TouchInfo> touchInfos(points.size()); 4046 WillBeHeapVector<TouchInfo> touchInfos(points.size());
4021 4047
4022 for (unsigned i = 0; i < points.size(); ++i) { 4048 for (unsigned i = 0; i < points.size(); ++i) {
4023 const PlatformTouchPoint& point = points[i]; 4049 const PlatformTouchPoint& point = points[i];
4024 PlatformTouchPoint::State pointState = point.state(); 4050 PlatformTouchPoint::State pointState = point.state();
4025 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr; 4051 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr;
4052 String regionID;
4026 4053
4027 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) { 4054 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) {
4028 // The target should be the original target for this touch, so get 4055 // The target should be the original target for this touch, so get
4029 // it from the hashmap. As it's a release or cancel we also remove 4056 // it from the hashmap. As it's a release or cancel we also remove
4030 // it from the map. 4057 // it from the map.
4031 touchTarget = m_targetForTouchID.take(point.id()); 4058 touchTarget = m_targetForTouchID.take(point.id());
4059 regionID = m_regionForTouchID.take(point.id());
4032 } else { 4060 } else {
4033 // No hittest is performed on move or stationary, since the target 4061 // No hittest is performed on move or stationary, since the target
4034 // is not allowed to change anyway. 4062 // is not allowed to change anyway.
4035 touchTarget = m_targetForTouchID.get(point.id()); 4063 touchTarget = m_targetForTouchID.get(point.id());
4064 regionID = m_regionForTouchID.get(point.id());
4036 } 4065 }
4037 4066
4038 LocalFrame* targetFrame = nullptr; 4067 LocalFrame* targetFrame = nullptr;
4039 bool knownTarget = false; 4068 bool knownTarget = false;
4040 if (touchTarget) { 4069 if (touchTarget) {
4041 Document& doc = touchTarget->toNode()->document(); 4070 Document& doc = touchTarget->toNode()->document();
4042 // If the target node has moved to a new document while it was being touched, 4071 // If the target node has moved to a new document while it was being touched,
4043 // we can't send events to the new document because that could leak nodes 4072 // we can't send events to the new document because that could leak nodes
4044 // from one document to another. See http://crbug.com/394339. 4073 // from one document to another. See http://crbug.com/394339.
4045 if (&doc == m_touchSequenceDocument.get()) { 4074 if (&doc == m_touchSequenceDocument.get()) {
(...skipping 25 matching lines...) Expand all
4071 float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); 4100 float scaleFactor = 1.0f / targetFrame->pageZoomFactor();
4072 4101
4073 TouchInfo& touchInfo = touchInfos[i]; 4102 TouchInfo& touchInfo = touchInfos[i];
4074 touchInfo.point = point; 4103 touchInfo.point = point;
4075 touchInfo.touchTarget = touchTarget; 4104 touchInfo.touchTarget = touchTarget;
4076 touchInfo.targetFrame = targetFrame; 4105 touchInfo.targetFrame = targetFrame;
4077 touchInfo.adjustedPagePoint = pagePoint.scaledBy(scaleFactor); 4106 touchInfo.adjustedPagePoint = pagePoint.scaledBy(scaleFactor);
4078 touchInfo.adjustedRadius = point.radius().scaledBy(scaleFactor); 4107 touchInfo.adjustedRadius = point.radius().scaledBy(scaleFactor);
4079 touchInfo.knownTarget = knownTarget; 4108 touchInfo.knownTarget = knownTarget;
4080 touchInfo.consumed = false; 4109 touchInfo.consumed = false;
4110 touchInfo.region = regionID;
4081 } 4111 }
4082 4112
4083 if (!m_inPointerCanceledState) { 4113 if (!m_inPointerCanceledState) {
4084 dispatchPointerEvents(event, touchInfos); 4114 dispatchPointerEvents(event, touchInfos);
4085 // Note that the disposition of any pointer events affects only the gene ration of touch 4115 // Note that the disposition of any pointer events affects only the gene ration of touch
4086 // events. If all pointer events were handled (and hence no touch events were fired), that 4116 // events. If all pointer events were handled (and hence no touch events were fired), that
4087 // is still equivalent to the touch events going unhandled because point er event handler 4117 // is still equivalent to the touch events going unhandled because point er event handler
4088 // don't block scroll gesture generation. 4118 // don't block scroll gesture generation.
4089 } 4119 }
4090 4120
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
4175 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4205 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4176 { 4206 {
4177 #if OS(MACOSX) 4207 #if OS(MACOSX)
4178 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4208 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4179 #else 4209 #else
4180 return PlatformEvent::AltKey; 4210 return PlatformEvent::AltKey;
4181 #endif 4211 #endif
4182 } 4212 }
4183 4213
4184 } // namespace blink 4214 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698