diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 19:48:37 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 19:48:37 +0000 |
commit | 39b6184b82a4531abbe3597a68703fb30954a22e (patch) | |
tree | 8843de381d3d44a005a63b955eb3d53e6c8ac584 | |
parent | e768baf6ebf5a49cc19d58d1761321b175c82c18 (diff) | |
download | chromium_src-39b6184b82a4531abbe3597a68703fb30954a22e.zip chromium_src-39b6184b82a4531abbe3597a68703fb30954a22e.tar.gz chromium_src-39b6184b82a4531abbe3597a68703fb30954a22e.tar.bz2 |
Revert 52721 - Refactor the implementation of InputWindowDialog.
- Move the implementation of each platform under its respective source directory.
- Rename the classes to match with pattern used in the chrome source.
- In the gtk side, use the gtk signal macros for the callback events.
BUG=None
TEST=open the bookmark editor dialog, everything should works as before on windows and linux.
Review URL: http://codereview.chromium.org/2832028
TBR=tfarina@chromium.org
Review URL: http://codereview.chromium.org/2835043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52727 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/input_window_dialog_gtk.h | 49 | ||||
-rw-r--r-- | chrome/browser/input_window_dialog_gtk.cc (renamed from chrome/browser/gtk/input_window_dialog_gtk.cc) | 98 | ||||
-rw-r--r-- | chrome/browser/input_window_dialog_win.cc (renamed from chrome/browser/views/input_window_dialog_win.cc) | 151 | ||||
-rw-r--r-- | chrome/browser/views/input_window_dialog_win.h | 105 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 6 |
5 files changed, 202 insertions, 207 deletions
diff --git a/chrome/browser/gtk/input_window_dialog_gtk.h b/chrome/browser/gtk/input_window_dialog_gtk.h deleted file mode 100644 index 7f7b736c..0000000 --- a/chrome/browser/gtk/input_window_dialog_gtk.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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_GTK_INPUT_WINDOW_DIALOG_GTK_H_ -#define CHROME_BROWSER_GTK_INPUT_WINDOW_DIALOG_GTK_H_ - -#include <gtk/gtk.h> - -#include "app/gtk_signal.h" -#include "base/basictypes.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/input_window_dialog.h" - -class InputWindowDialogGtk : public InputWindowDialog { - public: - // Creates a dialog. Takes ownership of |delegate|. - InputWindowDialogGtk(GtkWindow* parent, - const std::string& window_title, - const std::string& label, - const std::string& contents, - Delegate* delegate); - virtual ~InputWindowDialogGtk(); - - virtual void Show(); - virtual void Close(); - - private: - CHROMEG_CALLBACK_0(InputWindowDialogGtk, void, OnEntryChanged, GtkEditable*); - - CHROMEGTK_CALLBACK_1(InputWindowDialogGtk, void, OnResponse, int); - - CHROMEGTK_CALLBACK_1(InputWindowDialogGtk, gboolean, - OnWindowDeleteEvent, GdkEvent*); - - CHROMEGTK_CALLBACK_0(InputWindowDialogGtk, void, OnWindowDestroy); - - // The underlying gtk dialog window. - GtkWidget* dialog_; - - // The GtkEntry in this form. - GtkWidget* input_; - - // Our delegate. Consumes the window's output. - scoped_ptr<InputWindowDialog::Delegate> delegate_; - - DISALLOW_COPY_AND_ASSIGN(InputWindowDialogGtk); -}; -#endif // CHROME_BROWSER_GTK_INPUT_WINDOW_DIALOG_GTK_H_ diff --git a/chrome/browser/gtk/input_window_dialog_gtk.cc b/chrome/browser/input_window_dialog_gtk.cc index 2a7e2d0..3e61894 100644 --- a/chrome/browser/gtk/input_window_dialog_gtk.cc +++ b/chrome/browser/input_window_dialog_gtk.cc @@ -1,15 +1,55 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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/gtk/input_window_dialog_gtk.h" +#include "chrome/browser/input_window_dialog.h" + +#include <gtk/gtk.h> #include "base/message_loop.h" +#include "base/scoped_ptr.h" #include "base/string_piece.h" #include "base/utf_string_conversions.h" #include "chrome/browser/gtk/gtk_util.h" -InputWindowDialogGtk::InputWindowDialogGtk(GtkWindow* parent, +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 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, @@ -35,7 +75,7 @@ InputWindowDialogGtk::InputWindowDialogGtk(GtkWindow* parent, input_ = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(input_), contents.c_str()); g_signal_connect(input_, "changed", - G_CALLBACK(OnEntryChangedThunk), this); + 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); @@ -44,21 +84,21 @@ InputWindowDialogGtk::InputWindowDialogGtk(GtkWindow* parent, gtk_box_pack_start(GTK_BOX(content_area), hbox, FALSE, FALSE, 0); g_signal_connect(dialog_, "response", - G_CALLBACK(OnResponseThunk), this); + G_CALLBACK(OnResponse), this); g_signal_connect(dialog_, "delete-event", - G_CALLBACK(OnWindowDeleteEventThunk), this); + G_CALLBACK(OnWindowDeleteEvent), this); g_signal_connect(dialog_, "destroy", - G_CALLBACK(OnWindowDestroyThunk), this); + G_CALLBACK(OnWindowDestroy), this); } -InputWindowDialogGtk::~InputWindowDialogGtk() { +GtkInputWindowDialog::~GtkInputWindowDialog() { } -void InputWindowDialogGtk::Show() { +void GtkInputWindowDialog::Show() { gtk_util::ShowDialog(dialog_); } -void InputWindowDialogGtk::Close() { +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_) { @@ -67,27 +107,35 @@ void InputWindowDialogGtk::Close() { } } -void InputWindowDialogGtk::OnEntryChanged(GtkEditable* entry) { +// static +void GtkInputWindowDialog::OnEntryChanged(GtkEditable* entry, + GtkInputWindowDialog* window) { std::wstring value(UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(entry)))); - gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), + gtk_dialog_set_response_sensitive(GTK_DIALOG(window->dialog_), GTK_RESPONSE_ACCEPT, - delegate_->IsValid(value)); + window->delegate_->IsValid(value)); } -void InputWindowDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { +// 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(input_)))); - delegate_->InputAccepted(value); + std::wstring value(UTF8ToWide(gtk_entry_get_text( + GTK_ENTRY(window->input_)))); + window->delegate_->InputAccepted(value); } else { - delegate_->InputCanceled(); + window->delegate_->InputCanceled(); } - Close(); + window->Close(); } -gboolean InputWindowDialogGtk::OnWindowDeleteEvent(GtkWidget* widget, - GdkEvent* event) { - 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 @@ -95,8 +143,10 @@ gboolean InputWindowDialogGtk::OnWindowDeleteEvent(GtkWidget* widget, return TRUE; } -void InputWindowDialogGtk::OnWindowDestroy(GtkWidget* widget) { - MessageLoop::current()->DeleteSoon(FROM_HERE, this); +// static +void GtkInputWindowDialog::OnWindowDestroy(GtkWidget* widget, + GtkInputWindowDialog* dialog) { + MessageLoop::current()->DeleteSoon(FROM_HERE, dialog); } // static @@ -105,7 +155,7 @@ InputWindowDialog* InputWindowDialog::Create(gfx::NativeWindow parent, const std::wstring& label, const std::wstring& contents, Delegate* delegate) { - return new InputWindowDialogGtk(parent, + return new GtkInputWindowDialog(parent, WideToUTF8(window_title), WideToUTF8(label), WideToUTF8(contents), diff --git a/chrome/browser/views/input_window_dialog_win.cc b/chrome/browser/input_window_dialog_win.cc index 21cf5e5..2d606df 100644 --- a/chrome/browser/views/input_window_dialog_win.cc +++ b/chrome/browser/input_window_dialog_win.cc @@ -1,43 +1,112 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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/views/input_window_dialog_win.h" +#include "chrome/browser/input_window_dialog.h" #include "app/l10n_util.h" #include "base/compiler_specific.h" #include "base/message_loop.h" +#include "base/task.h" #include "views/grid_layout.h" +#include "views/controls/label.h" +#include "views/controls/textfield/textfield.h" #include "views/standard_layout.h" +#include "views/window/dialog_delegate.h" +#include "views/window/window.h" #include "grit/generated_resources.h" // Width to make the text field, in pixels. static const int kTextfieldWidth = 200; -InputWindowDialogWin::InputWindowDialogWin(gfx::NativeWindow 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(); -} +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(WinInputWindowDialog* delegate) + : delegate_(delegate), + ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)) { + DCHECK(delegate_); + } -InputWindowDialogWin::~InputWindowDialogWin() { -} + // views::DialogDelegate overrides: + virtual bool IsDialogButtonEnabled( + MessageBoxFlags::DialogButton button) const; + virtual bool Accept(); + virtual bool Cancel(); + virtual void DeleteDelegate(); + virtual std::wstring GetWindowTitle() const; + virtual bool IsModal() const { return true; } + virtual views::View* GetContentsView(); + + // views::Textfield::Controller overrides: + virtual void ContentsChanged(views::Textfield* sender, + const std::wstring& new_contents); + virtual bool HandleKeystroke(views::Textfield*, + const views::Textfield::Keystroke&) { + return false; + } -void InputWindowDialogWin::Show() { - window_->Show(); -} + protected: + // views::View overrides: + virtual void ViewHierarchyChanged(bool is_add, views::View* parent, + views::View* child); -void InputWindowDialogWin::Close() { - window_->Close(); -} + private: + // Set up dialog controls and layout. + void InitControlLayout(); + + // Sets focus to the first focusable element within the dialog. + void FocusFirstFocusableControl(); + + // The Textfield that the user can type into. + views::Textfield* text_field_; + + // The delegate that the ContentView uses to communicate changes to the + // caller. + WinInputWindowDialog* delegate_; + + // Helps us set focus to the first Textfield in the window. + ScopedRunnableMethodFactory<ContentView> focus_grabber_factory_; + + DISALLOW_COPY_AND_ASSIGN(ContentView); +}; /////////////////////////////////////////////////////////////////////////////// // ContentView, views::DialogDelegate implementation: @@ -61,10 +130,18 @@ bool ContentView::Cancel() { return true; } +void ContentView::DeleteDelegate() { + delete delegate_; +} + std::wstring ContentView::GetWindowTitle() const { return delegate_->window_title(); } +views::View* ContentView::GetContentsView() { + return this; +} + /////////////////////////////////////////////////////////////////////////////// // ContentView, views::Textfield::Controller implementation: @@ -120,16 +197,40 @@ void ContentView::FocusFirstFocusableControl() { text_field_->RequestFocus(); } +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(HWND parent, const std::wstring& window_title, const std::wstring& label, const std::wstring& contents, Delegate* delegate) { - return new InputWindowDialogWin(parent, + return new WinInputWindowDialog(parent, window_title, label, contents, delegate); } - diff --git a/chrome/browser/views/input_window_dialog_win.h b/chrome/browser/views/input_window_dialog_win.h deleted file mode 100644 index beb70f5..0000000 --- a/chrome/browser/views/input_window_dialog_win.h +++ /dev/null @@ -1,105 +0,0 @@ -// 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_VIEWS_INPUT_WINDOW_DIALOG_WIN_H_ -#define CHROME_BROWSER_VIEWS_INPUT_WINDOW_DIALOG_WIN_H_ - -#include "chrome/browser/input_window_dialog.h" - -#include "base/basictypes.h" -#include "base/scoped_ptr.h" -#include "base/task.h" -#include "views/controls/label.h" -#include "views/controls/textfield/textfield.h" -#include "views/window/dialog_delegate.h" -#include "views/window/window.h" - -// The Windows implementation of the cross platform input dialog interface. -class InputWindowDialogWin : public InputWindowDialog { - public: - InputWindowDialogWin(gfx::NativeWindow parent, - const std::wstring& window_title, - const std::wstring& label, - const std::wstring& contents, - Delegate* delegate); - virtual ~InputWindowDialogWin(); - - 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(InputWindowDialogWin* delegate) - : delegate_(delegate), - ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)) { - DCHECK(delegate_); - } - - // views::DialogDelegate overrides: - virtual bool IsDialogButtonEnabled( - MessageBoxFlags::DialogButton button) const; - virtual bool Accept(); - virtual bool Cancel(); - virtual void DeleteDelegate() { delete delegate_; } - virtual std::wstring GetWindowTitle() const; - virtual bool IsModal() const { return true; } - virtual views::View* GetContentsView() { return this; } - - // views::Textfield::Controller overrides: - virtual void ContentsChanged(views::Textfield* sender, - const std::wstring& new_contents); - virtual bool HandleKeystroke(views::Textfield*, - const views::Textfield::Keystroke&) { - return false; - } - - protected: - // views::View overrides: - virtual void ViewHierarchyChanged(bool is_add, views::View* parent, - views::View* child); - - private: - // Set up dialog controls and layout. - void InitControlLayout(); - - // Sets focus to the first focusable element within the dialog. - void FocusFirstFocusableControl(); - - // The Textfield that the user can type into. - views::Textfield* text_field_; - - // The delegate that the ContentView uses to communicate changes to the - // caller. - InputWindowDialogWin* delegate_; - - // Helps us set focus to the first Textfield in the window. - ScopedRunnableMethodFactory<ContentView> focus_grabber_factory_; - - DISALLOW_COPY_AND_ASSIGN(ContentView); -}; - -#endif // CHROME_BROWSER_VIEWS_INPUT_WINDOW_DIALOG_WIN_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 366ae95..7da139b 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1529,8 +1529,6 @@ 'browser/gtk/infobar_container_gtk.h', 'browser/gtk/infobar_gtk.cc', 'browser/gtk/infobar_gtk.h', - 'browser/gtk/input_window_dialog_gtk.cc', - 'browser/gtk/input_window_dialog_gtk.h', 'browser/gtk/keyword_editor_view.cc', 'browser/gtk/keyword_editor_view.h', 'browser/gtk/location_bar_view_gtk.cc', @@ -1779,6 +1777,8 @@ 'browser/in_process_webkit/webkit_thread.cc', 'browser/in_process_webkit/webkit_thread.h', 'browser/input_window_dialog.h', + 'browser/input_window_dialog_gtk.cc', + 'browser/input_window_dialog_win.cc', 'browser/intranet_redirect_detector.cc', 'browser/intranet_redirect_detector.h', 'browser/io_thread.cc', @@ -2611,8 +2611,6 @@ 'browser/views/infobars/translate_infobar_base.h', 'browser/views/infobars/translate_message_infobar.cc', 'browser/views/infobars/translate_message_infobar.h', - 'browser/views/input_window_dialog_win.cc', - 'browser/views/input_window_dialog_win.h', 'browser/views/jsmessage_box_dialog.cc', 'browser/views/jsmessage_box_dialog.h', 'browser/views/keyword_editor_view.cc', |