summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 20:15:29 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 20:15:29 +0000
commit0d8446f1516e7cbcfcb3654c185a13602f9d82c4 (patch)
tree07b1c82135031d531491ab8ce648dd14d8a38d6e /chrome/browser/gtk
parente5ae96a15b687fffe178eb8c4a7ea79a1ddd679c (diff)
downloadchromium_src-0d8446f1516e7cbcfcb3654c185a13602f9d82c4.zip
chromium_src-0d8446f1516e7cbcfcb3654c185a13602f9d82c4.tar.gz
chromium_src-0d8446f1516e7cbcfcb3654c185a13602f9d82c4.tar.bz2
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
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/constrained_window_gtk.cc37
-rw-r--r--chrome/browser/gtk/constrained_window_gtk.h19
2 files changed, 54 insertions, 2 deletions
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 <gdk/gdkkeysyms.h>
+
+#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<GdkModifierType>(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<TabContentsViewGtk*>(owner_->view());
}
+void ConstrainedWindowGtk::ConnectAccelerators() {
+ gtk_accel_group_connect(accel_group_,
+ GDK_Escape, static_cast<GdkModifierType>(0),
+ static_cast<GtkAccelFlags>(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);
}
+
diff --git a/chrome/browser/gtk/constrained_window_gtk.h b/chrome/browser/gtk/constrained_window_gtk.h
index fdfedf1..0af6e63 100644
--- a/chrome/browser/gtk/constrained_window_gtk.h
+++ b/chrome/browser/gtk/constrained_window_gtk.h
@@ -5,9 +5,10 @@
#ifndef CHROME_BROWSER_GTK_CONSTRAINED_WINDOW_GTK_H_
#define CHROME_BROWSER_GTK_CONSTRAINED_WINDOW_GTK_H_
-#include "chrome/browser/tab_contents/constrained_window.h"
+#include <gtk/gtk.h>
#include "base/basictypes.h"
+#include "chrome/browser/tab_contents/constrained_window.h"
#include "chrome/common/owned_widget_gtk.h"
class TabContents;
@@ -53,6 +54,20 @@ class ConstrainedWindowGtk : public ConstrainedWindow {
ConstrainedWindowGtk(TabContents* owner,
ConstrainedWindowGtkDelegate* delegate);
+ // Connects the ESC accelerator to the window.
+ void ConnectAccelerators();
+
+ // Handles an ESC accelerator being pressed.
+ static gboolean OnEscapeThunk(GtkAccelGroup* accel_group,
+ GObject* acceleratable,
+ guint keyval,
+ GdkModifierType modifier,
+ gpointer user_data) {
+ return reinterpret_cast<ConstrainedWindowGtk*>(user_data)->OnEscape();
+ }
+
+ gboolean OnEscape();
+
// The TabContents that owns and constrains this ConstrainedWindow.
TabContents* owner_;
@@ -65,6 +80,8 @@ class ConstrainedWindowGtk : public ConstrainedWindow {
// Stores if |ShowConstrainedWindow()| has been called.
bool visible_;
+ GtkAccelGroup* accel_group_;
+
DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowGtk);
};