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

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

Issue 11421079: Persist the Instant API to committed search result pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More fixes Created 8 years 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 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/tab_contents_container_gtk.h" 5 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "chrome/browser/ui/gtk/status_bubble_gtk.h" 10 #include "chrome/browser/ui/gtk/status_bubble_gtk.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
13 #include "content/public/browser/notification_source.h" 12 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/render_widget_host_view.h" 13 #include "content/public/browser/render_widget_host_view.h"
15 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
16 #include "ui/base/gtk/gtk_expanded_container.h" 15 #include "ui/base/gtk/gtk_expanded_container.h"
17 #include "ui/base/gtk/gtk_floating_container.h" 16 #include "ui/base/gtk/gtk_floating_container.h"
18 #include "ui/gfx/native_widget_types.h" 17 #include "ui/gfx/native_widget_types.h"
19 18
20 using content::WebContents;
21
22 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) 19 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble)
23 : tab_(NULL), 20 : tab_(NULL),
24 preview_(NULL), 21 preview_(NULL),
25 status_bubble_(status_bubble) { 22 status_bubble_(status_bubble) {
26 Init(); 23 Init();
27 } 24 }
28 25
29 TabContentsContainerGtk::~TabContentsContainerGtk() { 26 TabContentsContainerGtk::~TabContentsContainerGtk() {
30 floating_.Destroy(); 27 floating_.Destroy();
31 } 28 }
(...skipping 25 matching lines...) Expand all
57 g_signal_connect(floating_.get(), "set-floating-position", 54 g_signal_connect(floating_.get(), "set-floating-position",
58 G_CALLBACK(OnSetFloatingPosition), this); 55 G_CALLBACK(OnSetFloatingPosition), this);
59 } 56 }
60 57
61 gtk_widget_show(expanded_); 58 gtk_widget_show(expanded_);
62 gtk_widget_show(floating_.get()); 59 gtk_widget_show(floating_.get());
63 60
64 ViewIDUtil::SetDelegateForWidget(widget(), this); 61 ViewIDUtil::SetDelegateForWidget(widget(), this);
65 } 62 }
66 63
67 void TabContentsContainerGtk::SetTab(TabContents* tab) { 64 void TabContentsContainerGtk::SetTab(content::WebContents* tab) {
68 if (tab_ == tab) 65 if (tab_ == tab)
69 return; 66 return;
70 67
71 if (tab_) 68 if (tab_)
72 HideTab(tab_); 69 HideTab(tab_);
73 70
74 tab_ = tab; 71 tab_ = tab;
75 72
76 if (tab_) { 73 if (tab_) {
77 // If the preview is becoming the new permanent tab, we just reassign some 74 // If the preview is becoming the new permanent tab, we just reassign some
78 // pointers. Otherwise, we have to actually add it to the widget hierarchy. 75 // pointers. Otherwise, we have to actually add it to the widget hierarchy.
79 if (tab_ == preview_) 76 if (tab_ == preview_)
80 preview_ = NULL; 77 preview_ = NULL;
81 else 78 else
82 PackTab(tab_); 79 PackTab(tab_);
83 80
84 // Make sure that the tab is below the find bar. Sometimes the content 81 // Make sure that the tab is below the find bar. Sometimes the content
85 // native view will be null. 82 // native view will be null.
86 GtkWidget* widget = tab_->web_contents()->GetContentNativeView(); 83 GtkWidget* widget = tab_->GetContentNativeView();
87 if (widget) { 84 if (widget) {
88 GdkWindow* content_gdk_window = gtk_widget_get_window(widget); 85 GdkWindow* content_gdk_window = gtk_widget_get_window(widget);
89 if (content_gdk_window) 86 if (content_gdk_window)
90 gdk_window_lower(content_gdk_window); 87 gdk_window_lower(content_gdk_window);
91 } 88 }
92 } 89 }
93 } 90 }
94 91
95 void TabContentsContainerGtk::SetPreview(TabContents* preview) { 92 void TabContentsContainerGtk::SetPreview(content::WebContents* preview) {
96 if (preview_ == preview) 93 if (preview_ == preview)
97 return; 94 return;
98 95
99 if (preview_) { 96 if (preview_) {
100 HideTab(preview_); 97 HideTab(preview_);
101 GtkWidget* preview_widget = preview_->web_contents()->GetNativeView(); 98 GtkWidget* preview_widget = preview_->GetNativeView();
102 if (preview_widget) 99 if (preview_widget)
103 gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); 100 gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget);
104 } 101 }
105 102
106 preview_ = preview; 103 preview_ = preview;
107 104
108 if (preview_) 105 if (preview_)
109 PackTab(preview_); 106 PackTab(preview_);
110 } 107 }
111 108
112 void TabContentsContainerGtk::PackTab(TabContents* tab) { 109 void TabContentsContainerGtk::PackTab(content::WebContents* tab) {
113 gfx::NativeView widget = tab->web_contents()->GetNativeView(); 110 gfx::NativeView widget = tab->GetNativeView();
114 if (widget) { 111 if (widget) {
115 if (gtk_widget_get_parent(widget) != expanded_) 112 if (gtk_widget_get_parent(widget) != expanded_)
116 gtk_container_add(GTK_CONTAINER(expanded_), widget); 113 gtk_container_add(GTK_CONTAINER(expanded_), widget);
117 gtk_widget_show(widget); 114 gtk_widget_show(widget);
118 } 115 }
119 116
120 tab->web_contents()->WasShown(); 117 tab->WasShown();
121 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 118 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
122 content::Source<WebContents>(tab->web_contents())); 119 content::Source<content::WebContents>(tab));
123 } 120 }
124 121
125 void TabContentsContainerGtk::HideTab(TabContents* tab) { 122 void TabContentsContainerGtk::HideTab(content::WebContents* tab) {
126 gfx::NativeView widget = tab->web_contents()->GetNativeView(); 123 gfx::NativeView widget = tab->GetNativeView();
127 if (widget) 124 if (widget)
128 gtk_widget_hide(widget); 125 gtk_widget_hide(widget);
129 126
130 tab->web_contents()->WasHidden(); 127 tab->WasHidden();
131 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 128 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
132 content::Source<WebContents>(tab->web_contents())); 129 content::Source<content::WebContents>(tab));
133 } 130 }
134 131
135 void TabContentsContainerGtk::DetachTab(WebContents* tab) { 132 void TabContentsContainerGtk::DetachTab(content::WebContents* tab) {
136 gfx::NativeView widget = tab->GetNativeView(); 133 gfx::NativeView widget = tab->GetNativeView();
137 134
138 // It is possible to detach an unrealized, unparented WebContents if you 135 // It is possible to detach an unrealized, unparented WebContents if you
139 // slow things down enough in valgrind. Might happen in the real world, too. 136 // slow things down enough in valgrind. Might happen in the real world, too.
140 if (widget) { 137 if (widget) {
141 GtkWidget* parent = gtk_widget_get_parent(widget); 138 GtkWidget* parent = gtk_widget_get_parent(widget);
142 if (parent) { 139 if (parent) {
143 DCHECK_EQ(parent, expanded_); 140 DCHECK_EQ(parent, expanded_);
144 gtk_container_remove(GTK_CONTAINER(expanded_), widget); 141 gtk_container_remove(GTK_CONTAINER(expanded_), widget);
145 } 142 }
146 } 143 }
147 } 144 }
148 145
149 void TabContentsContainerGtk::Observe( 146 void TabContentsContainerGtk::Observe(
150 int type, 147 int type,
151 const content::NotificationSource& source, 148 const content::NotificationSource& source,
152 const content::NotificationDetails& details) { 149 const content::NotificationDetails& details) {
153 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); 150 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type);
154 WebContentsDestroyed(content::Source<WebContents>(source).ptr()); 151 WebContentsDestroyed(content::Source<content::WebContents>(source).ptr());
155 } 152 }
156 153
157 void TabContentsContainerGtk::WebContentsDestroyed(WebContents* contents) { 154 void TabContentsContainerGtk::WebContentsDestroyed(
155 content::WebContents* contents) {
158 // Sometimes, a WebContents is destroyed before we know about it. This allows 156 // Sometimes, a WebContents is destroyed before we know about it. This allows
159 // us to clean up our state in case this happens. 157 // us to clean up our state in case this happens.
160 if (preview_ && contents == preview_->web_contents()) 158 if (contents == preview_)
161 SetPreview(NULL); 159 SetPreview(NULL);
162 else if (tab_ && contents == tab_->web_contents()) 160 else if (contents == tab_)
163 SetTab(NULL); 161 SetTab(NULL);
164 else 162 else
165 NOTREACHED(); 163 NOTREACHED();
166 } 164 }
167 165
168 // Prevent |preview_| from getting focus via the tab key. If |tab_| exists, try 166 // Prevent |preview_| from getting focus via the tab key. If |tab_| exists, try
169 // to focus that. Otherwise, do nothing, but stop event propagation. See bug 167 // to focus that. Otherwise, do nothing, but stop event propagation. See bug
170 // http://crbug.com/63365 168 // http://crbug.com/63365
171 gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget, 169 gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget,
172 GtkDirectionType focus) { 170 GtkDirectionType focus) {
173 if (preview_) { 171 if (preview_) {
174 gtk_widget_child_focus(tab_->web_contents()->GetContentNativeView(), focus); 172 gtk_widget_child_focus(tab_->GetContentNativeView(), focus);
175 return TRUE; 173 return TRUE;
176 } 174 }
177 175
178 // No preview contents; let the default handler run. 176 // No preview contents; let the default handler run.
179 return FALSE; 177 return FALSE;
180 } 178 }
181 179
182 // ----------------------------------------------------------------------------- 180 // -----------------------------------------------------------------------------
183 // ViewIDUtil::Delegate implementation 181 // ViewIDUtil::Delegate implementation
184 182
(...skipping 27 matching lines...) Expand all
212 g_value_set_int(&value, allocation->width - requisition.width); 210 g_value_set_int(&value, allocation->width - requisition.width);
213 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 211 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
214 status->widget(), "x", &value); 212 status->widget(), "x", &value);
215 213
216 int child_y = std::max(allocation->height - requisition.height, 0); 214 int child_y = std::max(allocation->height - requisition.height, 0);
217 g_value_set_int(&value, child_y + status->y_offset()); 215 g_value_set_int(&value, child_y + status->y_offset());
218 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 216 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
219 status->widget(), "y", &value); 217 status->widget(), "y", &value);
220 g_value_unset(&value); 218 g_value_unset(&value);
221 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698