1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/gtk/constrained_window_gtk.h"
7 #include <gdk/gdkkeysyms.h>
9 #include "chrome/browser/ui/gtk/gtk_util.h"
10 #include "ui/base/gtk/gtk_hig_constants.h"
13 gboolean
OnKeyPress(GtkWidget
* sender
, GdkEventKey
* key
, gpointer user_data
) {
14 if (key
->keyval
== GDK_Escape
) {
15 gtk_widget_destroy(sender
);
23 GtkWidget
* CreateWebContentsModalDialogGtk(
25 GtkWidget
* focus_widget
) {
26 // Unlike other users of CreateBorderBin, we need a dedicated frame around
28 GtkWidget
* border
= gtk_event_box_new();
29 GtkWidget
* frame
= gtk_frame_new(NULL
);
30 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_OUT
);
32 GtkWidget
* alignment
= gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
33 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment
),
34 ui::kContentAreaBorder
, ui::kContentAreaBorder
,
35 ui::kContentAreaBorder
, ui::kContentAreaBorder
);
37 if (gtk_widget_get_parent(contents
))
38 gtk_widget_reparent(contents
, alignment
);
40 gtk_container_add(GTK_CONTAINER(alignment
), contents
);
42 gtk_container_add(GTK_CONTAINER(frame
), alignment
);
43 gtk_container_add(GTK_CONTAINER(border
), frame
);
45 gtk_widget_add_events(border
, GDK_KEY_PRESS_MASK
);
46 g_signal_connect(border
,
48 reinterpret_cast<GCallback
>(&OnKeyPress
),
51 // This is a little hacky, but it's better than subclassing GtkWidget just to
52 // add one new property.
53 g_object_set_data(G_OBJECT(border
), "focus_widget", focus_widget
);