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