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 16 matching lines...) Expand all Loading... |
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 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 class SMILTime { | 34 class SMILTime { |
35 public: | 35 public: |
36 SMILTime() : m_time(0) { } | 36 SMILTime() : m_time(0) { } |
37 SMILTime(double time) : m_time(time) { ASSERT(!std::isnan(time)); } | 37 SMILTime(double time) : m_time(time) { } |
38 SMILTime(const SMILTime& o) : m_time(o.m_time) { } | |
39 | 38 |
40 static SMILTime unresolved() { return unresolvedValue; } | 39 static SMILTime unresolved() { return std::numeric_limits<double>::quiet_NaN
(); } |
41 static SMILTime indefinite() { return indefiniteValue; } | 40 static SMILTime indefinite() { return std::numeric_limits<double>::infinity(
); } |
42 | 41 |
43 SMILTime& operator=(const SMILTime& o) { m_time = o.m_time; return *this; } | |
44 double value() const { return m_time; } | 42 double value() const { return m_time; } |
45 | 43 |
46 bool isFinite() const { return m_time < indefiniteValue; } | 44 bool isFinite() const { return std::isfinite(m_time); } |
47 bool isIndefinite() const { return m_time == indefiniteValue; } | 45 bool isIndefinite() const { return std::isinf(m_time); } |
48 bool isUnresolved() const { return m_time == unresolvedValue; } | 46 bool isUnresolved() const { return std::isnan(m_time); } |
49 | 47 |
50 private: | 48 private: |
51 static const double unresolvedValue; | |
52 static const double indefiniteValue; | |
53 | |
54 double m_time; | 49 double m_time; |
55 }; | 50 }; |
56 | 51 |
57 class SMILTimeWithOrigin { | 52 class SMILTimeWithOrigin { |
58 public: | 53 public: |
59 enum Origin { | 54 enum Origin { |
60 ParserOrigin, | 55 ParserOrigin, |
61 ScriptOrigin | 56 ScriptOrigin |
62 }; | 57 }; |
63 | 58 |
(...skipping 17 matching lines...) Expand all Loading... |
81 }; | 76 }; |
82 | 77 |
83 struct SMILInterval { | 78 struct SMILInterval { |
84 SMILInterval() { } | 79 SMILInterval() { } |
85 SMILInterval(const SMILTime& begin, const SMILTime& end) : begin(begin), end
(end) { } | 80 SMILInterval(const SMILTime& begin, const SMILTime& end) : begin(begin), end
(end) { } |
86 | 81 |
87 SMILTime begin; | 82 SMILTime begin; |
88 SMILTime end; | 83 SMILTime end; |
89 }; | 84 }; |
90 | 85 |
91 inline bool operator==(const SMILTime& a, const SMILTime& b) { return a.isFinite
() && a.value() == b.value(); } | 86 inline bool operator==(const SMILTime& a, const SMILTime& b) { return (a.isUnres
olved() && b.isUnresolved()) || a.value() == b.value(); } |
92 inline bool operator!(const SMILTime& a) { return !a.isFinite() || !a.value(); } | 87 inline bool operator!(const SMILTime& a) { return !a.isFinite() || !a.value(); } |
93 inline bool operator!=(const SMILTime& a, const SMILTime& b) { return !operator=
=(a, b); } | 88 inline bool operator!=(const SMILTime& a, const SMILTime& b) { return !operator=
=(a, b); } |
94 inline bool operator>(const SMILTime& a, const SMILTime& b) { return a.value() >
b.value(); } | 89 inline bool operator>(const SMILTime& a, const SMILTime& b) { return a.isUnresol
ved() || (a.value() > b.value()); } |
95 inline bool operator<(const SMILTime& a, const SMILTime& b) { return a.value() <
b.value(); } | 90 inline bool operator<(const SMILTime& a, const SMILTime& b) { return operator>(b
, a); } |
96 inline bool operator>=(const SMILTime& a, const SMILTime& b) { return a.value()
> b.value() || operator==(a, b); } | 91 inline bool operator>=(const SMILTime& a, const SMILTime& b) { return operator>(
a, b) || operator==(a, b); } |
97 inline bool operator<=(const SMILTime& a, const SMILTime& b) { return a.value()
< b.value() || operator==(a, b); } | 92 inline bool operator<=(const SMILTime& a, const SMILTime& b) { return operator<(
a, b) || operator==(a, b); } |
98 inline bool operator<(const SMILTimeWithOrigin& a, const SMILTimeWithOrigin& b)
{ return a.time() < b.time(); } | 93 inline bool operator<(const SMILTimeWithOrigin& a, const SMILTimeWithOrigin& b)
{ return a.time() < b.time(); } |
99 | 94 |
100 SMILTime operator+(const SMILTime&, const SMILTime&); | 95 SMILTime operator+(const SMILTime&, const SMILTime&); |
101 SMILTime operator-(const SMILTime&, const SMILTime&); | 96 SMILTime operator-(const SMILTime&, const SMILTime&); |
102 // So multiplying times does not make too much sense but SMIL defines it for dur
ation * repeatCount | 97 // So multiplying times does not make too much sense but SMIL defines it for dur
ation * repeatCount |
103 SMILTime operator*(const SMILTime&, const SMILTime&); | 98 SMILTime operator*(const SMILTime&, const SMILTime&); |
104 | 99 |
105 inline bool operator!=(const SMILInterval& a, const SMILInterval& b) | 100 inline bool operator!=(const SMILInterval& a, const SMILInterval& b) |
106 { | 101 { |
107 // Compare the "raw" values since the operator!= for SMILTime always return | 102 // Compare the "raw" values since the operator!= for SMILTime always return |
108 // true for non-finite times. | 103 // true for non-finite times. |
109 return a.begin.value() != b.begin.value() || a.end.value() != b.end.value(); | 104 return a.begin.value() != b.begin.value() || a.end.value() != b.end.value(); |
110 } | 105 } |
111 | 106 |
112 } | 107 } |
113 | 108 |
114 #endif // SMILTime_h | 109 #endif // SMILTime_h |
OLD | NEW |