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
[email protected]
Review URL: http://codereview.chromium.org/2835043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52727 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/gtk/input_window_dialog_gtk.cc b/chrome/browser/gtk/input_window_dialog_gtk.cc
deleted file mode 100644
index 2a7e2d07..0000000
--- a/chrome/browser/gtk/input_window_dialog_gtk.cc
+++ /dev/null
@@ -1,113 +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.
-
-#include "chrome/browser/gtk/input_window_dialog_gtk.h"
-
-#include "base/message_loop.h"
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/gtk/gtk_util.h"
-
-InputWindowDialogGtk::InputWindowDialogGtk(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,
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
- GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
- NULL)),
- delegate_(delegate) {
- gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT);
- gtk_dialog_set_has_separator(GTK_DIALOG(dialog_), FALSE);
-
- GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox;
- gtk_box_set_spacing(GTK_BOX(content_area), 18);
-
- GtkWidget* hbox = gtk_hbox_new(FALSE, 6);
- 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(input_, "changed",
- 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);
-
- gtk_widget_show_all(hbox);
-
- gtk_box_pack_start(GTK_BOX(content_area), hbox, FALSE, FALSE, 0);
-
- g_signal_connect(dialog_, "response",
- G_CALLBACK(OnResponseThunk), this);
- g_signal_connect(dialog_, "delete-event",
- G_CALLBACK(OnWindowDeleteEventThunk), this);
- g_signal_connect(dialog_, "destroy",
- G_CALLBACK(OnWindowDestroyThunk), this);
-}
-
-InputWindowDialogGtk::~InputWindowDialogGtk() {
-}
-
-void InputWindowDialogGtk::Show() {
- gtk_util::ShowDialog(dialog_);
-}
-
-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_) {
- gtk_widget_destroy(GTK_WIDGET(dialog_));
- dialog_ = NULL;
- }
-}
-
-void InputWindowDialogGtk::OnEntryChanged(GtkEditable* entry) {
- std::wstring value(UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(entry))));
- gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_),
- GTK_RESPONSE_ACCEPT,
- delegate_->IsValid(value));
-}
-
-void InputWindowDialogGtk::OnResponse(GtkWidget* dialog, int response_id) {
- if (response_id == GTK_RESPONSE_ACCEPT) {
- std::wstring value(UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(input_))));
- delegate_->InputAccepted(value);
- } else {
- delegate_->InputCanceled();
- }
-
- 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
- // force the destruction without us being able to stop it.
- return TRUE;
-}
-
-void InputWindowDialogGtk::OnWindowDestroy(GtkWidget* widget) {
- MessageLoop::current()->DeleteSoon(FROM_HERE, this);
-}
-
-// static
-InputWindowDialog* InputWindowDialog::Create(gfx::NativeWindow parent,
- const std::wstring& window_title,
- const std::wstring& label,
- const std::wstring& contents,
- Delegate* delegate) {
- return new InputWindowDialogGtk(parent,
- WideToUTF8(window_title),
- WideToUTF8(label),
- WideToUTF8(contents),
- delegate);
-}
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/input_window_dialog_gtk.cc b/chrome/browser/input_window_dialog_gtk.cc
new file mode 100644
index 0000000..3e61894
--- /dev/null
+++ b/chrome/browser/input_window_dialog_gtk.cc
@@ -0,0 +1,163 @@
+// 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_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,
+ 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,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ NULL)),
+ delegate_(delegate) {
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_has_separator(GTK_DIALOG(dialog_), FALSE);
+
+ GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox;
+ gtk_box_set_spacing(GTK_BOX(content_area), 18);
+
+ GtkWidget* hbox = gtk_hbox_new(FALSE, 6);
+ 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(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_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_util::ShowDialog(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_dialog_set_response_sensitive(GTK_DIALOG(window->dialog_),
+ GTK_RESPONSE_ACCEPT,
+ 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/input_window_dialog_win.cc b/chrome/browser/input_window_dialog_win.cc
new file mode 100644
index 0000000..2d606df
--- /dev/null
+++ b/chrome/browser/input_window_dialog_win.cc
@@ -0,0 +1,236 @@
+// 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 "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_;
+
+ // 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:
+
+bool ContentView::IsDialogButtonEnabled(
+ MessageBoxFlags::DialogButton button) const {
+ if (button == MessageBoxFlags::DIALOGBUTTON_OK &&
+ !delegate_->delegate()->IsValid(text_field_->text())) {
+ return false;
+ }
+ return true;
+}
+
+bool ContentView::Accept() {
+ delegate_->delegate()->InputAccepted(text_field_->text());
+ return true;
+}
+
+bool ContentView::Cancel() {
+ delegate_->delegate()->InputCanceled();
+ 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:
+
+void ContentView::ContentsChanged(views::Textfield* sender,
+ const std::wstring& new_contents) {
+ GetDialogClientView()->UpdateDialogButtons();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// ContentView, protected:
+
+void ContentView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (is_add && child == this)
+ InitControlLayout();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// ContentView, private:
+
+void ContentView::InitControlLayout() {
+ text_field_ = new views::Textfield;
+ text_field_->SetText(delegate_->contents());
+ text_field_->SetController(this);
+
+ using views::ColumnSet;
+ using views::GridLayout;
+
+ // TODO(sky): Vertical alignment should be baseline.
+ GridLayout* layout = CreatePanelGridLayout(this);
+ SetLayoutManager(layout);
+
+ ColumnSet* c1 = layout->AddColumnSet(0);
+ c1->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
+ GridLayout::USE_PREF, 0, 0);
+ c1->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
+ c1->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
+ GridLayout::USE_PREF, kTextfieldWidth, kTextfieldWidth);
+
+ layout->StartRow(0, 0);
+ views::Label* label = new views::Label(delegate_->label());
+ layout->AddView(label);
+ layout->AddView(text_field_);
+
+ MessageLoop::current()->PostTask(FROM_HERE,
+ focus_grabber_factory_.NewRunnableMethod(
+ &ContentView::FocusFirstFocusableControl));
+}
+
+void ContentView::FocusFirstFocusableControl() {
+ text_field_->SelectAll();
+ 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,
+ window_title,
+ label,
+ contents,
+ delegate);
+}
diff --git a/chrome/browser/views/input_window_dialog_win.cc b/chrome/browser/views/input_window_dialog_win.cc
deleted file mode 100644
index 21cf5e5..0000000
--- a/chrome/browser/views/input_window_dialog_win.cc
+++ /dev/null
@@ -1,135 +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.
-
-#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 "views/grid_layout.h"
-#include "views/standard_layout.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();
-}
-
-InputWindowDialogWin::~InputWindowDialogWin() {
-}
-
-void InputWindowDialogWin::Show() {
- window_->Show();
-}
-
-void InputWindowDialogWin::Close() {
- window_->Close();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ContentView, views::DialogDelegate implementation:
-
-bool ContentView::IsDialogButtonEnabled(
- MessageBoxFlags::DialogButton button) const {
- if (button == MessageBoxFlags::DIALOGBUTTON_OK &&
- !delegate_->delegate()->IsValid(text_field_->text())) {
- return false;
- }
- return true;
-}
-
-bool ContentView::Accept() {
- delegate_->delegate()->InputAccepted(text_field_->text());
- return true;
-}
-
-bool ContentView::Cancel() {
- delegate_->delegate()->InputCanceled();
- return true;
-}
-
-std::wstring ContentView::GetWindowTitle() const {
- return delegate_->window_title();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ContentView, views::Textfield::Controller implementation:
-
-void ContentView::ContentsChanged(views::Textfield* sender,
- const std::wstring& new_contents) {
- GetDialogClientView()->UpdateDialogButtons();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ContentView, protected:
-
-void ContentView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (is_add && child == this)
- InitControlLayout();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// ContentView, private:
-
-void ContentView::InitControlLayout() {
- text_field_ = new views::Textfield;
- text_field_->SetText(delegate_->contents());
- text_field_->SetController(this);
-
- using views::ColumnSet;
- using views::GridLayout;
-
- // TODO(sky): Vertical alignment should be baseline.
- GridLayout* layout = CreatePanelGridLayout(this);
- SetLayoutManager(layout);
-
- ColumnSet* c1 = layout->AddColumnSet(0);
- c1->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
- GridLayout::USE_PREF, 0, 0);
- c1->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
- c1->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
- GridLayout::USE_PREF, kTextfieldWidth, kTextfieldWidth);
-
- layout->StartRow(0, 0);
- views::Label* label = new views::Label(delegate_->label());
- layout->AddView(label);
- layout->AddView(text_field_);
-
- MessageLoop::current()->PostTask(FROM_HERE,
- focus_grabber_factory_.NewRunnableMethod(
- &ContentView::FocusFirstFocusableControl));
-}
-
-void ContentView::FocusFirstFocusableControl() {
- text_field_->SelectAll();
- text_field_->RequestFocus();
-}
-
-// 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,
- 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 beb70f5f..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 366ae953..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',