Commit c18ebe7a authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Locked mouse event check ShouldGenerateAppCommand

When pointer is locked, we still need to check ShouldGenerateAppCommand
and set event handled so that won't generate unnecessary navigate
appcommand when kExtendedMouseButtons is enabled. This causes unable
to preventDefault on mouse back/forward buttons to prevent navigation
while pointer is locked.

Bug: 852709
Change-Id: I5f75a68e36037210c38310f8d83825c5efdf311e
Reviewed-on: https://chromium-review.googlesource.com/1148886
Commit-Queue: Ella Ge <eirage@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577889}
parent 95bf7a9e
...@@ -751,16 +751,15 @@ void RenderWidgetHostViewEventHandler::HandleMouseEventWhileLocked( ...@@ -751,16 +751,15 @@ void RenderWidgetHostViewEventHandler::HandleMouseEventWhileLocked(
ProcessMouseWheelEvent(mouse_wheel_event, *event->latency()); ProcessMouseWheelEvent(mouse_wheel_event, *event->latency());
} }
} }
return; } else {
}
gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint());
// If we receive non client mouse messages while we are in the locked state // If we receive non client mouse messages while we are in the locked state
// it probably means that the mouse left the borders of our window and // it probably means that the mouse left the borders of our window and
// needs to be moved back to the center. // needs to be moved back to the center.
if (event->flags() & ui::EF_IS_NON_CLIENT) { if (event->flags() & ui::EF_IS_NON_CLIENT) {
// TODO(jonross): ideally this would not be done for mus (crbug.com/621412) // TODO(jonross): ideally this would not be done for mus
// (crbug.com/621412)
MoveCursorToCenter(); MoveCursorToCenter();
return; return;
} }
...@@ -818,6 +817,9 @@ void RenderWidgetHostViewEventHandler::HandleMouseEventWhileLocked( ...@@ -818,6 +817,9 @@ void RenderWidgetHostViewEventHandler::HandleMouseEventWhileLocked(
SetKeyboardFocus(); SetKeyboardFocus();
} }
} }
}
if (!ShouldGenerateAppCommand(event))
event->SetHandled();
} }
void RenderWidgetHostViewEventHandler::ModifyEventMovementAndCoords( void RenderWidgetHostViewEventHandler::ModifyEventMovementAndCoords(
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Mouse Button Back/Forward</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
var testMouseUp = async_test('Tests that when pointer is locked, the mouseup is preventable.');
var received_back = false;
var received_forward = false;
window.addEventListener('mouseup', function(e) {
if (e.button == 0) {
document.body.requestPointerLock();
} else if (e.button == 3) {
received_back = true;
e.preventDefault();
} else if (e.button == 4) {
received_forward = true;
e.preventDefault();
}
if (document.pointerLockElement && received_back && received_forward) {
testMouseUp.done();
document.exitPointerLock();
}
});
</script>
</head>
<body id="target">
<h4>Test Description: Tests that the mouseup event is prevented.
<ol>
<li>Click the left mouse button to lock pointer</li>
<li>Click the back mouse button</li>
<li>Click the back mouse forward</li>
</ol>
</h4>
</body>
</html>
importAutomationScript('/pointerevents/pointerevent_common_input.js');
function inject_input() {
return mouseClickInTarget('#target', undefined, "left").then(function() {
return mouseClickInTarget('#target', undefined, "back").then(function() {
return mouseClickInTarget('#target', undefined, "forward");
});
});
}
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