diff options
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/browser_dialogs.h | 11 | ||||
-rw-r--r-- | chrome/browser/views/edit_search_engine_dialog.cc (renamed from chrome/browser/views/edit_keyword_controller.cc) | 146 | ||||
-rw-r--r-- | chrome/browser/views/edit_search_engine_dialog.h (renamed from chrome/browser/views/edit_keyword_controller.h) | 51 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/views/keyword_editor_view.cc | 14 | ||||
-rw-r--r-- | chrome/browser/views/keyword_editor_view.h | 6 |
7 files changed, 118 insertions, 118 deletions
diff --git a/chrome/browser/views/browser_dialogs.h b/chrome/browser/views/browser_dialogs.h index fd81d7b..9f33f64 100644 --- a/chrome/browser/views/browser_dialogs.h +++ b/chrome/browser/views/browser_dialogs.h @@ -14,6 +14,7 @@ class Browser; class BrowserView; +class EditSearchEngineControllerDelegate; class FindBar; class GURL; class HtmlDialogUIDelegate; @@ -85,6 +86,16 @@ void ShowNewProfileDialog(); // Shows the Task Manager. void ShowTaskManager(); +// Shows a dialog box that allows a search engine to be edited. |template_url| +// is the search engine being edited. If it is NULL, then the dialog will add a +// new search engine with the data the user supplies. |delegate| is an object +// to be notified when the user is done editing, or NULL. If NULL, the dialog +// will update the model with the user's edits directly. +void EditSearchEngine(gfx::NativeWindow parent, + const TemplateURL* template_url, + EditSearchEngineControllerDelegate* delegate, + Profile* profile); + } // namespace browser #endif // CHROME_BROWSER_VIEWS_BROWSER_DIALOGS_H_ diff --git a/chrome/browser/views/edit_keyword_controller.cc b/chrome/browser/views/edit_search_engine_dialog.cc index 7258b2d..18d3c6f 100644 --- a/chrome/browser/views/edit_keyword_controller.cc +++ b/chrome/browser/views/edit_search_engine_dialog.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/views/edit_keyword_controller.h" +#include "chrome/browser/views/edit_search_engine_dialog.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/string_util.h" +#include "chrome/browser/search_engines/edit_search_engine_controller.h" #include "chrome/browser/search_engines/template_url.h" #include "googleurl/src/gurl.h" #include "grit/app_resources.h" @@ -32,103 +33,101 @@ std::wstring GetDisplayURL(const TemplateURL& turl) { } } // namespace -// static -void EditKeywordControllerBase::Create(gfx::NativeWindow parent_window, - const TemplateURL* template_url, - Delegate* delegate, - Profile* profile) { - EditKeywordController* controller = - new EditKeywordController(parent_window, template_url, delegate, profile); - controller->Show(); +namespace browser { + +void EditSearchEngine(gfx::NativeWindow parent, + const TemplateURL* template_url, + EditSearchEngineControllerDelegate* delegate, + Profile* profile) { + EditSearchEngineDialog::Show(parent, template_url, delegate, profile); } -EditKeywordController::EditKeywordController( - HWND parent, +} // namespace browser + +EditSearchEngineDialog::EditSearchEngineDialog( const TemplateURL* template_url, - Delegate* delegate, + EditSearchEngineControllerDelegate* delegate, Profile* profile) - : EditKeywordControllerBase(template_url, delegate, profile), - parent_(parent) { + : controller_(new EditSearchEngineController(template_url, + delegate, + profile)) { Init(); } -void EditKeywordController::Show() { +// static +void EditSearchEngineDialog::Show(gfx::NativeWindow parent, + const TemplateURL* template_url, + EditSearchEngineControllerDelegate* delegate, + Profile* profile) { + EditSearchEngineDialog* contents = + new EditSearchEngineDialog(template_url, delegate, profile); // Window interprets an empty rectangle as needing to query the content for // the size as well as centering relative to the parent. - views::Window::CreateChromeWindow(::IsWindow(parent_) ? parent_ : NULL, - gfx::Rect(), this); - window()->Show(); - GetDialogClientView()->UpdateDialogButtons(); - title_tf_->SelectAll(); - title_tf_->RequestFocus(); + views::Window::CreateChromeWindow(parent, gfx::Rect(), contents); + contents->window()->Show(); + contents->GetDialogClientView()->UpdateDialogButtons(); + contents->title_tf_->SelectAll(); + contents->title_tf_->RequestFocus(); } -bool EditKeywordController::IsModal() const { - // If we were called without a KeywordEditorView, and our associated - // window happens to have gone away while the TemplateURLFetcher was - // loading, we might not have a valid parent anymore. - // ::IsWindow() returns a BOOL, which is a typedef for an int and causes a - // warning if we try to return it or cast it as a bool. - if (::IsWindow(parent_)) - return true; - return false; +bool EditSearchEngineDialog::IsModal() const { + return true; } -std::wstring EditKeywordController::GetWindowTitle() const { - return l10n_util::GetString(template_url() ? +std::wstring EditSearchEngineDialog::GetWindowTitle() const { + return l10n_util::GetString(controller_->template_url() ? IDS_SEARCH_ENGINES_EDITOR_EDIT_WINDOW_TITLE : IDS_SEARCH_ENGINES_EDITOR_NEW_WINDOW_TITLE); } -bool EditKeywordController::IsDialogButtonEnabled( +bool EditSearchEngineDialog::IsDialogButtonEnabled( MessageBoxFlags::DialogButton button) const { if (button == MessageBoxFlags::DIALOGBUTTON_OK) { - return (IsKeywordValid() && IsTitleValid() && IsURLValid()); + return (controller_->IsKeywordValid(keyword_tf_->text()) && + controller_->IsTitleValid(title_tf_->text()) && + controller_->IsURLValid(url_tf_->text())); } return true; } -void EditKeywordController::DeleteDelegate() { - // User canceled the save, delete us. - delete this; -} - -bool EditKeywordController::Cancel() { - CleanUpCancelledAdd(); +bool EditSearchEngineDialog::Cancel() { + controller_->CleanUpCancelledAdd(); return true; } -bool EditKeywordController::Accept() { - AcceptAddOrEdit(); +bool EditSearchEngineDialog::Accept() { + controller_->AcceptAddOrEdit(keyword_tf_->text(), title_tf_->text(), + url_tf_->text()); return true; } -views::View* EditKeywordController::GetContentsView() { - return view_; +views::View* EditSearchEngineDialog::GetContentsView() { + return this; } -void EditKeywordController::ContentsChanged(Textfield* sender, - const std::wstring& new_contents) { +void EditSearchEngineDialog::ContentsChanged(Textfield* sender, + const std::wstring& new_contents) { GetDialogClientView()->UpdateDialogButtons(); UpdateImageViews(); } -bool EditKeywordController::HandleKeystroke( +bool EditSearchEngineDialog::HandleKeystroke( Textfield* sender, const views::Textfield::Keystroke& key) { return false; } -void EditKeywordController::Init() { +void EditSearchEngineDialog::Init() { // Create the views we'll need. - view_ = new views::View(); - if (template_url()) { - title_tf_ = CreateTextfield(template_url()->short_name(), false); - keyword_tf_ = CreateTextfield(template_url()->keyword(), true); - url_tf_ = CreateTextfield(GetDisplayURL(*template_url()), false); + if (controller_->template_url()) { + title_tf_ = + CreateTextfield(controller_->template_url()->short_name(), false); + keyword_tf_ = CreateTextfield(controller_->template_url()->keyword(), true); + url_tf_ = + CreateTextfield(GetDisplayURL(*controller_->template_url()), false); // We don't allow users to edit prepopulate URLs. This is done as // occasionally we need to update the URL of prepopulated TemplateURLs. - url_tf_->SetReadOnly(template_url()->prepopulate_id() != 0); + url_tf_->SetReadOnly(controller_->template_url()->prepopulate_id() != 0); } else { title_tf_ = CreateTextfield(std::wstring(), false); keyword_tf_ = CreateTextfield(std::wstring(), true); @@ -145,8 +144,8 @@ void EditKeywordController::Init() { const int unrelated_y = kUnrelatedControlVerticalSpacing; // View and GridLayout take care of deleting GridLayout for us. - GridLayout* layout = CreatePanelGridLayout(view_); - view_->SetLayoutManager(layout); + GridLayout* layout = CreatePanelGridLayout(this); + SetLayoutManager(layout); // Define the structure of the layout. @@ -221,14 +220,14 @@ void EditKeywordController::Init() { layout->AddPaddingRow(0, related_y); } -views::Label* EditKeywordController::CreateLabel(int message_id) { +views::Label* EditSearchEngineDialog::CreateLabel(int message_id) { views::Label* label = new views::Label(l10n_util::GetString(message_id)); label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); return label; } -Textfield* EditKeywordController::CreateTextfield(const std::wstring& text, - bool lowercase) { +Textfield* EditSearchEngineDialog::CreateTextfield(const std::wstring& text, + bool lowercase) { Textfield* text_field = new Textfield( lowercase ? Textfield::STYLE_LOWERCASE : Textfield::STYLE_DEFAULT); text_field->SetText(text); @@ -236,29 +235,18 @@ Textfield* EditKeywordController::CreateTextfield(const std::wstring& text, return text_field; } -std::wstring EditKeywordController::GetURLInput() const { - return url_tf_->text(); -} - -std::wstring EditKeywordController::GetKeywordInput() const { - return keyword_tf_->text(); -} - -std::wstring EditKeywordController::GetTitleInput() const { - return title_tf_->text(); -} - -void EditKeywordController::UpdateImageViews() { - UpdateImageView(keyword_iv_, IsKeywordValid(), +void EditSearchEngineDialog::UpdateImageViews() { + UpdateImageView(keyword_iv_, controller_->IsKeywordValid(keyword_tf_->text()), IDS_SEARCH_ENGINES_INVALID_KEYWORD_TT); - UpdateImageView(url_iv_, IsURLValid(), IDS_SEARCH_ENGINES_INVALID_URL_TT); - UpdateImageView(title_iv_, IsTitleValid(), + UpdateImageView(url_iv_, controller_->IsURLValid(url_tf_->text()), + IDS_SEARCH_ENGINES_INVALID_URL_TT); + UpdateImageView(title_iv_, controller_->IsTitleValid(title_tf_->text()), IDS_SEARCH_ENGINES_INVALID_TITLE_TT); } -void EditKeywordController::UpdateImageView(ImageView* image_view, - bool is_valid, - int invalid_message_id) { +void EditSearchEngineDialog::UpdateImageView(ImageView* image_view, + bool is_valid, + int invalid_message_id) { if (is_valid) { image_view->SetTooltipText(std::wstring()); image_view->SetImage( diff --git a/chrome/browser/views/edit_keyword_controller.h b/chrome/browser/views/edit_search_engine_dialog.h index fe79f4f..9f12cc1 100644 --- a/chrome/browser/views/edit_keyword_controller.h +++ b/chrome/browser/views/edit_search_engine_dialog.h @@ -2,17 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// EditKeywordController provides text fields for editing a keyword: the title, +// EditSearchEngineDialog provides text fields for editing a keyword: the title, // url and actual keyword. It is used by the KeywordEditorView of the Options // dialog, and also on its own to confirm the addition of a keyword added by // the ExternalJSObject via the RenderView. -#ifndef CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H_ -#define CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H_ +#ifndef CHROME_BROWSER_VIEWS_EDIT_SEARCH_ENGINE_DIALOG_H_ +#define CHROME_BROWSER_VIEWS_EDIT_SEARCH_ENGINE_DIALOG_H_ #include <windows.h> -#include "chrome/browser/search_engines/edit_keyword_controller_base.h" #include "views/controls/textfield/textfield.h" #include "views/window/dialog_delegate.h" @@ -22,32 +21,33 @@ class ImageView; class Window; } +class EditSearchEngineController; +class EditSearchEngineControllerDelegate; class Profile; class TemplateURL; class TemplateURLModel; -class EditKeywordController : public views::Textfield::Controller, - public views::DialogDelegate, - public EditKeywordControllerBase { +class EditSearchEngineDialog : public views::View, + public views::Textfield::Controller, + public views::DialogDelegate { public: // The |template_url| and/or |delegate| may be NULL. - EditKeywordController(HWND parent, - const TemplateURL* template_url, - Delegate* delegate, - Profile* profile); - - virtual ~EditKeywordController() {} - - // Shows the dialog to the user. EditKeywordController takes care of - // deleting itself after show has been invoked. - void Show(); - - // DialogDelegate overrides. + EditSearchEngineDialog(const TemplateURL* template_url, + EditSearchEngineControllerDelegate* delegate, + Profile* profile); + virtual ~EditSearchEngineDialog() {} + + // Shows the dialog to the user. + static void Show(gfx::NativeWindow parent, + const TemplateURL* template_url, + EditSearchEngineControllerDelegate* delegate, + Profile* profile); + + // views::DialogDelegate overrides. virtual bool IsModal() const; virtual std::wstring GetWindowTitle() const; virtual bool IsDialogButtonEnabled( MessageBoxFlags::DialogButton button) const; - virtual void DeleteDelegate(); virtual bool Cancel(); virtual bool Accept(); virtual views::View* GetContentsView(); @@ -70,11 +70,6 @@ class EditKeywordController : public views::Textfield::Controller, // Textfield is configured to map all input to lower case. views::Textfield* CreateTextfield(const std::wstring& text, bool lowercase); - // EditKeywordControllerBase overrides - virtual std::wstring GetURLInput() const; - virtual std::wstring GetKeywordInput() const; - virtual std::wstring GetTitleInput() const; - // Invokes UpdateImageView for each of the images views. void UpdateImageViews(); @@ -101,7 +96,9 @@ class EditKeywordController : public views::Textfield::Controller, views::ImageView* keyword_iv_; views::ImageView* url_iv_; - DISALLOW_COPY_AND_ASSIGN(EditKeywordController); + scoped_ptr<EditSearchEngineController> controller_; + + DISALLOW_COPY_AND_ASSIGN(EditSearchEngineDialog); }; -#endif // CHROME_BROWSER_VIEWS_EDIT_KEYWORD_CONTROLLER_H_ +#endif // CHROME_BROWSER_VIEWS_EDIT_SEARCH_ENGINE_DIALOG_H_ diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index bfb85f8..ea96ac1 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -809,6 +809,12 @@ void BrowserView::DisableInactiveFrame() { frame_->GetWindow()->DisableInactiveRendering(); } +void BrowserView::ConfirmAddSearchProvider(const TemplateURL* template_url, + Profile* profile) { + browser::EditSearchEngine(GetWindow()->GetNativeWindow(), template_url, NULL, + profile); +} + void BrowserView::ToggleBookmarkBar() { bookmark_utils::ToggleWhenVisible(browser_->profile()); } diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 03b75a3..4ca85c4 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -213,6 +213,8 @@ class BrowserView : public BrowserWindow, virtual bool IsBookmarkBarVisible() const; virtual gfx::Rect GetRootWindowResizerRect() const; virtual void DisableInactiveFrame(); + virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, + Profile* profile); virtual void ToggleBookmarkBar(); virtual void ShowAboutChromeDialog(); virtual void ShowTaskManager(); diff --git a/chrome/browser/views/keyword_editor_view.cc b/chrome/browser/views/keyword_editor_view.cc index bfe3065..bfdd65d 100644 --- a/chrome/browser/views/keyword_editor_view.cc +++ b/chrome/browser/views/keyword_editor_view.cc @@ -16,7 +16,7 @@ #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/views/edit_keyword_controller.h" +#include "chrome/browser/views/browser_dialogs.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "googleurl/src/gurl.h" @@ -584,10 +584,8 @@ void KeywordEditorView::OnDoubleClick() { void KeywordEditorView::ButtonPressed(views::Button* sender) { if (sender == add_button_) { - EditKeywordController* controller = - new EditKeywordController(GetWidget()->GetNativeView(), NULL, this, - profile_); - controller->Show(); + browser::EditSearchEngine(GetWindow()->GetNativeWindow(), NULL, this, + profile_); } else if (sender == remove_button_) { DCHECK(table_view_->SelectedRowCount() > 0); // Remove the observer while we modify the model, that way we don't need to @@ -613,10 +611,8 @@ void KeywordEditorView::ButtonPressed(views::Button* sender) { const int selected_row = table_view_->FirstSelectedRow(); const TemplateURL* template_url = &table_model_->GetTemplateURL(selected_row); - EditKeywordController* controller = - new EditKeywordController(GetWidget()->GetNativeView(), template_url, - this, profile_); - controller->Show(); + browser::EditSearchEngine(GetWindow()->GetNativeWindow(), template_url, + this, profile_); } else if (sender == make_default_button_) { MakeDefaultSearchProvider(); } else { diff --git a/chrome/browser/views/keyword_editor_view.h b/chrome/browser/views/keyword_editor_view.h index a0b56ad..c906d65 100644 --- a/chrome/browser/views/keyword_editor_view.h +++ b/chrome/browser/views/keyword_editor_view.h @@ -9,7 +9,7 @@ #include <map> #include "app/table_model.h" -#include "chrome/browser/search_engines/edit_keyword_controller_base.h" +#include "chrome/browser/search_engines/edit_search_engine_controller.h" #include "chrome/browser/search_engines/template_url_model.h" #include "views/controls/button/button.h" #include "views/controls/table/table_view_observer.h" @@ -121,7 +121,7 @@ class KeywordEditorView : public views::View, public views::ButtonListener, public TemplateURLModelObserver, public views::DialogDelegate, - public EditKeywordControllerBase::Delegate { + public EditSearchEngineControllerDelegate { friend class KeywordEditorViewTest; FRIEND_TEST(KeywordEditorViewTest, MakeDefault); public: @@ -132,7 +132,7 @@ class KeywordEditorView : public views::View, explicit KeywordEditorView(Profile* profile); virtual ~KeywordEditorView(); - // Overridden from EditKeywordControllerBase::Delegate. + // Overridden from EditSearchEngineControllerDelegate. // Calls AddTemplateURL or ModifyTemplateURL as appropriate. virtual void OnEditedKeyword(const TemplateURL* template_url, const std::wstring& title, |