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

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: 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
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 278
278 dispatcher.dispatch(); 279 dispatcher.dispatch();
279 bool swallowEvent = event().defaultHandled() || event().defaultPrevented(); 280 bool swallowEvent = event().defaultHandled() || event().defaultPrevented();
280 281
281 if (event().type() != EventTypeNames::click || event().detail() != 2) 282 if (event().type() != EventTypeNames::click || event().detail() != 2)
282 return !swallowEvent; 283 return !swallowEvent;
283 284
284 // Special case: If it's a double click event, we also send the dblclick eve nt. This is not part 285 // 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 286 // 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. 287 // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
287 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(); 288 MouseEventInit eventInitDict;
289 eventInitDict.setSourceDevice(event().sourceDevice());
290 RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create(nullptr , EventTypeNames::dblclick, eventInitDict);
288 doubleClickEvent->initMouseEvent(nullptr, EventTypeNames::dblclick, event(). bubbles(), event().cancelable(), event().view(), 291 doubleClickEvent->initMouseEvent(nullptr, EventTypeNames::dblclick, event(). bubbles(), event().cancelable(), event().view(),
Rick Byers 2015/06/25 03:34:54 nit: You should really be using either an eventIni
lanwei 2015/06/25 19:26:40 Done.
289 event().detail(), event().screenX(), event().screenY(), event().clientX( ), event().clientY(), 292 event().detail(), event().screenX(), event().screenY(), event().clientX( ), event().clientY(),
290 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey (), 293 event().ctrlKey(), event().altKey(), event().shiftKey(), event().metaKey (),
291 event().button(), relatedTarget, event().buttons()); 294 event().button(), relatedTarget, event().buttons());
292 if (event().defaultHandled()) 295 if (event().defaultHandled())
293 doubleClickEvent->setDefaultHandled(); 296 doubleClickEvent->setDefaultHandled();
294 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent)); 297 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent));
295 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) 298 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ())
296 return false; 299 return false;
297 return !swallowEvent; 300 return !swallowEvent;
298 } 301 }
299 302
300 } // namespace blink 303 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698