1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ShapeUtils_h
8 #define mozilla_ShapeUtils_h
12 #include "nsStyleConsts.h"
19 // ShapeUtils is a namespace class containing utility functions related to
20 // processing basic shapes in the CSS Shapes Module.
21 // https://drafts.csswg.org/css-shapes/#basic-shape-functions
23 struct ShapeUtils final
{
24 // Compute the length of a keyword <shape-radius>, i.e. closest-side or
25 // farthest-side, for a circle or an ellipse on a single dimension. The
26 // caller needs to call for both dimensions and combine the result.
27 // https://drafts.csswg.org/css-shapes/#typedef-shape-radius.
28 // @return The length of the radius in app units.
29 static nscoord
ComputeShapeRadius(const StyleShapeRadius
& aType
,
30 const nscoord aCenter
,
31 const nscoord aPosMin
,
32 const nscoord aPosMax
);
34 // Compute the center of a circle or an ellipse.
35 // @param aRefBox The reference box of the basic shape.
36 // @return The point of the center.
37 static nsPoint
ComputeCircleOrEllipseCenter(const StyleBasicShape
&,
38 const nsRect
& aRefBox
);
40 // Compute the radius for a circle.
41 // @param aCenter the center of the circle.
42 // @param aRefBox the reference box of the circle.
43 // @return The length of the radius in app units.
44 static nscoord
ComputeCircleRadius(const StyleBasicShape
&,
45 const nsPoint
& aCenter
,
46 const nsRect
& aRefBox
);
48 // Compute the radii for an ellipse.
49 // @param aCenter the center of the ellipse.
50 // @param aRefBox the reference box of the ellipse.
51 // @return The radii of the ellipse in app units. The width and height
52 // represent the x-axis and y-axis radii of the ellipse.
53 static nsSize
ComputeEllipseRadii(const StyleBasicShape
&,
54 const nsPoint
& aCenter
,
55 const nsRect
& aRefBox
);
57 // Compute the rect for an inset. If the inset amount is larger than
58 // aRefBox itself, this will return a rect the same shape as the inverse
59 // rect that would be created by insetting aRefBox by the inset amount.
60 // This process is *not* what is called for by the current spec at
61 // https://drafts.csswg.org/css-shapes-1/#supported-basic-shapes.
62 // The spec currently treats empty shapes, including overly-inset rects, as
63 // defining 'empty float areas' that don't affect layout. However, it is
64 // practically useful to treat empty shapes as having edges for purposes of
65 // affecting layout, and there is growing momentum for the approach we
67 // @param aRefBox the reference box of the inset.
68 // @return The inset rect in app units.
69 static nsRect
ComputeInsetRect(const StyleBasicShape
&, const nsRect
& aRefBox
);
71 // Compute the radii for an inset.
72 // @param aRefBox the reference box of the inset.
73 // @param aRadii the returned radii in app units.
74 // @return true if any of the radii is nonzero; false otherwise.
75 static bool ComputeInsetRadii(const StyleBasicShape
&, const nsRect
& aRefBox
,
78 // Compute the vertices for a polygon.
79 // @param aRefBox the reference box of the polygon.
80 // @return The vertices in app units; the coordinate space is the same
82 static nsTArray
<nsPoint
> ComputePolygonVertices(const StyleBasicShape
&,
83 const nsRect
& aRefBox
);
86 } // namespace mozilla
88 #endif // mozilla_ShapeUtils_h