summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 22:06:27 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 22:06:27 +0000
commit77767745f94bb6e2ae267260de97af697fd2af82 (patch)
treefa18692d1ce6a175bb4ce5c7b9481c5c4f87750e /chrome/browser
parent9d166afe522da91217060a34787b16fa705f15e3 (diff)
downloadchromium_src-77767745f94bb6e2ae267260de97af697fd2af82.zip
chromium_src-77767745f94bb6e2ae267260de97af697fd2af82.tar.gz
chromium_src-77767745f94bb6e2ae267260de97af697fd2af82.tar.bz2
Moves ActionComboboxModel class to its own header so we can share common code between windows and linux.
BUG=None TEST=compiles, and still works as before. Review URL: http://codereview.chromium.org/661225 Patch from thiago.farina@gmail.com. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40446 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/content_setting_combo_model.cc59
-rw-r--r--chrome/browser/content_setting_combo_model.h32
-rw-r--r--chrome/browser/gtk/options/content_exception_editor.cc51
-rw-r--r--chrome/browser/gtk/options/content_exception_editor.h15
-rw-r--r--chrome/browser/views/options/exception_editor_view.cc45
-rw-r--r--chrome/browser/views/options/exception_editor_view.h21
6 files changed, 105 insertions, 118 deletions
diff --git a/chrome/browser/content_setting_combo_model.cc b/chrome/browser/content_setting_combo_model.cc
new file mode 100644
index 0000000..e37c151
--- /dev/null
+++ b/chrome/browser/content_setting_combo_model.cc
@@ -0,0 +1,59 @@
+// 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/content_setting_combo_model.h"
+
+#include "app/l10n_util.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+// The settings shown in the combobox if show_ask_ is false;
+const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_BLOCK };
+
+// The settings shown in the combobox if show_ask_ is true;
+const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_ASK,
+ CONTENT_SETTING_BLOCK };
+
+} // namespace
+
+ContentSettingComboModel::ContentSettingComboModel(bool show_ask)
+ : show_ask_(show_ask) {
+}
+
+ContentSettingComboModel::~ContentSettingComboModel() {
+}
+
+int ContentSettingComboModel::GetItemCount() {
+ return show_ask_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings);
+}
+
+std::wstring ContentSettingComboModel::GetItemAt(int index) {
+ switch (SettingForIndex(index)) {
+ case CONTENT_SETTING_ALLOW:
+ return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON);
+ case CONTENT_SETTING_BLOCK:
+ return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON);
+ case CONTENT_SETTING_ASK:
+ return l10n_util::GetString(IDS_EXCEPTIONS_ASK_BUTTON);
+ default:
+ NOTREACHED();
+ }
+ return std::wstring();
+}
+
+ContentSetting ContentSettingComboModel::SettingForIndex(int index) {
+ return show_ask_ ? kAskSettings[index] : kNoAskSettings[index];
+}
+
+int ContentSettingComboModel::IndexForSetting(ContentSetting setting) {
+ for (int i = 0; i < GetItemCount(); ++i)
+ if (SettingForIndex(i) == setting)
+ return i;
+ NOTREACHED();
+ return 0;
+}
+
diff --git a/chrome/browser/content_setting_combo_model.h b/chrome/browser/content_setting_combo_model.h
new file mode 100644
index 0000000..751e9d0
--- /dev/null
+++ b/chrome/browser/content_setting_combo_model.h
@@ -0,0 +1,32 @@
+// 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_CONTENT_SETTING_COMBO_MODEL_H_
+#define CHROME_BROWSER_CONTENT_SETTING_COMBO_MODEL_H_
+
+#include "app/combobox_model.h"
+
+#include "base/basictypes.h"
+#include "chrome/common/content_settings.h"
+
+class ContentSettingComboModel : public ComboboxModel {
+ public:
+ explicit ContentSettingComboModel(bool show_ask);
+ virtual ~ContentSettingComboModel();
+
+ virtual int GetItemCount();
+
+ virtual std::wstring GetItemAt(int index);
+
+ ContentSetting SettingForIndex(int index);
+
+ int IndexForSetting(ContentSetting);
+
+ private:
+ const bool show_ask_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSettingComboModel);
+};
+
+#endif // CHROME_BROWSER_CONTENT_SETTING_COMBO_MODEL_H_
diff --git a/chrome/browser/gtk/options/content_exception_editor.cc b/chrome/browser/gtk/options/content_exception_editor.cc
index 9547f49..3147307 100644
--- a/chrome/browser/gtk/options/content_exception_editor.cc
+++ b/chrome/browser/gtk/options/content_exception_editor.cc
@@ -18,15 +18,6 @@
namespace {
-// The settings shown in the combobox if show_ask_ is false;
-const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW,
- CONTENT_SETTING_BLOCK };
-
-// The settings shown in the combobox if show_ask_ is true;
-const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW,
- CONTENT_SETTING_ASK,
- CONTENT_SETTING_BLOCK };
-
// Returns true if the host name is valid.
bool ValidHost(const std::string& host) {
if (host.empty())
@@ -54,7 +45,7 @@ ContentExceptionEditor::ContentExceptionEditor(
ContentSetting setting)
: delegate_(delegate),
model_(model),
- show_ask_(model->content_type() == CONTENT_SETTINGS_TYPE_COOKIES),
+ cb_model_(model->content_type() == CONTENT_SETTINGS_TYPE_COOKIES),
index_(index),
host_(host),
setting_(setting) {
@@ -80,12 +71,12 @@ ContentExceptionEditor::ContentExceptionEditor(
host_image_ = gtk_image_new_from_pixbuf(NULL);
action_combo_ = gtk_combo_box_new_text();
- for (int i = 0; i < GetItemCount(); ++i) {
+ for (int i = 0; i < cb_model_.GetItemCount(); ++i) {
gtk_combo_box_append_text(GTK_COMBO_BOX(action_combo_),
- GetTitleFor(i).c_str());
+ WideToUTF8(cb_model_.GetItemAt(i)).c_str());
}
gtk_combo_box_set_active(GTK_COMBO_BOX(action_combo_),
- IndexForSetting(setting_));
+ cb_model_.IndexForSetting(setting_));
GtkWidget* table = gtk_util::CreateLabeledControlsGroup(
NULL,
@@ -109,36 +100,6 @@ ContentExceptionEditor::ContentExceptionEditor(
g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this);
}
-int ContentExceptionEditor::GetItemCount() {
- return show_ask_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings);
-}
-
-std::string ContentExceptionEditor::GetTitleFor(int index) {
- switch (SettingForIndex(index)) {
- case CONTENT_SETTING_ALLOW:
- return l10n_util::GetStringUTF8(IDS_EXCEPTIONS_ALLOW_BUTTON);
- case CONTENT_SETTING_BLOCK:
- return l10n_util::GetStringUTF8(IDS_EXCEPTIONS_BLOCK_BUTTON);
- case CONTENT_SETTING_ASK:
- return l10n_util::GetStringUTF8(IDS_EXCEPTIONS_ASK_BUTTON);
- default:
- NOTREACHED();
- }
- return std::string();
-}
-
-ContentSetting ContentExceptionEditor::SettingForIndex(int index) {
- return show_ask_ ? kAskSettings[index] : kNoAskSettings[index];
-}
-
-int ContentExceptionEditor::IndexForSetting(ContentSetting setting) {
- for (int i = 0; i < GetItemCount(); ++i)
- if (SettingForIndex(i) == setting)
- return i;
- NOTREACHED();
- return 0;
-}
-
bool ContentExceptionEditor::IsHostValid(const std::string& host) const {
bool is_valid_host = ValidHost(host) &&
(model_->IndexOfExceptionByHost(host) == -1);
@@ -171,8 +132,8 @@ void ContentExceptionEditor::OnResponse(
if (response_id == GTK_RESPONSE_OK) {
// Notify our delegate to update everything.
std::string new_host = gtk_entry_get_text(GTK_ENTRY(window->entry_));
- ContentSetting setting = window->SettingForIndex(gtk_combo_box_get_active(
- GTK_COMBO_BOX(window->action_combo_)));
+ ContentSetting setting = window->cb_model_.SettingForIndex(
+ gtk_combo_box_get_active(GTK_COMBO_BOX(window->action_combo_)));
window->delegate_->AcceptExceptionEdit(new_host, setting, window->index_,
window->is_new());
}
diff --git a/chrome/browser/gtk/options/content_exception_editor.h b/chrome/browser/gtk/options/content_exception_editor.h
index a40b4d2..8c618b8 100644
--- a/chrome/browser/gtk/options/content_exception_editor.h
+++ b/chrome/browser/gtk/options/content_exception_editor.h
@@ -10,6 +10,7 @@
#include <string>
#include "chrome/browser/content_exceptions_table_model.h"
+#include "chrome/browser/content_setting_combo_model.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
@@ -41,16 +42,6 @@ class ContentExceptionEditor {
// Returns true if we're adding a new item.
bool is_new() const { return index_ == -1; }
- // Returns the number of items in the |action_combo_|.
- int GetItemCount();
-
- // Returns the string representation for an item in |action_combo_|.
- std::string GetTitleFor(int index);
-
- // Changes an index from |action_combo_| into a ContentSetting and vice versa.
- ContentSetting SettingForIndex(int index);
- int IndexForSetting(ContentSetting setting);
-
bool IsHostValid(const std::string& host) const;
void UpdateImage(GtkWidget* image, bool is_valid);
@@ -66,7 +57,9 @@ class ContentExceptionEditor {
Delegate* delegate_;
ContentExceptionsTableModel* model_;
- bool show_ask_;
+
+ // The model for Combobox widget.
+ ContentSettingComboModel cb_model_;
// Index of the item being edited. If -1, indicates this is a new entry.
const int index_;
diff --git a/chrome/browser/views/options/exception_editor_view.cc b/chrome/browser/views/options/exception_editor_view.cc
index 0b28545..97f84e0 100644
--- a/chrome/browser/views/options/exception_editor_view.cc
+++ b/chrome/browser/views/options/exception_editor_view.cc
@@ -21,15 +21,6 @@
namespace {
-// The settings shown in the combobox if show_ask_ is false.
-const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW,
- CONTENT_SETTING_BLOCK };
-
-// The settings shown in the combobox if show_ask_ is true.
-const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW,
- CONTENT_SETTING_ASK,
- CONTENT_SETTING_BLOCK };
-
// Returns true if the host name is valid.
bool ValidHost(const std::string& host) {
if (host.empty())
@@ -41,38 +32,6 @@ bool ValidHost(const std::string& host) {
} // namespace
-int ExceptionEditorView::ActionComboboxModel::GetItemCount() {
- return show_ask_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings);
-}
-
-std::wstring ExceptionEditorView::ActionComboboxModel::GetItemAt(int index) {
- switch (setting_for_index(index)) {
- case CONTENT_SETTING_ALLOW:
- return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON);
- case CONTENT_SETTING_BLOCK:
- return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON);
- case CONTENT_SETTING_ASK:
- return l10n_util::GetString(IDS_EXCEPTIONS_ASK_BUTTON);
- default:
- NOTREACHED();
- }
- return std::wstring();
-}
-
-ContentSetting ExceptionEditorView::ActionComboboxModel::setting_for_index(
- int index) {
- return show_ask_ ? kAskSettings[index] : kNoAskSettings[index];
-}
-
-int ExceptionEditorView::ActionComboboxModel::index_for_setting(
- ContentSetting setting) {
- for (int i = 0; i < GetItemCount(); ++i)
- if (setting_for_index(i) == setting)
- return i;
- NOTREACHED();
- return 0;
-}
-
ExceptionEditorView::ExceptionEditorView(Delegate* delegate,
ContentExceptionsTableModel* model,
int index,
@@ -120,7 +79,7 @@ bool ExceptionEditorView::Cancel() {
bool ExceptionEditorView::Accept() {
std::string new_host = UTF16ToUTF8(host_tf_->text());
ContentSetting setting =
- cb_model_.setting_for_index(action_cb_->selected_item());
+ cb_model_.SettingForIndex(action_cb_->selected_item());
delegate_->AcceptExceptionEdit(new_host, setting, index_, is_new());
return true;
}
@@ -154,7 +113,7 @@ void ExceptionEditorView::Init() {
action_cb_ = new views::Combobox(&cb_model_);
if (!is_new())
- action_cb_->SetSelectedItem(cb_model_.index_for_setting(setting_));
+ action_cb_->SetSelectedItem(cb_model_.IndexForSetting(setting_));
GridLayout* layout = CreatePanelGridLayout(this);
SetLayoutManager(layout);
diff --git a/chrome/browser/views/options/exception_editor_view.h b/chrome/browser/views/options/exception_editor_view.h
index 5523e9c..d542e99 100644
--- a/chrome/browser/views/options/exception_editor_view.h
+++ b/chrome/browser/views/options/exception_editor_view.h
@@ -7,7 +7,7 @@
#include <string>
-#include "app/combobox_model.h"
+#include "chrome/browser/content_setting_combo_model.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
#include "views/window/dialog_delegate.h"
@@ -73,23 +73,6 @@ class ExceptionEditorView : public views::View,
const views::Textfield::Keystroke& key);
private:
- // Model for the combobox.
- class ActionComboboxModel : public ComboboxModel {
- public:
- explicit ActionComboboxModel(bool show_ask) : show_ask_(show_ask) {}
-
- virtual int GetItemCount();
- virtual std::wstring GetItemAt(int index);
-
- ContentSetting setting_for_index(int index);
- int index_for_setting(ContentSetting);
-
- private:
- const bool show_ask_;
-
- DISALLOW_COPY_AND_ASSIGN(ActionComboboxModel);
- };
-
void Init();
views::Label* CreateLabel(int message_id);
@@ -103,7 +86,7 @@ class ExceptionEditorView : public views::View,
Delegate* delegate_;
ContentExceptionsTableModel* model_;
- ActionComboboxModel cb_model_;
+ ContentSettingComboModel cb_model_;
// Index of the item being edited. If -1, indices this is a new entry.
const int index_;