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

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

Issue 1165693005: Change MouseEvent.button to be 'short' instead of 'unsigned short' (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
« no previous file with comments | « Source/core/events/MouseEvent.h ('k') | Source/core/events/MouseEvent.idl » ('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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 event.movementDelta().x(), event.movementDelta().y(), 53 event.movementDelta().x(), event.movementDelta().y(),
54 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even t.button(), 54 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even t.button(),
55 platformModifiersToButtons(event.modifiers()), 55 platformModifiersToButtons(event.modifiers()),
56 relatedTarget, nullptr, false, event.syntheticEventType(), event.timesta mp()); 56 relatedTarget, nullptr, false, event.syntheticEventType(), event.timesta mp());
57 } 57 }
58 58
59 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, 59 PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
60 int detail, int screenX, int screenY, int windowX, int windowY, 60 int detail, int screenX, int screenY, int windowX, int windowY,
61 int movementX, int movementY, 61 int movementX, int movementY,
62 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, 62 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
63 unsigned short button, unsigned short buttons, 63 short button, unsigned short buttons,
64 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, DataTransfer* dataTransfe r, bool isSimulated, PlatformMouseEvent::SyntheticEventType syntheticEventType, 64 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, DataTransfer* dataTransfe r, bool isSimulated, PlatformMouseEvent::SyntheticEventType syntheticEventType,
65 double uiCreateTime) 65 double uiCreateTime)
66 { 66 {
67 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view, 67 return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view,
68 detail, screenX, screenY, windowX, windowY, 68 detail, screenX, screenY, windowX, windowY,
69 movementX, movementY, 69 movementX, movementY,
70 ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, data Transfer, isSimulated, syntheticEventType, uiCreateTime)); 70 ctrlKey, altKey, shiftKey, metaKey, button, buttons, relatedTarget, data Transfer, isSimulated, syntheticEventType, uiCreateTime));
71 } 71 }
72 72
73 MouseEvent::MouseEvent() 73 MouseEvent::MouseEvent()
74 : m_button(0) 74 : m_button(0)
75 , m_buttons(0) 75 , m_buttons(0)
76 , m_buttonDown(false)
77 , m_relatedTarget(nullptr) 76 , m_relatedTarget(nullptr)
78 , m_dataTransfer(nullptr) 77 , m_dataTransfer(nullptr)
79 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) 78 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable)
80 { 79 {
81 } 80 }
82 81
83 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,
84 int detail, int screenX, int screenY, int windowX, int windowY, 83 int detail, int screenX, int screenY, int windowX, int windowY,
85 int movementX, int movementY, 84 int movementX, int movementY,
86 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, 85 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
87 unsigned short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventT arget> relatedTarget, 86 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re latedTarget,
88 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE ventType syntheticEventType, 87 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE ventType syntheticEventType,
89 double uiCreateTime) 88 double uiCreateTime)
90 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY), 89 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY),
91 IntPoint(windowX, windowY), 90 IntPoint(windowX, windowY),
92 IntPoint(movementX, movementY), 91 IntPoint(movementX, movementY),
93 ctrlKey, altKey, shiftKey, metaKey, isSimulated) 92 ctrlKey, altKey, shiftKey, metaKey, isSimulated)
94 , m_button(button == (unsigned short)-1 ? 0 : button) 93 , m_button(button)
95 , m_buttons(buttons) 94 , m_buttons(buttons)
96 , m_buttonDown(button != (unsigned short)-1)
97 , m_relatedTarget(relatedTarget) 95 , m_relatedTarget(relatedTarget)
98 , m_dataTransfer(dataTransfer) 96 , m_dataTransfer(dataTransfer)
99 , m_syntheticEventType(syntheticEventType) 97 , m_syntheticEventType(syntheticEventType)
100 { 98 {
101 setUICreateTime(uiCreateTime); 99 setUICreateTime(uiCreateTime);
102 } 100 }
103 101
104 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer) 102 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer)
105 : 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()),
106 IntPoint(0 /* pageX */, 0 /* pageY */), 104 IntPoint(0 /* pageX */, 0 /* pageY */),
107 IntPoint(initializer.movementX(), initializer.movementY()), 105 IntPoint(initializer.movementX(), initializer.movementY()),
108 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */) 106 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */)
109 , m_button(initializer.button() == (unsigned short)-1 ? 0 : initializer.butt on()) 107 , m_button(initializer.button())
110 , m_buttons(initializer.buttons()) 108 , m_buttons(initializer.buttons())
111 , m_buttonDown(initializer.button() != (unsigned short)-1)
112 , m_relatedTarget(initializer.relatedTarget()) 109 , m_relatedTarget(initializer.relatedTarget())
113 , m_dataTransfer(nullptr) 110 , m_dataTransfer(nullptr)
114 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) 111 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable)
115 { 112 {
116 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); 113 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY()));
117 } 114 }
118 115
119 MouseEvent::~MouseEvent() 116 MouseEvent::~MouseEvent()
120 { 117 {
121 } 118 }
122 119
123 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) 120 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers)
124 { 121 {
125 unsigned short buttons = 0; 122 unsigned short buttons = 0;
126 123
127 if (modifiers & PlatformEvent::LeftButtonDown) 124 if (modifiers & PlatformEvent::LeftButtonDown)
128 buttons |= 1; 125 buttons |= 1;
129 if (modifiers & PlatformEvent::RightButtonDown) 126 if (modifiers & PlatformEvent::RightButtonDown)
130 buttons |= 2; 127 buttons |= 2;
131 if (modifiers & PlatformEvent::MiddleButtonDown) 128 if (modifiers & PlatformEvent::MiddleButtonDown)
132 buttons |= 4; 129 buttons |= 4;
133 130
134 return buttons; 131 return buttons;
135 } 132 }
136 133
137 void MouseEvent::initMouseEvent(ScriptState* scriptState, const AtomicString& ty pe, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, 134 void MouseEvent::initMouseEvent(ScriptState* scriptState, const AtomicString& ty pe, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
138 int detail, int screenX, int screenY, int client X, int clientY, 135 int detail, int screenX, int screenY, int client X, int clientY,
139 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey, 136 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey,
140 unsigned short button, PassRefPtrWillBeRawPtr<Ev entTarget> relatedTarget, unsigned short buttons) 137 short button, PassRefPtrWillBeRawPtr<EventTarget > relatedTarget, unsigned short buttons)
141 { 138 {
142 if (dispatched()) 139 if (dispatched())
143 return; 140 return;
144 141
145 if (scriptState && scriptState->world().isIsolatedWorld()) 142 if (scriptState && scriptState->world().isIsolatedWorld())
146 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif tKey, metaKey); 143 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif tKey, metaKey);
147 144
148 initUIEvent(type, canBubble, cancelable, view, detail); 145 initUIEvent(type, canBubble, cancelable, view, detail);
149 146
150 m_screenLocation = IntPoint(screenX, screenY); 147 m_screenLocation = IntPoint(screenX, screenY);
151 m_ctrlKey = ctrlKey; 148 m_ctrlKey = ctrlKey;
152 m_altKey = altKey; 149 m_altKey = altKey;
153 m_shiftKey = shiftKey; 150 m_shiftKey = shiftKey;
154 m_metaKey = metaKey; 151 m_metaKey = metaKey;
155 m_button = button == (unsigned short)-1 ? 0 : button; 152 m_button = button;
156 m_buttons = buttons; 153 m_buttons = buttons;
157 m_buttonDown = button != (unsigned short)-1;
158 m_relatedTarget = relatedTarget; 154 m_relatedTarget = relatedTarget;
159 155
160 initCoordinates(IntPoint(clientX, clientY)); 156 initCoordinates(IntPoint(clientX, clientY));
161 157
162 // FIXME: m_isSimulated is not set to false here. 158 // FIXME: m_isSimulated is not set to false here.
163 // FIXME: m_dataTransfer is not set to nullptr here. 159 // FIXME: m_dataTransfer is not set to nullptr here.
164 } 160 }
165 161
166 const AtomicString& MouseEvent::interfaceName() const 162 const AtomicString& MouseEvent::interfaceName() const
167 { 163 {
(...skipping 10 matching lines...) Expand all
178 const AtomicString& t = type(); 174 const AtomicString& t = type();
179 return t == EventTypeNames::dragenter || t == EventTypeNames::dragover || t == EventTypeNames::dragleave || t == EventTypeNames::drop 175 return t == EventTypeNames::dragenter || t == EventTypeNames::dragover || t == EventTypeNames::dragleave || t == EventTypeNames::drop
180 || t == EventTypeNames::dragstart|| t == EventTypeNames::drag || t == EventTypeNames::dragend; 176 || t == EventTypeNames::dragstart|| t == EventTypeNames::drag || t == EventTypeNames::dragend;
181 } 177 }
182 178
183 int MouseEvent::which() const 179 int MouseEvent::which() const
184 { 180 {
185 // For the DOM, the return values for left, middle and right mouse buttons a re 0, 1, 2, respectively. 181 // For the DOM, the return values for left, middle and right mouse buttons a re 0, 1, 2, respectively.
186 // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively. 182 // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
187 // So we must add 1. 183 // So we must add 1.
188 if (!m_buttonDown)
189 return 0;
190 return m_button + 1; 184 return m_button + 1;
191 } 185 }
192 186
193 Node* MouseEvent::toElement() const 187 Node* MouseEvent::toElement() const
194 { 188 {
195 // MSIE extension - "the object toward which the user is moving the mouse po inter" 189 // MSIE extension - "the object toward which the user is moving the mouse po inter"
196 if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouselea ve) 190 if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouselea ve)
197 return relatedTarget() ? relatedTarget()->toNode() : 0; 191 return relatedTarget() ? relatedTarget()->toNode() : 0;
198 192
199 return target() ? target()->toNode() : 0; 193 return target() ? target()->toNode() : 0;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 event().button(), relatedTarget, event().buttons()); 291 event().button(), relatedTarget, event().buttons());
298 if (event().defaultHandled()) 292 if (event().defaultHandled())
299 doubleClickEvent->setDefaultHandled(); 293 doubleClickEvent->setDefaultHandled();
300 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent)); 294 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent));
301 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) 295 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ())
302 return false; 296 return false;
303 return !swallowEvent; 297 return !swallowEvent;
304 } 298 }
305 299
306 } // namespace blink 300 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/events/MouseEvent.h ('k') | Source/core/events/MouseEvent.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698