Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / constrained_window_gtk.cc
blob564561b2906f2a23f8524ea9c16c9686bd8907a3
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"
12 namespace {
13 gboolean OnKeyPress(GtkWidget* sender, GdkEventKey* key, gpointer user_data) {
14 if (key->keyval == GDK_Escape) {
15 gtk_widget_destroy(sender);
16 return TRUE;
19 return FALSE;
21 } // namespace
23 GtkWidget* CreateWebContentsModalDialogGtk(
24 GtkWidget* contents,
25 GtkWidget* focus_widget) {
26 // Unlike other users of CreateBorderBin, we need a dedicated frame around
27 // our "window".
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);
39 else
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,
47 "key-press-event",
48 reinterpret_cast<GCallback>(&OnKeyPress),
49 NULL);
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);
55 return border;