| 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 "content/public/browser/web_contents_view.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 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) | 20 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) |
| 21 : tab_(NULL), | 21 : tab_(NULL), |
| 22 preview_(NULL), | 22 overlay_(NULL), |
| 23 status_bubble_(status_bubble) { | 23 status_bubble_(status_bubble) { |
| 24 Init(); | 24 Init(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 TabContentsContainerGtk::~TabContentsContainerGtk() { | 27 TabContentsContainerGtk::~TabContentsContainerGtk() { |
| 28 floating_.Destroy(); | 28 floating_.Destroy(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void TabContentsContainerGtk::Init() { | 31 void TabContentsContainerGtk::Init() { |
| 32 // A high level overview of the TabContentsContainer: | 32 // A high level overview of the TabContentsContainer: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 void TabContentsContainerGtk::SetTab(content::WebContents* tab) { | 65 void TabContentsContainerGtk::SetTab(content::WebContents* tab) { |
| 66 if (tab_ == tab) | 66 if (tab_ == tab) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 if (tab_) | 69 if (tab_) |
| 70 HideTab(tab_); | 70 HideTab(tab_); |
| 71 | 71 |
| 72 tab_ = tab; | 72 tab_ = tab; |
| 73 | 73 |
| 74 if (tab_) { | 74 if (tab_) { |
| 75 // If the preview is becoming the new permanent tab, we just reassign some | 75 // If the overlay is becoming the new permanent tab, we just reassign some |
| 76 // 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. |
| 77 if (tab_ == preview_) | 77 if (tab_ == overlay_) |
| 78 preview_ = NULL; | 78 overlay_ = NULL; |
| 79 else | 79 else |
| 80 PackTab(tab_); | 80 PackTab(tab_); |
| 81 | 81 |
| 82 // 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 |
| 83 // native view will be null. | 83 // native view will be null. |
| 84 GtkWidget* widget = tab_->GetView()->GetContentNativeView(); | 84 GtkWidget* widget = tab_->GetView()->GetContentNativeView(); |
| 85 if (widget) { | 85 if (widget) { |
| 86 GdkWindow* content_gdk_window = gtk_widget_get_window(widget); | 86 GdkWindow* content_gdk_window = gtk_widget_get_window(widget); |
| 87 if (content_gdk_window) | 87 if (content_gdk_window) |
| 88 gdk_window_lower(content_gdk_window); | 88 gdk_window_lower(content_gdk_window); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 void TabContentsContainerGtk::SetPreview(content::WebContents* preview) { | 93 void TabContentsContainerGtk::SetOverlay(content::WebContents* overlay) { |
| 94 if (preview_ == preview) | 94 if (overlay_ == overlay) |
| 95 return; | 95 return; |
| 96 | 96 |
| 97 if (preview_) { | 97 if (overlay_) { |
| 98 HideTab(preview_); | 98 HideTab(overlay_); |
| 99 GtkWidget* preview_widget = preview_->GetView()->GetNativeView(); | 99 GtkWidget* overlay_widget = overlay_->GetView()->GetNativeView(); |
| 100 if (preview_widget) | 100 if (overlay_widget) |
| 101 gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); | 101 gtk_container_remove(GTK_CONTAINER(expanded_), overlay_widget); |
| 102 } | 102 } |
| 103 | 103 |
| 104 preview_ = preview; | 104 overlay_ = overlay; |
| 105 | 105 |
| 106 if (preview_) | 106 if (overlay_) |
| 107 PackTab(preview_); | 107 PackTab(overlay_); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void TabContentsContainerGtk::PackTab(content::WebContents* tab) { | 110 void TabContentsContainerGtk::PackTab(content::WebContents* tab) { |
| 111 gfx::NativeView widget = tab->GetView()->GetNativeView(); | 111 gfx::NativeView widget = tab->GetView()->GetNativeView(); |
| 112 if (widget) { | 112 if (widget) { |
| 113 if (gtk_widget_get_parent(widget) != expanded_) | 113 if (gtk_widget_get_parent(widget) != expanded_) |
| 114 gtk_container_add(GTK_CONTAINER(expanded_), widget); | 114 gtk_container_add(GTK_CONTAINER(expanded_), widget); |
| 115 gtk_widget_show(widget); | 115 gtk_widget_show(widget); |
| 116 } | 116 } |
| 117 | 117 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 const content::NotificationSource& source, | 149 const content::NotificationSource& source, |
| 150 const content::NotificationDetails& details) { | 150 const content::NotificationDetails& details) { |
| 151 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); | 151 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); |
| 152 WebContentsDestroyed(content::Source<content::WebContents>(source).ptr()); | 152 WebContentsDestroyed(content::Source<content::WebContents>(source).ptr()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void TabContentsContainerGtk::WebContentsDestroyed( | 155 void TabContentsContainerGtk::WebContentsDestroyed( |
| 156 content::WebContents* contents) { | 156 content::WebContents* contents) { |
| 157 // Sometimes, a WebContents is destroyed before we know about it. This allows | 157 // Sometimes, a WebContents is destroyed before we know about it. This allows |
| 158 // us to clean up our state in case this happens. | 158 // us to clean up our state in case this happens. |
| 159 if (contents == preview_) | 159 if (contents == overlay_) |
| 160 SetPreview(NULL); | 160 SetOverlay(NULL); |
| 161 else if (contents == tab_) | 161 else if (contents == tab_) |
| 162 SetTab(NULL); | 162 SetTab(NULL); |
| 163 else | 163 else |
| 164 NOTREACHED(); | 164 NOTREACHED(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Prevent |preview_| from getting focus via the tab key. If |tab_| exists, try | 167 // Prevent |overlay_| from getting focus via the tab key. If |tab_| exists, try |
| 168 // 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 |
| 169 // http://crbug.com/63365 | 169 // http://crbug.com/63365 |
| 170 gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget, | 170 gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget, |
| 171 GtkDirectionType focus) { | 171 GtkDirectionType focus) { |
| 172 if (preview_) { | 172 if (overlay_) { |
| 173 gtk_widget_child_focus(tab_->GetView()->GetContentNativeView(), focus); | 173 gtk_widget_child_focus(tab_->GetView()->GetContentNativeView(), focus); |
| 174 return TRUE; | 174 return TRUE; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // No preview contents; let the default handler run. | 177 // No overlay contents; let the default handler run. |
| 178 return FALSE; | 178 return FALSE; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // ----------------------------------------------------------------------------- | 181 // ----------------------------------------------------------------------------- |
| 182 // ViewIDUtil::Delegate implementation | 182 // ViewIDUtil::Delegate implementation |
| 183 | 183 |
| 184 GtkWidget* TabContentsContainerGtk::GetWidgetForViewID(ViewID view_id) { | 184 GtkWidget* TabContentsContainerGtk::GetWidgetForViewID(ViewID view_id) { |
| 185 if (view_id == VIEW_ID_TAB_CONTAINER) | 185 if (view_id == VIEW_ID_TAB_CONTAINER) |
| 186 return widget(); | 186 return widget(); |
| 187 | 187 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 211 g_value_set_int(&value, allocation->width - requisition.width); | 211 g_value_set_int(&value, allocation->width - requisition.width); |
| 212 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 212 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 213 status->widget(), "x", &value); | 213 status->widget(), "x", &value); |
| 214 | 214 |
| 215 int child_y = std::max(allocation->height - requisition.height, 0); | 215 int child_y = std::max(allocation->height - requisition.height, 0); |
| 216 g_value_set_int(&value, child_y + status->y_offset()); | 216 g_value_set_int(&value, child_y + status->y_offset()); |
| 217 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 217 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 218 status->widget(), "y", &value); | 218 status->widget(), "y", &value); |
| 219 g_value_unset(&value); | 219 g_value_unset(&value); |
| 220 } | 220 } |
| OLD | NEW |