diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 23:00:17 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 23:00:17 +0000 |
commit | f9c773362c778437308629ff41d117a1a1cdda81 (patch) | |
tree | ef680b3fde7340a63f56b613cd5fa151e157a1cd /chrome | |
parent | c3c656369b267ecc86962085af5202764012c72d (diff) | |
download | chromium_src-f9c773362c778437308629ff41d117a1a1cdda81.zip chromium_src-f9c773362c778437308629ff41d117a1a1cdda81.tar.gz chromium_src-f9c773362c778437308629ff41d117a1a1cdda81.tar.bz2 |
Adds (non-working) folders and GTK dialogs.
- Folders can be created and edited in the bookmark bar. They
aren't drop targets nor do they popup a menu with their contents.
- Refactor the input window interface to be platform neutral
and use that in EditFolderController.
Review URL: http://codereview.chromium.org/87010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14371 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_context_menu.cc | 66 | ||||
-rw-r--r-- | chrome/browser/browser.vcproj | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 64 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 5 | ||||
-rw-r--r-- | chrome/browser/input_window_dialog.h | 52 | ||||
-rw-r--r-- | chrome/browser/input_window_dialog_gtk.cc | 166 | ||||
-rw-r--r-- | chrome/browser/input_window_dialog_win.cc (renamed from chrome/browser/views/input_window.cc) | 104 | ||||
-rw-r--r-- | chrome/browser/views/browser_views.vcproj | 8 | ||||
-rw-r--r-- | chrome/browser/views/input_window.h | 43 | ||||
-rw-r--r-- | chrome/chrome.gyp | 5 |
10 files changed, 393 insertions, 128 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu.cc b/chrome/browser/bookmarks/bookmark_context_menu.cc index ae0e22c..57f3631 100644 --- a/chrome/browser/bookmarks/bookmark_context_menu.cc +++ b/chrome/browser/bookmarks/bookmark_context_menu.cc @@ -4,10 +4,12 @@ #include "chrome/browser/bookmarks/bookmark_context_menu.h" +#include "base/compiler_specific.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/input_window_dialog.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/page_navigator.h" @@ -21,7 +23,6 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/bookmark_editor_view.h" #include "chrome/browser/views/bookmark_manager_view.h" -#include "chrome/browser/views/input_window.h" #include "chrome/views/window/window.h" #endif @@ -40,14 +41,13 @@ bool NodeHasURLs(BookmarkNode* node) { return false; } -#if defined(OS_WIN) // EditFolderController ------------------------------------------------------- // EditFolderController manages the editing and/or creation of a folder. If the // user presses ok, the name change is committed to the model. // // EditFolderController deletes itself when the window is closed. -class EditFolderController : public InputWindowDelegate, +class EditFolderController : public InputWindowDialog::Delegate, public BookmarkModelObserver { public: virtual ~EditFolderController() { @@ -78,37 +78,41 @@ class EditFolderController : public InputWindowDelegate, is_new_(is_new), show_in_manager_(show_in_manager) { DCHECK(is_new_ || node); - window_ = CreateInputWindow(wnd, this); - model_->AddObserver(this); - } - void Show() { - window_->Show(); - } + std::wstring title = is_new_ ? + l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE_NEW) : + l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE); + std::wstring label = + l10n_util::GetString(IDS_BOOMARK_BAR_EDIT_FOLDER_LABEL); + std::wstring contents = is_new_ ? + l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME) : + node_->GetTitle(); - // InputWindowDelegate methods. - virtual std::wstring GetTextFieldLabel() { - return l10n_util::GetString(IDS_BOOMARK_BAR_EDIT_FOLDER_LABEL); + dialog_ = InputWindowDialog::Create(wnd, title, label, contents, this); + model_->AddObserver(this); } - virtual std::wstring GetTextFieldContents() { - if (is_new_) - return l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME); - return node_->GetTitle(); + void Show() { + dialog_->Show(); } + // InputWindowDialog::Delegate methods. virtual bool IsValid(const std::wstring& text) { return !text.empty(); } virtual void InputAccepted(const std::wstring& text) { if (is_new_) { - BookmarkNode* node = + ALLOW_UNUSED BookmarkNode* node = model_->AddGroup(node_, node_->GetChildCount(), text); if (show_in_manager_) { +#if defined(OS_WIN) BookmarkManagerView* manager = BookmarkManagerView::current(); if (manager && manager->profile() == profile_) manager->SelectInTree(node); +#else + NOTIMPLEMENTED() << "BookmarkManagerView not yet implemented"; +#endif } } else { model_->SetTitle(node_, text); @@ -118,16 +122,6 @@ class EditFolderController : public InputWindowDelegate, virtual void InputCanceled() { } - virtual void DeleteDelegate() { - delete this; - } - - virtual std::wstring GetWindowTitle() const { - return is_new_ ? - l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE_NEW) : - l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE); - } - // BookmarkModelObserver methods, all invoke ModelChanged and close the // dialog. virtual void Loaded(BookmarkModel* model) {} @@ -171,7 +165,7 @@ class EditFolderController : public InputWindowDelegate, } void ModelChanged() { - window_->Close(); + dialog_->Close(); } Profile* profile_; @@ -185,11 +179,12 @@ class EditFolderController : public InputWindowDelegate, // If is_new_ is true and a new node is created, it is selected in the // bookmark manager. bool show_in_manager_; - views::Window* window_; + InputWindowDialog* dialog_; DISALLOW_COPY_AND_ASSIGN(EditFolderController); }; +#if defined(OS_WIN) // SelectOnCreationHandler ---------------------------------------------------- // Used when adding a new bookmark. If a new bookmark is created it is selected @@ -340,8 +335,8 @@ void BookmarkContextMenu::ExecuteCommand(int id) { return; } -#if defined(OS_WIN) if (selection_[0]->is_url()) { +#if defined(OS_WIN) BookmarkEditorView::Configuration editor_config; if (configuration_ == BOOKMARK_BAR) editor_config = BookmarkEditorView::SHOW_TREE; @@ -349,13 +344,13 @@ void BookmarkContextMenu::ExecuteCommand(int id) { editor_config = BookmarkEditorView::NO_TREE; BookmarkEditorView::Show(wnd_, profile_, NULL, selection_[0], editor_config, NULL); +#else + NOTIMPLEMENTED() << "BookmarkEditorView unimplemented"; +#endif } else { EditFolderController::Show(profile_, wnd_, selection_[0], false, false); } -#else - NOTIMPLEMENTED() << "IDS_BOOKMARK_BAR_RENAME_FOLDER / BAR_EDIT"; -#endif break; case IDS_BOOKMARK_BAR_REMOVE: { @@ -394,13 +389,8 @@ void BookmarkContextMenu::ExecuteCommand(int id) { case IDS_BOOMARK_BAR_NEW_FOLDER: { UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_NewFolder", profile_); - -#if defined(OS_WIN) EditFolderController::Show(profile_, wnd_, GetParentForNewNodes(), true, (configuration_ != BOOKMARK_BAR)); -#else - NOTIMPLEMENTED() << "New Folder not implemented"; -#endif break; } diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index a698e6f..854355d 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -402,6 +402,14 @@ > </File> <File + RelativePath=".\input_window_dialog.h" + > + </File> + <File + RelativePath=".\input_window_dialog_win.cc" + > + </File> + <File RelativePath=".\jankometer.cc" > </File> diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 0c8346e..85a6bb7 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -127,8 +127,9 @@ void BookmarkBarGtk::Init(Profile* profile) { other_bookmarks_button_ = gtk_chrome_button_new(); g_signal_connect(other_bookmarks_button_, "button-press-event", G_CALLBACK(&OnButtonPressed), this); - gtk_button_set_label(GTK_BUTTON(other_bookmarks_button_), - "Other bookmarks"); + gtk_button_set_label( + GTK_BUTTON(other_bookmarks_button_), + l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str()); gtk_button_set_image(GTK_BUTTON(other_bookmarks_button_), gtk_image_new_from_pixbuf(folder_icon)); @@ -301,6 +302,12 @@ void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node, gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(default_bookmark_icon)); } + } else { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed( + IDR_BOOKMARK_BAR_FOLDER); + gtk_button_set_image(GTK_BUTTON(button), + gtk_image_new_from_pixbuf(default_bookmark_icon)); } } @@ -309,18 +316,19 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton( GtkWidget* button = gtk_chrome_button_new(); ConfigureButtonForNode(node, button); - if (node->is_url()) { - // The tool item is also a source for dragging - gtk_drag_source_set(button, GDK_BUTTON1_MASK, - target_table, G_N_ELEMENTS(target_table), - GDK_ACTION_MOVE); - g_signal_connect(G_OBJECT(button), "drag-begin", - G_CALLBACK(&OnButtonDragBegin), this); - g_signal_connect(G_OBJECT(button), "drag-end", - G_CALLBACK(&OnButtonDragEnd), this); + // The tool item is also a source for dragging + gtk_drag_source_set(button, GDK_BUTTON1_MASK, + target_table, G_N_ELEMENTS(target_table), + GDK_ACTION_MOVE); + g_signal_connect(G_OBJECT(button), "drag-begin", + G_CALLBACK(&OnButtonDragBegin), this); + g_signal_connect(G_OBJECT(button), "drag-end", + G_CALLBACK(&OnButtonDragEnd), this); + + if (node->is_url()) { // Connect to 'button-release-event' instead of 'clicked' because we need - // to access to the modifier keys and we do different things on each + // access to the modifier keys and we do different things on each // button. g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(OnButtonPressed), this); @@ -328,7 +336,16 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton( G_CALLBACK(OnButtonReleased), this); GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); } else { - NOTIMPLEMENTED(); + // TODO(erg): This button can also be a drop target. + + // Connect to 'button-release-event' instead of 'clicked' because we need + // access to the modifier keys and we do different things on each + // button. + g_signal_connect(G_OBJECT(button), "button-press-event", + G_CALLBACK(OnButtonPressed), this); + g_signal_connect(G_OBJECT(button), "button-release-event", + G_CALLBACK(OnFolderButtonReleased), this); + GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); } return button; @@ -424,6 +441,7 @@ gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender, return FALSE; } +// static gboolean BookmarkBarGtk::OnButtonReleased(GtkWidget* sender, GdkEventButton* event, BookmarkBarGtk* bar) { @@ -506,6 +524,26 @@ void BookmarkBarGtk::OnButtonDragEnd(GtkWidget* button, } // static +gboolean BookmarkBarGtk::OnFolderButtonReleased(GtkWidget* sender, + GdkEventButton* event, + BookmarkBarGtk* bar) { + if (bar->ignore_button_release_) { + // Don't handle this message; it was a drag. + bar->ignore_button_release_ = false; + return FALSE; + } + + BookmarkNode* node = bar->GetNodeForToolButton(sender); + DCHECK(node); + DCHECK(bar->page_navigator_); + + NOTIMPLEMENTED() << "Flesh this out once I can make folders."; + + // Allow other handlers to run so the button state is updated correctly. + return FALSE; +} + +// static gboolean BookmarkBarGtk::OnToolbarExpose(GtkWidget* widget, GdkEventExpose* event, BookmarkBarGtk* bar) { diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index 0a37d51..17f508f 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -131,6 +131,11 @@ class BookmarkBarGtk : public BookmarkModelObserver { GdkDragContext* drag_context, BookmarkBarGtk* bar); + // GtkButton callbacks for folder buttons + static gboolean OnFolderButtonReleased(GtkWidget* sender, + GdkEventButton* event, + BookmarkBarGtk* bar); + // GtkToolbar callbacks static gboolean OnToolbarExpose(GtkWidget* widget, GdkEventExpose* event, BookmarkBarGtk* window); diff --git a/chrome/browser/input_window_dialog.h b/chrome/browser/input_window_dialog.h new file mode 100644 index 0000000..5229c1b --- /dev/null +++ b/chrome/browser/input_window_dialog.h @@ -0,0 +1,52 @@ +// Copyright (c) 2009 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_INPUT_WINDOW_DIALOG_H_ +#define CHROME_BROWSER_INPUT_WINDOW_DIALOG_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/gfx/native_widget_types.h" + +// Cross platform access to a modal input window. +class InputWindowDialog { + public: + class Delegate { + public: + virtual ~Delegate() { } + + // Checks whether |text| is a valid input string. + virtual bool IsValid(const std::wstring& text) = 0; + + // Callback for when the user clicks the OK button. + virtual void InputAccepted(const std::wstring& text) = 0; + + // Callback for when the user clicks the Cancel button. + virtual void InputCanceled() = 0; + }; + + // Creates a new input window dialog from the parent window + // |parent|, Ownership of |delegate| is taken by InputWindowDialog or + // InputWindowDialog's owner. + static InputWindowDialog* Create(gfx::NativeWindow parent, + const std::wstring& window_title, + const std::wstring& label, + const std::wstring& contents, + Delegate* delegate); + + // Displays the window. + virtual void Show() = 0; + + // Closes the window. + virtual void Close() = 0; + + protected: + InputWindowDialog() { } + + private: + DISALLOW_COPY_AND_ASSIGN(InputWindowDialog); +}; + +#endif // CHROME_BROWSER_INPUT_WINDOW_DIALOG_H_ diff --git a/chrome/browser/input_window_dialog_gtk.cc b/chrome/browser/input_window_dialog_gtk.cc new file mode 100644 index 0000000..8ef031e --- /dev/null +++ b/chrome/browser/input_window_dialog_gtk.cc @@ -0,0 +1,166 @@ +// Copyright (c) 2009 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/input_window_dialog.h" + +#include <gtk/gtk.h> + +#include "base/message_loop.h" +#include "base/scoped_ptr.h" +#include "base/string_util.h" + +class GtkInputWindowDialog : public InputWindowDialog { + public: + // Creates a dialog. Takes ownership of |delegate|. + GtkInputWindowDialog(GtkWindow* parent, + const std::string& window_title, + const std::string& label, + const std::string& contents, + Delegate* delegate); + virtual ~GtkInputWindowDialog(); + + virtual void Show(); + virtual void Close(); + + private: + static void OnEntryChanged(GtkEditable* entry, + GtkInputWindowDialog* window); + + static void OnResponse(GtkDialog* dialog, int response_id, + GtkInputWindowDialog* window); + + static gboolean OnWindowDeleteEvent(GtkWidget* widget, + GdkEvent* event, + GtkInputWindowDialog* dialog); + + static void OnWindowDestroy(GtkWidget* widget, GtkInputWindowDialog* dialog); + + // The underlying gtk dialog window. + GtkWidget* dialog_; + + // The Cancel or Close button + GtkWidget* close_button_; + + // The OK button. + GtkWidget* ok_button_; + + // The GtkEntry in this form. + GtkWidget* input_; + + // Our delegate. Consumes the window's output. + scoped_ptr<InputWindowDialog::Delegate> delegate_; +}; + + +GtkInputWindowDialog::GtkInputWindowDialog(GtkWindow* parent, + const std::string& window_title, + const std::string& label, + const std::string& contents, + Delegate* delegate) + : dialog_(gtk_dialog_new_with_buttons( + window_title.c_str(), + parent, + GTK_DIALOG_MODAL, + NULL)), + close_button_(gtk_dialog_add_button(GTK_DIALOG(dialog_), + GTK_STOCK_CANCEL, + GTK_RESPONSE_REJECT)), + ok_button_(gtk_dialog_add_button(GTK_DIALOG(dialog_), + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT)), + delegate_(delegate) { + gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); + + GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; + GtkWidget* hbox = gtk_hbox_new(FALSE, 5); + GtkWidget* label_widget = gtk_label_new(label.c_str()); + gtk_box_pack_start(GTK_BOX(hbox), label_widget, FALSE, FALSE, 0); + + input_ = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(input_), contents.c_str()); + g_signal_connect(G_OBJECT(input_), "changed", + G_CALLBACK(OnEntryChanged), this); + g_object_set(G_OBJECT(input_), "activates-default", TRUE, NULL); + gtk_box_pack_start(GTK_BOX(hbox), input_, TRUE, TRUE, 0); + + gtk_widget_show_all(hbox); + gtk_container_set_border_width(GTK_CONTAINER(hbox), 5); + gtk_box_pack_start(GTK_BOX(content_area), hbox, FALSE, FALSE, 0); + + g_signal_connect(dialog_, "response", + G_CALLBACK(OnResponse), this); + g_signal_connect(dialog_, "delete-event", + G_CALLBACK(OnWindowDeleteEvent), this); + g_signal_connect(dialog_, "destroy", + G_CALLBACK(OnWindowDestroy), this); +} + +GtkInputWindowDialog::~GtkInputWindowDialog() { +} + +void GtkInputWindowDialog::Show() { + gtk_widget_show(GTK_WIDGET(dialog_)); +} + +void GtkInputWindowDialog::Close() { + // Under the model that we've inherited from Windows, dialogs can receive + // more than one Close() call inside the current message loop event. + if (dialog_) { + gtk_widget_destroy(GTK_WIDGET(dialog_)); + dialog_ = NULL; + } +} + +// static +void GtkInputWindowDialog::OnEntryChanged(GtkEditable* entry, + GtkInputWindowDialog* window) { + std::wstring value(UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(entry)))); + gtk_widget_set_sensitive(GTK_WIDGET(window->ok_button_), + window->delegate_->IsValid(value)); +} + +// static +void GtkInputWindowDialog::OnResponse(GtkDialog* dialog, int response_id, + GtkInputWindowDialog* window) { + if (response_id == GTK_RESPONSE_ACCEPT) { + std::wstring value(UTF8ToWide(gtk_entry_get_text( + GTK_ENTRY(window->input_)))); + window->delegate_->InputAccepted(value); + } else { + window->delegate_->InputCanceled(); + } + + window->Close(); +} + +// static +gboolean GtkInputWindowDialog::OnWindowDeleteEvent( + GtkWidget* widget, + GdkEvent* event, + GtkInputWindowDialog* dialog) { + dialog->Close(); + + // Return true to prevent the gtk dialog from being destroyed. Close will + // destroy it for us and the default gtk_dialog_delete_event_handler() will + // force the destruction without us being able to stop it. + return TRUE; +} + +// static +void GtkInputWindowDialog::OnWindowDestroy(GtkWidget* widget, + GtkInputWindowDialog* dialog) { + MessageLoop::current()->DeleteSoon(FROM_HERE, dialog); +} + +// static +InputWindowDialog* InputWindowDialog::Create(gfx::NativeWindow parent, + const std::wstring& window_title, + const std::wstring& label, + const std::wstring& contents, + Delegate* delegate) { + return new GtkInputWindowDialog(parent, + WideToUTF8(window_title), + WideToUTF8(label), + WideToUTF8(contents), + delegate); +} diff --git a/chrome/browser/views/input_window.cc b/chrome/browser/input_window_dialog_win.cc index 2bc2363..9d1fa2b 100644 --- a/chrome/browser/views/input_window.cc +++ b/chrome/browser/input_window_dialog_win.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/views/input_window.h" +#include "chrome/browser/input_window_dialog.h" #include "base/message_loop.h" #include "base/task.h" @@ -11,22 +11,54 @@ #include "chrome/views/grid_layout.h" #include "chrome/views/controls/label.h" #include "chrome/views/controls/text_field.h" +#include "chrome/views/window/dialog_delegate.h" #include "chrome/views/window/window.h" #include "grit/generated_resources.h" // Width to make the text field, in pixels. static const int kTextFieldWidth = 200; -// ContentView ---------------------------------------------------------------- +class ContentView; + +// The Windows implementation of the cross platform input dialog interface. +class WinInputWindowDialog : public InputWindowDialog { + public: + WinInputWindowDialog(HWND parent, + const std::wstring& window_title, + const std::wstring& label, + const std::wstring& contents, + Delegate* delegate); + virtual ~WinInputWindowDialog(); + + virtual void Show(); + virtual void Close(); + + const std::wstring& window_title() const { return window_title_; } + const std::wstring& label() const { return label_; } + const std::wstring& contents() const { return contents_; } + + InputWindowDialog::Delegate* delegate() { return delegate_.get(); } + + private: + // Our chrome views window. + views::Window* window_; + + // Strings to feed to the on screen window. + std::wstring window_title_; + std::wstring label_; + std::wstring contents_; + + // Our delegate. Consumes the window's output. + scoped_ptr<InputWindowDialog::Delegate> delegate_; +}; // ContentView, as the name implies, is the content view for the InputWindow. // It registers accelerators that accept/cancel the input. - class ContentView : public views::View, public views::DialogDelegate, public views::TextField::Controller { public: - explicit ContentView(InputWindowDelegate* delegate) + explicit ContentView(WinInputWindowDialog* delegate) : delegate_(delegate), focus_grabber_factory_(this) { DCHECK(delegate_); @@ -37,7 +69,6 @@ class ContentView : public views::View, MessageBoxFlags::DialogButton button) const; virtual bool Accept(); virtual bool Cancel(); - virtual void WindowClosing(); virtual void DeleteDelegate(); virtual std::wstring GetWindowTitle() const; virtual bool IsModal() const { return true; } @@ -67,7 +98,7 @@ class ContentView : public views::View, // The delegate that the ContentView uses to communicate changes to the // caller. - InputWindowDelegate* delegate_; + WinInputWindowDialog* delegate_; // Helps us set focus to the first TextField in the window. ScopedRunnableMethodFactory<ContentView> focus_grabber_factory_; @@ -81,32 +112,28 @@ class ContentView : public views::View, bool ContentView::IsDialogButtonEnabled( MessageBoxFlags::DialogButton button) const { if (button == MessageBoxFlags::DIALOGBUTTON_OK && - !delegate_->IsValid(text_field_->GetText())) { + !delegate_->delegate()->IsValid(text_field_->GetText())) { return false; } return true; } bool ContentView::Accept() { - delegate_->InputAccepted(text_field_->GetText()); + delegate_->delegate()->InputAccepted(text_field_->GetText()); return true; } bool ContentView::Cancel() { - delegate_->InputCanceled(); + delegate_->delegate()->InputCanceled(); return true; } -void ContentView::WindowClosing() { - delegate_->WindowClosing(); -} - void ContentView::DeleteDelegate() { - delegate_->DeleteDelegate(); + delete delegate_; } std::wstring ContentView::GetWindowTitle() const { - return delegate_->GetWindowTitle(); + return delegate_->window_title(); } views::View* ContentView::GetContentsView() { @@ -136,7 +163,7 @@ void ContentView::ViewHierarchyChanged(bool is_add, void ContentView::InitControlLayout() { text_field_ = new views::TextField; - text_field_->SetText(delegate_->GetTextFieldContents()); + text_field_->SetText(delegate_->contents()); text_field_->SetController(this); using views::ColumnSet; @@ -154,7 +181,7 @@ void ContentView::InitControlLayout() { GridLayout::USE_PREF, kTextFieldWidth, kTextFieldWidth); layout->StartRow(0, 0); - views::Label* label = new views::Label(delegate_->GetTextFieldLabel()); + views::Label* label = new views::Label(delegate_->label()); layout->AddView(label); layout->AddView(text_field_); @@ -168,11 +195,40 @@ void ContentView::FocusFirstFocusableControl() { text_field_->RequestFocus(); } -views::Window* CreateInputWindow(HWND parent_hwnd, - InputWindowDelegate* delegate) { - views::Window* window = - views::Window::CreateChromeWindow(parent_hwnd, gfx::Rect(), - new ContentView(delegate)); - window->GetClientView()->AsDialogClientView()->UpdateDialogButtons(); - return window; +WinInputWindowDialog::WinInputWindowDialog(HWND parent, + const std::wstring& window_title, + const std::wstring& label, + const std::wstring& contents, + Delegate* delegate) + : window_title_(window_title), + label_(label), + contents_(contents), + delegate_(delegate) { + window_ = views::Window::CreateChromeWindow(parent, gfx::Rect(), + new ContentView(this)); + window_->GetClientView()->AsDialogClientView()->UpdateDialogButtons(); +} + +WinInputWindowDialog::~WinInputWindowDialog() { +} + +void WinInputWindowDialog::Show() { + window_->Show(); +} + +void WinInputWindowDialog::Close() { + window_->Close(); +} + +// static +InputWindowDialog* InputWindowDialog::Create(gfx::NativeWindow parent, + const std::wstring& window_title, + const std::wstring& label, + const std::wstring& contents, + Delegate* delegate) { + return new WinInputWindowDialog(parent, + window_title, + label, + contents, + delegate); } diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj index a923afa..25026a2 100644 --- a/chrome/browser/views/browser_views.vcproj +++ b/chrome/browser/views/browser_views.vcproj @@ -674,14 +674,6 @@ > </File> <File - RelativePath=".\input_window.cc" - > - </File> - <File - RelativePath=".\input_window.h" - > - </File> - <File RelativePath=".\jsmessage_box_dialog.cc" > </File> diff --git a/chrome/browser/views/input_window.h b/chrome/browser/views/input_window.h deleted file mode 100644 index d88ed98..0000000 --- a/chrome/browser/views/input_window.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2006-2008 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_VIEWS_INPUT_WINDOW_H__ -#define CHROME_BROWSER_VIEWS_INPUT_WINDOW_H__ - -#include "chrome/views/window/dialog_delegate.h" - -// InputWindowDelegate -------------------------------------------------------- - -class InputWindowDelegate : public views::DialogDelegate { - public: - // Returns the text displayed on the label preceding the text field. - virtual std::wstring GetTextFieldLabel() = 0; - - // Returns the initial contents of the text field. - virtual std::wstring GetTextFieldContents() { - return std::wstring(); - } - - // Returns whether the text is valid. InputAccepted is only invoked if the - // text is valid. - virtual bool IsValid(const std::wstring& text) { - return true; - } - - // Invoked when the user presses the ok button and the text is fvalid. - virtual void InputAccepted(const std::wstring& text) = 0; - - // Invoked when the user cancels the dialog. - virtual void InputCanceled() {} -}; - - -namespace views { -class Window; -}; - -views::Window* CreateInputWindow(HWND parent_hwnd, - InputWindowDelegate* delegate); - -#endif // CHROME_BROWSER_VIEWS_INPUT_WINDOW_H__ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 6ebcd31..7cdd1c5 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -839,6 +839,9 @@ 'browser/importer/mork_reader.h', 'browser/importer/toolbar_importer.cc', 'browser/importer/toolbar_importer.h', + 'browser/input_window_dialog.h', + 'browser/input_window_dialog_gtk.cc', + 'browser/input_window_dialog_win.cc', 'browser/jankometer.cc', 'browser/jankometer.h', 'browser/jsmessage_box_handler.cc', @@ -1208,8 +1211,6 @@ 'browser/views/infobars/infobar_container.h', 'browser/views/infobars/infobars.cc', 'browser/views/infobars/infobars.h', - 'browser/views/input_window.cc', - 'browser/views/input_window.h', 'browser/views/jsmessage_box_dialog.cc', 'browser/views/jsmessage_box_dialog.h', 'browser/views/keyword_editor_view.cc', |