|
Packit |
f0b94e |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
Packit |
f0b94e |
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
Packit |
f0b94e |
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
Packit |
f0b94e |
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
Packit |
f0b94e |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#ifndef mozilla_ShapeUtils_h
|
|
Packit |
f0b94e |
#define mozilla_ShapeUtils_h
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#include "nsCoord.h"
|
|
Packit |
f0b94e |
#include "nsSize.h"
|
|
Packit |
f0b94e |
#include "nsStyleConsts.h"
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
struct nsPoint;
|
|
Packit |
f0b94e |
struct nsRect;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
namespace mozilla {
|
|
Packit |
f0b94e |
class StyleBasicShape;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// ShapeUtils is a namespace class containing utility functions related to
|
|
Packit |
f0b94e |
// processing basic shapes in the CSS Shapes Module.
|
|
Packit |
f0b94e |
// https://drafts.csswg.org/css-shapes/#basic-shape-functions
|
|
Packit |
f0b94e |
//
|
|
Packit |
f0b94e |
struct ShapeUtils final {
|
|
Packit |
f0b94e |
// Compute the length of a keyword <shape-radius>, i.e. closest-side or
|
|
Packit |
f0b94e |
// farthest-side, for a circle or an ellipse on a single dimension. The
|
|
Packit |
f0b94e |
// caller needs to call for both dimensions and combine the result.
|
|
Packit |
f0b94e |
// https://drafts.csswg.org/css-shapes/#typedef-shape-radius.
|
|
Packit |
f0b94e |
// @return The length of the radius in app units.
|
|
Packit |
f0b94e |
static nscoord ComputeShapeRadius(const StyleShapeRadius aType,
|
|
Packit |
f0b94e |
const nscoord aCenter,
|
|
Packit |
f0b94e |
const nscoord aPosMin,
|
|
Packit |
f0b94e |
const nscoord aPosMax);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// Compute the center of a circle or an ellipse.
|
|
Packit |
f0b94e |
// @param aRefBox The reference box of the basic shape.
|
|
Packit |
f0b94e |
// @return The point of the center.
|
|
Packit |
f0b94e |
static nsPoint ComputeCircleOrEllipseCenter(
|
|
Packit |
f0b94e |
const UniquePtr<StyleBasicShape>& aBasicShape, const nsRect& aRefBox);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// Compute the radius for a circle.
|
|
Packit |
f0b94e |
// @param aCenter the center of the circle.
|
|
Packit |
f0b94e |
// @param aRefBox the reference box of the circle.
|
|
Packit |
f0b94e |
// @return The length of the radius in app units.
|
|
Packit |
f0b94e |
static nscoord ComputeCircleRadius(
|
|
Packit |
f0b94e |
const UniquePtr<StyleBasicShape>& aBasicShape, const nsPoint& aCenter,
|
|
Packit |
f0b94e |
const nsRect& aRefBox);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// Compute the radii for an ellipse.
|
|
Packit |
f0b94e |
// @param aCenter the center of the ellipse.
|
|
Packit |
f0b94e |
// @param aRefBox the reference box of the ellipse.
|
|
Packit |
f0b94e |
// @return The radii of the ellipse in app units. The width and height
|
|
Packit |
f0b94e |
// represent the x-axis and y-axis radii of the ellipse.
|
|
Packit |
f0b94e |
static nsSize ComputeEllipseRadii(
|
|
Packit |
f0b94e |
const UniquePtr<StyleBasicShape>& aBasicShape, const nsPoint& aCenter,
|
|
Packit |
f0b94e |
const nsRect& aRefBox);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// Compute the rect for an inset.
|
|
Packit |
f0b94e |
// @param aRefBox the reference box of the inset.
|
|
Packit |
f0b94e |
// @return The inset rect in app units.
|
|
Packit |
f0b94e |
static nsRect ComputeInsetRect(const UniquePtr<StyleBasicShape>& aBasicShape,
|
|
Packit |
f0b94e |
const nsRect& aRefBox);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// Compute the radii for an inset.
|
|
Packit |
f0b94e |
// @param aRefBox the reference box of the inset.
|
|
Packit |
f0b94e |
// @param aInsetRect the inset rect computed by ComputeInsetRect().
|
|
Packit |
f0b94e |
// @param aRadii the returned radii in app units.
|
|
Packit |
f0b94e |
// @return true if any of the radii is nonzero; false otherwise.
|
|
Packit |
f0b94e |
static bool ComputeInsetRadii(const UniquePtr<StyleBasicShape>& aBasicShape,
|
|
Packit |
f0b94e |
const nsRect& aInsetRect, const nsRect& aRefBox,
|
|
Packit |
f0b94e |
nscoord aRadii[8]);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
// Compute the vertices for a polygon.
|
|
Packit |
f0b94e |
// @param aRefBox the reference box of the polygon.
|
|
Packit |
f0b94e |
// @return The vertices in app units; the coordinate space is the same
|
|
Packit |
f0b94e |
// as aRefBox.
|
|
Packit |
f0b94e |
static nsTArray<nsPoint> ComputePolygonVertices(
|
|
Packit |
f0b94e |
const UniquePtr<StyleBasicShape>& aBasicShape, const nsRect& aRefBox);
|
|
Packit |
f0b94e |
};
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
} // namespace mozilla
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#endif // mozilla_ShapeUtils_h
|