diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:00:50 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:00:50 +0000 |
commit | d478b3f2db3a2c12694d8b318274fbb0c11327c8 (patch) | |
tree | bf64ff63aa88289d9ec4e7457179bf31c22072af | |
parent | a51788ec675f333ebd4b33934f2cc467f518c4e0 (diff) | |
download | chromium_src-d478b3f2db3a2c12694d8b318274fbb0c11327c8.zip chromium_src-d478b3f2db3a2c12694d8b318274fbb0c11327c8.tar.gz chromium_src-d478b3f2db3a2c12694d8b318274fbb0c11327c8.tar.bz2 |
Add a host validity status icon to the content settings exception editor. Original patch by Thiago Farina (see http://codereview.chromium.org/650011 ), r=me.
BUG=34181
TEST=Open the content settings exception editor, hit add, type a hostname, observe how status icon changes.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39931 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/options/exception_editor_view.cc | 54 | ||||
-rw-r--r-- | chrome/browser/views/options/exception_editor_view.h | 6 |
2 files changed, 43 insertions, 17 deletions
diff --git a/chrome/browser/views/options/exception_editor_view.cc b/chrome/browser/views/options/exception_editor_view.cc index 32a772b..0b28545 100644 --- a/chrome/browser/views/options/exception_editor_view.cc +++ b/chrome/browser/views/options/exception_editor_view.cc @@ -5,28 +5,33 @@ #include "chrome/browser/views/options/exception_editor_view.h" #include "app/l10n_util.h" +#include "app/resource_bundle.h" #include "chrome/browser/content_exceptions_table_model.h" #include "chrome/browser/host_content_settings_map.h" #include "googleurl/src/url_canon.h" #include "googleurl/src/url_parse.h" +#include "grit/app_resources.h" #include "grit/generated_resources.h" #include "net/base/net_util.h" #include "views/grid_layout.h" +#include "views/controls/image_view.h" #include "views/controls/label.h" #include "views/standard_layout.h" #include "views/window/window.h" -// The settings shown in the combobox if show_ask_ is false; -static const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK }; +namespace { -// The settings shown in the combobox if show_ask_ is true; -static const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_ASK, - CONTENT_SETTING_BLOCK }; +// 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. -static bool ValidHost(const std::string& host) { +bool ValidHost(const std::string& host) { if (host.empty()) return false; @@ -34,6 +39,8 @@ static bool ValidHost(const std::string& host) { return !net::CanonicalizeHost(host, &host_info).empty(); } +} // namespace + int ExceptionEditorView::ActionComboboxModel::GetItemCount() { return show_ask_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings); } @@ -101,15 +108,7 @@ std::wstring ExceptionEditorView::GetWindowTitle() const { bool ExceptionEditorView::IsDialogButtonEnabled( MessageBoxFlags::DialogButton button) const { if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - std::string new_host = UTF16ToUTF8(host_tf_->text()); - if (is_new()) { - return ValidHost(new_host) && - (model_->IndexOfExceptionByHost(new_host) == -1); - } - return !new_host.empty() && - (host_ == new_host || - (ValidHost(new_host) && - model_->IndexOfExceptionByHost(new_host) == -1)); + return IsHostValid(UTF16ToUTF8(host_tf_->text())); } return true; } @@ -133,6 +132,7 @@ views::View* ExceptionEditorView::GetContentsView() { void ExceptionEditorView::ContentsChanged(views::Textfield* sender, const std::wstring& new_contents) { GetDialogClientView()->UpdateDialogButtons(); + UpdateImageView(host_iv_, IsHostValid(UTF16ToUTF8(host_tf_->text()))); } bool ExceptionEditorView::HandleKeystroke( @@ -148,6 +148,10 @@ void ExceptionEditorView::Init() { host_tf_->SetText(UTF8ToUTF16(host_)); host_tf_->SetController(this); + host_iv_ = new views::ImageView; + + UpdateImageView(host_iv_, IsHostValid(UTF16ToUTF8(host_tf_->text()))); + action_cb_ = new views::Combobox(&cb_model_); if (!is_new()) action_cb_->SetSelectedItem(cb_model_.index_for_setting(setting_)); @@ -170,6 +174,7 @@ void ExceptionEditorView::Init() { layout->StartRow(0, 1); layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_HOST_TITLE)); layout->AddView(host_tf_); + layout->AddView(host_iv_); layout->StartRowWithPadding(0, 1, 0, kRelatedControlVerticalSpacing); layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_ACTION_TITLE)); @@ -181,3 +186,18 @@ views::Label* ExceptionEditorView::CreateLabel(int message_id) { label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); return label; } + +bool ExceptionEditorView::IsHostValid(const std::string& host) const { + bool is_valid_host = ValidHost(host) && + (model_->IndexOfExceptionByHost(host) == -1); + + return is_new() ? is_valid_host : (!host.empty() && + ((host_ == host) || is_valid_host)); +} + +void ExceptionEditorView::UpdateImageView(views::ImageView* image_view, + bool is_valid) { + return image_view->SetImage( + ResourceBundle::GetSharedInstance().GetBitmapNamed( + is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); +} diff --git a/chrome/browser/views/options/exception_editor_view.h b/chrome/browser/views/options/exception_editor_view.h index 6a86f79..5523e9c 100644 --- a/chrome/browser/views/options/exception_editor_view.h +++ b/chrome/browser/views/options/exception_editor_view.h @@ -15,6 +15,7 @@ #include "views/controls/textfield/textfield.h" namespace views { +class ImageView; class Label; } @@ -96,6 +97,10 @@ class ExceptionEditorView : public views::View, // Returns true if we're adding a new item. bool is_new() const { return index_ == -1; } + bool IsHostValid(const std::string& host) const; + + void UpdateImageView(views::ImageView* image_view, bool is_valid); + Delegate* delegate_; ContentExceptionsTableModel* model_; ActionComboboxModel cb_model_; @@ -106,6 +111,7 @@ class ExceptionEditorView : public views::View, const ContentSetting setting_; views::Textfield* host_tf_; + views::ImageView* host_iv_; views::Combobox* action_cb_; DISALLOW_COPY_AND_ASSIGN(ExceptionEditorView); |