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
,
87 Profile
* /* profile */,
94 void ModeIndicatorController::ShowModeIndicator() {
95 // TODO(komatsu): Show the mode indicator in the right bottom of the
96 // display when the launch bar is hidden and the focus is out. To
97 // implement it, we should consider to use message center or system
98 // notification. Note, launch bar can be vertical and can be placed
99 // right/left side of display.
103 // Get the short name of the changed input method (e.g. US, JA, etc.)
104 const InputMethodDescriptor descriptor
=
105 imm_
->GetActiveIMEState()->GetCurrentInputMethod();
106 const base::string16 short_name
=
107 imm_
->GetInputMethodUtil()->GetInputMethodShortName(descriptor
);
109 aura::Window
* parent
=
110 ash::Shell::GetContainer(ash::wm::GetActiveWindow()->GetRootWindow(),
111 ash::kShellWindowId_SettingBubbleContainer
);
112 ui::ime::ModeIndicatorView
* mi_view
= new ui::ime::ModeIndicatorView(
113 parent
, cursor_bounds_
, short_name
);
114 views::BubbleDelegateView::CreateBubble(mi_view
);
116 views::Widget
* mi_widget
= mi_view
->GetWidget();
117 if (GetModeIndicatorObserverForTesting())
118 GetModeIndicatorObserverForTesting()->AddModeIndicatorWidget(mi_widget
);
120 mi_observer_
->AddModeIndicatorWidget(mi_widget
);
121 mi_view
->ShowAndFadeOut();
124 } // namespace input_method
125 } // namespace chromeos