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

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

Issue 10545115: TabContentsWrapper -> TabContents, part 41. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "ui/base/gtk/focus_store_gtk.h" 19 #include "ui/base/gtk/focus_store_gtk.h"
20 #include "ui/base/gtk/gtk_compat.h" 20 #include "ui/base/gtk/gtk_compat.h"
21 #include "ui/base/gtk/gtk_hig_constants.h" 21 #include "ui/base/gtk/gtk_hig_constants.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() { 25 ConstrainedWindowGtkDelegate::~ConstrainedWindowGtkDelegate() {
26 } 26 }
27 27
28 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) { 28 bool ConstrainedWindowGtkDelegate::GetBackgroundColor(GdkColor* color) {
29 return false; 29 return false;
30 } 30 }
31 31
32 bool ConstrainedWindowGtkDelegate::ShouldHaveBorderPadding() const { 32 bool ConstrainedWindowGtkDelegate::ShouldHaveBorderPadding() const {
33 return true; 33 return true;
34 } 34 }
35 35
36 ConstrainedWindowGtk::ConstrainedWindowGtk( 36 ConstrainedWindowGtk::ConstrainedWindowGtk(
37 TabContentsWrapper* wrapper, 37 TabContents* tab_contents,
38 ConstrainedWindowGtkDelegate* delegate) 38 ConstrainedWindowGtkDelegate* delegate)
39 : wrapper_(wrapper), 39 : tab_contents_(tab_contents),
40 delegate_(delegate), 40 delegate_(delegate),
41 visible_(false), 41 visible_(false),
42 weak_factory_(this) { 42 weak_factory_(this) {
43 DCHECK(wrapper); 43 DCHECK(tab_contents);
44 DCHECK(delegate); 44 DCHECK(delegate);
45 GtkWidget* dialog = delegate->GetWidgetRoot(); 45 GtkWidget* dialog = delegate->GetWidgetRoot();
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);
(...skipping 18 matching lines...) Expand all
72 gtk_container_add(GTK_CONTAINER(frame), alignment); 72 gtk_container_add(GTK_CONTAINER(frame), alignment);
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 wrapper_->constrained_window_tab_helper()->AddConstrainedDialog(this); 82 tab_contents_->constrained_window_tab_helper()->AddConstrainedDialog(this);
83 } 83 }
84 84
85 ConstrainedWindowGtk::~ConstrainedWindowGtk() { 85 ConstrainedWindowGtk::~ConstrainedWindowGtk() {
86 border_.Destroy(); 86 border_.Destroy();
87 } 87 }
88 88
89 void ConstrainedWindowGtk::ShowConstrainedWindow() { 89 void ConstrainedWindowGtk::ShowConstrainedWindow() {
90 gtk_widget_show_all(border_.get()); 90 gtk_widget_show_all(border_.get());
91 91
92 // We collaborate with WebContentsView and stick ourselves in the 92 // We collaborate with WebContentsView and stick ourselves in the
93 // WebContentsView's floating container. 93 // WebContentsView's floating container.
94 ContainingView()->AttachConstrainedWindow(this); 94 ContainingView()->AttachConstrainedWindow(this);
95 95
96 visible_ = true; 96 visible_ = true;
97 } 97 }
98 98
99 void ConstrainedWindowGtk::CloseConstrainedWindow() { 99 void ConstrainedWindowGtk::CloseConstrainedWindow() {
100 if (visible_) 100 if (visible_)
101 ContainingView()->RemoveConstrainedWindow(this); 101 ContainingView()->RemoveConstrainedWindow(this);
102 delegate_->DeleteDelegate(); 102 delegate_->DeleteDelegate();
103 wrapper_->constrained_window_tab_helper()->WillClose(this); 103 tab_contents_->constrained_window_tab_helper()->WillClose(this);
104 104
105 delete this; 105 delete this;
106 } 106 }
107 107
108 void ConstrainedWindowGtk::FocusConstrainedWindow() { 108 void ConstrainedWindowGtk::FocusConstrainedWindow() {
109 GtkWidget* focus_widget = delegate_->GetFocusWidget(); 109 GtkWidget* focus_widget = delegate_->GetFocusWidget();
110 if (!focus_widget) 110 if (!focus_widget)
111 return; 111 return;
112 112
113 // 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
114 // until this tab is refocused. 114 // until this tab is refocused.
115 ConstrainedWindowTabHelper* helper = 115 ConstrainedWindowTabHelper* helper =
116 wrapper_->constrained_window_tab_helper(); 116 tab_contents_->constrained_window_tab_helper();
117 if ((!helper->delegate() || 117 if ((!helper->delegate() ||
118 helper->delegate()->ShouldFocusConstrainedWindow()) && 118 helper->delegate()->ShouldFocusConstrainedWindow()) &&
119 gtk_util::IsWidgetAncestryVisible(focus_widget)) { 119 gtk_util::IsWidgetAncestryVisible(focus_widget)) {
120 gtk_widget_grab_focus(focus_widget); 120 gtk_widget_grab_focus(focus_widget);
121 } else { 121 } else {
122 ContainingView()->focus_store()->SetWidget(focus_widget); 122 ContainingView()->focus_store()->SetWidget(focus_widget);
123 } 123 }
124 } 124 }
125 125
126 ConstrainedWindowGtk::TabContentsViewType* 126 ConstrainedWindowGtk::TabContentsViewType*
127 ConstrainedWindowGtk::ContainingView() { 127 ConstrainedWindowGtk::ContainingView() {
128 return ChromeWebContentsViewDelegateGtk::GetFor(wrapper_->web_contents()); 128 return
129 ChromeWebContentsViewDelegateGtk::GetFor(tab_contents_->web_contents());
129 } 130 }
130 131
131 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender, 132 gboolean ConstrainedWindowGtk::OnKeyPress(GtkWidget* sender,
132 GdkEventKey* key) { 133 GdkEventKey* key) {
133 if (key->keyval == GDK_Escape) { 134 if (key->keyval == GDK_Escape) {
134 // Let the stack unwind so the event handler can release its ref 135 // Let the stack unwind so the event handler can release its ref
135 // on widget(). 136 // on widget().
136 MessageLoop::current()->PostTask( 137 MessageLoop::current()->PostTask(
137 FROM_HERE, 138 FROM_HERE,
138 base::Bind(&ConstrainedWindowGtk::CloseConstrainedWindow, 139 base::Bind(&ConstrainedWindowGtk::CloseConstrainedWindow,
139 weak_factory_.GetWeakPtr())); 140 weak_factory_.GetWeakPtr()));
140 return TRUE; 141 return TRUE;
141 } 142 }
142 143
143 return FALSE; 144 return FALSE;
144 } 145 }
145 146
146 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender, 147 void ConstrainedWindowGtk::OnHierarchyChanged(GtkWidget* sender,
147 GtkWidget* previous_toplevel) { 148 GtkWidget* previous_toplevel) {
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
149 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(widget()))) 150 if (!gtk_widget_is_toplevel(gtk_widget_get_toplevel(widget())))
150 return; 151 return;
151 152
152 FocusConstrainedWindow(); 153 FocusConstrainedWindow();
153 } 154 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/constrained_window_gtk.h ('k') | chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698