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

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: Updating as per review comments 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 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) 76 , m_buttonDown(false)
77 , m_relatedTarget(nullptr) 77 , m_relatedTarget(nullptr)
78 , m_dataTransfer(nullptr) 78 , m_dataTransfer(nullptr)
79 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) 79 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable)
80 { 80 {
81 } 81 }
82 82
83 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance lable, PassRefPtrWillBeRawPtr<AbstractView> view, 83 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance lable, PassRefPtrWillBeRawPtr<AbstractView> view,
84 int detail, int screenX, int screenY, int windowX, int windowY, 84 int detail, int screenX, int screenY, int windowX, int windowY,
85 int movementX, int movementY, 85 int movementX, int movementY,
86 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, 86 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
87 unsigned short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventT arget> relatedTarget, 87 short button, unsigned short buttons, PassRefPtrWillBeRawPtr<EventTarget> re latedTarget,
88 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE ventType syntheticEventType, 88 DataTransfer* dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticE ventType syntheticEventType,
89 double uiCreateTime) 89 double uiCreateTime)
90 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY), 90 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint (screenX, screenY),
91 IntPoint(windowX, windowY), 91 IntPoint(windowX, windowY),
92 IntPoint(movementX, movementY), 92 IntPoint(movementX, movementY),
93 ctrlKey, altKey, shiftKey, metaKey, isSimulated) 93 ctrlKey, altKey, shiftKey, metaKey, isSimulated)
94 , m_button(button == (unsigned short)-1 ? 0 : button) 94 , m_button(button)
95 , m_buttons(buttons) 95 , m_buttons(buttons)
96 , m_buttonDown(button != (unsigned short)-1) 96 , m_buttonDown(button != -1)
philipj_slow 2015/06/10 08:46:25 Can the m_buttonDown member be removed? Just imple
ramya.v 2015/06/10 09:21:28 buttonDown() function is used in other places like
ramya.v 2015/06/10 09:25:39 Sorry, didn't get you, yes the variable can be re
ramya.v 2015/06/10 09:41:25 Done.
97 , m_relatedTarget(relatedTarget) 97 , m_relatedTarget(relatedTarget)
98 , m_dataTransfer(dataTransfer) 98 , m_dataTransfer(dataTransfer)
99 , m_syntheticEventType(syntheticEventType) 99 , m_syntheticEventType(syntheticEventType)
100 { 100 {
101 setUICreateTime(uiCreateTime); 101 setUICreateTime(uiCreateTime);
102 } 102 }
103 103
104 MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init ializer) 104 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()), 105 : MouseRelatedEvent(eventType, initializer.bubbles(), initializer.cancelable (), initializer.view(), initializer.detail(), IntPoint(initializer.screenX(), in itializer.screenY()),
106 IntPoint(0 /* pageX */, 0 /* pageY */), 106 IntPoint(0 /* pageX */, 0 /* pageY */),
107 IntPoint(initializer.movementX(), initializer.movementY()), 107 IntPoint(initializer.movementX(), initializer.movementY()),
108 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */) 108 initializer.ctrlKey(), initializer.altKey(), initializer.shiftKey(), ini tializer.metaKey(), false /* isSimulated */)
109 , m_button(initializer.button() == (unsigned short)-1 ? 0 : initializer.butt on()) 109 , m_button(initializer.button())
110 , m_buttons(initializer.buttons()) 110 , m_buttons(initializer.buttons())
111 , m_buttonDown(initializer.button() != (unsigned short)-1) 111 , m_buttonDown(initializer.button() != -1)
112 , m_relatedTarget(initializer.relatedTarget()) 112 , m_relatedTarget(initializer.relatedTarget())
113 , m_dataTransfer(nullptr) 113 , m_dataTransfer(nullptr)
114 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable) 114 , m_syntheticEventType(PlatformMouseEvent::RealOrIndistinguishable)
115 { 115 {
116 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); 116 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY()));
117 } 117 }
118 118
119 MouseEvent::~MouseEvent() 119 MouseEvent::~MouseEvent()
120 { 120 {
121 } 121 }
122 122
123 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers) 123 unsigned short MouseEvent::platformModifiersToButtons(unsigned modifiers)
124 { 124 {
125 unsigned short buttons = 0; 125 unsigned short buttons = 0;
126 126
127 if (modifiers & PlatformEvent::LeftButtonDown) 127 if (modifiers & PlatformEvent::LeftButtonDown)
128 buttons |= 1; 128 buttons |= 1;
129 if (modifiers & PlatformEvent::RightButtonDown) 129 if (modifiers & PlatformEvent::RightButtonDown)
130 buttons |= 2; 130 buttons |= 2;
131 if (modifiers & PlatformEvent::MiddleButtonDown) 131 if (modifiers & PlatformEvent::MiddleButtonDown)
132 buttons |= 4; 132 buttons |= 4;
133 133
134 return buttons; 134 return buttons;
135 } 135 }
136 136
137 void MouseEvent::initMouseEvent(ScriptState* scriptState, const AtomicString& ty pe, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view, 137 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, 138 int detail, int screenX, int screenY, int client X, int clientY,
139 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey, 139 bool ctrlKey, bool altKey, bool shiftKey, bool m etaKey,
140 unsigned short button, PassRefPtrWillBeRawPtr<Ev entTarget> relatedTarget, unsigned short buttons) 140 short button, PassRefPtrWillBeRawPtr<EventTarget > relatedTarget, unsigned short buttons)
141 { 141 {
142 if (dispatched()) 142 if (dispatched())
143 return; 143 return;
144 144
145 if (scriptState && scriptState->world().isIsolatedWorld()) 145 if (scriptState && scriptState->world().isIsolatedWorld())
146 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif tKey, metaKey); 146 UIEventWithKeyState::didCreateEventInIsolatedWorld(ctrlKey, altKey, shif tKey, metaKey);
147 147
148 initUIEvent(type, canBubble, cancelable, view, detail); 148 initUIEvent(type, canBubble, cancelable, view, detail);
149 149
150 m_screenLocation = IntPoint(screenX, screenY); 150 m_screenLocation = IntPoint(screenX, screenY);
151 m_ctrlKey = ctrlKey; 151 m_ctrlKey = ctrlKey;
152 m_altKey = altKey; 152 m_altKey = altKey;
153 m_shiftKey = shiftKey; 153 m_shiftKey = shiftKey;
154 m_metaKey = metaKey; 154 m_metaKey = metaKey;
155 m_button = button == (unsigned short)-1 ? 0 : button; 155 m_button = button;
156 m_buttons = buttons; 156 m_buttons = buttons;
157 m_buttonDown = button != (unsigned short)-1; 157 m_buttonDown = button != -1;
158 m_relatedTarget = relatedTarget; 158 m_relatedTarget = relatedTarget;
159 159
160 initCoordinates(IntPoint(clientX, clientY)); 160 initCoordinates(IntPoint(clientX, clientY));
161 161
162 // FIXME: m_isSimulated is not set to false here. 162 // FIXME: m_isSimulated is not set to false here.
163 // FIXME: m_dataTransfer is not set to nullptr here. 163 // FIXME: m_dataTransfer is not set to nullptr here.
164 } 164 }
165 165
166 const AtomicString& MouseEvent::interfaceName() const 166 const AtomicString& MouseEvent::interfaceName() const
167 { 167 {
(...skipping 10 matching lines...) Expand all
178 const AtomicString& t = type(); 178 const AtomicString& t = type();
179 return t == EventTypeNames::dragenter || t == EventTypeNames::dragover || t == EventTypeNames::dragleave || t == EventTypeNames::drop 179 return t == EventTypeNames::dragenter || t == EventTypeNames::dragover || t == EventTypeNames::dragleave || t == EventTypeNames::drop
180 || t == EventTypeNames::dragstart|| t == EventTypeNames::drag || t == EventTypeNames::dragend; 180 || t == EventTypeNames::dragstart|| t == EventTypeNames::drag || t == EventTypeNames::dragend;
181 } 181 }
182 182
183 int MouseEvent::which() const 183 int MouseEvent::which() const
184 { 184 {
185 // For the DOM, the return values for left, middle and right mouse buttons a re 0, 1, 2, respectively. 185 // 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. 186 // 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. 187 // So we must add 1.
188 if (!m_buttonDown)
189 return 0;
190 return m_button + 1; 188 return m_button + 1;
191 } 189 }
192 190
193 Node* MouseEvent::toElement() const 191 Node* MouseEvent::toElement() const
194 { 192 {
195 // MSIE extension - "the object toward which the user is moving the mouse po inter" 193 // MSIE extension - "the object toward which the user is moving the mouse po inter"
196 if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouselea ve) 194 if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouselea ve)
197 return relatedTarget() ? relatedTarget()->toNode() : 0; 195 return relatedTarget() ? relatedTarget()->toNode() : 0;
198 196
199 return target() ? target()->toNode() : 0; 197 return target() ? target()->toNode() : 0;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 event().button(), relatedTarget, event().buttons()); 295 event().button(), relatedTarget, event().buttons());
298 if (event().defaultHandled()) 296 if (event().defaultHandled())
299 doubleClickEvent->setDefaultHandled(); 297 doubleClickEvent->setDefaultHandled();
300 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent)); 298 EventDispatcher::dispatchEvent(dispatcher.node(), MouseEventDispatchMediator ::create(doubleClickEvent));
301 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ()) 299 if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented ())
302 return false; 300 return false;
303 return !swallowEvent; 301 return !swallowEvent;
304 } 302 }
305 303
306 } // namespace blink 304 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698