[gtk] gtk: Check return value of compute_bounds()



commit 01f7f255b5a2bb6407825c0f5dc05ecfe5cffe88
Author: Benjamin Otte <otte redhat com>
Date:   Wed Feb 20 04:53:47 2019 +0100

    gtk: Check return value of compute_bounds()
    
    Half of these calls will completely break if anybody ever uses CSS
    transforms with them, but hey...

 gtk/gtkcontainer.c           |  3 ++-
 gtk/gtkentry.c               |  8 +++---
 gtk/gtkgesturestylus.c       | 20 +++++++++------
 gtk/gtklistbox.c             | 12 ++++++---
 gtk/gtkmenu.c                |  4 ++-
 gtk/gtknotebook.c            | 52 ++++++++++++++++++++------------------
 gtk/gtkpaned.c               |  3 ++-
 gtk/gtkpopover.c             |  8 +++---
 gtk/gtkrange.c               | 55 ++++++++++++++++++++++++----------------
 gtk/gtkscale.c               |  7 +++---
 gtk/gtkscrolledwindow.c      |  3 ++-
 gtk/gtkswitch.c              |  4 ++-
 gtk/gtktooltip.c             | 16 ++++++++----
 gtk/gtktreeviewcolumn.c      |  3 ++-
 gtk/gtkwidget.c              | 60 ++++++++++++++++++++++++++++----------------
 gtk/gtkwidgetfocus.c         | 16 +++++++-----
 gtk/gtkwidgetpaintable.c     | 19 +++++++++-----
 gtk/inspector/fpsoverlay.c   | 16 ++++++------
 tests/testwidgettransforms.c |  6 ++---
 19 files changed, 193 insertions(+), 122 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index f1ef23e8e4..4c6219ec8a 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -1653,7 +1653,8 @@ gtk_container_real_set_focus_child (GtkContainer *container,
                                                  0, 0, &x, &y))
             return;
 
-          gtk_widget_compute_bounds (child, child, &child_bounds);
+          if (!gtk_widget_compute_bounds (child, child, &child_bounds))
+            return;
 
           if (vadj)
             gtk_adjustment_clamp_page (vadj, y, y + child_bounds.size.height);
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 035b81d828..854410dddf 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -2889,18 +2889,16 @@ gtk_entry_get_icon_area (GtkEntry             *entry,
 {
   GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
   EntryIconInfo *icon_info;
+  graphene_rect_t r;
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (icon_area != NULL);
 
   icon_info = priv->icons[icon_pos];
 
-  if (icon_info)
+  if (icon_info &&
+      gtk_widget_compute_bounds (icon_info->widget, GTK_WIDGET (entry), &r))
     {
-      graphene_rect_t r;
-
-      gtk_widget_compute_bounds (icon_info->widget, GTK_WIDGET (entry), &r);
-
       *icon_area = (GdkRectangle){
         floorf (r.origin.x),
         floorf (r.origin.y),
diff --git a/gtk/gtkgesturestylus.c b/gtk/gtkgesturestylus.c
index 4c9d704f6d..2122f08e09 100644
--- a/gtk/gtkgesturestylus.c
+++ b/gtk/gtkgesturestylus.c
@@ -284,13 +284,19 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus  *gesture,
 
       g_array_append_val (backlog_array, *time_coord);
       time_coord = &g_array_index (backlog_array, GdkTimeCoord, backlog_array->len - 1);
-      gtk_widget_compute_point (gtk_get_event_widget (event),
-                                gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
-                                &GRAPHENE_POINT_INIT (time_coord->axes[GDK_AXIS_X],
-                                                      time_coord->axes[GDK_AXIS_Y]),
-                                &p);
-      time_coord->axes[GDK_AXIS_X] = p.x;
-      time_coord->axes[GDK_AXIS_Y] = p.y;
+      if (gtk_widget_compute_point (gtk_get_event_widget (event),
+                                    gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
+                                    &GRAPHENE_POINT_INIT (time_coord->axes[GDK_AXIS_X],
+                                                          time_coord->axes[GDK_AXIS_Y]),
+                                    &p))
+        {
+          time_coord->axes[GDK_AXIS_X] = p.x;
+          time_coord->axes[GDK_AXIS_Y] = p.y;
+        }
+      else
+        {
+          g_array_set_size (backlog_array, backlog_array->len - 1);
+        }
     }
 
   *n_elems = backlog_array->len;
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 274956d8f8..f6ccfb1931 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -1443,7 +1443,9 @@ ensure_row_visible (GtkListBox    *box,
   if (!priv->adjustment)
     return;
 
-  gtk_widget_compute_bounds (GTK_WIDGET (row), GTK_WIDGET (box), &rect);
+  if (!gtk_widget_compute_bounds (GTK_WIDGET (row), GTK_WIDGET (box), &rect))
+    return;
+
   y = rect.origin.y;
   height = rect.size.height;
 
@@ -1451,9 +1453,11 @@ ensure_row_visible (GtkListBox    *box,
   header = ROW_PRIV (row)->header;
   if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header))
     {
-      gtk_widget_compute_bounds (header, GTK_WIDGET (box), &rect);
-      y = rect.origin.y;
-      height += rect.size.height;
+      if (gtk_widget_compute_bounds (header, GTK_WIDGET (box), &rect))
+        {
+          y = rect.origin.y;
+          height += rect.size.height;
+        }
     }
 
   gtk_adjustment_clamp_page (priv->adjustment, y, y + height);
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index c12b19bcf3..247dd4f12e 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -2812,7 +2812,9 @@ definitely_within_item (GtkMenu   *menu,
   int w, h;
   graphene_rect_t bounds;
 
-  gtk_widget_compute_bounds (widget, GTK_WIDGET (menu), &bounds);
+  if (!gtk_widget_compute_bounds (widget, GTK_WIDGET (menu), &bounds))
+    return FALSE;
+
   w = bounds.size.width;
   h = bounds.size.height;
 
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index decf8c61cd..af69ab3000 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -1628,10 +1628,9 @@ gtk_notebook_get_tab_area_position (GtkNotebook     *notebook,
 
   if (priv->show_tabs && gtk_notebook_has_current_page (notebook))
     {
-      gtk_widget_compute_bounds (priv->header_widget,
-                                 GTK_WIDGET (notebook),
-                                 rectangle);
-      return TRUE;
+      return gtk_widget_compute_bounds (priv->header_widget,
+                                        GTK_WIDGET (notebook),
+                                        rectangle);
     }
   else
     {
@@ -2094,9 +2093,10 @@ gtk_notebook_get_arrow (GtkNotebook *notebook,
           if (priv->arrow_widget[i] == NULL)
             continue;
 
-          gtk_widget_compute_bounds (priv->arrow_widget[i],
-                                     GTK_WIDGET (notebook),
-                                     &arrow_bounds);
+          if (!gtk_widget_compute_bounds (priv->arrow_widget[i],
+                                          GTK_WIDGET (notebook),
+                                          &arrow_bounds))
+            continue;
 
           if (graphene_rect_contains_point (&arrow_bounds,
                                             &(graphene_point_t){x, y}))
@@ -2184,7 +2184,8 @@ in_tabs (GtkNotebook *notebook,
   GtkNotebookPrivate *priv = notebook->priv;
   graphene_rect_t tabs_bounds;
 
-  gtk_widget_compute_bounds (priv->tabs_widget, GTK_WIDGET (notebook), &tabs_bounds);
+  if (!gtk_widget_compute_bounds (priv->tabs_widget, GTK_WIDGET (notebook), &tabs_bounds))
+    return FALSE;
 
   return graphene_rect_contains_point (&tabs_bounds,
                                        &(graphene_point_t){x, y});
@@ -2208,8 +2209,8 @@ get_tab_at_pos (GtkNotebook *notebook,
       if (!gtk_notebook_page_tab_label_is_visible (page))
         continue;
 
-      gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &bounds);
-
+      if (!gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &bounds))
+        continue;
 
       if (graphene_rect_contains_point (&bounds, &(graphene_point_t){x, y}))
         return children;
@@ -2285,10 +2286,14 @@ gtk_notebook_gesture_pressed (GtkGestureMultiPress *gesture,
           priv->drag_begin_x = priv->mouse_x;
           priv->drag_begin_y = priv->mouse_y;
 
-          gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds);
-
-          priv->drag_offset_x = priv->drag_begin_x - tab_bounds.origin.x;
-          priv->drag_offset_y = priv->drag_begin_y - tab_bounds.origin.y;
+          /* tab bounds get set to empty, which is fine */
+          priv->drag_offset_x = priv->drag_begin_x;
+          priv->drag_offset_y = priv->drag_begin_y;
+          if (gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds))
+            {
+              priv->drag_offset_x -= tab_bounds.origin.x;
+              priv->drag_offset_y -= tab_bounds.origin.y;
+            }
         }
     }
 }
@@ -2373,10 +2378,9 @@ get_drop_position (GtkNotebook *notebook)
   y = priv->mouse_y;
 
   is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
-  children = priv->children;
   last_child = NULL;
 
-  while (children)
+  for (children = priv->children; children; children = children->next)
     {
       page = children->data;
 
@@ -2387,7 +2391,8 @@ get_drop_position (GtkNotebook *notebook)
         {
           graphene_rect_t tab_bounds;
 
-          gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds);
+          if (!gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds))
+            continue;
 
           switch (priv->tab_pos)
             {
@@ -2418,8 +2423,6 @@ get_drop_position (GtkNotebook *notebook)
 
           last_child = children->next;
         }
-
-      children = children->next;
     }
 
   return last_child;
@@ -2895,10 +2898,10 @@ gtk_notebook_drag_begin (GtkWidget        *widget,
   gtk_widget_unparent (tab_label);
 
   priv->dnd_child = tab_label;
-  gtk_widget_compute_bounds (priv->dnd_child, priv->dnd_child, &bounds);
-  gtk_widget_set_size_request (priv->dnd_child,
-                               ceilf (bounds.size.width),
-                               ceilf (bounds.size.height));
+  if (gtk_widget_compute_bounds (priv->dnd_child, priv->dnd_child, &bounds))
+    gtk_widget_set_size_request (priv->dnd_child,
+                                 ceilf (bounds.size.width),
+                                 ceilf (bounds.size.height));
 
   gtk_style_context_add_class (gtk_widget_get_style_context (priv->dnd_child), "background");
 
@@ -4933,7 +4936,8 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook          *notebook,
       break;
     }
 
-  gtk_widget_compute_bounds (priv->cur_page->tab_widget, priv->cur_page->tab_widget, &drag_bounds);
+  if (!gtk_widget_compute_bounds (priv->cur_page->tab_widget, priv->cur_page->tab_widget, &drag_bounds))
+    graphene_rect_init_from_rect (&drag_bounds, graphene_rect_zero ());
 
   left_x   = CLAMP (priv->mouse_x - priv->drag_offset_x,
                     allocation->x, allocation->x + allocation->width - drag_bounds.size.width);
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 2cd216657e..9fc18c9667 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -293,7 +293,8 @@ get_handle_area (GtkPaned        *paned,
   GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned);
   int extra = 0;
 
-  gtk_widget_compute_bounds (priv->handle_widget, GTK_WIDGET (paned), area);
+  if (!gtk_widget_compute_bounds (priv->handle_widget, GTK_WIDGET (paned), area))
+    return;
 
   if (!gtk_paned_get_wide_handle (paned))
     extra = HANDLE_EXTRA_SIZE;
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index 69336460b9..bec65410f0 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -338,9 +338,8 @@ gesture_released (GtkGestureMultiPress *gesture,
     return;
 
   child = gtk_bin_get_child (GTK_BIN (popover));
-  gtk_widget_compute_bounds (child, GTK_WIDGET (popover), &child_bounds);
-
-  if (!graphene_rect_contains_point (&child_bounds,
+  if (!gtk_widget_compute_bounds (child, GTK_WIDGET (popover), &child_bounds) ||
+      !graphene_rect_contains_point (&child_bounds,
                                      &(graphene_point_t){x, y}))
     gtk_popover_popdown (popover);
 }
@@ -2147,7 +2146,8 @@ gtk_popover_get_pointing_to (GtkPopover   *popover,
     {
       graphene_rect_t r;
 
-      gtk_widget_compute_bounds (priv->widget, priv->widget, &r);
+      if (!gtk_widget_compute_bounds (priv->widget, priv->widget, &r))
+        return FALSE;
 
       rect->x = floorf (r.origin.x);
       rect->y = floorf (r.origin.y);
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 7af7f80a2c..a26e882ec9 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -920,14 +920,19 @@ gtk_range_get_range_rect (GtkRange     *range,
   g_return_if_fail (GTK_IS_RANGE (range));
   g_return_if_fail (range_rect != NULL);
 
-  gtk_widget_compute_bounds (priv->trough_widget, GTK_WIDGET (range), &r);
-
-  *range_rect = (GdkRectangle) {
-    floorf (r.origin.x),
-    floorf (r.origin.y),
-    ceilf (r.size.width),
-    ceilf (r.size.height),
-  };
+  if (!gtk_widget_compute_bounds (priv->trough_widget, GTK_WIDGET (range), &r))
+    {
+      *range_rect = (GdkRectangle) { 0, 0, 0, 0 };
+    }
+  else
+    {
+      *range_rect = (GdkRectangle) {
+        floorf (r.origin.x),
+        floorf (r.origin.y),
+        ceilf (r.size.width),
+        ceilf (r.size.height),
+      };
+    }
 }
 
 /**
@@ -953,7 +958,14 @@ gtk_range_get_slider_range (GtkRange *range,
 
   g_return_if_fail (GTK_IS_RANGE (range));
 
-  gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds);
+  if (!gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds))
+    {
+      if (slider_start)
+        *slider_start = 0;
+      if (slider_end)
+        *slider_end = 0;
+      return;
+    }
 
   if (priv->orientation == GTK_ORIENTATION_VERTICAL)
     {
@@ -1745,7 +1757,8 @@ coord_to_value (GtkRange *range,
   gint    slider_length;
   graphene_rect_t slider_bounds;
 
-  gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds);
+  if (!gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds))
+    graphene_rect_init (&slider_bounds, 0, 0, gtk_widget_get_width (priv->trough_widget), 
gtk_widget_get_height (priv->trough_widget));
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
@@ -1804,7 +1817,8 @@ gtk_range_key_controller_key_pressed (GtkEventControllerKey *controller,
     {
       graphene_rect_t slider_bounds;
 
-      gtk_widget_compute_bounds (priv->slider_widget, priv->trough_widget, &slider_bounds);
+      if (!gtk_widget_compute_bounds (priv->slider_widget, priv->trough_widget, &slider_bounds))
+        return GDK_EVENT_STOP;
 
       if (priv->orientation == GTK_ORIENTATION_VERTICAL)
         priv->slide_initial_slider_position = slider_bounds.origin.y;
@@ -1877,7 +1891,6 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
   guint button;
   GdkModifierType state_mask;
   GtkWidget *mouse_location;
-  graphene_rect_t slider_bounds;
 
   if (!gtk_widget_has_focus (widget))
     gtk_widget_grab_focus (widget);
@@ -1891,8 +1904,6 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
   source_device = gdk_event_get_source_device ((GdkEvent *) event);
   source = gdk_device_get_source (source_device);
 
-  gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds);
-
   g_object_get (gtk_widget_get_settings (widget),
                 "gtk-primary-button-warps-slider", &primary_warps,
                 NULL);
@@ -1931,13 +1942,15 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
             (!primary_warps && button == GDK_BUTTON_MIDDLE)))
     {
       int slider_range_x, slider_range_y;
+      graphene_rect_t slider_bounds;
 
       gtk_widget_translate_coordinates (priv->trough_widget, widget,
                                         priv->slider_x, priv->slider_y,
                                         &slider_range_x, &slider_range_y);
 
       /* If we aren't fixed, center on the slider. I.e. if this is not a scale... */
-      if (!priv->slider_size_fixed)
+      if (!priv->slider_size_fixed &&
+          gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds))
         {
           slider_range_x += (slider_bounds.size.width  / 2);
           slider_range_y += (slider_bounds.size.height / 2);
@@ -2012,6 +2025,7 @@ update_slider_position (GtkRange *range,
                         gint      mouse_y)
 {
   GtkRangePrivate *priv = gtk_range_get_instance_private (range);
+  graphene_rect_t trough_bounds;
   gdouble delta;
   gdouble c;
   gdouble new_value;
@@ -2025,17 +2039,15 @@ update_slider_position (GtkRange *range,
   gtk_widget_translate_coordinates (GTK_WIDGET (range), priv->trough_widget,
                                     mouse_x, mouse_y, &mouse_x, &mouse_y);
 
-  if (priv->zoom)
+  if (priv->zoom && 
+      gtk_widget_compute_bounds (priv->trough_widget, priv->trough_widget, &trough_bounds))
     {
-      graphene_rect_t trough_bounds;
-
-      gtk_widget_compute_bounds (priv->trough_widget, priv->trough_widget, &trough_bounds);
-
       zoom = MIN(1.0, (priv->orientation == GTK_ORIENTATION_VERTICAL ?
                        trough_bounds.size.height : trough_bounds.size.width) /
                        (gtk_adjustment_get_upper (priv->adjustment) -
                         gtk_adjustment_get_lower (priv->adjustment) -
                         gtk_adjustment_get_page_size (priv->adjustment)));
+
       /* the above is ineffective for scales, so just set a zoom factor */
       if (zoom == 1.0)
         zoom = 0.25;
@@ -2048,7 +2060,8 @@ update_slider_position (GtkRange *range,
     {
       graphene_rect_t slider_bounds;
 
-      gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds);
+      if (!gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds))
+        graphene_rect_init (&slider_bounds, 0, 0, 0, 0);
 
       if (priv->orientation == GTK_ORIENTATION_VERTICAL)
         priv->slide_initial_slider_position = (zoom * (mouse_y - priv->slide_initial_coordinate_delta) - 
slider_bounds.origin.y) / (zoom - 1.0);
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 9d3673e715..29607a9cca 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -336,7 +336,8 @@ gtk_scale_allocate_value (GtkScale *scale)
   range_height = gtk_widget_get_height (widget);
 
   slider_widget = gtk_range_get_slider_widget (range);
-  gtk_widget_compute_bounds (slider_widget, widget, &slider_bounds);
+  if (!gtk_widget_compute_bounds (slider_widget, widget, &slider_bounds))
+    graphene_rect_init (&slider_bounds, 0, 0, gtk_widget_get_width (widget), gtk_widget_get_height (widget));
 
   gtk_widget_measure (priv->value_widget,
                       GTK_ORIENTATION_HORIZONTAL, -1,
@@ -1519,7 +1520,8 @@ gtk_scale_real_get_layout_offsets (GtkScale *scale,
   GtkScalePrivate *priv = gtk_scale_get_instance_private (scale);
   graphene_rect_t value_bounds;
 
-  if (!priv->value_widget)
+  if (!priv->value_widget ||
+      !gtk_widget_compute_bounds (priv->value_widget, GTK_WIDGET (scale), &value_bounds))
     {
       *x = 0;
       *y = 0;
@@ -1527,7 +1529,6 @@ gtk_scale_real_get_layout_offsets (GtkScale *scale,
       return;
     }
 
-  gtk_widget_compute_bounds (priv->value_widget, GTK_WIDGET (scale), &value_bounds);
 
   *x = value_bounds.origin.x;
   *y = value_bounds.origin.y;
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 8e8f78e35b..ea1b402c4b 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -1046,7 +1046,8 @@ coords_close_to_indicator (GtkScrolledWindow *sw,
   graphene_rect_t indicator_bounds;
   gint distance;
 
-  gtk_widget_compute_bounds (indicator->scrollbar, GTK_WIDGET (sw), &indicator_bounds);
+  if (!gtk_widget_compute_bounds (indicator->scrollbar, GTK_WIDGET (sw), &indicator_bounds))
+    return FALSE;
 
   if (indicator->over)
     distance = INDICATOR_FAR_DISTANCE;
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index 4bdfb5094f..eefa49c708 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -191,7 +191,9 @@ gtk_switch_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
   GtkSwitchPrivate *priv = gtk_switch_get_instance_private (sw);
   graphene_rect_t switch_bounds;
 
-  gtk_widget_compute_bounds (GTK_WIDGET (sw), GTK_WIDGET (sw), &switch_bounds);
+  if (!gtk_widget_compute_bounds (GTK_WIDGET (sw), GTK_WIDGET (sw), &switch_bounds))
+    return;
+
   gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
 
   /* If the press didn't happen in the draggable handle,
diff --git a/gtk/gtktooltip.c b/gtk/gtktooltip.c
index 22fafbf47b..592d56d88a 100644
--- a/gtk/gtktooltip.c
+++ b/gtk/gtktooltip.c
@@ -585,11 +585,17 @@ gtk_tooltip_position (GtkTooltip *tooltip,
   tooltip->tooltip_widget = new_tooltip_widget;
 
   toplevel = _gtk_widget_get_toplevel (new_tooltip_widget);
-  gtk_widget_compute_bounds (new_tooltip_widget, toplevel, &anchor_bounds);
-  anchor_rect = (GdkRectangle) {
-    floorf (anchor_bounds.origin.x), floorf (anchor_bounds.origin.y),
-    ceilf (anchor_bounds.size.width), ceilf (anchor_bounds.size.height)
-  };
+  if (gtk_widget_compute_bounds (new_tooltip_widget, toplevel, &anchor_bounds))
+    {
+      anchor_rect = (GdkRectangle) {
+        floorf (anchor_bounds.origin.x), floorf (anchor_bounds.origin.y),
+        ceilf (anchor_bounds.size.width), ceilf (anchor_bounds.size.height)
+      };
+    }
+  else
+    {
+      anchor_rect = (GdkRectangle) { 0, 0, 0, 0 };
+    }
 
   settings = gtk_settings_get_for_display (display);
   g_object_get (settings,
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index aa730c8f9b..674cb7696b 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -3060,7 +3060,8 @@ _gtk_tree_view_column_coords_in_resize_rect (GtkTreeViewColumn *column,
       !priv->visible)
     return FALSE;
 
-  gtk_widget_compute_bounds (priv->button, priv->tree_view, &button_bounds);
+  if (!gtk_widget_compute_bounds (priv->button, priv->tree_view, &button_bounds))
+    return FALSE;
 
   if (gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_LTR)
     button_bounds.origin.x += button_bounds.size.width - TREE_VIEW_DRAG_WIDTH;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 21a1ff3333..ab2f219551 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2544,10 +2544,11 @@ _gtk_widget_emulate_press (GtkWidget      *widget,
     return;
 
   gdk_event_get_coords (event, &x, &y);
-  gtk_widget_compute_point (event_widget,
-                            gtk_widget_get_toplevel (event_widget),
-                            &GRAPHENE_POINT_INIT (x, y),
-                            &p);
+  if (!gtk_widget_compute_point (event_widget,
+                                 gtk_widget_get_toplevel (event_widget),
+                                 &GRAPHENE_POINT_INIT (x, y),
+                                 &p))
+      return;
 
   if (event->any.type == GDK_TOUCH_BEGIN ||
       event->any.type == GDK_TOUCH_UPDATE ||
@@ -3863,13 +3864,19 @@ gtk_widget_get_surface_allocation (GtkWidget     *widget,
 
   g_assert (GTK_IS_WINDOW (parent) || GTK_IS_POPOVER (parent));
 
-  gtk_widget_compute_bounds (widget, parent, &bounds);
-  *allocation = (GtkAllocation){
-    floorf (bounds.origin.x),
-    floorf (bounds.origin.y),
-    ceilf (bounds.size.width),
-    ceilf (bounds.size.height)
-  };
+  if (gtk_widget_compute_bounds (widget, parent, &bounds))
+    {
+      *allocation = (GtkAllocation){
+        floorf (bounds.origin.x),
+        floorf (bounds.origin.y),
+        ceilf (bounds.size.width),
+        ceilf (bounds.size.height)
+      };
+    }
+  else
+    {
+      *allocation = (GtkAllocation) { 0, 0, 0, 0 };
+    }
 }
 
 static void
@@ -5120,9 +5127,9 @@ _gtk_widget_run_controllers (GtkWidget           *widget,
   return handled;
 }
 
-static void
+static gboolean
 translate_event_coordinates (GdkEvent  *event,
-                       GtkWidget *widget);
+                             GtkWidget *widget);
 gboolean
 _gtk_widget_captured_event (GtkWidget      *widget,
                             const GdkEvent *event)
@@ -5138,7 +5145,11 @@ _gtk_widget_captured_event (GtkWidget      *widget,
     return TRUE;
 
   event_copy = gdk_event_copy (event);
-  translate_event_coordinates (event_copy, widget);
+  if (!translate_event_coordinates (event_copy, widget))
+    {
+      g_object_unref (event_copy);
+      return FALSE;
+    }
 
   return_val = _gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_CAPTURE);
 
@@ -5196,7 +5207,7 @@ event_surface_is_still_viewable (const GdkEvent *event)
     }
 }
 
-static void
+static gboolean
 translate_event_coordinates (GdkEvent  *event,
                              GtkWidget *widget)
 {
@@ -5205,16 +5216,19 @@ translate_event_coordinates (GdkEvent  *event,
   graphene_point_t p;
 
   if (!gdk_event_get_coords (event, &x, &y))
-    return;
+    return TRUE;
 
   event_widget = gtk_get_event_widget (event);
 
-  gtk_widget_compute_point (event_widget,
-                            widget,
-                            &GRAPHENE_POINT_INIT (x, y),
-                            &p);
+  if (!gtk_widget_compute_point (event_widget,
+                                 widget,
+                                 &GRAPHENE_POINT_INIT (x, y),
+                                 &p))
+    return FALSE;
 
   gdk_event_set_coords (event, p.x, p.y);
+
+  return TRUE;
 }
 
 static gboolean
@@ -5237,7 +5251,11 @@ gtk_widget_event_internal (GtkWidget      *widget,
 
   event_copy = gdk_event_copy (event);
 
-  translate_event_coordinates (event_copy, widget);
+  if (!translate_event_coordinates (event_copy, widget))
+    {
+      g_object_unref (event_copy);
+      return FALSE;
+    }
 
   if (widget == gtk_get_event_target (event_copy))
     return_val |= _gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_TARGET);
diff --git a/gtk/gtkwidgetfocus.c b/gtk/gtkwidgetfocus.c
index 79177311d4..af68bd7a56 100644
--- a/gtk/gtkwidgetfocus.c
+++ b/gtk/gtkwidgetfocus.c
@@ -80,8 +80,9 @@ tab_sort_func (gconstpointer a,
   GtkTextDirection text_direction = GPOINTER_TO_INT (user_data);
   float y1, y2;
 
-  gtk_widget_compute_bounds (child1, gtk_widget_get_parent (child1), &child_bounds1);
-  gtk_widget_compute_bounds (child2, gtk_widget_get_parent (child2), &child_bounds2);
+  if (!gtk_widget_compute_bounds (child1, gtk_widget_get_parent (child1), &child_bounds1) ||
+      !gtk_widget_compute_bounds (child2, gtk_widget_get_parent (child2), &child_bounds2))
+    return 0;
 
   y1 = child_bounds1.origin.y + (child_bounds1.size.height / 2.0f);
   y2 = child_bounds2.origin.y + (child_bounds2.size.height / 2.0f);
@@ -178,8 +179,9 @@ axis_compare (gconstpointer a,
   int start1, end1;
   int start2, end2;
 
-  gtk_widget_compute_bounds (*((GtkWidget **)a), compare->widget, &bounds1);
-  gtk_widget_compute_bounds (*((GtkWidget **)b), compare->widget, &bounds2);
+  if (!gtk_widget_compute_bounds (*((GtkWidget **)a), compare->widget, &bounds1) ||
+      !gtk_widget_compute_bounds (*((GtkWidget **)b), compare->widget, &bounds2))
+    return 0;
 
   get_axis_info (&bounds1, compare->axis, &start1, &end1);
   get_axis_info (&bounds2, compare->axis, &start2, &end2);
@@ -278,7 +280,8 @@ focus_sort_left_right (GtkWidget        *widget,
       graphene_rect_t old_focus_bounds;
 
       parent = gtk_widget_get_parent (widget);
-      gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds);
+      if (!gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds))
+        graphene_rect_init (&bounds, 0, 0, 0, 0);
 
       if (old_focus_coords (widget, &old_focus_bounds))
         {
@@ -379,7 +382,8 @@ focus_sort_up_down (GtkWidget        *widget,
       graphene_rect_t old_focus_bounds;
 
       parent = gtk_widget_get_parent (widget);
-      gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds);
+      if (!gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds))
+        graphene_rect_init (&bounds, 0, 0, 0, 0);
 
       if (old_focus_coords (widget, &old_focus_bounds))
         {
diff --git a/gtk/gtkwidgetpaintable.c b/gtk/gtkwidgetpaintable.c
index 531b1332fc..23a359d204 100644
--- a/gtk/gtkwidgetpaintable.c
+++ b/gtk/gtkwidgetpaintable.c
@@ -96,11 +96,17 @@ gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
 
       gtk_snapshot_push_clip (snapshot,
                               &GRAPHENE_RECT_INIT(0, 0, width, height));
-      gtk_widget_compute_bounds (self->widget, self->widget, &bounds);
-      graphene_matrix_init_from_2d (&transform,
-                                    width / bounds.size.width, 0.0,
-                                    0.0, height / bounds.size.height,
-                                    bounds.origin.x, bounds.origin.y);
+      if (gtk_widget_compute_bounds (self->widget, self->widget, &bounds))
+        {
+          graphene_matrix_init_from_2d (&transform,
+                                        width / bounds.size.width, 0.0,
+                                        0.0, height / bounds.size.height,
+                                        bounds.origin.x, bounds.origin.y);
+        }
+      else
+        {
+          graphene_matrix_init_identity (&transform);
+        }
       gtk_snapshot_push_transform (snapshot, &transform);
 
       gtk_widget_snapshot (self->widget, snapshot);
@@ -269,7 +275,8 @@ gtk_widget_paintable_snapshot_widget (GtkWidgetPaintable *self)
   if (self->widget == NULL)
     return gdk_paintable_new_empty (0, 0);
 
-  gtk_widget_compute_bounds (self->widget, self->widget, &bounds);
+  if (!gtk_widget_compute_bounds (self->widget, self->widget, &bounds))
+    return gdk_paintable_new_empty (0, 0);
 
   if (self->widget->priv->render_node == NULL)
     return gdk_paintable_new_empty (bounds.size.width, bounds.size.height);
diff --git a/gtk/inspector/fpsoverlay.c b/gtk/inspector/fpsoverlay.c
index 07ff181dd3..616781e7b1 100644
--- a/gtk/inspector/fpsoverlay.c
+++ b/gtk/inspector/fpsoverlay.c
@@ -158,6 +158,7 @@ gtk_fps_overlay_snapshot (GtkInspectorOverlay *overlay,
   double fps;
   char *fps_string;
   graphene_rect_t bounds;
+  gboolean has_bounds;
   int width, height;
   double overlay_opacity;
 
@@ -202,20 +203,20 @@ gtk_fps_overlay_snapshot (GtkInspectorOverlay *overlay,
   if (GTK_IS_WINDOW (widget))
     {
       GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
-      if (child)
-        gtk_widget_compute_bounds (child, widget, &bounds);
-      else
-        gtk_widget_compute_bounds (widget, widget, &bounds);
+      if (!child ||
+          !gtk_widget_compute_bounds (child, widget, &bounds))
+        has_bounds = gtk_widget_compute_bounds (widget, widget, &bounds);
     }
   else
     {
-      gtk_widget_compute_bounds (widget, widget, &bounds);
+      has_bounds = gtk_widget_compute_bounds (widget, widget, &bounds);
     }
 
   layout = gtk_widget_create_pango_layout (widget, fps_string);
   pango_layout_get_pixel_size (layout, &width, &height);
 
-  gtk_snapshot_offset (snapshot, bounds.origin.x + bounds.size.width - width, bounds.origin.y);
+  if (has_bounds)
+    gtk_snapshot_offset (snapshot, bounds.origin.x + bounds.size.width - width, bounds.origin.y);
   if (overlay_opacity < 1.0)
     gtk_snapshot_push_opacity (snapshot, overlay_opacity);
   gtk_snapshot_append_color (snapshot,
@@ -226,7 +227,8 @@ gtk_fps_overlay_snapshot (GtkInspectorOverlay *overlay,
                               &(GdkRGBA) { 1, 1, 1, 1 });
   if (overlay_opacity < 1.0)
     gtk_snapshot_pop (snapshot);
-  gtk_snapshot_offset (snapshot, - bounds.origin.x - bounds.size.width + width, - bounds.origin.y);
+  if (has_bounds)
+    gtk_snapshot_offset (snapshot, - bounds.origin.x - bounds.size.width + width, - bounds.origin.y);
   g_free (fps_string);
 
   gtk_widget_add_tick_callback (widget, gtk_fps_overlay_force_redraw, NULL, NULL);
diff --git a/tests/testwidgettransforms.c b/tests/testwidgettransforms.c
index 65c78825cc..9200335cdb 100644
--- a/tests/testwidgettransforms.c
+++ b/tests/testwidgettransforms.c
@@ -153,10 +153,10 @@ gtk_transform_tester_snapshot (GtkWidget   *widget,
 
   GTK_WIDGET_CLASS (gtk_transform_tester_parent_class)->snapshot (widget, snapshot);
 
-  if (!do_picking)
+  if (!do_picking ||
+      !gtk_widget_compute_bounds (self->test_widget, widget, &child_bounds) ||
+      !gtk_widget_compute_bounds (self->test_widget, self->test_widget, &self_bounds))
     return;
-  gtk_widget_compute_bounds (self->test_widget, widget, &child_bounds);
-  gtk_widget_compute_bounds (self->test_widget, self->test_widget, &self_bounds);
 
   {
     const struct {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]