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

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view_gtk.cc

Issue 8477042: Move Sad Tab implementation out of the TabContentsViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes for jochen and jam Created 9 years, 1 month 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/tab_contents/tab_contents_view_gtk.h" 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkkeysyms.h> 8 #include <gdk/gdkkeysyms.h>
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/browser_shutdown.h"
17 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" 16 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
18 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h" 17 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h"
19 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" 18 #include "chrome/browser/ui/gtk/constrained_window_gtk.h"
20 #include "chrome/browser/ui/gtk/sad_tab_gtk.h"
21 #include "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
22 #include "content/browser/renderer_host/render_view_host_factory.h" 20 #include "content/browser/renderer_host/render_view_host_factory.h"
23 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" 21 #include "content/browser/renderer_host/render_widget_host_view_gtk.h"
24 #include "content/browser/tab_contents/interstitial_page.h" 22 #include "content/browser/tab_contents/interstitial_page.h"
25 #include "content/browser/tab_contents/tab_contents.h" 23 #include "content/browser/tab_contents/tab_contents.h"
26 #include "content/browser/tab_contents/tab_contents_delegate.h" 24 #include "content/browser/tab_contents/tab_contents_delegate.h"
27 #include "content/browser/tab_contents/web_drag_dest_gtk.h" 25 #include "content/browser/tab_contents/web_drag_dest_gtk.h"
28 #include "content/browser/tab_contents/web_drag_source_gtk.h" 26 #include "content/browser/tab_contents/web_drag_source_gtk.h"
29 #include "content/public/browser/notification_source.h"
30 #include "content/public/browser/notification_types.h"
31 #include "ui/base/gtk/gtk_expanded_container.h" 27 #include "ui/base/gtk/gtk_expanded_container.h"
32 #include "ui/base/gtk/gtk_floating_container.h" 28 #include "ui/base/gtk/gtk_floating_container.h"
33 #include "ui/gfx/point.h" 29 #include "ui/gfx/point.h"
34 #include "ui/gfx/rect.h" 30 #include "ui/gfx/rect.h"
35 #include "ui/gfx/size.h" 31 #include "ui/gfx/size.h"
36 #include "webkit/glue/webdropdata.h" 32 #include "webkit/glue/webdropdata.h"
37 33
38 using WebKit::WebDragOperation; 34 using WebKit::WebDragOperation;
39 using WebKit::WebDragOperationsMask; 35 using WebKit::WebDragOperationsMask;
40 36
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 70
75 return FALSE; 71 return FALSE;
76 } 72 }
77 73
78 } // namespace 74 } // namespace
79 75
80 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) 76 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
81 : tab_contents_(tab_contents), 77 : tab_contents_(tab_contents),
82 floating_(gtk_floating_container_new()), 78 floating_(gtk_floating_container_new()),
83 expanded_(gtk_expanded_container_new()), 79 expanded_(gtk_expanded_container_new()),
84 constrained_window_(NULL) { 80 constrained_window_(NULL),
81 overlaid_view_(NULL) {
85 gtk_widget_set_name(expanded_, "chrome-tab-contents-view"); 82 gtk_widget_set_name(expanded_, "chrome-tab-contents-view");
86 g_signal_connect(expanded_, "size-allocate", 83 g_signal_connect(expanded_, "size-allocate",
87 G_CALLBACK(OnSizeAllocateThunk), this); 84 G_CALLBACK(OnSizeAllocateThunk), this);
88 g_signal_connect(expanded_, "child-size-request", 85 g_signal_connect(expanded_, "child-size-request",
89 G_CALLBACK(OnChildSizeRequestThunk), this); 86 G_CALLBACK(OnChildSizeRequestThunk), this);
90 g_signal_connect(floating_.get(), "set-floating-position", 87 g_signal_connect(floating_.get(), "set-floating-position",
91 G_CALLBACK(OnSetFloatingPositionThunk), this); 88 G_CALLBACK(OnSetFloatingPositionThunk), this);
92 89
93 gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_); 90 gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_);
94 gtk_widget_show(expanded_); 91 gtk_widget_show(expanded_);
95 gtk_widget_show(floating_.get()); 92 gtk_widget_show(floating_.get());
96 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
97 content::Source<TabContents>(tab_contents));
98 drag_source_.reset(new content::WebDragSourceGtk(tab_contents)); 93 drag_source_.reset(new content::WebDragSourceGtk(tab_contents));
99 } 94 }
100 95
101 TabContentsViewGtk::~TabContentsViewGtk() { 96 TabContentsViewGtk::~TabContentsViewGtk() {
102 floating_.Destroy(); 97 floating_.Destroy();
103 } 98 }
104 99
105 void TabContentsViewGtk::AttachConstrainedWindow( 100 void TabContentsViewGtk::AttachConstrainedWindow(
106 ConstrainedWindowGtk* constrained_window) { 101 ConstrainedWindowGtk* constrained_window) {
107 DCHECK(constrained_window_ == NULL); 102 DCHECK(constrained_window_ == NULL);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 void TabContentsViewGtk::SetPageTitle(const string16& title) { 186 void TabContentsViewGtk::SetPageTitle(const string16& title) {
192 // Set the window name to include the page title so it's easier to spot 187 // Set the window name to include the page title so it's easier to spot
193 // when debugging (e.g. via xwininfo -tree). 188 // when debugging (e.g. via xwininfo -tree).
194 gfx::NativeView content_view = GetContentNativeView(); 189 gfx::NativeView content_view = GetContentNativeView();
195 if (content_view && content_view->window) 190 if (content_view && content_view->window)
196 gdk_window_set_title(content_view->window, UTF16ToUTF8(title).c_str()); 191 gdk_window_set_title(content_view->window, UTF16ToUTF8(title).c_str());
197 } 192 }
198 193
199 void TabContentsViewGtk::OnTabCrashed(base::TerminationStatus status, 194 void TabContentsViewGtk::OnTabCrashed(base::TerminationStatus status,
200 int error_code) { 195 int error_code) {
201 // Only show the sad tab if we're not in browser shutdown, so that TabContents
202 // objects that are not in a browser (e.g., HTML dialogs) and thus are
203 // visible do not flash a sad tab page.
204 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
205 return;
206
207 if (tab_contents_ != NULL && !sad_tab_.get()) {
208 sad_tab_.reset(new SadTabGtk(
209 tab_contents_,
210 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ?
211 SadTabGtk::KILLED : SadTabGtk::CRASHED));
212 InsertIntoContentArea(sad_tab_->widget());
213 gtk_widget_show(sad_tab_->widget());
214 }
215 } 196 }
216 197
217 void TabContentsViewGtk::SizeContents(const gfx::Size& size) { 198 void TabContentsViewGtk::SizeContents(const gfx::Size& size) {
218 // We don't need to manually set the size of of widgets in GTK+, but we do 199 // We don't need to manually set the size of of widgets in GTK+, but we do
219 // need to pass the sizing information on to the RWHV which will pass the 200 // need to pass the sizing information on to the RWHV which will pass the
220 // sizing information on to the renderer. 201 // sizing information on to the renderer.
221 requested_size_ = size; 202 requested_size_ = size;
222 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); 203 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView();
223 if (rwhv) 204 if (rwhv)
224 rwhv->SetSize(size); 205 rwhv->SetSize(size);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 void TabContentsViewGtk::GetViewBounds(gfx::Rect* out) const { 253 void TabContentsViewGtk::GetViewBounds(gfx::Rect* out) const {
273 if (!floating_->window) { 254 if (!floating_->window) {
274 out->SetRect(0, 0, requested_size_.width(), requested_size_.height()); 255 out->SetRect(0, 0, requested_size_.width(), requested_size_.height());
275 return; 256 return;
276 } 257 }
277 int x = 0, y = 0, w, h; 258 int x = 0, y = 0, w, h;
278 gdk_window_get_geometry(floating_->window, &x, &y, &w, &h, NULL); 259 gdk_window_get_geometry(floating_->window, &x, &y, &w, &h, NULL);
279 out->SetRect(x, y, w, h); 260 out->SetRect(x, y, w, h);
280 } 261 }
281 262
263 void TabContentsViewGtk::InstallOverlayView(gfx::NativeView view) {
264 DCHECK(!overlaid_view_);
265 overlaid_view_ = view;
266 InsertIntoContentArea(view);
267 gtk_widget_show(view);
268 }
269
270 void TabContentsViewGtk::RemoveOverlayView() {
271 DCHECK(overlaid_view_);
272 gtk_container_remove(GTK_CONTAINER(expanded_), overlaid_view_);
273 overlaid_view_ = NULL;
274 }
275
282 void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) { 276 void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) {
283 focus_store_.SetWidget(widget); 277 focus_store_.SetWidget(widget);
284 } 278 }
285 279
286 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { 280 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) {
287 drag_dest_->UpdateDragStatus(operation); 281 drag_dest_->UpdateDragStatus(operation);
288 } 282 }
289 283
290 void TabContentsViewGtk::GotFocus() { 284 void TabContentsViewGtk::GotFocus() {
291 // This is only used in the views FocusManager stuff but it bleeds through 285 // This is only used in the views FocusManager stuff but it bleeds through
292 // all subclasses. http://crbug.com/21875 286 // all subclasses. http://crbug.com/21875
293 } 287 }
294 288
295 // This is called when we the renderer asks us to take focus back (i.e., it has 289 // This is called when we the renderer asks us to take focus back (i.e., it has
296 // iterated past the last focusable element on the page). 290 // iterated past the last focusable element on the page).
297 void TabContentsViewGtk::TakeFocus(bool reverse) { 291 void TabContentsViewGtk::TakeFocus(bool reverse) {
298 if (!tab_contents_->delegate()->TakeFocus(reverse)) { 292 if (!tab_contents_->delegate()->TakeFocus(reverse)) {
299 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), 293 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()),
300 reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD); 294 reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
301 } 295 }
302 } 296 }
303 297
304 void TabContentsViewGtk::Observe(int type,
305 const content::NotificationSource& source,
306 const content::NotificationDetails& details) {
307 switch (type) {
308 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: {
309 // No need to remove the SadTabGtk's widget from the container since
310 // the new RenderWidgetHostViewGtk instance already removed all the
311 // vbox's children.
312 sad_tab_.reset();
313 break;
314 }
315 default:
316 NOTREACHED() << "Got a notification we didn't register for.";
317 break;
318 }
319 }
320
321
322 void TabContentsViewGtk::CreateNewWindow( 298 void TabContentsViewGtk::CreateNewWindow(
323 int route_id, 299 int route_id,
324 const ViewHostMsg_CreateWindow_Params& params) { 300 const ViewHostMsg_CreateWindow_Params& params) {
325 delegate_view_helper_.CreateNewWindowFromTabContents( 301 delegate_view_helper_.CreateNewWindowFromTabContents(
326 tab_contents_, route_id, params); 302 tab_contents_, route_id, params);
327 } 303 }
328 304
329 void TabContentsViewGtk::CreateNewWidget( 305 void TabContentsViewGtk::CreateNewWidget(
330 int route_id, WebKit::WebPopupType popup_type) { 306 int route_id, WebKit::WebPopupType popup_type) {
331 delegate_view_helper_.CreateNewWidget(route_id, popup_type, 307 delegate_view_helper_.CreateNewWidget(route_id, popup_type,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 g_value_set_int(&value, child_x); 479 g_value_set_int(&value, child_x);
504 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 480 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
505 widget, "x", &value); 481 widget, "x", &value);
506 482
507 int child_y = std::max((allocation->height - requisition.height) / 2, 0); 483 int child_y = std::max((allocation->height - requisition.height) / 2, 0);
508 g_value_set_int(&value, child_y); 484 g_value_set_int(&value, child_y);
509 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 485 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
510 widget, "y", &value); 486 widget, "y", &value);
511 g_value_unset(&value); 487 g_value_unset(&value);
512 } 488 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_gtk.h ('k') | chrome/browser/tab_contents/tab_contents_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698