OLD | NEW |
| (Empty) |
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 #include "ash/system/chromeos/virtual_keyboard/tray_keyboard_lock.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/system/tray/system_tray.h" | |
9 #include "ash/system/tray/tray_item_more.h" | |
10 #include "ash/system/tray_accessibility.h" | |
11 #include "ash/virtual_keyboard_controller.h" | |
12 #include "grit/ash_resources.h" | |
13 #include "grit/ash_strings.h" | |
14 #include "ui/base/l10n/l10n_util.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 #include "ui/gfx/display.h" | |
17 #include "ui/keyboard/keyboard_util.h" | |
18 | |
19 namespace ash { | |
20 | |
21 namespace tray { | |
22 | |
23 // System tray item that handles toggling the state of the keyboard between | |
24 // enabled and disabled. | |
25 class KeyboardLockDefaultView : public TrayItemMore, | |
26 public VirtualKeyboardObserver, | |
27 public AccessibilityObserver { | |
28 public: | |
29 explicit KeyboardLockDefaultView(SystemTrayItem* owner, bool suppressed); | |
30 virtual ~KeyboardLockDefaultView(); | |
31 | |
32 // ActionableView | |
33 bool PerformAction(const ui::Event& event) override; | |
34 | |
35 // VirtualKeyboardObserver | |
36 void OnKeyboardSuppressionChanged(bool suppressed) override; | |
37 | |
38 // AccessibilityObserver: | |
39 void OnAccessibilityModeChanged( | |
40 ui::AccessibilityNotificationVisibility notify) override; | |
41 | |
42 private: | |
43 void Update(); | |
44 | |
45 // Whether the virtual keyboard is suppressed. | |
46 bool suppressed_; | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(KeyboardLockDefaultView); | |
49 }; | |
50 | |
51 KeyboardLockDefaultView::KeyboardLockDefaultView(SystemTrayItem* owner, | |
52 bool suppressed) | |
53 : TrayItemMore(owner, false), suppressed_(suppressed) { | |
54 Update(); | |
55 Shell::GetInstance()->system_tray_notifier()->AddVirtualKeyboardObserver( | |
56 this); | |
57 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); | |
58 } | |
59 | |
60 KeyboardLockDefaultView::~KeyboardLockDefaultView() { | |
61 Shell::GetInstance()->system_tray_notifier()->RemoveVirtualKeyboardObserver( | |
62 this); | |
63 Shell::GetInstance()->system_tray_notifier()->RemoveAccessibilityObserver( | |
64 this); | |
65 } | |
66 | |
67 bool KeyboardLockDefaultView::PerformAction(const ui::Event& event) { | |
68 Shell::GetInstance() | |
69 ->virtual_keyboard_controller() | |
70 ->ToggleIgnoreExternalKeyboard(); | |
71 return true; | |
72 } | |
73 | |
74 void KeyboardLockDefaultView::Update() { | |
75 base::string16 label; | |
76 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
77 if (keyboard::IsKeyboardEnabled()) { | |
78 SetImage( | |
79 bundle.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD_ENABLED)); | |
80 label = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED); | |
81 } else { | |
82 SetImage( | |
83 bundle.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_VIRTUAL_KEYBOARD_DISABLED)); | |
84 label = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED); | |
85 } | |
86 SetLabel(label); | |
87 SetAccessibleName(label); | |
88 SetVisible(suppressed_ && | |
89 !Shell::GetInstance() | |
90 ->accessibility_delegate() | |
91 ->IsVirtualKeyboardEnabled()); | |
92 } | |
93 | |
94 void KeyboardLockDefaultView::OnKeyboardSuppressionChanged(bool suppressed) { | |
95 suppressed_ = suppressed; | |
96 Update(); | |
97 } | |
98 | |
99 void KeyboardLockDefaultView::OnAccessibilityModeChanged( | |
100 ui::AccessibilityNotificationVisibility notify) { | |
101 Update(); | |
102 } | |
103 | |
104 } // namespace tray | |
105 | |
106 TrayKeyboardLock::TrayKeyboardLock(SystemTray* system_tray) | |
107 : SystemTrayItem(system_tray), virtual_keyboard_suppressed_(false) { | |
108 Shell::GetInstance()->system_tray_notifier()->AddVirtualKeyboardObserver( | |
109 this); | |
110 } | |
111 | |
112 TrayKeyboardLock::~TrayKeyboardLock() { | |
113 Shell::GetInstance()->system_tray_notifier()->RemoveVirtualKeyboardObserver( | |
114 this); | |
115 } | |
116 | |
117 void TrayKeyboardLock::OnKeyboardSuppressionChanged(bool suppressed) { | |
118 virtual_keyboard_suppressed_ = suppressed; | |
119 } | |
120 | |
121 views::View* TrayKeyboardLock::CreateDefaultView(user::LoginStatus status) { | |
122 return new tray::KeyboardLockDefaultView(this, virtual_keyboard_suppressed_); | |
123 } | |
124 | |
125 } // namespace ash | |
OLD | NEW |