mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-20 23:37:33 +09:00
Support CSS sizing math functions
This commit is contained in:
parent
7766f8f53d
commit
c47cea4ddf
12 changed files with 1234 additions and 28 deletions
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "nsCoord.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
|
@ -106,7 +108,44 @@ public:
|
|||
|
||||
// If this returns true the value is definitely zero. It it returns false
|
||||
// it might be zero. So it's best used for conservative optimization.
|
||||
bool IsDefinitelyZero() const { return mLength == 0 && mPercent == 0; }
|
||||
bool IsDefinitelyZero() const {
|
||||
return mLength == 0 && mPercent == 0 && !mHasPercent;
|
||||
}
|
||||
};
|
||||
|
||||
struct CalcNode final {
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CalcNode)
|
||||
|
||||
enum class Type : uint8_t {
|
||||
Leaf,
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
Min,
|
||||
Max,
|
||||
Clamp
|
||||
};
|
||||
|
||||
static already_AddRefed<CalcNode> CreateLeaf(nscoord aLength,
|
||||
float aPercent,
|
||||
bool aHasPercent);
|
||||
static already_AddRefed<CalcNode> Create(Type aType);
|
||||
|
||||
bool HasPercent() const;
|
||||
bool Equals(const CalcNode& aOther) const;
|
||||
uint32_t HashValue(uint32_t aHash) const;
|
||||
|
||||
Type mType;
|
||||
nscoord mLength;
|
||||
float mPercent;
|
||||
float mNumber;
|
||||
bool mHasPercent;
|
||||
nsTArray<RefPtr<CalcNode>> mChildren;
|
||||
|
||||
private:
|
||||
explicit CalcNode(Type aType);
|
||||
~CalcNode() {}
|
||||
};
|
||||
|
||||
// Reference counted calc() value. This is the type that is used to store
|
||||
|
|
@ -115,6 +154,11 @@ public:
|
|||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Calc)
|
||||
Calc() {}
|
||||
|
||||
bool HasCalcNode() const { return !!mNode; }
|
||||
nscoord Resolve(nscoord aPercentageBasis) const;
|
||||
|
||||
RefPtr<CalcNode> mNode;
|
||||
|
||||
private:
|
||||
Calc(const Calc&) = delete;
|
||||
~Calc() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue