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 "base/command_line.h"
6 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/input_method/input_method_util.h"
9 #include "chrome/browser/chromeos/input_method/mode_indicator_controller.h"
10 #include "chrome/browser/chromeos/input_method/mode_indicator_widget.h"
11 #include "chromeos/chromeos_switches.h"
14 namespace input_method {
17 // Show mode indicator with the current ime's short name.
18 void ShowModeIndicator(InputMethodManager* manager,
19 ModeIndicatorWidget* mi_widget) {
20 // Need the flag, --enable-ime-mode-indicator at this moment.
21 // TODO(komatsu): When this is enabled by defalut, delete command_line.h
22 // and chromeos_switches.h from the header files.
23 if (!CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kEnableIMEModeIndicator))
30 // Get the short name of the changed input method (e.g. US, JA, etc.)
31 const InputMethodDescriptor descriptor = manager->GetCurrentInputMethod();
32 const std::string short_name = UTF16ToUTF8(
33 manager->GetInputMethodUtil()->GetInputMethodShortName(descriptor));
34 mi_widget->SetLabelTextUtf8(short_name);
36 // Show the widget and hide it after 750msec.
38 const int kDelayMSec = 750;
39 mi_widget->DelayHide(kDelayMSec);
43 ModeIndicatorController::ModeIndicatorController(
44 ModeIndicatorWidget* mi_widget) {
45 mi_widget_.reset(mi_widget);
47 InputMethodManager* imm = InputMethodManager::Get();
49 imm->AddObserver(this);
52 ModeIndicatorController::~ModeIndicatorController() {
53 InputMethodManager* imm = InputMethodManager::Get();
55 imm->RemoveObserver(this);
58 void ModeIndicatorController::SetCursorLocation(
59 const gfx::Rect& cursor_location) {
60 mi_widget_->SetCursorLocation(cursor_location);
63 void ModeIndicatorController::InputMethodChanged(InputMethodManager* manager,
68 ShowModeIndicator(manager, mi_widget_.get());
71 void ModeIndicatorController::InputMethodPropertyChanged(
72 InputMethodManager* manager) {
76 } // namespace input_method
77 } // namespace chromeos