summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 12:12:42 +0000
committeryusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 12:12:42 +0000
commit5095143c11becbaaa88837a56d35ccd8677a68f7 (patch)
tree9e138c968872fec897dfd8062db542416bc83604
parentcc226f1b5bfb08121dbfdc8a29fc51258df76976 (diff)
downloadchromium_src-5095143c11becbaaa88837a56d35ccd8677a68f7.zip
chromium_src-5095143c11becbaaa88837a56d35ccd8677a68f7.tar.gz
chromium_src-5095143c11becbaaa88837a56d35ccd8677a68f7.tar.bz2
Moving Korean IME (ibus-hangul) preferences from IBus side (ibus-gconf & ibus-memconf) to Chrome side. This change should make it easier to sync the IME preferences with cloud.
BUG=crosbug.com/2299 BUG=crosbug.com/488 TEST=manual Review URL: http://codereview.chromium.org/1599005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43205 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/language_preferences.h33
-rw-r--r--chrome/browser/chromeos/options/language_config_view.cc13
-rw-r--r--chrome/browser/chromeos/options/language_config_view.h9
-rw-r--r--chrome/browser/chromeos/options/language_hangul_config_view.cc93
-rw-r--r--chrome/browser/chromeos/options/language_hangul_config_view.h28
-rw-r--r--chrome/browser/chromeos/options/system_page_view.cc2
-rw-r--r--chrome/browser/chromeos/preferences.cc30
-rw-r--r--chrome/browser/chromeos/preferences.h9
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
10 files changed, 151 insertions, 70 deletions
diff --git a/chrome/browser/chromeos/language_preferences.h b/chrome/browser/chromeos/language_preferences.h
new file mode 100644
index 0000000..3fee2e3
--- /dev/null
+++ b/chrome/browser/chromeos/language_preferences.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2010 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_LANGUAGE_PREFERENCES_H_
+#define CHROME_BROWSER_CHROMEOS_LANGUAGE_PREFERENCES_H_
+
+namespace chromeos {
+
+// For Korean IME (ibus-hangul)
+const struct HangulKeyboardNameIDPair {
+ const wchar_t* keyboard_name;
+ const wchar_t* keyboard_id;
+} kHangulKeyboardNameIDPairs[] = {
+ // We have to sync the IDs with those in ibus-hangul/files/setup/main.py.
+ { L"Dubeolsik", L"2" },
+ { L"Sebeolsik Final", L"3f" },
+ { L"Sebeolsik 390", L"39" },
+ { L"Sebeolsik No-shift", L"3s" },
+ { L"Sebeolsik 2 set", L"32" },
+ // TODO(yusukes): Use generated_resources.grd IDs for |keyboard_name|.
+};
+
+// For ibus-daemon
+// For Simplified Chinese IME (ibus-pinyin)
+// For Traditional Chinese IME (ibus-chewing)
+// For Japanese IME (ibus-google-japanese-input)
+
+// TODO(yusukes): Add constants for these components.
+} // chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_LANGUAGE_PREFERENCES_H_
+
diff --git a/chrome/browser/chromeos/options/language_config_view.cc b/chrome/browser/chromeos/options/language_config_view.cc
index f97b2c4..a442a6b 100644
--- a/chrome/browser/chromeos/options/language_config_view.cc
+++ b/chrome/browser/chromeos/options/language_config_view.cc
@@ -151,16 +151,19 @@ class InputMethodCheckbox : public views::Checkbox {
};
namespace {
+
// Creates the LanguageHangulConfigView. The function is used to create
// the object via a function pointer. See also
// InitInputMethodConfigViewMap().
-views::DialogDelegate* CreateLanguageHangulConfigView() {
- return new LanguageHangulConfigView;
+views::DialogDelegate* CreateLanguageHangulConfigView(Profile* profile) {
+ return new LanguageHangulConfigView(profile);
}
+
} // namespace
-LanguageConfigView::LanguageConfigView()
- : language_library_(NULL),
+LanguageConfigView::LanguageConfigView(Profile* profile)
+ : profile_(profile),
+ language_library_(NULL),
root_container_(NULL),
right_container_(NULL),
add_language_button_(NULL),
@@ -518,7 +521,7 @@ views::DialogDelegate* LanguageConfigView::CreateInputMethodConfigureView(
input_method_config_view_map_.find(language.id);
if (iter != input_method_config_view_map_.end()) {
CreateDialogDelegateFunction function = iter->second;
- return function();
+ return function(profile_);
}
return NULL;
}
diff --git a/chrome/browser/chromeos/options/language_config_view.h b/chrome/browser/chromeos/options/language_config_view.h
index f8a6cde..6c8c11c 100644
--- a/chrome/browser/chromeos/options/language_config_view.h
+++ b/chrome/browser/chromeos/options/language_config_view.h
@@ -18,6 +18,8 @@
#include "views/controls/table/table_view_observer.h"
#include "views/window/dialog_delegate.h"
+class Profile;
+
namespace chromeos {
class InputMethodButton;
@@ -30,7 +32,7 @@ class LanguageConfigView : public TableModel,
public views::TableViewObserver,
public views::View {
public:
- LanguageConfigView();
+ explicit LanguageConfigView(Profile* profile);
virtual ~LanguageConfigView();
// views::ButtonListener overrides.
@@ -89,13 +91,16 @@ class LanguageConfigView : public TableModel,
views::DialogDelegate* CreateInputMethodConfigureView(
const InputLanguage& language);
+ // The profile object. Does not take ownership of the object.
+ Profile* profile_;
+
// The language library interface.
LanguageLibrary* language_library_;
// The codes of the preferred languages.
std::vector<std::string> preferred_language_codes_;
// The map of the input language id to a pointer to the function for
// creating the input method configuration dialog.
- typedef views::DialogDelegate* (*CreateDialogDelegateFunction)();
+ typedef views::DialogDelegate* (*CreateDialogDelegateFunction)(Profile*);
typedef std::map<std::string,
CreateDialogDelegateFunction> InputMethodConfigViewMap;
InputMethodConfigViewMap input_method_config_view_map_;
diff --git a/chrome/browser/chromeos/options/language_hangul_config_view.cc b/chrome/browser/chromeos/options/language_hangul_config_view.cc
index a97cb08..ca31d92 100644
--- a/chrome/browser/chromeos/options/language_hangul_config_view.cc
+++ b/chrome/browser/chromeos/options/language_hangul_config_view.cc
@@ -6,8 +6,14 @@
#include "app/combobox_model.h"
#include "app/l10n_util.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/common/notification_type.h"
+#include "chrome/common/pref_names.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/language_library.h"
+#include "chrome/browser/chromeos/language_preferences.h"
+#include "chrome/browser/chromeos/preferences.h"
+#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "views/controls/button/checkbox.h"
@@ -18,22 +24,15 @@
namespace chromeos {
-const char LanguageHangulConfigView::kHangulSection[] = "engine/Hangul";
-const char LanguageHangulConfigView::kHangulKeyboardConfigName[] =
- "HangulKeyboard";
-
// The combobox model for the list of hangul keyboards.
class HangulKeyboardComboboxModel : public ComboboxModel {
public:
HangulKeyboardComboboxModel() {
- // We have to sync the IDs ("2", "3f", "39", ...) with those in
- // ibus-hangul/setup/main.py.
- // TODO(yusukes): Use l10n_util::GetString for these label strings.
- layouts_.push_back(std::make_pair(L"Dubeolsik", "2"));
- layouts_.push_back(std::make_pair(L"Sebeolsik Final", "3f"));
- layouts_.push_back(std::make_pair(L"Sebeolsik 390", "39"));
- layouts_.push_back(std::make_pair(L"Sebeolsik No-shift", "3s"));
- layouts_.push_back(std::make_pair(L"Sebeolsik 2 set", "32"));
+ for (size_t i = 0; i < arraysize(kHangulKeyboardNameIDPairs); ++i) {
+ layouts_.push_back(std::make_pair(
+ kHangulKeyboardNameIDPairs[i].keyboard_name,
+ kHangulKeyboardNameIDPairs[i].keyboard_id));
+ }
}
// Implements ComboboxModel interface.
@@ -52,10 +51,10 @@ class HangulKeyboardComboboxModel : public ComboboxModel {
// Gets a keyboard layout ID (e.g. "2", "3f", ..) for an item at zero-origin
// |index|. This function is NOT part of the ComboboxModel interface.
- std::string GetItemIDAt(int index) {
+ std::wstring GetItemIDAt(int index) {
if (index < 0 || index > GetItemCount()) {
LOG(ERROR) << "Index is out of bounds: " << index;
- return "";
+ return L"";
}
return layouts_.at(index).second;
}
@@ -63,7 +62,7 @@ class HangulKeyboardComboboxModel : public ComboboxModel {
// Gets an index (>= 0) of an item whose keyboard layout ID is |layout_ld|.
// Returns -1 if such item is not found. This function is NOT part of the
// ComboboxModel interface.
- int GetIndexFromID(const std::string& layout_id) {
+ int GetIndexFromID(const std::wstring& layout_id) {
for (size_t i = 0; i < layouts_.size(); ++i) {
if (GetItemIDAt(i) == layout_id) {
return static_cast<int>(i);
@@ -73,14 +72,17 @@ class HangulKeyboardComboboxModel : public ComboboxModel {
}
private:
- std::vector<std::pair<std::wstring, std::string> > layouts_;
+ std::vector<std::pair<std::wstring, std::wstring> > layouts_;
DISALLOW_COPY_AND_ASSIGN(HangulKeyboardComboboxModel);
};
-LanguageHangulConfigView::LanguageHangulConfigView()
- : contents_(NULL),
+LanguageHangulConfigView::LanguageHangulConfigView(Profile* profile)
+ : OptionsPageView(profile),
+ contents_(NULL),
hangul_keyboard_combobox_(NULL),
hangul_keyboard_combobox_model_(new HangulKeyboardComboboxModel) {
+ keyboard_pref_.Init(
+ prefs::kLanguageHangulKeyboard, profile->GetPrefs(), this);
}
LanguageHangulConfigView::~LanguageHangulConfigView() {
@@ -88,14 +90,10 @@ LanguageHangulConfigView::~LanguageHangulConfigView() {
void LanguageHangulConfigView::ItemChanged(
views::Combobox* sender, int prev_index, int new_index) {
- ImeConfigValue config;
- config.type = ImeConfigValue::kValueTypeString;
- config.string_value =
- hangul_keyboard_combobox_model_->GetItemIDAt(new_index);
- CrosLibrary::Get()->GetLanguageLibrary()->SetImeConfig(
- kHangulSection, kHangulKeyboardConfigName, config);
-
- UpdateHangulKeyboardCombobox();
+ const std::wstring id
+ = hangul_keyboard_combobox_model_->GetItemIDAt(new_index);
+ LOG(INFO) << "Changing Hangul keyboard pref to " << id;
+ keyboard_pref_.SetValue(id);
}
void LanguageHangulConfigView::Layout() {
@@ -115,19 +113,10 @@ gfx::Size LanguageHangulConfigView::GetPreferredSize() {
IDS_FONTSLANG_DIALOG_HEIGHT_LINES));
}
-void LanguageHangulConfigView::ViewHierarchyChanged(
- bool is_add, views::View* parent, views::View* child) {
- // Can't init before we're inserted into a Container.
- if (is_add && child == this) {
- Init();
- }
-}
-
-void LanguageHangulConfigView::Init() {
+void LanguageHangulConfigView::InitControlLayout() {
using views::ColumnSet;
using views::GridLayout;
- if (contents_) return; // Already initialized.
contents_ = new views::View;
AddChildView(contents_);
@@ -152,20 +141,30 @@ void LanguageHangulConfigView::Init() {
hangul_keyboard_combobox_
= new views::Combobox(hangul_keyboard_combobox_model_.get());
hangul_keyboard_combobox_->set_listener(this);
- UpdateHangulKeyboardCombobox();
+
+ // Initialize the combobox to what's saved in user preferences. Otherwise,
+ // ItemChanged() will be called with |new_index| == 0.
+ NotifyPrefChanged();
layout->AddView(hangul_keyboard_combobox_);
}
-void LanguageHangulConfigView::UpdateHangulKeyboardCombobox() {
- DCHECK(hangul_keyboard_combobox_);
- ImeConfigValue config;
- if (CrosLibrary::Get()->GetLanguageLibrary()->GetImeConfig(
- kHangulSection, kHangulKeyboardConfigName, &config)) {
- const int index
- = hangul_keyboard_combobox_model_->GetIndexFromID(config.string_value);
- if (index >= 0) {
- hangul_keyboard_combobox_->SetSelectedItem(index);
- }
+void LanguageHangulConfigView::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::PREF_CHANGED) {
+ // Observe(PREF_CHANGED) is called when the chromeos::Preferences object
+ // changed the prefs::kLanguageHangulKeyboard preference. Note that this
+ // function is NOT called when this dialog calls keyboard_pref_.SetValue().
+ NotifyPrefChanged();
+ }
+}
+
+void LanguageHangulConfigView::NotifyPrefChanged() {
+ const std::wstring id = keyboard_pref_.GetValue();
+ const int index
+ = hangul_keyboard_combobox_model_->GetIndexFromID(id);
+ if (index >= 0) {
+ hangul_keyboard_combobox_->SetSelectedItem(index);
}
}
diff --git a/chrome/browser/chromeos/options/language_hangul_config_view.h b/chrome/browser/chromeos/options/language_hangul_config_view.h
index c4798eb..a4c21d3 100644
--- a/chrome/browser/chromeos/options/language_hangul_config_view.h
+++ b/chrome/browser/chromeos/options/language_hangul_config_view.h
@@ -9,6 +9,8 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/chromeos/cros/language_library.h"
+#include "chrome/browser/pref_member.h"
+#include "chrome/browser/views/options/options_page_view.h"
#include "views/controls/combobox/combobox.h"
#include "views/controls/label.h"
#include "views/window/dialog_delegate.h"
@@ -19,9 +21,9 @@ class HangulKeyboardComboboxModel;
// A dialog box for showing a password textfield.
class LanguageHangulConfigView : public views::Combobox::Listener,
public views::DialogDelegate,
- public views::View {
+ public OptionsPageView {
public:
- LanguageHangulConfigView();
+ explicit LanguageHangulConfigView(Profile* profile);
virtual ~LanguageHangulConfigView();
// views::Combobox::Listener overrides.
@@ -34,23 +36,23 @@ class LanguageHangulConfigView : public views::Combobox::Listener,
virtual views::View* GetContentsView() { return this; }
virtual std::wstring GetWindowTitle() const;
- // views::View overrides:
+ // views::View overrides.
virtual void Layout();
virtual gfx::Size GetPreferredSize();
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child);
+
+ // OptionsPageView overrides.
+ virtual void InitControlLayout();
+
+ // NotificationObserver overrides.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
private:
- // Initializes UI.
- void Init();
// Updates the hangul keyboard combobox.
- void UpdateHangulKeyboardCombobox();
-
- // GConf config path names for the Korean IME.
- static const char kHangulSection[];
- static const char kHangulKeyboardConfigName[];
+ void NotifyPrefChanged();
+ StringPrefMember keyboard_pref_;
views::View* contents_;
// A combobox for Hangul keyboard layouts and its model.
diff --git a/chrome/browser/chromeos/options/system_page_view.cc b/chrome/browser/chromeos/options/system_page_view.cc
index cd9b491..138e107 100644
--- a/chrome/browser/chromeos/options/system_page_view.cc
+++ b/chrome/browser/chromeos/options/system_page_view.cc
@@ -393,7 +393,7 @@ void LanguageSection::ButtonPressed(
views::Window* window = views::Window::CreateChromeWindow(
NULL,
gfx::Rect(),
- new LanguageConfigView());
+ new LanguageConfigView(profile()));
window->SetIsAlwaysOnTop(true);
window->Show();
}
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc
index 61b414c..043e6c3 100644
--- a/chrome/browser/chromeos/preferences.cc
+++ b/chrome/browser/chromeos/preferences.cc
@@ -5,14 +5,25 @@
#include "chrome/browser/chromeos/preferences.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/language_library.h"
#include "chrome/browser/chromeos/cros/synaptics_library.h"
+#include "chrome/browser/chromeos/language_preferences.h"
#include "chrome/browser/pref_member.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "unicode/timezone.h"
+namespace {
+
+// Section and config names for the IBus configuration daemon.
+const char kHangulSectionName[] = "engine/Hangul";
+const char kHangulKeyboardConfigName[] = "HangulKeyboard";
+
+} // namespace
+
namespace chromeos {
// static
@@ -22,6 +33,8 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kVertEdgeScrollEnabled, false);
prefs->RegisterIntegerPref(prefs::kTouchpadSpeedFactor, 5);
prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity, 5);
+ prefs->RegisterStringPref(prefs::kLanguageHangulKeyboard,
+ kHangulKeyboardNameIDPairs[0].keyboard_id);
}
void Preferences::Init(PrefService* prefs) {
@@ -30,14 +43,15 @@ void Preferences::Init(PrefService* prefs) {
vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this);
speed_factor_.Init(prefs::kTouchpadSpeedFactor, prefs, this);
sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this);
+ language_hangul_keyboard_.Init(prefs::kLanguageHangulKeyboard, prefs, this);
// Initialize touchpad settings to what's saved in user preferences.
NotifyPrefChanged(NULL);
}
void Preferences::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
+ const NotificationSource& source,
+ const NotificationDetails& details) {
if (type == NotificationType::PREF_CHANGED)
NotifyPrefChanged(Details<std::wstring>(details).ptr());
}
@@ -61,6 +75,9 @@ void Preferences::NotifyPrefChanged(const std::wstring* pref_name) {
CrosLibrary::Get()->GetSynapticsLibrary()->SetRangeParameter(
PARAM_RANGE_TOUCH_SENSITIVITY,
sensitivity_.GetValue());
+ if (!pref_name || *pref_name == prefs::kLanguageHangulKeyboard)
+ SetLanguageConfigString(kHangulSectionName, kHangulKeyboardConfigName,
+ language_hangul_keyboard_.GetValue());
}
void Preferences::SetTimeZone(const std::wstring& id) {
@@ -69,4 +86,13 @@ void Preferences::SetTimeZone(const std::wstring& id) {
icu::TimeZone::adoptDefault(timezone);
}
+void Preferences::SetLanguageConfigString(const char* section,
+ const char* name,
+ const std::wstring& value) {
+ ImeConfigValue config;
+ config.type = ImeConfigValue::kValueTypeString;
+ config.string_value = WideToUTF8(value);
+ CrosLibrary::Get()->GetLanguageLibrary()->SetImeConfig(section, name, config);
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h
index 0613335..f4cb2e3 100644
--- a/chrome/browser/chromeos/preferences.h
+++ b/chrome/browser/chromeos/preferences.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_CHROMEOS_PREFERENCES_H_
#define CHROME_BROWSER_CHROMEOS_PREFERENCES_H_
+#include <string>
+
#include "chrome/browser/pref_member.h"
#include "chrome/common/notification_observer.h"
@@ -41,11 +43,18 @@ class Preferences : public NotificationObserver {
private:
void SetTimeZone(const std::wstring& id);
+ // Writes |value| to the IME (IBus) configuration daemon. |section| (e.g.
+ // "engine/Hangul") and |name| (e.g. "HangulKeyboard") should not be NULL.
+ void SetLanguageConfigString(const char* section,
+ const char* name,
+ const std::wstring& value);
+
StringPrefMember timezone_;
BooleanPrefMember tap_to_click_enabled_;
BooleanPrefMember vert_edge_scroll_enabled_;
IntegerPrefMember speed_factor_;
IntegerPrefMember sensitivity_;
+ StringPrefMember language_hangul_keyboard_;
DISALLOW_COPY_AND_ASSIGN(Preferences);
};
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 2160495..fc65d58 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -193,6 +193,9 @@ const wchar_t kTouchpadSpeedFactor[] = L"settings.touchpad.speed_factor";
// A integer pref for the touchpad sensitivity.
const wchar_t kTouchpadSensitivity[] = L"settings.touchpad.sensitivity";
+
+// A string pref which determines the keyboard layout for Hangul IME.
+const wchar_t kLanguageHangulKeyboard[] = L"settings.language.hangul_keyboard";
#endif
// The disabled messages in IPC logging.
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 4db387d..21cf129 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -72,6 +72,7 @@ extern const wchar_t kTapToClickEnabled[];
extern const wchar_t kVertEdgeScrollEnabled[];
extern const wchar_t kTouchpadSpeedFactor[];
extern const wchar_t kTouchpadSensitivity[];
+extern const wchar_t kLanguageHangulKeyboard[];
#endif
extern const wchar_t kIpcDisabledMessages[];
extern const wchar_t kShowHomeButton[];