Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/gtk/constrained_window_gtk.cc

Issue 6251001: Move chrome/browser/gtk/ to chrome/browser/ui/gtk/... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2009 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.
4
5 #include "chrome/browser/gtk/constrained_window_gtk.h"
6
7 #include <gdk/gdkkeysyms.h>
8
9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/gtk/gtk_util.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12
13 #if defined(TOUCH_UI)
14 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
15 #else
16 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
17 #endif
18
19 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() {
20 }
21
22 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) {
23 return false;
24 }
25
26 ConstrainedWindowGtk::ConstrainedWindowGtk(
27 TabContents* owner, ConstrainedWindowGtkDelegate* delegate)
28 : owner_(owner),
29 delegate_(delegate),
30 visible_(false),
31 factory_(this) {
32 DCHECK(owner);
33 DCHECK(delegate);
34 GtkWidget* dialog = delegate->GetWidgetRoot();
35
36 // Unlike other users of CreateBorderBin, we need a dedicated frame around
37 // our "window".
38 GtkWidget* ebox = gtk_event_box_new();
39 GtkWidget* frame = gtk_frame_new(NULL);
40 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
41
42 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
43 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
44 gtk_util::kContentAreaBorder, gtk_util::kContentAreaBorder,
45 gtk_util::kContentAreaBorder, gtk_util::kContentAreaBorder);
46 GdkColor background;
47 if (delegate->GetBackgroundColor(&background)) {
48 gtk_widget_modify_base(ebox, GTK_STATE_NORMAL, &background);
49 gtk_widget_modify_fg(ebox, GTK_STATE_NORMAL, &background);
50 gtk_widget_modify_bg(ebox, GTK_STATE_NORMAL, &background);
51 }
52
53 if (gtk_widget_get_parent(dialog))
54 gtk_widget_reparent(dialog, alignment);
55 else
56 gtk_container_add(GTK_CONTAINER(alignment), dialog);
57
58 gtk_container_add(GTK_CONTAINER(frame), alignment);
59 gtk_container_add(GTK_CONTAINER(ebox), frame);
60 border_.Own(ebox);
61
62 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK);
63 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk),
64 this);
65 }
66
67 ConstrainedWindowGtk::~ConstrainedWindowGtk() {
68 border_.Destroy();
69 }
70
71 void ConstrainedWindowGtk::ShowConstrainedWindow() {
72 gtk_widget_show_all(border_.get());
73
74 // We collaborate with TabContentsView and stick ourselves in the
75 // TabContentsView's floating container.
76 ContainingView()->AttachConstrainedWindow(this);
77
78 visible_ = true;
79 }
80
81 void ConstrainedWindowGtk::CloseConstrainedWindow() {
82 if (visible_)
83 ContainingView()->RemoveConstrainedWindow(this);
84 delegate_->DeleteDelegate();
85 owner_->WillClose(this);
86
87 delete this;
88 }
89
90 ConstrainedWindowGtk::TabContentsViewType*
91 ConstrainedWindowGtk::ContainingView() {
92 return static_cast<TabContentsViewType*>(owner_->view());
93 }
94
95 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender,
96 GdkEventKey* key) {
97 if (key->keyval == GDK_Escape) {
98 // Let the stack unwind so the event handler can release its ref
99 // on widget().
100 MessageLoop::current()->PostTask(FROM_HERE,
101 factory_.NewRunnableMethod(
102 &ConstrainedWindowGtk::CloseConstrainedWindow));
103 return TRUE;
104 }
105
106 return FALSE;
107 }
108
109 // static
110 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog(
111 TabContents* parent,
112 ConstrainedWindowGtkDelegate* delegate) {
113 return new ConstrainedWindowGtk(parent, delegate);
114 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/constrained_window_gtk.h ('k') | chrome/browser/gtk/content_setting_bubble_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698