blob: 28f5e32e1f06db0cb50603fe17ed916927ff9078 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2015 The Chromium Authors
reveman5cacf70c2015-12-09 22:50:022// 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 Januschkafa9871de2024-05-10 18:51:478#include <string_view>
9
David Padlipsky20258f22024-02-17 01:50:0210#include "ash/public/mojom/input_device_settings.mojom.h"
Shawn Gallea1310d8a2018-11-14 23:07:2111#include "base/containers/flat_map.h"
David Padlipsky544ae2a02024-02-17 01:25:0612#include "base/containers/flat_set.h"
reveman5cacf70c2015-12-09 22:50:0213#include "base/time/time.h"
Hidehiko Abe190f69342021-04-02 19:58:4514#include "components/exo/key_state.h"
reveman5cacf70c2015-12-09 22:50:0215
16namespace ui {
Wezc0a18162023-10-19 16:24:5017enum class DomCode : uint32_t;
reveman5cacf70c2015-12-09 22:50:0218}
19
20namespace exo {
Hidehiko Abe3375cfe52020-09-29 08:48:2621struct KeyboardModifiers;
reveman5cacf70c2015-12-09 22:50:0222class Surface;
23
24// Handles events on keyboards in context-specific ways.
25class KeyboardDelegate {
26 public:
Hidehiko Abe0fbe4abc2020-09-18 02:15:1327 virtual ~KeyboardDelegate() = default;
28
reveman5cacf70c2015-12-09 22:50:0229 // 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 Padlipsky20258f22024-02-17 01:50:0236 const base::flat_map<PhysicalCode, base::flat_set<KeyState>>&
David Padlipsky544ae2a02024-02-17 01:25:0637 pressed_keys) = 0;
reveman5cacf70c2015-12-09 22:50:0238
39 // Called when keyboard focus leaves a valid target surface.
40 virtual void OnKeyboardLeave(Surface* surface) = 0;
41
Hidehiko Abeb477f012021-03-30 04:28:2742 // 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
yhanada6b8fafc52017-07-27 11:40:3444 // 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 Abeb477f012021-03-30 04:28:2747 ui::DomCode code,
yhanada6b8fafc52017-07-27 11:40:3448 bool pressed) = 0;
reveman5cacf70c2015-12-09 22:50:0249
50 // Called when keyboard modifier state changed.
Hidehiko Abe3375cfe52020-09-29 08:48:2651 virtual void OnKeyboardModifiers(const KeyboardModifiers& modifiers) = 0;
reveman5cacf70c2015-12-09 22:50:0252
Chloe Pelling8a2fb0a2020-05-05 23:12:0253 // Called when key repeat settings are changed.
54 virtual void OnKeyRepeatSettingsChanged(bool enabled,
55 base::TimeDelta delay,
56 base::TimeDelta interval) = 0;
Hidehiko Abec07fd66e2020-09-19 12:43:1457
58 // Called when keyboard layout is updated.
Helmut Januschkafa9871de2024-05-10 18:51:4759 virtual void OnKeyboardLayoutUpdated(std::string_view keymap) = 0;
reveman5cacf70c2015-12-09 22:50:0260};
61
62} // namespace exo
63
64#endif // COMPONENTS_EXO_KEYBOARD_DELEGATE_H_