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

Side by Side Diff: sky/engine/core/css/StylePropertySet.cpp

Issue 760183003: Enable/Unprefix Animations & Transitions, add basic tests (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: patch for landing Created 6 years 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
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return nullptr; 140 return nullptr;
141 return propertyAt(foundPropertyIndex).value(); 141 return propertyAt(foundPropertyIndex).value();
142 } 142 }
143 143
144 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID) 144 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
145 { 145 {
146 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 146 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
147 if (!shorthand.length()) 147 if (!shorthand.length())
148 return false; 148 return false;
149 149
150 bool ret = removePropertiesInSet(shorthand.properties(), shorthand.length()) ; 150 return removePropertiesInSet(shorthand.properties(), shorthand.length());
151
152 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propertyID);
153 if (prefixingVariant == propertyID)
154 return ret;
155
156 StylePropertyShorthand shorthandPrefixingVariant = shorthandForProperty(pref ixingVariant);
157 return removePropertiesInSet(shorthandPrefixingVariant.properties(), shortha ndPrefixingVariant.length());
158 } 151 }
159 152
160 bool MutableStylePropertySet::removeProperty(CSSPropertyID propertyID, String* r eturnText) 153 bool MutableStylePropertySet::removeProperty(CSSPropertyID propertyID, String* r eturnText)
161 { 154 {
162 if (removeShorthandProperty(propertyID)) { 155 if (removeShorthandProperty(propertyID)) {
163 // FIXME: Return an equivalent shorthand when possible. 156 // FIXME: Return an equivalent shorthand when possible.
164 if (returnText) 157 if (returnText)
165 *returnText = ""; 158 *returnText = "";
166 return true; 159 return true;
167 } 160 }
168 161
169 int foundPropertyIndex = findPropertyIndex(propertyID); 162 int foundPropertyIndex = findPropertyIndex(propertyID);
170 if (foundPropertyIndex == -1) { 163 if (foundPropertyIndex == -1) {
171 if (returnText) 164 if (returnText)
172 *returnText = ""; 165 *returnText = "";
173 return false; 166 return false;
174 } 167 }
175 168
176 if (returnText) 169 if (returnText)
177 *returnText = propertyAt(foundPropertyIndex).value()->cssText(); 170 *returnText = propertyAt(foundPropertyIndex).value()->cssText();
178 171
179 // A more efficient removal strategy would involve marking entries as empty 172 // A more efficient removal strategy would involve marking entries as empty
180 // and sweeping them when the vector grows too big. 173 // and sweeping them when the vector grows too big.
181 m_propertyVector.remove(foundPropertyIndex); 174 m_propertyVector.remove(foundPropertyIndex);
182 175
183 removePrefixedOrUnprefixedProperty(propertyID);
184
185 return true; 176 return true;
186 } 177 }
187 178
188 void MutableStylePropertySet::removePrefixedOrUnprefixedProperty(CSSPropertyID p ropertyID)
189 {
190 int foundPropertyIndex = findPropertyIndex(prefixingVariantForPropertyId(pro pertyID));
191 if (foundPropertyIndex == -1)
192 return;
193 m_propertyVector.remove(foundPropertyIndex);
194 }
195
196 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const 179 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const
197 { 180 {
198 int foundPropertyIndex = findPropertyIndex(propertyID); 181 int foundPropertyIndex = findPropertyIndex(propertyID);
199 if (foundPropertyIndex != -1) 182 if (foundPropertyIndex != -1)
200 return propertyAt(foundPropertyIndex).isImportant(); 183 return propertyAt(foundPropertyIndex).isImportant();
201 184
202 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 185 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
203 if (!shorthand.length()) 186 if (!shorthand.length())
204 return false; 187 return false;
205 188
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 for (unsigned i = 0; i < shorthand.length(); ++i) 235 for (unsigned i = 0; i < shorthand.length(); ++i)
253 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im portant)); 236 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im portant));
254 } 237 }
255 238
256 void MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot) 239 void MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot)
257 { 240 {
258 if (!removeShorthandProperty(property.id())) { 241 if (!removeShorthandProperty(property.id())) {
259 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ()); 242 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ());
260 if (toReplace) { 243 if (toReplace) {
261 *toReplace = property; 244 *toReplace = property;
262 setPrefixingVariantProperty(property);
263 return; 245 return;
264 } 246 }
265 } 247 }
266 appendPrefixingVariantProperty(property); 248 appendProperty(property);
267 } 249 }
268 250
269 unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert y, CSSPropertyID prefixingVariant) 251 void MutableStylePropertySet::appendProperty(const CSSProperty& property)
270 {
271 if (!property.isSetFromShorthand())
272 return 0;
273
274 CSSPropertyID prefixedShorthand = prefixingVariantForPropertyId(property.sho rthandID());
275 Vector<StylePropertyShorthand, 4> shorthands;
276 getMatchingShorthandsForLonghand(prefixingVariant, &shorthands);
277 return indexOfShorthandForLonghand(prefixedShorthand, shorthands);
278 }
279
280 void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
281 { 252 {
282 m_propertyVector.append(property); 253 m_propertyVector.append(property);
283 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id() );
284 if (prefixingVariant == property.id())
285 return;
286
287 m_propertyVector.append(CSSProperty(prefixingVariant, property.value(), prop erty.isImportant(), property.isSetFromShorthand(), getIndexInShorthandVectorForP refixingVariant(property, prefixingVariant), property.metadata().m_implicit));
288 }
289
290 void MutableStylePropertySet::setPrefixingVariantProperty(const CSSProperty& pro perty)
291 {
292 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id() );
293 CSSProperty* toReplace = findCSSPropertyWithID(prefixingVariant);
294 if (toReplace && prefixingVariant != property.id())
295 *toReplace = CSSProperty(prefixingVariant, property.value(), property.is Important(), property.isSetFromShorthand(), getIndexInShorthandVectorForPrefixin gVariant(property, prefixingVariant), property.metadata().m_implicit);
296 } 254 }
297 255
298 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSValueID i dentifier, bool important) 256 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSValueID i dentifier, bool important)
299 { 257 {
300 setProperty(CSSProperty(propertyID, cssValuePool().createIdentifierValue(ide ntifier), important)); 258 setProperty(CSSProperty(propertyID, cssValuePool().createIdentifierValue(ide ntifier), important));
301 return true; 259 return true;
302 } 260 }
303 261
304 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSPropertyI D identifier, bool important) 262 bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSPropertyI D identifier, bool important)
305 { 263 {
(...skipping 26 matching lines...) Expand all
332 // Only add properties that have no !important counterpart present 290 // Only add properties that have no !important counterpart present
333 if (!propertyIsImportant(property.id()) || property.isImportant()) 291 if (!propertyIsImportant(property.id()) || property.isImportant())
334 setProperty(property); 292 setProperty(property);
335 } 293 }
336 294
337 String StylePropertySet::asText() const 295 String StylePropertySet::asText() const
338 { 296 {
339 return StylePropertySerializer(*this).asText(); 297 return StylePropertySerializer(*this).asText();
340 } 298 }
341 299
342 void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet* other)
343 {
344 unsigned size = other->propertyCount();
345 for (unsigned n = 0; n < size; ++n) {
346 PropertyReference toMerge = other->propertyAt(n);
347 CSSProperty* old = findCSSPropertyWithID(toMerge.id());
348 if (old)
349 setProperty(toMerge.toCSSProperty(), old);
350 else
351 appendPrefixingVariantProperty(toMerge.toCSSProperty());
352 }
353 }
354
355 bool StylePropertySet::hasFailedOrCanceledSubresources() const 300 bool StylePropertySet::hasFailedOrCanceledSubresources() const
356 { 301 {
357 unsigned size = propertyCount(); 302 unsigned size = propertyCount();
358 for (unsigned i = 0; i < size; ++i) { 303 for (unsigned i = 0; i < size; ++i) {
359 if (propertyAt(i).value()->hasFailedOrCanceledSubresources()) 304 if (propertyAt(i).value()->hasFailedOrCanceledSubresources())
360 return true; 305 return true;
361 } 306 }
362 return false; 307 return false;
363 } 308 }
364 309
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 result.appendLiteral(": "); 508 result.appendLiteral(": ");
564 result.append(propertyValue()->cssText()); 509 result.append(propertyValue()->cssText());
565 if (isImportant()) 510 if (isImportant())
566 result.appendLiteral(" !important"); 511 result.appendLiteral(" !important");
567 result.append(';'); 512 result.append(';');
568 return result.toString(); 513 return result.toString();
569 } 514 }
570 515
571 516
572 } // namespace blink 517 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/StylePropertySet.h ('k') | sky/engine/core/css/StylePropertyShorthandCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698