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

Side by Side Diff: sky/engine/core/events/MouseEvent.cpp

Issue 870073003: Remove mouse events from Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 /*
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include "sky/engine/config.h"
24 #include "sky/engine/core/events/MouseEvent.h"
25
26 #include "sky/engine/core/dom/Element.h"
27 #include "sky/engine/core/events/EventDispatcher.h"
28 #include "sky/engine/platform/PlatformMouseEvent.h"
29
30 namespace blink {
31
32 MouseEventInit::MouseEventInit()
33 : screenX(0)
34 , screenY(0)
35 , clientX(0)
36 , clientY(0)
37 , ctrlKey(false)
38 , altKey(false)
39 , shiftKey(false)
40 , metaKey(false)
41 , button(0)
42 , relatedTarget(nullptr)
43 {
44 }
45
46 PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& type, const MouseE ventInit& initializer)
47 {
48 return adoptRef(new MouseEvent(type, initializer));
49 }
50
51 PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& eventType, PassRef Ptr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtr< Node> relatedTarget)
52 {
53 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt on);
54
55 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT ype == EventTypeNames::mouseleave;
56 bool isCancelable = !isMouseEnterOrLeave;
57 bool isBubbling = !isMouseEnterOrLeave;
58
59 return MouseEvent::create(
60 eventType, isBubbling, isCancelable, view,
61 detail, event.globalPosition().x(), event.globalPosition().y(), event.po sition().x(), event.position().y(),
62 event.movementDelta().x(), event.movementDelta().y(),
63 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even t.button(),
64 relatedTarget, false, event.syntheticEventType());
65 }
66
67 PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubb le, bool cancelable, PassRefPtr<AbstractView> view,
68 int detail, int screenX, int screenY, int pageX, int pageY,
69 int movementX, int movementY,
70 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short butto n,
71 PassRefPtr<EventTarget> relatedTarget, bool isSimulated, PlatformMouseEvent: :SyntheticEventType syntheticEventType)
72 {
73 return adoptRef(new MouseEvent(type, canBubble, cancelable, view,
74 detail, screenX, screenY, pageX, pageY,
75 movementX, movementY,
76 ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, isSimulated, syntheticEventType));
77 }
78
79 MouseEvent::MouseEvent()
80 : m_button(0)
81 , m_buttonDown(false)
82 {
83 }
84
85 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance lable, PassRefPtr<AbstractView> view,
86 int detail, int screenX, int screenY, int pageX, int pageY,
87 int movementX, int movementY,
88 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
89 unsigned short button, PassRefPtr<EventTarget> relatedTarget,
90 bool isSimulated, PlatformMouseEvent::SyntheticEventType syntheticEventType)
91 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY),
92 IntPoint(pageX, pageY),
93 IntPoint(movementX, movementY),
94 ctrlKey, altKey, shiftKey, metaKey, isSimulated)
95 , m_button(button == (unsigned short)-1 ? 0 : button)
96 , m_buttonDown(button != (unsigned short)-1)
97 , m_relatedTarget(relatedTarget)
98 , m_syntheticEventType(syntheticEventType)
99 {
100 }
101
102 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer)
103 : MouseRelatedEvent(eventType, initializer.bubbles, initializer.cancelable, initializer.view, initializer.detail, IntPoint(initializer.screenX, initializer. screenY),
104 IntPoint(0 /* pageX */, 0 /* pageY */),
105 IntPoint(0 /* movementX */, 0 /* movementY */),
106 initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializ er.metaKey, false /* isSimulated */)
107 , m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button )
108 , m_buttonDown(initializer.button != (unsigned short)-1)
109 , m_relatedTarget(initializer.relatedTarget)
110 {
111 initCoordinates(IntPoint(initializer.clientX, initializer.clientY));
112 }
113
114 MouseEvent::~MouseEvent()
115 {
116 }
117
118 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool c ancelable, PassRefPtr<AbstractView> view,
119 int detail, int screenX, int screenY, int client X, int clientY,
120 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey,
121 unsigned short button, PassRefPtr<EventTarget> r elatedTarget)
122 {
123 if (dispatched())
124 return;
125
126 initUIEvent(type, canBubble, cancelable, view, detail);
127
128 m_screenLocation = IntPoint(screenX, screenY);
129 m_ctrlKey = ctrlKey;
130 m_altKey = altKey;
131 m_shiftKey = shiftKey;
132 m_metaKey = metaKey;
133 m_button = button == (unsigned short)-1 ? 0 : button;
134 m_buttonDown = button != (unsigned short)-1;
135 m_relatedTarget = relatedTarget;
136
137 initCoordinates(IntPoint(clientX, clientY));
138
139 // FIXME: m_isSimulated is not set to false here.
140 }
141
142 const AtomicString& MouseEvent::interfaceName() const
143 {
144 return EventNames::MouseEvent;
145 }
146
147 bool MouseEvent::isMouseEvent() const
148 {
149 return true;
150 }
151
152 bool MouseEvent::isDragEvent() const
153 {
154 const AtomicString& t = type();
155 return t == EventTypeNames::dragenter || t == EventTypeNames::dragover || t == EventTypeNames::dragleave || t == EventTypeNames::drop
156 || t == EventTypeNames::dragstart|| t == EventTypeNames::drag || t == EventTypeNames::dragend;
157 }
158
159 int MouseEvent::which() const
160 {
161 // For the DOM, the return values for left, middle and right mouse buttons a re 0, 1, 2, respectively.
162 // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
163 // So we must add 1.
164 if (!m_buttonDown)
165 return 0;
166 return m_button + 1;
167 }
168
169 Node* MouseEvent::toElement() const
170 {
171 // MSIE extension - "the object toward which the user is moving the mouse po inter"
172 if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouselea ve)
173 return relatedTarget() ? relatedTarget()->toNode() : 0;
174
175 return target() ? target()->toNode() : 0;
176 }
177
178 Node* MouseEvent::fromElement() const
179 {
180 // MSIE extension - "object from which activation or the mouse pointer is ex iting during the event" (huh?)
181 if (type() != EventTypeNames::mouseout && type() != EventTypeNames::mouselea ve)
182 return relatedTarget() ? relatedTarget()->toNode() : 0;
183
184 return target() ? target()->toNode() : 0;
185 }
186
187 PassRefPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const AtomicString& eventType, PassRefPtr<AbstractView> view, PassRefPtr<Event> underlyingEvent)
188 {
189 return adoptRef(new SimulatedMouseEvent(eventType, view, underlyingEvent));
190 }
191
192 SimulatedMouseEvent::~SimulatedMouseEvent()
193 {
194 }
195
196 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP tr<AbstractView> view, PassRefPtr<Event> underlyingEvent)
197 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, 0,
198 nullptr, true, PlatformMouseEvent::RealOrIndistinguishable)
199 {
200 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve nt.get())) {
201 m_ctrlKey = keyStateEvent->ctrlKey();
202 m_altKey = keyStateEvent->altKey();
203 m_shiftKey = keyStateEvent->shiftKey();
204 m_metaKey = keyStateEvent->metaKey();
205 }
206 setUnderlyingEvent(underlyingEvent);
207
208 if (this->underlyingEvent() && this->underlyingEvent()->isMouseEvent()) {
209 MouseEvent* mouseEvent = toMouseEvent(this->underlyingEvent());
210 m_screenLocation = mouseEvent->screenLocation();
211 initCoordinates(mouseEvent->clientLocation());
212 }
213 }
214
215 PassRefPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::create(PassRe fPtr<MouseEvent> mouseEvent, MouseEventType mouseEventType)
216 {
217 return adoptRef(new MouseEventDispatchMediator(mouseEvent, mouseEventType));
218 }
219
220 MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtr<MouseEvent> mo useEvent, MouseEventType mouseEventType)
221 : EventDispatchMediator(mouseEvent), m_mouseEventType(mouseEventType)
222 {
223 }
224
225 MouseEvent* MouseEventDispatchMediator::event() const
226 {
227 return toMouseEvent(EventDispatchMediator::event());
228 }
229
230 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) cons t
231 {
232 if (isSyntheticMouseEvent()) {
233 event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()- >relatedTarget());
234 return dispatcher->dispatch();
235 }
236
237 if (event()->type().isEmpty())
238 return true; // Shouldn't happen.
239
240 ASSERT(!event()->target() || event()->target() != event()->relatedTarget());
241
242 EventTarget* relatedTarget = event()->relatedTarget();
243 event()->eventPath().adjustForRelatedTarget(dispatcher->node(), relatedTarge t);
244
245 dispatcher->dispatch();
246 bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented() ;
247
248 if (event()->type() != EventTypeNames::click || event()->detail() != 2)
249 return !swallowEvent;
250
251 // Special case: If it's a double click event, we also send the dblclick eve nt. This is not part
252 // of the DOM specs, but is used for compatibility with the ondblclick="" at tribute. This is treated
253 // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
254 RefPtr<MouseEvent> doubleClickEvent = MouseEvent::create();
255 doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event()->bubbles( ), event()->cancelable(), event()->view(),
256 event()->detail(), event()->screenX(), even t()->screenY(), event()->clientX(), event()->clientY(),
257 event()->ctrlKey(), event()->altKey(), even t()->shiftKey(), event()->metaKey(),
258 event()->button(), relatedTarget);
259 if (event()->defaultHandled())
260 doubleClickEvent->setDefaultHandled();
261 EventDispatcher::dispatchEvent(dispatcher->node(), MouseEventDispatchMediato r::create(doubleClickEvent));
262 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ())
263 return false;
264 return !swallowEvent;
265 }
266
267 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698