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)); | |
|
apavlov
2013/06/18 09:59:50
whitespace around '*'
| |
| 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 m_keys = parseKeyString(m_keyText); | |
| 76 if (m_keys.size()) | |
| 77 m_keyText = s; | |
| 78 else | |
| 79 m_keyText = String(); | |
| 80 } | |
| 81 | |
| 82 void StyleKeyframe::setKeys(const Vector<float>& keys) | |
| 83 { | |
| 84 m_keyText = String(); | |
| 85 m_keys = keys; | |
| 86 } | |
| 87 | |
| 56 /* static */ | 88 /* static */ |
| 57 void StyleKeyframe::parseKeyString(const String& s, Vector<float>& keys) | 89 Vector<float> StyleKeyframe::parseKeyString(const String& s) |
|
apavlov
2013/06/18 09:59:50
Vector's copy ctor performs TypeOperations::uninit
| |
| 58 { | 90 { |
| 59 keys.clear(); | 91 Vector<float> keys; |
| 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 keys; | |
| 111 } | |
| 76 } | 112 } |
| 77 if (key < 0) { | 113 |
| 78 keys.clear(); | |
| 79 return; | |
| 80 } | |
| 81 keys.append(key); | 114 keys.append(key); |
| 82 } | 115 } |
| 116 | |
| 117 return keys; | |
| 83 } | 118 } |
| 84 | 119 |
| 85 String StyleKeyframe::cssText() const | 120 String StyleKeyframe::cssText() const |
| 86 { | 121 { |
| 87 StringBuilder result; | 122 StringBuilder result; |
| 88 result.append(keyText()); | 123 result.append(keyText()); |
| 89 result.appendLiteral(" { "); | 124 result.appendLiteral(" { "); |
| 90 String decls = m_properties->asText(); | 125 String decls = m_properties->asText(); |
| 91 result.append(decls); | 126 result.append(decls); |
| 92 if (!decls.isEmpty()) | 127 if (!decls.isEmpty()) |
| 93 result.append(' '); | 128 result.append(' '); |
| 94 result.append('}'); | 129 result.append('}'); |
| 95 return result.toString(); | 130 return result.toString(); |
| 96 } | 131 } |
| 97 | 132 |
| 98 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 133 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 99 { | 134 { |
| 100 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); | 135 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
| 101 info.addMember(m_properties, "properties"); | 136 info.addMember(m_properties, "properties"); |
| 102 info.addMember(m_key, "key"); | 137 info.addMember(m_keyText, "keyText"); |
| 103 } | 138 } |
| 104 | 139 |
| 105 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt) | 140 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt) |
| 106 : CSSRule(0) | 141 : CSSRule(0) |
| 107 , m_keyframe(keyframe) | 142 , m_keyframe(keyframe) |
| 108 { | 143 { |
| 109 setParentRule(parent); | 144 setParentRule(parent); |
| 110 } | 145 } |
| 111 | 146 |
| 112 CSSKeyframeRule::~CSSKeyframeRule() | 147 CSSKeyframeRule::~CSSKeyframeRule() |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 130 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); | 165 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); |
| 131 } | 166 } |
| 132 | 167 |
| 133 void CSSKeyframeRule::reattach(StyleRuleBase*) | 168 void CSSKeyframeRule::reattach(StyleRuleBase*) |
| 134 { | 169 { |
| 135 // No need to reattach, the underlying data is shareable on mutation. | 170 // No need to reattach, the underlying data is shareable on mutation. |
| 136 ASSERT_NOT_REACHED(); | 171 ASSERT_NOT_REACHED(); |
| 137 } | 172 } |
| 138 | 173 |
| 139 } // namespace WebCore | 174 } // namespace WebCore |
| OLD | NEW |