[gtk/wip/baedert/transforms6: 245/273] widget: Don't use compute_bounds in _real_contains
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/transforms6: 245/273] widget: Don't use compute_bounds in _real_contains
- Date: Wed, 13 Feb 2019 09:13:52 +0000 (UTC)
commit 544d1a8be42e4572296ab4c79a36f5f2709e4f0b
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 40fb4d2c29..66269e7ae2 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -790,18 +790,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 *
@@ -4022,48 +4080,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]