Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: Source/core/css/CSSKeyframeRule.cpp

Issue 13943004: Avoid reparsing keyframe selectors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/CSSKeyframeRule.h ('k') | Source/core/css/CSSParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(); 92 keys.clear();
60 Vector<String> strings; 93 Vector<String> strings;
61 s.split(',', strings); 94 s.split(',', strings);
62 95
63 for (size_t i = 0; i < strings.size(); ++i) { 96 for (size_t i = 0; i < strings.size(); ++i) {
64 float key = -1; 97 float key = -1;
65 String cur = strings[i].stripWhiteSpace(); 98 String cur = strings[i].stripWhiteSpace();
66 99
67 // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a l egal floating point number 100 // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a l egal floating point number
68 if (cur == "from") 101 if (cur == "from")
69 key = 0; 102 key = 0;
70 else if (cur == "to") 103 else if (cur == "to")
71 key = 1; 104 key = 1;
72 else if (cur.endsWith('%')) { 105 else if (cur.endsWith('%')) {
73 float k = cur.substring(0, cur.length() - 1).toFloat(); 106 float k = cur.substring(0, cur.length() - 1).toFloat();
74 if (k >= 0 && k <= 100) 107 if (k >= 0 && k <= 100) {
75 key = k / 100; 108 key = k / 100;
109 } else {
110 keys.clear();
111 return;
112 }
76 } 113 }
77 if (key < 0) { 114
78 keys.clear();
79 return;
80 }
81 keys.append(key); 115 keys.append(key);
82 } 116 }
83 } 117 }
84 118
85 String StyleKeyframe::cssText() const 119 String StyleKeyframe::cssText() const
86 { 120 {
87 StringBuilder result; 121 StringBuilder result;
88 result.append(keyText()); 122 result.append(keyText());
89 result.appendLiteral(" { "); 123 result.appendLiteral(" { ");
90 String decls = m_properties->asText(); 124 String decls = m_properties->asText();
91 result.append(decls); 125 result.append(decls);
92 if (!decls.isEmpty()) 126 if (!decls.isEmpty())
93 result.append(' '); 127 result.append(' ');
94 result.append('}'); 128 result.append('}');
95 return result.toString(); 129 return result.toString();
96 } 130 }
97 131
98 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 132 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
99 { 133 {
100 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); 134 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
101 info.addMember(m_properties, "properties"); 135 info.addMember(m_properties, "properties");
102 info.addMember(m_key, "key"); 136 info.addMember(m_keyText, "keyText");
103 } 137 }
104 138
105 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt) 139 CSSKeyframeRule::CSSKeyframeRule(StyleKeyframe* keyframe, CSSKeyframesRule* pare nt)
106 : CSSRule(0) 140 : CSSRule(0)
107 , m_keyframe(keyframe) 141 , m_keyframe(keyframe)
108 { 142 {
109 setParentRule(parent); 143 setParentRule(parent);
110 } 144 }
111 145
112 CSSKeyframeRule::~CSSKeyframeRule() 146 CSSKeyframeRule::~CSSKeyframeRule()
(...skipping 17 matching lines...) Expand all
130 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); 164 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper");
131 } 165 }
132 166
133 void CSSKeyframeRule::reattach(StyleRuleBase*) 167 void CSSKeyframeRule::reattach(StyleRuleBase*)
134 { 168 {
135 // No need to reattach, the underlying data is shareable on mutation. 169 // No need to reattach, the underlying data is shareable on mutation.
136 ASSERT_NOT_REACHED(); 170 ASSERT_NOT_REACHED();
137 } 171 }
138 172
139 } // namespace WebCore 173 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSKeyframeRule.h ('k') | Source/core/css/CSSParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698