LCOV - code coverage report
Current view: top level - layout/style - nsStyleCoord.h (source / functions) Hit Total Coverage
Test: output.info Lines: 147 179 82.1 %
Date: 2017-07-14 16:53:18 Functions: 51 60 85.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /* representation of length values in computed style data */
       7             : 
       8             : #ifndef nsStyleCoord_h___
       9             : #define nsStyleCoord_h___
      10             : 
      11             : #include <type_traits>
      12             : 
      13             : #include "mozilla/EnumTypeTraits.h"
      14             : #include "nsCoord.h"
      15             : #include "nsStyleConsts.h"
      16             : 
      17             : namespace mozilla {
      18             : 
      19             : class WritingMode;
      20             : 
      21             : // Logical axis, edge, side and corner constants for use in various places.
      22             : enum LogicalAxis {
      23             :   eLogicalAxisBlock  = 0x0,
      24             :   eLogicalAxisInline = 0x1
      25             : };
      26             : enum LogicalEdge {
      27             :   eLogicalEdgeStart  = 0x0,
      28             :   eLogicalEdgeEnd    = 0x1
      29             : };
      30             : enum LogicalSide {
      31             :   eLogicalSideBStart = (eLogicalAxisBlock  << 1) | eLogicalEdgeStart,  // 0x0
      32             :   eLogicalSideBEnd   = (eLogicalAxisBlock  << 1) | eLogicalEdgeEnd,    // 0x1
      33             :   eLogicalSideIStart = (eLogicalAxisInline << 1) | eLogicalEdgeStart,  // 0x2
      34             :   eLogicalSideIEnd   = (eLogicalAxisInline << 1) | eLogicalEdgeEnd     // 0x3
      35             : };
      36             : 
      37             : enum LogicalCorner
      38             : {
      39             :   eLogicalCornerBStartIStart = 0,
      40             :   eLogicalCornerBStartIEnd   = 1,
      41             :   eLogicalCornerBEndIEnd     = 2,
      42             :   eLogicalCornerBEndIStart   = 3
      43             : };
      44             : 
      45             : } // namespace mozilla
      46             : 
      47             : enum nsStyleUnit : uint8_t {
      48             :   eStyleUnit_Null         = 0,      // (no value) value is not specified
      49             :   eStyleUnit_Normal       = 1,      // (no value)
      50             :   eStyleUnit_Auto         = 2,      // (no value)
      51             :   eStyleUnit_None         = 3,      // (no value)
      52             :   eStyleUnit_Percent      = 10,     // (float) 1.0 == 100%
      53             :   eStyleUnit_Factor       = 11,     // (float) a multiplier
      54             :   eStyleUnit_Degree       = 12,     // (float) angle in degrees
      55             :   eStyleUnit_Grad         = 13,     // (float) angle in grads
      56             :   eStyleUnit_Radian       = 14,     // (float) angle in radians
      57             :   eStyleUnit_Turn         = 15,     // (float) angle in turns
      58             :   eStyleUnit_FlexFraction = 16,     // (float) <flex> in fr units
      59             :   eStyleUnit_Coord        = 20,     // (nscoord) value is twips
      60             :   eStyleUnit_Integer      = 30,     // (int) value is simple integer
      61             :   eStyleUnit_Enumerated   = 32,     // (int) value has enumerated meaning
      62             : 
      63             :   // The following are reference counted allocated types.
      64             :   eStyleUnit_Calc         = 40,     // (Calc*) calc() toplevel; always present
      65             :                                     // to distinguish 50% from calc(50%), etc.
      66             : 
      67             :   eStyleUnit_MAX          = 40      // highest valid nsStyleUnit value
      68             : };
      69             : 
      70             : typedef union {
      71             :   int32_t     mInt;   // nscoord is a int32_t for now
      72             :   float       mFloat;
      73             :   // An mPointer is a reference counted pointer.  Currently this can only
      74             :   // ever be an nsStyleCoord::Calc*.
      75             :   void*       mPointer;
      76             : } nsStyleUnion;
      77             : 
      78             : /**
      79             :  * Class that hold a single size specification used by the style
      80             :  * system.  The size specification consists of two parts -- a number
      81             :  * and a unit.  The number is an integer, a floating point value, an
      82             :  * nscoord, or undefined, and the unit is an nsStyleUnit.  Checking
      83             :  * the unit is a must before asking for the value in any particular
      84             :  * form.
      85             :  */
      86             :  /** <div rustbindgen private accessor="unsafe"></div> */
      87             : class nsStyleCoord {
      88             : public:
      89             :   // Non-reference counted calc() value.  See nsStyleStruct.h for some uses
      90             :   // of this.
      91         127 :   struct CalcValue {
      92             :     // Every calc() expression evaluates to a length plus a percentage.
      93             :     nscoord mLength;
      94             :     float mPercent;
      95             :     bool mHasPercent; // whether there was any % syntax, even if 0
      96             : 
      97        2595 :     bool operator==(const CalcValue& aOther) const {
      98        5190 :       return mLength == aOther.mLength &&
      99        5190 :              mPercent == aOther.mPercent &&
     100        5190 :              mHasPercent == aOther.mHasPercent;
     101             :     }
     102             :     bool operator!=(const CalcValue& aOther) const {
     103             :       return !(*this == aOther);
     104             :     }
     105             : 
     106        1314 :     nscoord ToLength() const {
     107        1314 :       MOZ_ASSERT(!mHasPercent);
     108        1314 :       return mLength;
     109             :     }
     110             : 
     111             :     // If this returns true the value is definitely zero. It it returns false
     112             :     // it might be zero. So it's best used for conservative optimization.
     113           0 :     bool IsDefinitelyZero() const { return mLength == 0 && mPercent == 0; }
     114             :   };
     115             : 
     116             :   // Reference counted calc() value.  This is the type that is used to store
     117             :   // the calc() value in nsStyleCoord.
     118             :   struct Calc final : public CalcValue {
     119        1219 :     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Calc)
     120         127 :     Calc() {}
     121             : 
     122             :   private:
     123             :     Calc(const Calc&) = delete;
     124          95 :     ~Calc() {}
     125             :     Calc& operator=(const Calc&) = delete;
     126             :   };
     127             : 
     128             :   explicit nsStyleCoord(nsStyleUnit aUnit = eStyleUnit_Null);
     129             :   enum CoordConstructorType { CoordConstructor };
     130             :   inline nsStyleCoord(nscoord aValue, CoordConstructorType);
     131             :   nsStyleCoord(int32_t aValue, nsStyleUnit aUnit);
     132             :   nsStyleCoord(float aValue, nsStyleUnit aUnit);
     133             :   inline nsStyleCoord(const nsStyleCoord& aCopy);
     134             :   inline nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit);
     135       57156 :   ~nsStyleCoord() { Reset(); }
     136             : 
     137         416 :   nsStyleCoord&  operator=(const nsStyleCoord& aOther)
     138             :   {
     139         416 :     if (this != &aOther) {
     140         416 :       SetValue(mUnit, mValue, aOther);
     141             :     }
     142         416 :     return *this;
     143             :   }
     144             :   bool           operator==(const nsStyleCoord& aOther) const;
     145             :   bool           operator!=(const nsStyleCoord& aOther) const;
     146             : 
     147       42227 :   nsStyleUnit GetUnit() const {
     148       42227 :     NS_ASSERTION(mUnit != eStyleUnit_Null, "reading uninitialized value");
     149       42227 :     return mUnit;
     150             :   }
     151             : 
     152          23 :   bool IsAngleValue() const {
     153          23 :     return eStyleUnit_Degree <= mUnit && mUnit <= eStyleUnit_Turn;
     154             :   }
     155             : 
     156      229377 :   static bool IsCalcUnit(nsStyleUnit aUnit) {
     157      229377 :     return aUnit == eStyleUnit_Calc;
     158             :   }
     159             : 
     160      137793 :   static bool IsPointerUnit(nsStyleUnit aUnit) {
     161      137793 :     return IsCalcUnit(aUnit);
     162             :   }
     163             : 
     164       10082 :   bool IsCalcUnit() const {
     165       10082 :     return IsCalcUnit(mUnit);
     166             :   }
     167             : 
     168             :   bool IsPointerValue() const {
     169             :     return IsPointerUnit(mUnit);
     170             :   }
     171             : 
     172        6325 :   bool IsCoordPercentCalcUnit() const {
     173        6463 :     return mUnit == eStyleUnit_Coord ||
     174        6427 :            mUnit == eStyleUnit_Percent ||
     175        6427 :            IsCalcUnit();
     176             :   }
     177             : 
     178             :   // Does this calc() expression have any percentages inside it?  Can be
     179             :   // called only when IsCalcUnit() is true.
     180           6 :   bool CalcHasPercent() const {
     181           6 :     return GetCalcValue()->mHasPercent;
     182             :   }
     183             : 
     184        4188 :   bool HasPercent() const {
     185        8376 :     return mUnit == eStyleUnit_Percent ||
     186        8330 :            (IsCalcUnit() && CalcHasPercent());
     187             :   }
     188             : 
     189      156738 :   static bool ConvertsToLength(const nsStyleUnit aUnit,
     190             :                                const nsStyleUnion aValue) {
     191      316313 :     return aUnit == eStyleUnit_Coord ||
     192      164757 :            (IsCalcUnit(aUnit) && !AsCalcValue(aValue)->mHasPercent);
     193             :   }
     194             : 
     195        2714 :   bool ConvertsToLength() const {
     196        2714 :     return ConvertsToLength(mUnit, mValue);
     197             :   }
     198             : 
     199       76320 :   static nscoord ToLength(nsStyleUnit aUnit, nsStyleUnion aValue) {
     200       76320 :     MOZ_ASSERT(ConvertsToLength(aUnit, aValue));
     201       76320 :     if (IsCalcUnit(aUnit)) {
     202        1314 :       return AsCalcValue(aValue)->ToLength(); // Note: This asserts !mHasPercent
     203             :     }
     204       75006 :     MOZ_ASSERT(aUnit == eStyleUnit_Coord);
     205       75006 :     return aValue.mInt;
     206             :   }
     207             : 
     208          32 :   nscoord ToLength() const {
     209          32 :     return ToLength(GetUnit(), mValue);
     210             :   }
     211             : 
     212             :   // Callers must verify IsCalcUnit before calling this function.
     213        4562 :   static Calc* AsCalcValue(nsStyleUnion aValue) {
     214        4562 :     return static_cast<Calc*>(aValue.mPointer);
     215             :   }
     216             : 
     217             :   nscoord     GetCoordValue() const;
     218             :   int32_t     GetIntValue() const;
     219             :   float       GetPercentValue() const;
     220             :   float       GetFactorValue() const;
     221             :   float       GetFactorOrPercentValue() const;
     222             :   float       GetAngleValue() const;
     223             :   double      GetAngleValueInDegrees() const;
     224             :   double      GetAngleValueInRadians() const;
     225             :   float       GetFlexFractionValue() const;
     226             :   Calc*       GetCalcValue() const;
     227             :   template<typename T,
     228             :            typename = typename std::enable_if<std::is_enum<T>::value>::type>
     229           0 :   T GetEnumValue() const
     230             :   {
     231           0 :     MOZ_ASSERT(GetUnit() == eStyleUnit_Enumerated,
     232             :                "The unit must be eStyleUnit_Enumerated!");
     233           0 :     return static_cast<T>(GetIntValue());
     234             :   }
     235             : 
     236             :   // Sets to null and releases any refcounted objects.  Only use this if the
     237             :   // object is initialized (i.e. don't use it in nsStyleCoord constructors).
     238             :   void Reset();
     239             : 
     240             :   void  SetCoordValue(nscoord aValue);
     241             :   void  SetIntValue(int32_t aValue, nsStyleUnit aUnit);
     242             :   void  SetPercentValue(float aValue);
     243             :   void  SetFactorValue(float aValue);
     244             :   void  SetAngleValue(float aValue, nsStyleUnit aUnit);
     245             :   void  SetFlexFractionValue(float aValue);
     246             :   void  SetNormalValue();
     247             :   void  SetAutoValue();
     248             :   void  SetNoneValue();
     249             :   void  SetCalcValue(Calc* aValue);
     250             :   template<typename T,
     251             :            typename = typename std::enable_if<std::is_enum<T>::value>::type>
     252           0 :   void SetEnumValue(T aValue)
     253             :   {
     254             :     static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value,
     255             :                   "aValue must be an enum that fits within mValue.mInt!");
     256           0 :     SetIntValue(static_cast<int32_t>(aValue), eStyleUnit_Enumerated);
     257           0 :   }
     258             : 
     259             :   // Resets a coord represented by a unit/value pair.
     260             :   static inline void Reset(nsStyleUnit& aUnit, nsStyleUnion& aValue);
     261             : 
     262             :   // Sets a coord represented by a unit/value pair from a second
     263             :   // unit/value pair.
     264             :   static inline void SetValue(nsStyleUnit& aUnit,
     265             :                               nsStyleUnion& aValue,
     266             :                               nsStyleUnit aOtherUnit,
     267             :                               const nsStyleUnion& aOtherValue);
     268             : 
     269             :   // Sets a coord represented by a unit/value pair from an nsStyleCoord.
     270             :   static inline void SetValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
     271             :                               const nsStyleCoord& aOther);
     272             : 
     273             :   // Like the above, but do not reset before setting.
     274             :   static inline void InitWithValue(nsStyleUnit& aUnit,
     275             :                                    nsStyleUnion& aValue,
     276             :                                    nsStyleUnit aOtherUnit,
     277             :                                    const nsStyleUnion& aOtherValue);
     278             : 
     279             :   static inline void InitWithValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
     280             :                                    const nsStyleCoord& aOther);
     281             : 
     282             : private:
     283             :   nsStyleUnit   mUnit;
     284             :   nsStyleUnion  mValue;
     285             : };
     286             : 
     287             : /**
     288             :  * Class that represents a set of top/right/bottom/left nsStyleCoords.
     289             :  * This is commonly used to hold the widths of the borders, margins,
     290             :  * or paddings of a box.
     291             :  */
     292             :  /** <div rustbindgen private accessor="unsafe"></div> */
     293             : class nsStyleSides {
     294             : public:
     295             :   nsStyleSides();
     296             :   nsStyleSides(const nsStyleSides&);
     297             :   ~nsStyleSides();
     298             : 
     299             :   nsStyleSides&  operator=(const nsStyleSides& aCopy);
     300             :   bool           operator==(const nsStyleSides& aOther) const;
     301             :   bool           operator!=(const nsStyleSides& aOther) const;
     302             : 
     303             :   inline nsStyleUnit GetUnit(mozilla::Side aSide) const;
     304             :   inline nsStyleUnit GetLeftUnit() const;
     305             :   inline nsStyleUnit GetTopUnit() const;
     306             :   inline nsStyleUnit GetRightUnit() const;
     307             :   inline nsStyleUnit GetBottomUnit() const;
     308             : 
     309             :   inline nsStyleCoord Get(mozilla::Side aSide) const;
     310             :   inline nsStyleCoord GetLeft() const;
     311             :   inline nsStyleCoord GetTop() const;
     312             :   inline nsStyleCoord GetRight() const;
     313             :   inline nsStyleCoord GetBottom() const;
     314             : 
     315             :   // Methods to access the units and values in terms of logical sides
     316             :   // for a given writing mode.
     317             :   // NOTE: The definitions are in WritingModes.h (after we have the full
     318             :   // declaration of WritingMode available).
     319             :   inline nsStyleUnit GetUnit(mozilla::WritingMode aWritingMode,
     320             :                              mozilla::LogicalSide aSide) const;
     321             :   inline nsStyleUnit GetIStartUnit(mozilla::WritingMode aWritingMode) const;
     322             :   inline nsStyleUnit GetBStartUnit(mozilla::WritingMode aWritingMode) const;
     323             :   inline nsStyleUnit GetIEndUnit(mozilla::WritingMode aWritingMode) const;
     324             :   inline nsStyleUnit GetBEndUnit(mozilla::WritingMode aWritingMode) const;
     325             : 
     326             :   // Return true if either the start or end side in the axis is 'auto'.
     327             :   inline bool HasBlockAxisAuto(mozilla::WritingMode aWritingMode) const;
     328             :   inline bool HasInlineAxisAuto(mozilla::WritingMode aWritingMode) const;
     329             : 
     330             :   inline nsStyleCoord Get(mozilla::WritingMode aWritingMode,
     331             :                           mozilla::LogicalSide aSide) const;
     332             :   inline nsStyleCoord GetIStart(mozilla::WritingMode aWritingMode) const;
     333             :   inline nsStyleCoord GetBStart(mozilla::WritingMode aWritingMode) const;
     334             :   inline nsStyleCoord GetIEnd(mozilla::WritingMode aWritingMode) const;
     335             :   inline nsStyleCoord GetBEnd(mozilla::WritingMode aWritingMode) const;
     336             : 
     337             :   // Sets each side to null and releases any refcounted objects.  Only use this
     338             :   // if the object is initialized (i.e. don't use it in nsStyleSides
     339             :   // constructors).
     340             :   void Reset();
     341             : 
     342             :   inline void Set(mozilla::Side aSide, const nsStyleCoord& aCoord);
     343             :   inline void SetLeft(const nsStyleCoord& aCoord);
     344             :   inline void SetTop(const nsStyleCoord& aCoord);
     345             :   inline void SetRight(const nsStyleCoord& aCoord);
     346             :   inline void SetBottom(const nsStyleCoord& aCoord);
     347             : 
     348       76288 :   nscoord ToLength(mozilla::Side aSide) const {
     349       76288 :     return nsStyleCoord::ToLength(mUnits[aSide], mValues[aSide]);
     350             :   }
     351             : 
     352       19426 :   bool ConvertsToLength() const {
     353       97130 :     NS_FOR_CSS_SIDES(side) {
     354       77704 :       if (!nsStyleCoord::ConvertsToLength(mUnits[side], mValues[side])) {
     355           0 :         return false;
     356             :       }
     357             :     }
     358       19426 :     return true;
     359             :   }
     360             : 
     361             : protected:
     362             :   nsStyleUnit   mUnits[4];
     363             :   nsStyleUnion  mValues[4];
     364             : };
     365             : 
     366             : /**
     367             :  * Class that represents a set of top-left/top-right/bottom-right/bottom-left
     368             :  * nsStyleCoord pairs.  This is used to hold the dimensions of the
     369             :  * corners of a box (for, e.g., border-radius and outline-radius).
     370             :  */
     371             :  /** <div rustbindgen private accessor="unsafe"></div> */
     372             : class nsStyleCorners {
     373             : public:
     374             :   nsStyleCorners();
     375             :   nsStyleCorners(const nsStyleCorners&);
     376             :   ~nsStyleCorners();
     377             : 
     378             :   // use compiler's version
     379             :   nsStyleCorners& operator=(const nsStyleCorners& aCopy);
     380             :   bool           operator==(const nsStyleCorners& aOther) const;
     381             :   bool           operator!=(const nsStyleCorners& aOther) const;
     382             : 
     383             :   // aHalfCorner is always one of enum HalfCorner in gfx/2d/Types.h.
     384             :   inline nsStyleUnit GetUnit(uint8_t aHalfCorner) const;
     385             : 
     386             :   inline nsStyleCoord Get(uint8_t aHalfCorner) const;
     387             : 
     388             :   // Sets each corner to null and releases any refcounted objects.  Only use
     389             :   // this if the object is initialized (i.e. don't use it in nsStyleCorners
     390             :   // constructors).
     391             :   void Reset();
     392             : 
     393             :   inline void Set(uint8_t aHalfCorner, const nsStyleCoord& aCoord);
     394             : 
     395             : protected:
     396             :   // Stored as:
     397             :   // top-left.x, top-left.y,
     398             :   // top-right.x, top-right.y,
     399             :   // bottom-right.x, bottom-right.y,
     400             :   // bottom-left.x, bottom-left.y
     401             :   nsStyleUnit   mUnits[8];
     402             :   nsStyleUnion  mValues[8];
     403             : };
     404             : 
     405             : 
     406             : // -------------------------
     407             : // nsStyleCoord inlines
     408             : //
     409         826 : inline nsStyleCoord::nsStyleCoord(nscoord aValue, CoordConstructorType)
     410         826 :   : mUnit(eStyleUnit_Coord)
     411             : {
     412         826 :   mValue.mInt = aValue;
     413         826 : }
     414             : 
     415       14250 : inline nsStyleCoord::nsStyleCoord(const nsStyleCoord& aCopy)
     416       14250 :   : mUnit(eStyleUnit_Null)
     417             : {
     418       14250 :   InitWithValue(mUnit, mValue, aCopy);
     419       14250 : }
     420             : 
     421       43632 : inline nsStyleCoord::nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit)
     422       43632 :   : mUnit(eStyleUnit_Null)
     423             : {
     424       43632 :   InitWithValue(mUnit, mValue, aUnit, aValue);
     425       43632 : }
     426             : 
     427       19926 : inline bool nsStyleCoord::operator!=(const nsStyleCoord& aOther) const
     428             : {
     429       19926 :   return !((*this) == aOther);
     430             : }
     431             : 
     432        9526 : inline nscoord nsStyleCoord::GetCoordValue() const
     433             : {
     434        9526 :   NS_ASSERTION((mUnit == eStyleUnit_Coord), "not a coord value");
     435        9526 :   if (mUnit == eStyleUnit_Coord) {
     436        9526 :     return mValue.mInt;
     437             :   }
     438           0 :   return 0;
     439             : }
     440             : 
     441         478 : inline int32_t nsStyleCoord::GetIntValue() const
     442             : {
     443         478 :   NS_ASSERTION((mUnit == eStyleUnit_Enumerated) ||
     444             :                (mUnit == eStyleUnit_Integer), "not an int value");
     445         646 :   if ((mUnit == eStyleUnit_Enumerated) ||
     446         168 :       (mUnit == eStyleUnit_Integer)) {
     447         478 :     return mValue.mInt;
     448             :   }
     449           0 :   return 0;
     450             : }
     451             : 
     452         344 : inline float nsStyleCoord::GetPercentValue() const
     453             : {
     454         344 :   NS_ASSERTION(mUnit == eStyleUnit_Percent, "not a percent value");
     455         344 :   if (mUnit == eStyleUnit_Percent) {
     456         344 :     return mValue.mFloat;
     457             :   }
     458           0 :   return 0.0f;
     459             : }
     460             : 
     461        6468 : inline float nsStyleCoord::GetFactorValue() const
     462             : {
     463        6468 :   NS_ASSERTION(mUnit == eStyleUnit_Factor, "not a factor value");
     464        6468 :   if (mUnit == eStyleUnit_Factor) {
     465        6468 :     return mValue.mFloat;
     466             :   }
     467           0 :   return 0.0f;
     468             : }
     469             : 
     470           0 : inline float nsStyleCoord::GetFactorOrPercentValue() const
     471             : {
     472           0 :   NS_ASSERTION(mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent,
     473             :                "not a percent or factor value");
     474           0 :   if (mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent) {
     475           0 :     return mValue.mFloat;
     476             :   }
     477           0 :   return 0.0f;
     478             : }
     479             : 
     480           0 : inline float nsStyleCoord::GetAngleValue() const
     481             : {
     482           0 :   NS_ASSERTION(mUnit >= eStyleUnit_Degree &&
     483             :                mUnit <= eStyleUnit_Turn, "not an angle value");
     484           0 :   if (mUnit >= eStyleUnit_Degree && mUnit <= eStyleUnit_Turn) {
     485           0 :     return mValue.mFloat;
     486             :   }
     487           0 :   return 0.0f;
     488             : }
     489             : 
     490           0 : inline float nsStyleCoord::GetFlexFractionValue() const
     491             : {
     492           0 :   NS_ASSERTION(mUnit == eStyleUnit_FlexFraction, "not a fr value");
     493           0 :   if (mUnit == eStyleUnit_FlexFraction) {
     494           0 :     return mValue.mFloat;
     495             :   }
     496           0 :   return 0.0f;
     497             : }
     498             : 
     499         411 : inline nsStyleCoord::Calc* nsStyleCoord::GetCalcValue() const
     500             : {
     501         411 :   NS_ASSERTION(IsCalcUnit(), "not a pointer value");
     502         411 :   if (IsCalcUnit()) {
     503         411 :     return AsCalcValue(mValue);
     504             :   }
     505           0 :   return nullptr;
     506             : }
     507             : 
     508             : /* static */ inline void
     509       72075 : nsStyleCoord::Reset(nsStyleUnit& aUnit, nsStyleUnion& aValue)
     510             : {
     511       72075 :   MOZ_ASSERT(aUnit <= eStyleUnit_MAX,
     512             :              "calling Reset on uninitialized nsStyleCoord?");
     513             : 
     514       72075 :   switch (aUnit) {
     515             :     case eStyleUnit_Calc:
     516         546 :       static_cast<Calc*>(aValue.mPointer)->Release();
     517         546 :       break;
     518             :     default:
     519       71529 :       MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic");
     520             :   }
     521             : 
     522       72075 :   aUnit = eStyleUnit_Null;
     523       72075 :   aValue.mInt = 0;
     524       72075 : }
     525             : 
     526             : /* static */ inline void
     527        8833 : nsStyleCoord::SetValue(nsStyleUnit& aUnit,
     528             :                        nsStyleUnion& aValue,
     529             :                        nsStyleUnit aOtherUnit,
     530             :                        const nsStyleUnion& aOtherValue)
     531             : {
     532        8833 :   Reset(aUnit, aValue);
     533        8833 :   InitWithValue(aUnit, aValue, aOtherUnit, aOtherValue);
     534        8833 : }
     535             : 
     536             : /* static */ inline void
     537       66715 : nsStyleCoord::InitWithValue(nsStyleUnit& aUnit,
     538             :                             nsStyleUnion& aValue,
     539             :                             nsStyleUnit aOtherUnit,
     540             :                             const nsStyleUnion& aOtherValue)
     541             : {
     542       66715 :   aUnit = aOtherUnit;
     543       66715 :   aValue = aOtherValue;
     544             : 
     545       66715 :   switch (aUnit) {
     546             :     case eStyleUnit_Calc:
     547         451 :       static_cast<Calc*>(aValue.mPointer)->AddRef();
     548         451 :       break;
     549             :     default:
     550       66264 :       MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic");
     551             :   }
     552       66715 : }
     553             : 
     554             : /* static */ inline void
     555        4717 : nsStyleCoord::SetValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
     556             :                        const nsStyleCoord& aOther)
     557             : {
     558        4717 :   SetValue(aUnit, aValue, aOther.mUnit, aOther.mValue);
     559        4717 : }
     560             : 
     561             : /* static */ inline void
     562       14250 : nsStyleCoord::InitWithValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
     563             :                             const nsStyleCoord& aOther)
     564             : {
     565       14250 :   InitWithValue(aUnit, aValue, aOther.mUnit, aOther.mValue);
     566       14250 : }
     567             : 
     568             : 
     569             : // -------------------------
     570             : // nsStyleSides inlines
     571             : //
     572        1288 : inline bool nsStyleSides::operator!=(const nsStyleSides& aOther) const
     573             : {
     574        1288 :   return !((*this) == aOther);
     575             : }
     576             : 
     577        1427 : inline nsStyleUnit nsStyleSides::GetUnit(mozilla::Side aSide) const
     578             : {
     579        1427 :   return (nsStyleUnit)mUnits[aSide];
     580             : }
     581             : 
     582           0 : inline nsStyleUnit nsStyleSides::GetLeftUnit() const
     583             : {
     584           0 :   return GetUnit(mozilla::eSideLeft);
     585             : }
     586             : 
     587          60 : inline nsStyleUnit nsStyleSides::GetTopUnit() const
     588             : {
     589          60 :   return GetUnit(mozilla::eSideTop);
     590             : }
     591             : 
     592           0 : inline nsStyleUnit nsStyleSides::GetRightUnit() const
     593             : {
     594           0 :   return GetUnit(mozilla::eSideRight);
     595             : }
     596             : 
     597          60 : inline nsStyleUnit nsStyleSides::GetBottomUnit() const
     598             : {
     599          60 :   return GetUnit(mozilla::eSideBottom);
     600             : }
     601             : 
     602       12352 : inline nsStyleCoord nsStyleSides::Get(mozilla::Side aSide) const
     603             : {
     604       12352 :   return nsStyleCoord(mValues[aSide], nsStyleUnit(mUnits[aSide]));
     605             : }
     606             : 
     607         129 : inline nsStyleCoord nsStyleSides::GetLeft() const
     608             : {
     609         129 :   return Get(mozilla::eSideLeft);
     610             : }
     611             : 
     612          52 : inline nsStyleCoord nsStyleSides::GetTop() const
     613             : {
     614          52 :   return Get(mozilla::eSideTop);
     615             : }
     616             : 
     617         102 : inline nsStyleCoord nsStyleSides::GetRight() const
     618             : {
     619         102 :   return Get(mozilla::eSideRight);
     620             : }
     621             : 
     622          52 : inline nsStyleCoord nsStyleSides::GetBottom() const
     623             : {
     624          52 :   return Get(mozilla::eSideBottom);
     625             : }
     626             : 
     627        3171 : inline void nsStyleSides::Set(mozilla::Side aSide, const nsStyleCoord& aCoord)
     628             : {
     629        3171 :   nsStyleCoord::SetValue(mUnits[aSide], mValues[aSide], aCoord);
     630        3171 : }
     631             : 
     632             : inline void nsStyleSides::SetLeft(const nsStyleCoord& aCoord)
     633             : {
     634             :   Set(mozilla::eSideLeft, aCoord);
     635             : }
     636             : 
     637             : inline void nsStyleSides::SetTop(const nsStyleCoord& aCoord)
     638             : {
     639             :   Set(mozilla::eSideTop, aCoord);
     640             : }
     641             : 
     642             : inline void nsStyleSides::SetRight(const nsStyleCoord& aCoord)
     643             : {
     644             :   Set(mozilla::eSideRight, aCoord);
     645             : }
     646             : 
     647             : inline void nsStyleSides::SetBottom(const nsStyleCoord& aCoord)
     648             : {
     649             :   Set(mozilla::eSideBottom, aCoord);
     650             : }
     651             : 
     652             : // -------------------------
     653             : // nsStyleCorners inlines
     654             : //
     655         586 : inline bool nsStyleCorners::operator!=(const nsStyleCorners& aOther) const
     656             : {
     657         586 :   return !((*this) == aOther);
     658             : }
     659             : 
     660             : inline nsStyleUnit nsStyleCorners::GetUnit(uint8_t aCorner) const
     661             : {
     662             :   return (nsStyleUnit)mUnits[aCorner];
     663             : }
     664             : 
     665        7206 : inline nsStyleCoord nsStyleCorners::Get(uint8_t aCorner) const
     666             : {
     667        7206 :   return nsStyleCoord(mValues[aCorner], nsStyleUnit(mUnits[aCorner]));
     668             : }
     669             : 
     670        1130 : inline void nsStyleCorners::Set(uint8_t aCorner, const nsStyleCoord& aCoord)
     671             : {
     672        1130 :   nsStyleCoord::SetValue(mUnits[aCorner], mValues[aCorner], aCoord);
     673        1130 : }
     674             : 
     675             : #endif /* nsStyleCoord_h___ */

Generated by: LCOV version 1.13