1 // Copyright 2013 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.
5 #include "chrome/browser/chromeos/input_method/mode_indicator_controller.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/window_util.h"
10 #include "base/logging.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chromeos/input_method/input_method_util.h"
13 #include "ui/chromeos/ime/mode_indicator_view.h"
16 namespace input_method
{
19 ModeIndicatorObserverInterface
* g_mode_indicator_observer_for_testing_
= NULL
;
22 class ModeIndicatorObserver
: public ModeIndicatorObserverInterface
{
24 ModeIndicatorObserver()
25 : active_widget_(NULL
) {}
27 ~ModeIndicatorObserver() override
{
29 active_widget_
->RemoveObserver(this);
32 // If other active mode indicator widget is shown, close it immedicately
33 // without fading animation. Then store this widget as the active widget.
34 void AddModeIndicatorWidget(views::Widget
* widget
) override
{
37 active_widget_
->Close();
38 active_widget_
= widget
;
39 widget
->AddObserver(this);
42 // views::WidgetObserver override:
43 void OnWidgetDestroying(views::Widget
* widget
) override
{
44 if (widget
== active_widget_
)
45 active_widget_
= NULL
;
49 views::Widget
* active_widget_
;
53 ModeIndicatorController::ModeIndicatorController(InputMethodManager
* imm
)
56 mi_observer_(new ModeIndicatorObserver
) {
58 imm_
->AddObserver(this);
61 ModeIndicatorController::~ModeIndicatorController() {
62 imm_
->RemoveObserver(this);
65 void ModeIndicatorController::SetCursorBounds(
66 const gfx::Rect
& cursor_bounds
) {
67 cursor_bounds_
= cursor_bounds
;
70 void ModeIndicatorController::FocusStateChanged(bool is_focused
) {
71 is_focused_
= is_focused
;
75 void ModeIndicatorController::SetModeIndicatorObserverForTesting(
76 ModeIndicatorObserverInterface
* observer
) {
77 g_mode_indicator_observer_for_testing_
= observer
;
81 ModeIndicatorObserverInterface
*
82 ModeIndicatorController::GetModeIndicatorObserverForTesting() {
83 return g_mode_indicator_observer_for_testing_
;
86 void ModeIndicatorController::InputMethodChanged(InputMethodManager
* manager
,
93 void ModeIndicatorController::ShowModeIndicator() {
94 // TODO(komatsu): Show the mode indicator in the right bottom of the
95 // display when the launch bar is hidden and the focus is out. To
96 // implement it, we should consider to use message center or system
97 // notification. Note, launch bar can be vertical and can be placed
98 // right/left side of display.
102 // Get the short name of the changed input method (e.g. US, JA, etc.)
103 const InputMethodDescriptor descriptor
=
104 imm_
->GetActiveIMEState()->GetCurrentInputMethod();
105 const base::string16 short_name
=
106 imm_
->GetInputMethodUtil()->GetInputMethodShortName(descriptor
);
108 aura::Window
* parent
=
109 ash::Shell::GetContainer(ash::wm::GetActiveWindow()->GetRootWindow(),
110 ash::kShellWindowId_SettingBubbleContainer
);
111 ui::ime::ModeIndicatorView
* mi_view
= new ui::ime::ModeIndicatorView(
112 parent
, cursor_bounds_
, short_name
);
113 views::BubbleDelegateView::CreateBubble(mi_view
);
115 views::Widget
* mi_widget
= mi_view
->GetWidget();
116 if (GetModeIndicatorObserverForTesting())
117 GetModeIndicatorObserverForTesting()->AddModeIndicatorWidget(mi_widget
);
119 mi_observer_
->AddModeIndicatorWidget(mi_widget
);
120 mi_view
->ShowAndFadeOut();
123 } // namespace input_method
124 } // namespace chromeos