OLD | NEW |
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/system/ime_menu/ime_menu_tray.h" | 5 #include "ash/system/ime_menu/ime_menu_tray.h" |
6 | 6 |
7 #include "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
8 #include "ash/ash_constants.h" | 8 #include "ash/ash_constants.h" |
9 #include "ash/resources/grit/ash_resources.h" | 9 #include "ash/resources/grit/ash_resources.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
11 #include "ash/session/session_controller.h" | 11 #include "ash/session/session_controller.h" |
12 #include "ash/shelf/shelf.h" | 12 #include "ash/shelf/shelf.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/shell_port.h" | 14 #include "ash/shell_port.h" |
15 #include "ash/strings/grit/ash_strings.h" | 15 #include "ash/strings/grit/ash_strings.h" |
16 #include "ash/system/ime/ime_util.h" | 16 #include "ash/system/ime/ime_util.h" |
17 #include "ash/system/ime_menu/ime_list_view.h" | 17 #include "ash/system/ime_menu/ime_list_view.h" |
18 #include "ash/system/tray/system_menu_button.h" | 18 #include "ash/system/tray/system_menu_button.h" |
19 #include "ash/system/tray/system_tray_controller.h" | 19 #include "ash/system/tray/system_tray_controller.h" |
20 #include "ash/system/tray/system_tray_notifier.h" | 20 #include "ash/system/tray/system_tray_notifier.h" |
21 #include "ash/system/tray/tray_constants.h" | 21 #include "ash/system/tray/tray_constants.h" |
22 #include "ash/system/tray/tray_container.h" | 22 #include "ash/system/tray/tray_container.h" |
23 #include "ash/system/tray/tray_popup_item_style.h" | 23 #include "ash/system/tray/tray_popup_item_style.h" |
24 #include "ash/system/tray/tray_popup_utils.h" | 24 #include "ash/system/tray/tray_popup_utils.h" |
25 #include "ash/system/tray/tray_utils.h" | 25 #include "ash/system/tray/tray_utils.h" |
26 #include "base/metrics/histogram_macros.h" | 26 #include "base/metrics/histogram_macros.h" |
27 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
28 #include "components/session_manager/session_manager_types.h" | 28 #include "components/session_manager/session_manager_types.h" |
29 #include "ui/base/ime/chromeos/input_method_manager.h" | |
30 #include "ui/base/ime/ime_bridge.h" | 29 #include "ui/base/ime/ime_bridge.h" |
31 #include "ui/base/ime/text_input_client.h" | 30 #include "ui/base/ime/text_input_client.h" |
32 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/gfx/paint_vector_icon.h" | 33 #include "ui/gfx/paint_vector_icon.h" |
35 #include "ui/gfx/range/range.h" | 34 #include "ui/gfx/range/range.h" |
36 #include "ui/keyboard/keyboard_controller.h" | 35 #include "ui/keyboard/keyboard_controller.h" |
37 #include "ui/keyboard/keyboard_util.h" | 36 #include "ui/keyboard/keyboard_util.h" |
38 #include "ui/views/controls/button/button.h" | 37 #include "ui/views/controls/button/button.h" |
39 #include "ui/views/controls/label.h" | 38 #include "ui/views/controls/label.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 show_keyboard_(false), | 284 show_keyboard_(false), |
286 force_show_keyboard_(false), | 285 force_show_keyboard_(false), |
287 keyboard_suppressed_(false), | 286 keyboard_suppressed_(false), |
288 show_bubble_after_keyboard_hidden_(false), | 287 show_bubble_after_keyboard_hidden_(false), |
289 weak_ptr_factory_(this) { | 288 weak_ptr_factory_(this) { |
290 SetInkDropMode(InkDropMode::ON); | 289 SetInkDropMode(InkDropMode::ON); |
291 SetupLabelForTray(label_); | 290 SetupLabelForTray(label_); |
292 label_->SetElideBehavior(gfx::TRUNCATE); | 291 label_->SetElideBehavior(gfx::TRUNCATE); |
293 tray_container()->AddChildView(label_); | 292 tray_container()->AddChildView(label_); |
294 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); | 293 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); |
295 tray_notifier->AddIMEObserver(this); | |
296 tray_notifier->AddVirtualKeyboardObserver(this); | 294 tray_notifier->AddVirtualKeyboardObserver(this); |
| 295 |
| 296 // May be null in tests. |
| 297 InputMethodManager* input_method_manager = InputMethodManager::Get(); |
| 298 if (input_method_manager) { |
| 299 input_method_manager->AddObserver(this); |
| 300 input_method_manager->AddImeMenuObserver(this); |
| 301 } |
| 302 ui::ime::InputMethodMenuManager::GetInstance()->AddObserver(this); |
297 } | 303 } |
298 | 304 |
299 ImeMenuTray::~ImeMenuTray() { | 305 ImeMenuTray::~ImeMenuTray() { |
300 if (bubble_) | 306 if (bubble_) |
301 bubble_->bubble_view()->reset_delegate(); | 307 bubble_->bubble_view()->reset_delegate(); |
| 308 ui::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this); |
| 309 InputMethodManager* input_method_manager = InputMethodManager::Get(); |
| 310 if (input_method_manager) { |
| 311 input_method_manager->RemoveImeMenuObserver(this); |
| 312 input_method_manager->RemoveObserver(this); |
| 313 } |
302 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); | 314 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); |
303 tray_notifier->RemoveIMEObserver(this); | |
304 tray_notifier->RemoveVirtualKeyboardObserver(this); | 315 tray_notifier->RemoveVirtualKeyboardObserver(this); |
305 keyboard::KeyboardController* keyboard_controller = | 316 keyboard::KeyboardController* keyboard_controller = |
306 keyboard::KeyboardController::GetInstance(); | 317 keyboard::KeyboardController::GetInstance(); |
307 if (keyboard_controller) | 318 if (keyboard_controller) |
308 keyboard_controller->RemoveObserver(this); | 319 keyboard_controller->RemoveObserver(this); |
309 } | 320 } |
310 | 321 |
311 void ImeMenuTray::ShowImeMenuBubble() { | 322 void ImeMenuTray::ShowImeMenuBubble() { |
312 keyboard::KeyboardController* keyboard_controller = | 323 keyboard::KeyboardController* keyboard_controller = |
313 keyboard::KeyboardController::GetInstance(); | 324 keyboard::KeyboardController::GetInstance(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } | 446 } |
436 | 447 |
437 bool ImeMenuTray::PerformAction(const ui::Event& event) { | 448 bool ImeMenuTray::PerformAction(const ui::Event& event) { |
438 if (bubble_) | 449 if (bubble_) |
439 HideImeMenuBubble(); | 450 HideImeMenuBubble(); |
440 else | 451 else |
441 ShowImeMenuBubble(); | 452 ShowImeMenuBubble(); |
442 return true; | 453 return true; |
443 } | 454 } |
444 | 455 |
445 void ImeMenuTray::OnIMERefresh() { | 456 void ImeMenuTray::RefreshCurrentIme() { |
446 UpdateTrayLabel(); | 457 UpdateTrayLabel(); |
447 if (bubble_ && ime_list_view_) { | 458 if (bubble_ && ime_list_view_) { |
448 IMEInfoList list = ime_util::GetAvailableIMEList(); | 459 IMEInfoList list = ime_util::GetAvailableIMEList(); |
449 IMEPropertyInfoList property_list = ime_util::GetCurrentIMEProperties(); | 460 IMEPropertyInfoList property_list = ime_util::GetCurrentIMEProperties(); |
450 ime_list_view_->Update(list, property_list, false, | 461 ime_list_view_->Update(list, property_list, false, |
451 ImeListView::SHOW_SINGLE_IME); | 462 ImeListView::SHOW_SINGLE_IME); |
452 } | 463 } |
453 } | 464 } |
454 | 465 |
455 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | 466 // InputMethodManager::Observer: |
| 467 void ImeMenuTray::InputMethodChanged(InputMethodManager* manager, |
| 468 Profile* profile, |
| 469 bool show_message) { |
| 470 RefreshCurrentIme(); |
| 471 } |
| 472 |
| 473 // InputMethodMenuManager::Observer: |
| 474 void ImeMenuTray::ImeMenuActivationChanged(bool is_activated) { |
456 SetVisible(is_activated); | 475 SetVisible(is_activated); |
457 if (is_activated) | 476 if (is_activated) |
458 UpdateTrayLabel(); | 477 UpdateTrayLabel(); |
459 else | 478 else |
460 HideImeMenuBubble(); | 479 HideImeMenuBubble(); |
461 } | 480 } |
462 | 481 |
463 void ImeMenuTray::BubbleViewDestroyed() { | 482 void ImeMenuTray::ImeMenuListChanged() {} |
| 483 |
| 484 void ImeMenuTray::ImeMenuItemsChanged( |
| 485 const std::string& engine_id, |
| 486 const std::vector<InputMethodManager::MenuItem>& items) {} |
| 487 |
| 488 // ui::ime::InputMethodMenuManager::Observer: |
| 489 void ImeMenuTray::InputMethodMenuItemChanged( |
| 490 ui::ime::InputMethodMenuManager* manager) { |
| 491 RefreshCurrentIme(); |
464 } | 492 } |
465 | 493 |
| 494 void ImeMenuTray::BubbleViewDestroyed() {} |
| 495 |
466 void ImeMenuTray::OnMouseEnteredView() {} | 496 void ImeMenuTray::OnMouseEnteredView() {} |
467 | 497 |
468 void ImeMenuTray::OnMouseExitedView() {} | 498 void ImeMenuTray::OnMouseExitedView() {} |
469 | 499 |
470 base::string16 ImeMenuTray::GetAccessibleNameForBubble() { | 500 base::string16 ImeMenuTray::GetAccessibleNameForBubble() { |
471 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 501 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
472 } | 502 } |
473 | 503 |
474 void ImeMenuTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 504 void ImeMenuTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
475 HideBubbleWithView(bubble_view); | 505 HideBubbleWithView(bubble_view); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 else | 571 else |
542 label_->SetText(current_ime_.short_name); | 572 label_->SetText(current_ime_.short_name); |
543 } | 573 } |
544 | 574 |
545 void ImeMenuTray::DisableVirtualKeyboard() { | 575 void ImeMenuTray::DisableVirtualKeyboard() { |
546 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); | 576 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); |
547 force_show_keyboard_ = false; | 577 force_show_keyboard_ = false; |
548 } | 578 } |
549 | 579 |
550 } // namespace ash | 580 } // namespace ash |
OLD | NEW |