[gtk+/wip/otte/rendernode: 28/30] roundedbox: Add gtk_rounded_boxes_init_for_style()



commit a41ed24c7ac43b64f28710a351c2273b66a1f39c
Author: Benjamin Otte <otte redhat com>
Date:   Mon Dec 19 19:19:15 2016 +0100

    roundedbox: Add gtk_rounded_boxes_init_for_style()
    
    Instead of making people intiialize a rectangle and then applying border
    radius manually, provide a constructor that does it for them.
    While doing that, also allow people to instead request the padding box
    or the content box.
    
    Refactor all relevant code to use this new constructor.

 docs/reference/gtk/Makefile.am |    1 -
 gtk/Makefile.am                |    1 -
 gtk/gtkcolorscale.c            |    1 -
 gtk/gtkcolorswatch.c           |   18 ++++++++++-----
 gtk/gtkcssimagebuiltin.c       |    1 -
 gtk/gtkcssshadowvalue.c        |    1 -
 gtk/gtkpopover.c               |    7 +++--
 gtk/gtkrender.c                |   45 ----------------------------------------
 gtk/gtkrenderbackground.c      |   36 ++++---------------------------
 gtk/gtkrenderborder.c          |    6 +---
 gtk/gtkrenderprivate.h         |   34 ------------------------------
 gtk/gtkroundedbox.c            |   40 ++++++++++++++++++++++++++++++++--
 gtk/gtkroundedboxprivate.h     |   11 +++++++--
 13 files changed, 68 insertions(+), 134 deletions(-)
---
diff --git a/docs/reference/gtk/Makefile.am b/docs/reference/gtk/Makefile.am
index 300c585..e02fc81 100644
--- a/docs/reference/gtk/Makefile.am
+++ b/docs/reference/gtk/Makefile.am
@@ -166,7 +166,6 @@ IGNORE_HFILES = \
        gtkrenderbackgroundprivate.h    \
        gtkrenderborderprivate.h        \
        gtkrendericonprivate.h          \
-       gtkrenderprivate.h              \
        gtkroundedboxprivate.h          \
        gtkscaleprivate.h               \
        gtksearchengine.h               \
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 2578e1f..bdb4898 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -526,7 +526,6 @@ gtk_private_h_sources =             \
        gtkrenderbackgroundprivate.h \
        gtkrenderborderprivate.h \
        gtkrendericonprivate.h  \
-       gtkrenderprivate.h      \
        gtkresources.h          \
        gtkroundedboxprivate.h  \
        gtksearchengine.h       \
diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c
index b6560a7..b8564ae 100644
--- a/gtk/gtkcolorscale.c
+++ b/gtk/gtkcolorscale.c
@@ -28,7 +28,6 @@
 #include "gtkaccessible.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
-#include "gtkrenderprivate.h"
 #include "gtksnapshot.h"
 
 #include <math.h>
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index 15f6b6c..9c95754 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -28,14 +28,15 @@
 #include "gtkmenushell.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
-#include "gtkrenderprivate.h"
 #include "gtkiconhelperprivate.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkcsscustomgadgetprivate.h"
+#include "gtkroundedboxprivate.h"
 #include "gtkwidgetprivate.h"
 #include "gtkstylecontextprivate.h"
 #include "a11y/gtkcolorswatchaccessibleprivate.h"
 
+#include "gsk/gskroundedrectprivate.h"
 
 /*
  * GtkColorSwatch has two CSS nodes, the main one named colorswatch
@@ -120,6 +121,7 @@ gtk_color_swatch_render (GtkCssGadget *gadget,
       cairo_pattern_t *pattern;
       cairo_matrix_t matrix;
       GtkAllocation allocation, border_allocation;
+      GskRoundedRect content_box;
 
       gtk_widget_get_allocation (widget, &allocation);
       gtk_css_gadget_get_border_allocation (gadget, &border_allocation, NULL);
@@ -127,11 +129,15 @@ gtk_color_swatch_render (GtkCssGadget *gadget,
       border_allocation.x -= allocation.x;
       border_allocation.y -= allocation.y;
 
-      gtk_render_content_path (context, cr,
-                               border_allocation.x,
-                               border_allocation.y,
-                               border_allocation.width,
-                               border_allocation.height);
+      gtk_rounded_boxes_init_for_style (NULL,
+                                        NULL,
+                                        &content_box,
+                                        gtk_style_context_lookup_style (context),
+                                        border_allocation.x,
+                                        border_allocation.y,
+                                        border_allocation.width,
+                                        border_allocation.height);
+      gsk_rounded_rect_path (&content_box, cr);
 
       if (swatch->priv->use_alpha)
         {
diff --git a/gtk/gtkcssimagebuiltin.c b/gtk/gtkcssimagebuiltin.c
index 00a267c..67cc061 100644
--- a/gtk/gtkcssimagebuiltin.c
+++ b/gtk/gtkcssimagebuiltin.c
@@ -26,7 +26,6 @@
 #include "gtkcssrgbavalueprivate.h"
 #include "gtkcssstyleprivate.h"
 #include "gtkhslaprivate.h"
-#include "gtkrenderprivate.h"
 
 #include <math.h>
 
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index d9e1aaa..bcb874d 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -26,7 +26,6 @@
 #include "gtkcssrgbavalueprivate.h"
 #include "gtksnapshot.h"
 #include "gtkstylecontextprivate.h"
-#include "gtkrenderprivate.h"
 #include "gtkpango.h"
 
 #include "gsk/gskcairoblurprivate.h"
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index 6e8ba94..48778fb 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -918,9 +918,10 @@ gtk_popover_fill_border_path (GtkPopover *popover,
 
   gtk_popover_get_rect_coords (popover, &x, &y, &w, &h);
 
-  _gtk_rounded_box_init_rect (&box, x, y, w, h);
-  _gtk_rounded_box_apply_border_radius_for_style (&box,
-                                                  gtk_style_context_lookup_style (context));
+  gtk_rounded_boxes_init_for_style (&box,
+                                    NULL, NULL,
+                                    gtk_style_context_lookup_style (context),
+                                    x, y, w, h);
   gsk_rounded_rect_path (&box, cr);
   cairo_fill (cr);
 }
diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c
index 7ff3427..3d4bbba 100644
--- a/gtk/gtkrender.c
+++ b/gtk/gtkrender.c
@@ -18,7 +18,6 @@
 #include "config.h"
 
 #include "gtkrender.h"
-#include "gtkrenderprivate.h"
 
 #include <math.h>
 
@@ -914,47 +913,3 @@ gtk_render_icon_surface (GtkStyleContext *context,
                                      x, y);
 }
 
-/*
- * gtk_render_content_path:
- * @context: style context to get style information from
- * @cr: cairo context to add path to
- * @x: x coordinate of CSS box
- * @y: y coordinate of CSS box
- * @width: width of CSS box
- * @height: height of CSS box
- *
- * Adds the path of the content box to @cr for a given border box.
- * This function respects rounded corners.
- *
- * This is useful if you are drawing content that is supposed to
- * fill the whole content area, like the color buttons in
- * #GtkColorChooserDialog.
- **/
-void
-gtk_render_content_path (GtkStyleContext *context,
-                         cairo_t         *cr,
-                         double           x,
-                         double           y,
-                         double           width,
-                         double           height)
-{
-  GskRoundedRect box;
-
-  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
-  g_return_if_fail (cr != NULL);
-
-  _gtk_rounded_box_init_rect (&box, x, y, width, height);
-  _gtk_rounded_box_apply_border_radius_for_style (&box, gtk_style_context_lookup_style (context));
-
-  gsk_rounded_rect_shrink (&box,
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_PADDING_TOP), 100),
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_PADDING_RIGHT), 100),
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_PADDING_BOTTOM), 100),
-                           _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100)
-                           + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_PADDING_LEFT), 100));
-
-  gsk_rounded_rect_path (&box, cr);
-}
diff --git a/gtk/gtkrenderbackground.c b/gtk/gtkrenderbackground.c
index ae80f5f..051a9fd 100644
--- a/gtk/gtkrenderbackground.c
+++ b/gtk/gtkrenderbackground.c
@@ -529,39 +529,13 @@ gtk_theming_background_init (GtkThemingBackground *bg,
                              double                width,
                              double                height)
 {
-  GtkBorder border, padding;
-
   bg->style = style;
 
-  border.top = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100);
-  border.right = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100);
-  border.bottom = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100);
-  border.left = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100);
-  padding.top = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_PADDING_TOP), 100);
-  padding.right = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_PADDING_RIGHT), 100);
-  padding.bottom = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_PADDING_BOTTOM), 100);
-  padding.left = _gtk_css_number_value_get (gtk_css_style_get_value (bg->style, 
GTK_CSS_PROPERTY_PADDING_LEFT), 100);
-
-  /* In the CSS box model, by default the background positioning area is
-   * the padding-box, i.e. all the border-box minus the borders themselves,
-   * which determines also its default size, see
-   * http://dev.w3.org/csswg/css3-background/#background-origin
-   *
-   * In the future we might want to support different origins or clips, but
-   * right now we just shrink to the default.
-   */
-  _gtk_rounded_box_init_rect (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], 0, 0, width, height);
-  _gtk_rounded_box_apply_border_radius_for_style (&bg->boxes[GTK_CSS_AREA_BORDER_BOX], bg->style);
-
-  bg->boxes[GTK_CSS_AREA_PADDING_BOX] = bg->boxes[GTK_CSS_AREA_BORDER_BOX];
-  gsk_rounded_rect_shrink (&bg->boxes[GTK_CSS_AREA_PADDING_BOX],
-                          border.top, border.right,
-                          border.bottom, border.left);
-
-  bg->boxes[GTK_CSS_AREA_CONTENT_BOX] = bg->boxes[GTK_CSS_AREA_PADDING_BOX];
-  gsk_rounded_rect_shrink (&bg->boxes[GTK_CSS_AREA_CONTENT_BOX],
-                          padding.top, padding.right,
-                          padding.bottom, padding.left);
+  gtk_rounded_boxes_init_for_style (&bg->boxes[GTK_CSS_AREA_BORDER_BOX],
+                                    &bg->boxes[GTK_CSS_AREA_PADDING_BOX],
+                                    &bg->boxes[GTK_CSS_AREA_CONTENT_BOX],
+                                    style,
+                                    0, 0, width, height);
 }
 
 void
diff --git a/gtk/gtkrenderborder.c b/gtk/gtkrenderborder.c
index 429ae39..d6223c4 100644
--- a/gtk/gtkrenderborder.c
+++ b/gtk/gtkrenderborder.c
@@ -912,8 +912,7 @@ gtk_css_style_render_border (GtkCssStyle *style,
       colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR));
       colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_LEFT_COLOR));
 
-      _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
-      _gtk_rounded_box_apply_border_radius_for_style (&border_box, style);
+      gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, x, y, width, height);
 
       render_border (cr, &border_box, border_width, colors, border_style);
     }
@@ -970,8 +969,7 @@ gtk_css_style_snapshot_border (GtkCssStyle *style,
       colors[2] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR));
       colors[3] = *_gtk_css_rgba_value_get_rgba (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_LEFT_COLOR));
 
-      _gtk_rounded_box_init_rect (&border_box, 0, 0, width, height);
-      _gtk_rounded_box_apply_border_radius_for_style (&border_box, style);
+      gtk_rounded_boxes_init_for_style (&border_box, NULL, NULL, style, 0, 0, width, height);
 
       snapshot_border (snapshot, &border_box, border_width, colors, border_style);
     }
diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c
index 11430c0..6c45067 100644
--- a/gtk/gtkroundedbox.c
+++ b/gtk/gtkroundedbox.c
@@ -20,6 +20,7 @@
 #include "gtkroundedboxprivate.h"
 
 #include "gtkcsscornervalueprivate.h"
+#include "gtkcssnumbervalueprivate.h"
 #include "gtkcsstypesprivate.h"
 #include "gtkstylecontextprivate.h"
 
@@ -121,17 +122,50 @@ _gtk_rounded_box_apply_border_radius (GskRoundedRect *box,
 }
 
 void
-_gtk_rounded_box_apply_border_radius_for_style (GskRoundedRect   *box,
-                                                GtkCssStyle      *style)
+gtk_rounded_boxes_init_for_style (GskRoundedRect *border_box,
+                                  GskRoundedRect *padding_box,
+                                  GskRoundedRect *content_box,
+                                  GtkCssStyle    *style,
+                                  double          x,
+                                  double          y,
+                                  double          width,
+                                  double          height)
 {
   GtkCssValue *corner[4];
+  GskRoundedRect box;
+
+  gsk_rounded_rect_init_from_rect (&box, &GRAPHENE_RECT_INIT (x, y, width, height), 0);
 
   corner[GSK_CORNER_TOP_LEFT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS);
   corner[GSK_CORNER_TOP_RIGHT] = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS);
   corner[GSK_CORNER_BOTTOM_LEFT] = gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS);
   corner[GSK_CORNER_BOTTOM_RIGHT] = gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS);
 
-  _gtk_rounded_box_apply_border_radius (box, corner);
+  _gtk_rounded_box_apply_border_radius (&box, corner);
+
+  if (border_box)
+    gsk_rounded_rect_init_copy (border_box, &box);
+
+  if (padding_box || content_box)
+    {
+      gsk_rounded_rect_shrink (&box,
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100),
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100),
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100),
+                               _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100));
+      if (padding_box)
+        gsk_rounded_rect_init_copy (padding_box, &box);
+
+      if (content_box)
+        {
+          gsk_rounded_rect_shrink (&box,
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_PADDING_TOP), 100),
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_PADDING_RIGHT), 100),
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_PADDING_BOTTOM), 100),
+                                   _gtk_css_number_value_get (gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_PADDING_LEFT), 100));
+          gsk_rounded_rect_init_copy (content_box, &box);
+        }
+    }
 }
 
 void
diff --git a/gtk/gtkroundedboxprivate.h b/gtk/gtkroundedboxprivate.h
index 55f72d7..4f9c0a1 100644
--- a/gtk/gtkroundedboxprivate.h
+++ b/gtk/gtkroundedboxprivate.h
@@ -33,9 +33,14 @@ void            _gtk_rounded_box_init_rect                      (GskRoundedRect
                                                                  double                  y,
                                                                  double                  width,
                                                                  double                  height);
-
-void            _gtk_rounded_box_apply_border_radius_for_style  (GskRoundedRect         *box,
-                                                                 GtkCssStyle            *style);
+void            gtk_rounded_boxes_init_for_style                (GskRoundedRect         *border_box,
+                                                                 GskRoundedRect         *padding_box,
+                                                                 GskRoundedRect         *content_box,
+                                                                 GtkCssStyle            *style,
+                                                                 double                  x,
+                                                                 double                  y,
+                                                                 double                  width,
+                                                                 double                  height);
 
 void            _gtk_rounded_box_apply_outline_radius_for_style (GskRoundedRect         *box,
                                                                  GtkCssStyle            *style);


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