summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 19:17:55 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 19:17:55 +0000
commit75b841290867be611cb33719fbe267b0b2f9b362 (patch)
tree054ba514f71c6b7a0c44c8d8573bb8cf4c22bb6e
parent20c116aafb9841c035115685d2fe7c876b2521ae (diff)
downloadchromium_src-75b841290867be611cb33719fbe267b0b2f9b362.zip
chromium_src-75b841290867be611cb33719fbe267b0b2f9b362.tar.gz
chromium_src-75b841290867be611cb33719fbe267b0b2f9b362.tar.bz2
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 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52721 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/input_window_dialog_gtk.cc (renamed from chrome/browser/input_window_dialog_gtk.cc)98
-rw-r--r--chrome/browser/gtk/input_window_dialog_gtk.h49
-rw-r--r--chrome/browser/views/input_window_dialog_win.cc (renamed from chrome/browser/input_window_dialog_win.cc)151
-rw-r--r--chrome/browser/views/input_window_dialog_win.h105
-rw-r--r--chrome/chrome_browser.gypi6
5 files changed, 207 insertions, 202 deletions
diff --git a/chrome/browser/input_window_dialog_gtk.cc b/chrome/browser/gtk/input_window_dialog_gtk.cc
index 3e61894..2a7e2d0 100644
--- a/chrome/browser/input_window_dialog_gtk.cc
+++ b/chrome/browser/gtk/input_window_dialog_gtk.cc
@@ -1,55 +1,15 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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/input_window_dialog.h"
-
-#include <gtk/gtk.h>
+#include "chrome/browser/gtk/input_window_dialog_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"
-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,
+InputWindowDialogGtk::InputWindowDialogGtk(GtkWindow* parent,
const std::string& window_title,
const std::string& label,
const std::string& contents,
@@ -75,7 +35,7 @@ GtkInputWindowDialog::GtkInputWindowDialog(GtkWindow* parent,
input_ = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(input_), contents.c_str());
g_signal_connect(input_, "changed",
- G_CALLBACK(OnEntryChanged), this);
+ G_CALLBACK(OnEntryChangedThunk), this);
g_object_set(G_OBJECT(input_), "activates-default", TRUE, NULL);
gtk_box_pack_start(GTK_BOX(hbox), input_, TRUE, TRUE, 0);
@@ -84,21 +44,21 @@ GtkInputWindowDialog::GtkInputWindowDialog(GtkWindow* parent,
gtk_box_pack_start(GTK_BOX(content_area), hbox, FALSE, FALSE, 0);
g_signal_connect(dialog_, "response",
- G_CALLBACK(OnResponse), this);
+ G_CALLBACK(OnResponseThunk), this);
g_signal_connect(dialog_, "delete-event",
- G_CALLBACK(OnWindowDeleteEvent), this);
+ G_CALLBACK(OnWindowDeleteEventThunk), this);
g_signal_connect(dialog_, "destroy",
- G_CALLBACK(OnWindowDestroy), this);
+ G_CALLBACK(OnWindowDestroyThunk), this);
}
-GtkInputWindowDialog::~GtkInputWindowDialog() {
+InputWindowDialogGtk::~InputWindowDialogGtk() {
}
-void GtkInputWindowDialog::Show() {
+void InputWindowDialogGtk::Show() {
gtk_util::ShowDialog(dialog_);
}
-void GtkInputWindowDialog::Close() {
+void InputWindowDialogGtk::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_) {
@@ -107,35 +67,27 @@ void GtkInputWindowDialog::Close() {
}
}
-// static
-void GtkInputWindowDialog::OnEntryChanged(GtkEditable* entry,
- GtkInputWindowDialog* window) {
+void InputWindowDialogGtk::OnEntryChanged(GtkEditable* entry) {
std::wstring value(UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(entry))));
- gtk_dialog_set_response_sensitive(GTK_DIALOG(window->dialog_),
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_),
GTK_RESPONSE_ACCEPT,
- window->delegate_->IsValid(value));
+ delegate_->IsValid(value));
}
-// static
-void GtkInputWindowDialog::OnResponse(GtkDialog* dialog, int response_id,
- GtkInputWindowDialog* window) {
+void InputWindowDialogGtk::OnResponse(GtkWidget* dialog, int response_id) {
if (response_id == GTK_RESPONSE_ACCEPT) {
- std::wstring value(UTF8ToWide(gtk_entry_get_text(
- GTK_ENTRY(window->input_))));
- window->delegate_->InputAccepted(value);
+ std::wstring value(UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(input_))));
+ delegate_->InputAccepted(value);
} else {
- window->delegate_->InputCanceled();
+ delegate_->InputCanceled();
}
- window->Close();
+ Close();
}
-// static
-gboolean GtkInputWindowDialog::OnWindowDeleteEvent(
- GtkWidget* widget,
- GdkEvent* event,
- GtkInputWindowDialog* dialog) {
- dialog->Close();
+gboolean InputWindowDialogGtk::OnWindowDeleteEvent(GtkWidget* widget,
+ GdkEvent* event) {
+ 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
@@ -143,10 +95,8 @@ gboolean GtkInputWindowDialog::OnWindowDeleteEvent(
return TRUE;
}
-// static
-void GtkInputWindowDialog::OnWindowDestroy(GtkWidget* widget,
- GtkInputWindowDialog* dialog) {
- MessageLoop::current()->DeleteSoon(FROM_HERE, dialog);
+void InputWindowDialogGtk::OnWindowDestroy(GtkWidget* widget) {
+ MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
// static
@@ -155,7 +105,7 @@ InputWindowDialog* InputWindowDialog::Create(gfx::NativeWindow parent,
const std::wstring& label,
const std::wstring& contents,
Delegate* delegate) {
- return new GtkInputWindowDialog(parent,
+ return new InputWindowDialogGtk(parent,
WideToUTF8(window_title),
WideToUTF8(label),
WideToUTF8(contents),
diff --git a/chrome/browser/gtk/input_window_dialog_gtk.h b/chrome/browser/gtk/input_window_dialog_gtk.h
new file mode 100644
index 0000000..7f7b736c
--- /dev/null
+++ b/chrome/browser/gtk/input_window_dialog_gtk.h
@@ -0,0 +1,49 @@
+// 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/input_window_dialog_win.cc b/chrome/browser/views/input_window_dialog_win.cc
index 2d606df..21cf5e5 100644
--- a/chrome/browser/input_window_dialog_win.cc
+++ b/chrome/browser/views/input_window_dialog_win.cc
@@ -1,112 +1,43 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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/input_window_dialog.h"
+#include "chrome/browser/views/input_window_dialog_win.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;
-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_);
- }
-
- // 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;
- }
-
- 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_;
+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();
+}
- // The delegate that the ContentView uses to communicate changes to the
- // caller.
- WinInputWindowDialog* delegate_;
+InputWindowDialogWin::~InputWindowDialogWin() {
+}
- // Helps us set focus to the first Textfield in the window.
- ScopedRunnableMethodFactory<ContentView> focus_grabber_factory_;
+void InputWindowDialogWin::Show() {
+ window_->Show();
+}
- DISALLOW_COPY_AND_ASSIGN(ContentView);
-};
+void InputWindowDialogWin::Close() {
+ window_->Close();
+}
///////////////////////////////////////////////////////////////////////////////
// ContentView, views::DialogDelegate implementation:
@@ -130,18 +61,10 @@ 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:
@@ -197,40 +120,16 @@ 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 WinInputWindowDialog(parent,
+ return new InputWindowDialogWin(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
new file mode 100644
index 0000000..beb70f5
--- /dev/null
+++ b/chrome/browser/views/input_window_dialog_win.h
@@ -0,0 +1,105 @@
+// 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 7da139b..366ae95 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1529,6 +1529,8 @@
'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',
@@ -1777,8 +1779,6 @@
'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,6 +2611,8 @@
'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',