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

Unified Diff: Source/web/WebInputEventConversion.cpp

Issue 727593003: Implement MouseEvent buttons attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: nits Created 6 years 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
« no previous file with comments | « Source/platform/RuntimeEnabledFeatures.in ('k') | Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebInputEventConversion.cpp
diff --git a/Source/web/WebInputEventConversion.cpp b/Source/web/WebInputEventConversion.cpp
index a748a44b14db7a0729e6aa1a644c29751e911106..b4c76c6b3b7bb0253ef1c70ef3759a951e5d84f5 100644
--- a/Source/web/WebInputEventConversion.cpp
+++ b/Source/web/WebInputEventConversion.cpp
@@ -112,6 +112,32 @@ static unsigned toPlatformEventModifiers(int webModifiers)
return newModifiers;
}
+static unsigned toPlatformMouseEventModifiers(int webModifiers)
+{
+ unsigned newModifiers = toPlatformEventModifiers(webModifiers);
+ if (webModifiers & WebInputEvent::LeftButtonDown)
+ newModifiers |= PlatformEvent::LeftButtonDown;
+ if (webModifiers & WebInputEvent::MiddleButtonDown)
+ newModifiers |= PlatformEvent::MiddleButtonDown;
+ if (webModifiers & WebInputEvent::RightButtonDown)
+ newModifiers |= PlatformEvent::RightButtonDown;
+ return newModifiers;
+}
+
+static unsigned toPlatformModifierFrom(WebMouseEvent::Button button)
+{
+ if (button == WebMouseEvent::ButtonNone)
+ return 0;
+
+ unsigned webMouseButtonToPlatformModifier[] = {
+ PlatformEvent::LeftButtonDown,
+ PlatformEvent::MiddleButtonDown,
+ PlatformEvent::RightButtonDown
+ };
+
+ return webMouseButtonToPlatformModifier[button];
+}
+
// MakePlatformMouseEvent -----------------------------------------------------
PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMouseEvent& e)
@@ -122,7 +148,7 @@ PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo
m_globalPosition = IntPoint(e.globalX, e.globalY);
m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX), scaleDeltaToWindow(widget, e.movementY));
m_button = static_cast<MouseButton>(e.button);
- m_modifiers = toPlatformEventModifiers(e.modifiers);
+ m_modifiers = toPlatformMouseEventModifiers(e.modifiers);
m_timestamp = e.timeStampSeconds;
m_clickCount = e.clickCount;
@@ -139,6 +165,12 @@ PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo
case WebInputEvent::MouseUp:
m_type = PlatformEvent::MouseReleased;
+
+ // The MouseEvent spec requires that buttons indicates the state
+ // immediately after the event takes place. To ensure consistency
+ // between platforms here, we explicitly clear the button that is
+ // in the process of being released.
+ m_modifiers &= ~toPlatformModifierFrom(e.button);
break;
default:
@@ -161,7 +193,7 @@ PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
m_type = PlatformEvent::Wheel;
- m_modifiers = toPlatformEventModifiers(e.modifiers);
+ m_modifiers = toPlatformMouseEventModifiers(e.modifiers);
m_hasPreciseScrollingDeltas = e.hasPreciseScrollingDeltas;
#if OS(MACOSX)
« no previous file with comments | « Source/platform/RuntimeEnabledFeatures.in ('k') | Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698