OLD | NEW |
| (Empty) |
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 #include "ash/keyboard/keyboard_ui.h" | |
6 | |
7 #include "ash/common/accessibility_delegate.h" | |
8 #include "ash/common/system/accessibility_observer.h" | |
9 #include "ash/common/system/tray/wm_system_tray_notifier.h" | |
10 #include "ash/common/wm_shell.h" | |
11 #include "ash/keyboard/keyboard_ui_observer.h" | |
12 #include "ash/system/tray_accessibility.h" | |
13 #include "base/memory/ptr_util.h" | |
14 #include "ui/keyboard/keyboard_controller.h" | |
15 | |
16 namespace ash { | |
17 | |
18 class KeyboardUIImpl : public KeyboardUI, public AccessibilityObserver { | |
19 public: | |
20 KeyboardUIImpl() { | |
21 WmShell::Get()->system_tray_notifier()->AddAccessibilityObserver(this); | |
22 } | |
23 | |
24 ~KeyboardUIImpl() override { | |
25 if (WmShell::HasInstance() && WmShell::Get()->system_tray_notifier()) | |
26 WmShell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(this); | |
27 } | |
28 | |
29 // KeyboardUI: | |
30 void Show() override { | |
31 keyboard::KeyboardController::GetInstance()->ShowKeyboard(true); | |
32 } | |
33 void Hide() override { | |
34 // Do nothing as this is called from ash::Shell, which also calls through | |
35 // to the appropriate keyboard functions. | |
36 } | |
37 bool IsEnabled() override { | |
38 return WmShell::Get() | |
39 ->GetAccessibilityDelegate() | |
40 ->IsVirtualKeyboardEnabled(); | |
41 } | |
42 | |
43 // AccessibilityObserver: | |
44 void OnAccessibilityModeChanged( | |
45 AccessibilityNotificationVisibility notify) override { | |
46 FOR_EACH_OBSERVER(KeyboardUIObserver, *observers(), | |
47 OnKeyboardEnabledStateChanged(IsEnabled())); | |
48 } | |
49 | |
50 private: | |
51 DISALLOW_COPY_AND_ASSIGN(KeyboardUIImpl); | |
52 }; | |
53 | |
54 KeyboardUI::~KeyboardUI() {} | |
55 | |
56 // static | |
57 std::unique_ptr<KeyboardUI> KeyboardUI::Create() { | |
58 return base::WrapUnique(new KeyboardUIImpl); | |
59 } | |
60 | |
61 void KeyboardUI::AddObserver(KeyboardUIObserver* observer) { | |
62 observers_.AddObserver(observer); | |
63 } | |
64 | |
65 void KeyboardUI::RemoveObserver(KeyboardUIObserver* observer) { | |
66 observers_.RemoveObserver(observer); | |
67 } | |
68 | |
69 KeyboardUI::KeyboardUI() {} | |
70 | |
71 } // namespace ash | |
OLD | NEW |