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

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

Issue 11111022: Remove TabContents from constrained windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unrelated gtk code Created 8 years, 2 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" 5 #include "chrome/browser/ui/gtk/constrained_window_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/constrained_window_tab_helper.h" 12 #include "chrome/browser/ui/constrained_window_tab_helper.h"
13 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" 13 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h"
14 #include "chrome/browser/ui/gtk/gtk_util.h" 14 #include "chrome/browser/ui/gtk/gtk_util.h"
15 #include "chrome/browser/ui/gtk/tab_contents/chrome_web_contents_view_delegate_g tk.h" 15 #include "chrome/browser/ui/gtk/tab_contents/chrome_web_contents_view_delegate_g tk.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents.h"
17 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
19 #include "ui/base/gtk/focus_store_gtk.h" 18 #include "ui/base/gtk/focus_store_gtk.h"
20 #include "ui/base/gtk/gtk_compat.h" 19 #include "ui/base/gtk/gtk_compat.h"
21 #include "ui/base/gtk/gtk_hig_constants.h" 20 #include "ui/base/gtk/gtk_hig_constants.h"
22 21
23 using content::BrowserThread; 22 using content::BrowserThread;
24 23
25 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() { 24 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() {
26 } 25 }
27 26
28 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) { 27 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) {
29 return false; 28 return false;
30 } 29 }
31 30
32 bool ConstrainedWindowGtkDelegate::ShouldHaveBorderPadding() const { 31 bool ConstrainedWindowGtkDelegate::ShouldHaveBorderPadding() const {
33 return true; 32 return true;
34 } 33 }
35 34
36 ConstrainedWindowGtk::ConstrainedWindowGtk( 35 ConstrainedWindowGtk::ConstrainedWindowGtk(
37 TabContents* tab_contents, 36 content::WebContents* web_contents,
38 ConstrainedWindowGtkDelegate* delegate) 37 ConstrainedWindowGtkDelegate* delegate)
39 : tab_contents_(tab_contents), 38 : web_contents_(web_contents),
40 delegate_(delegate), 39 delegate_(delegate),
41 visible_(false), 40 visible_(false),
42 weak_factory_(this) { 41 weak_factory_(this) {
43 DCHECK(tab_contents); 42 DCHECK(web_contents);
44 DCHECK(delegate); 43 DCHECK(delegate);
45 GtkWidget* dialog = delegate->GetWidgetRoot(); 44 GtkWidget* dialog = delegate->GetWidgetRoot();
45 ConstrainedWindowTabHelper::CreateForWebContents(web_contents);
46 46
47 // Unlike other users of CreateBorderBin, we need a dedicated frame around 47 // Unlike other users of CreateBorderBin, we need a dedicated frame around
48 // our "window". 48 // our "window".
49 GtkWidget* ebox = gtk_event_box_new(); 49 GtkWidget* ebox = gtk_event_box_new();
50 GtkWidget* frame = gtk_frame_new(NULL); 50 GtkWidget* frame = gtk_frame_new(NULL);
51 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); 51 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
52 52
53 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 53 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
54 if (delegate->ShouldHaveBorderPadding()) { 54 if (delegate->ShouldHaveBorderPadding()) {
55 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 55 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
(...skipping 17 matching lines...) Expand all
73 gtk_container_add(GTK_CONTAINER(ebox), frame); 73 gtk_container_add(GTK_CONTAINER(ebox), frame);
74 border_.Own(ebox); 74 border_.Own(ebox);
75 75
76 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK); 76 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK);
77 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk), 77 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk),
78 this); 78 this);
79 g_signal_connect(widget(), "hierarchy-changed", 79 g_signal_connect(widget(), "hierarchy-changed",
80 G_CALLBACK(OnHierarchyChangedThunk), this); 80 G_CALLBACK(OnHierarchyChangedThunk), this);
81 81
82 ConstrainedWindowTabHelper* constrained_window_tab_helper = 82 ConstrainedWindowTabHelper* constrained_window_tab_helper =
83 ConstrainedWindowTabHelper::FromWebContents( 83 ConstrainedWindowTabHelper::FromWebContents(web_contents_);
84 tab_contents_->web_contents());
85 constrained_window_tab_helper->AddConstrainedDialog(this); 84 constrained_window_tab_helper->AddConstrainedDialog(this);
86 } 85 }
87 86
88 ConstrainedWindowGtk::~ConstrainedWindowGtk() { 87 ConstrainedWindowGtk::~ConstrainedWindowGtk() {
89 border_.Destroy(); 88 border_.Destroy();
90 } 89 }
91 90
92 void ConstrainedWindowGtk::ShowConstrainedWindow() { 91 void ConstrainedWindowGtk::ShowConstrainedWindow() {
93 gtk_widget_show_all(border_.get()); 92 gtk_widget_show_all(border_.get());
94 93
95 // We collaborate with WebContentsView and stick ourselves in the 94 // We collaborate with WebContentsView and stick ourselves in the
96 // WebContentsView's floating container. 95 // WebContentsView's floating container.
97 ContainingView()->AttachConstrainedWindow(this); 96 ContainingView()->AttachConstrainedWindow(this);
98 97
99 visible_ = true; 98 visible_ = true;
100 } 99 }
101 100
102 void ConstrainedWindowGtk::CloseConstrainedWindow() { 101 void ConstrainedWindowGtk::CloseConstrainedWindow() {
103 if (visible_) 102 if (visible_)
104 ContainingView()->RemoveConstrainedWindow(this); 103 ContainingView()->RemoveConstrainedWindow(this);
105 delegate_->DeleteDelegate(); 104 delegate_->DeleteDelegate();
106 ConstrainedWindowTabHelper* constrained_window_tab_helper = 105 ConstrainedWindowTabHelper* constrained_window_tab_helper =
107 ConstrainedWindowTabHelper::FromWebContents( 106 ConstrainedWindowTabHelper::FromWebContents(web_contents_);
108 tab_contents_->web_contents());
109 constrained_window_tab_helper->WillClose(this); 107 constrained_window_tab_helper->WillClose(this);
110 108
111 delete this; 109 delete this;
112 } 110 }
113 111
114 void ConstrainedWindowGtk::FocusConstrainedWindow() { 112 void ConstrainedWindowGtk::FocusConstrainedWindow() {
115 GtkWidget* focus_widget = delegate_->GetFocusWidget(); 113 GtkWidget* focus_widget = delegate_->GetFocusWidget();
116 if (!focus_widget) 114 if (!focus_widget)
117 return; 115 return;
118 116
119 // The user may have focused another tab. In this case do not grab focus 117 // The user may have focused another tab. In this case do not grab focus
120 // until this tab is refocused. 118 // until this tab is refocused.
121 ConstrainedWindowTabHelper* helper = 119 ConstrainedWindowTabHelper* helper =
122 ConstrainedWindowTabHelper::FromWebContents( 120 ConstrainedWindowTabHelper::FromWebContents(web_contents_);
123 tab_contents_->web_contents());
124 if ((!helper->delegate() || 121 if ((!helper->delegate() ||
125 helper->delegate()->ShouldFocusConstrainedWindow()) && 122 helper->delegate()->ShouldFocusConstrainedWindow()) &&
126 gtk_util::IsWidgetAncestryVisible(focus_widget)) { 123 gtk_util::IsWidgetAncestryVisible(focus_widget)) {
127 gtk_widget_grab_focus(focus_widget); 124 gtk_widget_grab_focus(focus_widget);
128 } else { 125 } else {
129 ContainingView()->focus_store()->SetWidget(focus_widget); 126 ContainingView()->focus_store()->SetWidget(focus_widget);
130 } 127 }
131 } 128 }
132 129
133 ConstrainedWindowGtk::TabContentsViewType* 130 ConstrainedWindowGtk::TabContentsViewType*
134 ConstrainedWindowGtk::ContainingView() { 131 ConstrainedWindowGtk::ContainingView() {
135 return 132 return ChromeWebContentsViewDelegateGtk::GetFor(web_contents_);
136 ChromeWebContentsViewDelegateGtk::GetFor(tab_contents_->web_contents());
137 } 133 }
138 134
139 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender, 135 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender,
140 GdkEventKey* key) { 136 GdkEventKey* key) {
141 if (key->keyval == GDK_Escape) { 137 if (key->keyval == GDK_Escape) {
142 // Let the stack unwind so the event handler can release its ref 138 // Let the stack unwind so the event handler can release its ref
143 // on widget(). 139 // on widget().
144 MessageLoop::current()->PostTask( 140 MessageLoop::current()->PostTask(
145 FROM_HERE, 141 FROM_HERE,
146 base::Bind(&ConstrainedWindowGtk::CloseConstrainedWindow, 142 base::Bind(&ConstrainedWindowGtk::CloseConstrainedWindow,
147 weak_factory_.GetWeakPtr())); 143 weak_factory_.GetWeakPtr()));
148 return TRUE; 144 return TRUE;
149 } 145 }
150 146
151 return FALSE; 147 return FALSE;
152 } 148 }
153 149
154 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender, 150 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender,
155 GtkWidget* previous_toplevel) { 151 GtkWidget* previous_toplevel) {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
157 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(widget()))) 153 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(widget())))
158 return; 154 return;
159 155
160 FocusConstrainedWindow(); 156 FocusConstrainedWindow();
161 } 157 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/constrained_window_gtk.h ('k') | chrome/browser/ui/gtk/extensions/media_galleries_dialog_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698