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

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

Issue 2255323004: Create MouseEventManager and EventHandlingUtil (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 4 years, 3 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/input/MouseEventManager.h"
6
7 #include "core/dom/ElementTraversal.h"
8 #include "core/events/MouseEvent.h"
9 #include "core/html/HTMLCanvasElement.h"
10 #include "core/input/EventHandlingUtil.h"
11
12 namespace blink {
13
14 namespace {
15
16 PlatformMouseEvent mouseEventWithRegion(Node* node, const PlatformMouseEvent& mo useEvent)
17 {
18 if (!node->isElementNode())
19 return mouseEvent;
20
21 Element* element = toElement(node);
22 if (!element->isInCanvasSubtree())
23 return mouseEvent;
24
25 HTMLCanvasElement* canvas = Traversal<HTMLCanvasElement>::firstAncestorOrSel f(*element);
26 // In this case, the event target is canvas and mouse rerouting doesn't happ en.
27 if (canvas == element)
28 return mouseEvent;
29 String region = canvas->getIdFromControl(element);
30 PlatformMouseEvent newMouseEvent = mouseEvent;
31 newMouseEvent.setRegion(region);
32 return newMouseEvent;
33 }
34
35 } // namespace
36
37 MouseEventManager::MouseEventBoundaryEventDispatcher::MouseEventBoundaryEventDis patcher(
38 MouseEventManager* mouseEventManager,
39 const PlatformMouseEvent* platformMouseEvent,
40 EventTarget* exitedTarget)
41 : m_mouseEventManager(mouseEventManager)
42 , m_platformMouseEvent(platformMouseEvent)
43 , m_exitedTarget(exitedTarget)
44 {
45 }
46
47 void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchOut(
48 EventTarget* target, EventTarget* relatedTarget)
49 {
50 dispatch(target, relatedTarget, EventTypeNames::mouseout, mouseEventWithRegi on(m_exitedTarget->toNode(), *m_platformMouseEvent), false);
51 }
52
53 void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchOver(
54 EventTarget* target, EventTarget* relatedTarget)
55 {
56 dispatch(target, relatedTarget, EventTypeNames::mouseover, *m_platformMouseE vent, false);
57 }
58
59 void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchLeave(
60 EventTarget* target, EventTarget* relatedTarget, bool checkForListener)
61 {
62 dispatch(target, relatedTarget, EventTypeNames::mouseleave, mouseEventWithRe gion(m_exitedTarget->toNode(), *m_platformMouseEvent), checkForListener);
63 }
64
65 void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchEnter(
66 EventTarget* target, EventTarget* relatedTarget, bool checkForListener)
67 {
68 dispatch(target, relatedTarget, EventTypeNames::mouseenter, *m_platformMouse Event, checkForListener);
69 }
70
71 AtomicString MouseEventManager::MouseEventBoundaryEventDispatcher::getLeaveEvent ()
72 {
73 return EventTypeNames::mouseleave;
74 }
75
76 AtomicString MouseEventManager::MouseEventBoundaryEventDispatcher::getEnterEvent ()
77 {
78 return EventTypeNames::mouseenter;
79 }
80
81 void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatch(
82 EventTarget* target, EventTarget* relatedTarget, const AtomicString& type,
83 const PlatformMouseEvent& platformMouseEvent, bool checkForListener)
84 {
85 m_mouseEventManager->dispatchMouseEvent(target, type, platformMouseEvent,
86 relatedTarget, 0, checkForListener);
87 }
88
89 void MouseEventManager::sendBoundaryEvents(
90 EventTarget* exitedTarget,
91 EventTarget* enteredTarget,
92 const PlatformMouseEvent& mousePlatformEvent)
93 {
94 MouseEventBoundaryEventDispatcher boundaryEventDispatcher(this, &mousePlatfo rmEvent, exitedTarget);
95 boundaryEventDispatcher.sendBoundaryEvents(exitedTarget, enteredTarget);
96 }
97
98 WebInputEventResult MouseEventManager::dispatchMouseEvent(
99 EventTarget* target,
100 const AtomicString& mouseEventType,
101 const PlatformMouseEvent& mouseEvent,
102 EventTarget* relatedTarget,
103 int detail,
104 bool checkForListener)
105 {
106 if (target && target->toNode()
107 && (!checkForListener || target->hasEventListeners(mouseEventType))) {
108 Node* targetNode = target->toNode();
109 MouseEvent* event = MouseEvent::create(mouseEventType,
110 targetNode->document().domWindow(), mouseEvent, detail,
111 relatedTarget ? relatedTarget->toNode() : nullptr);
112 DispatchEventResult dispatchResult = target->dispatchEvent(event);
113 return EventHandlingUtil::toWebInputEventResult(dispatchResult);
114 }
115 return WebInputEventResult::NotHandled;
116 }
117
118 MouseEventManager::MouseEventManager(LocalFrame* frame)
119 : m_frame(frame)
120 {
121 clear();
122 }
123
124 void MouseEventManager::clear()
125 {
126 }
127
128 DEFINE_TRACE(MouseEventManager)
129 {
130 visitor->trace(m_frame);
131 visitor->trace(m_nodeUnderMouse);
132 }
133
134 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/MouseEventManager.h ('k') | third_party/WebKit/Source/core/input/PointerEventManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698