1 // Copyright 2016 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 CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_KEYBOARD_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_KEYBOARD_HANDLER_H_
7 
8 #include "base/macros.h"
9 #include "base/scoped_observer.h"
10 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
11 #include "ui/events/devices/device_data_manager.h"
12 #include "ui/events/devices/input_device_event_observer.h"
13 
14 namespace base {
15 class ListValue;
16 }
17 
18 namespace chromeos {
19 namespace settings {
20 
21 // Chrome OS "Keyboard" settings page UI handler.
22 class KeyboardHandler
23     : public ::settings::SettingsPageUIHandler,
24       public ui::InputDeviceEventObserver {
25  public:
26   // Name of the message sent to WebUI when the keys that should be shown
27   // change.
28   static const char kShowKeysChangedName[];
29 
30   // Class used by tests to interact with KeyboardHandler internals.
31   class TestAPI {
32    public:
TestAPI(KeyboardHandler * handler)33     explicit TestAPI(KeyboardHandler* handler) { handler_ = handler; }
34 
35     // Simulates a request from WebUI to initialize the page.
36     void Initialize();
37 
38    private:
39     KeyboardHandler* handler_;  // Not owned.
40     DISALLOW_COPY_AND_ASSIGN(TestAPI);
41   };
42 
43   KeyboardHandler();
44   ~KeyboardHandler() override;
45 
46   // SettingsPageUIHandler implementation.
47   void RegisterMessages() override;
48   void OnJavascriptAllowed() override;
49   void OnJavascriptDisallowed() override;
50 
51   // ui::InputDeviceEventObserver implementation.
52   void OnInputDeviceConfigurationChanged(uint8_t input_device_types) override;
53 
54  private:
55   // Initializes the page with the current keyboard information.
56   void HandleInitialize(const base::ListValue* args);
57 
58   // Shows the Ash keyboard shortcut viewer.
59   void HandleShowKeyboardShortcutViewer(const base::ListValue* args) const;
60 
61   // Determines what types of keyboards are attached.
62   void HandleKeyboardChange(const base::ListValue* args);
63 
64   // Shows or hides the Caps Lock and Diamond key settings based on whether the
65   // system status.
66   void UpdateShowKeys();
67 
68   // Sends the UI a message about whether hardware keyboard are attached.
69   void UpdateKeyboards();
70 
71   ScopedObserver<ui::DeviceDataManager, ui::InputDeviceEventObserver> observer_{
72       this};
73 
74   DISALLOW_COPY_AND_ASSIGN(KeyboardHandler);
75 };
76 
77 }  // namespace settings
78 }  // namespace chromeos
79 
80 #endif  // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_KEYBOARD_HANDLER_H_
81