Commit 22603a76 authored by komatsu@chromium.org's avatar komatsu@chromium.org

Create ModeIndicatorController

This class is a controller of ModeIndicatorWidget.

BUG=177765

Review URL: https://codereview.chromium.org/25670002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226445 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f61f796
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/input_method/mode_indicator_controller.h"
#include "chrome/browser/chromeos/input_method/mode_indicator_widget.h"
namespace chromeos {
namespace input_method {
namespace {
// Show mode indicator with the current ime's short name.
void ShowModeIndicator(InputMethodManager* manager,
ModeIndicatorWidget* mi_widget) {
DCHECK(manager);
DCHECK(mi_widget);
// Get the short name of the changed input method (e.g. US, JA, etc.)
const InputMethodDescriptor descriptor = manager->GetCurrentInputMethod();
const std::string short_name = UTF16ToUTF8(
manager->GetInputMethodUtil()->GetInputMethodShortName(descriptor));
mi_widget->SetLabelTextUtf8(short_name);
// Show the widget and hide it after 750msec.
mi_widget->Show();
const int kDelayMSec = 750;
mi_widget->DelayHide(kDelayMSec);
}
} // namespace
ModeIndicatorController::ModeIndicatorController(
ModeIndicatorWidget *mi_widget) {
mi_widget_.reset(mi_widget);
}
ModeIndicatorController::~ModeIndicatorController() {
}
void ModeIndicatorController::SetCursorLocation(
const gfx::Rect& cursor_location) {
mi_widget_->SetCursorLocation(cursor_location);
}
void ModeIndicatorController::InputMethodChanged(InputMethodManager* manager,
bool show_message) {
if (!show_message)
return;
ShowModeIndicator(manager, mi_widget_.get());
}
void ModeIndicatorController::InputMethodPropertyChanged(
InputMethodManager* manager) {
// Do nothing.
}
} // namespace input_method
} // namespace chromeos
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MODE_INDICATOR_CONTROLLER_H_
#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MODE_INDICATOR_CONTROLLER_H_
#include "base/memory/scoped_ptr.h"
#include "chromeos/ime/input_method_manager.h"
namespace gfx {
class Rect;
} // namespace gfx
namespace chromeos {
namespace input_method {
class ModeIndicatorWidget;
// ModeIndicatorController is the controller of ModeIndicatiorWidget on the
// MVC model.
class ModeIndicatorController
: public InputMethodManager::Observer {
public:
// This class takes the ownership of |mi_widget|.
explicit ModeIndicatorController(ModeIndicatorWidget *mi_widget);
virtual ~ModeIndicatorController();
// Set cursor location, which is the base point to display this indicator.
// Bacisally this indicator is displayed underneath the cursor.
void SetCursorLocation(const gfx::Rect& cursor_location);
private:
// InputMethodManager::Observer implementation.
virtual void InputMethodChanged(InputMethodManager* manager,
bool show_message) OVERRIDE;
virtual void InputMethodPropertyChanged(InputMethodManager* manager) OVERRIDE;
scoped_ptr<ModeIndicatorWidget> mi_widget_;
DISALLOW_COPY_AND_ASSIGN(ModeIndicatorController);
};
} // namespace input_method
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_MODE_INDICATOR_CONTROLLER_H_
......@@ -403,6 +403,8 @@
'browser/chromeos/input_method/component_extension_ime_manager_impl.h',
'browser/chromeos/input_method/mock_ibus_controller.cc',
'browser/chromeos/input_method/mock_ibus_controller.h',
'browser/chromeos/input_method/mode_indicator_controller.cc',
'browser/chromeos/input_method/mode_indicator_controller.h',
'browser/chromeos/input_method/mode_indicator_view.cc',
'browser/chromeos/input_method/mode_indicator_view.h',
'browser/chromeos/input_method/mode_indicator_widget.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment