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

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

Issue 7880003: content: Move constrained window code from TabContents to TabContentsWrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac regression now that shutdown timing was changed for views. Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/constrained_window_tab_helper.h"
10 #include "chrome/browser/ui/gtk/gtk_util.h" 11 #include "chrome/browser/ui/gtk/gtk_util.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
12 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
13 #include "ui/base/gtk/gtk_hig_constants.h" 15 #include "ui/base/gtk/gtk_hig_constants.h"
14 16
15 #if defined(TOUCH_UI) 17 #if defined(TOUCH_UI)
16 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" 18 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
17 #elif defined(TOOLKIT_VIEWS) 19 #elif defined(TOOLKIT_VIEWS)
18 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h" 20 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h"
19 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" 21 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
20 #else 22 #else
21 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" 23 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
22 #endif 24 #endif
23 25
24 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() { 26 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() {
25 } 27 }
26 28
27 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) { 29 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) {
28 return false; 30 return false;
29 } 31 }
30 32
31 bool ConstrainedWindowGtkDelegate::ShouldHaveBorderPadding() const { 33 bool ConstrainedWindowGtkDelegate::ShouldHaveBorderPadding() const {
32 return true; 34 return true;
33 } 35 }
34 36
35 ConstrainedWindowGtk::ConstrainedWindowGtk( 37 ConstrainedWindowGtk::ConstrainedWindowGtk(
36 TabContents* owner, ConstrainedWindowGtkDelegate* delegate) 38 TabContentsWrapper* wrapper, ConstrainedWindowGtkDelegate* delegate)
37 : owner_(owner), 39 : wrapper_(wrapper),
38 delegate_(delegate), 40 delegate_(delegate),
39 visible_(false), 41 visible_(false),
40 factory_(this) { 42 factory_(this) {
41 DCHECK(owner); 43 DCHECK(wrapper);
42 DCHECK(delegate); 44 DCHECK(delegate);
43 GtkWidget* dialog = delegate->GetWidgetRoot(); 45 GtkWidget* dialog = delegate->GetWidgetRoot();
44 46
45 // Unlike other users of CreateBorderBin, we need a dedicated frame around 47 // Unlike other users of CreateBorderBin, we need a dedicated frame around
46 // our "window". 48 // our "window".
47 GtkWidget* ebox = gtk_event_box_new(); 49 GtkWidget* ebox = gtk_event_box_new();
48 GtkWidget* frame = gtk_frame_new(NULL); 50 GtkWidget* frame = gtk_frame_new(NULL);
49 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); 51 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
50 52
51 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);
(...skipping 18 matching lines...) Expand all
70 gtk_container_add(GTK_CONTAINER(frame), alignment); 72 gtk_container_add(GTK_CONTAINER(frame), alignment);
71 gtk_container_add(GTK_CONTAINER(ebox), frame); 73 gtk_container_add(GTK_CONTAINER(ebox), frame);
72 border_.Own(ebox); 74 border_.Own(ebox);
73 75
74 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK); 76 gtk_widget_add_events(widget(), GDK_KEY_PRESS_MASK);
75 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk), 77 g_signal_connect(widget(), "key-press-event", G_CALLBACK(OnKeyPressThunk),
76 this); 78 this);
77 g_signal_connect(widget(), "hierarchy-changed", 79 g_signal_connect(widget(), "hierarchy-changed",
78 G_CALLBACK(OnHierarchyChangedThunk), this); 80 G_CALLBACK(OnHierarchyChangedThunk), this);
79 81
80 owner->AddConstrainedDialog(this); 82 wrapper_->constrained_window_tab_helper()->AddConstrainedDialog(this);
81 } 83 }
82 84
83 ConstrainedWindowGtk::~ConstrainedWindowGtk() { 85 ConstrainedWindowGtk::~ConstrainedWindowGtk() {
84 border_.Destroy(); 86 border_.Destroy();
85 } 87 }
86 88
87 void ConstrainedWindowGtk::ShowConstrainedWindow() { 89 void ConstrainedWindowGtk::ShowConstrainedWindow() {
88 gtk_widget_show_all(border_.get()); 90 gtk_widget_show_all(border_.get());
89 91
90 // We collaborate with TabContentsView and stick ourselves in the 92 // We collaborate with TabContentsView and stick ourselves in the
91 // TabContentsView's floating container. 93 // TabContentsView's floating container.
92 ContainingView()->AttachConstrainedWindow(this); 94 ContainingView()->AttachConstrainedWindow(this);
93 95
94 visible_ = true; 96 visible_ = true;
95 } 97 }
96 98
97 void ConstrainedWindowGtk::CloseConstrainedWindow() { 99 void ConstrainedWindowGtk::CloseConstrainedWindow() {
98 if (visible_) 100 if (visible_)
99 ContainingView()->RemoveConstrainedWindow(this); 101 ContainingView()->RemoveConstrainedWindow(this);
100 delegate_->DeleteDelegate(); 102 delegate_->DeleteDelegate();
101 owner_->WillClose(this); 103 wrapper_->constrained_window_tab_helper()->WillClose(this);
102 104
103 delete this; 105 delete this;
104 } 106 }
105 107
106 void ConstrainedWindowGtk::FocusConstrainedWindow() { 108 void ConstrainedWindowGtk::FocusConstrainedWindow() {
107 GtkWidget* focus_widget = delegate_->GetFocusWidget(); 109 GtkWidget* focus_widget = delegate_->GetFocusWidget();
108 if (!focus_widget) 110 if (!focus_widget)
109 return; 111 return;
110 112
111 // The user may have focused another tab. In this case do not grab focus 113 // The user may have focused another tab. In this case do not grab focus
112 // until this tab is refocused. 114 // until this tab is refocused.
113 if ((!owner_->delegate() || 115 if ((!wrapper_->delegate() ||
114 owner_->delegate()->ShouldFocusConstrainedWindow()) && 116 wrapper_->delegate()->ShouldFocusConstrainedWindow()) &&
115 gtk_util::IsWidgetAncestryVisible(focus_widget)) { 117 gtk_util::IsWidgetAncestryVisible(focus_widget)) {
116 gtk_widget_grab_focus(focus_widget); 118 gtk_widget_grab_focus(focus_widget);
117 } else { 119 } else {
118 // TODO(estade): this define should not need to be here because this class 120 // TODO(estade): this define should not need to be here because this class
119 // should not be used on linux/views. 121 // should not be used on linux/views.
120 #if defined(TOOLKIT_GTK) 122 #if defined(TOOLKIT_GTK)
121 static_cast<TabContentsViewGtk*>(owner_->view())-> 123 static_cast<TabContentsViewGtk*>(wrapper_->view())->
122 SetFocusedWidget(focus_widget); 124 SetFocusedWidget(focus_widget);
123 #endif 125 #endif
124 } 126 }
125 } 127 }
126 128
127 ConstrainedWindowGtk::TabContentsViewType* 129 ConstrainedWindowGtk::TabContentsViewType*
128 ConstrainedWindowGtk::ContainingView() { 130 ConstrainedWindowGtk::ContainingView() {
129 #if defined(TOOLKIT_VIEWS) && !defined(TOUCH_UI) 131 #if defined(TOOLKIT_VIEWS) && !defined(TOUCH_UI)
130 return static_cast<NativeTabContentsViewGtk*>( 132 return static_cast<NativeTabContentsViewGtk*>(
131 static_cast<TabContentsViewViews*>(owner_->view())-> 133 static_cast<TabContentsViewViews*>(wrapper_->view())->
132 native_tab_contents_view()); 134 native_tab_contents_view());
133 #else 135 #else
134 return static_cast<TabContentsViewType*>(owner_->view()); 136 return static_cast<TabContentsViewType*>(wrapper_->view());
135 #endif 137 #endif
136 } 138 }
137 139
138 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender, 140 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender,
139 GdkEventKey* key) { 141 GdkEventKey* key) {
140 if (key->keyval == GDK_Escape) { 142 if (key->keyval == GDK_Escape) {
141 // Let the stack unwind so the event handler can release its ref 143 // Let the stack unwind so the event handler can release its ref
142 // on widget(). 144 // on widget().
143 MessageLoop::current()->PostTask(FROM_HERE, 145 MessageLoop::current()->PostTask(FROM_HERE,
144 factory_.NewRunnableMethod( 146 factory_.NewRunnableMethod(
145 &ConstrainedWindowGtk::CloseConstrainedWindow)); 147 &ConstrainedWindowGtk::CloseConstrainedWindow));
146 return TRUE; 148 return TRUE;
147 } 149 }
148 150
149 return FALSE; 151 return FALSE;
150 } 152 }
151 153
152 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender, 154 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender,
153 GtkWidget* previous_toplevel) { 155 GtkWidget* previous_toplevel) {
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
155 if (!GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(widget()))) 157 if (!GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(widget())))
156 return; 158 return;
157 159
158 FocusConstrainedWindow(); 160 FocusConstrainedWindow();
159 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698