| OLD | NEW |
| 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/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_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
| 14 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "ui/base/gtk/gtk_expanded_container.h" | 16 #include "ui/base/gtk/gtk_expanded_container.h" |
| 17 #include "ui/base/gtk/gtk_floating_container.h" | 17 #include "ui/base/gtk/gtk_floating_container.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 19 | 19 |
| 20 using content::WebContents; | 20 using content::WebContents; |
| 21 | 21 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 g_signal_connect(floating_.get(), "set-floating-position", | 57 g_signal_connect(floating_.get(), "set-floating-position", |
| 58 G_CALLBACK(OnSetFloatingPosition), this); | 58 G_CALLBACK(OnSetFloatingPosition), this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 gtk_widget_show(expanded_); | 61 gtk_widget_show(expanded_); |
| 62 gtk_widget_show(floating_.get()); | 62 gtk_widget_show(floating_.get()); |
| 63 | 63 |
| 64 ViewIDUtil::SetDelegateForWidget(widget(), this); | 64 ViewIDUtil::SetDelegateForWidget(widget(), this); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void TabContentsContainerGtk::SetTab(TabContentsWrapper* tab) { | 67 void TabContentsContainerGtk::SetTab(TabContents* tab) { |
| 68 HideTab(tab_); | 68 HideTab(tab_); |
| 69 if (tab_) { | 69 if (tab_) { |
| 70 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 70 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 71 content::Source<TabContentsWrapper>(tab_)); | 71 content::Source<TabContents>(tab_)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 tab_ = tab; | 74 tab_ = tab; |
| 75 | 75 |
| 76 if (tab_ == preview_) { | 76 if (tab_ == preview_) { |
| 77 // If the preview contents is becoming the new permanent tab contents, we | 77 // If the preview contents is becoming the new permanent tab contents, we |
| 78 // just reassign some pointers. | 78 // just reassign some pointers. |
| 79 preview_ = NULL; | 79 preview_ = NULL; |
| 80 } else if (tab_) { | 80 } else if (tab_) { |
| 81 // Otherwise we actually have to add it to the widget hierarchy. | 81 // Otherwise we actually have to add it to the widget hierarchy. |
| 82 PackTab(tab); | 82 PackTab(tab); |
| 83 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 83 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 84 content::Source<TabContentsWrapper>(tab_)); | 84 content::Source<TabContents>(tab_)); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 TabContentsWrapper* TabContentsContainerGtk::GetVisibleTab() { | 88 TabContents* TabContentsContainerGtk::GetVisibleTab() { |
| 89 return preview_ ? preview_ : tab_; | 89 return preview_ ? preview_ : tab_; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void TabContentsContainerGtk::SetPreview(TabContentsWrapper* preview) { | 92 void TabContentsContainerGtk::SetPreview(TabContents* preview) { |
| 93 if (preview_) | 93 if (preview_) |
| 94 RemovePreview(); | 94 RemovePreview(); |
| 95 else | 95 else |
| 96 HideTab(tab_); | 96 HideTab(tab_); |
| 97 | 97 |
| 98 preview_ = preview; | 98 preview_ = preview; |
| 99 | 99 |
| 100 PackTab(preview); | 100 PackTab(preview); |
| 101 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 101 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 102 content::Source<TabContentsWrapper>(preview_)); | 102 content::Source<TabContents>(preview_)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void TabContentsContainerGtk::RemovePreview() { | 105 void TabContentsContainerGtk::RemovePreview() { |
| 106 if (!preview_) | 106 if (!preview_) |
| 107 return; | 107 return; |
| 108 | 108 |
| 109 HideTab(preview_); | 109 HideTab(preview_); |
| 110 | 110 |
| 111 GtkWidget* preview_widget = preview_->web_contents()->GetNativeView(); | 111 GtkWidget* preview_widget = preview_->web_contents()->GetNativeView(); |
| 112 if (preview_widget) | 112 if (preview_widget) |
| 113 gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); | 113 gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); |
| 114 | 114 |
| 115 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 115 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 116 content::Source<TabContentsWrapper>(preview_)); | 116 content::Source<TabContents>(preview_)); |
| 117 preview_ = NULL; | 117 preview_ = NULL; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void TabContentsContainerGtk::PopPreview() { | 120 void TabContentsContainerGtk::PopPreview() { |
| 121 if (!preview_) | 121 if (!preview_) |
| 122 return; | 122 return; |
| 123 | 123 |
| 124 RemovePreview(); | 124 RemovePreview(); |
| 125 | 125 |
| 126 PackTab(tab_); | 126 PackTab(tab_); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void TabContentsContainerGtk::PackTab(TabContentsWrapper* tab) { | 129 void TabContentsContainerGtk::PackTab(TabContents* tab) { |
| 130 if (!tab) | 130 if (!tab) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 gfx::NativeView widget = tab->web_contents()->GetNativeView(); | 133 gfx::NativeView widget = tab->web_contents()->GetNativeView(); |
| 134 if (widget) { | 134 if (widget) { |
| 135 if (gtk_widget_get_parent(widget) != expanded_) | 135 if (gtk_widget_get_parent(widget) != expanded_) |
| 136 gtk_container_add(GTK_CONTAINER(expanded_), widget); | 136 gtk_container_add(GTK_CONTAINER(expanded_), widget); |
| 137 gtk_widget_show(widget); | 137 gtk_widget_show(widget); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // We need to make sure that we are below the findbar. | 140 // We need to make sure that we are below the findbar. |
| 141 // Sometimes the content native view will be null. | 141 // Sometimes the content native view will be null. |
| 142 if (tab->web_contents()->GetContentNativeView()) { | 142 if (tab->web_contents()->GetContentNativeView()) { |
| 143 GdkWindow* content_gdk_window = gtk_widget_get_window( | 143 GdkWindow* content_gdk_window = gtk_widget_get_window( |
| 144 tab->web_contents()->GetContentNativeView()); | 144 tab->web_contents()->GetContentNativeView()); |
| 145 if (content_gdk_window) | 145 if (content_gdk_window) |
| 146 gdk_window_lower(content_gdk_window); | 146 gdk_window_lower(content_gdk_window); |
| 147 } | 147 } |
| 148 | 148 |
| 149 tab->web_contents()->ShowContents(); | 149 tab->web_contents()->ShowContents(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void TabContentsContainerGtk::HideTab(TabContentsWrapper* tab) { | 152 void TabContentsContainerGtk::HideTab(TabContents* tab) { |
| 153 if (!tab) | 153 if (!tab) |
| 154 return; | 154 return; |
| 155 | 155 |
| 156 gfx::NativeView widget = tab->web_contents()->GetNativeView(); | 156 gfx::NativeView widget = tab->web_contents()->GetNativeView(); |
| 157 if (widget) | 157 if (widget) |
| 158 gtk_widget_hide(widget); | 158 gtk_widget_hide(widget); |
| 159 | 159 |
| 160 tab->web_contents()->WasHidden(); | 160 tab->web_contents()->WasHidden(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void TabContentsContainerGtk::DetachTab(TabContentsWrapper* tab) { | 163 void TabContentsContainerGtk::DetachTab(TabContents* tab) { |
| 164 gfx::NativeView widget = tab->web_contents()->GetNativeView(); | 164 gfx::NativeView widget = tab->web_contents()->GetNativeView(); |
| 165 | 165 |
| 166 // It is possible to detach an unrealized, unparented WebContents if you | 166 // It is possible to detach an unrealized, unparented WebContents if you |
| 167 // slow things down enough in valgrind. Might happen in the real world, too. | 167 // slow things down enough in valgrind. Might happen in the real world, too. |
| 168 if (widget) { | 168 if (widget) { |
| 169 GtkWidget* parent = gtk_widget_get_parent(widget); | 169 GtkWidget* parent = gtk_widget_get_parent(widget); |
| 170 if (parent) { | 170 if (parent) { |
| 171 DCHECK_EQ(parent, expanded_); | 171 DCHECK_EQ(parent, expanded_); |
| 172 gtk_container_remove(GTK_CONTAINER(expanded_), widget); | 172 gtk_container_remove(GTK_CONTAINER(expanded_), widget); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 void TabContentsContainerGtk::Observe( | 177 void TabContentsContainerGtk::Observe( |
| 178 int type, | 178 int type, |
| 179 const content::NotificationSource& source, | 179 const content::NotificationSource& source, |
| 180 const content::NotificationDetails& details) { | 180 const content::NotificationDetails& details) { |
| 181 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, type); | 181 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, type); |
| 182 WebContentsDestroyed( | 182 WebContentsDestroyed( |
| 183 content::Source<TabContentsWrapper>(source)->web_contents()); | 183 content::Source<TabContents>(source)->web_contents()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void TabContentsContainerGtk::WebContentsDestroyed(WebContents* contents) { | 186 void TabContentsContainerGtk::WebContentsDestroyed(WebContents* contents) { |
| 187 // Sometimes, a WebContents is destroyed before we know about it. This allows | 187 // Sometimes, a WebContents is destroyed before we know about it. This allows |
| 188 // us to clean up our state in case this happens. | 188 // us to clean up our state in case this happens. |
| 189 if (preview_ && contents == preview_->web_contents()) | 189 if (preview_ && contents == preview_->web_contents()) |
| 190 PopPreview(); | 190 PopPreview(); |
| 191 else if (tab_ && contents == tab_->web_contents()) | 191 else if (tab_ && contents == tab_->web_contents()) |
| 192 SetTab(NULL); | 192 SetTab(NULL); |
| 193 else | 193 else |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 g_value_set_int(&value, allocation->width - requisition.width); | 241 g_value_set_int(&value, allocation->width - requisition.width); |
| 242 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 242 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 243 status->widget(), "x", &value); | 243 status->widget(), "x", &value); |
| 244 | 244 |
| 245 int child_y = std::max(allocation->height - requisition.height, 0); | 245 int child_y = std::max(allocation->height - requisition.height, 0); |
| 246 g_value_set_int(&value, child_y + status->y_offset()); | 246 g_value_set_int(&value, child_y + status->y_offset()); |
| 247 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 247 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 248 status->widget(), "y", &value); | 248 status->widget(), "y", &value); |
| 249 g_value_unset(&value); | 249 g_value_unset(&value); |
| 250 } | 250 } |
| OLD | NEW |