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

Side by Side Diff: ash/system/ime/tray_ime_chromeos.cc

Issue 2920883002: chromeos: Make ash system tray directly observe IME state changes (Closed)
Patch Set: Created 3 years, 6 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 | « ash/system/ime/tray_ime_chromeos.h ('k') | ash/system/ime_menu/ime_menu_tray.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/system/ime/tray_ime_chromeos.h" 5 #include "ash/system/ime/tray_ime_chromeos.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/resources/vector_icons/vector_icons.h" 10 #include "ash/resources/vector_icons/vector_icons.h"
(...skipping 11 matching lines...) Expand all
22 #include "ash/system/tray/tray_popup_item_style.h" 22 #include "ash/system/tray/tray_popup_item_style.h"
23 #include "ash/system/tray/tray_popup_utils.h" 23 #include "ash/system/tray/tray_popup_utils.h"
24 #include "ash/system/tray/tray_utils.h" 24 #include "ash/system/tray/tray_utils.h"
25 #include "ash/system/tray/tri_view.h" 25 #include "ash/system/tray/tri_view.h"
26 #include "ash/system/tray_accessibility.h" 26 #include "ash/system/tray_accessibility.h"
27 #include "base/logging.h" 27 #include "base/logging.h"
28 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
29 #include "components/strings/grit/components_strings.h" 29 #include "components/strings/grit/components_strings.h"
30 #include "ui/accessibility/ax_enums.h" 30 #include "ui/accessibility/ax_enums.h"
31 #include "ui/accessibility/ax_node_data.h" 31 #include "ui/accessibility/ax_node_data.h"
32 #include "ui/base/ime/chromeos/input_method_manager.h"
33 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/gfx/font.h" 33 #include "ui/gfx/font.h"
35 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
36 #include "ui/gfx/paint_vector_icon.h" 35 #include "ui/gfx/paint_vector_icon.h"
37 #include "ui/keyboard/keyboard_util.h" 36 #include "ui/keyboard/keyboard_util.h"
38 #include "ui/views/controls/image_view.h" 37 #include "ui/views/controls/image_view.h"
39 #include "ui/views/controls/label.h" 38 #include "ui/views/controls/label.h"
40 #include "ui/views/layout/box_layout.h" 39 #include "ui/views/layout/box_layout.h"
41 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
42 41
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 TrayIME::TrayIME(SystemTray* system_tray) 150 TrayIME::TrayIME(SystemTray* system_tray)
152 : SystemTrayItem(system_tray, UMA_IME), 151 : SystemTrayItem(system_tray, UMA_IME),
153 tray_label_(NULL), 152 tray_label_(NULL),
154 default_(NULL), 153 default_(NULL),
155 detailed_(NULL), 154 detailed_(NULL),
156 keyboard_suppressed_(false), 155 keyboard_suppressed_(false),
157 is_visible_(true) { 156 is_visible_(true) {
158 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); 157 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier();
159 tray_notifier->AddVirtualKeyboardObserver(this); 158 tray_notifier->AddVirtualKeyboardObserver(this);
160 tray_notifier->AddAccessibilityObserver(this); 159 tray_notifier->AddAccessibilityObserver(this);
161 tray_notifier->AddIMEObserver(this); 160
161 // May be null in tests.
162 InputMethodManager* input_method_manager = InputMethodManager::Get();
163 if (input_method_manager) {
164 input_method_manager->AddObserver(this);
165 input_method_manager->AddImeMenuObserver(this);
166 }
167 ui::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
162 } 168 }
163 169
164 TrayIME::~TrayIME() { 170 TrayIME::~TrayIME() {
171 ui::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this);
172 InputMethodManager* input_method_manager = InputMethodManager::Get();
173 if (input_method_manager) {
174 input_method_manager->RemoveImeMenuObserver(this);
175 input_method_manager->RemoveObserver(this);
176 }
177
165 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); 178 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier();
166 tray_notifier->RemoveIMEObserver(this);
167 tray_notifier->RemoveAccessibilityObserver(this); 179 tray_notifier->RemoveAccessibilityObserver(this);
168 tray_notifier->RemoveVirtualKeyboardObserver(this); 180 tray_notifier->RemoveVirtualKeyboardObserver(this);
169 } 181 }
170 182
171 void TrayIME::OnKeyboardSuppressionChanged(bool suppressed) { 183 void TrayIME::OnKeyboardSuppressionChanged(bool suppressed) {
172 keyboard_suppressed_ = suppressed; 184 keyboard_suppressed_ = suppressed;
173 Update(); 185 Update();
174 } 186 }
175 187
176 void TrayIME::OnAccessibilityModeChanged( 188 void TrayIME::OnAccessibilityModeChanged(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 270 }
259 271
260 void TrayIME::DestroyDefaultView() { 272 void TrayIME::DestroyDefaultView() {
261 default_ = NULL; 273 default_ = NULL;
262 } 274 }
263 275
264 void TrayIME::DestroyDetailedView() { 276 void TrayIME::DestroyDetailedView() {
265 detailed_ = NULL; 277 detailed_ = NULL;
266 } 278 }
267 279
268 void TrayIME::OnIMERefresh() { 280 void TrayIME::RefreshCurrentIme() {
269 // Caches the current ime state. 281 // Caches the current ime state.
270 current_ime_ = ime_util::GetCurrentIME(); 282 current_ime_ = ime_util::GetCurrentIME();
271 ime_list_ = ime_util::GetAvailableIMEList(); 283 ime_list_ = ime_util::GetAvailableIMEList();
272 property_list_ = ime_util::GetCurrentIMEProperties(); 284 property_list_ = ime_util::GetCurrentIMEProperties();
273 auto ime_state = InputMethodManager::Get()->GetActiveIMEState(); 285 auto ime_state = InputMethodManager::Get()->GetActiveIMEState();
274 ime_managed_message_ = 286 ime_managed_message_ =
275 ime_state->GetAllowedInputMethods().empty() 287 ime_state->GetAllowedInputMethods().empty()
276 ? base::string16() 288 ? base::string16()
277 : l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY); 289 : l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY);
278 290
279 Update(); 291 Update();
280 } 292 }
281 293
282 void TrayIME::OnIMEMenuActivationChanged(bool is_active) { 294 // InputMethodManager::Observer:
295 void TrayIME::InputMethodChanged(InputMethodManager* manager,
296 Profile* profile,
297 bool show_message) {
298 RefreshCurrentIme();
299 }
300
301 // InputMethodMenuManager::Observer:
302 void TrayIME::ImeMenuActivationChanged(bool is_active) {
283 is_visible_ = !is_active; 303 is_visible_ = !is_active;
284 if (is_visible_) 304 if (is_visible_)
285 OnIMERefresh(); 305 RefreshCurrentIme();
286 else 306 else
287 Update(); 307 Update();
288 } 308 }
289 309
310 void TrayIME::ImeMenuListChanged() {}
311
312 void TrayIME::ImeMenuItemsChanged(
313 const std::string& engine_id,
314 const std::vector<InputMethodManager::MenuItem>& items) {}
315
316 // ui::ime::InputMethodMenuManager::Observer:
317 void TrayIME::InputMethodMenuItemChanged(
318 ui::ime::InputMethodMenuManager* manager) {
319 RefreshCurrentIme();
320 }
321
290 bool TrayIME::IsIMEManaged() { 322 bool TrayIME::IsIMEManaged() {
291 return !ime_managed_message_.empty(); 323 return !ime_managed_message_.empty();
292 } 324 }
293 325
294 bool TrayIME::ShouldDefaultViewBeVisible() { 326 bool TrayIME::ShouldDefaultViewBeVisible() {
295 return is_visible_ && 327 return is_visible_ &&
296 (ShouldShowImeTrayItem(ime_list_.size()) || 328 (ShouldShowImeTrayItem(ime_list_.size()) ||
297 property_list_.size() > 1 || ShouldShowKeyboardToggle()); 329 property_list_.size() > 1 || ShouldShowKeyboardToggle());
298 } 330 }
299 331
300 bool TrayIME::ShouldShowImeTrayItem(size_t ime_count) { 332 bool TrayIME::ShouldShowImeTrayItem(size_t ime_count) {
301 // If managed, we want to show the tray icon even if there's only one input 333 // If managed, we want to show the tray icon even if there's only one input
302 // method to choose from. 334 // method to choose from.
303 size_t threshold = IsIMEManaged() ? 1 : 2; 335 size_t threshold = IsIMEManaged() ? 1 : 2;
304 return ime_count >= threshold; 336 return ime_count >= threshold;
305 } 337 }
306 338
307 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() { 339 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() {
308 // If managed, we also want to show a single IME. 340 // If managed, we also want to show a single IME.
309 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME 341 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME
310 : ImeListView::HIDE_SINGLE_IME; 342 : ImeListView::HIDE_SINGLE_IME;
311 } 343 }
312 344
313 } // namespace ash 345 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/ime/tray_ime_chromeos.h ('k') | ash/system/ime_menu/ime_menu_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698