nsStyleCoord.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. /* representation of length values in computed style data */
  6. #ifndef nsStyleCoord_h___
  7. #define nsStyleCoord_h___
  8. #include "nsCoord.h"
  9. #include "nsStyleConsts.h"
  10. namespace mozilla {
  11. class WritingMode;
  12. // Logical axis, edge and side constants for use in various places.
  13. enum LogicalAxis {
  14. eLogicalAxisBlock = 0x0,
  15. eLogicalAxisInline = 0x1
  16. };
  17. enum LogicalEdge {
  18. eLogicalEdgeStart = 0x0,
  19. eLogicalEdgeEnd = 0x1
  20. };
  21. enum LogicalSide {
  22. eLogicalSideBStart = (eLogicalAxisBlock << 1) | eLogicalEdgeStart, // 0x0
  23. eLogicalSideBEnd = (eLogicalAxisBlock << 1) | eLogicalEdgeEnd, // 0x1
  24. eLogicalSideIStart = (eLogicalAxisInline << 1) | eLogicalEdgeStart, // 0x2
  25. eLogicalSideIEnd = (eLogicalAxisInline << 1) | eLogicalEdgeEnd // 0x3
  26. };
  27. } // namespace mozilla
  28. enum nsStyleUnit : uint8_t {
  29. eStyleUnit_Null = 0, // (no value) value is not specified
  30. eStyleUnit_Normal = 1, // (no value)
  31. eStyleUnit_Auto = 2, // (no value)
  32. eStyleUnit_None = 3, // (no value)
  33. eStyleUnit_Percent = 10, // (float) 1.0 == 100%
  34. eStyleUnit_Factor = 11, // (float) a multiplier
  35. eStyleUnit_Degree = 12, // (float) angle in degrees
  36. eStyleUnit_Grad = 13, // (float) angle in grads
  37. eStyleUnit_Radian = 14, // (float) angle in radians
  38. eStyleUnit_Turn = 15, // (float) angle in turns
  39. eStyleUnit_FlexFraction = 16, // (float) <flex> in fr units
  40. eStyleUnit_Coord = 20, // (nscoord) value is twips
  41. eStyleUnit_Integer = 30, // (int) value is simple integer
  42. eStyleUnit_Enumerated = 32, // (int) value has enumerated meaning
  43. // The following are reference counted allocated types.
  44. eStyleUnit_Calc = 40, // (Calc*) calc() toplevel; always present
  45. // to distinguish 50% from calc(50%), etc.
  46. eStyleUnit_MAX = 40 // highest valid nsStyleUnit value
  47. };
  48. typedef union {
  49. int32_t mInt; // nscoord is a int32_t for now
  50. float mFloat;
  51. // An mPointer is a reference counted pointer. Currently this can only
  52. // ever be an nsStyleCoord::Calc*.
  53. void* mPointer;
  54. } nsStyleUnion;
  55. /**
  56. * Class that hold a single size specification used by the style
  57. * system. The size specification consists of two parts -- a number
  58. * and a unit. The number is an integer, a floating point value, an
  59. * nscoord, or undefined, and the unit is an nsStyleUnit. Checking
  60. * the unit is a must before asking for the value in any particular
  61. * form.
  62. */
  63. /** <div rustbindgen private accessor="unsafe"></div> */
  64. class nsStyleCoord {
  65. public:
  66. // Non-reference counted calc() value. See nsStyleStruct.h for some uses
  67. // of this.
  68. struct CalcValue {
  69. // Every calc() expression evaluates to a length plus a percentage.
  70. nscoord mLength;
  71. float mPercent;
  72. bool mHasPercent; // whether there was any % syntax, even if 0
  73. bool operator==(const CalcValue& aOther) const {
  74. return mLength == aOther.mLength &&
  75. mPercent == aOther.mPercent &&
  76. mHasPercent == aOther.mHasPercent;
  77. }
  78. bool operator!=(const CalcValue& aOther) const {
  79. return !(*this == aOther);
  80. }
  81. nscoord ToLength() const {
  82. MOZ_ASSERT(!mHasPercent);
  83. return mLength;
  84. }
  85. // If this returns true the value is definitely zero. It it returns false
  86. // it might be zero. So it's best used for conservative optimization.
  87. bool IsDefinitelyZero() const { return mLength == 0 && mPercent == 0; }
  88. };
  89. // Reference counted calc() value. This is the type that is used to store
  90. // the calc() value in nsStyleCoord.
  91. struct Calc final : public CalcValue {
  92. NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Calc)
  93. Calc() {}
  94. private:
  95. Calc(const Calc&) = delete;
  96. ~Calc() {}
  97. Calc& operator=(const Calc&) = delete;
  98. };
  99. explicit nsStyleCoord(nsStyleUnit aUnit = eStyleUnit_Null);
  100. enum CoordConstructorType { CoordConstructor };
  101. inline nsStyleCoord(nscoord aValue, CoordConstructorType);
  102. nsStyleCoord(int32_t aValue, nsStyleUnit aUnit);
  103. nsStyleCoord(float aValue, nsStyleUnit aUnit);
  104. inline nsStyleCoord(const nsStyleCoord& aCopy);
  105. inline nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit);
  106. ~nsStyleCoord() { Reset(); }
  107. nsStyleCoord& operator=(const nsStyleCoord& aOther)
  108. {
  109. if (this != &aOther) {
  110. SetValue(mUnit, mValue, aOther);
  111. }
  112. return *this;
  113. }
  114. bool operator==(const nsStyleCoord& aOther) const;
  115. bool operator!=(const nsStyleCoord& aOther) const;
  116. nsStyleUnit GetUnit() const {
  117. NS_ASSERTION(mUnit != eStyleUnit_Null, "reading uninitialized value");
  118. return mUnit;
  119. }
  120. bool IsAngleValue() const {
  121. return eStyleUnit_Degree <= mUnit && mUnit <= eStyleUnit_Turn;
  122. }
  123. static bool IsCalcUnit(nsStyleUnit aUnit) {
  124. return aUnit == eStyleUnit_Calc;
  125. }
  126. static bool IsPointerUnit(nsStyleUnit aUnit) {
  127. return IsCalcUnit(aUnit);
  128. }
  129. bool IsCalcUnit() const {
  130. return IsCalcUnit(mUnit);
  131. }
  132. bool IsPointerValue() const {
  133. return IsPointerUnit(mUnit);
  134. }
  135. bool IsCoordPercentCalcUnit() const {
  136. return mUnit == eStyleUnit_Coord ||
  137. mUnit == eStyleUnit_Percent ||
  138. IsCalcUnit();
  139. }
  140. // Does this calc() expression have any percentages inside it? Can be
  141. // called only when IsCalcUnit() is true.
  142. bool CalcHasPercent() const {
  143. return GetCalcValue()->mHasPercent;
  144. }
  145. bool HasPercent() const {
  146. return mUnit == eStyleUnit_Percent ||
  147. (IsCalcUnit() && CalcHasPercent());
  148. }
  149. static bool ConvertsToLength(const nsStyleUnit aUnit,
  150. const nsStyleUnion aValue) {
  151. return aUnit == eStyleUnit_Coord ||
  152. (IsCalcUnit(aUnit) && !AsCalcValue(aValue)->mHasPercent);
  153. }
  154. bool ConvertsToLength() const {
  155. return ConvertsToLength(mUnit, mValue);
  156. }
  157. static nscoord ToLength(nsStyleUnit aUnit, nsStyleUnion aValue) {
  158. MOZ_ASSERT(ConvertsToLength(aUnit, aValue));
  159. if (IsCalcUnit(aUnit)) {
  160. return AsCalcValue(aValue)->ToLength(); // Note: This asserts !mHasPercent
  161. }
  162. MOZ_ASSERT(aUnit == eStyleUnit_Coord);
  163. return aValue.mInt;
  164. }
  165. nscoord ToLength() const {
  166. return ToLength(GetUnit(), mValue);
  167. }
  168. // Callers must verify IsCalcUnit before calling this function.
  169. static Calc* AsCalcValue(nsStyleUnion aValue) {
  170. return static_cast<Calc*>(aValue.mPointer);
  171. }
  172. nscoord GetCoordValue() const;
  173. int32_t GetIntValue() const;
  174. float GetPercentValue() const;
  175. float GetFactorValue() const;
  176. float GetFactorOrPercentValue() const;
  177. float GetAngleValue() const;
  178. double GetAngleValueInDegrees() const;
  179. double GetAngleValueInRadians() const;
  180. float GetFlexFractionValue() const;
  181. Calc* GetCalcValue() const;
  182. uint32_t HashValue(uint32_t aHash) const;
  183. // Sets to null and releases any refcounted objects. Only use this if the
  184. // object is initialized (i.e. don't use it in nsStyleCoord constructors).
  185. void Reset();
  186. void SetCoordValue(nscoord aValue);
  187. void SetIntValue(int32_t aValue, nsStyleUnit aUnit);
  188. void SetPercentValue(float aValue);
  189. void SetFactorValue(float aValue);
  190. void SetAngleValue(float aValue, nsStyleUnit aUnit);
  191. void SetFlexFractionValue(float aValue);
  192. void SetNormalValue();
  193. void SetAutoValue();
  194. void SetNoneValue();
  195. void SetCalcValue(Calc* aValue);
  196. // Resets a coord represented by a unit/value pair.
  197. static inline void Reset(nsStyleUnit& aUnit, nsStyleUnion& aValue);
  198. // Sets a coord represented by a unit/value pair from a second
  199. // unit/value pair.
  200. static inline void SetValue(nsStyleUnit& aUnit,
  201. nsStyleUnion& aValue,
  202. nsStyleUnit aOtherUnit,
  203. const nsStyleUnion& aOtherValue);
  204. // Sets a coord represented by a unit/value pair from an nsStyleCoord.
  205. static inline void SetValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
  206. const nsStyleCoord& aOther);
  207. // Like the above, but do not reset before setting.
  208. static inline void InitWithValue(nsStyleUnit& aUnit,
  209. nsStyleUnion& aValue,
  210. nsStyleUnit aOtherUnit,
  211. const nsStyleUnion& aOtherValue);
  212. static inline void InitWithValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
  213. const nsStyleCoord& aOther);
  214. private:
  215. nsStyleUnit mUnit;
  216. nsStyleUnion mValue;
  217. };
  218. /**
  219. * Class that represents a set of top/right/bottom/left nsStyleCoords.
  220. * This is commonly used to hold the widths of the borders, margins,
  221. * or paddings of a box.
  222. */
  223. /** <div rustbindgen private accessor="unsafe"></div> */
  224. class nsStyleSides {
  225. public:
  226. nsStyleSides();
  227. nsStyleSides(const nsStyleSides&);
  228. ~nsStyleSides();
  229. nsStyleSides& operator=(const nsStyleSides& aCopy);
  230. bool operator==(const nsStyleSides& aOther) const;
  231. bool operator!=(const nsStyleSides& aOther) const;
  232. inline nsStyleUnit GetUnit(mozilla::css::Side aSide) const;
  233. inline nsStyleUnit GetLeftUnit() const;
  234. inline nsStyleUnit GetTopUnit() const;
  235. inline nsStyleUnit GetRightUnit() const;
  236. inline nsStyleUnit GetBottomUnit() const;
  237. inline nsStyleCoord Get(mozilla::css::Side aSide) const;
  238. inline nsStyleCoord GetLeft() const;
  239. inline nsStyleCoord GetTop() const;
  240. inline nsStyleCoord GetRight() const;
  241. inline nsStyleCoord GetBottom() const;
  242. // Methods to access the units and values in terms of logical sides
  243. // for a given writing mode.
  244. // NOTE: The definitions are in WritingModes.h (after we have the full
  245. // declaration of WritingMode available).
  246. inline nsStyleUnit GetUnit(mozilla::WritingMode aWritingMode,
  247. mozilla::LogicalSide aSide) const;
  248. inline nsStyleUnit GetIStartUnit(mozilla::WritingMode aWritingMode) const;
  249. inline nsStyleUnit GetBStartUnit(mozilla::WritingMode aWritingMode) const;
  250. inline nsStyleUnit GetIEndUnit(mozilla::WritingMode aWritingMode) const;
  251. inline nsStyleUnit GetBEndUnit(mozilla::WritingMode aWritingMode) const;
  252. // Return true if either the start or end side in the axis is 'auto'.
  253. inline bool HasBlockAxisAuto(mozilla::WritingMode aWritingMode) const;
  254. inline bool HasInlineAxisAuto(mozilla::WritingMode aWritingMode) const;
  255. inline nsStyleCoord Get(mozilla::WritingMode aWritingMode,
  256. mozilla::LogicalSide aSide) const;
  257. inline nsStyleCoord GetIStart(mozilla::WritingMode aWritingMode) const;
  258. inline nsStyleCoord GetBStart(mozilla::WritingMode aWritingMode) const;
  259. inline nsStyleCoord GetIEnd(mozilla::WritingMode aWritingMode) const;
  260. inline nsStyleCoord GetBEnd(mozilla::WritingMode aWritingMode) const;
  261. // Sets each side to null and releases any refcounted objects. Only use this
  262. // if the object is initialized (i.e. don't use it in nsStyleSides
  263. // constructors).
  264. void Reset();
  265. inline void Set(mozilla::css::Side aSide, const nsStyleCoord& aCoord);
  266. inline void SetLeft(const nsStyleCoord& aCoord);
  267. inline void SetTop(const nsStyleCoord& aCoord);
  268. inline void SetRight(const nsStyleCoord& aCoord);
  269. inline void SetBottom(const nsStyleCoord& aCoord);
  270. nscoord ToLength(mozilla::css::Side aSide) const {
  271. return nsStyleCoord::ToLength(mUnits[aSide], mValues[aSide]);
  272. }
  273. bool ConvertsToLength() const {
  274. NS_FOR_CSS_SIDES(side) {
  275. if (!nsStyleCoord::ConvertsToLength(mUnits[side], mValues[side])) {
  276. return false;
  277. }
  278. }
  279. return true;
  280. }
  281. protected:
  282. nsStyleUnit mUnits[4];
  283. nsStyleUnion mValues[4];
  284. };
  285. /**
  286. * Class that represents a set of top-left/top-right/bottom-right/bottom-left
  287. * nsStyleCoord pairs. This is used to hold the dimensions of the
  288. * corners of a box (for, e.g., border-radius and outline-radius).
  289. */
  290. /** <div rustbindgen private accessor="unsafe"></div> */
  291. class nsStyleCorners {
  292. public:
  293. nsStyleCorners();
  294. nsStyleCorners(const nsStyleCorners&);
  295. ~nsStyleCorners();
  296. // use compiler's version
  297. nsStyleCorners& operator=(const nsStyleCorners& aCopy);
  298. bool operator==(const nsStyleCorners& aOther) const;
  299. bool operator!=(const nsStyleCorners& aOther) const;
  300. // aCorner is always one of NS_CORNER_* defined in nsStyleConsts.h
  301. inline nsStyleUnit GetUnit(uint8_t aHalfCorner) const;
  302. inline nsStyleCoord Get(uint8_t aHalfCorner) const;
  303. // Sets each corner to null and releases any refcounted objects. Only use
  304. // this if the object is initialized (i.e. don't use it in nsStyleCorners
  305. // constructors).
  306. void Reset();
  307. inline void Set(uint8_t aHalfCorner, const nsStyleCoord& aCoord);
  308. protected:
  309. // Stored as:
  310. // top-left.x, top-left.y,
  311. // top-right.x, top-right.y,
  312. // bottom-right.x, bottom-right.y,
  313. // bottom-left.x, bottom-left.y
  314. nsStyleUnit mUnits[8];
  315. nsStyleUnion mValues[8];
  316. };
  317. // -------------------------
  318. // nsStyleCoord inlines
  319. //
  320. inline nsStyleCoord::nsStyleCoord(nscoord aValue, CoordConstructorType)
  321. : mUnit(eStyleUnit_Coord)
  322. {
  323. mValue.mInt = aValue;
  324. }
  325. inline nsStyleCoord::nsStyleCoord(const nsStyleCoord& aCopy)
  326. : mUnit(eStyleUnit_Null)
  327. {
  328. InitWithValue(mUnit, mValue, aCopy);
  329. }
  330. inline nsStyleCoord::nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit)
  331. : mUnit(eStyleUnit_Null)
  332. {
  333. InitWithValue(mUnit, mValue, aUnit, aValue);
  334. }
  335. inline bool nsStyleCoord::operator!=(const nsStyleCoord& aOther) const
  336. {
  337. return !((*this) == aOther);
  338. }
  339. inline nscoord nsStyleCoord::GetCoordValue() const
  340. {
  341. NS_ASSERTION((mUnit == eStyleUnit_Coord), "not a coord value");
  342. if (mUnit == eStyleUnit_Coord) {
  343. return mValue.mInt;
  344. }
  345. return 0;
  346. }
  347. inline int32_t nsStyleCoord::GetIntValue() const
  348. {
  349. NS_ASSERTION((mUnit == eStyleUnit_Enumerated) ||
  350. (mUnit == eStyleUnit_Integer), "not an int value");
  351. if ((mUnit == eStyleUnit_Enumerated) ||
  352. (mUnit == eStyleUnit_Integer)) {
  353. return mValue.mInt;
  354. }
  355. return 0;
  356. }
  357. inline float nsStyleCoord::GetPercentValue() const
  358. {
  359. NS_ASSERTION(mUnit == eStyleUnit_Percent, "not a percent value");
  360. if (mUnit == eStyleUnit_Percent) {
  361. return mValue.mFloat;
  362. }
  363. return 0.0f;
  364. }
  365. inline float nsStyleCoord::GetFactorValue() const
  366. {
  367. NS_ASSERTION(mUnit == eStyleUnit_Factor, "not a factor value");
  368. if (mUnit == eStyleUnit_Factor) {
  369. return mValue.mFloat;
  370. }
  371. return 0.0f;
  372. }
  373. inline float nsStyleCoord::GetFactorOrPercentValue() const
  374. {
  375. NS_ASSERTION(mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent,
  376. "not a percent or factor value");
  377. if (mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent) {
  378. return mValue.mFloat;
  379. }
  380. return 0.0f;
  381. }
  382. inline float nsStyleCoord::GetAngleValue() const
  383. {
  384. NS_ASSERTION(mUnit >= eStyleUnit_Degree &&
  385. mUnit <= eStyleUnit_Turn, "not an angle value");
  386. if (mUnit >= eStyleUnit_Degree && mUnit <= eStyleUnit_Turn) {
  387. return mValue.mFloat;
  388. }
  389. return 0.0f;
  390. }
  391. inline float nsStyleCoord::GetFlexFractionValue() const
  392. {
  393. NS_ASSERTION(mUnit == eStyleUnit_FlexFraction, "not a fr value");
  394. if (mUnit == eStyleUnit_FlexFraction) {
  395. return mValue.mFloat;
  396. }
  397. return 0.0f;
  398. }
  399. inline nsStyleCoord::Calc* nsStyleCoord::GetCalcValue() const
  400. {
  401. NS_ASSERTION(IsCalcUnit(), "not a pointer value");
  402. if (IsCalcUnit()) {
  403. return AsCalcValue(mValue);
  404. }
  405. return nullptr;
  406. }
  407. /* static */ inline void
  408. nsStyleCoord::Reset(nsStyleUnit& aUnit, nsStyleUnion& aValue)
  409. {
  410. MOZ_ASSERT(aUnit <= eStyleUnit_MAX,
  411. "calling Reset on uninitialized nsStyleCoord?");
  412. switch (aUnit) {
  413. case eStyleUnit_Calc:
  414. static_cast<Calc*>(aValue.mPointer)->Release();
  415. break;
  416. default:
  417. MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic");
  418. }
  419. aUnit = eStyleUnit_Null;
  420. aValue.mInt = 0;
  421. }
  422. /* static */ inline void
  423. nsStyleCoord::SetValue(nsStyleUnit& aUnit,
  424. nsStyleUnion& aValue,
  425. nsStyleUnit aOtherUnit,
  426. const nsStyleUnion& aOtherValue)
  427. {
  428. Reset(aUnit, aValue);
  429. InitWithValue(aUnit, aValue, aOtherUnit, aOtherValue);
  430. }
  431. /* static */ inline void
  432. nsStyleCoord::InitWithValue(nsStyleUnit& aUnit,
  433. nsStyleUnion& aValue,
  434. nsStyleUnit aOtherUnit,
  435. const nsStyleUnion& aOtherValue)
  436. {
  437. aUnit = aOtherUnit;
  438. aValue = aOtherValue;
  439. switch (aUnit) {
  440. case eStyleUnit_Calc:
  441. static_cast<Calc*>(aValue.mPointer)->AddRef();
  442. break;
  443. default:
  444. MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic");
  445. }
  446. }
  447. /* static */ inline void
  448. nsStyleCoord::SetValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
  449. const nsStyleCoord& aOther)
  450. {
  451. SetValue(aUnit, aValue, aOther.mUnit, aOther.mValue);
  452. }
  453. /* static */ inline void
  454. nsStyleCoord::InitWithValue(nsStyleUnit& aUnit, nsStyleUnion& aValue,
  455. const nsStyleCoord& aOther)
  456. {
  457. InitWithValue(aUnit, aValue, aOther.mUnit, aOther.mValue);
  458. }
  459. // -------------------------
  460. // nsStyleSides inlines
  461. //
  462. inline bool nsStyleSides::operator!=(const nsStyleSides& aOther) const
  463. {
  464. return !((*this) == aOther);
  465. }
  466. inline nsStyleUnit nsStyleSides::GetUnit(mozilla::css::Side aSide) const
  467. {
  468. return (nsStyleUnit)mUnits[aSide];
  469. }
  470. inline nsStyleUnit nsStyleSides::GetLeftUnit() const
  471. {
  472. return GetUnit(NS_SIDE_LEFT);
  473. }
  474. inline nsStyleUnit nsStyleSides::GetTopUnit() const
  475. {
  476. return GetUnit(NS_SIDE_TOP);
  477. }
  478. inline nsStyleUnit nsStyleSides::GetRightUnit() const
  479. {
  480. return GetUnit(NS_SIDE_RIGHT);
  481. }
  482. inline nsStyleUnit nsStyleSides::GetBottomUnit() const
  483. {
  484. return GetUnit(NS_SIDE_BOTTOM);
  485. }
  486. inline nsStyleCoord nsStyleSides::Get(mozilla::css::Side aSide) const
  487. {
  488. return nsStyleCoord(mValues[aSide], nsStyleUnit(mUnits[aSide]));
  489. }
  490. inline nsStyleCoord nsStyleSides::GetLeft() const
  491. {
  492. return Get(NS_SIDE_LEFT);
  493. }
  494. inline nsStyleCoord nsStyleSides::GetTop() const
  495. {
  496. return Get(NS_SIDE_TOP);
  497. }
  498. inline nsStyleCoord nsStyleSides::GetRight() const
  499. {
  500. return Get(NS_SIDE_RIGHT);
  501. }
  502. inline nsStyleCoord nsStyleSides::GetBottom() const
  503. {
  504. return Get(NS_SIDE_BOTTOM);
  505. }
  506. inline void nsStyleSides::Set(mozilla::css::Side aSide, const nsStyleCoord& aCoord)
  507. {
  508. nsStyleCoord::SetValue(mUnits[aSide], mValues[aSide], aCoord);
  509. }
  510. inline void nsStyleSides::SetLeft(const nsStyleCoord& aCoord)
  511. {
  512. Set(NS_SIDE_LEFT, aCoord);
  513. }
  514. inline void nsStyleSides::SetTop(const nsStyleCoord& aCoord)
  515. {
  516. Set(NS_SIDE_TOP, aCoord);
  517. }
  518. inline void nsStyleSides::SetRight(const nsStyleCoord& aCoord)
  519. {
  520. Set(NS_SIDE_RIGHT, aCoord);
  521. }
  522. inline void nsStyleSides::SetBottom(const nsStyleCoord& aCoord)
  523. {
  524. Set(NS_SIDE_BOTTOM, aCoord);
  525. }
  526. // -------------------------
  527. // nsStyleCorners inlines
  528. //
  529. inline bool nsStyleCorners::operator!=(const nsStyleCorners& aOther) const
  530. {
  531. return !((*this) == aOther);
  532. }
  533. inline nsStyleUnit nsStyleCorners::GetUnit(uint8_t aCorner) const
  534. {
  535. return (nsStyleUnit)mUnits[aCorner];
  536. }
  537. inline nsStyleCoord nsStyleCorners::Get(uint8_t aCorner) const
  538. {
  539. return nsStyleCoord(mValues[aCorner], nsStyleUnit(mUnits[aCorner]));
  540. }
  541. inline void nsStyleCorners::Set(uint8_t aCorner, const nsStyleCoord& aCoord)
  542. {
  543. nsStyleCoord::SetValue(mUnits[aCorner], mValues[aCorner], aCoord);
  544. }
  545. #endif /* nsStyleCoord_h___ */