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

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

Issue 894913002: Prevent default actions for JS-generated mouse events other than click (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: TIL, gclient sync may rebase changes back in time 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/input/EventHandler.cpp » ('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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer) 102 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()), 103 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable (), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in itializer.screenY()),
104 IntPoint(0 /* pageX */, 0 /* pageY */), 104 IntPoint(0 /* pageX */, 0 /* pageY */),
105 IntPoint(initializer.movementX(), initializer.movementY()), 105 IntPoint(initializer.movementX(), initializer.movementY()),
106 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */) 106 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */)
107 , m_button(initializer.button()) 107 , m_button(initializer.button())
108 , m_buttons(initializer.buttons()) 108 , m_buttons(initializer.buttons())
109 , m_relatedTarget(initializer.relatedTarget()) 109 , m_relatedTarget(initializer.relatedTarget())
110 , m_dataTransfer(nullptr) 110 , m_dataTransfer(nullptr)
111 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) 111 , m_syntheticEventType(PlatformMouseEvent::FromScript)
112 { 112 {
113 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); 113 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY()));
114 } 114 }
115 115
116 MouseEvent::~MouseEvent() 116 MouseEvent::~MouseEvent()
117 { 117 {
118 } 118 }
119 119
120 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) 120 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers)
121 { 121 {
(...skipping 23 matching lines...) Expand all
145 initUIEvent(type, canBubble, cancelable, view, detail); 145 initUIEvent(type, canBubble, cancelable, view, detail);
146 146
147 m_screenLocation = IntPoint(screenX, screenY); 147 m_screenLocation = IntPoint(screenX, screenY);
148 m_ctrlKey = ctrlKey; 148 m_ctrlKey = ctrlKey;
149 m_altKey = altKey; 149 m_altKey = altKey;
150 m_shiftKey = shiftKey; 150 m_shiftKey = shiftKey;
151 m_metaKey = metaKey; 151 m_metaKey = metaKey;
152 m_button = button; 152 m_button = button;
153 m_buttons = buttons; 153 m_buttons = buttons;
154 m_relatedTarget = relatedTarget; 154 m_relatedTarget = relatedTarget;
155 m_syntheticEventType = PlatformMouseEvent::FromScript;
155 156
156 initCoordinates(IntPoint(clientX, clientY)); 157 initCoordinates(IntPoint(clientX, clientY));
157 158
158 // FIXME: m_isSimulated is not set to false here. 159 // FIXME: m_isSimulated is not set to false here.
159 // FIXME: m_dataTransfer is not set to nullptr here. 160 // FIXME: m_dataTransfer is not set to nullptr here.
160 } 161 }
161 162
162 const AtomicString& MouseEvent::interfaceName() const 163 const AtomicString& MouseEvent::interfaceName() const
163 { 164 {
164 return EventNames::MouseEvent; 165 return EventNames::MouseEvent;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 m_screenLocation = mouseEvent->screenLocation(); 236 m_screenLocation = mouseEvent->screenLocation();
236 initCoordinates(mouseEvent->clientLocation()); 237 initCoordinates(mouseEvent->clientLocation());
237 } 238 }
238 } 239 }
239 240
240 DEFINE_TRACE(SimulatedMouseEvent) 241 DEFINE_TRACE(SimulatedMouseEvent)
241 { 242 {
242 MouseEvent::trace(visitor); 243 MouseEvent::trace(visitor);
243 } 244 }
244 245
245 PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::c reate(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent, MouseEventType mouseEventTy pe) 246 PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::c reate(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent)
246 { 247 {
247 return adoptRefWillBeNoop(new MouseEventDispatchMediator(mouseEvent, mouseEv entType)); 248 return adoptRefWillBeNoop(new MouseEventDispatchMediator(mouseEvent));
248 } 249 }
249 250
250 MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<Mo useEvent> mouseEvent, MouseEventType mouseEventType) 251 MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<Mo useEvent> mouseEvent)
251 : EventDispatchMediator(mouseEvent), m_mouseEventType(mouseEventType) 252 : EventDispatchMediator(mouseEvent)
252 { 253 {
253 } 254 }
254 255
255 MouseEvent& MouseEventDispatchMediator::event() const 256 MouseEvent& MouseEventDispatchMediator::event() const
256 { 257 {
257 return toMouseEvent(EventDispatchMediator::event()); 258 return toMouseEvent(EventDispatchMediator::event());
258 } 259 }
259 260
260 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher& dispatcher) cons t 261 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher& dispatcher) cons t
261 { 262 {
262 if (isSyntheticMouseEvent()) { 263 if (event().fromScript()) {
263 event().eventPath().adjustForRelatedTarget(dispatcher.node(), event().re latedTarget()); 264 event().eventPath().adjustForRelatedTarget(dispatcher.node(), event().re latedTarget());
264 return dispatcher.dispatch(); 265 return dispatcher.dispatch();
265 } 266 }
266 267
267 if (isDisabledFormControl(&dispatcher.node())) 268 if (isDisabledFormControl(&dispatcher.node()))
268 return false; 269 return false;
269 270
270 if (event().type().isEmpty()) 271 if (event().type().isEmpty())
271 return true; // Shouldn't happen. 272 return true; // Shouldn't happen.
272 273
(...skipping 18 matching lines...) Expand all
291 event().button(), relatedTarget, event().buttons()); 292 event().button(), relatedTarget, event().buttons());
292 if (event().defaultHandled()) 293 if (event().defaultHandled())
293 doubleClickEvent->setDefaultHandled(); 294 doubleClickEvent->setDefaultHandled();
294 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent)); 295 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent));
295 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) 296 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ())
296 return false; 297 return false;
297 return !swallowEvent; 298 return !swallowEvent;
298 } 299 }
299 300
300 } // namespace blink 301 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/events/MouseEvent.h ('k') | Source/core/input/EventHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698