blob: 4990b979f0b3eb1e7580b0c351b199cb61e97604 [file] [log] [blame]
reveman5cacf70c2015-12-09 22:50:021// 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 Gallea1310d8a2018-11-14 23:07:218#include "base/containers/flat_map.h"
Hidehiko Abe3375cfe52020-09-29 08:48:269#include "base/strings/string_piece.h"
reveman5cacf70c2015-12-09 22:50:0210#include "base/time/time.h"
11
12namespace ui {
13enum class DomCode;
14}
15
16namespace exo {
Hidehiko Abe3375cfe52020-09-29 08:48:2617struct KeyboardModifiers;
reveman5cacf70c2015-12-09 22:50:0218class Surface;
19
20// Handles events on keyboards in context-specific ways.
21class KeyboardDelegate {
22 public:
Hidehiko Abe0fbe4abc2020-09-18 02:15:1323 virtual ~KeyboardDelegate() = default;
24
reveman5cacf70c2015-12-09 22:50:0225 // 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 Reveman94a6f1a2018-06-25 17:04:5532 const base::flat_map<ui::DomCode, ui::DomCode>& pressed_keys) = 0;
reveman5cacf70c2015-12-09 22:50:0233
34 // Called when keyboard focus leaves a valid target surface.
35 virtual void OnKeyboardLeave(Surface* surface) = 0;
36
Hidehiko Abeb477f012021-03-30 04:28:2737 // 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
yhanada6b8fafc52017-07-27 11:40:3439 // 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 Abeb477f012021-03-30 04:28:2742 ui::DomCode code,
yhanada6b8fafc52017-07-27 11:40:3443 bool pressed) = 0;
reveman5cacf70c2015-12-09 22:50:0244
45 // Called when keyboard modifier state changed.
Hidehiko Abe3375cfe52020-09-29 08:48:2646 virtual void OnKeyboardModifiers(const KeyboardModifiers& modifiers) = 0;
reveman5cacf70c2015-12-09 22:50:0247
Chloe Pelling8a2fb0a2020-05-05 23:12:0248 // Called when key repeat settings are changed.
49 virtual void OnKeyRepeatSettingsChanged(bool enabled,
50 base::TimeDelta delay,
51 base::TimeDelta interval) = 0;
Hidehiko Abec07fd66e2020-09-19 12:43:1452
53 // Called when keyboard layout is updated.
Hidehiko Abe3375cfe52020-09-29 08:48:2654 virtual void OnKeyboardLayoutUpdated(base::StringPiece keymap) = 0;
reveman5cacf70c2015-12-09 22:50:0255};
56
57} // namespace exo
58
59#endif // COMPONENTS_EXO_KEYBOARD_DELEGATE_H_