Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Map Alt-Up/Down to PageUp/PageDown on Mac
Browse files Browse the repository at this point in the history
Match Safari's behavior

Used to be Control-Up/Down but actually it won't work because they are
usually used by Mission Control on Mac

BUG=570823

Review URL: https://codereview.chromium.org/1591743002

Cr-Commit-Position: refs/heads/master@{#370183}
  • Loading branch information
chongz authored and Commit bot committed Jan 19, 2016
1 parent 8f131d2 commit 2e7a4d4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This tests keyboard scrolling by pages.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS document.scrollingElement.scrollTop >= window.innerHeight * 0.875 became true
PASS document.scrollingElement.scrollTop became 0
PASS successfullyParsed is true

TEST COMPLETE

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style type="text/css">
::-webkit-scrollbar {
width: 0px;
height: 0px;
}

#greenbox {
width: 100px;
height: 2000px;
background: green;
}
#redbox {
width: 100px;
height: 2000px;
background: red;
}

</style>
</head>
<body style="margin:0" onload="runTest();">

<div id="greenbox"></div>
<div id="redbox"></div>

<p id="description"></p>
<div id="console"></div>
<script type="text/javascript">

function keyboardScrollPageDown()
{
if (navigator.platform.indexOf('Mac') == 0) {
eventSender.keyDown('downArrow', ["altKey"]);
} else {
eventSender.keyDown('pageDown');
}

// see kMinFractionToStepWhenPaging = 0.875f in ScrollableArea.cpp
shouldBecomeEqual("document.scrollingElement.scrollTop >= window.innerHeight * 0.875", "true", keyboardScrollPageUp);
}

function keyboardScrollPageUp()
{
if (navigator.platform.indexOf('Mac') == 0) {
eventSender.keyDown('upArrow', ["altKey"]);
} else {
eventSender.keyDown('pageUp');
}

// PageDown + PageUp goes back to 0
shouldBecomeEqual("document.scrollingElement.scrollTop", "0", finishJSTest);
}

jsTestIsAsync = true;

function runTest()
{
if (window.eventSender) {
description('This tests keyboard scrolling by pages.');
keyboardScrollPageDown();
} else {
debug("This test requires DumpRenderTree. Use PageUp/Down (or Alt-Up/Down for Mac) to validate the implementation.");
}
}
</script>

</body>
</html>
4 changes: 2 additions & 2 deletions third_party/WebKit/Source/web/WebViewImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,8 @@ bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers)
ScrollDirectionPhysical scrollDirectionPhysical;
ScrollGranularity scrollGranularity;
#if OS(MACOSX)
// Control-Up/Down should be PageUp/Down on Mac.
if (modifiers & WebMouseEvent::ControlKey) {
// Alt-Up/Down should be PageUp/Down on Mac.
if (modifiers & WebMouseEvent::AltKey) {
if (keyCode == VKEY_UP)
keyCode = VKEY_PRIOR;
else if (keyCode == VKEY_DOWN)
Expand Down

0 comments on commit 2e7a4d4

Please sign in to comment.