1 // Copyright 2014 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 ASH_KEYBOARD_VIRTUAL_KEYBOARD_CONTROLLER_H_
6 #define ASH_KEYBOARD_VIRTUAL_KEYBOARD_CONTROLLER_H_
7 
8 #include <stdint.h>
9 
10 #include "ash/ash_export.h"
11 #include "ash/bluetooth_devices_observer.h"
12 #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
13 #include "ash/public/cpp/session/session_observer.h"
14 #include "ash/public/cpp/tablet_mode_observer.h"
15 #include "base/macros.h"
16 #include "ui/base/ime/chromeos/ime_keyset.h"
17 #include "ui/events/devices/input_device_event_observer.h"
18 
19 namespace ash {
20 
21 // This class observes input device changes for the virtual keyboard.
22 // TODO(https://crbug.com/849995): Should rename this to not confuse it with
23 // KeyboardController. |ForceShowKeyboardWithKeyset| also does not really
24 // belong here based on the current class description.
25 class ASH_EXPORT VirtualKeyboardController
26     : public TabletModeObserver,
27       public ui::InputDeviceEventObserver,
28       public KeyboardControllerObserver,
29       public SessionObserver {
30  public:
31   VirtualKeyboardController();
32   ~VirtualKeyboardController() override;
33 
34   // Force enable the keyboard and show it with the given keyset: none, emoji,
35   // handwriting or voice. Works even in laptop mode.
36   void ForceShowKeyboardWithKeyset(chromeos::input_method::ImeKeyset keyset);
37 
38   // TabletModeObserver:
39   void OnTabletModeEventsBlockingChanged() override;
40 
41   // ui::InputDeviceEventObserver:
42   void OnInputDeviceConfigurationChanged(uint8_t input_device_types) override;
43 
44   // Toggles whether the presence of an external keyboard should be ignored
45   // when determining whether or not to show the on-screen keyboard.
46   void ToggleIgnoreExternalKeyboard();
47 
48   // KeyboardControllerObserver:
49   void OnKeyboardEnabledChanged(bool is_enabled) override;
50   void OnKeyboardHidden(bool is_temporary_hide) override;
51 
52   // SessionObserver:
53   void OnActiveUserSessionChanged(const AccountId& account_id) override;
54 
55  private:
56   // Updates the list of active input devices.
57   void UpdateDevices();
58 
59   // Updates the keyboard state.
60   void UpdateKeyboardEnabled();
61 
62   // Force enable the keyboard and show it, even in laptop mode.
63   void ForceShowKeyboard();
64 
65   // Callback function of |bluetooth_devices_observer_|. Called when the
66   // bluetooth adapter or |device| changes.
67   void OnBluetoothAdapterOrDeviceChanged(device::BluetoothDevice* device);
68 
69   // True if an external keyboard is connected.
70   bool has_external_keyboard_;
71   // True if an internal keyboard is connected.
72   bool has_internal_keyboard_;
73   // True if a touchscreen is connected.
74   bool has_touchscreen_;
75   // True if the presence of an external keyboard should be ignored.
76   bool ignore_external_keyboard_;
77 
78   // Observer to observe the bluetooth devices.
79   std::unique_ptr<BluetoothDevicesObserver> bluetooth_devices_observer_;
80 
81   DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardController);
82 };
83 
84 }  // namespace ash
85 
86 #endif  // ASH_KEYBOARD_VIRTUAL_KEYBOARD_CONTROLLER_H_
87