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

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

Issue 13943004: Avoid reparsing keyframe selectors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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/WebKitCSSKeyframeRule.h ('k') | no next file » | 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->copy(); 47 m_properties = m_properties->copy();
48 return m_properties.get(); 48 return 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/04/22 13:30:23 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)
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(); 114 keys.append(key);
79 return;
80 }
81 else
82 keys.append(key);
83 } 115 }
116
117 return keys;
84 } 118 }
85 119
86 String StyleKeyframe::cssText() const 120 String StyleKeyframe::cssText() const
87 { 121 {
88 StringBuilder result; 122 StringBuilder result;
89 result.append(keyText()); 123 result.append(keyText());
90 result.appendLiteral(" { "); 124 result.appendLiteral(" { ");
91 String decls = m_properties->asText(); 125 String decls = m_properties->asText();
92 result.append(decls); 126 result.append(decls);
93 if (!decls.isEmpty()) 127 if (!decls.isEmpty())
94 result.append(' '); 128 result.append(' ');
95 result.append('}'); 129 result.append('}');
96 return result.toString(); 130 return result.toString();
97 } 131 }
98 132
99 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 133 void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
100 { 134 {
101 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); 135 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
102 info.addMember(m_properties, "properties"); 136 info.addMember(m_properties, "properties");
103 info.addMember(m_key, "key"); 137 info.addMember(m_keyText, "keyText");
104 } 138 }
105 139
106 WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(StyleKeyframe* keyframe, WebKitCSSK eyframesRule* parent) 140 WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(StyleKeyframe* keyframe, WebKitCSSK eyframesRule* parent)
107 : CSSRule(0) 141 : CSSRule(0)
108 , m_keyframe(keyframe) 142 , m_keyframe(keyframe)
109 { 143 {
110 setParentRule(parent); 144 setParentRule(parent);
111 } 145 }
112 146
113 WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule() 147 WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule()
(...skipping 17 matching lines...) Expand all
131 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper"); 165 info.addMember(m_propertiesCSSOMWrapper, "propertiesCSSOMWrapper");
132 } 166 }
133 167
134 void WebKitCSSKeyframeRule::reattach(StyleRuleBase*) 168 void WebKitCSSKeyframeRule::reattach(StyleRuleBase*)
135 { 169 {
136 // No need to reattach, the underlying data is shareable on mutation. 170 // No need to reattach, the underlying data is shareable on mutation.
137 ASSERT_NOT_REACHED(); 171 ASSERT_NOT_REACHED();
138 } 172 }
139 173
140 } // namespace WebCore 174 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/WebKitCSSKeyframeRule.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698