OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2012 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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
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 #include "config.h" | 26 #include "config.h" |
27 #include "core/css/CSSKeyframeRule.h" | 27 #include "core/css/CSSKeyframeRule.h" |
28 | 28 |
29 #include "core/css/CSSKeyframesRule.h" | 29 #include "core/css/CSSKeyframesRule.h" |
30 #include "core/css/CSSParser.h" | |
30 #include "core/css/PropertySetCSSStyleDeclaration.h" | 31 #include "core/css/PropertySetCSSStyleDeclaration.h" |
31 #include "core/css/StylePropertySet.h" | 32 #include "core/css/StylePropertySet.h" |
33 #include "wtf/MemoryInstrumentationVector.h" | |
32 #include "wtf/text/StringBuilder.h" | 34 #include "wtf/text/StringBuilder.h" |
33 | 35 |
34 namespace WebCore { | 36 namespace WebCore { |
35 | 37 |
36 StyleKeyframe::StyleKeyframe() | 38 StyleKeyframe::StyleKeyframe() |
37 { | 39 { |
38 } | 40 } |
39 | 41 |
40 StyleKeyframe::~StyleKeyframe() | 42 StyleKeyframe::~StyleKeyframe() |
41 { | 43 { |
42 } | 44 } |
43 | 45 |
46 String StyleKeyframe::keyText() const | |
47 { | |
48 if (m_keyText.isNull()) { | |
49 StringBuilder keyText; | |
50 for (unsigned i = 0; i < m_keys->size(); ++i) { | |
51 if (i) | |
52 keyText.append(','); | |
53 keyText.append(String::number(m_keys->at(i))); | |
54 keyText.append('%'); | |
55 } | |
56 m_keyText = keyText.toString(); | |
57 } | |
58 return m_keyText; | |
59 } | |
60 | |
61 void StyleKeyframe::setKeyText(const String& keyText) | |
62 { | |
63 // FIXME: Should we trim whitespace? | |
64 // FIXME: Should we leave keyText unchanged when attempting to set to an | |
65 // invalid string? | |
66 m_keyText = keyText; | |
67 m_keys.clear(); | |
68 } | |
69 | |
70 const Vector<float>& StyleKeyframe::keys() const | |
71 { | |
72 if (!m_keys) { | |
apavlov
2013/07/15 11:54:37
The braces are optional here
Steve Block
2013/08/14 00:44:05
No longer relevant
| |
73 m_keys = CSSParser(CSSStrictMode).parseKeyframeKeyList(m_keyText); | |
74 } | |
75 // If an invalid key string was set, m_keys may be empty. | |
76 ASSERT(m_keys); | |
77 return *m_keys; | |
78 } | |
79 | |
80 void StyleKeyframe::setKeys(PassOwnPtr<Vector<float> > keys) | |
81 { | |
82 ASSERT(keys && !keys->isEmpty()); | |
83 m_keys = keys; | |
84 m_keyText = String(); | |
85 ASSERT(m_keyText.isNull()); | |
86 } | |
87 | |
44 MutableStylePropertySet* StyleKeyframe::mutableProperties() | 88 MutableStylePropertySet* StyleKeyframe::mutableProperties() |
45 { | 89 { |
46 if (!m_properties->isMutable()) | 90 if (!m_properties->isMutable()) |
47 m_properties = m_properties->mutableCopy(); | 91 m_properties = m_properties->mutableCopy(); |
48 return static_cast<MutableStylePropertySet*>(m_properties.get()); | 92 return static_cast<MutableStylePropertySet*>(m_properties.get()); |
49 } | 93 } |
50 | 94 |
51 void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties) | 95 void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties) |
52 { | 96 { |
53 m_properties = properties; | 97 m_properties = properties; |
54 } | 98 } |
55 | 99 |
56 /* static */ | |
57 void StyleKeyframe::parseKeyString(const String& s, Vector<float>& keys) | |
58 { | |
59 keys.clear(); | |
60 Vector<String> strings; | |
61 s.split(',', strings); | |
62 | |
63 for (size_t i = 0; i < strings.size(); ++i) { | |
64 float key = -1; | |
65 String cur = strings[i].stripWhiteSpace(); | |
66 | |
67 // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a l egal floating point number | |
68 if (cur == "from") | |
69 key = 0; | |
70 else if (cur == "to") | |
71 key = 1; | |
72 else if (cur.endsWith('%')) { | |
73 float k = cur.substring(0, cur.length() - 1).toFloat(); | |
74 if (k >= 0 && k <= 100) | |
75 key = k / 100; | |
76 } | |
77 if (key < 0) { | |
78 keys.clear(); | |
79 return; | |
80 } | |
81 keys.append(key); | |
82 } | |
83 } | |
84 | |
85 String StyleKeyframe::cssText() const | 100 String StyleKeyframe::cssText() const |
86 { | 101 { |
87 StringBuilder result; | 102 StringBuilder result; |
88 result.append(keyText()); | 103 result.append(keyText()); |
89 result.appendLiteral(" { "); | 104 result.appendLiteral(" { "); |
90 String decls = m_properties->asText(); | 105 String decls = m_properties->asText(); |
91 result.append(decls); | 106 result.append(decls); |
92 if (!decls.isEmpty()) | 107 if (!decls.isEmpty()) |
93 result.append(' '); | 108 result.append(' '); |
94 result.append('}'); | 109 result.append('}'); |
95 return result.toString(); | 110 return result.toString(); |
96 } | 111 } |
97 | 112 |
98 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 113 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
99 { | 114 { |
100 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); | 115 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
101 info.addMember(m_properties, "properties"); | 116 info.addMember(m_properties, "properties"); |
102 info.addMember(m_key, "key"); | 117 info.addMember(m_keyText, "keyText"); |
118 info.addMember(m_keys, "keys"); | |
103 } | 119 } |
104 | 120 |
105 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt) | 121 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt) |
106 : CSSRule(0) | 122 : CSSRule(0) |
107 , m_keyframe(keyframe) | 123 , m_keyframe(keyframe) |
108 { | 124 { |
109 setParentRule(parent); | 125 setParentRule(parent); |
110 } | 126 } |
111 | 127 |
112 CSSKeyframeRule::~CSSKeyframeRule() | 128 CSSKeyframeRule::~CSSKeyframeRule() |
(...skipping 17 matching lines...) Expand all Loading... | |
130 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); | 146 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); |
131 } | 147 } |
132 | 148 |
133 void CSSKeyframeRule::reattach(StyleRuleBase*) | 149 void CSSKeyframeRule::reattach(StyleRuleBase*) |
134 { | 150 { |
135 // No need to reattach, the underlying data is shareable on mutation. | 151 // No need to reattach, the underlying data is shareable on mutation. |
136 ASSERT_NOT_REACHED(); | 152 ASSERT_NOT_REACHED(); |
137 } | 153 } |
138 | 154 |
139 } // namespace WebCore | 155 } // namespace WebCore |
OLD | NEW |