Coverage Report

Created: 2018-09-25 14:53

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