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/gtk/find_bar_gtk.h" |
8 #include "chrome/browser/tab_contents/web_contents.h" | 9 #include "chrome/browser/tab_contents/web_contents.h" |
9 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 10 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
10 #include "chrome/common/notification_service.h" | 11 #include "chrome/common/notification_service.h" |
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 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_); | 16 gtk_widget_show_all(vbox_); |
21 g_signal_connect(fixed_, "size-allocate", | |
22 G_CALLBACK(OnSizeAllocate), this); | |
23 } | 17 } |
24 | 18 |
25 TabContentsContainerGtk::~TabContentsContainerGtk() { | 19 TabContentsContainerGtk::~TabContentsContainerGtk() { |
26 if (tab_contents_) | 20 if (tab_contents_) |
27 RemoveObservers(); | 21 RemoveObservers(); |
28 } | 22 } |
29 | 23 |
30 void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) { | 24 void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) { |
31 gtk_box_pack_start(GTK_BOX(box), vbox_, TRUE, TRUE, 0); | 25 gtk_box_pack_start(GTK_BOX(box), vbox_, TRUE, TRUE, 0); |
32 } | 26 } |
33 | 27 |
34 void TabContentsContainerGtk::AddFindBar(GtkWidget* findbar) { | |
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); | |
38 } | |
39 | |
40 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { | 28 void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { |
41 if (tab_contents_) { | 29 if (tab_contents_) { |
42 gfx::NativeView widget = tab_contents_->GetNativeView(); | 30 gfx::NativeView widget = tab_contents_->GetNativeView(); |
43 if (widget) | 31 if (widget) |
44 gtk_container_remove(GTK_CONTAINER(vbox_), widget); | 32 gtk_container_remove(GTK_CONTAINER(vbox_), widget); |
45 | 33 |
46 tab_contents_->WasHidden(); | 34 tab_contents_->WasHidden(); |
47 | 35 |
48 RemoveObservers(); | 36 RemoveObservers(); |
49 } | 37 } |
50 | 38 |
51 tab_contents_ = tab_contents; | 39 tab_contents_ = tab_contents; |
52 | 40 |
53 // When detaching the last tab of the browser SetTabContents is invoked | 41 // When detaching the last tab of the browser SetTabContents is invoked |
54 // with NULL. Don't attempt to do anything in that case. | 42 // with NULL. Don't attempt to do anything in that case. |
55 if (tab_contents_) { | 43 if (tab_contents_) { |
56 AddObservers(); | 44 AddObservers(); |
57 | 45 |
58 gfx::NativeView widget = tab_contents_->GetNativeView(); | 46 gfx::NativeView widget = tab_contents_->GetNativeView(); |
59 if (widget) { | 47 if (widget) { |
60 gtk_box_pack_end(GTK_BOX(vbox_), widget, TRUE, TRUE, 0); | 48 gtk_box_pack_end(GTK_BOX(vbox_), widget, TRUE, TRUE, 0); |
61 gtk_widget_show_all(widget); | 49 gtk_widget_show_all(widget); |
62 } | 50 } |
| 51 // We need to make sure that the find bar is on top before any painting |
| 52 // is done. |
| 53 if (tab_contents_->find_ui_active()) |
| 54 findbar_->AssureOnTop(); |
63 } | 55 } |
64 } | 56 } |
65 | 57 |
66 void TabContentsContainerGtk::Observe(NotificationType type, | 58 void TabContentsContainerGtk::Observe(NotificationType type, |
67 const NotificationSource& source, | 59 const NotificationSource& source, |
68 const NotificationDetails& details) { | 60 const NotificationDetails& details) { |
69 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { | 61 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { |
70 RenderViewHostSwitchedDetails* switched_details = | 62 RenderViewHostSwitchedDetails* switched_details = |
71 Details<RenderViewHostSwitchedDetails>(details).ptr(); | 63 Details<RenderViewHostSwitchedDetails>(details).ptr(); |
72 RenderViewHostChanged(switched_details->old_host, | 64 RenderViewHostChanged(switched_details->old_host, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // RENDER_VIEW_HOST_CHANGED notification. This was used on Windows for focus | 107 // RENDER_VIEW_HOST_CHANGED notification. This was used on Windows for focus |
116 // issues, and I'm not entirely convinced that this isn't necessary. | 108 // issues, and I'm not entirely convinced that this isn't necessary. |
117 } | 109 } |
118 | 110 |
119 void TabContentsContainerGtk::TabContentsDestroyed(TabContents* contents) { | 111 void TabContentsContainerGtk::TabContentsDestroyed(TabContents* contents) { |
120 // Sometimes, a TabContents is destroyed before we know about it. This allows | 112 // Sometimes, a TabContents is destroyed before we know about it. This allows |
121 // us to clean up our state in case this happens. | 113 // us to clean up our state in case this happens. |
122 DCHECK(contents == tab_contents_); | 114 DCHECK(contents == tab_contents_); |
123 SetTabContents(NULL); | 115 SetTabContents(NULL); |
124 } | 116 } |
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 |