blob: 9a10aa76097507002f66ec202e28b5a6ba459073 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/events/keyboard_driven_event_rewriter.h"
#include "chrome/browser/chromeos/events/event_rewriter.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "components/user_manager/user_manager.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
namespace chromeos {
namespace {
const int kModifierMask = ui::EF_SHIFT_DOWN;
// Returns true if and only if it is on login screen (i.e. user is not logged
// in) and the keyboard driven flag in the OEM manifest is on.
bool ShouldStripModifiersForArrowKeysAndEnter() {
if (user_manager::UserManager::IsInitialized() &&
!user_manager::UserManager::Get()->IsSessionStarted()) {
return system::InputDeviceSettings::Get()
->ForceKeyboardDrivenUINavigation();
}
return false;
}
} // namespace
KeyboardDrivenEventRewriter::KeyboardDrivenEventRewriter() {
}
KeyboardDrivenEventRewriter::~KeyboardDrivenEventRewriter() {
}
ui::EventRewriteStatus KeyboardDrivenEventRewriter::RewriteForTesting(
const ui::Event& event,
scoped_ptr<ui::Event>* rewritten_event) {
return Rewrite(event, rewritten_event);
}
ui::EventRewriteStatus KeyboardDrivenEventRewriter::RewriteEvent(
const ui::Event& event,
scoped_ptr<ui::Event>* rewritten_event) {
if (!ShouldStripModifiersForArrowKeysAndEnter())
return ui::EVENT_REWRITE_CONTINUE;
return Rewrite(event, rewritten_event);
}
ui::EventRewriteStatus KeyboardDrivenEventRewriter::NextDispatchEvent(
const ui::Event& last_event,
scoped_ptr<ui::Event>* new_event) {
NOTREACHED();
return ui::EVENT_REWRITE_CONTINUE;
}
ui::EventRewriteStatus KeyboardDrivenEventRewriter::Rewrite(
const ui::Event& event,
scoped_ptr<ui::Event>* rewritten_event) {
int flags = event.flags();
if ((flags & kModifierMask) != kModifierMask)
return ui::EVENT_REWRITE_CONTINUE;
DCHECK(event.type() == ui::ET_KEY_PRESSED ||
event.type() == ui::ET_KEY_RELEASED)
<< "Unexpected event type " << event.type();
const ui::KeyEvent& key_event = static_cast<const ui::KeyEvent&>(event);
ui::KeyboardCode key_code = key_event.key_code();
if (key_code != ui::VKEY_LEFT && key_code != ui::VKEY_RIGHT &&
key_code != ui::VKEY_UP && key_code != ui::VKEY_DOWN &&
key_code != ui::VKEY_RETURN && key_code != ui::VKEY_F6) {
return ui::EVENT_REWRITE_CONTINUE;
}
chromeos::EventRewriter::MutableKeyState state = {
flags & ~(ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN),
key_event.code(),
key_event.GetDomKey(),
key_event.key_code()};
chromeos::EventRewriter::BuildRewrittenKeyEvent(key_event, state,
rewritten_event);
return ui::EVENT_REWRITE_REWRITTEN;
}
} // namespace chromeos
|