Chromium Code Reviews| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 if (!m_properties->isMutable()) | 46 if (!m_properties->isMutable()) |
| 47 m_properties = m_properties->mutableCopy(); | 47 m_properties = m_properties->mutableCopy(); |
| 48 return static_cast<MutableStylePropertySet*>(m_properties.get()); | 48 return static_cast<MutableStylePropertySet*>(m_properties.get()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties) | 51 void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties) |
| 52 { | 52 { |
| 53 m_properties = properties; | 53 m_properties = properties; |
| 54 } | 54 } |
| 55 | 55 |
| 56 String StyleKeyframe::keyText() const | |
| 57 { | |
| 58 size_t keyCount = m_keys.size(); | |
| 59 if (m_keyText.isEmpty() && keyCount > 0) { | |
| 60 StringBuilder keyString; | |
| 61 for (size_t i = 0; i < keyCount; ++i) { | |
| 62 float key = m_keys[i]; | |
| 63 if (i) | |
| 64 keyString.append(','); | |
| 65 keyString.append(String::number(key * 100)); | |
| 66 keyString.append('%'); | |
| 67 } | |
| 68 m_keyText = keyString.toString(); | |
| 69 } | |
| 70 return m_keyText; | |
| 71 } | |
| 72 | |
| 73 void StyleKeyframe::setKeyText(const String& s) | |
| 74 { | |
| 75 parseKeyString(s, m_keys); | |
| 76 | |
| 77 if (m_keys.size()) | |
| 78 m_keyText = s; | |
| 79 else | |
| 80 m_keyText = String(); | |
| 81 } | |
| 82 | |
| 83 void StyleKeyframe::setKeys(const Vector<float>& keys) | |
| 84 { | |
| 85 m_keyText = String(); | |
| 86 m_keys = keys; | |
| 87 } | |
| 88 | |
| 56 /* static */ | 89 /* static */ |
| 57 void StyleKeyframe::parseKeyString(const String& s, Vector<float>& keys) | 90 void StyleKeyframe::parseKeyString(const String& s, Vector<float>& keys) |
| 58 { | 91 { |
| 59 keys.clear(); | |
|
apavlov
2013/07/04 22:02:52
Hmm, just noticed. Why did this get removed? When
| |
| 60 Vector<String> strings; | 92 Vector<String> strings; |
| 61 s.split(',', strings); | 93 s.split(',', strings); |
| 62 | 94 |
| 63 for (size_t i = 0; i < strings.size(); ++i) { | 95 for (size_t i = 0; i < strings.size(); ++i) { |
| 64 float key = -1; | 96 float key = -1; |
| 65 String cur = strings[i].stripWhiteSpace(); | 97 String cur = strings[i].stripWhiteSpace(); |
| 66 | 98 |
| 67 // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a l egal floating point number | 99 // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a l egal floating point number |
| 68 if (cur == "from") | 100 if (cur == "from") |
| 69 key = 0; | 101 key = 0; |
| 70 else if (cur == "to") | 102 else if (cur == "to") |
| 71 key = 1; | 103 key = 1; |
| 72 else if (cur.endsWith('%')) { | 104 else if (cur.endsWith('%')) { |
| 73 float k = cur.substring(0, cur.length() - 1).toFloat(); | 105 float k = cur.substring(0, cur.length() - 1).toFloat(); |
| 74 if (k >= 0 && k <= 100) | 106 if (k >= 0 && k <= 100) { |
| 75 key = k / 100; | 107 key = k / 100; |
| 108 } else { | |
| 109 keys.clear(); | |
| 110 return; | |
| 111 } | |
| 76 } | 112 } |
| 77 if (key < 0) { | 113 |
| 78 keys.clear(); | |
| 79 return; | |
| 80 } | |
| 81 keys.append(key); | 114 keys.append(key); |
| 82 } | 115 } |
| 83 } | 116 } |
| 84 | 117 |
| 85 String StyleKeyframe::cssText() const | 118 String StyleKeyframe::cssText() const |
| 86 { | 119 { |
| 87 StringBuilder result; | 120 StringBuilder result; |
| 88 result.append(keyText()); | 121 result.append(keyText()); |
| 89 result.appendLiteral(" { "); | 122 result.appendLiteral(" { "); |
| 90 String decls = m_properties->asText(); | 123 String decls = m_properties->asText(); |
| 91 result.append(decls); | 124 result.append(decls); |
| 92 if (!decls.isEmpty()) | 125 if (!decls.isEmpty()) |
| 93 result.append(' '); | 126 result.append(' '); |
| 94 result.append('}'); | 127 result.append('}'); |
| 95 return result.toString(); | 128 return result.toString(); |
| 96 } | 129 } |
| 97 | 130 |
| 98 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 131 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 99 { | 132 { |
| 100 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); | 133 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
| 101 info.addMember(m_properties, "properties"); | 134 info.addMember(m_properties, "properties"); |
| 102 info.addMember(m_key, "key"); | 135 info.addMember(m_keyText, "keyText"); |
| 103 } | 136 } |
| 104 | 137 |
| 105 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt) | 138 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt) |
| 106 : CSSRule(0) | 139 : CSSRule(0) |
| 107 , m_keyframe(keyframe) | 140 , m_keyframe(keyframe) |
| 108 { | 141 { |
| 109 setParentRule(parent); | 142 setParentRule(parent); |
| 110 } | 143 } |
| 111 | 144 |
| 112 CSSKeyframeRule::~CSSKeyframeRule() | 145 CSSKeyframeRule::~CSSKeyframeRule() |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 130 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); | 163 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); |
| 131 } | 164 } |
| 132 | 165 |
| 133 void CSSKeyframeRule::reattach(StyleRuleBase*) | 166 void CSSKeyframeRule::reattach(StyleRuleBase*) |
| 134 { | 167 { |
| 135 // No need to reattach, the underlying data is shareable on mutation. | 168 // No need to reattach, the underlying data is shareable on mutation. |
| 136 ASSERT_NOT_REACHED(); | 169 ASSERT_NOT_REACHED(); |
| 137 } | 170 } |
| 138 | 171 |
| 139 } // namespace WebCore | 172 } // namespace WebCore |
| OLD | NEW |