1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/keyboard_driven_event_rewriter.h"
9 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/browser/chromeos/system/input_device_settings.h"
11 #include "ui/events/event.h"
17 const int kModifierMask
= ui::EF_SHIFT_DOWN
;
19 // Returns true if and only if it is on login screen (i.e. user is not logged
20 // in) and the keyboard driven flag in the OEM manifest is on.
21 bool ShouldStripModifiersForArrowKeysAndEnter() {
22 if (UserManager::IsInitialized() &&
23 !UserManager::Get()->IsUserLoggedIn()) {
24 return system::keyboard_settings::ForceKeyboardDrivenUINavigation();
32 KeyboardDrivenEventRewriter::KeyboardDrivenEventRewriter() {}
34 KeyboardDrivenEventRewriter::~KeyboardDrivenEventRewriter() {}
36 bool KeyboardDrivenEventRewriter::RewriteIfKeyboardDrivenOnLoginScreen(
37 ui::KeyEvent
* event
) {
38 if (!ShouldStripModifiersForArrowKeysAndEnter())
41 return RewriteEvent(event
);
44 bool KeyboardDrivenEventRewriter::RewriteForTesting(ui::KeyEvent
* event
) {
45 return RewriteEvent(event
);
48 bool KeyboardDrivenEventRewriter::RewriteEvent(ui::KeyEvent
* event
) {
49 if ((event
->flags() & kModifierMask
) != kModifierMask
)
52 if (event
->key_code() != ui::VKEY_LEFT
&&
53 event
->key_code() != ui::VKEY_RIGHT
&&
54 event
->key_code() != ui::VKEY_UP
&&
55 event
->key_code() != ui::VKEY_DOWN
&&
56 event
->key_code() != ui::VKEY_RETURN
&&
57 event
->key_code() != ui::VKEY_F6
) {
61 XEvent
* xev
= event
->native_event();
62 XKeyEvent
* xkey
= &(xev
->xkey
);
63 xkey
->state
&= ~(ControlMask
| Mod1Mask
| ShiftMask
);
64 event
->set_flags(event
->flags() & ~kModifierMask
);
65 event
->NormalizeFlags();
69 } // namespace chromeos