OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) | 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) | 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 22 matching lines...) Expand all Loading... | |
33 MouseEventInit::MouseEventInit() | 33 MouseEventInit::MouseEventInit() |
34 : screenX(0) | 34 : screenX(0) |
35 , screenY(0) | 35 , screenY(0) |
36 , clientX(0) | 36 , clientX(0) |
37 , clientY(0) | 37 , clientY(0) |
38 , ctrlKey(false) | 38 , ctrlKey(false) |
39 , altKey(false) | 39 , altKey(false) |
40 , shiftKey(false) | 40 , shiftKey(false) |
41 , metaKey(false) | 41 , metaKey(false) |
42 , button(0) | 42 , button(0) |
43 , buttons(0) | |
43 , relatedTarget(nullptr) | 44 , relatedTarget(nullptr) |
44 { | 45 { |
45 } | 46 } |
46 | 47 |
47 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, const MouseEventInit& initializer) | 48 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, const MouseEventInit& initializer) |
48 { | 49 { |
49 return adoptRefWillBeNoop(new MouseEvent(type, initializer)); | 50 return adoptRefWillBeNoop(new MouseEvent(type, initializer)); |
50 } | 51 } |
51 | 52 |
52 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget) | 53 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget) |
53 { | 54 { |
54 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt on); | 55 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt on); |
55 | 56 |
56 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT ype == EventTypeNames::mouseleave; | 57 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT ype == EventTypeNames::mouseleave; |
57 bool isCancelable = !isMouseEnterOrLeave; | 58 bool isCancelable = !isMouseEnterOrLeave; |
58 bool isBubbling = !isMouseEnterOrLeave; | 59 bool isBubbling = !isMouseEnterOrLeave; |
59 | 60 |
61 unsigned short buttons = 0; | |
62 if (eventType != EventTypeNames::contextmenu) | |
Rick Byers
2014/11/28 17:36:02
why do you need to special case contextmenu here?
zino
2014/12/03 15:47:15
This was for asking question to you.
Done.
| |
63 buttons = platformModifiersToButtons(event.modifiers()); | |
64 | |
60 return MouseEvent::create( | 65 return MouseEvent::create( |
61 eventType, isBubbling, isCancelable, view, | 66 eventType, isBubbling, isCancelable, view, |
62 detail, event.globalPosition().x(), event.globalPosition().y(), event.po sition().x(), event.position().y(), | 67 detail, event.globalPosition().x(), event.globalPosition().y(), event.po sition().x(), event.position().y(), |
63 event.movementDelta().x(), event.movementDelta().y(), | 68 event.movementDelta().x(), event.movementDelta().y(), |
64 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even t.button(), | 69 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even t.button(), buttons, |
65 relatedTarget, nullptr, false, event.syntheticEventType()); | 70 relatedTarget, nullptr, false, event.syntheticEventType()); |
66 } | 71 } |
67 | 72 |
68 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, | 73 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, |
69 int detail, int screenX, int screenY, int pageX, int pageY, | 74 int detail, int screenX, int screenY, int pageX, int pageY, |
70 int movementX, int movementY, | 75 int movementX, int movementY, |
71 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short butto n, | 76 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
77 unsigned short button, unsigned short buttons, | |
72 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<Da taTransfer> dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticEventTy pe syntheticEventType) | 78 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<Da taTransfer> dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticEventTy pe syntheticEventType) |
73 { | 79 { |
74 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view, | 80 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view, |
75 detail, screenX, screenY, pageX, pageY, | 81 detail, screenX, screenY, pageX, pageY, |
76 movementX, movementY, | 82 movementX, movementY, |
77 ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, dataTransfer, isSimulated, syntheticEventType)); | 83 ctrlKey, altKey, shiftKey, metaKey, button, buttons, |
84 relatedTarget, dataTransfer, isSimulated, syntheticEventType)); | |
78 } | 85 } |
79 | 86 |
80 MouseEvent::MouseEvent() | 87 MouseEvent::MouseEvent() |
81 : m_button(0) | 88 : m_button(0) |
89 , m_buttons(0) | |
82 , m_buttonDown(false) | 90 , m_buttonDown(false) |
83 { | 91 { |
84 } | 92 } |
85 | 93 |
86 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance lable, PassRefPtrWillBeRawPtr<AbstractView> view, | 94 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance lable, PassRefPtrWillBeRawPtr<AbstractView> view, |
87 int detail, int screenX, int screenY, int pageX, int pageY, | 95 int detail, int screenX, int screenY, int pageX, int pageY, |
88 int movementX, int movementY, | 96 int movementX, int movementY, |
89 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, | 97 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
90 unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, | 98 unsigned short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventT arget> relatedTarget, |
91 PassRefPtrWillBeRawPtr<DataTransfer> dataTransfer, bool isSimulated, Platfor mMouseEvent::SyntheticEventType syntheticEventType) | 99 PassRefPtrWillBeRawPtr<DataTransfer> dataTransfer, bool isSimulated, Platfor mMouseEvent::SyntheticEventType syntheticEventType) |
92 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY), | 100 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY), |
93 IntPoint(pageX, pageY), | 101 IntPoint(pageX, pageY), |
94 IntPoint(movementX, movementY), | 102 IntPoint(movementX, movementY), |
95 ctrlKey, altKey, shiftKey, metaKey, isSimulated) | 103 ctrlKey, altKey, shiftKey, metaKey, isSimulated) |
96 , m_button(button == (unsigned short)-1 ? 0 : button) | 104 , m_button(button == (unsigned short)-1 ? 0 : button) |
105 , m_buttons(buttons) | |
97 , m_buttonDown(button != (unsigned short)-1) | 106 , m_buttonDown(button != (unsigned short)-1) |
98 , m_relatedTarget(relatedTarget) | 107 , m_relatedTarget(relatedTarget) |
99 , m_dataTransfer(dataTransfer) | 108 , m_dataTransfer(dataTransfer) |
100 , m_syntheticEventType(syntheticEventType) | 109 , m_syntheticEventType(syntheticEventType) |
101 { | 110 { |
102 } | 111 } |
103 | 112 |
104 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer) | 113 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer) |
105 : MouseRelatedEvent(eventType, initializer.bubbles, initializer.cancelable, initializer.view, initializer.detail, IntPoint(initializer.screenX, initializer. screenY), | 114 : MouseRelatedEvent(eventType, initializer.bubbles, initializer.cancelable, initializer.view, initializer.detail, IntPoint(initializer.screenX, initializer. screenY), |
106 IntPoint(0 /* pageX */, 0 /* pageY */), | 115 IntPoint(0 /* pageX */, 0 /* pageY */), |
107 IntPoint(0 /* movementX */, 0 /* movementY */), | 116 IntPoint(0 /* movementX */, 0 /* movementY */), |
108 initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializ er.metaKey, false /* isSimulated */) | 117 initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializ er.metaKey, false /* isSimulated */) |
109 , m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button ) | 118 , m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button ) |
119 , m_buttons(initializer.buttons) | |
110 , m_buttonDown(initializer.button != (unsigned short)-1) | 120 , m_buttonDown(initializer.button != (unsigned short)-1) |
111 , m_relatedTarget(initializer.relatedTarget) | 121 , m_relatedTarget(initializer.relatedTarget) |
112 , m_dataTransfer(nullptr) | 122 , m_dataTransfer(nullptr) |
113 { | 123 { |
114 initCoordinates(IntPoint(initializer.clientX, initializer.clientY)); | 124 initCoordinates(IntPoint(initializer.clientX, initializer.clientY)); |
115 } | 125 } |
116 | 126 |
117 MouseEvent::~MouseEvent() | 127 MouseEvent::~MouseEvent() |
118 { | 128 { |
119 } | 129 } |
120 | 130 |
131 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) | |
132 { | |
133 unsigned short buttons = 0; | |
134 | |
135 if (modifiers & PlatformEvent::LeftButtonDown) | |
136 buttons |= 1; | |
137 if (modifiers & PlatformEvent::RightButtonDown) | |
138 buttons |= 2; | |
139 if (modifiers & PlatformEvent::MiddleButtonDown) | |
140 buttons |= 4; | |
141 | |
142 return buttons; | |
143 } | |
144 | |
121 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool c ancelable, PassRefPtrWillBeRawPtr<AbstractView> view, | 145 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool c ancelable, PassRefPtrWillBeRawPtr<AbstractView> view, |
122 int detail, int screenX, int screenY, int client X, int clientY, | 146 int detail, int screenX, int screenY, int client X, int clientY, |
123 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey, | 147 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey, |
124 unsigned short button, PassRefPtrWillBeRawPtr<Ev entTarget> relatedTarget) | 148 unsigned short button, PassRefPtrWillBeRawPtr<Ev entTarget> relatedTarget, unsigned short buttons) |
125 { | 149 { |
126 if (dispatched()) | 150 if (dispatched()) |
127 return; | 151 return; |
128 | 152 |
129 initUIEvent(type, canBubble, cancelable, view, detail); | 153 initUIEvent(type, canBubble, cancelable, view, detail); |
130 | 154 |
131 m_screenLocation = IntPoint(screenX, screenY); | 155 m_screenLocation = IntPoint(screenX, screenY); |
132 m_ctrlKey = ctrlKey; | 156 m_ctrlKey = ctrlKey; |
133 m_altKey = altKey; | 157 m_altKey = altKey; |
134 m_shiftKey = shiftKey; | 158 m_shiftKey = shiftKey; |
135 m_metaKey = metaKey; | 159 m_metaKey = metaKey; |
136 m_button = button == (unsigned short)-1 ? 0 : button; | 160 m_button = button == (unsigned short)-1 ? 0 : button; |
137 m_buttonDown = button != (unsigned short)-1; | 161 m_buttonDown = button != (unsigned short)-1; |
138 m_relatedTarget = relatedTarget; | 162 m_relatedTarget = relatedTarget; |
163 m_buttons = buttons; | |
139 | 164 |
140 initCoordinates(IntPoint(clientX, clientY)); | 165 initCoordinates(IntPoint(clientX, clientY)); |
141 | 166 |
142 // FIXME: m_isSimulated is not set to false here. | 167 // FIXME: m_isSimulated is not set to false here. |
143 // FIXME: m_dataTransfer is not set to nullptr here. | 168 // FIXME: m_dataTransfer is not set to nullptr here. |
144 } | 169 } |
145 | 170 |
146 const AtomicString& MouseEvent::interfaceName() const | 171 const AtomicString& MouseEvent::interfaceName() const |
147 { | 172 { |
148 return EventNames::MouseEvent; | 173 return EventNames::MouseEvent; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 PassRefPtrWillBeRawPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const At omicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWill BeRawPtr<Event> underlyingEvent) | 223 PassRefPtrWillBeRawPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const At omicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWill BeRawPtr<Event> underlyingEvent) |
199 { | 224 { |
200 return adoptRefWillBeNoop(new SimulatedMouseEvent(eventType, view, underlyin gEvent)); | 225 return adoptRefWillBeNoop(new SimulatedMouseEvent(eventType, view, underlyin gEvent)); |
201 } | 226 } |
202 | 227 |
203 SimulatedMouseEvent::~SimulatedMouseEvent() | 228 SimulatedMouseEvent::~SimulatedMouseEvent() |
204 { | 229 { |
205 } | 230 } |
206 | 231 |
207 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP trWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent ) | 232 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefP trWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent ) |
208 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, 0, | 233 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, 0, 0, |
209 nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) | 234 nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) |
210 { | 235 { |
211 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve nt.get())) { | 236 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEve nt.get())) { |
212 m_ctrlKey = keyStateEvent->ctrlKey(); | 237 m_ctrlKey = keyStateEvent->ctrlKey(); |
213 m_altKey = keyStateEvent->altKey(); | 238 m_altKey = keyStateEvent->altKey(); |
214 m_shiftKey = keyStateEvent->shiftKey(); | 239 m_shiftKey = keyStateEvent->shiftKey(); |
215 m_metaKey = keyStateEvent->metaKey(); | 240 m_metaKey = keyStateEvent->metaKey(); |
216 } | 241 } |
217 setUnderlyingEvent(underlyingEvent); | 242 setUnderlyingEvent(underlyingEvent); |
218 | 243 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented() ; | 290 bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented() ; |
266 | 291 |
267 if (event()->type() != EventTypeNames::click || event()->detail() != 2) | 292 if (event()->type() != EventTypeNames::click || event()->detail() != 2) |
268 return !swallowEvent; | 293 return !swallowEvent; |
269 | 294 |
270 // Special case: If it's a double click event, we also send the dblclick eve nt. This is not part | 295 // Special case: If it's a double click event, we also send the dblclick eve nt. This is not part |
271 // of the DOM specs, but is used for compatibility with the ondblclick="" at tribute. This is treated | 296 // of the DOM specs, but is used for compatibility with the ondblclick="" at tribute. This is treated |
272 // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same. | 297 // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same. |
273 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); | 298 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); |
274 doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event()->bubbles( ), event()->cancelable(), event()->view(), | 299 doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event()->bubbles( ), event()->cancelable(), event()->view(), |
275 event()->detail(), event()->screenX(), even t()->screenY(), event()->clientX(), event()->clientY(), | 300 event()->detail(), event()->screenX(), event()->screenY(), event()->clie ntX(), event()->clientY(), |
276 event()->ctrlKey(), event()->altKey(), even t()->shiftKey(), event()->metaKey(), | 301 event()->ctrlKey(), event()->altKey(), event()->shiftKey(), event()->met aKey(), |
277 event()->button(), relatedTarget); | 302 event()->button(), relatedTarget, event()->buttons()); |
278 if (event()->defaultHandled()) | 303 if (event()->defaultHandled()) |
279 doubleClickEvent->setDefaultHandled(); | 304 doubleClickEvent->setDefaultHandled(); |
280 EventDispatcher::dispatchEvent(dispatcher->node(), MouseEventDispatchMediato r::create(doubleClickEvent)); | 305 EventDispatcher::dispatchEvent(dispatcher->node(), MouseEventDispatchMediato r::create(doubleClickEvent)); |
281 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) | 306 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) |
282 return false; | 307 return false; |
283 return !swallowEvent; | 308 return !swallowEvent; |
284 } | 309 } |
285 | 310 |
286 } // namespace blink | 311 } // namespace blink |
OLD | NEW |