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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 void StyleResolver::resetRuleFeatures() | 241 void StyleResolver::resetRuleFeatures() |
242 { | 242 { |
243 // Need to recreate RuleFeatureSet. | 243 // Need to recreate RuleFeatureSet. |
244 m_features.clear(); | 244 m_features.clear(); |
245 m_siblingRuleSet.clear(); | 245 m_siblingRuleSet.clear(); |
246 m_uncommonAttributeRuleSet.clear(); | 246 m_uncommonAttributeRuleSet.clear(); |
247 m_needCollectFeatures = true; | 247 m_needCollectFeatures = true; |
248 } | 248 } |
249 | 249 |
250 void StyleResolver::addTreeBoundaryCrossingRules(const WillBeHeapVector<MinimalR
uleData>& rules, ContainerNode* scope) | 250 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet
* parentStyleSheet, ContainerNode& scope) |
251 { | |
252 for (unsigned i = 0; i < rules.size(); ++i) { | |
253 const MinimalRuleData& info = rules[i]; | |
254 m_treeBoundaryCrossingRules.addRule(info.m_rule, info.m_selectorIndex, s
cope, info.m_flags); | |
255 } | |
256 } | |
257 | |
258 void StyleResolver::processScopedRules(const RuleSet& authorRules, const KURL& s
heetBaseURL, ContainerNode* scope) | |
259 { | 251 { |
260 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul
es = authorRules.keyframesRules(); | 252 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul
es = authorRules.keyframesRules(); |
261 for (unsigned i = 0; i < keyframesRules.size(); ++i) | 253 for (unsigned i = 0; i < keyframesRules.size(); ++i) |
262 ensureScopedStyleResolver(scope)->addKeyframeStyle(keyframesRules[i]); | 254 ensureScopedStyleResolver(&scope)->addKeyframeStyle(keyframesRules[i]); |
263 | 255 |
264 addTreeBoundaryCrossingRules(authorRules.treeBoundaryCrossingRules(), scope)
; | 256 m_treeBoundaryCrossingRules.addTreeBoundaryCrossingRules(authorRules, scope,
parentStyleSheet); |
265 | 257 |
266 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. | 258 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo
r the moment. |
267 if (!scope || scope->isDocumentNode()) { | 259 if (scope.isDocumentNode()) { |
268 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR
ules = authorRules.fontFaceRules(); | 260 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR
ules = authorRules.fontFaceRules(); |
269 for (unsigned i = 0; i < fontFaceRules.size(); ++i) | 261 for (unsigned i = 0; i < fontFaceRules.size(); ++i) |
270 addFontFaceRule(&m_document, document().styleEngine()->fontSelector(
), fontFaceRules[i]); | 262 addFontFaceRule(&m_document, document().styleEngine()->fontSelector(
), fontFaceRules[i]); |
271 if (fontFaceRules.size()) | 263 if (fontFaceRules.size()) |
272 invalidateMatchedPropertiesCache(); | 264 invalidateMatchedPropertiesCache(); |
273 } else { | |
274 addTreeBoundaryCrossingRules(authorRules.shadowDistributedRules(), scope
); | |
275 } | 265 } |
276 } | 266 } |
277 | 267 |
278 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode) | 268 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode) |
279 { | 269 { |
280 // FIXME: When chanking scoped attribute, scopingNode's hasScopedHTMLStyleCh
ild has been already modified. | 270 // FIXME: When chanking scoped attribute, scopingNode's hasScopedHTMLStyleCh
ild has been already modified. |
281 // So we cannot use hasScopedHTMLStyleChild flag here. | 271 // So we cannot use hasScopedHTMLStyleChild flag here. |
282 ScopedStyleResolver* resolver = scopingNode ? m_styleTree.lookupScopedStyleR
esolverFor(scopingNode) : m_styleTree.scopedStyleResolverForDocument(); | 272 ScopedStyleResolver* resolver = scopingNode ? m_styleTree.lookupScopedStyleR
esolverFor(scopingNode) : m_styleTree.scopedStyleResolverForDocument(); |
283 if (!resolver) | 273 if (!resolver) |
284 return; | 274 return; |
285 | 275 |
286 treeBoundaryCrossingRules().reset(scopingNode); | 276 m_treeBoundaryCrossingRules.reset(scopingNode); |
287 | 277 |
288 resolver->resetAuthorStyle(); | 278 resolver->resetAuthorStyle(); |
289 resetRuleFeatures(); | 279 resetRuleFeatures(); |
290 if (!scopingNode) | 280 if (!scopingNode) |
291 return; | 281 return; |
292 | 282 |
293 m_styleTree.remove(scopingNode); | 283 m_styleTree.remove(scopingNode); |
294 } | 284 } |
295 | 285 |
296 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const Vector<RuleFeature>& ru
les) | 286 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const Vector<RuleFeature>& ru
les) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 void StyleResolver::popParentShadowRoot(const ShadowRoot& shadowRoot) | 383 void StyleResolver::popParentShadowRoot(const ShadowRoot& shadowRoot) |
394 { | 384 { |
395 ASSERT(shadowRoot.host()); | 385 ASSERT(shadowRoot.host()); |
396 m_styleTree.popStyleCache(shadowRoot); | 386 m_styleTree.popStyleCache(shadowRoot); |
397 } | 387 } |
398 | 388 |
399 StyleResolver::~StyleResolver() | 389 StyleResolver::~StyleResolver() |
400 { | 390 { |
401 } | 391 } |
402 | 392 |
403 inline void StyleResolver::collectTreeBoundaryCrossingRules(Element* element, El
ementRuleCollector& collector, bool includeEmptyRules) | |
404 { | |
405 if (m_treeBoundaryCrossingRules.isEmpty()) | |
406 return; | |
407 | |
408 // When comparing rules declared in outer treescopes, outer's rules win. | |
409 CascadeOrder outerCascadeOrder = m_treeBoundaryCrossingRules.size() + m_tree
BoundaryCrossingRules.size(); | |
410 // When comparing rules declared in inner treescopes, inner's rules win. | |
411 CascadeOrder innerCascadeOrder = m_treeBoundaryCrossingRules.size(); | |
412 | |
413 for (DocumentOrderedList::iterator it = m_treeBoundaryCrossingRules.begin();
it != m_treeBoundaryCrossingRules.end(); ++it) { | |
414 const ContainerNode* scopingNode = toContainerNode(*it); | |
415 RuleSet* ruleSet = m_treeBoundaryCrossingRules.ruleSetScopedBy(scopingNo
de); | |
416 unsigned boundaryBehavior = SelectorChecker::ScopeContainsLastMatchedEle
ment; | |
417 bool isInnerTreeScope = element->treeScope().isInclusiveAncestorOf(scopi
ngNode->treeScope()); | |
418 | |
419 // If a given scoping node is a shadow root and a given element is in a
descendant tree of tree hosted by | |
420 // the scoping node's shadow host, we should use ScopeIsShadowHost. | |
421 if (scopingNode && scopingNode->isShadowRoot()) { | |
422 if (element->isInDescendantTreeOf(toShadowRoot(scopingNode)->host())
) | |
423 boundaryBehavior |= SelectorChecker::ScopeIsShadowHost; | |
424 scopingNode = toShadowRoot(scopingNode)->host(); | |
425 } | |
426 | |
427 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer
CascadeOrder; | |
428 collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRules,
scopingNode), collector.matchedResult().ranges.authorRuleRange(), static_cast<Se
lectorChecker::BehaviorAtBoundary>(boundaryBehavior), ignoreCascadeScope, cascad
eOrder); | |
429 ++innerCascadeOrder; | |
430 --outerCascadeOrder; | |
431 } | |
432 } | |
433 | |
434 static inline bool applyAuthorStylesOf(const Element* element) | 393 static inline bool applyAuthorStylesOf(const Element* element) |
435 { | 394 { |
436 return element->treeScope().applyAuthorStyles() || (element->shadow() && ele
ment->shadow()->applyAuthorStyles()); | 395 return element->treeScope().applyAuthorStyles() || (element->shadow() && ele
ment->shadow()->applyAuthorStyles()); |
437 } | 396 } |
438 | 397 |
439 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC
ollector& collector, bool includeEmptyRules, Vector<ScopedStyleResolver*, 8>& re
solvers, Vector<ScopedStyleResolver*, 8>& resolversInShadowTree) | 398 void StyleResolver::matchAuthorRulesForShadowHost(Element* element, ElementRuleC
ollector& collector, bool includeEmptyRules, Vector<ScopedStyleResolver*, 8>& re
solvers, Vector<ScopedStyleResolver*, 8>& resolversInShadowTree) |
440 { | 399 { |
441 collector.clearMatchedRules(); | 400 collector.clearMatchedRules(); |
442 collector.matchedResult().ranges.authorRuleRange().setLast(collector.matched
Result().matchedProperties.size() - 1); | 401 collector.matchedResult().ranges.authorRuleRange().setLast(collector.matched
Result().matchedProperties.size() - 1); |
443 | 402 |
444 CascadeScope cascadeScope = 0; | 403 CascadeScope cascadeScope = 0; |
445 CascadeOrder cascadeOrder = 0; | 404 CascadeOrder cascadeOrder = 0; |
446 bool applyAuthorStyles = applyAuthorStylesOf(element); | 405 bool applyAuthorStyles = applyAuthorStylesOf(element); |
447 | 406 |
448 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) | 407 for (int j = resolversInShadowTree.size() - 1; j >= 0; --j) |
449 resolversInShadowTree.at(j)->collectMatchingAuthorRules(collector, inclu
deEmptyRules, applyAuthorStyles, cascadeScope, cascadeOrder++); | 408 resolversInShadowTree.at(j)->collectMatchingAuthorRules(collector, inclu
deEmptyRules, applyAuthorStyles, cascadeScope, cascadeOrder++); |
450 | 409 |
451 if (resolvers.isEmpty() || resolvers.first()->treeScope() != element->treeSc
ope()) | 410 if (resolvers.isEmpty() || resolvers.first()->treeScope() != element->treeSc
ope()) |
452 ++cascadeScope; | 411 ++cascadeScope; |
453 cascadeOrder += resolvers.size(); | 412 cascadeOrder += resolvers.size(); |
454 for (unsigned i = 0; i < resolvers.size(); ++i) | 413 for (unsigned i = 0; i < resolvers.size(); ++i) |
455 resolvers.at(i)->collectMatchingAuthorRules(collector, includeEmptyRules
, applyAuthorStyles, cascadeScope++, --cascadeOrder); | 414 resolvers.at(i)->collectMatchingAuthorRules(collector, includeEmptyRules
, applyAuthorStyles, cascadeScope++, --cascadeOrder); |
456 | 415 |
457 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 416 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); |
458 collector.sortAndTransferMatchedRules(); | 417 collector.sortAndTransferMatchedRules(); |
459 } | 418 } |
460 | 419 |
461 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) | 420 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col
lector, bool includeEmptyRules) |
462 { | 421 { |
463 collector.clearMatchedRules(); | 422 collector.clearMatchedRules(); |
464 collector.matchedResult().ranges.authorRuleRange().setLast(collector.matched
Result().matchedProperties.size() - 1); | 423 collector.matchedResult().ranges.authorRuleRange().setLast(collector.matched
Result().matchedProperties.size() - 1); |
465 | 424 |
466 bool applyAuthorStyles = applyAuthorStylesOf(element); | 425 bool applyAuthorStyles = applyAuthorStylesOf(element); |
467 if (m_styleTree.hasOnlyScopedResolverForDocument()) { | 426 if (m_styleTree.hasOnlyScopedResolverForDocument()) { |
468 m_styleTree.scopedStyleResolverForDocument()->collectMatchingAuthorRules
(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); | 427 m_styleTree.scopedStyleResolverForDocument()->collectMatchingAuthorRules
(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); |
469 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 428 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co
llector, includeEmptyRules); |
470 collector.sortAndTransferMatchedRules(); | 429 collector.sortAndTransferMatchedRules(); |
471 return; | 430 return; |
472 } | 431 } |
473 | 432 |
474 Vector<ScopedStyleResolver*, 8> resolvers; | 433 Vector<ScopedStyleResolver*, 8> resolvers; |
475 m_styleTree.resolveScopedStyles(element, resolvers); | 434 m_styleTree.resolveScopedStyles(element, resolvers); |
476 | 435 |
477 Vector<ScopedStyleResolver*, 8> resolversInShadowTree; | 436 Vector<ScopedStyleResolver*, 8> resolversInShadowTree; |
478 m_styleTree.collectScopedResolversForHostedShadowTrees(element, resolversInS
hadowTree); | 437 m_styleTree.collectScopedResolversForHostedShadowTrees(element, resolversInS
hadowTree); |
479 if (!resolversInShadowTree.isEmpty()) { | 438 if (!resolversInShadowTree.isEmpty()) { |
480 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res
olvers, resolversInShadowTree); | 439 matchAuthorRulesForShadowHost(element, collector, includeEmptyRules, res
olvers, resolversInShadowTree); |
481 return; | 440 return; |
482 } | 441 } |
483 | 442 |
484 if (resolvers.isEmpty()) | 443 if (resolvers.isEmpty()) |
485 return; | 444 return; |
486 | 445 |
487 CascadeScope cascadeScope = 0; | 446 CascadeScope cascadeScope = 0; |
488 CascadeOrder cascadeOrder = resolvers.size(); | 447 CascadeOrder cascadeOrder = resolvers.size(); |
489 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { | 448 for (unsigned i = 0; i < resolvers.size(); ++i, --cascadeOrder) { |
490 ScopedStyleResolver* resolver = resolvers.at(i); | 449 ScopedStyleResolver* resolver = resolvers.at(i); |
491 // FIXME: Need to clarify how to treat style scoped. | 450 // FIXME: Need to clarify how to treat style scoped. |
492 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r
esolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder); | 451 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r
esolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder); |
493 } | 452 } |
494 | 453 |
495 collectTreeBoundaryCrossingRules(element, collector, includeEmptyRules); | 454 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec
tor, includeEmptyRules); |
496 collector.sortAndTransferMatchedRules(); | 455 collector.sortAndTransferMatchedRules(); |
497 } | 456 } |
498 | 457 |
499 void StyleResolver::matchWatchSelectorRules(ElementRuleCollector& collector) | 458 void StyleResolver::matchWatchSelectorRules(ElementRuleCollector& collector) |
500 { | 459 { |
501 if (!m_watchedSelectorsRules) | 460 if (!m_watchedSelectorsRules) |
502 return; | 461 return; |
503 | 462 |
504 collector.clearMatchedRules(); | 463 collector.clearMatchedRules(); |
505 collector.matchedResult().ranges.userRuleRange().setLast(collector.matchedRe
sult().matchedProperties.size() - 1); | 464 collector.matchedResult().ranges.userRuleRange().setLast(collector.matchedRe
sult().matchedProperties.size() - 1); |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 visitor->trace(m_keyframesRuleMap); | 1378 visitor->trace(m_keyframesRuleMap); |
1420 visitor->trace(m_viewportDependentMediaQueryResults); | 1379 visitor->trace(m_viewportDependentMediaQueryResults); |
1421 visitor->trace(m_viewportStyleResolver); | 1380 visitor->trace(m_viewportStyleResolver); |
1422 visitor->trace(m_siblingRuleSet); | 1381 visitor->trace(m_siblingRuleSet); |
1423 visitor->trace(m_uncommonAttributeRuleSet); | 1382 visitor->trace(m_uncommonAttributeRuleSet); |
1424 visitor->trace(m_watchedSelectorsRules); | 1383 visitor->trace(m_watchedSelectorsRules); |
1425 visitor->trace(m_treeBoundaryCrossingRules); | 1384 visitor->trace(m_treeBoundaryCrossingRules); |
1426 } | 1385 } |
1427 | 1386 |
1428 } // namespace WebCore | 1387 } // namespace WebCore |
OLD | NEW |