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

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: changed failing tests to use eventsender Created 5 years, 8 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer) 100 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer)
101 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable (), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in itializer.screenY()), 101 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable (), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in itializer.screenY()),
102 IntPoint(0 /* pageX */, 0 /* pageY */), 102 IntPoint(0 /* pageX */, 0 /* pageY */),
103 IntPoint(0 /* movementX */, 0 /* movementY */), 103 IntPoint(0 /* movementX */, 0 /* movementY */),
104 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */) 104 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */)
105 , m_button(initializer.button() == (unsigned short)-1 ? 0 : initializer.butt on()) 105 , m_button(initializer.button() == (unsigned short)-1 ? 0 : initializer.butt on())
106 , m_buttons(initializer.buttons()) 106 , m_buttons(initializer.buttons())
107 , m_buttonDown(initializer.button() != (unsigned short)-1) 107 , m_buttonDown(initializer.button() != (unsigned short)-1)
108 , m_relatedTarget(initializer.relatedTarget()) 108 , m_relatedTarget(initializer.relatedTarget())
109 , m_dataTransfer(nullptr) 109 , m_dataTransfer(nullptr)
110 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) 110 , m_syntheticEventType(PlatformMouseEvent::FromScript)
111 { 111 {
112 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); 112 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY()));
113 } 113 }
114 114
115 MouseEvent::~MouseEvent() 115 MouseEvent::~MouseEvent()
116 { 116 {
117 } 117 }
118 118
119 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) 119 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers)
120 { 120 {
(...skipping 21 matching lines...) Expand all
142 142
143 m_screenLocation = IntPoint(screenX, screenY); 143 m_screenLocation = IntPoint(screenX, screenY);
144 m_ctrlKey = ctrlKey; 144 m_ctrlKey = ctrlKey;
145 m_altKey = altKey; 145 m_altKey = altKey;
146 m_shiftKey = shiftKey; 146 m_shiftKey = shiftKey;
147 m_metaKey = metaKey; 147 m_metaKey = metaKey;
148 m_button = button == (unsigned short)-1 ? 0 : button; 148 m_button = button == (unsigned short)-1 ? 0 : button;
149 m_buttons = buttons; 149 m_buttons = buttons;
150 m_buttonDown = button != (unsigned short)-1; 150 m_buttonDown = button != (unsigned short)-1;
151 m_relatedTarget = relatedTarget; 151 m_relatedTarget = relatedTarget;
152 m_syntheticEventType = PlatformMouseEvent::FromScript;
152 153
153 initCoordinates(IntPoint(clientX, clientY)); 154 initCoordinates(IntPoint(clientX, clientY));
154 155
155 // FIXME: m_isSimulated is not set to false here. 156 // FIXME: m_isSimulated is not set to false here.
156 // FIXME: m_dataTransfer is not set to nullptr here. 157 // FIXME: m_dataTransfer is not set to nullptr here.
157 } 158 }
158 159
159 const AtomicString& MouseEvent::interfaceName() const 160 const AtomicString& MouseEvent::interfaceName() const
160 { 161 {
161 return EventNames::MouseEvent; 162 return EventNames::MouseEvent;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 m_screenLocation = mouseEvent->screenLocation(); 235 m_screenLocation = mouseEvent->screenLocation();
235 initCoordinates(mouseEvent->clientLocation()); 236 initCoordinates(mouseEvent->clientLocation());
236 } 237 }
237 } 238 }
238 239
239 DEFINE_TRACE(SimulatedMouseEvent) 240 DEFINE_TRACE(SimulatedMouseEvent)
240 { 241 {
241 MouseEvent::trace(visitor); 242 MouseEvent::trace(visitor);
242 } 243 }
243 244
244 PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::c reate(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent, MouseEventType mouseEventTy pe) 245 PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::c reate(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent)
245 { 246 {
246 return adoptRefWillBeNoop(new MouseEventDispatchMediator(mouseEvent, mouseEv entType)); 247 return adoptRefWillBeNoop(new MouseEventDispatchMediator(mouseEvent));
247 } 248 }
248 249
249 MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<Mo useEvent> mouseEvent, MouseEventType mouseEventType) 250 MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<Mo useEvent> mouseEvent)
250 : EventDispatchMediator(mouseEvent), m_mouseEventType(mouseEventType) 251 : EventDispatchMediator(mouseEvent)
251 { 252 {
252 } 253 }
253 254
254 MouseEvent& MouseEventDispatchMediator::event() const 255 MouseEvent& MouseEventDispatchMediator::event() const
255 { 256 {
256 return toMouseEvent(EventDispatchMediator::event()); 257 return toMouseEvent(EventDispatchMediator::event());
257 } 258 }
258 259
259 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher& dispatcher) cons t 260 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher& dispatcher) cons t
260 { 261 {
261 if (isSyntheticMouseEvent()) { 262 if (event().fromScript()) {
262 event().eventPath().adjustForRelatedTarget(dispatcher.node(), event().re latedTarget()); 263 event().eventPath().adjustForRelatedTarget(dispatcher.node(), event().re latedTarget());
263 return dispatcher.dispatch(); 264 return dispatcher.dispatch();
264 } 265 }
265 266
266 if (isDisabledFormControl(&dispatcher.node())) 267 if (isDisabledFormControl(&dispatcher.node()))
267 return false; 268 return false;
268 269
269 if (event().type().isEmpty()) 270 if (event().type().isEmpty())
270 return true; // Shouldn't happen. 271 return true; // Shouldn't happen.
271 272
(...skipping 18 matching lines...) Expand all
290 event().button(), relatedTarget, event().buttons()); 291 event().button(), relatedTarget, event().buttons());
291 if (event().defaultHandled()) 292 if (event().defaultHandled())
292 doubleClickEvent->setDefaultHandled(); 293 doubleClickEvent->setDefaultHandled();
293 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent)); 294 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent));
294 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) 295 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ())
295 return false; 296 return false;
296 return !swallowEvent; 297 return !swallowEvent;
297 } 298 }
298 299
299 } // namespace blink 300 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698