2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* representation of length values in computed style data */
|
|
|
|
|
1998-04-29 03:54:06 +04:00
|
|
|
#ifndef nsStyleCoord_h___
|
|
|
|
#define nsStyleCoord_h___
|
|
|
|
|
|
|
|
#include "nsCoord.h"
|
2003-01-18 18:58:49 +03:00
|
|
|
#include "nsStyleConsts.h"
|
1998-04-29 03:54:06 +04:00
|
|
|
|
2015-05-11 13:35:47 +03:00
|
|
|
namespace mozilla {
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2015-05-11 13:35:47 +03:00
|
|
|
class WritingMode;
|
|
|
|
|
|
|
|
// Logical axis, edge and side constants for use in various places.
|
|
|
|
enum LogicalAxis {
|
|
|
|
eLogicalAxisBlock = 0x0,
|
|
|
|
eLogicalAxisInline = 0x1
|
|
|
|
};
|
|
|
|
enum LogicalEdge {
|
|
|
|
eLogicalEdgeStart = 0x0,
|
|
|
|
eLogicalEdgeEnd = 0x1
|
|
|
|
};
|
|
|
|
enum LogicalSide {
|
|
|
|
eLogicalSideBStart = (eLogicalAxisBlock << 1) | eLogicalEdgeStart, // 0x0
|
|
|
|
eLogicalSideBEnd = (eLogicalAxisBlock << 1) | eLogicalEdgeEnd, // 0x1
|
|
|
|
eLogicalSideIStart = (eLogicalAxisInline << 1) | eLogicalEdgeStart, // 0x2
|
|
|
|
eLogicalSideIEnd = (eLogicalAxisInline << 1) | eLogicalEdgeEnd // 0x3
|
|
|
|
};
|
2015-07-13 18:25:42 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|
2015-05-11 13:35:47 +03:00
|
|
|
|
2014-06-19 07:17:10 +04:00
|
|
|
enum nsStyleUnit : uint8_t {
|
1998-04-30 23:50:36 +04:00
|
|
|
eStyleUnit_Null = 0, // (no value) value is not specified
|
|
|
|
eStyleUnit_Normal = 1, // (no value)
|
|
|
|
eStyleUnit_Auto = 2, // (no value)
|
2007-05-11 10:01:31 +04:00
|
|
|
eStyleUnit_None = 3, // (no value)
|
1998-04-30 23:50:36 +04:00
|
|
|
eStyleUnit_Percent = 10, // (float) 1.0 == 100%
|
1998-05-13 02:18:42 +04:00
|
|
|
eStyleUnit_Factor = 11, // (float) a multiplier
|
2009-11-02 22:36:43 +03:00
|
|
|
eStyleUnit_Degree = 12, // (float) angle in degrees
|
2009-11-02 22:36:43 +03:00
|
|
|
eStyleUnit_Grad = 13, // (float) angle in grads
|
2009-11-02 22:36:43 +03:00
|
|
|
eStyleUnit_Radian = 14, // (float) angle in radians
|
2012-02-04 09:01:23 +04:00
|
|
|
eStyleUnit_Turn = 15, // (float) angle in turns
|
2014-03-11 02:54:13 +04:00
|
|
|
eStyleUnit_FlexFraction = 16, // (float) <flex> in fr units
|
1998-04-30 23:50:36 +04:00
|
|
|
eStyleUnit_Coord = 20, // (nscoord) value is twips
|
|
|
|
eStyleUnit_Integer = 30, // (int) value is simple integer
|
2010-07-03 08:18:55 +04:00
|
|
|
eStyleUnit_Enumerated = 32, // (int) value has enumerated meaning
|
2010-09-11 20:27:13 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
// The following are reference counted allocated types.
|
|
|
|
eStyleUnit_Calc = 40, // (Calc*) calc() toplevel; always present
|
2010-09-11 20:27:13 +04:00
|
|
|
// to distinguish 50% from calc(50%), etc.
|
2014-06-19 07:18:03 +04:00
|
|
|
|
|
|
|
eStyleUnit_MAX = 40 // highest valid nsStyleUnit value
|
1998-04-29 03:54:06 +04:00
|
|
|
};
|
|
|
|
|
1998-05-13 02:18:42 +04:00
|
|
|
typedef union {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mInt; // nscoord is a int32_t for now
|
1998-05-13 02:18:42 +04:00
|
|
|
float mFloat;
|
2014-06-19 07:18:03 +04:00
|
|
|
// An mPointer is a reference counted pointer. Currently this can only
|
|
|
|
// ever be an nsStyleCoord::Calc*.
|
2010-07-03 08:18:55 +04:00
|
|
|
void* mPointer;
|
1998-05-13 02:18:42 +04:00
|
|
|
} nsStyleUnion;
|
|
|
|
|
2002-07-30 09:34:55 +04:00
|
|
|
/**
|
|
|
|
* Class that hold a single size specification used by the style
|
|
|
|
* system. The size specification consists of two parts -- a number
|
|
|
|
* and a unit. The number is an integer, a floating point value, an
|
|
|
|
* nscoord, or undefined, and the unit is an nsStyleUnit. Checking
|
|
|
|
* the unit is a must before asking for the value in any particular
|
|
|
|
* form.
|
|
|
|
*/
|
1998-04-29 03:54:06 +04:00
|
|
|
class nsStyleCoord {
|
|
|
|
public:
|
2014-06-19 07:18:03 +04:00
|
|
|
// Non-reference counted calc() value. See nsStyleStruct.h for some uses
|
|
|
|
// of this.
|
|
|
|
struct CalcValue {
|
2010-09-11 20:27:13 +04:00
|
|
|
// Every calc() expression evaluates to a length plus a percentage.
|
|
|
|
nscoord mLength;
|
|
|
|
float mPercent;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasPercent; // whether there was any % syntax, even if 0
|
2010-09-11 20:27:13 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
bool operator==(const CalcValue& aOther) const {
|
2010-09-11 20:27:13 +04:00
|
|
|
return mLength == aOther.mLength &&
|
|
|
|
mPercent == aOther.mPercent &&
|
|
|
|
mHasPercent == aOther.mHasPercent;
|
|
|
|
}
|
2014-06-19 07:18:03 +04:00
|
|
|
bool operator!=(const CalcValue& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
2015-11-09 03:40:37 +03:00
|
|
|
|
2016-05-04 00:20:48 +03:00
|
|
|
nscoord ToLength() const {
|
|
|
|
MOZ_ASSERT(!mHasPercent);
|
|
|
|
return mLength;
|
|
|
|
}
|
|
|
|
|
2015-11-09 03:40:37 +03:00
|
|
|
// 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; }
|
2014-06-19 07:18:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Reference counted calc() value. This is the type that is used to store
|
|
|
|
// the calc() value in nsStyleCoord.
|
2015-03-21 19:28:04 +03:00
|
|
|
struct Calc final : public CalcValue {
|
2014-06-19 07:18:03 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(Calc)
|
|
|
|
Calc() {}
|
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
Calc(const Calc&) = delete;
|
2014-06-19 07:18:03 +04:00
|
|
|
~Calc() {}
|
2015-01-07 02:35:02 +03:00
|
|
|
Calc& operator=(const Calc&) = delete;
|
2010-09-11 20:27:13 +04:00
|
|
|
};
|
2010-07-03 08:18:55 +04:00
|
|
|
|
2014-08-08 03:48:38 +04:00
|
|
|
explicit nsStyleCoord(nsStyleUnit aUnit = eStyleUnit_Null);
|
2009-10-14 06:38:20 +04:00
|
|
|
enum CoordConstructorType { CoordConstructor };
|
|
|
|
inline nsStyleCoord(nscoord aValue, CoordConstructorType);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStyleCoord(int32_t aValue, nsStyleUnit aUnit);
|
2001-03-08 05:41:16 +03:00
|
|
|
nsStyleCoord(float aValue, nsStyleUnit aUnit);
|
2008-03-06 03:05:26 +03:00
|
|
|
inline nsStyleCoord(const nsStyleCoord& aCopy);
|
|
|
|
inline nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit);
|
2014-06-19 07:18:03 +04:00
|
|
|
~nsStyleCoord() { Reset(); }
|
1998-04-29 03:54:06 +04:00
|
|
|
|
2012-02-25 09:23:14 +04:00
|
|
|
nsStyleCoord& operator=(const nsStyleCoord& aOther)
|
|
|
|
{
|
2014-06-19 07:18:03 +04:00
|
|
|
if (this != &aOther) {
|
|
|
|
SetValue(mUnit, mValue, aOther);
|
|
|
|
}
|
2012-02-25 09:23:14 +04:00
|
|
|
return *this;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator==(const nsStyleCoord& aOther) const;
|
|
|
|
bool operator!=(const nsStyleCoord& aOther) const;
|
1998-04-29 03:54:06 +04:00
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
nsStyleUnit GetUnit() const {
|
2007-05-11 10:02:31 +04:00
|
|
|
NS_ASSERTION(mUnit != eStyleUnit_Null, "reading uninitialized value");
|
|
|
|
return mUnit;
|
|
|
|
}
|
2009-09-10 23:03:36 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsAngleValue() const {
|
2012-02-04 09:01:23 +04:00
|
|
|
return eStyleUnit_Degree <= mUnit && mUnit <= eStyleUnit_Turn;
|
2009-11-02 22:36:43 +03:00
|
|
|
}
|
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
static bool IsCalcUnit(nsStyleUnit aUnit) {
|
|
|
|
return aUnit == eStyleUnit_Calc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsPointerUnit(nsStyleUnit aUnit) {
|
|
|
|
return IsCalcUnit(aUnit);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCalcUnit() const {
|
2014-06-19 07:18:03 +04:00
|
|
|
return IsCalcUnit(mUnit);
|
2010-09-11 20:27:13 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPointerValue() const {
|
2014-06-19 07:18:03 +04:00
|
|
|
return IsPointerUnit(mUnit);
|
2010-07-03 08:18:55 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCoordPercentCalcUnit() const {
|
2010-08-11 23:32:53 +04:00
|
|
|
return mUnit == eStyleUnit_Coord ||
|
|
|
|
mUnit == eStyleUnit_Percent ||
|
|
|
|
IsCalcUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does this calc() expression have any percentages inside it? Can be
|
|
|
|
// called only when IsCalcUnit() is true.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CalcHasPercent() const {
|
2010-09-11 20:27:13 +04:00
|
|
|
return GetCalcValue()->mHasPercent;
|
2010-07-03 08:18:55 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasPercent() const {
|
2010-08-25 14:17:55 +04:00
|
|
|
return mUnit == eStyleUnit_Percent ||
|
|
|
|
(IsCalcUnit() && CalcHasPercent());
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ConvertsToLength() const {
|
2010-08-25 14:17:55 +04:00
|
|
|
return mUnit == eStyleUnit_Coord ||
|
|
|
|
(IsCalcUnit() && !CalcHasPercent());
|
|
|
|
}
|
|
|
|
|
2016-05-04 00:20:48 +03:00
|
|
|
nscoord ToLength() const {
|
|
|
|
MOZ_ASSERT(ConvertsToLength());
|
|
|
|
if (GetUnit() == eStyleUnit_Coord) {
|
|
|
|
return GetCoordValue();
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(IsCalcUnit() && !CalcHasPercent());
|
|
|
|
return GetCalcValue()->ToLength();
|
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
nscoord GetCoordValue() const;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetIntValue() const;
|
2010-05-11 19:49:44 +04:00
|
|
|
float GetPercentValue() const;
|
|
|
|
float GetFactorValue() const;
|
2014-08-21 04:52:28 +04:00
|
|
|
float GetFactorOrPercentValue() const;
|
2010-05-11 19:49:44 +04:00
|
|
|
float GetAngleValue() const;
|
2014-08-21 02:46:59 +04:00
|
|
|
double GetAngleValueInDegrees() const;
|
2010-05-11 19:49:44 +04:00
|
|
|
double GetAngleValueInRadians() const;
|
2014-03-11 02:54:13 +04:00
|
|
|
float GetFlexFractionValue() const;
|
2010-09-11 20:27:13 +04:00
|
|
|
Calc* GetCalcValue() const;
|
2012-08-27 08:08:32 +04:00
|
|
|
uint32_t HashValue(uint32_t aHash) const;
|
1998-04-29 03:54:06 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
// Sets to null and releases any refcounted objects. Only use this if the
|
|
|
|
// object is initialized (i.e. don't use it in nsStyleCoord constructors).
|
|
|
|
void Reset();
|
|
|
|
|
2001-03-08 05:41:16 +03:00
|
|
|
void SetCoordValue(nscoord aValue);
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetIntValue(int32_t aValue, nsStyleUnit aUnit);
|
2001-03-08 05:41:16 +03:00
|
|
|
void SetPercentValue(float aValue);
|
|
|
|
void SetFactorValue(float aValue);
|
2009-11-02 22:36:43 +03:00
|
|
|
void SetAngleValue(float aValue, nsStyleUnit aUnit);
|
2014-03-11 02:54:13 +04:00
|
|
|
void SetFlexFractionValue(float aValue);
|
2010-05-11 19:49:44 +04:00
|
|
|
void SetNormalValue();
|
|
|
|
void SetAutoValue();
|
|
|
|
void SetNoneValue();
|
2010-09-11 20:27:13 +04:00
|
|
|
void SetCalcValue(Calc* aValue);
|
1998-04-29 03:54:06 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
// Resets a coord represented by a unit/value pair.
|
|
|
|
static inline void Reset(nsStyleUnit& aUnit, nsStyleUnion& aValue);
|
|
|
|
|
|
|
|
// Sets a coord represented by a unit/value pair from a second
|
|
|
|
// unit/value pair.
|
|
|
|
static inline void SetValue(nsStyleUnit& aUnit,
|
|
|
|
nsStyleUnion& aValue,
|
|
|
|
nsStyleUnit aOtherUnit,
|
|
|
|
const nsStyleUnion& aOtherValue);
|
|
|
|
|
|
|
|
// Sets a coord represented by a unit/value pair from an nsStyleCoord.
|
|
|
|
static inline void SetValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
|
|
|
|
const nsStyleCoord& aOther);
|
|
|
|
|
2012-02-25 09:23:14 +04:00
|
|
|
private:
|
1998-05-13 02:18:42 +04:00
|
|
|
nsStyleUnit mUnit;
|
|
|
|
nsStyleUnion mValue;
|
1998-04-29 03:54:06 +04:00
|
|
|
};
|
|
|
|
|
2002-07-30 09:34:55 +04:00
|
|
|
/**
|
|
|
|
* Class that represents a set of top/right/bottom/left nsStyleCoords.
|
|
|
|
* This is commonly used to hold the widths of the borders, margins,
|
|
|
|
* or paddings of a box.
|
|
|
|
*/
|
1998-05-13 02:18:42 +04:00
|
|
|
class nsStyleSides {
|
|
|
|
public:
|
2010-05-11 19:49:44 +04:00
|
|
|
nsStyleSides();
|
2014-06-19 07:18:03 +04:00
|
|
|
nsStyleSides(const nsStyleSides&);
|
|
|
|
~nsStyleSides();
|
1998-05-13 02:18:42 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
nsStyleSides& operator=(const nsStyleSides& aCopy);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator==(const nsStyleSides& aOther) const;
|
|
|
|
bool operator!=(const nsStyleSides& aOther) const;
|
1998-05-13 02:18:42 +04:00
|
|
|
|
2010-04-27 20:15:02 +04:00
|
|
|
inline nsStyleUnit GetUnit(mozilla::css::Side aSide) const;
|
2010-05-11 19:49:44 +04:00
|
|
|
inline nsStyleUnit GetLeftUnit() const;
|
|
|
|
inline nsStyleUnit GetTopUnit() const;
|
|
|
|
inline nsStyleUnit GetRightUnit() const;
|
|
|
|
inline nsStyleUnit GetBottomUnit() const;
|
2003-01-18 18:58:49 +03:00
|
|
|
|
2010-04-27 20:15:02 +04:00
|
|
|
inline nsStyleCoord Get(mozilla::css::Side aSide) const;
|
2008-03-06 03:05:26 +03:00
|
|
|
inline nsStyleCoord GetLeft() const;
|
|
|
|
inline nsStyleCoord GetTop() const;
|
|
|
|
inline nsStyleCoord GetRight() const;
|
|
|
|
inline nsStyleCoord GetBottom() const;
|
1998-05-13 02:18:42 +04:00
|
|
|
|
2015-05-11 13:35:47 +03:00
|
|
|
// Methods to access the units and values in terms of logical sides
|
|
|
|
// for a given writing mode.
|
|
|
|
// NOTE: The definitions are in WritingModes.h (after we have the full
|
|
|
|
// declaration of WritingMode available).
|
|
|
|
inline nsStyleUnit GetUnit(mozilla::WritingMode aWritingMode,
|
|
|
|
mozilla::LogicalSide aSide) const;
|
|
|
|
inline nsStyleUnit GetIStartUnit(mozilla::WritingMode aWritingMode) const;
|
|
|
|
inline nsStyleUnit GetBStartUnit(mozilla::WritingMode aWritingMode) const;
|
|
|
|
inline nsStyleUnit GetIEndUnit(mozilla::WritingMode aWritingMode) const;
|
|
|
|
inline nsStyleUnit GetBEndUnit(mozilla::WritingMode aWritingMode) const;
|
|
|
|
|
|
|
|
inline nsStyleCoord Get(mozilla::WritingMode aWritingMode,
|
|
|
|
mozilla::LogicalSide aSide) const;
|
|
|
|
inline nsStyleCoord GetIStart(mozilla::WritingMode aWritingMode) const;
|
|
|
|
inline nsStyleCoord GetBStart(mozilla::WritingMode aWritingMode) const;
|
|
|
|
inline nsStyleCoord GetIEnd(mozilla::WritingMode aWritingMode) const;
|
|
|
|
inline nsStyleCoord GetBEnd(mozilla::WritingMode aWritingMode) const;
|
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
// Sets each side to null and releases any refcounted objects. Only use this
|
|
|
|
// if the object is initialized (i.e. don't use it in nsStyleSides
|
|
|
|
// constructors).
|
|
|
|
void Reset();
|
2003-01-18 18:58:49 +03:00
|
|
|
|
2010-04-27 20:15:02 +04:00
|
|
|
inline void Set(mozilla::css::Side aSide, const nsStyleCoord& aCoord);
|
2003-01-18 18:58:49 +03:00
|
|
|
inline void SetLeft(const nsStyleCoord& aCoord);
|
|
|
|
inline void SetTop(const nsStyleCoord& aCoord);
|
|
|
|
inline void SetRight(const nsStyleCoord& aCoord);
|
|
|
|
inline void SetBottom(const nsStyleCoord& aCoord);
|
1998-05-13 02:18:42 +04:00
|
|
|
|
2016-05-04 00:20:48 +03:00
|
|
|
bool ConvertsToLength() const {
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
if (!Get(side).ConvertsToLength()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
1998-05-13 02:18:42 +04:00
|
|
|
protected:
|
2014-06-19 07:17:10 +04:00
|
|
|
nsStyleUnit mUnits[4];
|
2003-01-18 18:58:49 +03:00
|
|
|
nsStyleUnion mValues[4];
|
1998-05-13 02:18:42 +04:00
|
|
|
};
|
|
|
|
|
2008-10-01 09:50:52 +04:00
|
|
|
/**
|
|
|
|
* Class that represents a set of top-left/top-right/bottom-left/bottom-right
|
|
|
|
* nsStyleCoord pairs. This is used to hold the dimensions of the
|
|
|
|
* corners of a box (for, e.g., border-radius and outline-radius).
|
|
|
|
*/
|
|
|
|
class nsStyleCorners {
|
|
|
|
public:
|
2010-05-11 19:49:44 +04:00
|
|
|
nsStyleCorners();
|
2014-06-19 07:18:03 +04:00
|
|
|
nsStyleCorners(const nsStyleCorners&);
|
|
|
|
~nsStyleCorners();
|
2008-10-01 09:50:52 +04:00
|
|
|
|
|
|
|
// use compiler's version
|
2014-06-19 07:18:03 +04:00
|
|
|
nsStyleCorners& operator=(const nsStyleCorners& aCopy);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator==(const nsStyleCorners& aOther) const;
|
|
|
|
bool operator!=(const nsStyleCorners& aOther) const;
|
2008-10-01 09:50:52 +04:00
|
|
|
|
|
|
|
// aCorner is always one of NS_CORNER_* defined in nsStyleConsts.h
|
2012-08-22 19:56:38 +04:00
|
|
|
inline nsStyleUnit GetUnit(uint8_t aHalfCorner) const;
|
2008-10-01 09:50:52 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline nsStyleCoord Get(uint8_t aHalfCorner) const;
|
2008-10-01 09:50:52 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
// Sets each corner to null and releases any refcounted objects. Only use
|
|
|
|
// this if the object is initialized (i.e. don't use it in nsStyleCorners
|
|
|
|
// constructors).
|
|
|
|
void Reset();
|
2008-10-01 09:50:52 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline void Set(uint8_t aHalfCorner, const nsStyleCoord& aCoord);
|
2008-10-01 09:50:52 +04:00
|
|
|
|
|
|
|
protected:
|
2014-06-19 07:17:10 +04:00
|
|
|
nsStyleUnit mUnits[8];
|
2008-10-01 09:50:52 +04:00
|
|
|
nsStyleUnion mValues[8];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-05-13 02:18:42 +04:00
|
|
|
// -------------------------
|
|
|
|
// nsStyleCoord inlines
|
|
|
|
//
|
2009-10-14 06:38:20 +04:00
|
|
|
inline nsStyleCoord::nsStyleCoord(nscoord aValue, CoordConstructorType)
|
|
|
|
: mUnit(eStyleUnit_Coord)
|
|
|
|
{
|
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
|
2008-03-06 03:05:26 +03:00
|
|
|
inline nsStyleCoord::nsStyleCoord(const nsStyleCoord& aCopy)
|
2014-06-19 07:18:03 +04:00
|
|
|
: mUnit(eStyleUnit_Null)
|
2008-03-06 03:05:26 +03:00
|
|
|
{
|
2014-06-19 07:18:03 +04:00
|
|
|
SetValue(mUnit, mValue, aCopy);
|
2008-03-06 03:05:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline nsStyleCoord::nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit)
|
2014-06-19 07:18:03 +04:00
|
|
|
: mUnit(eStyleUnit_Null)
|
2008-03-06 03:05:26 +03:00
|
|
|
{
|
2014-06-19 07:18:03 +04:00
|
|
|
SetValue(mUnit, mValue, aUnit, aValue);
|
2008-03-06 03:05:26 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool nsStyleCoord::operator!=(const nsStyleCoord& aOther) const
|
1999-07-18 04:13:08 +04:00
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
return !((*this) == aOther);
|
1999-07-18 04:13:08 +04:00
|
|
|
}
|
|
|
|
|
2012-04-07 04:01:32 +04:00
|
|
|
inline nscoord nsStyleCoord::GetCoordValue() const
|
1998-04-29 03:54:06 +04:00
|
|
|
{
|
1998-04-30 23:50:36 +04:00
|
|
|
NS_ASSERTION((mUnit == eStyleUnit_Coord), "not a coord value");
|
|
|
|
if (mUnit == eStyleUnit_Coord) {
|
1998-04-29 03:54:06 +04:00
|
|
|
return mValue.mInt;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline int32_t nsStyleCoord::GetIntValue() const
|
1998-04-29 03:54:06 +04:00
|
|
|
{
|
2007-05-11 10:00:26 +04:00
|
|
|
NS_ASSERTION((mUnit == eStyleUnit_Enumerated) ||
|
1998-04-30 23:50:36 +04:00
|
|
|
(mUnit == eStyleUnit_Integer), "not an int value");
|
2007-05-11 10:00:26 +04:00
|
|
|
if ((mUnit == eStyleUnit_Enumerated) ||
|
1998-04-30 23:50:36 +04:00
|
|
|
(mUnit == eStyleUnit_Integer)) {
|
1998-04-29 03:54:06 +04:00
|
|
|
return mValue.mInt;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
inline float nsStyleCoord::GetPercentValue() const
|
1998-04-29 03:54:06 +04:00
|
|
|
{
|
1998-04-30 23:50:36 +04:00
|
|
|
NS_ASSERTION(mUnit == eStyleUnit_Percent, "not a percent value");
|
1998-04-29 03:54:06 +04:00
|
|
|
if (mUnit == eStyleUnit_Percent) {
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
inline float nsStyleCoord::GetFactorValue() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eStyleUnit_Factor, "not a factor value");
|
|
|
|
if (mUnit == eStyleUnit_Factor) {
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2014-08-21 04:52:28 +04:00
|
|
|
inline float nsStyleCoord::GetFactorOrPercentValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent,
|
|
|
|
"not a percent or factor value");
|
|
|
|
if (mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent) {
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
inline float nsStyleCoord::GetAngleValue() const
|
2009-11-02 22:36:43 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit >= eStyleUnit_Degree &&
|
2012-02-04 09:01:23 +04:00
|
|
|
mUnit <= eStyleUnit_Turn, "not an angle value");
|
|
|
|
if (mUnit >= eStyleUnit_Degree && mUnit <= eStyleUnit_Turn) {
|
2009-11-02 22:36:43 +03:00
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2014-03-11 02:54:13 +04:00
|
|
|
inline float nsStyleCoord::GetFlexFractionValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eStyleUnit_FlexFraction, "not a fr value");
|
|
|
|
if (mUnit == eStyleUnit_FlexFraction) {
|
|
|
|
return mValue.mFloat;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2010-09-11 20:27:13 +04:00
|
|
|
inline nsStyleCoord::Calc* nsStyleCoord::GetCalcValue() const
|
2010-07-03 08:18:55 +04:00
|
|
|
{
|
2010-09-11 20:27:13 +04:00
|
|
|
NS_ASSERTION(IsCalcUnit(), "not a pointer value");
|
|
|
|
if (IsCalcUnit()) {
|
|
|
|
return static_cast<Calc*>(mValue.mPointer);
|
2010-07-03 08:18:55 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-07-03 08:18:55 +04:00
|
|
|
}
|
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
/* static */ inline void
|
|
|
|
nsStyleCoord::Reset(nsStyleUnit& aUnit, nsStyleUnion& aValue)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aUnit <= eStyleUnit_MAX,
|
|
|
|
"calling Reset on uninitialized nsStyleCoord?");
|
|
|
|
|
|
|
|
switch (aUnit) {
|
|
|
|
case eStyleUnit_Calc:
|
|
|
|
static_cast<Calc*>(aValue.mPointer)->Release();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic");
|
|
|
|
}
|
|
|
|
|
|
|
|
aUnit = eStyleUnit_Null;
|
|
|
|
aValue.mInt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline void
|
|
|
|
nsStyleCoord::SetValue(nsStyleUnit& aUnit,
|
|
|
|
nsStyleUnion& aValue,
|
|
|
|
nsStyleUnit aOtherUnit,
|
|
|
|
const nsStyleUnion& aOtherValue)
|
|
|
|
{
|
|
|
|
Reset(aUnit, aValue);
|
|
|
|
|
|
|
|
aUnit = aOtherUnit;
|
|
|
|
aValue = aOtherValue;
|
2010-07-03 08:18:55 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
switch (aUnit) {
|
|
|
|
case eStyleUnit_Calc:
|
|
|
|
static_cast<Calc*>(aValue.mPointer)->AddRef();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline void
|
|
|
|
nsStyleCoord::SetValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
|
|
|
|
const nsStyleCoord& aOther)
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2014-06-19 07:18:03 +04:00
|
|
|
SetValue(aUnit, aValue, aOther.mUnit, aOther.mValue);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
1998-04-29 03:54:06 +04:00
|
|
|
|
2014-06-19 07:18:03 +04:00
|
|
|
|
1998-05-13 02:18:42 +04:00
|
|
|
// -------------------------
|
|
|
|
// nsStyleSides inlines
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool nsStyleSides::operator!=(const nsStyleSides& aOther) const
|
1999-07-18 04:13:08 +04:00
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
return !((*this) == aOther);
|
1999-07-18 04:13:08 +04:00
|
|
|
}
|
|
|
|
|
2010-04-27 20:15:02 +04:00
|
|
|
inline nsStyleUnit nsStyleSides::GetUnit(mozilla::css::Side aSide) const
|
2003-01-18 18:58:49 +03:00
|
|
|
{
|
|
|
|
return (nsStyleUnit)mUnits[aSide];
|
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
inline nsStyleUnit nsStyleSides::GetLeftUnit() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
return GetUnit(NS_SIDE_LEFT);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
inline nsStyleUnit nsStyleSides::GetTopUnit() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
return GetUnit(NS_SIDE_TOP);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
inline nsStyleUnit nsStyleSides::GetRightUnit() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
return GetUnit(NS_SIDE_RIGHT);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
2010-05-11 19:49:44 +04:00
|
|
|
inline nsStyleUnit nsStyleSides::GetBottomUnit() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
return GetUnit(NS_SIDE_BOTTOM);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
2010-04-27 20:15:02 +04:00
|
|
|
inline nsStyleCoord nsStyleSides::Get(mozilla::css::Side aSide) const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2008-03-06 03:05:26 +03:00
|
|
|
return nsStyleCoord(mValues[aSide], nsStyleUnit(mUnits[aSide]));
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
2008-03-06 03:05:26 +03:00
|
|
|
inline nsStyleCoord nsStyleSides::GetLeft() const
|
2003-01-18 18:58:49 +03:00
|
|
|
{
|
2008-03-06 03:05:26 +03:00
|
|
|
return Get(NS_SIDE_LEFT);
|
2003-01-18 18:58:49 +03:00
|
|
|
}
|
|
|
|
|
2008-03-06 03:05:26 +03:00
|
|
|
inline nsStyleCoord nsStyleSides::GetTop() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2008-03-06 03:05:26 +03:00
|
|
|
return Get(NS_SIDE_TOP);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
2008-03-06 03:05:26 +03:00
|
|
|
inline nsStyleCoord nsStyleSides::GetRight() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2008-03-06 03:05:26 +03:00
|
|
|
return Get(NS_SIDE_RIGHT);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
2008-03-06 03:05:26 +03:00
|
|
|
inline nsStyleCoord nsStyleSides::GetBottom() const
|
1998-05-13 02:18:42 +04:00
|
|
|
{
|
2008-03-06 03:05:26 +03:00
|
|
|
return Get(NS_SIDE_BOTTOM);
|
2003-01-18 18:58:49 +03:00
|
|
|
}
|
|
|
|
|
2010-04-27 20:15:02 +04:00
|
|
|
inline void nsStyleSides::Set(mozilla::css::Side aSide, const nsStyleCoord& aCoord)
|
2003-01-18 18:58:49 +03:00
|
|
|
{
|
2014-06-19 07:18:03 +04:00
|
|
|
nsStyleCoord::SetValue(mUnits[aSide], mValues[aSide], aCoord);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void nsStyleSides::SetLeft(const nsStyleCoord& aCoord)
|
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
Set(NS_SIDE_LEFT, aCoord);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void nsStyleSides::SetTop(const nsStyleCoord& aCoord)
|
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
Set(NS_SIDE_TOP, aCoord);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void nsStyleSides::SetRight(const nsStyleCoord& aCoord)
|
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
Set(NS_SIDE_RIGHT, aCoord);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void nsStyleSides::SetBottom(const nsStyleCoord& aCoord)
|
|
|
|
{
|
2003-01-18 18:58:49 +03:00
|
|
|
Set(NS_SIDE_BOTTOM, aCoord);
|
1998-05-13 02:18:42 +04:00
|
|
|
}
|
1998-04-29 03:54:06 +04:00
|
|
|
|
2008-10-01 09:50:52 +04:00
|
|
|
// -------------------------
|
|
|
|
// nsStyleCorners inlines
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool nsStyleCorners::operator!=(const nsStyleCorners& aOther) const
|
2008-10-01 09:50:52 +04:00
|
|
|
{
|
|
|
|
return !((*this) == aOther);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline nsStyleUnit nsStyleCorners::GetUnit(uint8_t aCorner) const
|
2008-10-01 09:50:52 +04:00
|
|
|
{
|
|
|
|
return (nsStyleUnit)mUnits[aCorner];
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline nsStyleCoord nsStyleCorners::Get(uint8_t aCorner) const
|
2008-10-01 09:50:52 +04:00
|
|
|
{
|
|
|
|
return nsStyleCoord(mValues[aCorner], nsStyleUnit(mUnits[aCorner]));
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline void nsStyleCorners::Set(uint8_t aCorner, const nsStyleCoord& aCoord)
|
2008-10-01 09:50:52 +04:00
|
|
|
{
|
2014-06-19 07:18:03 +04:00
|
|
|
nsStyleCoord::SetValue(mUnits[aCorner], mValues[aCorner], aCoord);
|
2008-10-01 09:50:52 +04:00
|
|
|
}
|
|
|
|
|
1998-04-29 03:54:06 +04:00
|
|
|
#endif /* nsStyleCoord_h___ */
|