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