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 |
11 namespace { | 11 namespace { |
12 | 12 |
13 enum { | 13 enum { |
14 PROP_0, | 14 PROP_0, |
15 PROP_HIDE_CHILD_DIRECTLY | 15 PROP_HIDE_CHILD_DIRECTLY |
16 }; | 16 }; |
17 | 17 |
18 struct SizeAllocateData { | 18 struct SizeAllocateData { |
19 GtkChromeShrinkableHBox* box; | 19 GtkChromeShrinkableHBox* box; |
20 GtkAllocation* allocation; | 20 GtkAllocation* allocation; |
21 GtkTextDirection direction; | 21 GtkTextDirection direction; |
22 bool homogeneous; | 22 bool homogeneous; |
23 int border_width; | 23 int border_width; |
24 | 24 |
25 // Maximum child width when |homogeneous| is TRUE. | 25 // Maximum child width when |homogeneous| is TRUE. |
26 int homogeneous_child_width; | 26 int homogeneous_child_width; |
27 }; | 27 }; |
28 | 28 |
29 void CountVisibleChildren(GtkWidget* child, gpointer userdata) { | 29 void CountVisibleChildren(GtkWidget* child, gpointer userdata) { |
30 if (GTK_WIDGET_VISIBLE(child)) | 30 if (gtk_widget_get_visible(child)) |
31 ++(*reinterpret_cast<int*>(userdata)); | 31 ++(*reinterpret_cast<int*>(userdata)); |
32 } | 32 } |
33 | 33 |
34 void SumChildrenWidthRequisition(GtkWidget* child, gpointer userdata) { | 34 void SumChildrenWidthRequisition(GtkWidget* child, gpointer userdata) { |
35 if (GTK_WIDGET_VISIBLE(child)) { | 35 if (gtk_widget_get_visible(child)) { |
36 GtkRequisition req; | 36 GtkRequisition req; |
37 gtk_widget_get_child_requisition(child, &req); | 37 gtk_widget_get_child_requisition(child, &req); |
38 (*reinterpret_cast<int*>(userdata)) += std::max(req.width, 0); | 38 (*reinterpret_cast<int*>(userdata)) += std::max(req.width, 0); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 void ShowInvisibleChildren(GtkWidget* child, gpointer userdata) { | 42 void ShowInvisibleChildren(GtkWidget* child, gpointer userdata) { |
43 if (!GTK_WIDGET_VISIBLE(child)) { | 43 if (!gtk_widget_get_visible(child)) { |
44 gtk_widget_show(child); | 44 gtk_widget_show(child); |
45 ++(*reinterpret_cast<int*>(userdata)); | 45 ++(*reinterpret_cast<int*>(userdata)); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 void ChildSizeAllocate(GtkWidget* child, gpointer userdata) { | 49 void ChildSizeAllocate(GtkWidget* child, gpointer userdata) { |
50 if (!GTK_WIDGET_VISIBLE(child)) | 50 if (!gtk_widget_get_visible(child)) |
51 return; | 51 return; |
52 | 52 |
53 SizeAllocateData* data = reinterpret_cast<SizeAllocateData*>(userdata); | 53 SizeAllocateData* data = reinterpret_cast<SizeAllocateData*>(userdata); |
54 GtkAllocation child_allocation = child->allocation; | 54 GtkAllocation child_allocation = child->allocation; |
55 | 55 |
56 if (data->homogeneous) { | 56 if (data->homogeneous) { |
57 // Make sure the child is not overlapped with others' boundary. | 57 // Make sure the child is not overlapped with others' boundary. |
58 if (child_allocation.width > data->homogeneous_child_width) { | 58 if (child_allocation.width > data->homogeneous_child_width) { |
59 child_allocation.x += | 59 child_allocation.x += |
60 (child_allocation.width - data->homogeneous_child_width) / 2; | 60 (child_allocation.width - data->homogeneous_child_width) / 2; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 274 |
275 gint gtk_chrome_shrinkable_hbox_get_visible_child_count( | 275 gint gtk_chrome_shrinkable_hbox_get_visible_child_count( |
276 GtkChromeShrinkableHBox* box) { | 276 GtkChromeShrinkableHBox* box) { |
277 gint visible_children_count = 0; | 277 gint visible_children_count = 0; |
278 gtk_container_foreach(GTK_CONTAINER(box), CountVisibleChildren, | 278 gtk_container_foreach(GTK_CONTAINER(box), CountVisibleChildren, |
279 &visible_children_count); | 279 &visible_children_count); |
280 return visible_children_count; | 280 return visible_children_count; |
281 } | 281 } |
282 | 282 |
283 G_END_DECLS | 283 G_END_DECLS |
OLD | NEW |