This source file includes following definitions.
- AddModeIndicatorWidget
- OnWidgetDestroying
- mi_observer_
- SetCursorBounds
- FocusStateChanged
- SetModeIndicatorObserverForTesting
- GetModeIndicatorObserverForTesting
- InputMethodChanged
- ShowModeIndicator
#include "chrome/browser/chromeos/input_method/mode_indicator_controller.h"
#include "ash/ime/mode_indicator_view.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/window_util.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
namespace chromeos {
namespace input_method {
namespace {
ModeIndicatorObserverInterface* g_mode_indicator_observer_for_testing_ = NULL;
}
class ModeIndicatorObserver : public ModeIndicatorObserverInterface {
public:
ModeIndicatorObserver()
: active_widget_(NULL) {}
virtual ~ModeIndicatorObserver() {
if (active_widget_)
active_widget_->RemoveObserver(this);
}
virtual void AddModeIndicatorWidget(views::Widget* widget) OVERRIDE {
DCHECK(widget);
if (active_widget_)
active_widget_->Close();
active_widget_ = widget;
widget->AddObserver(this);
}
virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE {
if (widget == active_widget_)
active_widget_ = NULL;
}
private:
views::Widget* active_widget_;
};
ModeIndicatorController::ModeIndicatorController(InputMethodManager* imm)
: imm_(imm),
is_focused_(false),
mi_observer_(new ModeIndicatorObserver) {
DCHECK(imm_);
imm_->AddObserver(this);
}
ModeIndicatorController::~ModeIndicatorController() {
imm_->RemoveObserver(this);
}
void ModeIndicatorController::SetCursorBounds(
const gfx::Rect& cursor_bounds) {
cursor_bounds_ = cursor_bounds;
}
void ModeIndicatorController::FocusStateChanged(bool is_focused) {
is_focused_ = is_focused;
}
void ModeIndicatorController::SetModeIndicatorObserverForTesting(
ModeIndicatorObserverInterface* observer) {
g_mode_indicator_observer_for_testing_ = observer;
}
ModeIndicatorObserverInterface*
ModeIndicatorController::GetModeIndicatorObserverForTesting() {
return g_mode_indicator_observer_for_testing_;
}
void ModeIndicatorController::InputMethodChanged(InputMethodManager* manager,
bool show_message) {
if (!show_message)
return;
ShowModeIndicator();
}
void ModeIndicatorController::ShowModeIndicator() {
if (!is_focused_)
return;
const InputMethodDescriptor descriptor = imm_->GetCurrentInputMethod();
const base::string16 short_name =
imm_->GetInputMethodUtil()->GetInputMethodShortName(descriptor);
aura::Window* parent =
ash::Shell::GetContainer(ash::wm::GetActiveWindow()->GetRootWindow(),
ash::kShellWindowId_InputMethodContainer);
ash::ime::ModeIndicatorView* mi_view = new ash::ime::ModeIndicatorView(
parent, cursor_bounds_, short_name);
views::BubbleDelegateView::CreateBubble(mi_view);
views::Widget* mi_widget = mi_view->GetWidget();
if (GetModeIndicatorObserverForTesting())
GetModeIndicatorObserverForTesting()->AddModeIndicatorWidget(mi_widget);
mi_observer_->AddModeIndicatorWidget(mi_widget);
mi_view->ShowAndFadeOut();
}
}
}