mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 09:18:42 +09:00
Issue #1925 - Convert NS_SIDE_TO_HALF_CORNER to a constexpr function.
This commit is contained in:
parent
2a399b60a1
commit
c096b46278
4 changed files with 29 additions and 15 deletions
|
|
@ -459,6 +459,9 @@ static inline mozilla::HalfCorner operator++(mozilla::HalfCorner& aHalfCorner) {
|
|||
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);
|
||||
|
|
@ -489,6 +492,23 @@ 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
|
||||
|
||||
#endif /* MOZILLA_GFX_TYPES_H_ */
|
||||
|
|
|
|||
|
|
@ -1284,8 +1284,8 @@ nsIFrame::ComputeBorderRadii(const nsStyleCorners& aBorderRadius,
|
|||
bool haveRadius = false;
|
||||
double ratio = 1.0f;
|
||||
NS_FOR_CSS_SIDES(side) {
|
||||
uint32_t hc1 = NS_SIDE_TO_HALF_CORNER(side, false, true);
|
||||
uint32_t hc2 = NS_SIDE_TO_HALF_CORNER(side, true, true);
|
||||
uint32_t hc1 = SideToHalfCorner(side, false, true);
|
||||
uint32_t hc2 = SideToHalfCorner(side, true, true);
|
||||
nscoord length =
|
||||
SideIsVertical(side) ? aBorderArea.height : aBorderArea.width;
|
||||
nscoord sum = aRadii[hc1] + aRadii[hc2];
|
||||
|
|
@ -1310,8 +1310,8 @@ nsIFrame::InsetBorderRadii(nscoord aRadii[8], const nsMargin &aOffsets)
|
|||
{
|
||||
NS_FOR_CSS_SIDES(side) {
|
||||
nscoord offset = aOffsets.Side(side);
|
||||
uint32_t hc1 = NS_SIDE_TO_HALF_CORNER(side, false, false);
|
||||
uint32_t hc2 = NS_SIDE_TO_HALF_CORNER(side, true, false);
|
||||
uint32_t hc1 = SideToHalfCorner(side, false, false);
|
||||
uint32_t hc2 = SideToHalfCorner(side, true, false);
|
||||
aRadii[hc1] = std::max(0, aRadii[hc1] - offset);
|
||||
aRadii[hc2] = std::max(0, aRadii[hc2] - offset);
|
||||
}
|
||||
|
|
@ -1322,8 +1322,8 @@ nsIFrame::OutsetBorderRadii(nscoord aRadii[8], const nsMargin &aOffsets)
|
|||
{
|
||||
NS_FOR_CSS_SIDES(side) {
|
||||
nscoord offset = aOffsets.Side(side);
|
||||
uint32_t hc1 = NS_SIDE_TO_HALF_CORNER(side, false, false);
|
||||
uint32_t hc2 = NS_SIDE_TO_HALF_CORNER(side, true, false);
|
||||
uint32_t hc1 = SideToHalfCorner(side, false, false);
|
||||
uint32_t hc2 = SideToHalfCorner(side, true, false);
|
||||
if (aRadii[hc1] > 0)
|
||||
aRadii[hc1] += offset;
|
||||
if (aRadii[hc2] > 0)
|
||||
|
|
|
|||
|
|
@ -16,13 +16,6 @@
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
// The results of these conversion macros are exhaustively checked in
|
||||
// nsStyleCoord.cpp.
|
||||
// Arguments must not have side effects.
|
||||
|
||||
#define NS_SIDE_TO_HALF_CORNER(side_, second_, parallel_) \
|
||||
((((side_) + !!(second_))*2 + ((side_) + !(parallel_))%2) % 8)
|
||||
|
||||
// Basic shapes
|
||||
enum class StyleBasicShapeType : uint8_t {
|
||||
Polygon,
|
||||
|
|
|
|||
|
|
@ -397,9 +397,10 @@ CASE(eSideLeft, false, eCornerBottomLeft);
|
|||
CASE(eSideLeft, true, eCornerTopLeft);
|
||||
#undef CASE
|
||||
|
||||
//Validation of SideToHalfCorner.
|
||||
#define CASE(side, second, parallel, result) \
|
||||
static_assert(NS_SIDE_TO_HALF_CORNER(side, second, parallel) == result, \
|
||||
"NS_SIDE_TO_HALF_CORNER is wrong")
|
||||
static_assert(SideToHalfCorner(side, second, parallel) == result, \
|
||||
"SideToHalfCorner is wrong")
|
||||
CASE(eSideTop, false, true, eCornerTopLeftX);
|
||||
CASE(eSideTop, false, false, eCornerTopLeftY);
|
||||
CASE(eSideTop, true, true, eCornerTopRightX);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue