Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 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 COMPONENTS_EXO_KEYBOARD_DELEGATE_H_ |
| 6 | #define COMPONENTS_EXO_KEYBOARD_DELEGATE_H_ |
| 7 | |
Helmut Januschka | fa9871de | 2024-05-10 18:51:47 | [diff] [blame] | 8 | #include <string_view> |
| 9 | |
David Padlipsky | 20258f2 | 2024-02-17 01:50:02 | [diff] [blame] | 10 | #include "ash/public/mojom/input_device_settings.mojom.h" |
Shawn Gallea | 1310d8a | 2018-11-14 23:07:21 | [diff] [blame] | 11 | #include "base/containers/flat_map.h" |
David Padlipsky | 544ae2a0 | 2024-02-17 01:25:06 | [diff] [blame] | 12 | #include "base/containers/flat_set.h" |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 13 | #include "base/time/time.h" |
Hidehiko Abe | 190f6934 | 2021-04-02 19:58:45 | [diff] [blame] | 14 | #include "components/exo/key_state.h" |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 15 | |
| 16 | namespace ui { |
Wez | c0a1816 | 2023-10-19 16:24:50 | [diff] [blame] | 17 | enum class DomCode : uint32_t; |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | namespace exo { |
Hidehiko Abe | 3375cfe5 | 2020-09-29 08:48:26 | [diff] [blame] | 21 | struct KeyboardModifiers; |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 22 | class Surface; |
| 23 | |
| 24 | // Handles events on keyboards in context-specific ways. |
| 25 | class KeyboardDelegate { |
| 26 | public: |
Hidehiko Abe | 0fbe4abc | 2020-09-18 02:15:13 | [diff] [blame] | 27 | virtual ~KeyboardDelegate() = default; |
| 28 | |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 29 | // This should return true if |surface| is a valid target for this keyboard. |
| 30 | // E.g. the surface is owned by the same client as the keyboard. |
| 31 | virtual bool CanAcceptKeyboardEventsForSurface(Surface* surface) const = 0; |
| 32 | |
| 33 | // Called when keyboard focus enters a new valid target surface. |
| 34 | virtual void OnKeyboardEnter( |
| 35 | Surface* surface, |
David Padlipsky | 20258f2 | 2024-02-17 01:50:02 | [diff] [blame] | 36 | const base::flat_map<PhysicalCode, base::flat_set<KeyState>>& |
David Padlipsky | 544ae2a0 | 2024-02-17 01:25:06 | [diff] [blame] | 37 | pressed_keys) = 0; |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 38 | |
| 39 | // Called when keyboard focus leaves a valid target surface. |
| 40 | virtual void OnKeyboardLeave(Surface* surface) = 0; |
| 41 | |
Hidehiko Abe | b477f01 | 2021-03-30 04:28:27 | [diff] [blame] | 42 | // Called when keyboard key state changed. |pressed| is true when a key with |
| 43 | // |code| was pressed and false if it was released. Should return the serial |
yhanada | 6b8fafc5 | 2017-07-27 11:40:34 | [diff] [blame] | 44 | // number that will be used by the client to acknowledge the change in |
| 45 | // key state. |
| 46 | virtual uint32_t OnKeyboardKey(base::TimeTicks time_stamp, |
Hidehiko Abe | b477f01 | 2021-03-30 04:28:27 | [diff] [blame] | 47 | ui::DomCode code, |
yhanada | 6b8fafc5 | 2017-07-27 11:40:34 | [diff] [blame] | 48 | bool pressed) = 0; |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 49 | |
| 50 | // Called when keyboard modifier state changed. |
Hidehiko Abe | 3375cfe5 | 2020-09-29 08:48:26 | [diff] [blame] | 51 | virtual void OnKeyboardModifiers(const KeyboardModifiers& modifiers) = 0; |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 52 | |
Chloe Pelling | 8a2fb0a | 2020-05-05 23:12:02 | [diff] [blame] | 53 | // Called when key repeat settings are changed. |
| 54 | virtual void OnKeyRepeatSettingsChanged(bool enabled, |
| 55 | base::TimeDelta delay, |
| 56 | base::TimeDelta interval) = 0; |
Hidehiko Abe | c07fd66e | 2020-09-19 12:43:14 | [diff] [blame] | 57 | |
| 58 | // Called when keyboard layout is updated. |
Helmut Januschka | fa9871de | 2024-05-10 18:51:47 | [diff] [blame] | 59 | virtual void OnKeyboardLayoutUpdated(std::string_view keymap) = 0; |
reveman | 5cacf70c | 2015-12-09 22:50:02 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace exo |
| 63 | |
| 64 | #endif // COMPONENTS_EXO_KEYBOARD_DELEGATE_H_ |