diff options
author | robert.bradford@intel.com <robert.bradford@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 21:25:41 +0000 |
---|---|---|
committer | robert.bradford@intel.com <robert.bradford@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 21:25:41 +0000 |
commit | 6ca4dc81bd632c79de0da9ee0e426df3b0e8c0a4 (patch) | |
tree | 4179c4615a49438071894fd941e61ec7a59acf3d /ui/base/gtk | |
parent | 68837976876708372139edc8921eb55713f75ab4 (diff) | |
download | chromium_src-6ca4dc81bd632c79de0da9ee0e426df3b0e8c0a4.zip chromium_src-6ca4dc81bd632c79de0da9ee0e426df3b0e8c0a4.tar.gz chromium_src-6ca4dc81bd632c79de0da9ee0e426df3b0e8c0a4.tar.bz2 |
GTK: Port ui/base/gtk to use avoid deprecated API and accessors
New API used:
gtk_widget_{set,get}_has_window - added 2.18 - replaces !GTK_WIDGET_NO_WINDOW
gtk_widget_{set,get}_allocation - added 2.18 - replaces direct access
gtk_bin_get_child - replaces direct access
gtk_widget_get_window - added 2.14 - replaces direct access
g_cclosure_marshal_VOID__BOXED - replaces gtk_marshal_VOID__BOXED
With these changes this directory can compile with GSEAL enabled and
deprecated functions disabled.
BUG=79722
TEST=Compiles and also the ui_unittests pass
Review URL: http://codereview.chromium.org/8646002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/gtk')
-rw-r--r-- | ui/base/gtk/gtk_expanded_container.cc | 12 | ||||
-rw-r--r-- | ui/base/gtk/gtk_expanded_container_unittest.cc | 45 | ||||
-rw-r--r-- | ui/base/gtk/gtk_floating_container.cc | 19 | ||||
-rw-r--r-- | ui/base/gtk/tooltip_window_gtk.cc | 19 |
4 files changed, 51 insertions, 44 deletions
diff --git a/ui/base/gtk/gtk_expanded_container.cc b/ui/base/gtk/gtk_expanded_container.cc index bfc5a46..30fc3db 100644 --- a/ui/base/gtk/gtk_expanded_container.cc +++ b/ui/base/gtk/gtk_expanded_container.cc @@ -68,7 +68,7 @@ void ChildSizeAllocate(GtkWidget* child, gpointer userdata) { child_allocation.x = x + data->border_width; child_allocation.y = y + data->border_width; - if (GTK_WIDGET_NO_WINDOW(data->container)) { + if (!gtk_widget_get_has_window(data->container)) { child_allocation.x += data->allocation->x; child_allocation.y += data->allocation->y; } @@ -143,10 +143,10 @@ static void gtk_expanded_container_init(GtkExpandedContainer* container) { static void gtk_expanded_container_size_allocate(GtkWidget* widget, GtkAllocation* allocation) { - widget->allocation = *allocation; + gtk_widget_set_allocation(widget, allocation); - if (!GTK_WIDGET_NO_WINDOW(widget) && gtk_widget_get_realized(widget)) { - gdk_window_move_resize(widget->window, + if (gtk_widget_get_has_window(widget) && gtk_widget_get_realized(widget)) { + gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, @@ -183,13 +183,13 @@ void gtk_expanded_container_set_has_window(GtkExpandedContainer* container, gboolean has_window) { g_return_if_fail(GTK_IS_EXPANDED_CONTAINER(container)); g_return_if_fail(!gtk_widget_get_realized(GTK_WIDGET(container))); - gtk_fixed_set_has_window(GTK_FIXED(container), has_window); + gtk_widget_set_has_window(GTK_WIDGET(container), has_window); } gboolean gtk_expanded_container_get_has_window( GtkExpandedContainer* container) { g_return_val_if_fail(GTK_IS_EXPANDED_CONTAINER(container), FALSE); - return gtk_fixed_get_has_window(GTK_FIXED(container)); + return gtk_widget_get_has_window(GTK_WIDGET(container)); } G_END_DECLS diff --git a/ui/base/gtk/gtk_expanded_container_unittest.cc b/ui/base/gtk/gtk_expanded_container_unittest.cc index c8721a3..99bcad3 100644 --- a/ui/base/gtk/gtk_expanded_container_unittest.cc +++ b/ui/base/gtk/gtk_expanded_container_unittest.cc @@ -6,6 +6,23 @@ #include "testing/gtest/include/gtest/gtest.h" +#define EXPECT_ALLOCATION_EQ(widget, x_, y_, width_, height_) \ +do { \ + GtkAllocation allocation; \ + gtk_widget_get_allocation(widget, &allocation); \ + EXPECT_EQ(x_, allocation.x); \ + EXPECT_EQ(y_, allocation.y); \ + EXPECT_EQ(width_, allocation.width); \ + EXPECT_EQ(height_, allocation.height); \ +} while(0); + +#define EXPECT_ALLOCATION_PARAM_EQ(widget, param, value) \ +do { \ + GtkAllocation allocation; \ + gtk_widget_get_allocation(widget, &allocation); \ + EXPECT_EQ(value,allocation.param); \ +} while(0); + class GtkExpandedContainerTest : public testing::Test { protected: GtkExpandedContainerTest() @@ -78,24 +95,18 @@ TEST_F(GtkExpandedContainerTest, Expand) { GtkAllocation allocation = { 0, 0, 50, 100 }; gtk_widget_size_allocate(expanded_, &allocation); - EXPECT_EQ(0, child1->allocation.x); - EXPECT_EQ(0, child1->allocation.y); - EXPECT_EQ(50, child1->allocation.width); - EXPECT_EQ(100, child1->allocation.height); + EXPECT_ALLOCATION_EQ(child1, 0, 0, 50, 100); - EXPECT_EQ(10, child2->allocation.x); - EXPECT_EQ(20, child2->allocation.y); - EXPECT_EQ(50, child2->allocation.width); - EXPECT_EQ(100, child2->allocation.height); + EXPECT_ALLOCATION_EQ(child2, 10, 20, 50, 100); allocation.x = 10; allocation.y = 20; gtk_widget_size_allocate(expanded_, &allocation); - EXPECT_EQ(10, child1->allocation.x); - EXPECT_EQ(20, child1->allocation.y); - EXPECT_EQ(20, child2->allocation.x); - EXPECT_EQ(40, child2->allocation.y); + EXPECT_ALLOCATION_PARAM_EQ(child1, x, 10); + EXPECT_ALLOCATION_PARAM_EQ(child1, y, 20); + EXPECT_ALLOCATION_PARAM_EQ(child2, x, 20); + EXPECT_ALLOCATION_PARAM_EQ(child2, y, 40); } // Test if the size allocation for children still works when using own @@ -111,10 +122,7 @@ TEST_F(GtkExpandedContainerTest, HasWindow) { GtkAllocation allocation = { 10, 10, 50, 100 }; gtk_widget_size_allocate(expanded_, &allocation); - EXPECT_EQ(0, child->allocation.x); - EXPECT_EQ(0, child->allocation.y); - EXPECT_EQ(50, child->allocation.width); - EXPECT_EQ(100, child->allocation.height); + EXPECT_ALLOCATION_EQ(child, 0, 0, 50, 100); } static void OnChildSizeRequest(GtkExpandedContainer* container, @@ -137,10 +145,7 @@ TEST_F(GtkExpandedContainerTest, ChildSizeRequest) { GtkAllocation allocation = { 0, 0, 300, 100 }; gtk_widget_size_allocate(expanded_, &allocation); - EXPECT_EQ(0, child->allocation.x); - EXPECT_EQ(0, child->allocation.y); - EXPECT_EQ(250, child->allocation.width); - EXPECT_EQ(25, child->allocation.height); + EXPECT_ALLOCATION_EQ(child, 0, 0, 250, 25); } TEST_F(GtkExpandedContainerTest, ChildPosition) { diff --git a/ui/base/gtk/gtk_floating_container.cc b/ui/base/gtk/gtk_floating_container.cc index 08449e2..929216e 100644 --- a/ui/base/gtk/gtk_floating_container.cc +++ b/ui/base/gtk/gtk_floating_container.cc @@ -120,14 +120,13 @@ static void gtk_floating_container_class_init( G_SIGNAL_ACTION), 0, NULL, NULL, - gtk_marshal_VOID__BOXED, + g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE); } static void gtk_floating_container_init(GtkFloatingContainer* container) { - GTK_WIDGET_SET_FLAGS(container, GTK_NO_WINDOW); - + gtk_widget_set_has_window(GTK_WIDGET(container), FALSE); container->floating_children = NULL; } @@ -136,7 +135,7 @@ static void gtk_floating_container_remove(GtkContainer* container, g_return_if_fail(GTK_IS_WIDGET(widget)); GtkBin* bin = GTK_BIN(container); - if (bin->child == widget) { + if (gtk_bin_get_child(bin) == widget) { ((GTK_CONTAINER_CLASS(gtk_floating_container_parent_class))->remove) (container, widget); } else { @@ -196,8 +195,8 @@ static void gtk_floating_container_forall(GtkContainer* container, static void gtk_floating_container_size_request(GtkWidget* widget, GtkRequisition* requisition) { GtkBin* bin = GTK_BIN(widget); - if (bin && bin->child) { - gtk_widget_size_request(bin->child, requisition); + if (bin && gtk_bin_get_child(bin)) { + gtk_widget_size_request(gtk_bin_get_child(bin), requisition); } else { requisition->width = 0; requisition->height = 0; @@ -206,10 +205,10 @@ static void gtk_floating_container_size_request(GtkWidget* widget, static void gtk_floating_container_size_allocate(GtkWidget* widget, GtkAllocation* allocation) { - widget->allocation = *allocation; + gtk_widget_set_allocation(widget, allocation); if (gtk_widget_get_has_window(widget) && gtk_widget_get_realized(widget)) { - gdk_window_move_resize(widget->window, + gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, @@ -218,8 +217,8 @@ static void gtk_floating_container_size_allocate(GtkWidget* widget, // Give the same allocation to our GtkBin component. GtkBin* bin = GTK_BIN(widget); - if (bin->child) { - gtk_widget_size_allocate(bin->child, allocation); + if (gtk_bin_get_child(bin)) { + gtk_widget_size_allocate(gtk_bin_get_child(bin), allocation); } // We need to give whoever is pulling our strings a chance to set the "x" and diff --git a/ui/base/gtk/tooltip_window_gtk.cc b/ui/base/gtk/tooltip_window_gtk.cc index 0a5900f..2ef65ee 100644 --- a/ui/base/gtk/tooltip_window_gtk.cc +++ b/ui/base/gtk/tooltip_window_gtk.cc @@ -64,16 +64,18 @@ void TooltipWindowGtk::Init() { // Paints our customized tooltip window. gboolean TooltipWindowGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { - gtk_paint_flat_box(widget->style, - widget->window, + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); + gtk_paint_flat_box(gtk_widget_get_style(widget), + gtk_widget_get_window(widget), GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, widget, "tooltip", 0, 0, - widget->allocation.width, - widget->allocation.height); + allocation.width, + allocation.height); return FALSE; } @@ -81,11 +83,12 @@ gboolean TooltipWindowGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { // Style change handler. void TooltipWindowGtk::OnStyleSet(GtkWidget* widget, GtkStyle* previous_style) { + GtkStyle* style = gtk_widget_get_style(widget); gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_), - widget->style->ythickness, - widget->style->ythickness, - widget->style->xthickness, - widget->style->xthickness); + style->ythickness, + style->ythickness, + style->xthickness, + style->xthickness); gtk_widget_queue_draw(widget); } |