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

Unified Diff: Source/core/events/MouseEvent.cpp

Issue 727593003: Implement MouseEvent buttons attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed comments Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/events/MouseEvent.cpp
diff --git a/Source/core/events/MouseEvent.cpp b/Source/core/events/MouseEvent.cpp
index b875392efae6270299157517467d31203ea4265d..5f125575472df6d60a0d3ad9de611202e5607618 100644
--- a/Source/core/events/MouseEvent.cpp
+++ b/Source/core/events/MouseEvent.cpp
@@ -40,6 +40,7 @@ MouseEventInit::MouseEventInit()
, shiftKey(false)
, metaKey(false)
, button(0)
+ , buttons(0)
, relatedTarget(nullptr)
{
}
@@ -61,24 +62,27 @@ PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventT
eventType, isBubbling, isCancelable, view,
detail, event.globalPosition().x(), event.globalPosition().y(), event.position().x(), event.position().y(),
event.movementDelta().x(), event.movementDelta().y(),
- event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(),
+ event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(), event.modifiers(),
relatedTarget, nullptr, false, event.syntheticEventType());
}
PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
int detail, int screenX, int screenY, int pageX, int pageY,
int movementX, int movementY,
- bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
+ bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
+ unsigned short button, unsigned modifiers,
PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<DataTransfer> dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticEventType syntheticEventType)
{
return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view,
detail, screenX, screenY, pageX, pageY,
movementX, movementY,
- ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, dataTransfer, isSimulated, syntheticEventType));
+ ctrlKey, altKey, shiftKey, metaKey, button, modifiers,
+ relatedTarget, dataTransfer, isSimulated, syntheticEventType));
}
MouseEvent::MouseEvent()
: m_button(0)
+ , m_buttons(0)
, m_buttonDown(false)
{
}
@@ -87,13 +91,14 @@ MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cance
int detail, int screenX, int screenY, int pageX, int pageY,
int movementX, int movementY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
- unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget,
+ unsigned short button, unsigned modifiers, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget,
PassRefPtrWillBeRawPtr<DataTransfer> dataTransfer, bool isSimulated, PlatformMouseEvent::SyntheticEventType syntheticEventType)
: MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint(screenX, screenY),
IntPoint(pageX, pageY),
IntPoint(movementX, movementY),
ctrlKey, altKey, shiftKey, metaKey, isSimulated)
, m_button(button == (unsigned short)-1 ? 0 : button)
+ , m_buttons(modifiersToButtons(eventType, button, modifiers))
, m_buttonDown(button != (unsigned short)-1)
, m_relatedTarget(relatedTarget)
, m_dataTransfer(dataTransfer)
@@ -107,6 +112,7 @@ MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& init
IntPoint(0 /* movementX */, 0 /* movementY */),
initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializer.metaKey, false /* isSimulated */)
, m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button)
+ , m_buttons(initializer.buttons == (unsigned short)-1 ? 0 : initializer.buttons)
, m_buttonDown(initializer.button != (unsigned short)-1)
, m_relatedTarget(initializer.relatedTarget)
, m_dataTransfer(nullptr)
@@ -118,10 +124,31 @@ MouseEvent::~MouseEvent()
{
}
+unsigned short MouseEvent::modifiersToButtons(const AtomicString& type, unsigned short button, unsigned modifiers)
+{
+ const unsigned buttonToModifier[] = {
+ PlatformEvent::LeftButtonDown,
+ PlatformEvent::MiddleButtonDown,
+ PlatformEvent::RightButtonDown
+ };
+ if (type == EventTypeNames::mouseup)
Rick Byers 2014/11/25 17:44:28 I don't think checking for mouseup here is suffici
zino 2014/11/28 12:29:28 Done.
+ modifiers &= ~buttonToModifier[button];
+
+ unsigned short buttons = 0;
+ if (modifiers & PlatformEvent::LeftButtonDown)
+ buttons |= 1;
+ if (modifiers & PlatformEvent::RightButtonDown)
+ buttons |= 2;
+ if (modifiers & PlatformEvent::MiddleButtonDown)
+ buttons |= 4;
+
+ return buttons;
+}
+
void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
int detail, int screenX, int screenY, int clientX, int clientY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
- unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget)
+ unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, unsigned short buttons)
{
if (dispatched())
return;
@@ -136,6 +163,7 @@ void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool c
m_button = button == (unsigned short)-1 ? 0 : button;
m_buttonDown = button != (unsigned short)-1;
m_relatedTarget = relatedTarget;
+ m_buttons = buttons;
initCoordinates(IntPoint(clientX, clientY));
@@ -205,7 +233,7 @@ SimulatedMouseEvent::~SimulatedMouseEvent()
}
SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent)
- : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, 0,
+ : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, 0, 0,
nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable)
{
if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) {
@@ -272,9 +300,9 @@ bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) cons
// as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create();
doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event()->bubbles(), event()->cancelable(), event()->view(),
- event()->detail(), event()->screenX(), event()->screenY(), event()->clientX(), event()->clientY(),
- event()->ctrlKey(), event()->altKey(), event()->shiftKey(), event()->metaKey(),
- event()->button(), relatedTarget);
+ event()->detail(), event()->screenX(), event()->screenY(), event()->clientX(), event()->clientY(),
+ event()->ctrlKey(), event()->altKey(), event()->shiftKey(), event()->metaKey(),
+ event()->button(), relatedTarget, event()->buttons());
if (event()->defaultHandled())
doubleClickEvent->setDefaultHandled();
EventDispatcher::dispatchEvent(dispatcher->node(), MouseEventDispatchMediator::create(doubleClickEvent));

Powered by Google App Engine
This is Rietveld 408576698