OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 3 Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
4 Copyright (C) 2011 Rik Cabanier (cabanier@adobe.com) | 4 Copyright (C) 2011 Rik Cabanier (cabanier@adobe.com) |
5 Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. | 5 Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. |
6 | 6 |
7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 WTF_MAKE_FAST_ALLOCATED; | 42 WTF_MAKE_FAST_ALLOCATED; |
43 public: | 43 public: |
44 Length() | 44 Length() |
45 : m_intValue(0), m_quirk(false), m_type(Auto), m_isFloat(false) | 45 : m_intValue(0), m_quirk(false), m_type(Auto), m_isFloat(false) |
46 { | 46 { |
47 } | 47 } |
48 | 48 |
49 Length(LengthType t) | 49 Length(LengthType t) |
50 : m_intValue(0), m_quirk(false), m_type(t), m_isFloat(false) | 50 : m_intValue(0), m_quirk(false), m_type(t), m_isFloat(false) |
51 { | 51 { |
| 52 ASSERT(t != Calculated); |
52 } | 53 } |
53 | 54 |
54 Length(int v, LengthType t, bool q = false) | 55 Length(int v, LengthType t, bool q = false) |
55 : m_intValue(v), m_quirk(q), m_type(t), m_isFloat(false) | 56 : m_intValue(v), m_quirk(q), m_type(t), m_isFloat(false) |
56 { | 57 { |
| 58 ASSERT(t != Calculated); |
57 } | 59 } |
58 | 60 |
59 Length(FractionalLayoutUnit v, LengthType t, bool q = false) | 61 Length(FractionalLayoutUnit v, LengthType t, bool q = false) |
60 : m_floatValue(v.toFloat()), m_quirk(q), m_type(t), m_isFloat(true) | 62 : m_floatValue(v.toFloat()), m_quirk(q), m_type(t), m_isFloat(true) |
61 { | 63 { |
| 64 ASSERT(t != Calculated); |
62 } | 65 } |
63 | 66 |
64 Length(float v, LengthType t, bool q = false) | 67 Length(float v, LengthType t, bool q = false) |
65 : m_floatValue(v), m_quirk(q), m_type(t), m_isFloat(true) | 68 : m_floatValue(v), m_quirk(q), m_type(t), m_isFloat(true) |
66 { | 69 { |
| 70 ASSERT(t != Calculated); |
67 } | 71 } |
68 | 72 |
69 Length(double v, LengthType t, bool q = false) | 73 Length(double v, LengthType t, bool q = false) |
70 : m_quirk(q), m_type(t), m_isFloat(true) | 74 : m_quirk(q), m_type(t), m_isFloat(true) |
71 { | 75 { |
72 m_floatValue = static_cast<float>(v); | 76 m_floatValue = static_cast<float>(v); |
73 } | 77 } |
74 | 78 |
75 explicit Length(PassRefPtr<CalculationValue>); | 79 explicit Length(PassRefPtr<CalculationValue>); |
76 | 80 |
77 Length(const Length& length) | 81 Length(const Length& length) |
78 { | 82 { |
79 initFromLength(length); | 83 initFromLength(length); |
80 } | 84 } |
81 | 85 |
82 Length& operator=(const Length& length) | 86 Length& operator=(const Length& length) |
83 { | 87 { |
84 initFromLength(length); | 88 initFromLength(length); |
85 return *this; | 89 return *this; |
86 } | 90 } |
87 | 91 |
88 ~Length() | 92 ~Length() |
89 { | 93 { |
90 if (isCalculated()) | 94 if (isCalculated()) |
91 decrementCalculatedRef(); | 95 decrementCalculatedRef(); |
92 } | 96 } |
93 | 97 |
94 bool operator==(const Length& o) const { return (m_type == o.m_type) && (m_q
uirk == o.m_quirk) && (isUndefined() || (getFloatValue() == o.getFloatValue()));
} | 98 bool operator==(const Length& o) const { return (m_type == o.m_type) && (m_q
uirk == o.m_quirk) && (isUndefined() || (getFloatValue() == o.getFloatValue()) |
| isCalculatedEqual(o)); } |
95 bool operator!=(const Length& o) const { return !(*this == o); } | 99 bool operator!=(const Length& o) const { return !(*this == o); } |
96 | 100 |
97 const Length& operator*=(float v) | 101 const Length& operator*=(float v) |
98 { | 102 { |
99 if (isCalculated()) { | 103 if (isCalculated()) { |
100 ASSERT_NOT_REACHED(); | 104 ASSERT_NOT_REACHED(); |
101 return *this; | 105 return *this; |
102 } | 106 } |
103 | 107 |
104 if (m_isFloat) | 108 if (m_isFloat) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 return getFloatValue() < 0; | 209 return getFloatValue() < 0; |
206 } | 210 } |
207 | 211 |
208 bool isAuto() const { return type() == Auto; } | 212 bool isAuto() const { return type() == Auto; } |
209 bool isRelative() const { return type() == Relative; } | 213 bool isRelative() const { return type() == Relative; } |
210 bool isPercent() const { return type() == Percent || type() == Calculated; } | 214 bool isPercent() const { return type() == Percent || type() == Calculated; } |
211 bool isFixed() const { return type() == Fixed; } | 215 bool isFixed() const { return type() == Fixed; } |
212 bool isIntrinsicOrAuto() const { return type() == Auto || type() == MinIntri
nsic || type() == Intrinsic; } | 216 bool isIntrinsicOrAuto() const { return type() == Auto || type() == MinIntri
nsic || type() == Intrinsic; } |
213 bool isSpecified() const { return type() == Fixed || type() == Percent || ty
pe() == Calculated || isViewportPercentage(); } | 217 bool isSpecified() const { return type() == Fixed || type() == Percent || ty
pe() == Calculated || isViewportPercentage(); } |
214 bool isCalculated() const { return type() == Calculated; } | 218 bool isCalculated() const { return type() == Calculated; } |
| 219 bool isCalculatedEqual(const Length&) const; |
215 | 220 |
216 Length blend(const Length& from, double progress) const | 221 Length blend(const Length& from, double progress) const |
217 { | 222 { |
218 // Blend two lengths to produce a new length that is in between them. U
sed for animation. | 223 // Blend two lengths to produce a new length that is in between them. U
sed for animation. |
219 if (!from.isZero() && !isZero() && from.type() != type()) | 224 if (!from.isZero() && !isZero() && from.type() != type()) |
220 return *this; | 225 return *this; |
221 | 226 |
222 if (from.isZero() && isZero()) | 227 if (from.isZero() && isZero()) |
223 return *this; | 228 return *this; |
| 229 |
| 230 // FIXME http://webkit.org/b/86160 - Blending doesn't work with calculat
ed expressions |
| 231 if (type() == Calculated) |
| 232 return *this; |
224 | 233 |
225 LengthType resultType = type(); | 234 LengthType resultType = type(); |
226 if (isZero()) | 235 if (isZero()) |
227 resultType = from.type(); | 236 resultType = from.type(); |
228 | 237 |
229 if (resultType == Percent) { | 238 if (resultType == Percent) { |
230 float fromPercent = from.isZero() ? 0 : from.percent(); | 239 float fromPercent = from.isZero() ? 0 : from.percent(); |
231 float toPercent = isZero() ? 0 : percent(); | 240 float toPercent = isZero() ? 0 : percent(); |
232 return Length(WebCore::blend(fromPercent, toPercent, progress), Perc
ent); | 241 return Length(WebCore::blend(fromPercent, toPercent, progress), Perc
ent); |
233 } | 242 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 unsigned char m_type; | 300 unsigned char m_type; |
292 bool m_isFloat; | 301 bool m_isFloat; |
293 }; | 302 }; |
294 | 303 |
295 PassOwnArrayPtr<Length> newCoordsArray(const String&, int& len); | 304 PassOwnArrayPtr<Length> newCoordsArray(const String&, int& len); |
296 PassOwnArrayPtr<Length> newLengthArray(const String&, int& len); | 305 PassOwnArrayPtr<Length> newLengthArray(const String&, int& len); |
297 | 306 |
298 } // namespace WebCore | 307 } // namespace WebCore |
299 | 308 |
300 #endif // Length_h | 309 #endif // Length_h |
OLD | NEW |