Commit 2306a9ca authored by Navid Zolghadr's avatar Navid Zolghadr Committed by Commit Bot

Update modifiers when buttons is set in MouseEvent

NACL expects modifiers to contain buttons information.
So we need to also set that information not only in
buttons field but also modifiers.

Bug: 839539, 839303
Change-Id: Ib859a2e071984be4625f0a42094982c7513ae5ae
Reviewed-on: https://chromium-review.googlesource.com/1052171Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarElla Ge <eirage@chromium.org>
Commit-Queue: Navid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557657}
parent 021a2437
...@@ -81,6 +81,28 @@ const LayoutObject* FindTargetLayoutObject(Node*& target_node) { ...@@ -81,6 +81,28 @@ const LayoutObject* FindTargetLayoutObject(Node*& target_node) {
return layout_object; return layout_object;
} }
unsigned ButtonsToWebInputEventModifiers(unsigned short buttons) {
unsigned modifiers = 0;
if (buttons &
static_cast<unsigned short>(WebPointerProperties::Buttons::kLeft))
modifiers |= WebInputEvent::kLeftButtonDown;
if (buttons &
static_cast<unsigned short>(WebPointerProperties::Buttons::kRight))
modifiers |= WebInputEvent::kRightButtonDown;
if (buttons &
static_cast<unsigned short>(WebPointerProperties::Buttons::kMiddle))
modifiers |= WebInputEvent::kMiddleButtonDown;
if (buttons &
static_cast<unsigned short>(WebPointerProperties::Buttons::kBack))
modifiers |= WebInputEvent::kBackButtonDown;
if (buttons &
static_cast<unsigned short>(WebPointerProperties::Buttons::kForward))
modifiers |= WebInputEvent::kForwardButtonDown;
return modifiers;
}
} // namespace } // namespace
MouseEvent* MouseEvent::Create(ScriptState* script_state, MouseEvent* MouseEvent::Create(ScriptState* script_state,
...@@ -113,23 +135,24 @@ MouseEvent* MouseEvent::Create(const AtomicString& event_type, ...@@ -113,23 +135,24 @@ MouseEvent* MouseEvent::Create(const AtomicString& event_type,
} }
SyntheticEventType synthetic_type = kPositionless; SyntheticEventType synthetic_type = kPositionless;
double screen_x = 0; MouseEventInit initializer;
double screen_y = 0;
if (underlying_event && underlying_event->IsMouseEvent()) { if (underlying_event && underlying_event->IsMouseEvent()) {
synthetic_type = kRealOrIndistinguishable; synthetic_type = kRealOrIndistinguishable;
MouseEvent* mouse_event = ToMouseEvent(underlying_event); MouseEvent* mouse_event = ToMouseEvent(underlying_event);
screen_x = mouse_event->screenX(); initializer.setScreenX(mouse_event->screenX());
screen_y = mouse_event->screenY(); initializer.setScreenY(mouse_event->screenY());
initializer.setSourceCapabilities(
view ? view->GetInputDeviceCapabilities()->FiresTouchEvents(false)
: nullptr);
} }
MouseEventInit initializer;
initializer.setBubbles(true); initializer.setBubbles(true);
initializer.setCancelable(true); initializer.setCancelable(true);
initializer.setScreenX(screen_x);
initializer.setScreenY(screen_y);
initializer.setView(view); initializer.setView(view);
initializer.setComposed(true); initializer.setComposed(true);
UIEventWithKeyState::SetFromWebInputEventModifiers(initializer, modifiers); UIEventWithKeyState::SetFromWebInputEventModifiers(initializer, modifiers);
initializer.setButtons(
MouseEvent::WebInputEventModifiersToButtons(modifiers));
TimeTicks timestamp = underlying_event ? underlying_event->PlatformTimeStamp() TimeTicks timestamp = underlying_event ? underlying_event->PlatformTimeStamp()
: CurrentTimeTicks(); : CurrentTimeTicks();
...@@ -176,6 +199,7 @@ MouseEvent::MouseEvent(const AtomicString& event_type, ...@@ -176,6 +199,7 @@ MouseEvent::MouseEvent(const AtomicString& event_type,
region_(initializer.region()), region_(initializer.region()),
menu_source_type_(menu_source_type) { menu_source_type_(menu_source_type) {
InitCoordinates(initializer.clientX(), initializer.clientY()); InitCoordinates(initializer.clientX(), initializer.clientY());
modifiers_ |= ButtonsToWebInputEventModifiers(buttons_);
} }
void MouseEvent::InitCoordinates(const double client_x, const double client_y) { void MouseEvent::InitCoordinates(const double client_x, const double client_y) {
......
...@@ -710,7 +710,9 @@ TEST_F(WebPluginContainerTest, PasteAndMatchStyleFromContextMenu) { ...@@ -710,7 +710,9 @@ TEST_F(WebPluginContainerTest, PasteAndMatchStyleFromContextMenu) {
class EventTestPlugin : public FakeWebPlugin { class EventTestPlugin : public FakeWebPlugin {
public: public:
explicit EventTestPlugin(const WebPluginParams& params) explicit EventTestPlugin(const WebPluginParams& params)
: FakeWebPlugin(params), last_event_type_(WebInputEvent::kUndefined) {} : FakeWebPlugin(params),
last_event_type_(WebInputEvent::kUndefined),
last_event_modifiers_(WebInputEvent::kNoModifiers) {}
WebInputEventResult HandleInputEvent( WebInputEventResult HandleInputEvent(
const WebCoalescedInputEvent& coalesced_event, const WebCoalescedInputEvent& coalesced_event,
...@@ -718,6 +720,7 @@ class EventTestPlugin : public FakeWebPlugin { ...@@ -718,6 +720,7 @@ class EventTestPlugin : public FakeWebPlugin {
const WebInputEvent& event = coalesced_event.Event(); const WebInputEvent& event = coalesced_event.Event();
coalesced_event_count_ = coalesced_event.CoalescedEventSize(); coalesced_event_count_ = coalesced_event.CoalescedEventSize();
last_event_type_ = event.GetType(); last_event_type_ = event.GetType();
last_event_modifiers_ = event.GetModifiers();
if (WebInputEvent::IsMouseEventType(event.GetType()) || if (WebInputEvent::IsMouseEventType(event.GetType()) ||
event.GetType() == WebInputEvent::kMouseWheel) { event.GetType() == WebInputEvent::kMouseWheel) {
const WebMouseEvent& mouse_event = const WebMouseEvent& mouse_event =
...@@ -742,6 +745,8 @@ class EventTestPlugin : public FakeWebPlugin { ...@@ -742,6 +745,8 @@ class EventTestPlugin : public FakeWebPlugin {
IntPoint GetLastEventLocation() { return last_event_location_; } IntPoint GetLastEventLocation() { return last_event_location_; }
int GetLastEventModifiers() { return last_event_modifiers_; }
void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; } void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; }
size_t GetCoalescedEventCount() { return coalesced_event_count_; } size_t GetCoalescedEventCount() { return coalesced_event_count_; }
...@@ -752,6 +757,7 @@ class EventTestPlugin : public FakeWebPlugin { ...@@ -752,6 +757,7 @@ class EventTestPlugin : public FakeWebPlugin {
size_t coalesced_event_count_; size_t coalesced_event_count_;
WebInputEvent::Type last_event_type_; WebInputEvent::Type last_event_type_;
IntPoint last_event_location_; IntPoint last_event_location_;
int last_event_modifiers_;
}; };
TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) {
...@@ -798,6 +804,39 @@ TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) { ...@@ -798,6 +804,39 @@ TEST_F(WebPluginContainerTest, GestureLongPressReachesPlugin) {
test_plugin->GetLastInputEventType()); test_plugin->GetLastInputEventType());
} }
TEST_F(WebPluginContainerTest, MouseEventButtons) {
RegisterMockedURL("plugin_container.html");
// Must outlive |web_view_helper|.
CustomPluginWebFrameClient<EventTestPlugin> plugin_web_frame_client;
FrameTestHelpers::WebViewHelper web_view_helper;
WebViewImpl* web_view = web_view_helper.InitializeAndLoad(
base_url_ + "plugin_container.html", &plugin_web_frame_client);
EnablePlugins(web_view, WebSize(300, 300));
WebElement plugin_container_one_element =
web_view->MainFrameImpl()->GetDocument().GetElementById(
WebString::FromUTF8("translated-plugin"));
WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(
plugin_container_one_element.PluginContainer())
->Plugin();
EventTestPlugin* test_plugin = static_cast<EventTestPlugin*>(plugin);
WebMouseEvent event = FrameTestHelpers::CreateMouseEvent(
WebMouseEvent::kMouseMove, WebMouseEvent::Button::kNoButton,
WebPoint(30, 30),
WebInputEvent::kMiddleButtonDown | WebInputEvent::kShiftKey);
WebRect rect = plugin_container_one_element.BoundsInViewport();
event.SetPositionInWidget(rect.x + rect.width / 2, rect.y + rect.height / 2);
web_view->HandleInputEvent(WebCoalescedInputEvent(event));
RunPendingTasks();
EXPECT_EQ(WebInputEvent::kMouseMove, test_plugin->GetLastInputEventType());
EXPECT_EQ(WebInputEvent::kMiddleButtonDown | WebInputEvent::kShiftKey,
test_plugin->GetLastEventModifiers());
}
TEST_F(WebPluginContainerTest, MouseWheelEventTranslated) { TEST_F(WebPluginContainerTest, MouseWheelEventTranslated) {
RegisterMockedURL("plugin_container.html"); RegisterMockedURL("plugin_container.html");
// Must outlive |web_view_helper|. // Must outlive |web_view_helper|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment