From 0d8446f1516e7cbcfcb3654c185a13602f9d82c4 Mon Sep 17 00:00:00 2001 From: "zelidrag@chromium.org" Date: Wed, 14 Apr 2010 20:15:29 +0000 Subject: Fixed ESC handling on constrained dialogs on GTK. We used to stop the entire page navigation previously instead of continuing with other page elements if some can't be loaded. This change makes GTK implementation consistent with other platforms. BUG=27585 TEST=go to http://www/~thakis/cgi-bin/test.html, press ESC when login dialog appears, observe broken image #1, press ESC on the next dialog, observe broken image #2. Review URL: http://codereview.chromium.org/1627022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44527 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/gtk/constrained_window_gtk.cc | 37 +++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'chrome/browser/gtk/constrained_window_gtk.cc') diff --git a/chrome/browser/gtk/constrained_window_gtk.cc b/chrome/browser/gtk/constrained_window_gtk.cc index cd562b1..0b72fe6 100644 --- a/chrome/browser/gtk/constrained_window_gtk.cc +++ b/chrome/browser/gtk/constrained_window_gtk.cc @@ -4,6 +4,9 @@ #include "chrome/browser/gtk/constrained_window_gtk.h" +#include + +#include "chrome/browser/browser_list.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" @@ -12,7 +15,8 @@ ConstrainedWindowGtk::ConstrainedWindowGtk( TabContents* owner, ConstrainedWindowGtkDelegate* delegate) : owner_(owner), delegate_(delegate), - visible_(false) { + visible_(false), + accel_group_(gtk_accel_group_new()) { DCHECK(owner); DCHECK(delegate); GtkWidget* dialog = delegate->GetWidgetRoot(); @@ -30,10 +34,18 @@ ConstrainedWindowGtk::ConstrainedWindowGtk( gtk_container_add(GTK_CONTAINER(frame), alignment); gtk_container_add(GTK_CONTAINER(ebox), frame); border_.Own(ebox); + ConnectAccelerators(); } ConstrainedWindowGtk::~ConstrainedWindowGtk() { border_.Destroy(); + + gtk_accel_group_disconnect_key(accel_group_, GDK_Escape, + static_cast(0)); + gtk_window_remove_accel_group( + GTK_WINDOW(ContainingView()->GetTopLevelNativeWindow()), + accel_group_); + g_object_unref(accel_group_); } void ConstrainedWindowGtk::ShowConstrainedWindow() { @@ -59,9 +71,32 @@ TabContentsViewGtk* ConstrainedWindowGtk::ContainingView() { return static_cast(owner_->view()); } +void ConstrainedWindowGtk::ConnectAccelerators() { + gtk_accel_group_connect(accel_group_, + GDK_Escape, static_cast(0), + static_cast(0), + g_cclosure_new(G_CALLBACK(OnEscapeThunk), + this, NULL)); + gtk_window_add_accel_group( + GTK_WINDOW(ContainingView()->GetTopLevelNativeWindow()), + accel_group_); +} + + +gboolean ConstrainedWindowGtk::OnEscape() { + // Handle this accelerator only if this is on the currently selected tab. + Browser* browser = BrowserList::GetLastActive(); + if (!browser || browser->GetSelectedTabContents() != owner_) + return FALSE; + + CloseConstrainedWindow(); + return TRUE; +} + // static ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( TabContents* parent, ConstrainedWindowGtkDelegate* delegate) { return new ConstrainedWindowGtk(parent, delegate); } + -- cgit v1.1