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

Side by Side Diff: Source/core/events/MouseEvent.cpp

Issue 1174683004: Populates sourceDevice attribute into MouseEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add initinternal Created 5 years, 6 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
« no previous file with comments | « Source/core/events/MouseEvent.h ('k') | Source/core/events/MouseRelatedEvent.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) 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 16 matching lines...) Expand all
27 #include "bindings/core/v8/ScriptState.h" 27 #include "bindings/core/v8/ScriptState.h"
28 #include "core/clipboard/DataTransfer.h" 28 #include "core/clipboard/DataTransfer.h"
29 #include "core/dom/Element.h" 29 #include "core/dom/Element.h"
30 #include "core/events/EventDispatcher.h" 30 #include "core/events/EventDispatcher.h"
31 #include "platform/PlatformMouseEvent.h" 31 #include "platform/PlatformMouseEvent.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(ScriptState* scriptState, const AtomicString& type, const MouseEventInit& initializer) 35 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(ScriptState* scriptState, const AtomicString& type, const MouseEventInit& initializer)
36 { 36 {
37 if (scriptState->world().isIsolatedWorld()) 37 if (scriptState && scriptState->world().isIsolatedWorld())
38 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey() , initializer.altKey(), initializer.shiftKey(), initializer.metaKey()); 38 UIEventWithKeyState::didCreateEventInIsolatedWorld(initializer.ctrlKey() , initializer.altKey(), initializer.shiftKey(), initializer.metaKey());
39 return adoptRefWillBeNoop(new MouseEvent(type, initializer)); 39 return adoptRefWillBeNoop(new MouseEvent(type, initializer));
40 } 40 }
41 41
42 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget) 42 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT ype, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget)
43 { 43 {
44 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt on); 44 ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButt on);
45 45
46 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT ype == EventTypeNames::mouseleave; 46 bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventT ype == EventTypeNames::mouseleave;
47 bool isCancelable = !isMouseEnterOrLeave; 47 bool isCancelable = !isMouseEnterOrLeave;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance lable, PassRefPtrWillBeRawPtr<AbstractView> view, 82 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance lable, PassRefPtrWillBeRawPtr<AbstractView> view,
83 int detail, int screenX, int screenY, int windowX, int windowY, 83 int detail, int screenX, int screenY, int windowX, int windowY,
84 int movementX, int movementY, 84 int movementX, int movementY,
85 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, 85 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
86 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re latedTarget, 86 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re latedTarget,
87 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE ventType syntheticEventType, 87 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE ventType syntheticEventType,
88 double uiCreateTime) 88 double uiCreateTime)
89 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY), 89 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY),
90 IntPoint(windowX, windowY), 90 IntPoint(windowX, windowY),
91 IntPoint(movementX, movementY), 91 IntPoint(movementX, movementY),
92 ctrlKey, altKey, shiftKey, metaKey, isSimulated) 92 ctrlKey, altKey, shiftKey, metaKey, isSimulated,
93 syntheticEventType == PlatformMouseEvent::FromTouch ? InputDevice::fires TouchEventsInputDevice() : InputDevice::doesntFireTouchEventsInputDevice())
93 , m_button(button) 94 , m_button(button)
94 , m_buttons(buttons) 95 , m_buttons(buttons)
95 , m_relatedTarget(relatedTarget) 96 , m_relatedTarget(relatedTarget)
96 , m_dataTransfer(dataTransfer) 97 , m_dataTransfer(dataTransfer)
97 , m_syntheticEventType(syntheticEventType) 98 , m_syntheticEventType(syntheticEventType)
98 { 99 {
99 setUICreateTime(uiCreateTime); 100 setUICreateTime(uiCreateTime);
100 } 101 }
101 102
102 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer) 103 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer)
103 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable (), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in itializer.screenY()), 104 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable (), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in itializer.screenY()),
104 IntPoint(0 /* pageX */, 0 /* pageY */), 105 IntPoint(0 /* pageX */, 0 /* pageY */),
105 IntPoint(initializer.movementX(), initializer.movementY()), 106 IntPoint(initializer.movementX(), initializer.movementY()),
106 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */) 107 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */, initializer.sourceDevice())
107 , m_button(initializer.button()) 108 , m_button(initializer.button())
108 , m_buttons(initializer.buttons()) 109 , m_buttons(initializer.buttons())
109 , m_relatedTarget(initializer.relatedTarget()) 110 , m_relatedTarget(initializer.relatedTarget())
110 , m_dataTransfer(nullptr) 111 , m_dataTransfer(nullptr)
111 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) 112 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable)
112 { 113 {
113 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); 114 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY()));
114 } 115 }
115 116
116 MouseEvent::~MouseEvent() 117 MouseEvent::~MouseEvent()
(...skipping 12 matching lines...) Expand all
129 buttons |= 4; 130 buttons |= 4;
130 131
131 return buttons; 132 return buttons;
132 } 133 }
133 134
134 void MouseEvent::initMouseEvent(ScriptState* scriptState, const AtomicString& ty pe, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, 135 void MouseEvent::initMouseEvent(ScriptState* scriptState, const AtomicString& ty pe, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
135 int detail, int screenX, int screenY, int client X, int clientY, 136 int detail, int screenX, int screenY, int client X, int clientY,
136 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey, 137 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey,
137 short button, PassRefPtrWillBeRawPtr<EventTarget > relatedTarget, unsigned short buttons) 138 short button, PassRefPtrWillBeRawPtr<EventTarget > relatedTarget, unsigned short buttons)
138 { 139 {
140 initMouseEventInternal(scriptState, type, canBubble, cancelable, view, detai l, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, butto n, relatedTarget, nullptr, buttons);
141 }
142
143 void MouseEvent::initMouseEventInternal(ScriptState* scriptState, const AtomicSt ring& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView > view,
144 int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey , bool altKey, bool shiftKey, bool metaKey,
145 short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, InputDevice * sourceDevice, unsigned short buttons)
146 {
139 if (dispatched()) 147 if (dispatched())
140 return; 148 return;
141 149
142 if (scriptState && scriptState->world().isIsolatedWorld()) 150 if (scriptState && scriptState->world().isIsolatedWorld())
143 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif tKey, metaKey); 151 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif tKey, metaKey);
144 152
145 initUIEvent(type, canBubble, cancelable, view, detail); 153 initUIEvent(type, canBubble, cancelable, view, detail);
146 154
147 m_screenLocation = IntPoint(screenX, screenY); 155 m_screenLocation = IntPoint(screenX, screenY);
148 m_ctrlKey = ctrlKey; 156 m_ctrlKey = ctrlKey;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 dispatcher.dispatch(); 286 dispatcher.dispatch();
279 bool swallowEvent = event().defaultHandled() || event().defaultPrevented(); 287 bool swallowEvent = event().defaultHandled() || event().defaultPrevented();
280 288
281 if (event().type() != EventTypeNames::click || event().detail() != 2) 289 if (event().type() != EventTypeNames::click || event().detail() != 2)
282 return !swallowEvent; 290 return !swallowEvent;
283 291
284 // Special case: If it's a double click event, we also send the dblclick eve nt. This is not part 292 // Special case: If it's a double click event, we also send the dblclick eve nt. This is not part
285 // of the DOM specs, but is used for compatibility with the ondblclick="" at tribute. This is treated 293 // of the DOM specs, but is used for compatibility with the ondblclick="" at tribute. This is treated
286 // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same. 294 // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
287 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); 295 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create();
288 doubleClickEvent->initMouseEvent(nullptr, EventTypeNames::dblclick, event(). bubbles(), event().cancelable(), event().view(), 296 doubleClickEvent->initMouseEventInternal(nullptr, EventTypeNames::dblclick, event().bubbles(), event().cancelable(), event().view(),
289 event().detail(), event().screenX(), event().screenY(), event().clientX( ), event().clientY(), 297 event().detail(), event().screenX(), event().screenY(), event().clientX( ), event().clientY(),
290 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey (), 298 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey (),
291 event().button(), relatedTarget, event().buttons()); 299 event().button(), relatedTarget, event().sourceDevice(), event().buttons ());
292 if (event().defaultHandled()) 300 if (event().defaultHandled())
293 doubleClickEvent->setDefaultHandled(); 301 doubleClickEvent->setDefaultHandled();
294 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent)); 302 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent));
295 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) 303 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ())
296 return false; 304 return false;
297 return !swallowEvent; 305 return !swallowEvent;
298 } 306 }
299 307
300 } // namespace blink 308 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/events/MouseEvent.h ('k') | Source/core/events/MouseRelatedEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698