| 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/web_contents.h" | 8 #include "chrome/browser/tab_contents/web_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" |
| 11 | 11 |
| 12 | 12 |
| 13 TabContentsContainerGtk::TabContentsContainerGtk() | 13 TabContentsContainerGtk::TabContentsContainerGtk() |
| 14 : tab_contents_(NULL), | 14 : tab_contents_(NULL), |
| 15 vbox_(gtk_vbox_new(FALSE, 0)) { | 15 vbox_(gtk_vbox_new(FALSE, 0)), |
| 16 gtk_widget_show(vbox_); | 16 fixed_(gtk_fixed_new()), |
| 17 findbar_(NULL) { |
| 18 gtk_widget_set_size_request(fixed_, -1, 0); |
| 19 gtk_box_pack_start(GTK_BOX(vbox_), fixed_, FALSE, FALSE, 0); |
| 20 gtk_widget_show_all(vbox_); |
| 21 g_signal_connect(fixed_, "size-allocate", |
| 22 G_CALLBACK(OnSizeAllocate), this); |
| 17 } | 23 } |
| 18 | 24 |
| 19 TabContentsContainerGtk::~TabContentsContainerGtk() { | 25 TabContentsContainerGtk::~TabContentsContainerGtk() { |
| 20 if (tab_contents_) | 26 if (tab_contents_) |
| 21 RemoveObservers(); | 27 RemoveObservers(); |
| 22 } | 28 } |
| 23 | 29 |
| 24 void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) { | 30 void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) { |
| 25 gtk_box_pack_start(GTK_BOX(box), vbox_, TRUE, TRUE, 0); | 31 gtk_box_pack_start(GTK_BOX(box), vbox_, TRUE, TRUE, 0); |
| 26 } | 32 } |
| 27 | 33 |
| 28 void TabContentsContainerGtk::AddFindBar(GtkWidget* findbar) { | 34 void TabContentsContainerGtk::AddFindBar(GtkWidget* findbar) { |
| 29 gtk_box_pack_start(GTK_BOX(vbox_), findbar, FALSE, FALSE, 0); | 35 findbar_ = findbar; |
| 36 // We will reposition it later (when we get a size-allocate event). |
| 37 gtk_fixed_put(GTK_FIXED(fixed_), findbar, 0, 0); |
| 30 } | 38 } |
| 31 | 39 |
| 32 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { | 40 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { |
| 33 if (tab_contents_) { | 41 if (tab_contents_) { |
| 34 gfx::NativeView widget = tab_contents_->GetNativeView(); | 42 gfx::NativeView widget = tab_contents_->GetNativeView(); |
| 35 if (widget) | 43 if (widget) |
| 36 gtk_container_remove(GTK_CONTAINER(vbox_), widget); | 44 gtk_container_remove(GTK_CONTAINER(vbox_), widget); |
| 37 | 45 |
| 38 tab_contents_->WasHidden(); | 46 tab_contents_->WasHidden(); |
| 39 | 47 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // RENDER_VIEW_HOST_CHANGED notification. This was used on Windows for focus | 115 // RENDER_VIEW_HOST_CHANGED notification. This was used on Windows for focus |
| 108 // issues, and I'm not entirely convinced that this isn't necessary. | 116 // issues, and I'm not entirely convinced that this isn't necessary. |
| 109 } | 117 } |
| 110 | 118 |
| 111 void TabContentsContainerGtk::TabContentsDestroyed(TabContents* contents) { | 119 void TabContentsContainerGtk::TabContentsDestroyed(TabContents* contents) { |
| 112 // Sometimes, a TabContents is destroyed before we know about it. This allows | 120 // Sometimes, a TabContents is destroyed before we know about it. This allows |
| 113 // us to clean up our state in case this happens. | 121 // us to clean up our state in case this happens. |
| 114 DCHECK(contents == tab_contents_); | 122 DCHECK(contents == tab_contents_); |
| 115 SetTabContents(NULL); | 123 SetTabContents(NULL); |
| 116 } | 124 } |
| 125 |
| 126 void TabContentsContainerGtk::OnSizeAllocate(GtkWidget* fixed, |
| 127 GtkAllocation* allocation, TabContentsContainerGtk* contents_container) { |
| 128 GtkWidget* findbar = contents_container->findbar_; |
| 129 DCHECK(findbar); |
| 130 if (!GTK_WIDGET_VISIBLE(findbar)) |
| 131 return; |
| 132 |
| 133 // TODO(port): Logic for the positioning of the find bar should be factored |
| 134 // out of here and browser/views/* and into FindBarController. |
| 135 int xposition = allocation->width - findbar->allocation.width - 50; |
| 136 if (xposition == findbar->allocation.x) { |
| 137 return; |
| 138 } else { |
| 139 gtk_fixed_move(GTK_FIXED(fixed), findbar, xposition, 0); |
| 140 } |
| 141 } |
| OLD | NEW |