[gtk/wip/baedert/transforms6: 132/155] widget: Don't use compute_bounds in _real_contains



commit b9946117ca7e268fc73f7589acb1152d1b1acb67
Author: Timm Bäder <mail baedert org>
Date:   Sat Aug 11 22:03:08 2018 +0200

    widget: Don't use compute_bounds in _real_contains
    
    compute_bounds will look at the widget transformation and return an
    axis-aligned rectangle containing the given widget.

 gtk/gtkwidget.c | 108 ++++++++++++++++++++++++++++++++------------------------
 1 file changed, 62 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 19c19034fe..d289cab3da 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -786,18 +786,76 @@ gtk_widget_real_snapshot (GtkWidget   *widget,
     gtk_widget_snapshot_child (widget, child, snapshot);
 }
 
+static gint
+get_number (GtkCssStyle *style,
+            guint        property)
+{
+  double d = _gtk_css_number_value_get (gtk_css_style_get_value (style, property), 100);
+
+  if (d < 1)
+    return ceil (d);
+  else
+    return floor (d);
+}
+
+static void
+get_box_margin (GtkCssStyle *style,
+                GtkBorder   *margin)
+{
+  margin->top = get_number (style, GTK_CSS_PROPERTY_MARGIN_TOP);
+  margin->left = get_number (style, GTK_CSS_PROPERTY_MARGIN_LEFT);
+  margin->bottom = get_number (style, GTK_CSS_PROPERTY_MARGIN_BOTTOM);
+  margin->right = get_number (style, GTK_CSS_PROPERTY_MARGIN_RIGHT);
+}
+
+static void
+get_box_border (GtkCssStyle *style,
+                GtkBorder   *border)
+{
+  border->top = get_number (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH);
+  border->left = get_number (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH);
+  border->bottom = get_number (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH);
+  border->right = get_number (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH);
+}
+
+static void
+get_box_padding (GtkCssStyle *style,
+                 GtkBorder   *border)
+{
+  border->top = get_number (style, GTK_CSS_PROPERTY_PADDING_TOP);
+  border->left = get_number (style, GTK_CSS_PROPERTY_PADDING_LEFT);
+  border->bottom = get_number (style, GTK_CSS_PROPERTY_PADDING_BOTTOM);
+  border->right = get_number (style, GTK_CSS_PROPERTY_PADDING_RIGHT);
+}
+
 static gboolean
 gtk_widget_real_contains (GtkWidget *widget,
                           gdouble    x,
                           gdouble    y)
 {
-  graphene_rect_t widget_bounds;
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+  graphene_rect_t bounds;
+  GtkBorder margin, border, padding;
+  GtkCssStyle *style;
+
+  /*
+   * A widget always sees itself untransformed, so in here we don't need
+   * to consider the transformation at all.
+   */
+  style = gtk_css_node_get_style (priv->cssnode);
+  get_box_margin (style, &margin);
+  get_box_border (style, &border);
+  get_box_padding (style, &padding);
 
-  gtk_widget_compute_bounds (widget, widget, &widget_bounds);
+  graphene_rect_init (&bounds,
+                      - border.left - padding.left,
+                      - border.top - padding.top,
+                      priv->allocation.width - margin.left - margin.right,
+                      priv->allocation.height - margin.top - margin.bottom);
 
   /* XXX: This misses rounded rects */
-  return graphene_rect_contains_point (&widget_bounds,
-                                       &(graphene_point_t){x, y});
+  return graphene_rect_contains_point (&bounds,
+                                       &(graphene_point_t){ x, y});
 }
 
 static GtkWidget *
@@ -3999,48 +4057,6 @@ gtk_widget_get_frame_clock (GtkWidget *widget)
     }
 }
 
-static gint
-get_number (GtkCssStyle *style,
-            guint        property)
-{
-  double d = _gtk_css_number_value_get (gtk_css_style_get_value (style, property), 100);
-
-  if (d < 1)
-    return ceil (d);
-  else
-    return floor (d);
-}
-
-static void
-get_box_margin (GtkCssStyle *style,
-                GtkBorder   *margin)
-{
-  margin->top = get_number (style, GTK_CSS_PROPERTY_MARGIN_TOP);
-  margin->left = get_number (style, GTK_CSS_PROPERTY_MARGIN_LEFT);
-  margin->bottom = get_number (style, GTK_CSS_PROPERTY_MARGIN_BOTTOM);
-  margin->right = get_number (style, GTK_CSS_PROPERTY_MARGIN_RIGHT);
-}
-
-static void
-get_box_border (GtkCssStyle *style,
-                GtkBorder   *border)
-{
-  border->top = get_number (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH);
-  border->left = get_number (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH);
-  border->bottom = get_number (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH);
-  border->right = get_number (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH);
-}
-
-static void
-get_box_padding (GtkCssStyle *style,
-                 GtkBorder   *border)
-{
-  border->top = get_number (style, GTK_CSS_PROPERTY_PADDING_TOP);
-  border->left = get_number (style, GTK_CSS_PROPERTY_PADDING_LEFT);
-  border->bottom = get_number (style, GTK_CSS_PROPERTY_PADDING_BOTTOM);
-  border->right = get_number (style, GTK_CSS_PROPERTY_PADDING_RIGHT);
-}
-
 /**
  * gtk_widget_size_allocate:
  * @widget: a #GtkWidget


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