Flutter Engine
The Flutter Engine
keyboard.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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.
4
5#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_KEYBOARD_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_KEYBOARD_H_
7
8#include <fuchsia/ui/input3/cpp/fidl.h>
9
10namespace flutter_runner {
11
12// Keyboard handles the keyboard signals from fuchsia.ui.input3. Specifically,
13// input3 has no notion of a code point, and does not track stateful versions
14// of the modifier keys.
15class Keyboard final {
16 public:
17 explicit Keyboard();
18
19 // Consumes the given keyboard event. Keyboard will adjust the modifier
20 // state based on the info given in the event. Returns true if the event has
21 // been integrated into the internal state successfully, or false otherwise.
22 bool ConsumeEvent(fuchsia::ui::input3::KeyEvent event);
23
24 // Gets the currently active modifier keys.
25 uint32_t Modifiers();
26
27 // Gets the last encountered code point. The reported code point depends on
28 // the state of the modifier keys.
29 uint32_t LastCodePoint();
30
31 // Gets the last encountered HID usage. This is a 32-bit number, with the
32 // upper 16 bits equal to `LastHidUsagePage()`, and the lower 16 bits equal
33 // to `LastHIDUsageID()`.
34 //
35 // The key corresponding to A will have the usage 0x7004. This function will
36 // return 0x7004 in that case.
37 uint32_t LastHIDUsage();
38
39 // Gets the last encountered HID usage page.
40 //
41 // The key corresponding to A will have the usage 0x7004. This function will
42 // return 0x7 in that case.
43 uint16_t LastHIDUsagePage();
44
45 // Gets the last encountered HID usage ID.
46 //
47 // The key corresponding to A will have the usage 0x7004. This function will
48 // return 0x4 in that case.
49 uint16_t LastHIDUsageID();
50
51 private:
52 // Return true if any level shift is active.
53 bool IsShift();
54
55 // Returns true if the last key event was about a key that may have a code
56 // point associated.
57 bool IsKeys();
58
59 // Returns the value of the last key as a uint32_t.
60 // If there isn't such a value (as in the case of on-screen keyboards), this
61 // will return a 0;
62 uint32_t GetLastKey();
63
64 // Set to false until any event is received.
65 bool any_events_received_ : 1;
66
67 // The flags below show the state of the keyboard modifiers after the last
68 // event has been processed. Stateful keys remain in the same state after
69 // a release and require an additional press to toggle.
70 bool stateful_caps_lock_ : 1;
71 bool left_shift_ : 1;
72 bool right_shift_ : 1;
73 bool left_alt_ : 1;
74 bool right_alt_ : 1;
75 bool left_ctrl_ : 1;
76 bool right_ctrl_ : 1;
77
78 // The last received key event. If any_events_received_ is not set, this is
79 // not valid.
80 fuchsia::ui::input3::KeyEvent last_event_;
81};
82
83} // namespace flutter_runner
84
85#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_KEYBOARD_H_
uint16_t LastHIDUsagePage()
Definition: keyboard.cc:349
uint32_t LastCodePoint()
Definition: keyboard.cc:307
uint16_t LastHIDUsageID()
Definition: keyboard.cc:345
bool ConsumeEvent(fuchsia::ui::input3::KeyEvent event)
Definition: keyboard.cc:174
FlKeyEvent * event