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

Side by Side Diff: sky/engine/core/css/resolver/StyleResolver.cpp

Issue 860423004: Remove css !important (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 | « sky/engine/core/css/resolver/StyleResolver.h ('k') | sky/engine/core/dom/Element.h » ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 229
230 applyMatchedProperties(state, collector.matchedResult()); 230 applyMatchedProperties(state, collector.matchedResult());
231 } 231 }
232 232
233 // Cache our original display. 233 // Cache our original display.
234 state.style()->setOriginalDisplay(state.style()->display()); 234 state.style()->setOriginalDisplay(state.style()->display());
235 235
236 StyleAdjuster adjuster; 236 StyleAdjuster adjuster;
237 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element); 237 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element);
238 238
239 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before
240 // important rules, but this currently happens here as we require adjustment to have happened
241 // before deciding which properties to transition.
242 if (applyAnimatedProperties(state, element)) 239 if (applyAnimatedProperties(state, element))
243 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element) ; 240 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element) ;
244 241
245 setAnimationUpdateIfNeeded(state, *element); 242 setAnimationUpdateIfNeeded(state, *element);
246 243
247 if (state.style()->hasViewportUnits()) 244 if (state.style()->hasViewportUnits())
248 m_document.setHasViewportUnits(); 245 m_document.setHasViewportUnits();
249 246
250 // Now return the style. 247 // Now return the style.
251 return state.takeStyle(); 248 return state.takeStyle();
(...skipping 12 matching lines...) Expand all
264 result.addMatchedProperties(&keyframe->properties()); 261 result.addMatchedProperties(&keyframe->properties());
265 262
266 ASSERT(!state.style()); 263 ASSERT(!state.style());
267 264
268 // Create the style 265 // Create the style
269 state.setStyle(RenderStyle::clone(&elementStyle)); 266 state.setStyle(RenderStyle::clone(&elementStyle));
270 state.setLineHeightValue(0); 267 state.setLineHeightValue(0);
271 268
272 state.fontBuilder().initForStyleResolve(state.document(), state.style()); 269 state.fontBuilder().initForStyleResolve(state.document(), state.style());
273 270
274 // We don't need to bother with !important. Since there is only ever one
275 // decl, there's nothing to override. So just add the first properties.
276 // We also don't need to bother with animation properties since the only 271 // We also don't need to bother with animation properties since the only
277 // relevant one is animation-timing-function and we special-case that in 272 // relevant one is animation-timing-function and we special-case that in
278 // CSSAnimations.cpp 273 // CSSAnimations.cpp
279 bool inheritedOnly = false; 274 bool inheritedOnly = false;
280 applyMatchedProperties<HighPriorityProperties>(state, result, false, inherit edOnly); 275 applyMatchedProperties<HighPriorityProperties>(state, result, inheritedOnly) ;
281 276
282 // If our font got dirtied, go ahead and update it now. 277 // If our font got dirtied, go ahead and update it now.
283 updateFont(state); 278 updateFont(state);
284 279
285 // Line-height is set when we are sure we decided on the font-size 280 // Line-height is set when we are sure we decided on the font-size
286 if (state.lineHeightValue()) 281 if (state.lineHeightValue())
287 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue()); 282 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
288 283
289 // Now do rest of the properties. 284 // Now do rest of the properties.
290 applyMatchedProperties<LowPriorityProperties>(state, result, false, inherite dOnly); 285 applyMatchedProperties<LowPriorityProperties>(state, result, inheritedOnly);
291 286
292 loadPendingResources(state); 287 loadPendingResources(state);
293 288
294 return state.takeStyle(); 289 return state.takeStyle();
295 } 290 }
296 291
297 // This function is used by the WebAnimations JavaScript API method animate(). 292 // This function is used by the WebAnimations JavaScript API method animate().
298 // FIXME: Remove this when animate() switches away from resolution-dependent par sing. 293 // FIXME: Remove this when animate() switches away from resolution-dependent par sing.
299 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(Element & element, CSSPropertyID property, CSSValue& value) 294 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(Element & element, CSSPropertyID property, CSSValue& value)
300 { 295 {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 if (CSSPropertyMetadata::isInheritedProperty(propertyId)) 476 if (CSSPropertyMetadata::isInheritedProperty(propertyId))
482 value = cssValuePool().createInheritedValue().get(); 477 value = cssValuePool().createInheritedValue().get();
483 else 478 else
484 value = cssValuePool().createExplicitInitialValue().get(); 479 value = cssValuePool().createExplicitInitialValue().get();
485 } 480 }
486 StyleBuilder::applyProperty(propertyId, state, value); 481 StyleBuilder::applyProperty(propertyId, state, value);
487 } 482 }
488 } 483 }
489 484
490 template <StyleResolver::StyleApplicationPass pass> 485 template <StyleResolver::StyleApplicationPass pass>
491 void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper tySet* properties, bool isImportant, bool inheritedOnly) 486 void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper tySet* properties, bool inheritedOnly)
492 { 487 {
493 unsigned propertyCount = properties->propertyCount(); 488 unsigned propertyCount = properties->propertyCount();
494 for (unsigned i = 0; i < propertyCount; ++i) { 489 for (unsigned i = 0; i < propertyCount; ++i) {
495 StylePropertySet::PropertyReference current = properties->propertyAt(i); 490 StylePropertySet::PropertyReference current = properties->propertyAt(i);
496 if (isImportant != current.isImportant())
497 continue;
498 491
499 CSSPropertyID property = current.id(); 492 CSSPropertyID property = current.id();
500 if (property == CSSPropertyAll) { 493 if (property == CSSPropertyAll) {
501 applyAllProperty<pass>(state, current.value()); 494 applyAllProperty<pass>(state, current.value());
502 continue; 495 continue;
503 } 496 }
504 497
505 if (inheritedOnly && !current.isInherited()) { 498 if (inheritedOnly && !current.isInherited()) {
506 // If the property value is explicitly inherited, we need to apply f urther non-inherited properties 499 // If the property value is explicitly inherited, we need to apply f urther non-inherited properties
507 // as they might override the value inherited here. For this reason we don't allow declarations with 500 // as they might override the value inherited here. For this reason we don't allow declarations with
508 // explicitly inherited properties to be cached. 501 // explicitly inherited properties to be cached.
509 ASSERT(!current.value()->isInheritedValue()); 502 ASSERT(!current.value()->isInheritedValue());
510 continue; 503 continue;
511 } 504 }
512 505
513 if (!isPropertyForPass<pass>(property)) 506 if (!isPropertyForPass<pass>(property))
514 continue; 507 continue;
515 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) 508 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight)
516 state.setLineHeightValue(current.value()); 509 state.setLineHeightValue(current.value());
517 else 510 else
518 StyleBuilder::applyProperty(current.id(), state, current.value()); 511 StyleBuilder::applyProperty(current.id(), state, current.value());
519 } 512 }
520 } 513 }
521 514
522 template <StyleResolver::StyleApplicationPass pass> 515 template <StyleResolver::StyleApplicationPass pass>
523 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool isImportant, bool inheritedOnly) 516 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool inheritedOnly)
524 { 517 {
525 for (const RefPtr<StylePropertySet>& properties : matchResult.matchedPropert ies) { 518 for (const RefPtr<StylePropertySet>& properties : matchResult.matchedPropert ies) {
526 applyProperties<pass>(state, properties.get(), isImportant, inheritedOnl y); 519 applyProperties<pass>(state, properties.get(), inheritedOnly);
527 } 520 }
528 } 521 }
529 522
530 static unsigned computeMatchedPropertiesHash(const RefPtr<StylePropertySet>* pro perties, unsigned size) 523 static unsigned computeMatchedPropertiesHash(const RefPtr<StylePropertySet>* pro perties, unsigned size)
531 { 524 {
532 return StringHasher::hashMemory(properties, sizeof(*properties) * size); 525 return StringHasher::hashMemory(properties, sizeof(*properties) * size);
533 } 526 }
534 527
535 void StyleResolver::invalidateMatchedPropertiesCache() 528 void StyleResolver::invalidateMatchedPropertiesCache()
536 { 529 {
(...skipping 28 matching lines...) Expand all
565 558
566 // If the cache item parent style has identical inherited properties to the current parent style then the 559 // If the cache item parent style has identical inherited properties to the current parent style then the
567 // resulting style will be identical too. We copy the inherited prop erties over from the cache and are done. 560 // resulting style will be identical too. We copy the inherited prop erties over from the cache and are done.
568 state.style()->inheritFrom(cachedMatchedProperties->renderStyle.get( )); 561 state.style()->inheritFrom(cachedMatchedProperties->renderStyle.get( ));
569 562
570 return; 563 return;
571 } 564 }
572 applyInheritedOnly = true; 565 applyInheritedOnly = true;
573 } 566 }
574 567
575 // Now we have all of the matched rules in the appropriate order. Walk the r ules and apply
576 // high-priority properties first, i.e., those properties that other propert ies depend on.
577 // The order is (1) high-priority not important, (2) high-priority important , (3) normal not important
578 // and (4) normal important.
579 state.setLineHeightValue(0); 568 state.setLineHeightValue(0);
580 applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, ap plyInheritedOnly); 569 applyMatchedProperties<HighPriorityProperties>(state, matchResult, applyInhe ritedOnly);
581 applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, app lyInheritedOnly);
582 570
583 // If our font got dirtied, go ahead and update it now. 571 // If our font got dirtied, go ahead and update it now.
584 updateFont(state); 572 updateFont(state);
585 573
586 // Line-height is set when we are sure we decided on the font-size. 574 // Line-height is set when we are sure we decided on the font-size.
587 if (state.lineHeightValue()) 575 if (state.lineHeightValue())
588 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue()); 576 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
589 577
590 // Many properties depend on the font. If it changes we just apply all prope rties. 578 // Many properties depend on the font. If it changes we just apply all prope rties.
591 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription()) 579 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription())
592 applyInheritedOnly = false; 580 applyInheritedOnly = false;
593 581
594 // Now do the author and user normal priority properties and all the !import ant properties. 582 applyMatchedProperties<LowPriorityProperties>(state, matchResult, applyInher itedOnly);
595 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, app lyInheritedOnly);
596 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, appl yInheritedOnly);
597 583
598 loadPendingResources(state); 584 loadPendingResources(state);
599 585
600 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, state.style(), state.parentStyle())) { 586 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, state.style(), state.parentStyle())) {
601 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded); 587 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded);
602 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa sh, matchResult); 588 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa sh, matchResult);
603 } 589 }
604 590
605 ASSERT(!state.fontBuilder().fontDirty()); 591 ASSERT(!state.fontBuilder().fontDirty());
606 } 592 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 break; 643 break;
658 default: 644 default:
659 break; 645 break;
660 } 646 }
661 StyleBuilder::applyProperty(properties[i].property, state, propertie s[i].value); 647 StyleBuilder::applyProperty(properties[i].property, state, propertie s[i].value);
662 } 648 }
663 } 649 }
664 } 650 }
665 651
666 } // namespace blink 652 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/resolver/StyleResolver.h ('k') | sky/engine/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698