| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/tab_contents_container_gtk.h" | 5 #include "chrome/browser/gtk/tab_contents_container_gtk.h" |
| 6 | 6 |
| 7 #include "base/gfx/native_widget_types.h" | 7 #include "base/gfx/native_widget_types.h" |
| 8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
| 9 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 9 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) { | 23 void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) { |
| 24 gtk_box_pack_start(GTK_BOX(box), vbox_, TRUE, TRUE, 0); | 24 gtk_box_pack_start(GTK_BOX(box), vbox_, TRUE, TRUE, 0); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { | 27 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { |
| 28 if (tab_contents_) { | 28 if (tab_contents_) { |
| 29 gfx::NativeView widget = tab_contents_->GetNativeView(); | 29 gfx::NativeView widget = tab_contents_->GetNativeView(); |
| 30 if (widget) | 30 if (widget) |
| 31 gtk_container_remove(GTK_CONTAINER(vbox_), widget); | 31 gtk_widget_hide(widget); |
| 32 | 32 |
| 33 tab_contents_->WasHidden(); | 33 tab_contents_->WasHidden(); |
| 34 | 34 |
| 35 RemoveObservers(); | 35 RemoveObservers(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 tab_contents_ = tab_contents; | 38 tab_contents_ = tab_contents; |
| 39 | 39 |
| 40 // When detaching the last tab of the browser SetTabContents is invoked | 40 // When detaching the last tab of the browser SetTabContents is invoked |
| 41 // with NULL. Don't attempt to do anything in that case. | 41 // with NULL. Don't attempt to do anything in that case. |
| 42 if (tab_contents_) { | 42 if (tab_contents_) { |
| 43 AddObservers(); | 43 AddObservers(); |
| 44 | 44 |
| 45 gfx::NativeView widget = tab_contents_->GetNativeView(); | 45 gfx::NativeView widget = tab_contents_->GetNativeView(); |
| 46 if (widget) { | 46 if (widget) { |
| 47 gtk_box_pack_end(GTK_BOX(vbox_), widget, TRUE, TRUE, 0); | 47 // Pack it into |vbox_| if it isn't already. |
| 48 if (widget->parent != vbox_) |
| 49 gtk_box_pack_end(GTK_BOX(vbox_), widget, TRUE, TRUE, 0); |
| 48 gtk_widget_show(widget); | 50 gtk_widget_show(widget); |
| 49 } | 51 } |
| 52 |
| 50 // We need to make sure that we are below the findbar. | 53 // We need to make sure that we are below the findbar. |
| 51 // Sometimes the content native view will be null. | 54 // Sometimes the content native view will be null. |
| 52 // TODO(estade): will this case ever cause findbar occlusion problems? | 55 // TODO(estade): will this case ever cause findbar occlusion problems? |
| 53 if (tab_contents_->GetContentNativeView()) { | 56 if (tab_contents_->GetContentNativeView()) { |
| 54 GdkWindow* content_gdk_window = | 57 GdkWindow* content_gdk_window = |
| 55 tab_contents_->GetContentNativeView()->window; | 58 tab_contents_->GetContentNativeView()->window; |
| 56 if (content_gdk_window) | 59 if (content_gdk_window) |
| 57 gdk_window_lower(content_gdk_window); | 60 gdk_window_lower(content_gdk_window); |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 } | 63 } |
| 61 | 64 |
| 65 void TabContentsContainerGtk::DetachTabContents(TabContents* tab_contents) { |
| 66 gfx::NativeView widget = tab_contents_->GetNativeView(); |
| 67 if (widget) { |
| 68 DCHECK_EQ(widget->parent, vbox_); |
| 69 gtk_container_remove(GTK_CONTAINER(vbox_), widget); |
| 70 } |
| 71 } |
| 72 |
| 62 void TabContentsContainerGtk::Observe(NotificationType type, | 73 void TabContentsContainerGtk::Observe(NotificationType type, |
| 63 const NotificationSource& source, | 74 const NotificationSource& source, |
| 64 const NotificationDetails& details) { | 75 const NotificationDetails& details) { |
| 65 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { | 76 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { |
| 66 RenderViewHostSwitchedDetails* switched_details = | 77 RenderViewHostSwitchedDetails* switched_details = |
| 67 Details<RenderViewHostSwitchedDetails>(details).ptr(); | 78 Details<RenderViewHostSwitchedDetails>(details).ptr(); |
| 68 RenderViewHostChanged(switched_details->old_host, | 79 RenderViewHostChanged(switched_details->old_host, |
| 69 switched_details->new_host); | 80 switched_details->new_host); |
| 70 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | 81 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { |
| 71 TabContentsDestroyed(Source<TabContents>(source).ptr()); | 82 TabContentsDestroyed(Source<TabContents>(source).ptr()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // RENDER_VIEW_HOST_CHANGED notification. This was used on Windows for focus | 122 // RENDER_VIEW_HOST_CHANGED notification. This was used on Windows for focus |
| 112 // issues, and I'm not entirely convinced that this isn't necessary. | 123 // issues, and I'm not entirely convinced that this isn't necessary. |
| 113 } | 124 } |
| 114 | 125 |
| 115 void TabContentsContainerGtk::TabContentsDestroyed(TabContents* contents) { | 126 void TabContentsContainerGtk::TabContentsDestroyed(TabContents* contents) { |
| 116 // Sometimes, a TabContents is destroyed before we know about it. This allows | 127 // Sometimes, a TabContents is destroyed before we know about it. This allows |
| 117 // us to clean up our state in case this happens. | 128 // us to clean up our state in case this happens. |
| 118 DCHECK(contents == tab_contents_); | 129 DCHECK(contents == tab_contents_); |
| 119 SetTabContents(NULL); | 130 SetTabContents(NULL); |
| 120 } | 131 } |
| OLD | NEW |