Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef SMILTime_h | 26 #ifndef SMILTime_h |
| 27 #define SMILTime_h | 27 #define SMILTime_h |
| 28 | 28 |
| 29 #include "wtf/Assertions.h" | 29 #include "wtf/Assertions.h" |
| 30 #include "wtf/MathExtras.h" | 30 #include "wtf/MathExtras.h" |
| 31 #include "wtf/StdLibExtras.h" | |
| 31 | 32 |
| 32 namespace blink { | 33 namespace blink { |
| 33 | 34 |
| 34 class SMILTime { | 35 class SMILTime { |
| 35 public: | 36 public: |
| 36 SMILTime() : m_time(0) { } | 37 SMILTime() : m_time(0) { } |
| 37 SMILTime(double time) : m_time(time) { ASSERT(!std::isnan(time)); } | 38 SMILTime(double time) : m_time(time) { } |
| 38 SMILTime(const SMILTime& o) : m_time(o.m_time) { } | 39 SMILTime(const SMILTime& o) : m_time(o.m_time) { } |
|
fs
2014/08/19 21:49:43
While you're here... I believe this could be dropp
reni
2014/08/21 14:20:06
Done.
| |
| 39 | 40 |
| 40 static SMILTime unresolved() { return unresolvedValue; } | 41 static SMILTime unresolved() { return unresolvedValue(); } |
| 41 static SMILTime indefinite() { return indefiniteValue; } | 42 static SMILTime indefinite() { return indefiniteValue(); } |
| 42 | 43 |
| 43 SMILTime& operator=(const SMILTime& o) { m_time = o.m_time; return *this; } | 44 SMILTime& operator=(const SMILTime& o) { m_time = o.m_time; return *this; } |
|
fs
2014/08/19 21:49:43
This should be possible to drop as well.
reni
2014/08/21 14:20:06
Done.
| |
| 44 double value() const { return m_time; } | 45 double value() const { return m_time; } |
| 45 | 46 |
| 46 bool isFinite() const { return m_time < indefiniteValue; } | 47 bool isFinite() const { return m_time < indefiniteValue(); } |
|
fs
2014/08/19 21:49:43
Use std::isfinite here (hopefully that also droppi
reni
2014/08/21 14:20:06
Done.
| |
| 47 bool isIndefinite() const { return m_time == indefiniteValue; } | 48 bool isIndefinite() const { return std::isinf(m_time); } |
| 48 bool isUnresolved() const { return m_time == unresolvedValue; } | 49 bool isUnresolved() const { return std::isnan(m_time); } |
| 49 | 50 |
| 50 private: | 51 private: |
| 51 static const double unresolvedValue; | 52 static const double& unresolvedValue() |
|
fs
2014/08/19 21:49:43
I'd suggest instead just have unresolved()/indefin
reni
2014/08/21 14:20:06
Done.
| |
| 52 static const double indefiniteValue; | 53 { |
| 54 DEFINE_STATIC_LOCAL(double, unresolvedValue, (std::numeric_limits<double >::quiet_NaN())); | |
| 55 return unresolvedValue; | |
| 56 } | |
| 57 | |
| 58 static const double& indefiniteValue() | |
| 59 { | |
| 60 DEFINE_STATIC_LOCAL(double, indefiniteValue, (std::numeric_limits<double >::infinity())); | |
| 61 return indefiniteValue; | |
| 62 } | |
| 53 | 63 |
| 54 double m_time; | 64 double m_time; |
| 55 }; | 65 }; |
| 56 | 66 |
| 57 class SMILTimeWithOrigin { | 67 class SMILTimeWithOrigin { |
| 58 public: | 68 public: |
| 59 enum Origin { | 69 enum Origin { |
| 60 ParserOrigin, | 70 ParserOrigin, |
| 61 ScriptOrigin | 71 ScriptOrigin |
| 62 }; | 72 }; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 81 }; | 91 }; |
| 82 | 92 |
| 83 struct SMILInterval { | 93 struct SMILInterval { |
| 84 SMILInterval() { } | 94 SMILInterval() { } |
| 85 SMILInterval(const SMILTime& begin, const SMILTime& end) : begin(begin), end (end) { } | 95 SMILInterval(const SMILTime& begin, const SMILTime& end) : begin(begin), end (end) { } |
| 86 | 96 |
| 87 SMILTime begin; | 97 SMILTime begin; |
| 88 SMILTime end; | 98 SMILTime end; |
| 89 }; | 99 }; |
| 90 | 100 |
| 91 inline bool operator==(const SMILTime& a, const SMILTime& b) { return a.isFinite () && a.value() == b.value(); } | 101 inline bool operator==(const SMILTime& a, const SMILTime& b) |
| 92 inline bool operator!(const SMILTime& a) { return !a.isFinite() || !a.value(); } | 102 { |
| 93 inline bool operator!=(const SMILTime& a, const SMILTime& b) { return !operator= =(a, b); } | 103 if (a.isUnresolved() && b.isUnresolved()) |
| 94 inline bool operator>(const SMILTime& a, const SMILTime& b) { return a.value() > b.value(); } | 104 return true; |
| 95 inline bool operator<(const SMILTime& a, const SMILTime& b) { return a.value() < b.value(); } | 105 return a.isFinite() && a.value() == b.value(); |
|
fs
2014/08/19 21:49:43
I think the following would work equal well:
a.is
fs
2014/08/19 22:27:14
s/==/&&/
reni
2014/08/21 14:20:06
Done.
| |
| 96 inline bool operator>=(const SMILTime& a, const SMILTime& b) { return a.value() > b.value() || operator==(a, b); } | 106 } |
| 97 inline bool operator<=(const SMILTime& a, const SMILTime& b) { return a.value() < b.value() || operator==(a, b); } | 107 |
| 98 inline bool operator<(const SMILTimeWithOrigin& a, const SMILTimeWithOrigin& b) { return a.time() < b.time(); } | 108 inline bool operator!(const SMILTime& a) |
| 109 { | |
| 110 return !a.isFinite() || !a.value(); | |
|
fs
2014/08/19 21:49:43
It's _probably_ possible to simplify this (to just
| |
| 111 } | |
| 112 | |
| 113 inline bool operator!=(const SMILTime& a, const SMILTime& b) | |
| 114 { | |
| 115 if (a.isUnresolved() && b.isUnresolved()) | |
| 116 return false; | |
| 117 if (a.isUnresolved() || b.isUnresolved()) | |
| 118 return true; | |
| 119 return !operator==(a, b); | |
|
fs
2014/08/19 21:49:43
This really ought to be possible to have as it pre
reni
2014/08/21 14:20:06
Done.
| |
| 120 } | |
| 121 | |
| 122 inline bool operator>(const SMILTime& a, const SMILTime& b) | |
| 123 { | |
| 124 if (a.isUnresolved() && b.isUnresolved()) | |
| 125 return false; | |
| 126 if (a.isUnresolved()) | |
| 127 return true; | |
| 128 if (b.isUnresolved()) | |
| 129 return false; | |
| 130 return a.value() > b.value(); | |
|
fs
2014/08/19 21:49:43
Make this:
a.isUnresolved() || a.value() > b.valu
reni
2014/08/21 14:20:06
Done.
fs
2014/08/21 15:30:39
It dawned on me why we want the LHS here. In gener
reni
2014/08/21 20:52:31
Done.
| |
| 131 } | |
| 132 | |
| 133 inline bool operator<(const SMILTime& a, const SMILTime& b) | |
| 134 { | |
| 135 if (a.isUnresolved() && b.isUnresolved()) | |
| 136 return false; | |
| 137 if (a.isUnresolved()) | |
| 138 return false; | |
| 139 if (b.isUnresolved()) | |
| 140 return true; | |
| 141 return a.value() < b.value(); | |
|
fs
2014/08/19 21:49:43
Could either use the operator> above (with operand
reni
2014/08/21 14:20:06
Done.
| |
| 142 } | |
| 143 | |
| 144 inline bool operator>=(const SMILTime& a, const SMILTime& b) | |
| 145 { | |
| 146 if (a.isUnresolved() && b.isUnresolved()) | |
| 147 return true; | |
| 148 if (a.isUnresolved()) | |
| 149 return true; | |
| 150 if (b.isUnresolved()) | |
| 151 return false; | |
| 152 return a.value() > b.value() || operator==(a, b); | |
|
fs
2014/08/19 21:49:43
This (and <=) could just use the operator> (operat
reni
2014/08/21 14:20:06
Done.
| |
| 153 } | |
| 154 | |
| 155 inline bool operator<=(const SMILTime& a, const SMILTime& b) | |
| 156 { | |
| 157 if (a.isUnresolved() && b.isUnresolved()) | |
| 158 return true; | |
| 159 if (a.isUnresolved()) | |
| 160 return false; | |
| 161 if (b.isUnresolved()) | |
| 162 return true; | |
| 163 return a.value() < b.value() || operator==(a, b); | |
| 164 } | |
| 165 | |
| 166 inline bool operator<(const SMILTimeWithOrigin& a, const SMILTimeWithOrigin& b) | |
| 167 { | |
| 168 return a.time() < b.time(); | |
| 169 } | |
| 99 | 170 |
| 100 SMILTime operator+(const SMILTime&, const SMILTime&); | 171 SMILTime operator+(const SMILTime&, const SMILTime&); |
| 101 SMILTime operator-(const SMILTime&, const SMILTime&); | 172 SMILTime operator-(const SMILTime&, const SMILTime&); |
| 102 // So multiplying times does not make too much sense but SMIL defines it for dur ation * repeatCount | 173 // So multiplying times does not make too much sense but SMIL defines it for dur ation * repeatCount |
| 103 SMILTime operator*(const SMILTime&, const SMILTime&); | 174 SMILTime operator*(const SMILTime&, const SMILTime&); |
| 104 | 175 |
| 105 inline bool operator!=(const SMILInterval& a, const SMILInterval& b) | 176 inline bool operator!=(const SMILInterval& a, const SMILInterval& b) |
| 106 { | 177 { |
| 107 // Compare the "raw" values since the operator!= for SMILTime always return | 178 // Compare the "raw" values since the operator!= for SMILTime always return |
| 108 // true for non-finite times. | 179 // true for non-finite times. |
| 109 return a.begin.value() != b.begin.value() || a.end.value() != b.end.value(); | 180 return a.begin.value() != b.begin.value() || a.end.value() != b.end.value(); |
| 110 } | 181 } |
| 111 | 182 |
| 112 } | 183 } |
| 113 | 184 |
| 114 #endif // SMILTime_h | 185 #endif // SMILTime_h |
| OLD | NEW |