| OLD | NEW |
| 1 // Copyright 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/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
| 13 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/browser/web_contents_view.h" |
| 15 #include "ui/base/gtk/gtk_expanded_container.h" | 16 #include "ui/base/gtk/gtk_expanded_container.h" |
| 16 #include "ui/base/gtk/gtk_floating_container.h" | 17 #include "ui/base/gtk/gtk_floating_container.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 18 | 19 |
| 19 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) | 20 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) |
| 20 : tab_(NULL), | 21 : tab_(NULL), |
| 21 preview_(NULL), | 22 preview_(NULL), |
| 22 status_bubble_(status_bubble) { | 23 status_bubble_(status_bubble) { |
| 23 Init(); | 24 Init(); |
| 24 } | 25 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if (tab_) { | 74 if (tab_) { |
| 74 // If the preview is becoming the new permanent tab, we just reassign some | 75 // If the preview is becoming the new permanent tab, we just reassign some |
| 75 // pointers. Otherwise, we have to actually add it to the widget hierarchy. | 76 // pointers. Otherwise, we have to actually add it to the widget hierarchy. |
| 76 if (tab_ == preview_) | 77 if (tab_ == preview_) |
| 77 preview_ = NULL; | 78 preview_ = NULL; |
| 78 else | 79 else |
| 79 PackTab(tab_); | 80 PackTab(tab_); |
| 80 | 81 |
| 81 // Make sure that the tab is below the find bar. Sometimes the content | 82 // Make sure that the tab is below the find bar. Sometimes the content |
| 82 // native view will be null. | 83 // native view will be null. |
| 83 GtkWidget* widget = tab_->GetContentNativeView(); | 84 GtkWidget* widget = tab_->GetView()->GetContentNativeView(); |
| 84 if (widget) { | 85 if (widget) { |
| 85 GdkWindow* content_gdk_window = gtk_widget_get_window(widget); | 86 GdkWindow* content_gdk_window = gtk_widget_get_window(widget); |
| 86 if (content_gdk_window) | 87 if (content_gdk_window) |
| 87 gdk_window_lower(content_gdk_window); | 88 gdk_window_lower(content_gdk_window); |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 | 92 |
| 92 void TabContentsContainerGtk::SetPreview(content::WebContents* preview) { | 93 void TabContentsContainerGtk::SetPreview(content::WebContents* preview) { |
| 93 if (preview_ == preview) | 94 if (preview_ == preview) |
| 94 return; | 95 return; |
| 95 | 96 |
| 96 if (preview_) { | 97 if (preview_) { |
| 97 HideTab(preview_); | 98 HideTab(preview_); |
| 98 GtkWidget* preview_widget = preview_->GetNativeView(); | 99 GtkWidget* preview_widget = preview_->GetView()->GetNativeView(); |
| 99 if (preview_widget) | 100 if (preview_widget) |
| 100 gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); | 101 gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); |
| 101 } | 102 } |
| 102 | 103 |
| 103 preview_ = preview; | 104 preview_ = preview; |
| 104 | 105 |
| 105 if (preview_) | 106 if (preview_) |
| 106 PackTab(preview_); | 107 PackTab(preview_); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void TabContentsContainerGtk::PackTab(content::WebContents* tab) { | 110 void TabContentsContainerGtk::PackTab(content::WebContents* tab) { |
| 110 gfx::NativeView widget = tab->GetNativeView(); | 111 gfx::NativeView widget = tab->GetView()->GetNativeView(); |
| 111 if (widget) { | 112 if (widget) { |
| 112 if (gtk_widget_get_parent(widget) != expanded_) | 113 if (gtk_widget_get_parent(widget) != expanded_) |
| 113 gtk_container_add(GTK_CONTAINER(expanded_), widget); | 114 gtk_container_add(GTK_CONTAINER(expanded_), widget); |
| 114 gtk_widget_show(widget); | 115 gtk_widget_show(widget); |
| 115 } | 116 } |
| 116 | 117 |
| 117 tab->WasShown(); | 118 tab->WasShown(); |
| 118 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 119 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 119 content::Source<content::WebContents>(tab)); | 120 content::Source<content::WebContents>(tab)); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void TabContentsContainerGtk::HideTab(content::WebContents* tab) { | 123 void TabContentsContainerGtk::HideTab(content::WebContents* tab) { |
| 123 gfx::NativeView widget = tab->GetNativeView(); | 124 gfx::NativeView widget = tab->GetView()->GetNativeView(); |
| 124 if (widget) | 125 if (widget) |
| 125 gtk_widget_hide(widget); | 126 gtk_widget_hide(widget); |
| 126 | 127 |
| 127 tab->WasHidden(); | 128 tab->WasHidden(); |
| 128 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 129 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 129 content::Source<content::WebContents>(tab)); | 130 content::Source<content::WebContents>(tab)); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void TabContentsContainerGtk::DetachTab(content::WebContents* tab) { | 133 void TabContentsContainerGtk::DetachTab(content::WebContents* tab) { |
| 133 gfx::NativeView widget = tab->GetNativeView(); | 134 gfx::NativeView widget = tab->GetView()->GetNativeView(); |
| 134 | 135 |
| 135 // It is possible to detach an unrealized, unparented WebContents if you | 136 // It is possible to detach an unrealized, unparented WebContents if you |
| 136 // slow things down enough in valgrind. Might happen in the real world, too. | 137 // slow things down enough in valgrind. Might happen in the real world, too. |
| 137 if (widget) { | 138 if (widget) { |
| 138 GtkWidget* parent = gtk_widget_get_parent(widget); | 139 GtkWidget* parent = gtk_widget_get_parent(widget); |
| 139 if (parent) { | 140 if (parent) { |
| 140 DCHECK_EQ(parent, expanded_); | 141 DCHECK_EQ(parent, expanded_); |
| 141 gtk_container_remove(GTK_CONTAINER(expanded_), widget); | 142 gtk_container_remove(GTK_CONTAINER(expanded_), widget); |
| 142 } | 143 } |
| 143 } | 144 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 162 else | 163 else |
| 163 NOTREACHED(); | 164 NOTREACHED(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Prevent |preview_| from getting focus via the tab key. If |tab_| exists, try | 167 // Prevent |preview_| from getting focus via the tab key. If |tab_| exists, try |
| 167 // to focus that. Otherwise, do nothing, but stop event propagation. See bug | 168 // to focus that. Otherwise, do nothing, but stop event propagation. See bug |
| 168 // http://crbug.com/63365 | 169 // http://crbug.com/63365 |
| 169 gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget, | 170 gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget, |
| 170 GtkDirectionType focus) { | 171 GtkDirectionType focus) { |
| 171 if (preview_) { | 172 if (preview_) { |
| 172 gtk_widget_child_focus(tab_->GetContentNativeView(), focus); | 173 gtk_widget_child_focus(tab_->GetView()->GetContentNativeView(), focus); |
| 173 return TRUE; | 174 return TRUE; |
| 174 } | 175 } |
| 175 | 176 |
| 176 // No preview contents; let the default handler run. | 177 // No preview contents; let the default handler run. |
| 177 return FALSE; | 178 return FALSE; |
| 178 } | 179 } |
| 179 | 180 |
| 180 // ----------------------------------------------------------------------------- | 181 // ----------------------------------------------------------------------------- |
| 181 // ViewIDUtil::Delegate implementation | 182 // ViewIDUtil::Delegate implementation |
| 182 | 183 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 210 g_value_set_int(&value, allocation->width - requisition.width); | 211 g_value_set_int(&value, allocation->width - requisition.width); |
| 211 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 212 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 212 status->widget(), "x", &value); | 213 status->widget(), "x", &value); |
| 213 | 214 |
| 214 int child_y = std::max(allocation->height - requisition.height, 0); | 215 int child_y = std::max(allocation->height - requisition.height, 0); |
| 215 g_value_set_int(&value, child_y + status->y_offset()); | 216 g_value_set_int(&value, child_y + status->y_offset()); |
| 216 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 217 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 217 status->widget(), "y", &value); | 218 status->widget(), "y", &value); |
| 218 g_value_unset(&value); | 219 g_value_unset(&value); |
| 219 } | 220 } |
| OLD | NEW |