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