Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: ash/common/keyboard/keyboard_ui.cc

Issue 2201323002: Simplify VirtualKeyboardTray (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ash/common/keyboard/keyboard_ui_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/keyboard/keyboard_ui.h" 5 #include "ash/common/keyboard/keyboard_ui.h"
6 6
7 #include "ash/common/accessibility_delegate.h" 7 #include "ash/common/accessibility_delegate.h"
8 #include "ash/common/keyboard/keyboard_ui_observer.h" 8 #include "ash/common/keyboard/keyboard_ui_observer.h"
9 #include "ash/common/system/accessibility_observer.h" 9 #include "ash/common/system/accessibility_observer.h"
10 #include "ash/common/system/tray/system_tray_notifier.h" 10 #include "ash/common/system/tray/system_tray_notifier.h"
11 #include "ash/common/system/tray_accessibility.h" 11 #include "ash/common/system/tray_accessibility.h"
12 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "ui/keyboard/keyboard_controller.h" 14 #include "ui/keyboard/keyboard_controller.h"
15 15
16 namespace ash { 16 namespace ash {
17 17
18 class KeyboardUIImpl : public KeyboardUI, public AccessibilityObserver { 18 class KeyboardUIImpl : public KeyboardUI, public AccessibilityObserver {
19 public: 19 public:
20 KeyboardUIImpl() { 20 KeyboardUIImpl() : enabled_(false) {
21 WmShell::Get()->system_tray_notifier()->AddAccessibilityObserver(this); 21 WmShell::Get()->system_tray_notifier()->AddAccessibilityObserver(this);
22 } 22 }
23 23
24 ~KeyboardUIImpl() override { 24 ~KeyboardUIImpl() override {
25 if (WmShell::HasInstance() && WmShell::Get()->system_tray_notifier()) 25 if (WmShell::HasInstance() && WmShell::Get()->system_tray_notifier())
26 WmShell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(this); 26 WmShell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(this);
27 } 27 }
28 28
29 // KeyboardUI: 29 // KeyboardUI:
30 void Show() override { 30 void Show() override {
31 keyboard::KeyboardController::GetInstance()->ShowKeyboard(true); 31 keyboard::KeyboardController::GetInstance()->ShowKeyboard(true);
32 } 32 }
33 void Hide() override { 33 void Hide() override {
34 // Do nothing as this is called from ash::Shell, which also calls through 34 // Do nothing as this is called from ash::Shell, which also calls through
35 // to the appropriate keyboard functions. 35 // to the appropriate keyboard functions.
36 } 36 }
37 bool IsEnabled() override { 37 bool IsEnabled() override {
38 return WmShell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); 38 return WmShell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled();
39 } 39 }
40 40
41 // AccessibilityObserver: 41 // AccessibilityObserver:
42 void OnAccessibilityModeChanged( 42 void OnAccessibilityModeChanged(
43 AccessibilityNotificationVisibility notify) override { 43 AccessibilityNotificationVisibility notify) override {
44 bool enabled = IsEnabled();
45 if (enabled_ == enabled)
46 return;
47
48 enabled_ = enabled;
44 FOR_EACH_OBSERVER(KeyboardUIObserver, *observers(), 49 FOR_EACH_OBSERVER(KeyboardUIObserver, *observers(),
45 OnKeyboardEnabledStateChanged(IsEnabled())); 50 OnKeyboardEnabledStateChanged(enabled));
46 } 51 }
47 52
48 private: 53 private:
54 bool enabled_;
55
49 DISALLOW_COPY_AND_ASSIGN(KeyboardUIImpl); 56 DISALLOW_COPY_AND_ASSIGN(KeyboardUIImpl);
50 }; 57 };
51 58
52 KeyboardUI::~KeyboardUI() {} 59 KeyboardUI::~KeyboardUI() {}
53 60
54 // static 61 // static
55 std::unique_ptr<KeyboardUI> KeyboardUI::Create() { 62 std::unique_ptr<KeyboardUI> KeyboardUI::Create() {
56 return base::WrapUnique(new KeyboardUIImpl); 63 return base::WrapUnique(new KeyboardUIImpl);
57 } 64 }
58 65
59 void KeyboardUI::AddObserver(KeyboardUIObserver* observer) { 66 void KeyboardUI::AddObserver(KeyboardUIObserver* observer) {
60 observers_.AddObserver(observer); 67 observers_.AddObserver(observer);
61 } 68 }
62 69
63 void KeyboardUI::RemoveObserver(KeyboardUIObserver* observer) { 70 void KeyboardUI::RemoveObserver(KeyboardUIObserver* observer) {
64 observers_.RemoveObserver(observer); 71 observers_.RemoveObserver(observer);
65 } 72 }
66 73
67 KeyboardUI::KeyboardUI() {} 74 KeyboardUI::KeyboardUI() {}
68 75
69 } // namespace ash 76 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/keyboard/keyboard_ui_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698