OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gtk_chrome_shrinkable_hbox.h" | 5 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } else { | 79 } else { |
80 // All children are left aligned, so make sure the child won't overflow | 80 // All children are left aligned, so make sure the child won't overflow |
81 // its parent's right edge. | 81 // its parent's right edge. |
82 int overflow = (child_allocation.x + child_allocation.width + padding - | 82 int overflow = (child_allocation.x + child_allocation.width + padding - |
83 (data->allocation->x + data->allocation->width - data->border_width)); | 83 (data->allocation->x + data->allocation->width - data->border_width)); |
84 if (overflow > 0) | 84 if (overflow > 0) |
85 child_allocation.width -= overflow; | 85 child_allocation.width -= overflow; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 if (child_allocation.width != child->allocation.width) { | 89 GtkAllocation current_allocation; |
| 90 gtk_widget_get_allocation(child, ¤t_allocation); |
| 91 |
| 92 if (child_allocation.width != current_allocation.width) { |
90 if (data->box->hide_child_directly || child_allocation.width <= 1) | 93 if (data->box->hide_child_directly || child_allocation.width <= 1) |
91 gtk_widget_hide(child); | 94 gtk_widget_hide(child); |
92 else | 95 else |
93 gtk_widget_size_allocate(child, &child_allocation); | 96 gtk_widget_size_allocate(child, &child_allocation); |
94 } | 97 } |
95 } | 98 } |
96 | 99 |
97 } // namespace | 100 } // namespace |
98 | 101 |
99 G_BEGIN_DECLS | 102 G_BEGIN_DECLS |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 173 } |
171 } | 174 } |
172 | 175 |
173 static void gtk_chrome_shrinkable_hbox_size_allocate( | 176 static void gtk_chrome_shrinkable_hbox_size_allocate( |
174 GtkWidget* widget, GtkAllocation* allocation) { | 177 GtkWidget* widget, GtkAllocation* allocation) { |
175 GtkChromeShrinkableHBox* box = GTK_CHROME_SHRINKABLE_HBOX(widget); | 178 GtkChromeShrinkableHBox* box = GTK_CHROME_SHRINKABLE_HBOX(widget); |
176 gint children_width_requisition = 0; | 179 gint children_width_requisition = 0; |
177 gtk_container_foreach(GTK_CONTAINER(widget), SumChildrenWidthRequisition, | 180 gtk_container_foreach(GTK_CONTAINER(widget), SumChildrenWidthRequisition, |
178 &children_width_requisition); | 181 &children_width_requisition); |
179 | 182 |
| 183 GtkAllocation widget_allocation; |
| 184 gtk_widget_get_allocation(widget, &widget_allocation); |
| 185 |
180 // If we are allocated to more width or some children are removed or shrunk, | 186 // If we are allocated to more width or some children are removed or shrunk, |
181 // then we need to show all invisible children before calling parent class's | 187 // then we need to show all invisible children before calling parent class's |
182 // size_allocate method, because the new width may be enough to show those | 188 // size_allocate method, because the new width may be enough to show those |
183 // hidden children. | 189 // hidden children. |
184 if (widget->allocation.width < allocation->width || | 190 if (widget_allocation.width < allocation->width || |
185 box->children_width_requisition > children_width_requisition) { | 191 box->children_width_requisition > children_width_requisition) { |
186 gtk_container_foreach(GTK_CONTAINER(widget), | 192 gtk_container_foreach(GTK_CONTAINER(widget), |
187 reinterpret_cast<GtkCallback>(gtk_widget_show), NULL); | 193 reinterpret_cast<GtkCallback>(gtk_widget_show), NULL); |
188 | 194 |
189 // If there were any invisible children, showing them will trigger another | 195 // If there were any invisible children, showing them will trigger another |
190 // allocate. But we still need to go through the size allocate process | 196 // allocate. But we still need to go through the size allocate process |
191 // in this iteration, otherwise before the next allocate iteration, the | 197 // in this iteration, otherwise before the next allocate iteration, the |
192 // children may be redrawn on the screen with incorrect size allocation. | 198 // children may be redrawn on the screen with incorrect size allocation. |
193 } | 199 } |
194 | 200 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 280 |
275 gint gtk_chrome_shrinkable_hbox_get_visible_child_count( | 281 gint gtk_chrome_shrinkable_hbox_get_visible_child_count( |
276 GtkChromeShrinkableHBox* box) { | 282 GtkChromeShrinkableHBox* box) { |
277 gint visible_children_count = 0; | 283 gint visible_children_count = 0; |
278 gtk_container_foreach(GTK_CONTAINER(box), CountVisibleChildren, | 284 gtk_container_foreach(GTK_CONTAINER(box), CountVisibleChildren, |
279 &visible_children_count); | 285 &visible_children_count); |
280 return visible_children_count; | 286 return visible_children_count; |
281 } | 287 } |
282 | 288 |
283 G_END_DECLS | 289 G_END_DECLS |
OLD | NEW |