Commit f3964ad1 authored by yusukes@google.com's avatar yusukes@google.com

Remove multiple inheritance from input_method_menu_button.h.

Currently chromeos::InputMethodMenuButton is derived from both StatusAreaButton and InputMethodMenu, which violates the Chrome coding guideline. This change removes the multiple inheritance by adding InputMethodMenu object to InputMethodMenuButton as a member variable.

BUG=chromium-os:7572
TEST=manually & try bot

Review URL: http://codereview.chromium.org/6262012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72467 0039d316-1c4b-4281-b951-d872f2087c98
parent 57b26b16
......@@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "views/controls/button/menu_button.h"
#include "views/widget/widget_gtk.h"
namespace chromeos {
......
......@@ -9,7 +9,7 @@
#include <string>
#include "base/scoped_ptr.h"
#include "chrome/browser/chromeos/status/input_method_menu_button.h"
#include "chrome/browser/chromeos/status/input_method_menu.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
namespace chromeos {
......
......@@ -97,10 +97,6 @@ class InputMethodMenu : public views::ViewMenuDelegate,
static std::wstring GetTextForMenu(const InputMethodDescriptor& input_method);
protected:
// Parses |input_method| and then calls UpdateUI().
void UpdateUIFromInputMethod(const InputMethodDescriptor& input_method,
size_t num_active_input_methods);
// Rebuilds model and menu2 objects in preparetion to open the menu.
void PrepareForMenuOpen();
......@@ -126,6 +122,10 @@ class InputMethodMenu : public views::ViewMenuDelegate,
// customizing languages and input.
virtual void OpenConfigUI() = 0;
// Parses |input_method| and then calls UpdateUI().
void UpdateUIFromInputMethod(const InputMethodDescriptor& input_method,
size_t num_active_input_methods);
// Rebuilds |model_|. This function should be called whenever
// |input_method_descriptors_| is updated, or ImePropertiesChanged() is
// called.
......
......@@ -32,6 +32,35 @@ const int kFontSizeDelta = 0;
const int kFontSizeDelta = 1;
#endif
// A class which implements interfaces of chromeos::InputMethodMenu. This class
// is just for avoiding multiple inheritance.
class MenuImpl : public chromeos::InputMethodMenu {
public:
MenuImpl(chromeos::InputMethodMenuButton* button,
PrefService* pref_service,
chromeos::StatusAreaHost::ScreenMode screen_mode)
: InputMethodMenu(pref_service, screen_mode, false), button_(button) {}
private:
// InputMethodMenu implementation.
virtual void UpdateUI(const std::string& input_method_id,
const std::wstring& name,
const std::wstring& tooltip,
size_t num_active_input_methods) {
button_->UpdateUI(input_method_id, name, tooltip, num_active_input_methods);
}
virtual bool ShouldSupportConfigUI() {
return button_->ShouldSupportConfigUI();
}
virtual void OpenConfigUI() {
button_->OpenConfigUI();
}
// The UI (views button) to which this class delegates all requests.
chromeos::InputMethodMenuButton* button_;
DISALLOW_COPY_AND_ASSIGN(MenuImpl);
};
} // namespace
namespace chromeos {
......@@ -41,9 +70,7 @@ namespace chromeos {
InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host)
: StatusAreaButton(this),
InputMethodMenu(GetPrefService(host),
host->GetScreenMode(),
false /* for_out_of_box_experience_dialog */),
menu_(new MenuImpl(this, GetPrefService(host), host->GetScreenMode())),
host_(host) {
set_border(NULL);
set_use_menu_button_paint(true);
......@@ -63,7 +90,7 @@ InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host)
// |pref_service| is not available (for example, unit tests) or |pref_service|
// is available, but Chrome preferences are not available (for example,
// initial OS boot).
InputMethodMenuButton::UpdateUI(hardware_keyboard_id, L"US", L"", 1);
UpdateUI(hardware_keyboard_id, L"US", L"", 1);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -84,6 +111,8 @@ void InputMethodMenuButton::OnLocaleChanged() {
chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
const InputMethodDescriptor& input_method =
input_method_library->current_input_method();
const std::wstring name = InputMethodMenu::GetTextForIndicator(input_method);
const std::wstring tooltip = InputMethodMenu::GetTextForMenu(input_method);
// In general, we should not call an input method API in the input method
// button classes (status/input_menu_button*.cc) for performance reasons (see
......@@ -92,14 +121,19 @@ void InputMethodMenuButton::OnLocaleChanged() {
// to call GetNumActiveInputMethods here.
const size_t num_active_input_methods =
input_method_library->GetNumActiveInputMethods();
UpdateUI(input_method.id, name, tooltip, num_active_input_methods);
UpdateUIFromInputMethod(input_method, num_active_input_methods);
Layout();
SchedulePaint();
}
////////////////////////////////////////////////////////////////////////////////
// InputMethodMenu::InputMethodMenuHost implementation:
// views::ViewMenuDelegate implementation:
void InputMethodMenuButton::RunMenu(views::View* unused_source,
const gfx::Point& pt) {
menu_->RunMenu(unused_source, pt);
}
void InputMethodMenuButton::UpdateUI(const std::string& input_method_id,
const std::wstring& name,
......
......@@ -10,6 +10,7 @@
#include "chrome/browser/chromeos/status/input_method_menu.h"
#include "chrome/browser/chromeos/status/status_area_button.h"
#include "views/controls/menu/view_menu_delegate.h"
namespace chromeos {
......@@ -18,7 +19,7 @@ class StatusAreaHost;
// A class for the button in the status area which expands the dropdown menu for
// switching input method and keyboard layout.
class InputMethodMenuButton : public StatusAreaButton,
public InputMethodMenu {
public views::ViewMenuDelegate {
public:
explicit InputMethodMenuButton(StatusAreaHost* host);
virtual ~InputMethodMenuButton() {}
......@@ -27,7 +28,9 @@ class InputMethodMenuButton : public StatusAreaButton,
virtual gfx::Size GetPreferredSize();
virtual void OnLocaleChanged();
private:
// views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* unused_source, const gfx::Point& pt);
// InputMethodMenu implementation.
virtual void UpdateUI(const std::string& input_method_id,
const std::wstring& name,
......@@ -36,6 +39,8 @@ class InputMethodMenuButton : public StatusAreaButton,
virtual bool ShouldSupportConfigUI();
virtual void OpenConfigUI();
private:
scoped_ptr<InputMethodMenu> menu_;
StatusAreaHost* host_;
DISALLOW_COPY_AND_ASSIGN(InputMethodMenuButton);
......
......@@ -72,7 +72,7 @@
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/preferences.h"
#include "chrome/browser/chromeos/status/input_method_menu_button.h"
#include "chrome/browser/chromeos/status/input_method_menu.h"
#include "chrome/browser/chromeos/user_cros_settings_provider.h"
#endif
......@@ -110,7 +110,7 @@ void RegisterLocalState(PrefService* local_state) {
chromeos::UserManager::RegisterPrefs(local_state);
chromeos::UserCrosSettingsProvider::RegisterPrefs(local_state);
WizardController::RegisterPrefs(local_state);
chromeos::InputMethodMenuButton::RegisterPrefs(local_state);
chromeos::InputMethodMenu::RegisterPrefs(local_state);
chromeos::ApplyServicesCustomization::RegisterPrefs(local_state);
chromeos::SignedSettingsTempStorage::RegisterPrefs(local_state);
#endif
......
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