Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2024-08-05 10:39:53 +08:00
commit d27ddaffd7
73 changed files with 930 additions and 951 deletions

View file

@ -383,30 +383,30 @@ struct BaseRect {
Point TopRight() const { return Point(XMost(), y); }
Point BottomLeft() const { return Point(x, YMost()); }
Point BottomRight() const { return Point(XMost(), YMost()); }
Point AtCorner(int aCorner) const {
Point AtCorner(Corner aCorner) const {
switch (aCorner) {
case RectCorner::TopLeft: return TopLeft();
case RectCorner::TopRight: return TopRight();
case RectCorner::BottomRight: return BottomRight();
case RectCorner::BottomLeft: return BottomLeft();
case eCornerTopLeft: return TopLeft();
case eCornerTopRight: return TopRight();
case eCornerBottomRight: return BottomRight();
case eCornerBottomLeft: return BottomLeft();
}
MOZ_CRASH("GFX: Incomplete switch");
}
Point CCWCorner(mozilla::Side side) const {
switch (side) {
case NS_SIDE_TOP: return TopLeft();
case NS_SIDE_RIGHT: return TopRight();
case NS_SIDE_BOTTOM: return BottomRight();
case NS_SIDE_LEFT: return BottomLeft();
case eSideTop: return TopLeft();
case eSideRight: return TopRight();
case eSideBottom: return BottomRight();
case eSideLeft: return BottomLeft();
}
MOZ_CRASH("GFX: Incomplete switch");
}
Point CWCorner(mozilla::Side side) const {
switch (side) {
case NS_SIDE_TOP: return TopRight();
case NS_SIDE_RIGHT: return BottomRight();
case NS_SIDE_BOTTOM: return BottomLeft();
case NS_SIDE_LEFT: return TopLeft();
case eSideTop: return TopRight();
case eSideRight: return BottomRight();
case eSideBottom: return BottomLeft();
case eSideLeft: return TopLeft();
}
MOZ_CRASH("GFX: Incomplete switch");
}
@ -427,10 +427,10 @@ struct BaseRect {
T Edge(mozilla::Side aSide) const
{
switch (aSide) {
case NS_SIDE_TOP: return Y();
case NS_SIDE_RIGHT: return XMost();
case NS_SIDE_BOTTOM: return YMost();
case NS_SIDE_LEFT: return X();
case eSideTop: return Y();
case eSideRight: return XMost();
case eSideBottom: return YMost();
case eSideLeft: return X();
}
MOZ_CRASH("GFX: Incomplete switch");
}

View file

@ -241,7 +241,7 @@ FindBezierNearestPoint(const Bezier& aBezier, const Point& aTarget,
}
void
GetBezierPointsForCorner(Bezier* aBezier, mozilla::css::Corner aCorner,
GetBezierPointsForCorner(Bezier* aBezier, mozilla::Corner aCorner,
const Point& aCornerPoint, const Size& aCornerSize)
{
// Calculate bezier control points for elliptic arc.

View file

@ -127,7 +127,7 @@ Point FindBezierNearestPoint(const Bezier& aBezier, const Point& aTarget,
// | |
// v mPoints[0] |
// -------------+
void GetBezierPointsForCorner(Bezier* aBezier, mozilla::css::Corner aCorner,
void GetBezierPointsForCorner(Bezier* aBezier, mozilla::Corner aCorner,
const Point& aCornerPoint,
const Size& aCornerSize);

View file

@ -125,10 +125,10 @@ AppendRoundedRectToPath(PathBuilder* aPathBuilder,
Point pc, p0, p1, p2, p3;
if (aDrawClockwise) {
aPathBuilder->MoveTo(Point(aRect.X() + aRadii[RectCorner::TopLeft].width,
aPathBuilder->MoveTo(Point(aRect.X() + aRadii[eCornerTopLeft].width,
aRect.Y()));
} else {
aPathBuilder->MoveTo(Point(aRect.X() + aRect.Width() - aRadii[RectCorner::TopRight].width,
aPathBuilder->MoveTo(Point(aRect.X() + aRect.Width() - aRadii[eCornerTopRight].width,
aRect.Y()));
}

View file

@ -178,35 +178,35 @@ inline already_AddRefed<Path> MakePathForRect(const DrawTarget& aDrawTarget,
}
struct RectCornerRadii {
Size radii[RectCorner::Count];
Size radii[eCornerCount];
RectCornerRadii() {}
explicit RectCornerRadii(Float radius) {
for (int i = 0; i < RectCorner::Count; i++) {
NS_FOR_CSS_FULL_CORNERS(i) {
radii[i].SizeTo(radius, radius);
}
}
explicit RectCornerRadii(Float radiusX, Float radiusY) {
for (int i = 0; i < RectCorner::Count; i++) {
NS_FOR_CSS_FULL_CORNERS(i) {
radii[i].SizeTo(radiusX, radiusY);
}
}
RectCornerRadii(Float tl, Float tr, Float br, Float bl) {
radii[RectCorner::TopLeft].SizeTo(tl, tl);
radii[RectCorner::TopRight].SizeTo(tr, tr);
radii[RectCorner::BottomRight].SizeTo(br, br);
radii[RectCorner::BottomLeft].SizeTo(bl, bl);
radii[eCornerTopLeft].SizeTo(tl, tl);
radii[eCornerTopRight].SizeTo(tr, tr);
radii[eCornerBottomRight].SizeTo(br, br);
radii[eCornerBottomLeft].SizeTo(bl, bl);
}
RectCornerRadii(const Size& tl, const Size& tr,
const Size& br, const Size& bl) {
radii[RectCorner::TopLeft] = tl;
radii[RectCorner::TopRight] = tr;
radii[RectCorner::BottomRight] = br;
radii[RectCorner::BottomLeft] = bl;
radii[eCornerTopLeft] = tl;
radii[eCornerTopRight] = tr;
radii[eCornerBottomRight] = br;
radii[eCornerBottomLeft] = bl;
}
const Size& operator[](size_t aCorner) const {
@ -218,38 +218,35 @@ struct RectCornerRadii {
}
bool operator==(const RectCornerRadii& aOther) const {
for (size_t i = 0; i < RectCorner::Count; i++) {
if (radii[i] != aOther.radii[i]) return false;
}
return true;
return TopLeft() == aOther.TopLeft() &&
TopRight() == aOther.TopRight() &&
BottomRight() == aOther.BottomRight() &&
BottomLeft() == aOther.BottomLeft();
}
bool AreRadiiSame() const {
for (size_t i = 1; i < RectCorner::Count; i++) {
if (radii[i] != radii[0]) {
return false;
}
}
return true;
return TopLeft() == TopRight() &&
TopLeft() == BottomRight() &&
TopLeft() == BottomLeft();
}
void Scale(Float aXScale, Float aYScale) {
for (int i = 0; i < RectCorner::Count; i++) {
NS_FOR_CSS_FULL_CORNERS(i) {
radii[i].Scale(aXScale, aYScale);
}
}
const Size TopLeft() const { return radii[RectCorner::TopLeft]; }
Size& TopLeft() { return radii[RectCorner::TopLeft]; }
const Size TopLeft() const { return radii[eCornerTopLeft]; }
Size& TopLeft() { return radii[eCornerTopLeft]; }
const Size TopRight() const { return radii[RectCorner::TopRight]; }
Size& TopRight() { return radii[RectCorner::TopRight]; }
const Size TopRight() const { return radii[eCornerTopRight]; }
Size& TopRight() { return radii[eCornerTopRight]; }
const Size BottomRight() const { return radii[RectCorner::BottomRight]; }
Size& BottomRight() { return radii[RectCorner::BottomRight]; }
const Size BottomRight() const { return radii[eCornerBottomRight]; }
Size& BottomRight() { return radii[eCornerBottomRight]; }
const Size BottomLeft() const { return radii[RectCorner::BottomLeft]; }
Size& BottomLeft() { return radii[RectCorner::BottomLeft]; }
const Size BottomLeft() const { return radii[eCornerBottomLeft]; }
Size& BottomLeft() { return radii[eCornerBottomLeft]; }
};
/**

View file

@ -7,6 +7,7 @@
#define MOZILLA_GFX_TYPES_H_
#include "mozilla/EndianUtils.h"
#include "mozilla/MacroArgs.h" // for MOZ_CONCAT
#include <stddef.h>
#include <stdint.h>
@ -358,21 +359,6 @@ typedef mozilla::gfx::SurfaceFormat gfxImageFormat;
namespace mozilla {
// We can't use MOZ_BEGIN_ENUM_CLASS here because that prevents the enum
// values from being used for indexing. Wrapping the enum in a struct does at
// least gives us name scoping.
struct RectCorner {
enum {
// This order is important since Rect::AtCorner, AppendRoundedRectToPath
// and other code depends on it!
TopLeft = 0,
TopRight = 1,
BottomRight = 2,
BottomLeft = 3,
Count = 4
};
};
// Side constants for use in various places.
enum Side { eSideTop, eSideRight, eSideBottom, eSideLeft };
@ -387,11 +373,132 @@ enum SideBits {
eSideBitsAll = eSideBitsTopBottom | eSideBitsLeftRight
};
// Creates a for loop that walks over the four mozilla::Side values.
// We use an int32_t helper variable (instead of a Side) for our loop counter,
// to avoid triggering undefined behavior just before we exit the loop (at
// which point the counter is incremented beyond the largest valid Side value).
#define NS_FOR_CSS_SIDES(var_) \
int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eSideTop; \
for (mozilla::Side var_; \
MOZ_CONCAT(var_,__LINE__) <= mozilla::eSideLeft && \
((var_ = mozilla::Side(MOZ_CONCAT(var_,__LINE__))), true); \
++MOZ_CONCAT(var_,__LINE__))
static inline Side& operator++(Side& side) {
MOZ_ASSERT(side >= eSideTop && side <= eSideLeft,
"Out of range side");
side = Side(side + 1);
return side;
}
enum Corner {
// This order is important!
eCornerTopLeft = 0,
eCornerTopRight = 1,
eCornerBottomRight = 2,
eCornerBottomLeft = 3
};
// RectCornerRadii::radii depends on this value. It is not being added to
// Corner because we want to lift the responsibility to handle it in the
// switch-case.
constexpr int eCornerCount = 4;
// Creates a for loop that walks over the four mozilla::Corner values. This
// implementation uses the same technique as NS_FOR_CSS_SIDES.
#define NS_FOR_CSS_FULL_CORNERS(var_) \
int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eCornerTopLeft; \
for (mozilla::Corner var_; \
MOZ_CONCAT(var_,__LINE__) <= mozilla::eCornerBottomLeft && \
(var_ = mozilla::Corner(MOZ_CONCAT(var_,__LINE__)), true); \
++MOZ_CONCAT(var_,__LINE__))
static inline mozilla::Corner operator++(mozilla::Corner& aCorner) {
MOZ_ASSERT(aCorner >= eCornerTopLeft && aCorner <= eCornerBottomLeft,
"Out of range corner!");
aCorner = mozilla::Corner(aCorner + 1);
return aCorner;
}
// Indices into "half corner" arrays (e.g. nsStyleCorners)
enum HalfCorner {
// This order is important!
eCornerTopLeftX = 0,
eCornerTopLeftY = 1,
eCornerTopRightX = 2,
eCornerTopRightY = 3,
eCornerBottomRightX = 4,
eCornerBottomRightY = 5,
eCornerBottomLeftX = 6,
eCornerBottomLeftY = 7
};
// Creates a for loop that walks over the eight mozilla::HalfCorner values.
// This implementation uses the same technique as NS_FOR_CSS_SIDES.
#define NS_FOR_CSS_HALF_CORNERS(var_) \
int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eCornerTopLeftX; \
for (mozilla::HalfCorner var_; \
MOZ_CONCAT(var_,__LINE__) <= mozilla::eCornerBottomLeftY && \
(var_ = mozilla::HalfCorner(MOZ_CONCAT(var_,__LINE__)), true); \
++MOZ_CONCAT(var_,__LINE__))
static inline mozilla::HalfCorner operator++(mozilla::HalfCorner& aHalfCorner) {
MOZ_ASSERT(aHalfCorner >= eCornerTopLeftX && aHalfCorner <= eCornerBottomLeftY,
"Out of range half corner!");
aHalfCorner = mozilla::HalfCorner(aHalfCorner + 1);
return aHalfCorner;
}
// The result of the conversion functions below are exhaustively checked in
// nsStyleCoord.cpp, which also serves as usage examples.
constexpr bool HalfCornerIsX(HalfCorner aHalfCorner)
{
return !(aHalfCorner % 2);
}
constexpr Corner HalfToFullCorner(HalfCorner aHalfCorner)
{
return Corner(aHalfCorner / 2);
}
constexpr HalfCorner FullToHalfCorner(Corner aCorner, bool aIsVertical)
{
return HalfCorner(aCorner * 2 + aIsVertical);
}
constexpr bool SideIsVertical(Side aSide)
{
return aSide % 2;
}
/* @param aIsSecond: when true, return the clockwise second of the two
* corners associated with aSide. For example, with aSide = eSideBottom the
* result is eCornerBottomRight when aIsSecond is false, and
* eCornerBottomLeft when aIsSecond is true.
*/
constexpr Corner SideToFullCorner(Side aSide, bool aIsSecond)
{
return Corner((aSide + aIsSecond) % 4);
}
/* @param aIsSecond: when true, return the clockwise second of the two
* corners associated with aSide. For example, with aSide = eSideBottom the
* result is eCornerBottomRight when aIsSecond is false, and
* eCornerBottomLeft when aIsSecond is true.
* @param aIsParallel: return the half-corner that is parallel with aSide
* when aIsParallel is true. For example with aSide=eSideTop, aIsSecond=true
* the result is eCornerTopRightX when aIsParallel is true, and
* eCornerTopRightY when aIsParallel is false (because "X" is parallel with
* eSideTop/eSideBottom, similarly "Y" is parallel with eSideLeft/eSideRight)
*/
constexpr HalfCorner SideToHalfCorner(Side aSide,
bool aIsSecond,
bool aIsParallel)
{
return HalfCorner(((aSide + aIsSecond) * 2 + (aSide + !aIsParallel) % 2) % 8);
}
} // namespace mozilla
#define NS_SIDE_TOP mozilla::eSideTop
#define NS_SIDE_RIGHT mozilla::eSideRight
#define NS_SIDE_BOTTOM mozilla::eSideBottom
#define NS_SIDE_LEFT mozilla::eSideLeft
#endif /* MOZILLA_GFX_TYPES_H_ */