summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 01:04:54 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 01:04:54 +0000
commit9b82ad7a837506f27669a1465c215b80bcec2d68 (patch)
treedd32f492f2ca3f395804fd7c6015c62be0dc2596
parent4eb2ac96bb677b63173fab432bc66903a53f79b0 (diff)
downloadchromium_src-9b82ad7a837506f27669a1465c215b80bcec2d68.zip
chromium_src-9b82ad7a837506f27669a1465c215b80bcec2d68.tar.gz
chromium_src-9b82ad7a837506f27669a1465c215b80bcec2d68.tar.bz2
gtk: Split DefaultEncodingComboboxModel into its own file so it can be shared with the views UI side.
BUG=None TEST=manually, everything should works as before. Review URL: http://codereview.chromium.org/1993004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47609 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/default_encoding_combo_model.cc49
-rw-r--r--chrome/browser/default_encoding_combo_model.h38
-rw-r--r--chrome/browser/gtk/options/fonts_page_gtk.cc40
-rw-r--r--chrome/browser/gtk/options/fonts_page_gtk.h11
-rw-r--r--chrome/browser/views/options/fonts_page_view.cc68
-rw-r--r--chrome/chrome_browser.gypi2
6 files changed, 108 insertions, 100 deletions
diff --git a/chrome/browser/default_encoding_combo_model.cc b/chrome/browser/default_encoding_combo_model.cc
new file mode 100644
index 0000000..7db6cce
--- /dev/null
+++ b/chrome/browser/default_encoding_combo_model.cc
@@ -0,0 +1,49 @@
+// 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.
+
+#include "chrome/browser/default_encoding_combo_model.h"
+
+#include "app/l10n_util.h"
+#include "app/l10n_util_collator.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/pref_member.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/pref_names.h"
+
+DefaultEncodingComboboxModel::DefaultEncodingComboboxModel() {
+ // Initialize the vector of all sorted encodings according to current
+ // UI locale.
+ std::string locale = g_browser_process->GetApplicationLocale();
+ int size = CharacterEncoding::GetSupportCanonicalEncodingCount();
+ for (int i = 0; i < size; ++i) {
+ sorted_encoding_list_.push_back(CharacterEncoding::EncodingInfo(
+ CharacterEncoding::GetEncodingCommandIdByIndex(i)));
+ }
+ l10n_util::SortVectorWithStringKey(locale, &sorted_encoding_list_, true);
+}
+
+std::wstring DefaultEncodingComboboxModel::GetItemAt(int index) {
+ DCHECK(index >= 0 && index < GetItemCount());
+ return sorted_encoding_list_[index].encoding_display_name;
+}
+
+std::string DefaultEncodingComboboxModel::GetEncodingCharsetByIndex(int index) {
+ DCHECK(index >= 0 && index < GetItemCount());
+ int encoding_id = sorted_encoding_list_[index].encoding_id;
+ return CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
+}
+
+int DefaultEncodingComboboxModel::GetSelectedEncodingIndex(Profile* profile) {
+ StringPrefMember current_encoding_string;
+ current_encoding_string.Init(prefs::kDefaultCharset,
+ profile->GetPrefs(),
+ NULL);
+ const std::wstring current_encoding = current_encoding_string.GetValue();
+ for (int i = 0; i < GetItemCount(); ++i) {
+ if (GetEncodingCharsetByIndex(i) == WideToASCII(current_encoding))
+ return i;
+ }
+
+ return 0;
+}
diff --git a/chrome/browser/default_encoding_combo_model.h b/chrome/browser/default_encoding_combo_model.h
new file mode 100644
index 0000000..9901238
--- /dev/null
+++ b/chrome/browser/default_encoding_combo_model.h
@@ -0,0 +1,38 @@
+// 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_DEFAULT_ENCODING_COMBO_MODEL_H_
+#define CHROME_BROWSER_DEFAULT_ENCODING_COMBO_MODEL_H_
+
+#include <string>
+#include <vector>
+
+#include "app/combobox_model.h"
+#include "chrome/browser/character_encoding.h"
+
+class Profile;
+
+class DefaultEncodingComboboxModel : public ComboboxModel {
+ public:
+ DefaultEncodingComboboxModel();
+ virtual ~DefaultEncodingComboboxModel() {}
+
+ // Overridden from ComboboxModel.
+ virtual int GetItemCount() {
+ return static_cast<int>(sorted_encoding_list_.size());
+ }
+
+ virtual std::wstring GetItemAt(int index);
+
+ std::string GetEncodingCharsetByIndex(int index);
+
+ int GetSelectedEncodingIndex(Profile* profile);
+
+ private:
+ std::vector<CharacterEncoding::EncodingInfo> sorted_encoding_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultEncodingComboboxModel);
+};
+
+#endif // CHROME_BROWSER_DEFAULT_ENCODING_COMBO_MODEL_H_
diff --git a/chrome/browser/gtk/options/fonts_page_gtk.cc b/chrome/browser/gtk/options/fonts_page_gtk.cc
index 42bcfb0..9e73e3e 100644
--- a/chrome/browser/gtk/options/fonts_page_gtk.cc
+++ b/chrome/browser/gtk/options/fonts_page_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -7,6 +7,7 @@
#include "app/l10n_util.h"
#include "app/l10n_util_collator.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/default_encoding_combo_model.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/gtk/options/options_layout_gtk.h"
#include "chrome/browser/profile.h"
@@ -111,20 +112,11 @@ void FontsPageGtk::InitDefaultEncodingComboBox() {
default_encoding_combobox_ = gtk_combo_box_new_text();
g_signal_connect(default_encoding_combobox_, "changed",
G_CALLBACK(OnDefaultEncodingChangedThunk), this);
- int canonical_encoding_names_length =
- CharacterEncoding::GetSupportCanonicalEncodingCount();
- // Initialize the vector of all sorted encodings according to current
- // UI locale.
- std::string locale = g_browser_process->GetApplicationLocale();
- for (int i = 0; i < canonical_encoding_names_length; i++) {
- sorted_encoding_list_.push_back(CharacterEncoding::EncodingInfo(
- CharacterEncoding::GetEncodingCommandIdByIndex(i)));
- }
- l10n_util::SortVectorWithStringKey(locale, &sorted_encoding_list_, true);
- for (size_t i = 0; i < sorted_encoding_list_.size(); i++) {
+ default_encoding_combobox_model_.reset(new DefaultEncodingComboboxModel);
+ for (int i = 0; i < default_encoding_combobox_model_->GetItemCount(); ++i) {
gtk_combo_box_append_text(
GTK_COMBO_BOX(default_encoding_combobox_),
- WideToUTF8(sorted_encoding_list_[i].encoding_display_name).c_str());
+ WideToUTF8(default_encoding_combobox_model_->GetItemAt(i)).c_str());
}
}
@@ -148,15 +140,9 @@ void FontsPageGtk::NotifyPrefChanged(const std::wstring* pref_name) {
fixed_width_size_.GetValue()).c_str());
}
if (!pref_name || *pref_name == prefs::kDefaultCharset) {
- const std::string current_encoding =
- WideToASCII(default_encoding_.GetValue());
- for (size_t i = 0; i < sorted_encoding_list_.size(); i++) {
- if (CharacterEncoding::GetCanonicalEncodingNameByCommandId(
- sorted_encoding_list_[i].encoding_id) == current_encoding) {
- gtk_combo_box_set_active(GTK_COMBO_BOX(default_encoding_combobox_), i);
- break;
- }
- }
+ gtk_combo_box_set_active(
+ GTK_COMBO_BOX(default_encoding_combobox_),
+ default_encoding_combobox_model_->GetSelectedEncodingIndex(profile()));
}
}
@@ -195,12 +181,6 @@ void FontsPageGtk::OnFixedFontSet(GtkWidget* font_button) {
void FontsPageGtk::OnDefaultEncodingChanged(GtkWidget* combo_box) {
int index = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box));
- if (index < 0 ||
- static_cast<size_t>(index) >= sorted_encoding_list_.size()) {
- NOTREACHED();
- return;
- }
- default_encoding_.SetValue(
- ASCIIToWide(CharacterEncoding::GetCanonicalEncodingNameByCommandId(
- sorted_encoding_list_[index].encoding_id)));
+ default_encoding_.SetValue(ASCIIToWide(default_encoding_combobox_model_->
+ GetEncodingCharsetByIndex(index)));
}
diff --git a/chrome/browser/gtk/options/fonts_page_gtk.h b/chrome/browser/gtk/options/fonts_page_gtk.h
index 92a44ad..837f48f 100644
--- a/chrome/browser/gtk/options/fonts_page_gtk.h
+++ b/chrome/browser/gtk/options/fonts_page_gtk.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -12,18 +12,19 @@
#include <vector>
#include "app/gtk_signal.h"
+#include "base/scoped_ptr.h"
#include "chrome/browser/character_encoding.h"
#include "chrome/browser/pref_member.h"
#include "chrome/browser/options_page_base.h"
+class DefaultEncodingComboboxModel;
+
class FontsPageGtk : public OptionsPageBase {
public:
explicit FontsPageGtk(Profile* profile);
virtual ~FontsPageGtk();
- GtkWidget* get_page_widget() const {
- return page_;
- }
+ GtkWidget* get_page_widget() const { return page_; }
private:
void Init();
@@ -51,6 +52,7 @@ class FontsPageGtk : public OptionsPageBase {
// The default encoding combobox widget.
GtkWidget* default_encoding_combobox_;
+ scoped_ptr<DefaultEncodingComboboxModel> default_encoding_combobox_model_;
// The widget containing the options for this page.
GtkWidget* page_;
@@ -66,7 +68,6 @@ class FontsPageGtk : public OptionsPageBase {
// Default encoding preference.
StringPrefMember default_encoding_;
- std::vector<CharacterEncoding::EncodingInfo> sorted_encoding_list_;
DISALLOW_COPY_AND_ASSIGN(FontsPageGtk);
};
diff --git a/chrome/browser/views/options/fonts_page_view.cc b/chrome/browser/views/options/fonts_page_view.cc
index 2854bbd..4fd923e 100644
--- a/chrome/browser/views/options/fonts_page_view.cc
+++ b/chrome/browser/views/options/fonts_page_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -11,14 +11,12 @@
#include <vector>
-#include "app/combobox_model.h"
#include "app/l10n_util.h"
#include "app/l10n_util_collator.h"
#include "app/resource_bundle.h"
#include "base/file_util.h"
#include "base/string_util.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/character_encoding.h"
+#include "chrome/browser/default_encoding_combo_model.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/shell_dialogs.h"
@@ -35,66 +33,6 @@
#include "views/standard_layout.h"
#include "views/widget/widget.h"
-namespace {
-
-static std::vector<CharacterEncoding::EncodingInfo> sorted_encoding_list;
-
-} // namespace
-
-class DefaultEncodingComboboxModel : public ComboboxModel {
- public:
- DefaultEncodingComboboxModel() {
- canonical_encoding_names_length_ =
- CharacterEncoding::GetSupportCanonicalEncodingCount();
- // Initialize the vector of all sorted encodings according to current
- // UI locale.
- if (!sorted_encoding_list.size()) {
- std::string locale = g_browser_process->GetApplicationLocale();
- for (int i = 0; i < canonical_encoding_names_length_; i++) {
- sorted_encoding_list.push_back(CharacterEncoding::EncodingInfo(
- CharacterEncoding::GetEncodingCommandIdByIndex(i)));
- }
- l10n_util::SortVectorWithStringKey(locale, &sorted_encoding_list, true);
- }
- }
-
- virtual ~DefaultEncodingComboboxModel() {}
-
- // Overridden from ComboboxModel.
- virtual int GetItemCount() {
- return canonical_encoding_names_length_;
- }
-
- virtual std::wstring GetItemAt(int index) {
- DCHECK(index >= 0 && canonical_encoding_names_length_ > index);
- return sorted_encoding_list[index].encoding_display_name;
- }
-
- std::string GetEncodingCharsetByIndex(int index) {
- DCHECK(index >= 0 && canonical_encoding_names_length_ > index);
- int encoding_id = sorted_encoding_list[index].encoding_id;
- return CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
- }
-
- int GetSelectedEncodingIndex(Profile* profile) {
- StringPrefMember current_encoding_string;
- current_encoding_string.Init(prefs::kDefaultCharset,
- profile->GetPrefs(),
- NULL);
- const std::wstring current_encoding = current_encoding_string.GetValue();
- for (int i = 0; i < canonical_encoding_names_length_; i++) {
- if (GetEncodingCharsetByIndex(i) == WideToASCII(current_encoding))
- return i;
- }
-
- return 0;
- }
-
- private:
- int canonical_encoding_names_length_;
- DISALLOW_COPY_AND_ASSIGN(DefaultEncodingComboboxModel);
-};
-
////////////////////////////////////////////////////////////////////////////////
// FontDisplayView
@@ -127,7 +65,7 @@ class FontDisplayView : public views::View {
static const int kFontDisplayMaxHeightChars = 1;
static const int kFontDisplayLabelPadding = 5;
- DISALLOW_EVIL_CONSTRUCTORS(FontDisplayView);
+ DISALLOW_COPY_AND_ASSIGN(FontDisplayView);
};
FontDisplayView::FontDisplayView()
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 32a2c1d..cb52ae8 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -887,6 +887,8 @@
'browser/cross_site_request_manager.h',
'browser/custom_home_pages_table_model.cc',
'browser/custom_home_pages_table_model.h',
+ 'browser/default_encoding_combo_model.cc',
+ 'browser/default_encoding_combo_model.h',
'browser/defaults.cc',
'browser/defaults.h',
'browser/diagnostics/diagnostics_main.cc',