Skip to content

Commit

Permalink
Implement more modifier queries for getModifierState on Keyboard/Mous…
Browse files Browse the repository at this point in the history
…e events.

Include support for querying:
Accel, AltGraph, CapsLock, Fn, NumLock, OS, ScrollLock, Symbol

A large portion of this change is cleaning up how the modifiers are passed
into event construction. Instead of passing 4 booleans; try to pass the
event flag mask or the EventModifierInit dictionary directly.

See intent to ship:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/3mwQZ2wdy18

Not all platforms currently are setting the flags appropriately on the
constructed WebInputEvents; this will be done in a follow-up change.

BUG=265458

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

Cr-Commit-Position: refs/heads/master@{#352334}
  • Loading branch information
dtapuska authored and Commit bot committed Oct 5, 2015
1 parent f8bab5e commit 299efe1
Show file tree
Hide file tree
Showing 45 changed files with 1,473 additions and 427 deletions.
22 changes: 22 additions & 0 deletions components/test_runner/event_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ int GetKeyModifier(const std::string& modifier_name) {
return WebInputEvent::MiddleButtonDown;
} else if (!strcmp(characters, "rightButton")) {
return WebInputEvent::RightButtonDown;
} else if (!strcmp(characters, "capsLockOn")) {
return WebInputEvent::CapsLockOn;
} else if (!strcmp(characters, "numLockOn")) {
return WebInputEvent::NumLockOn;
} else if (!strcmp(characters, "locationLeft")) {
return WebInputEvent::IsLeft;
} else if (!strcmp(characters, "locationRight")) {
return WebInputEvent::IsRight;
} else if (!strcmp(characters, "locationNumpad")) {
return WebInputEvent::IsKeyPad;
} else if (!strcmp(characters, "isComposing")) {
return WebInputEvent::IsComposing;
} else if (!strcmp(characters, "altGraphKey")) {
return WebInputEvent::AltGrKey;
} else if (!strcmp(characters, "osKey")) {
return WebInputEvent::OSKey;
} else if (!strcmp(characters, "fnKey")) {
return WebInputEvent::FnKey;
} else if (!strcmp(characters, "symbolKey")) {
return WebInputEvent::SymbolKey;
} else if (!strcmp(characters, "scrollLockOn")) {
return WebInputEvent::ScrollLockOn;
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ PASS new KeyboardEvent('eventType', { metaKey: false }).metaKey is false
PASS new KeyboardEvent('eventType', { metaKey: true }).metaKey is true
PASS new KeyboardEvent('eventType', { repeat: false }).repeat is false
PASS new KeyboardEvent('eventType', { repeat: true }).repeat is true
PASS new KeyboardEvent('eventType', { ctrlKey: false }).getModifierState('Control'); is false
PASS new KeyboardEvent('eventType', { ctrlKey: true }).getModifierState('Control'); is true
PASS new KeyboardEvent('eventType', { shiftKey: false }).getModifierState('Shift'); is false
PASS new KeyboardEvent('eventType', { shiftKey: true }).getModifierState('Shift'); is true
PASS new KeyboardEvent('eventType', { metaKey: false }).getModifierState('Meta'); is false
PASS new KeyboardEvent('eventType', { metaKey: true }).getModifierState('Meta'); is true
PASS new KeyboardEvent('eventType', { altKey: false }).getModifierState('Alt'); is false
PASS new KeyboardEvent('eventType', { altKey: true }).getModifierState('Alt'); is true
PASS new KeyboardEvent('eventType', { modifierAltGraph: false }).getModifierState('AltGraph'); is false
PASS new KeyboardEvent('eventType', { modifierAltGraph: true }).getModifierState('AltGraph'); is true
PASS new KeyboardEvent('eventType', { modifierOS: false }).getModifierState('OS'); is false
PASS new KeyboardEvent('eventType', { modifierOS: true }).getModifierState('OS'); is true
PASS new KeyboardEvent('eventType', { modifierFn: false }).getModifierState('Fn'); is false
PASS new KeyboardEvent('eventType', { modifierFn: true }).getModifierState('Fn'); is true
PASS new KeyboardEvent('eventType', { modifierCapsLock: false }).getModifierState('CapsLock'); is false
PASS new KeyboardEvent('eventType', { modifierCapsLock: true }).getModifierState('CapsLock'); is true
PASS new KeyboardEvent('eventType', { modifierScrollLock: false }).getModifierState('ScrollLock'); is false
PASS new KeyboardEvent('eventType', { modifierScrollLock: true }).getModifierState('ScrollLock'); is true
PASS new KeyboardEvent('eventType', { modifierNumLock: false }).getModifierState('NumLock'); is false
PASS new KeyboardEvent('eventType', { modifierNumLock: true }).getModifierState('NumLock'); is true
PASS new KeyboardEvent('eventType', { modifierSymbol: false }).getModifierState('Symbol'); is false
PASS new KeyboardEvent('eventType', { modifierSymbol: true }).getModifierState('Symbol'); is true
PASS new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, repeat: true }).bubbles is true
PASS new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, repeat: true }).cancelable is true
PASS new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, repeat: true }).view is window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/input-modifiers.js"></script>
</head>
<body>
<script>
Expand Down Expand Up @@ -115,6 +116,12 @@
shouldBe("new KeyboardEvent('eventType', { " + attr + ": true })." + attr, "true");
});

// all modifiers are passed correctly.
forEachModifier(function(attr, modifierName) {
shouldBe("new KeyboardEvent('eventType', { " + attr + ": false }).getModifierState('" + modifierName + "');", "false");
shouldBe("new KeyboardEvent('eventType', { " + attr + ": true }).getModifierState('" + modifierName + "');", "true");
});

// All initializers are passed.
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, repeat: true }).bubbles", "true");
shouldBe("new KeyboardEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, keyIdentifier: 'chocolate', location: 222, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, repeat: true }).cancelable", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ PASS new MouseEvent('eventType', { shiftKey: false }).shiftKey is false
PASS new MouseEvent('eventType', { shiftKey: true }).shiftKey is true
PASS new MouseEvent('eventType', { metaKey: false }).metaKey is false
PASS new MouseEvent('eventType', { metaKey: true }).metaKey is true
PASS new MouseEvent('eventType', { ctrlKey: false }).getModifierState('Control'); is false
PASS new MouseEvent('eventType', { ctrlKey: true }).getModifierState('Control'); is true
PASS new MouseEvent('eventType', { shiftKey: false }).getModifierState('Shift'); is false
PASS new MouseEvent('eventType', { shiftKey: true }).getModifierState('Shift'); is true
PASS new MouseEvent('eventType', { metaKey: false }).getModifierState('Meta'); is false
PASS new MouseEvent('eventType', { metaKey: true }).getModifierState('Meta'); is true
PASS new MouseEvent('eventType', { altKey: false }).getModifierState('Alt'); is false
PASS new MouseEvent('eventType', { altKey: true }).getModifierState('Alt'); is true
PASS new MouseEvent('eventType', { modifierAltGraph: false }).getModifierState('AltGraph'); is false
PASS new MouseEvent('eventType', { modifierAltGraph: true }).getModifierState('AltGraph'); is true
PASS new MouseEvent('eventType', { modifierOS: false }).getModifierState('OS'); is false
PASS new MouseEvent('eventType', { modifierOS: true }).getModifierState('OS'); is true
PASS new MouseEvent('eventType', { modifierFn: false }).getModifierState('Fn'); is false
PASS new MouseEvent('eventType', { modifierFn: true }).getModifierState('Fn'); is true
PASS new MouseEvent('eventType', { modifierCapsLock: false }).getModifierState('CapsLock'); is false
PASS new MouseEvent('eventType', { modifierCapsLock: true }).getModifierState('CapsLock'); is true
PASS new MouseEvent('eventType', { modifierScrollLock: false }).getModifierState('ScrollLock'); is false
PASS new MouseEvent('eventType', { modifierScrollLock: true }).getModifierState('ScrollLock'); is true
PASS new MouseEvent('eventType', { modifierNumLock: false }).getModifierState('NumLock'); is false
PASS new MouseEvent('eventType', { modifierNumLock: true }).getModifierState('NumLock'); is true
PASS new MouseEvent('eventType', { modifierSymbol: false }).getModifierState('Symbol'); is false
PASS new MouseEvent('eventType', { modifierSymbol: true }).getModifierState('Symbol'); is true
PASS new MouseEvent('eventType', { button: 0 }).button is 0
PASS new MouseEvent('eventType', { button: 1 }).button is 1
PASS new MouseEvent('eventType', { button: -2 }).button is -2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/input-modifiers.js"></script>
</head>
<body>
<script>
Expand Down Expand Up @@ -102,6 +103,12 @@
shouldBe("new MouseEvent('eventType', { " + attr + ": true })." + attr, "true");
});

// all modifiers are passed correctly.
forEachModifier(function(attr, modifierName) {
shouldBe("new MouseEvent('eventType', { " + attr + ": false }).getModifierState('" + modifierName + "');", "false");
shouldBe("new MouseEvent('eventType', { " + attr + ": true }).getModifierState('" + modifierName + "');", "true");
});

// button is passed.
// Numbers within the short range.
shouldBe("new MouseEvent('eventType', { button: 0 }).button", "0");
Expand Down
Loading

0 comments on commit 299efe1

Please sign in to comment.