Improvements to Linux Disconnect/Continue windows.

* Use GtkDialog instead of GtkWindow - makes the code a lot simpler.
* Improve window layout (add some padding).
* Make ContinueWindow always-on-top, to stop it getting obscured.  Not sure if
this is really necessary.
* Set urgency hint on ContinueWindow - makes it throb in the taskbar.
* Modify Hide() methods to destroy the window, to avoid unnecessary
memory-leaking for tests.
* Hide the window when user clicks buttons, for instant feedback.  Partially
fixes crbug.com/87467 but not completely (the other window stays around if both
were visible).
* Add virtual destructors (coding-style fix).


BUG=87467
TEST=Manual


Review URL: http://codereview.chromium.org/7273077

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91614 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/remoting/host/continue_window_linux.cc b/remoting/host/continue_window_linux.cc
index cc15f6c..92b90af1 100644
--- a/remoting/host/continue_window_linux.cc
+++ b/remoting/host/continue_window_linux.cc
@@ -22,7 +22,7 @@
   virtual void Hide() OVERRIDE;
 
  private:
-  CHROMEG_CALLBACK_0(ContinueWindowLinux, void, OnOkClicked, GtkButton*);
+  CHROMEGTK_CALLBACK_1(ContinueWindowLinux, void, OnResponse, int);
 
   void CreateWindow();
 
@@ -43,54 +43,56 @@
 void ContinueWindowLinux::CreateWindow() {
   if (continue_window_) return;
 
-  continue_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  GtkWindow* window = GTK_WINDOW(continue_window_);
-  gtk_window_set_title(window, kTitle);
-  gtk_window_set_resizable(window, FALSE);
+  continue_window_ = gtk_dialog_new_with_buttons(
+      kTitle,
+      NULL,
+      static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
+      kCancelButtonText, GTK_RESPONSE_CANCEL,
+      kDefaultButtonText, GTK_RESPONSE_OK,
+      NULL);
 
-  g_signal_connect(window, "delete-event",
-                   G_CALLBACK(gtk_widget_hide_on_delete), NULL);
+  gtk_dialog_set_default_response(GTK_DIALOG(continue_window_),
+                                  GTK_RESPONSE_OK);
+  gtk_window_set_resizable(GTK_WINDOW(continue_window_), FALSE);
 
-  GtkWidget* main_area = gtk_vbox_new(FALSE, 0);
-  gtk_container_add(GTK_CONTAINER(continue_window_), main_area);
+  // Set always-on-top, otherwise this window tends to be obscured by the
+  // DisconnectWindow.
+  gtk_window_set_keep_above(GTK_WINDOW(continue_window_), TRUE);
 
-  GtkWidget* text_row = gtk_hbox_new(FALSE, 0);
-  gtk_container_add(GTK_CONTAINER(main_area), text_row);
+  g_signal_connect(continue_window_, "response",
+                   G_CALLBACK(OnResponseThunk), this);
+
+  GtkWidget* content_area = GTK_DIALOG(continue_window_)->vbox;
 
   GtkWidget* text_label = gtk_label_new(kMessage);
   gtk_label_set_line_wrap(GTK_LABEL(text_label), TRUE);
-  gtk_container_add(GTK_CONTAINER(text_row), text_label);
+  // TODO(lambroslambrou): Fix magic numbers, as in disconnect_window_linux.cc.
+  gtk_misc_set_padding(GTK_MISC(text_label), 12, 12);
+  gtk_container_add(GTK_CONTAINER(content_area), text_label);
 
-  GtkWidget* button_box = gtk_hbox_new(FALSE, 0);
-  gtk_container_add(GTK_CONTAINER(main_area), button_box);
-
-  GtkWidget* ok_button =
-      gtk_button_new_with_label(kDefaultButtonText);
-  gtk_box_pack_start(GTK_BOX(button_box), ok_button,
-                     TRUE, FALSE, 0);
-
-  g_signal_connect(ok_button, "clicked",
-                   G_CALLBACK(OnOkClickedThunk), this);
-
-  gtk_widget_show_all(main_area);
+  gtk_widget_show_all(content_area);
 }
 
 void ContinueWindowLinux::Show(remoting::ChromotingHost* host) {
   host_ = host;
   CreateWindow();
+  gtk_window_set_urgency_hint(GTK_WINDOW(continue_window_), TRUE);
   gtk_window_present(GTK_WINDOW(continue_window_));
 }
 
 void ContinueWindowLinux::Hide() {
-  CHECK(continue_window_);
-
-  gtk_widget_hide(continue_window_);
+  if (continue_window_) {
+    gtk_widget_destroy(continue_window_);
+    continue_window_ = NULL;
+  }
 }
 
-void ContinueWindowLinux::OnOkClicked(GtkButton* sender) {
-  CHECK(host_);
-
-  host_->PauseSession(false);
+void ContinueWindowLinux::OnResponse(GtkWidget* dialog, int response_id) {
+  if (response_id == GTK_RESPONSE_OK) {
+    host_->PauseSession(false);
+  } else {
+    host_->Shutdown(NULL);
+  }
   Hide();
 }
 
diff --git a/remoting/host/disconnect_window_linux.cc b/remoting/host/disconnect_window_linux.cc
index 4e9a010..f8a27d3 100644
--- a/remoting/host/disconnect_window_linux.cc
+++ b/remoting/host/disconnect_window_linux.cc
@@ -16,16 +16,14 @@
 class DisconnectWindowLinux : public DisconnectWindow {
  public:
   DisconnectWindowLinux();
+  virtual ~DisconnectWindowLinux();
 
   virtual void Show(ChromotingHost* host,
                     const std::string& username) OVERRIDE;
   virtual void Hide() OVERRIDE;
 
  private:
-  CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, gboolean, OnWindowDelete,
-                       GdkEvent*);
-  CHROMEG_CALLBACK_0(DisconnectWindowLinux, void, OnDisconnectClicked,
-                     GtkButton*);
+  CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, void, OnResponse, int);
 
   void CreateWindow();
 
@@ -41,12 +39,20 @@
       disconnect_window_(NULL) {
 }
 
+DisconnectWindowLinux::~DisconnectWindowLinux() {
+}
+
 void DisconnectWindowLinux::CreateWindow() {
   if (disconnect_window_) return;
 
-  disconnect_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  disconnect_window_ = gtk_dialog_new_with_buttons(
+      kTitle,
+      NULL,
+      GTK_DIALOG_NO_SEPARATOR,
+      kDisconnectButton, GTK_RESPONSE_OK,
+      NULL);
+
   GtkWindow* window = GTK_WINDOW(disconnect_window_);
-  gtk_window_set_title(window, kTitle);
   gtk_window_set_resizable(window, FALSE);
   // Try to keep the window always visible.
   gtk_window_stick(window);
@@ -55,14 +61,17 @@
   gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_UTILITY);
   gtk_window_set_deletable(window, FALSE);
 
-  g_signal_connect(disconnect_window_, "delete-event",
-                   G_CALLBACK(OnWindowDeleteThunk), this);
+  g_signal_connect(disconnect_window_, "response",
+                   G_CALLBACK(OnResponseThunk), this);
 
-  GtkWidget* main_area = gtk_vbox_new(FALSE, 0);
-  gtk_container_add(GTK_CONTAINER(disconnect_window_), main_area);
+  GtkWidget* content_area = GTK_DIALOG(disconnect_window_)->vbox;
 
   GtkWidget* username_row = gtk_hbox_new(FALSE, 0);
-  gtk_container_add(GTK_CONTAINER(main_area), username_row);
+  // TODO(lambroslambrou): Replace the magic number with an appropriate
+  // constant from a header file (such as chrome/browser/ui/gtk/gtk_util.h
+  // but check_deps disallows its #inclusion here).
+  gtk_container_set_border_width(GTK_CONTAINER(username_row), 12);
+  gtk_container_add(GTK_CONTAINER(content_area), username_row);
 
   GtkWidget* share_label = gtk_label_new(kSharingWith);
   gtk_container_add(GTK_CONTAINER(username_row), share_label);
@@ -70,17 +79,7 @@
   user_label_ = gtk_label_new(NULL);
   gtk_container_add(GTK_CONTAINER(username_row), user_label_);
 
-  GtkWidget* disconnect_box = gtk_hbox_new(FALSE, 0);
-  gtk_container_add(GTK_CONTAINER(main_area), disconnect_box);
-
-  GtkWidget* disconnect_button = gtk_button_new_with_label(kDisconnectButton);
-  gtk_box_pack_start(GTK_BOX(disconnect_box), disconnect_button,
-                     TRUE, FALSE, 0);
-
-  g_signal_connect(disconnect_button, "clicked",
-                   G_CALLBACK(OnDisconnectClickedThunk), this);
-
-  gtk_widget_show_all(main_area);
+  gtk_widget_show_all(content_area);
 }
 
 void DisconnectWindowLinux::Show(ChromotingHost* host,
@@ -92,20 +91,20 @@
 }
 
 void DisconnectWindowLinux::Hide() {
-  DCHECK(disconnect_window_);
-
-  gtk_widget_hide(disconnect_window_);
+  if (disconnect_window_) {
+    gtk_widget_destroy(disconnect_window_);
+    disconnect_window_ = NULL;
+  }
 }
 
-gboolean DisconnectWindowLinux::OnWindowDelete(GtkWidget* widget,
-                                               GdkEvent* event) {
-  // Don't allow the window to be closed.
-  return TRUE;
-}
+void DisconnectWindowLinux::OnResponse(GtkWidget* dialog, int response_id) {
+  // |response_id| is ignored, because there is only one button, and pressing
+  // it should have the same effect as closing the window (if the window Close
+  // button were visible).
+  CHECK(host_);
 
-void DisconnectWindowLinux::OnDisconnectClicked(GtkButton* sender) {
-  DCHECK(host_);
   host_->Shutdown(NULL);
+  Hide();
 }
 
 DisconnectWindow* DisconnectWindow::Create() {