| OLD | NEW |
| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 m_styleSharingList.clear(); | 141 m_styleSharingList.clear(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 StyleResolver::~StyleResolver() | 144 StyleResolver::~StyleResolver() |
| 145 { | 145 { |
| 146 } | 146 } |
| 147 | 147 |
| 148 void StyleResolver::matchRules(Element& element, ElementRuleCollector& collector
) | 148 void StyleResolver::matchRules(Element& element, ElementRuleCollector& collector
) |
| 149 { | 149 { |
| 150 collector.clearMatchedRules(); | 150 collector.clearMatchedRules(); |
| 151 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().
matchedProperties.size() - 1; | |
| 152 | 151 |
| 153 CascadeOrder cascadeOrder = 0; | 152 CascadeOrder cascadeOrder = 0; |
| 154 | 153 |
| 155 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); | 154 collector.collectMatchingRules(MatchRequest(&defaultStyles()), ++cascadeOrde
r); |
| 156 collector.collectMatchingRules(MatchRequest(&defaultStyles()), ruleRange, ++
cascadeOrder); | |
| 157 | 155 |
| 158 if (ShadowRoot* shadowRoot = element.shadowRoot()) | 156 if (ShadowRoot* shadowRoot = element.shadowRoot()) |
| 159 shadowRoot->scopedStyleResolver().collectMatchingHostRules(collector, ++
cascadeOrder); | 157 shadowRoot->scopedStyleResolver().collectMatchingHostRules(collector, ++
cascadeOrder); |
| 160 | 158 |
| 161 ScopedStyleResolver& resolver = element.treeScope().scopedStyleResolver(); | 159 ScopedStyleResolver& resolver = element.treeScope().scopedStyleResolver(); |
| 162 resolver.collectMatchingAuthorRules(collector, ++cascadeOrder); | 160 resolver.collectMatchingAuthorRules(collector, ++cascadeOrder); |
| 163 | 161 |
| 164 collector.sortAndTransferMatchedRules(); | 162 collector.sortAndTransferMatchedRules(); |
| 165 | 163 |
| 166 if (const StylePropertySet* inlineStyle = element.inlineStyle()) { | 164 if (const StylePropertySet* inlineStyle = element.inlineStyle()) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 state.setLineHeightValue(0); | 270 state.setLineHeightValue(0); |
| 273 | 271 |
| 274 state.fontBuilder().initForStyleResolve(state.document(), state.style()); | 272 state.fontBuilder().initForStyleResolve(state.document(), state.style()); |
| 275 | 273 |
| 276 // We don't need to bother with !important. Since there is only ever one | 274 // We don't need to bother with !important. Since there is only ever one |
| 277 // decl, there's nothing to override. So just add the first properties. | 275 // decl, there's nothing to override. So just add the first properties. |
| 278 // We also don't need to bother with animation properties since the only | 276 // We also don't need to bother with animation properties since the only |
| 279 // relevant one is animation-timing-function and we special-case that in | 277 // relevant one is animation-timing-function and we special-case that in |
| 280 // CSSAnimations.cpp | 278 // CSSAnimations.cpp |
| 281 bool inheritedOnly = false; | 279 bool inheritedOnly = false; |
| 282 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu
lt.matchedProperties.size() - 1, inheritedOnly); | 280 applyMatchedProperties<HighPriorityProperties>(state, result, false, inherit
edOnly); |
| 283 | 281 |
| 284 // If our font got dirtied, go ahead and update it now. | 282 // If our font got dirtied, go ahead and update it now. |
| 285 updateFont(state); | 283 updateFont(state); |
| 286 | 284 |
| 287 // Line-height is set when we are sure we decided on the font-size | 285 // Line-height is set when we are sure we decided on the font-size |
| 288 if (state.lineHeightValue()) | 286 if (state.lineHeightValue()) |
| 289 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig
htValue()); | 287 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig
htValue()); |
| 290 | 288 |
| 291 // Now do rest of the properties. | 289 // Now do rest of the properties. |
| 292 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul
t.matchedProperties.size() - 1, inheritedOnly); | 290 applyMatchedProperties<LowPriorityProperties>(state, result, false, inherite
dOnly); |
| 293 | 291 |
| 294 loadPendingResources(state); | 292 loadPendingResources(state); |
| 295 | 293 |
| 296 return state.takeStyle(); | 294 return state.takeStyle(); |
| 297 } | 295 } |
| 298 | 296 |
| 299 // This function is used by the WebAnimations JavaScript API method animate(). | 297 // This function is used by the WebAnimations JavaScript API method animate(). |
| 300 // FIXME: Remove this when animate() switches away from resolution-dependent par
sing. | 298 // FIXME: Remove this when animate() switches away from resolution-dependent par
sing. |
| 301 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(Element
& element, CSSPropertyID property, CSSValue& value) | 299 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(Element
& element, CSSPropertyID property, CSSValue& value) |
| 302 { | 300 { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 if (!isPropertyForPass<pass>(property)) | 513 if (!isPropertyForPass<pass>(property)) |
| 516 continue; | 514 continue; |
| 517 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) | 515 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) |
| 518 state.setLineHeightValue(current.value()); | 516 state.setLineHeightValue(current.value()); |
| 519 else | 517 else |
| 520 StyleBuilder::applyProperty(current.id(), state, current.value()); | 518 StyleBuilder::applyProperty(current.id(), state, current.value()); |
| 521 } | 519 } |
| 522 } | 520 } |
| 523 | 521 |
| 524 template <StyleResolver::StyleApplicationPass pass> | 522 template <StyleResolver::StyleApplicationPass pass> |
| 525 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc
hResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inher
itedOnly) | 523 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc
hResult& matchResult, bool isImportant, bool inheritedOnly) |
| 526 { | 524 { |
| 527 if (startIndex == -1) | 525 for (const RefPtr<StylePropertySet>& properties : matchResult.matchedPropert
ies) { |
| 528 return; | 526 applyProperties<pass>(state, properties.get(), isImportant, inheritedOnl
y); |
| 529 for (int i = startIndex; i <= endIndex; ++i) { | |
| 530 const MatchedProperties& matchedProperties = matchResult.matchedProperti
es[i]; | |
| 531 applyProperties<pass>(state, matchedProperties.properties.get(), isImpor
tant, inheritedOnly); | |
| 532 } | 527 } |
| 533 } | 528 } |
| 534 | 529 |
| 535 static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties
, unsigned size) | 530 static unsigned computeMatchedPropertiesHash(const RefPtr<StylePropertySet>* pro
perties, unsigned size) |
| 536 { | 531 { |
| 537 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size
); | 532 return StringHasher::hashMemory(properties, sizeof(*properties) * size); |
| 538 } | 533 } |
| 539 | 534 |
| 540 void StyleResolver::invalidateMatchedPropertiesCache() | 535 void StyleResolver::invalidateMatchedPropertiesCache() |
| 541 { | 536 { |
| 542 m_matchedPropertiesCache.clear(); | 537 m_matchedPropertiesCache.clear(); |
| 543 } | 538 } |
| 544 | 539 |
| 545 void StyleResolver::notifyResizeForViewportUnits() | 540 void StyleResolver::notifyResizeForViewportUnits() |
| 546 { | 541 { |
| 547 m_matchedPropertiesCache.clearViewportDependent(); | 542 m_matchedPropertiesCache.clearViewportDependent(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 575 return; | 570 return; |
| 576 } | 571 } |
| 577 applyInheritedOnly = true; | 572 applyInheritedOnly = true; |
| 578 } | 573 } |
| 579 | 574 |
| 580 // Now we have all of the matched rules in the appropriate order. Walk the r
ules and apply | 575 // Now we have all of the matched rules in the appropriate order. Walk the r
ules and apply |
| 581 // high-priority properties first, i.e., those properties that other propert
ies depend on. | 576 // high-priority properties first, i.e., those properties that other propert
ies depend on. |
| 582 // The order is (1) high-priority not important, (2) high-priority important
, (3) normal not important | 577 // The order is (1) high-priority not important, (2) high-priority important
, (3) normal not important |
| 583 // and (4) normal important. | 578 // and (4) normal important. |
| 584 state.setLineHeightValue(0); | 579 state.setLineHeightValue(0); |
| 585 applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, 0,
matchResult.matchedProperties.size() - 1, applyInheritedOnly); | 580 applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, ap
plyInheritedOnly); |
| 586 applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, mat
chResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInherit
edOnly); | 581 applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, app
lyInheritedOnly); |
| 587 applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, mat
chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); | |
| 588 | 582 |
| 589 // If our font got dirtied, go ahead and update it now. | 583 // If our font got dirtied, go ahead and update it now. |
| 590 updateFont(state); | 584 updateFont(state); |
| 591 | 585 |
| 592 // Line-height is set when we are sure we decided on the font-size. | 586 // Line-height is set when we are sure we decided on the font-size. |
| 593 if (state.lineHeightValue()) | 587 if (state.lineHeightValue()) |
| 594 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig
htValue()); | 588 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig
htValue()); |
| 595 | 589 |
| 596 // Many properties depend on the font. If it changes we just apply all prope
rties. | 590 // Many properties depend on the font. If it changes we just apply all prope
rties. |
| 597 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes
cription() != state.style()->fontDescription()) | 591 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes
cription() != state.style()->fontDescription()) |
| 598 applyInheritedOnly = false; | 592 applyInheritedOnly = false; |
| 599 | 593 |
| 600 // Now do the normal priority UA properties. | |
| 601 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat
chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); | |
| 602 | |
| 603 // Now do the author and user normal priority properties and all the !import
ant properties. | 594 // Now do the author and user normal priority properties and all the !import
ant properties. |
| 604 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat
chResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyI
nheritedOnly); | 595 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, app
lyInheritedOnly); |
| 605 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc
hResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInherite
dOnly); | 596 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, appl
yInheritedOnly); |
| 606 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc
hResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); | |
| 607 | 597 |
| 608 loadPendingResources(state); | 598 loadPendingResources(state); |
| 609 | 599 |
| 610 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache
able(element, state.style(), state.parentStyle())) { | 600 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache
able(element, state.style(), state.parentStyle())) { |
| 611 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded); | 601 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded); |
| 612 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa
sh, matchResult); | 602 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa
sh, matchResult); |
| 613 } | 603 } |
| 614 | 604 |
| 615 ASSERT(!state.fontBuilder().fontDirty()); | 605 ASSERT(!state.fontBuilder().fontDirty()); |
| 616 } | 606 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 break; | 657 break; |
| 668 default: | 658 default: |
| 669 break; | 659 break; |
| 670 } | 660 } |
| 671 StyleBuilder::applyProperty(properties[i].property, state, propertie
s[i].value); | 661 StyleBuilder::applyProperty(properties[i].property, state, propertie
s[i].value); |
| 672 } | 662 } |
| 673 } | 663 } |
| 674 } | 664 } |
| 675 | 665 |
| 676 } // namespace blink | 666 } // namespace blink |
| OLD | NEW |