/work/obj-fuzz/dist/include/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 | 0 | bool operator==(const CalcValue& aOther) const { |
101 | 0 | return mLength == aOther.mLength && |
102 | 0 | mPercent == aOther.mPercent && |
103 | 0 | mHasPercent == aOther.mHasPercent; |
104 | 0 | } |
105 | 0 | bool operator!=(const CalcValue& aOther) const { |
106 | 0 | return !(*this == aOther); |
107 | 0 | } |
108 | | |
109 | 0 | nscoord ToLength() const { |
110 | 0 | MOZ_ASSERT(!mHasPercent); |
111 | 0 | return mLength; |
112 | 0 | } |
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 | 0 | 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 | 0 | Calc() {} |
124 | | |
125 | | private: |
126 | | Calc(const Calc&) = delete; |
127 | 0 | ~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 | 0 | ~nsStyleCoord() { Reset(); } |
139 | | |
140 | | nsStyleCoord& operator=(const nsStyleCoord& aOther) |
141 | 0 | { |
142 | 0 | if (this != &aOther) { |
143 | 0 | SetValue(mUnit, mValue, aOther); |
144 | 0 | } |
145 | 0 | return *this; |
146 | 0 | } |
147 | | bool operator==(const nsStyleCoord& aOther) const; |
148 | | bool operator!=(const nsStyleCoord& aOther) const; |
149 | | |
150 | 0 | nsStyleUnit GetUnit() const { |
151 | 0 | NS_ASSERTION(mUnit != eStyleUnit_Null, "reading uninitialized value"); |
152 | 0 | return mUnit; |
153 | 0 | } |
154 | | |
155 | 0 | bool IsAngleValue() const { |
156 | 0 | return eStyleUnit_Degree <= mUnit && mUnit <= eStyleUnit_Turn; |
157 | 0 | } |
158 | | |
159 | 0 | static bool IsCalcUnit(nsStyleUnit aUnit) { |
160 | 0 | return aUnit == eStyleUnit_Calc; |
161 | 0 | } |
162 | | |
163 | 0 | static bool IsPointerUnit(nsStyleUnit aUnit) { |
164 | 0 | return IsCalcUnit(aUnit); |
165 | 0 | } |
166 | | |
167 | 0 | bool IsCalcUnit() const { |
168 | 0 | return IsCalcUnit(mUnit); |
169 | 0 | } |
170 | | |
171 | 0 | bool IsPointerValue() const { |
172 | 0 | return IsPointerUnit(mUnit); |
173 | 0 | } |
174 | | |
175 | 0 | bool IsCoordPercentCalcUnit() const { |
176 | 0 | return mUnit == eStyleUnit_Coord || |
177 | 0 | mUnit == eStyleUnit_Percent || |
178 | 0 | IsCalcUnit(); |
179 | 0 | } |
180 | | |
181 | | // Does this calc() expression have any percentages inside it? Can be |
182 | | // called only when IsCalcUnit() is true. |
183 | 0 | bool CalcHasPercent() const { |
184 | 0 | return GetCalcValue()->mHasPercent; |
185 | 0 | } |
186 | | |
187 | 0 | bool HasPercent() const { |
188 | 0 | return mUnit == eStyleUnit_Percent || |
189 | 0 | (IsCalcUnit() && CalcHasPercent()); |
190 | 0 | } |
191 | | |
192 | | static bool ConvertsToLength(const nsStyleUnit aUnit, |
193 | 0 | const nsStyleUnion aValue) { |
194 | 0 | return aUnit == eStyleUnit_Coord || |
195 | 0 | (IsCalcUnit(aUnit) && !AsCalcValue(aValue)->mHasPercent); |
196 | 0 | } |
197 | | |
198 | 0 | bool ConvertsToLength() const { |
199 | 0 | return ConvertsToLength(mUnit, mValue); |
200 | 0 | } |
201 | | |
202 | 0 | static nscoord ToLength(nsStyleUnit aUnit, nsStyleUnion aValue) { |
203 | 0 | MOZ_ASSERT(ConvertsToLength(aUnit, aValue)); |
204 | 0 | if (IsCalcUnit(aUnit)) { |
205 | 0 | return AsCalcValue(aValue)->ToLength(); // Note: This asserts !mHasPercent |
206 | 0 | } |
207 | 0 | MOZ_ASSERT(aUnit == eStyleUnit_Coord); |
208 | 0 | return aValue.mInt; |
209 | 0 | } |
210 | | |
211 | 0 | nscoord ToLength() const { |
212 | 0 | return ToLength(GetUnit(), mValue); |
213 | 0 | } |
214 | | |
215 | | // Callers must verify IsCalcUnit before calling this function. |
216 | 0 | static Calc* AsCalcValue(nsStyleUnion aValue) { |
217 | 0 | return static_cast<Calc*>(aValue.mPointer); |
218 | 0 | } |
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 | 0 | { |
246 | 0 | MOZ_ASSERT(GetUnit() == eStyleUnit_Enumerated, |
247 | 0 | "The unit must be eStyleUnit_Enumerated!"); |
248 | 0 | return static_cast<T>(GetIntValue()); |
249 | 0 | } Unexecuted instantiation: mozilla::StyleShapeRadius nsStyleCoord::GetEnumValue<mozilla::StyleShapeRadius, void>() const Unexecuted instantiation: mozilla::StyleGridTrackBreadth nsStyleCoord::GetEnumValue<mozilla::StyleGridTrackBreadth, void>() const |
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 | 0 | nscoord ToLength(mozilla::Side aSide) const { |
364 | 0 | return nsStyleCoord::ToLength(mUnits[aSide], mValues[aSide]); |
365 | 0 | } |
366 | | |
367 | 0 | bool ConvertsToLength() const { |
368 | 0 | NS_FOR_CSS_SIDES(side) { |
369 | 0 | if (!nsStyleCoord::ConvertsToLength(mUnits[side], mValues[side])) { |
370 | 0 | return false; |
371 | 0 | } |
372 | 0 | } |
373 | 0 | return true; |
374 | 0 | } |
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 | 0 | { |
427 | 0 | mValue.mInt = aValue; |
428 | 0 | } |
429 | | |
430 | | inline nsStyleCoord::nsStyleCoord(const nsStyleCoord& aCopy) |
431 | | : mUnit(eStyleUnit_Null) |
432 | 0 | { |
433 | 0 | InitWithValue(mUnit, mValue, aCopy); |
434 | 0 | } |
435 | | |
436 | | inline nsStyleCoord::nsStyleCoord(const nsStyleUnion& aValue, nsStyleUnit aUnit) |
437 | | : mUnit(eStyleUnit_Null) |
438 | 0 | { |
439 | 0 | InitWithValue(mUnit, mValue, aUnit, aValue); |
440 | 0 | } |
441 | | |
442 | | inline bool nsStyleCoord::operator!=(const nsStyleCoord& aOther) const |
443 | 0 | { |
444 | 0 | return !((*this) == aOther); |
445 | 0 | } |
446 | | |
447 | | inline nscoord nsStyleCoord::GetCoordValue() const |
448 | 0 | { |
449 | 0 | NS_ASSERTION((mUnit == eStyleUnit_Coord), "not a coord value"); |
450 | 0 | if (mUnit == eStyleUnit_Coord) { |
451 | 0 | return mValue.mInt; |
452 | 0 | } |
453 | 0 | return 0; |
454 | 0 | } |
455 | | |
456 | | inline int32_t nsStyleCoord::GetIntValue() const |
457 | 0 | { |
458 | 0 | NS_ASSERTION((mUnit == eStyleUnit_Enumerated) || |
459 | 0 | (mUnit == eStyleUnit_Integer), "not an int value"); |
460 | 0 | if ((mUnit == eStyleUnit_Enumerated) || |
461 | 0 | (mUnit == eStyleUnit_Integer)) { |
462 | 0 | return mValue.mInt; |
463 | 0 | } |
464 | 0 | return 0; |
465 | 0 | } |
466 | | |
467 | | inline float nsStyleCoord::GetPercentValue() const |
468 | 0 | { |
469 | 0 | NS_ASSERTION(mUnit == eStyleUnit_Percent, "not a percent value"); |
470 | 0 | if (mUnit == eStyleUnit_Percent) { |
471 | 0 | return mValue.mFloat; |
472 | 0 | } |
473 | 0 | return 0.0f; |
474 | 0 | } |
475 | | |
476 | | inline float nsStyleCoord::GetFactorValue() const |
477 | 0 | { |
478 | 0 | NS_ASSERTION(mUnit == eStyleUnit_Factor, "not a factor value"); |
479 | 0 | if (mUnit == eStyleUnit_Factor) { |
480 | 0 | return mValue.mFloat; |
481 | 0 | } |
482 | 0 | return 0.0f; |
483 | 0 | } |
484 | | |
485 | | inline float nsStyleCoord::GetFactorOrPercentValue() const |
486 | | { |
487 | | NS_ASSERTION(mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent, |
488 | | "not a percent or factor value"); |
489 | | if (mUnit == eStyleUnit_Factor || mUnit == eStyleUnit_Percent) { |
490 | | return mValue.mFloat; |
491 | | } |
492 | | return 0.0f; |
493 | | } |
494 | | |
495 | | inline float nsStyleCoord::GetAngleValue() const |
496 | 0 | { |
497 | 0 | NS_ASSERTION(mUnit >= eStyleUnit_Degree && |
498 | 0 | mUnit <= eStyleUnit_Turn, "not an angle value"); |
499 | 0 | if (mUnit >= eStyleUnit_Degree && mUnit <= eStyleUnit_Turn) { |
500 | 0 | return mValue.mFloat; |
501 | 0 | } |
502 | 0 | return 0.0f; |
503 | 0 | } |
504 | | |
505 | | inline float nsStyleCoord::GetFlexFractionValue() const |
506 | 0 | { |
507 | 0 | NS_ASSERTION(mUnit == eStyleUnit_FlexFraction, "not a fr value"); |
508 | 0 | if (mUnit == eStyleUnit_FlexFraction) { |
509 | 0 | return mValue.mFloat; |
510 | 0 | } |
511 | 0 | return 0.0f; |
512 | 0 | } |
513 | | |
514 | | inline nsStyleCoord::Calc* nsStyleCoord::GetCalcValue() const |
515 | 0 | { |
516 | 0 | NS_ASSERTION(IsCalcUnit(), "not a pointer value"); |
517 | 0 | if (IsCalcUnit()) { |
518 | 0 | return AsCalcValue(mValue); |
519 | 0 | } |
520 | 0 | return nullptr; |
521 | 0 | } |
522 | | |
523 | | /* static */ inline void |
524 | | nsStyleCoord::Reset(nsStyleUnit& aUnit, nsStyleUnion& aValue) |
525 | 0 | { |
526 | 0 | MOZ_ASSERT(aUnit <= eStyleUnit_MAX, |
527 | 0 | "calling Reset on uninitialized nsStyleCoord?"); |
528 | 0 |
|
529 | 0 | switch (aUnit) { |
530 | 0 | case eStyleUnit_Calc: |
531 | 0 | static_cast<Calc*>(aValue.mPointer)->Release(); |
532 | 0 | break; |
533 | 0 | default: |
534 | 0 | MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic"); |
535 | 0 | } |
536 | 0 |
|
537 | 0 | aUnit = eStyleUnit_Null; |
538 | 0 | aValue.mInt = 0; |
539 | 0 | } |
540 | | |
541 | | /* static */ inline void |
542 | | nsStyleCoord::SetValue(nsStyleUnit& aUnit, |
543 | | nsStyleUnion& aValue, |
544 | | nsStyleUnit aOtherUnit, |
545 | | const nsStyleUnion& aOtherValue) |
546 | 0 | { |
547 | 0 | Reset(aUnit, aValue); |
548 | 0 | InitWithValue(aUnit, aValue, aOtherUnit, aOtherValue); |
549 | 0 | } |
550 | | |
551 | | /* static */ inline void |
552 | | nsStyleCoord::InitWithValue(nsStyleUnit& aUnit, |
553 | | nsStyleUnion& aValue, |
554 | | nsStyleUnit aOtherUnit, |
555 | | const nsStyleUnion& aOtherValue) |
556 | 0 | { |
557 | 0 | aUnit = aOtherUnit; |
558 | 0 | aValue = aOtherValue; |
559 | 0 |
|
560 | 0 | switch (aUnit) { |
561 | 0 | case eStyleUnit_Calc: |
562 | 0 | static_cast<Calc*>(aValue.mPointer)->AddRef(); |
563 | 0 | break; |
564 | 0 | default: |
565 | 0 | MOZ_ASSERT(!IsPointerUnit(aUnit), "check pointer refcounting logic"); |
566 | 0 | } |
567 | 0 | } |
568 | | |
569 | | /* static */ inline void |
570 | | nsStyleCoord::SetValue(nsStyleUnit& aUnit, nsStyleUnion& aValue, |
571 | | const nsStyleCoord& aOther) |
572 | 0 | { |
573 | 0 | SetValue(aUnit, aValue, aOther.mUnit, aOther.mValue); |
574 | 0 | } |
575 | | |
576 | | /* static */ inline void |
577 | | nsStyleCoord::InitWithValue(nsStyleUnit& aUnit, nsStyleUnion& aValue, |
578 | | const nsStyleCoord& aOther) |
579 | 0 | { |
580 | 0 | InitWithValue(aUnit, aValue, aOther.mUnit, aOther.mValue); |
581 | 0 | } |
582 | | |
583 | | |
584 | | // ------------------------- |
585 | | // nsStyleSides inlines |
586 | | // |
587 | | inline bool nsStyleSides::operator!=(const nsStyleSides& aOther) const |
588 | 0 | { |
589 | 0 | return !((*this) == aOther); |
590 | 0 | } |
591 | | |
592 | | inline nsStyleUnit nsStyleSides::GetUnit(mozilla::Side aSide) const |
593 | 0 | { |
594 | 0 | return (nsStyleUnit)mUnits[aSide]; |
595 | 0 | } |
596 | | |
597 | | inline nsStyleUnit nsStyleSides::GetLeftUnit() const |
598 | 0 | { |
599 | 0 | return GetUnit(mozilla::eSideLeft); |
600 | 0 | } |
601 | | |
602 | | inline nsStyleUnit nsStyleSides::GetTopUnit() const |
603 | 0 | { |
604 | 0 | return GetUnit(mozilla::eSideTop); |
605 | 0 | } |
606 | | |
607 | | inline nsStyleUnit nsStyleSides::GetRightUnit() const |
608 | 0 | { |
609 | 0 | return GetUnit(mozilla::eSideRight); |
610 | 0 | } |
611 | | |
612 | | inline nsStyleUnit nsStyleSides::GetBottomUnit() const |
613 | 0 | { |
614 | 0 | return GetUnit(mozilla::eSideBottom); |
615 | 0 | } |
616 | | |
617 | | inline nsStyleCoord nsStyleSides::Get(mozilla::Side aSide) const |
618 | 0 | { |
619 | 0 | return nsStyleCoord(mValues[aSide], nsStyleUnit(mUnits[aSide])); |
620 | 0 | } |
621 | | |
622 | | inline nsStyleCoord nsStyleSides::GetLeft() const |
623 | 0 | { |
624 | 0 | return Get(mozilla::eSideLeft); |
625 | 0 | } |
626 | | |
627 | | inline nsStyleCoord nsStyleSides::GetTop() const |
628 | 0 | { |
629 | 0 | return Get(mozilla::eSideTop); |
630 | 0 | } |
631 | | |
632 | | inline nsStyleCoord nsStyleSides::GetRight() const |
633 | 0 | { |
634 | 0 | return Get(mozilla::eSideRight); |
635 | 0 | } |
636 | | |
637 | | inline nsStyleCoord nsStyleSides::GetBottom() const |
638 | 0 | { |
639 | 0 | return Get(mozilla::eSideBottom); |
640 | 0 | } |
641 | | |
642 | | inline void nsStyleSides::Set(mozilla::Side aSide, const nsStyleCoord& aCoord) |
643 | 0 | { |
644 | 0 | nsStyleCoord::SetValue(mUnits[aSide], mValues[aSide], aCoord); |
645 | 0 | } |
646 | | |
647 | | inline void nsStyleSides::SetLeft(const nsStyleCoord& aCoord) |
648 | 0 | { |
649 | 0 | Set(mozilla::eSideLeft, aCoord); |
650 | 0 | } |
651 | | |
652 | | inline void nsStyleSides::SetTop(const nsStyleCoord& aCoord) |
653 | 0 | { |
654 | 0 | Set(mozilla::eSideTop, aCoord); |
655 | 0 | } |
656 | | |
657 | | inline void nsStyleSides::SetRight(const nsStyleCoord& aCoord) |
658 | 0 | { |
659 | 0 | Set(mozilla::eSideRight, aCoord); |
660 | 0 | } |
661 | | |
662 | | inline void nsStyleSides::SetBottom(const nsStyleCoord& aCoord) |
663 | 0 | { |
664 | 0 | Set(mozilla::eSideBottom, aCoord); |
665 | 0 | } |
666 | | |
667 | | // ------------------------- |
668 | | // nsStyleCorners inlines |
669 | | // |
670 | | inline bool nsStyleCorners::operator!=(const nsStyleCorners& aOther) const |
671 | 0 | { |
672 | 0 | return !((*this) == aOther); |
673 | 0 | } |
674 | | |
675 | | inline nsStyleUnit nsStyleCorners::GetUnit(uint8_t aCorner) const |
676 | 0 | { |
677 | 0 | return (nsStyleUnit)mUnits[aCorner]; |
678 | 0 | } |
679 | | |
680 | | inline nsStyleCoord nsStyleCorners::Get(uint8_t aCorner) const |
681 | 0 | { |
682 | 0 | return nsStyleCoord(mValues[aCorner], nsStyleUnit(mUnits[aCorner])); |
683 | 0 | } |
684 | | |
685 | | inline void nsStyleCorners::Set(uint8_t aCorner, const nsStyleCoord& aCoord) |
686 | 0 | { |
687 | 0 | nsStyleCoord::SetValue(mUnits[aCorner], mValues[aCorner], aCoord); |
688 | 0 | } |
689 | | |
690 | | #endif /* nsStyleCoord_h___ */ |