| 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 "app/gfx/native_widget_types.h" | 7 #include "app/gfx/native_widget_types.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "chrome/browser/gtk/gtk_expanded_container.h" | |
| 10 #include "chrome/browser/gtk/gtk_floating_container.h" | 9 #include "chrome/browser/gtk/gtk_floating_container.h" |
| 11 #include "chrome/browser/gtk/status_bubble_gtk.h" | 10 #include "chrome/browser/gtk/status_bubble_gtk.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 12 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
| 14 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 15 | 14 |
| 15 namespace { |
| 16 |
| 17 // Allocates all normal tab contents views to the size of the passed in |
| 18 // |allocation|. |
| 19 void ResizeChildren(GtkWidget* widget, void* param) { |
| 20 GtkAllocation* allocation = reinterpret_cast<GtkAllocation*>(param); |
| 21 if (!GTK_WIDGET_VISIBLE(widget)) |
| 22 return; |
| 23 |
| 24 if (widget->allocation.width != allocation->width || |
| 25 widget->allocation.height != allocation->height) { |
| 26 gtk_widget_set_size_request(widget, allocation->width, |
| 27 allocation->height); |
| 28 } |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 16 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) | 33 TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) |
| 17 : tab_contents_(NULL), | 34 : tab_contents_(NULL), |
| 18 status_bubble_(status_bubble) { | 35 status_bubble_(status_bubble) { |
| 19 Init(); | 36 Init(); |
| 20 } | 37 } |
| 21 | 38 |
| 22 TabContentsContainerGtk::~TabContentsContainerGtk() { | 39 TabContentsContainerGtk::~TabContentsContainerGtk() { |
| 23 floating_.Destroy(); | 40 floating_.Destroy(); |
| 24 } | 41 } |
| 25 | 42 |
| 26 void TabContentsContainerGtk::Init() { | 43 void TabContentsContainerGtk::Init() { |
| 27 // A high level overview of the TabContentsContainer: | 44 // A high level overview of the TabContentsContainer: |
| 28 // | 45 // |
| 29 // +- GtkFloatingContainer |floating_| -------------------------------+ | 46 // +- GtkFloatingContainer |floating_| -------------------------------+ |
| 30 // |+- GtkExpandedContainer |expanded_| -----------------------------+| | 47 // |+- GtkFixedContainer |fixed_| -----------------------------------+| |
| 31 // || || | 48 // || || |
| 32 // || || | 49 // || || |
| 33 // || || | 50 // || || |
| 34 // || || | 51 // || || |
| 35 // |+- (StatusBubble) ------+ || | 52 // |+- (StatusBubble) ------+ || |
| 36 // |+ + || | 53 // |+ + || |
| 37 // |+-----------------------+----------------------------------------+| | 54 // |+-----------------------+----------------------------------------+| |
| 38 // +------------------------------------------------------------------+ | 55 // +------------------------------------------------------------------+ |
| 39 | 56 |
| 40 floating_.Own(gtk_floating_container_new()); | 57 floating_.Own(gtk_floating_container_new()); |
| 41 gtk_widget_set_name(floating_.get(), "chrome-tab-contents-container"); | 58 gtk_widget_set_name(floating_.get(), "chrome-tab-contents-container"); |
| 42 | 59 |
| 43 expanded_ = gtk_expanded_container_new(); | 60 fixed_ = gtk_fixed_new(); |
| 44 gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_); | 61 g_signal_connect(fixed_, "size-allocate", |
| 62 G_CALLBACK(OnFixedSizeAllocate), this); |
| 63 gtk_container_add(GTK_CONTAINER(floating_.get()), fixed_); |
| 45 | 64 |
| 46 if (status_bubble_) { | 65 if (status_bubble_) { |
| 47 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()), | 66 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()), |
| 48 status_bubble_->widget()); | 67 status_bubble_->widget()); |
| 49 g_signal_connect(floating_.get(), "set-floating-position", | 68 g_signal_connect(floating_.get(), "set-floating-position", |
| 50 G_CALLBACK(OnSetFloatingPosition), this); | 69 G_CALLBACK(OnSetFloatingPosition), this); |
| 51 } | 70 } |
| 52 | 71 |
| 53 gtk_widget_show(expanded_); | 72 gtk_widget_show(fixed_); |
| 54 gtk_widget_show(floating_.get()); | 73 gtk_widget_show(floating_.get()); |
| 55 | 74 |
| 56 ViewIDUtil::SetDelegateForWidget(widget(), this); | 75 ViewIDUtil::SetDelegateForWidget(widget(), this); |
| 57 } | 76 } |
| 58 | 77 |
| 59 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { | 78 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { |
| 60 if (tab_contents_) { | 79 if (tab_contents_) { |
| 61 gfx::NativeView widget = tab_contents_->GetNativeView(); | 80 gfx::NativeView widget = tab_contents_->GetNativeView(); |
| 62 if (widget) | 81 if (widget) |
| 63 gtk_widget_hide(widget); | 82 gtk_widget_hide(widget); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 79 // is shown. I'm not entirely sure that we need to observe this event under | 98 // is shown. I'm not entirely sure that we need to observe this event under |
| 80 // GTK, but am putting a stub implementation and a comment saying that if | 99 // GTK, but am putting a stub implementation and a comment saying that if |
| 81 // we crash after that NOTIMPLEMENTED(), we'll need it. | 100 // we crash after that NOTIMPLEMENTED(), we'll need it. |
| 82 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_CHANGED, | 101 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_CHANGED, |
| 83 Source<NavigationController>(&tab_contents_->controller())); | 102 Source<NavigationController>(&tab_contents_->controller())); |
| 84 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, | 103 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, |
| 85 Source<TabContents>(tab_contents_)); | 104 Source<TabContents>(tab_contents_)); |
| 86 | 105 |
| 87 gfx::NativeView widget = tab_contents_->GetNativeView(); | 106 gfx::NativeView widget = tab_contents_->GetNativeView(); |
| 88 if (widget) { | 107 if (widget) { |
| 89 if (widget->parent != expanded_) | 108 if (widget->parent != fixed_) |
| 90 gtk_container_add(GTK_CONTAINER(expanded_), widget); | 109 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); |
| 91 gtk_widget_show(widget); | 110 gtk_widget_show(widget); |
| 92 } | 111 } |
| 93 | 112 |
| 94 // We need to make sure that we are below the findbar. | 113 // We need to make sure that we are below the findbar. |
| 95 // Sometimes the content native view will be null. | 114 // Sometimes the content native view will be null. |
| 96 // TODO(estade): will this case ever cause findbar occlusion problems? | 115 // TODO(estade): will this case ever cause findbar occlusion problems? |
| 97 if (tab_contents_->GetContentNativeView()) { | 116 if (tab_contents_->GetContentNativeView()) { |
| 98 GdkWindow* content_gdk_window = | 117 GdkWindow* content_gdk_window = |
| 99 tab_contents_->GetContentNativeView()->window; | 118 tab_contents_->GetContentNativeView()->window; |
| 100 if (content_gdk_window) | 119 if (content_gdk_window) |
| 101 gdk_window_lower(content_gdk_window); | 120 gdk_window_lower(content_gdk_window); |
| 102 } | 121 } |
| 103 } | 122 } |
| 104 } | 123 } |
| 105 | 124 |
| 106 void TabContentsContainerGtk::DetachTabContents(TabContents* tab_contents) { | 125 void TabContentsContainerGtk::DetachTabContents(TabContents* tab_contents) { |
| 107 gfx::NativeView widget = tab_contents->GetNativeView(); | 126 gfx::NativeView widget = tab_contents->GetNativeView(); |
| 108 // It is possible to detach an unrealized, unparented TabContents if you | 127 // It is possible to detach an unrealized, unparented TabContents if you |
| 109 // slow things down enough in valgrind. Might happen in the real world, too. | 128 // slow things down enough in valgrind. Might happen in the real world, too. |
| 110 if (widget && widget->parent) { | 129 if (widget && widget->parent) { |
| 111 DCHECK_EQ(widget->parent, expanded_); | 130 DCHECK_EQ(widget->parent, fixed_); |
| 112 gtk_container_remove(GTK_CONTAINER(expanded_), widget); | 131 gtk_container_remove(GTK_CONTAINER(fixed_), widget); |
| 113 } | 132 } |
| 114 } | 133 } |
| 115 | 134 |
| 116 void TabContentsContainerGtk::Observe(NotificationType type, | 135 void TabContentsContainerGtk::Observe(NotificationType type, |
| 117 const NotificationSource& source, | 136 const NotificationSource& source, |
| 118 const NotificationDetails& details) { | 137 const NotificationDetails& details) { |
| 119 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { | 138 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { |
| 120 RenderViewHostSwitchedDetails* switched_details = | 139 RenderViewHostSwitchedDetails* switched_details = |
| 121 Details<RenderViewHostSwitchedDetails>(details).ptr(); | 140 Details<RenderViewHostSwitchedDetails>(details).ptr(); |
| 122 RenderViewHostChanged(switched_details->old_host, | 141 RenderViewHostChanged(switched_details->old_host, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 150 view_id == VIEW_ID_TAB_CONTAINER_FOCUS_VIEW) { | 169 view_id == VIEW_ID_TAB_CONTAINER_FOCUS_VIEW) { |
| 151 return widget(); | 170 return widget(); |
| 152 } | 171 } |
| 153 | 172 |
| 154 return NULL; | 173 return NULL; |
| 155 } | 174 } |
| 156 | 175 |
| 157 // ----------------------------------------------------------------------------- | 176 // ----------------------------------------------------------------------------- |
| 158 | 177 |
| 159 // static | 178 // static |
| 179 void TabContentsContainerGtk::OnFixedSizeAllocate( |
| 180 GtkWidget* fixed, |
| 181 GtkAllocation* allocation, |
| 182 TabContentsContainerGtk* container) { |
| 183 // Set all the tab contents GtkWidgets to the size of the allocation. |
| 184 gtk_container_foreach(GTK_CONTAINER(fixed), ResizeChildren, allocation); |
| 185 } |
| 186 |
| 187 // static |
| 160 void TabContentsContainerGtk::OnSetFloatingPosition( | 188 void TabContentsContainerGtk::OnSetFloatingPosition( |
| 161 GtkFloatingContainer* floating_container, GtkAllocation* allocation, | 189 GtkFloatingContainer* floating_container, GtkAllocation* allocation, |
| 162 TabContentsContainerGtk* tab_contents_container) { | 190 TabContentsContainerGtk* tab_contents_container) { |
| 163 StatusBubbleGtk* status = tab_contents_container->status_bubble_; | 191 StatusBubbleGtk* status = tab_contents_container->status_bubble_; |
| 164 | 192 |
| 165 // Look at the size request of the status bubble and tell the | 193 // Look at the size request of the status bubble and tell the |
| 166 // GtkFloatingContainer where we want it positioned. | 194 // GtkFloatingContainer where we want it positioned. |
| 167 GtkRequisition requisition; | 195 GtkRequisition requisition; |
| 168 gtk_widget_size_request(status->widget(), &requisition); | 196 gtk_widget_size_request(status->widget(), &requisition); |
| 169 | 197 |
| 170 bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); | 198 bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT); |
| 171 | 199 |
| 172 GValue value = { 0, }; | 200 GValue value = { 0, }; |
| 173 g_value_init(&value, G_TYPE_INT); | 201 g_value_init(&value, G_TYPE_INT); |
| 174 if (ltr ^ status->flip_horizontally()) // Is it on the left? | 202 if (ltr ^ status->flip_horizontally()) // Is it on the left? |
| 175 g_value_set_int(&value, 0); | 203 g_value_set_int(&value, 0); |
| 176 else | 204 else |
| 177 g_value_set_int(&value, allocation->width - requisition.width); | 205 g_value_set_int(&value, allocation->width - requisition.width); |
| 178 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 206 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 179 status->widget(), "x", &value); | 207 status->widget(), "x", &value); |
| 180 | 208 |
| 181 int child_y = std::max( | 209 int child_y = std::max( |
| 182 allocation->y + allocation->height - requisition.height, 0); | 210 allocation->y + allocation->height - requisition.height, 0); |
| 183 g_value_set_int(&value, child_y + status->y_offset()); | 211 g_value_set_int(&value, child_y + status->y_offset()); |
| 184 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 212 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 185 status->widget(), "y", &value); | 213 status->widget(), "y", &value); |
| 186 g_value_unset(&value); | 214 g_value_unset(&value); |
| 187 } | 215 } |
| OLD | NEW |