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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 #include "core/css/CSSValueList.h" | 52 #include "core/css/CSSValueList.h" |
53 #include "core/css/CSSValuePool.h" | 53 #include "core/css/CSSValuePool.h" |
54 #include "core/css/ElementRuleCollector.h" | 54 #include "core/css/ElementRuleCollector.h" |
55 #include "core/css/FontFace.h" | 55 #include "core/css/FontFace.h" |
56 #include "core/css/MediaQueryEvaluator.h" | 56 #include "core/css/MediaQueryEvaluator.h" |
57 #include "core/css/PageRuleCollector.h" | 57 #include "core/css/PageRuleCollector.h" |
58 #include "core/css/StylePropertySet.h" | 58 #include "core/css/StylePropertySet.h" |
59 #include "core/css/StyleRuleImport.h" | 59 #include "core/css/StyleRuleImport.h" |
60 #include "core/css/StyleSheetContents.h" | 60 #include "core/css/StyleSheetContents.h" |
61 #include "core/css/resolver/AnimatedStyleBuilder.h" | 61 #include "core/css/resolver/AnimatedStyleBuilder.h" |
62 #include "core/css/resolver/ElementResolveContext.h" | |
62 #include "core/css/resolver/MatchResult.h" | 63 #include "core/css/resolver/MatchResult.h" |
63 #include "core/css/resolver/MediaQueryResult.h" | 64 #include "core/css/resolver/MediaQueryResult.h" |
64 #include "core/css/resolver/SharedStyleFinder.h" | 65 #include "core/css/resolver/SharedStyleFinder.h" |
65 #include "core/css/resolver/StyleAdjuster.h" | 66 #include "core/css/resolver/StyleAdjuster.h" |
66 #include "core/css/resolver/StyleResolverParentScope.h" | 67 #include "core/css/resolver/StyleResolverParentScope.h" |
67 #include "core/css/resolver/StyleResolverState.h" | 68 #include "core/css/resolver/StyleResolverState.h" |
68 #include "core/css/resolver/StyleResolverStats.h" | 69 #include "core/css/resolver/StyleResolverStats.h" |
69 #include "core/css/resolver/ViewportStyleResolver.h" | 70 #include "core/css/resolver/ViewportStyleResolver.h" |
70 #include "core/dom/CSSSelectorWatch.h" | 71 #include "core/dom/CSSSelectorWatch.h" |
71 #include "core/dom/NodeRenderStyle.h" | 72 #include "core/dom/NodeRenderStyle.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 return rightToLeftDecl; | 121 return rightToLeftDecl; |
121 } | 122 } |
122 | 123 |
123 static void addFontFaceRule(Document* document, CSSFontSelector* cssFontSelector , const StyleRuleFontFace* fontFaceRule) | 124 static void addFontFaceRule(Document* document, CSSFontSelector* cssFontSelector , const StyleRuleFontFace* fontFaceRule) |
124 { | 125 { |
125 RefPtrWillBeRawPtr<FontFace> fontFace = FontFace::create(document, fontFaceR ule); | 126 RefPtrWillBeRawPtr<FontFace> fontFace = FontFace::create(document, fontFaceR ule); |
126 if (fontFace) | 127 if (fontFace) |
127 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule, fon tFace); | 128 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule, fon tFace); |
128 } | 129 } |
129 | 130 |
131 class StyleBasisContext : public ElementResolveContext { | |
rune
2014/11/13 14:28:42
I don't like the name StyleBasisContext. This is s
andersr
2014/11/13 14:57:20
Yeah, that's pretty good.
| |
132 STACK_ALLOCATED(); | |
133 public: | |
134 StyleBasisContext(Element* element, RenderStyle* parentStyle) | |
135 : ElementResolveContext(*element, parentStyle) | |
136 , m_pseudoElement(nullptr) | |
137 , m_activeAnimations(element->activeAnimations()) | |
138 , m_baseRenderStyle(m_activeAnimations ? m_activeAnimations->baseRenderS tyle() : nullptr) | |
139 , m_allowsInheritance(this->parentStyle()) | |
140 { | |
141 } | |
142 | |
143 StyleBasisContext(Element* element, RenderStyle* parentStyle, const PseudoSt yleRequest& pseudoRequest) | |
144 : ElementResolveContext(*element, parentStyle) | |
145 , m_pseudoElement(element->pseudoElement(pseudoRequest.pseudoId)) | |
146 , m_activeAnimations(m_pseudoElement ? m_pseudoElement->activeAnimations () : nullptr) | |
147 , m_baseRenderStyle(m_activeAnimations ? m_activeAnimations->baseRenderS tyle() : nullptr) | |
148 , m_allowsInheritance(pseudoRequest.allowsInheritance(this->parentStyle( ))) | |
149 { | |
150 } | |
151 | |
152 PseudoElement* pseudoElement() const { return m_pseudoElement; } | |
153 ActiveAnimations* activeAnimations() const { return m_activeAnimations; } | |
154 const RenderStyle* baseRenderStyle() const { return m_baseRenderStyle; } | |
155 bool allowsInheritance() const { return m_allowsInheritance; } | |
156 private: | |
157 PseudoElement* m_pseudoElement; | |
158 ActiveAnimations* m_activeAnimations; | |
159 const RenderStyle* m_baseRenderStyle; | |
160 bool m_allowsInheritance; | |
161 }; | |
162 | |
130 StyleResolver::StyleResolver(Document& document) | 163 StyleResolver::StyleResolver(Document& document) |
131 : m_document(document) | 164 : m_document(document) |
132 , m_viewportStyleResolver(ViewportStyleResolver::create(&document)) | 165 , m_viewportStyleResolver(ViewportStyleResolver::create(&document)) |
133 , m_needCollectFeatures(false) | 166 , m_needCollectFeatures(false) |
134 , m_printMediaType(false) | 167 , m_printMediaType(false) |
135 , m_styleResourceLoader(document.fetcher()) | 168 , m_styleResourceLoader(document.fetcher()) |
136 , m_styleSharingDepth(0) | 169 , m_styleSharingDepth(0) |
137 , m_styleResolverStatsSequence(0) | 170 , m_styleResolverStatsSequence(0) |
138 , m_accessCount(0) | 171 , m_accessCount(0) |
139 { | 172 { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 // Start loading resources referenced by this style. | 574 // Start loading resources referenced by this style. |
542 void StyleResolver::loadPendingResources(StyleResolverState& state) | 575 void StyleResolver::loadPendingResources(StyleResolverState& state) |
543 { | 576 { |
544 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); | 577 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); |
545 document().styleEngine()->fontSelector()->fontLoader()->loadPendingFonts(); | 578 document().styleEngine()->fontSelector()->fontLoader()->loadPendingFonts(); |
546 } | 579 } |
547 | 580 |
548 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior, | 581 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior, |
549 RuleMatchingBehavior matchingBehavior) | 582 RuleMatchingBehavior matchingBehavior) |
550 { | 583 { |
584 ASSERT(element); | |
551 ASSERT(document().frame()); | 585 ASSERT(document().frame()); |
552 ASSERT(document().settings()); | 586 ASSERT(document().settings()); |
553 ASSERT(!hasPendingAuthorStyleSheets()); | 587 ASSERT(!hasPendingAuthorStyleSheets()); |
554 ASSERT(!m_needCollectFeatures); | 588 ASSERT(!m_needCollectFeatures); |
555 | 589 |
556 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer | 590 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer |
557 // will vanish if a style recalc happens during loading. | 591 // will vanish if a style recalc happens during loading. |
558 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() & & !element->renderer()) { | 592 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() & & !element->renderer()) { |
559 if (!s_styleNotYetAvailable) { | 593 if (!s_styleNotYetAvailable) { |
560 s_styleNotYetAvailable = RenderStyle::create().leakRef(); | 594 s_styleNotYetAvailable = RenderStyle::create().leakRef(); |
561 s_styleNotYetAvailable->setDisplay(NONE); | 595 s_styleNotYetAvailable->setDisplay(NONE); |
562 s_styleNotYetAvailable->font().update(document().styleEngine()->font Selector()); | 596 s_styleNotYetAvailable->font().update(document().styleEngine()->font Selector()); |
563 } | 597 } |
564 | 598 |
565 document().setHasNodesWithPlaceholderStyle(); | 599 document().setHasNodesWithPlaceholderStyle(); |
566 return s_styleNotYetAvailable; | 600 return s_styleNotYetAvailable; |
567 } | 601 } |
568 | 602 |
569 didAccess(); | 603 didAccess(); |
570 | 604 |
571 StyleResolverParentScope::ensureParentStackIsPushed(); | 605 StyleResolverParentScope::ensureParentStackIsPushed(); |
572 | 606 |
573 if (element == document().documentElement()) | 607 if (element == document().documentElement()) |
574 resetDirectionAndWritingModeOnDocument(document()); | 608 resetDirectionAndWritingModeOnDocument(document()); |
575 StyleResolverState state(document(), element, defaultParent); | |
576 | 609 |
577 if (sharingBehavior == AllowStyleSharing && state.parentStyle()) { | 610 StyleBasisContext styleContext(element, defaultParent); |
578 SharedStyleFinder styleFinder(state.elementContext(), m_features, m_sibl ingRuleSet.get(), m_uncommonAttributeRuleSet.get(), *this); | 611 |
612 if (sharingBehavior == AllowStyleSharing && styleContext.parentStyle()) { | |
613 SharedStyleFinder styleFinder(styleContext, m_features, m_siblingRuleSet .get(), m_uncommonAttributeRuleSet.get(), *this); | |
579 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle()) | 614 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle()) |
580 return sharedStyle.release(); | 615 return sharedStyle.release(); |
581 } | 616 } |
582 | 617 |
583 ActiveAnimations* activeAnimations = element->activeAnimations(); | 618 StyleResolverState state(document(), styleContext, styleForContext(styleCont ext), parentStyleForContext(styleContext)); |
584 const RenderStyle* baseRenderStyle = activeAnimations ? activeAnimations->ba seRenderStyle() : nullptr; | |
585 | 619 |
586 if (baseRenderStyle) { | 620 if (!styleContext.baseRenderStyle() && styleContext.allowsInheritance()) |
587 state.setStyle(RenderStyle::clone(baseRenderStyle)); | 621 state.style()->inheritFrom(styleContext.parentStyle(), isAtShadowBoundar y(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); |
588 if (!state.parentStyle()) | |
589 state.setParentStyle(defaultStyleForElement()); | |
590 } else { | |
591 if (state.parentStyle()) { | |
592 state.setStyle(RenderStyle::create()); | |
593 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(e lement) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); | |
594 } else { | |
595 state.setStyle(defaultStyleForElement()); | |
596 state.setParentStyle(RenderStyle::clone(state.style())); | |
597 } | |
598 } | |
599 | 622 |
600 // contenteditable attribute (implemented by -webkit-user-modify) should | 623 // contenteditable attribute (implemented by -webkit-user-modify) should |
601 // be propagated from shadow host to distributed node. | 624 // be propagated from shadow host to distributed node. |
602 if (state.distributedToInsertionPoint()) { | 625 if (state.distributedToInsertionPoint()) { |
603 if (Element* parent = element->parentElement()) { | 626 if (Element* parent = element->parentElement()) { |
604 if (RenderStyle* styleOfShadowHost = parent->renderStyle()) | 627 if (RenderStyle* styleOfShadowHost = parent->renderStyle()) |
605 state.style()->setUserModify(styleOfShadowHost->userModify()); | 628 state.style()->setUserModify(styleOfShadowHost->userModify()); |
606 } | 629 } |
607 } | 630 } |
608 | 631 |
609 if (element->isLink()) { | 632 if (element->isLink()) { |
610 state.style()->setIsLink(true); | 633 state.style()->setIsLink(true); |
611 EInsideLink linkState = state.elementLinkState(); | 634 EInsideLink linkState = state.elementLinkState(); |
612 if (linkState != NotInsideLink) { | 635 if (linkState != NotInsideLink) { |
613 bool forceVisited = InspectorInstrumentation::forcePseudoState(eleme nt, CSSSelector::PseudoVisited); | 636 bool forceVisited = InspectorInstrumentation::forcePseudoState(eleme nt, CSSSelector::PseudoVisited); |
614 if (forceVisited) | 637 if (forceVisited) |
615 linkState = InsideVisitedLink; | 638 linkState = InsideVisitedLink; |
616 } | 639 } |
617 state.style()->setInsideLink(linkState); | 640 state.style()->setInsideLink(linkState); |
618 } | 641 } |
619 | 642 |
620 if (!baseRenderStyle) { | 643 if (!styleContext.baseRenderStyle()) { |
621 | 644 |
622 bool needsCollection = false; | 645 bool needsCollection = false; |
623 CSSDefaultStyleSheets::instance().ensureDefaultStyleSheetsForElement(ele ment, needsCollection); | 646 CSSDefaultStyleSheets::instance().ensureDefaultStyleSheetsForElement(ele ment, needsCollection); |
624 if (needsCollection) | 647 if (needsCollection) |
625 collectFeatures(); | 648 collectFeatures(); |
626 | 649 |
627 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style()); | 650 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style()); |
628 | 651 |
629 matchAllRules(state, collector, matchingBehavior != MatchAllRulesExcludi ngSMIL); | 652 matchAllRules(state, collector, matchingBehavior != MatchAllRulesExcludi ngSMIL); |
630 | 653 |
631 applyMatchedProperties(state, collector.matchedResult()); | 654 applyMatchedProperties(state, collector.matchedResult()); |
632 applyCallbackSelectors(state); | 655 applyCallbackSelectors(state); |
633 | 656 |
634 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); | 657 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); |
635 | 658 |
636 // Cache our original display. | 659 // Cache our original display. |
637 state.style()->setOriginalDisplay(state.style()->display()); | 660 state.style()->setOriginalDisplay(state.style()->display()); |
638 | 661 |
639 adjustRenderStyle(state, element); | 662 adjustRenderStyle(state, element); |
640 | 663 |
641 if (activeAnimations) | 664 if (styleContext.activeAnimations()) |
642 activeAnimations->updateBaseRenderStyle(state.style()); | 665 styleContext.activeAnimations()->updateBaseRenderStyle(state.style() ); |
643 } | 666 } |
644 | 667 |
645 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before | 668 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before |
646 // important rules, but this currently happens here as we require adjustment to have happened | 669 // important rules, but this currently happens here as we require adjustment to have happened |
647 // before deciding which properties to transition. | 670 // before deciding which properties to transition. |
648 if (applyAnimatedProperties(state, element)) | 671 if (applyAnimatedProperties(state, element)) |
649 adjustRenderStyle(state, element); | 672 adjustRenderStyle(state, element); |
650 | 673 |
651 if (isHTMLBodyElement(*element)) | 674 if (isHTMLBodyElement(*element)) |
652 document().textLinkColors().setTextColor(state.style()->color()); | 675 document().textLinkColors().setTextColor(state.style()->color()); |
653 | 676 |
654 setAnimationUpdateIfNeeded(state, *element); | 677 setAnimationUpdateIfNeeded(state, *element); |
655 | 678 |
656 if (state.style()->hasViewportUnits()) | 679 if (state.style()->hasViewportUnits()) |
657 document().setHasViewportUnits(); | 680 document().setHasViewportUnits(); |
658 | 681 |
659 // Now return the style. | 682 // Now return the style. |
660 return state.takeStyle(); | 683 return state.takeStyle(); |
661 } | 684 } |
662 | 685 |
663 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element& element, const RenderStyle& elementStyle, RenderStyle* parentStyle, const StyleKeyframe* keyfra me, const AtomicString& animationName) | 686 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element& element, const RenderStyle& elementStyle, RenderStyle* parentStyle, const StyleKeyframe* keyfra me, const AtomicString& animationName) |
664 { | 687 { |
665 ASSERT(document().frame()); | 688 ASSERT(document().frame()); |
666 ASSERT(document().settings()); | 689 ASSERT(document().settings()); |
667 ASSERT(!hasPendingAuthorStyleSheets()); | 690 ASSERT(!hasPendingAuthorStyleSheets()); |
668 | 691 |
669 if (&element == document().documentElement()) | 692 if (&element == document().documentElement()) |
670 resetDirectionAndWritingModeOnDocument(document()); | 693 resetDirectionAndWritingModeOnDocument(document()); |
671 StyleResolverState state(document(), &element, parentStyle); | 694 StyleResolverState state(document(), &element, RenderStyle::clone(&elementSt yle), parentStyle); |
672 | 695 |
673 MatchResult result; | 696 MatchResult result; |
674 result.addMatchedProperties(&keyframe->properties()); | 697 result.addMatchedProperties(&keyframe->properties()); |
675 | 698 |
676 ASSERT(!state.style()); | |
677 | |
678 // Create the style | |
679 state.setStyle(RenderStyle::clone(&elementStyle)); | |
680 | 699 |
681 // We don't need to bother with !important. Since there is only ever one | 700 // We don't need to bother with !important. Since there is only ever one |
682 // decl, there's nothing to override. So just add the first properties. | 701 // decl, there's nothing to override. So just add the first properties. |
683 // We also don't need to bother with animation properties since the only | 702 // We also don't need to bother with animation properties since the only |
684 // relevant one is animation-timing-function and we special-case that in | 703 // relevant one is animation-timing-function and we special-case that in |
685 // CSSAnimations.cpp | 704 // CSSAnimations.cpp |
686 bool inheritedOnly = false; | 705 bool inheritedOnly = false; |
687 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly); | 706 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly); |
688 | 707 |
689 // If our font got dirtied, go ahead and update it now. | 708 // If our font got dirtied, go ahead and update it now. |
(...skipping 11 matching lines...) Expand all Loading... | |
701 | 720 |
702 // This function is used by the WebAnimations JavaScript API method animate(). | 721 // This function is used by the WebAnimations JavaScript API method animate(). |
703 // FIXME: Remove this when animate() switches away from resolution-dependent par sing. | 722 // FIXME: Remove this when animate() switches away from resolution-dependent par sing. |
704 PassRefPtrWillBeRawPtr<AnimatableValue> StyleResolver::createAnimatableValueSnap shot(Element& element, CSSPropertyID property, CSSValue& value) | 723 PassRefPtrWillBeRawPtr<AnimatableValue> StyleResolver::createAnimatableValueSnap shot(Element& element, CSSPropertyID property, CSSValue& value) |
705 { | 724 { |
706 RefPtr<RenderStyle> style; | 725 RefPtr<RenderStyle> style; |
707 if (element.renderStyle()) | 726 if (element.renderStyle()) |
708 style = RenderStyle::clone(element.renderStyle()); | 727 style = RenderStyle::clone(element.renderStyle()); |
709 else | 728 else |
710 style = RenderStyle::create(); | 729 style = RenderStyle::create(); |
711 StyleResolverState state(element.document(), &element); | 730 StyleResolverState state(element.document(), &element, style); |
712 state.setStyle(style); | |
713 return createAnimatableValueSnapshot(state, property, value); | 731 return createAnimatableValueSnapshot(state, property, value); |
714 } | 732 } |
715 | 733 |
716 PassRefPtrWillBeRawPtr<AnimatableValue> StyleResolver::createAnimatableValueSnap shot(StyleResolverState& state, CSSPropertyID property, CSSValue& value) | 734 PassRefPtrWillBeRawPtr<AnimatableValue> StyleResolver::createAnimatableValueSnap shot(StyleResolverState& state, CSSPropertyID property, CSSValue& value) |
717 { | 735 { |
718 StyleBuilder::applyProperty(property, state, &value); | 736 StyleBuilder::applyProperty(property, state, &value); |
719 return CSSAnimatableValueFactory::create(property, *state.style()); | 737 return CSSAnimatableValueFactory::create(property, *state.style()); |
720 } | 738 } |
721 | 739 |
740 PassRefPtr<RenderStyle> StyleResolver::styleForContext(const StyleBasisContext& styleContext) | |
741 { | |
742 if (styleContext.baseRenderStyle()) | |
743 return RenderStyle::clone(styleContext.baseRenderStyle()); | |
744 if (styleContext.allowsInheritance()) | |
745 return RenderStyle::create(); | |
746 return initialRenderStyle(); | |
747 } | |
748 | |
749 PassRefPtr<RenderStyle> StyleResolver::parentStyleForContext(const StyleBasisCon text& styleContext) | |
750 { | |
751 if (styleContext.allowsInheritance()) | |
752 return styleContext.parentStyle(); | |
753 if (styleContext.baseRenderStyle()) | |
754 return initialRenderStyle(); | |
755 return nullptr; | |
rune
2014/11/13 14:28:42
Would it be better to do the clone() here instead
andersr
2014/11/13 14:57:20
I wanted to avoid this verbosity at each call site
| |
756 } | |
757 | |
722 PassRefPtrWillBeRawPtr<PseudoElement> StyleResolver::createPseudoElementIfNeeded (Element& parent, PseudoId pseudoId) | 758 PassRefPtrWillBeRawPtr<PseudoElement> StyleResolver::createPseudoElementIfNeeded (Element& parent, PseudoId pseudoId) |
723 { | 759 { |
724 RenderObject* parentRenderer = parent.renderer(); | 760 RenderObject* parentRenderer = parent.renderer(); |
725 if (!parentRenderer) | 761 if (!parentRenderer) |
726 return nullptr; | 762 return nullptr; |
727 | 763 |
728 if (pseudoId < FIRST_INTERNAL_PSEUDOID && !parentRenderer->style()->hasPseud oStyle(pseudoId)) | 764 if (pseudoId < FIRST_INTERNAL_PSEUDOID && !parentRenderer->style()->hasPseud oStyle(pseudoId)) |
729 return nullptr; | 765 return nullptr; |
730 | 766 |
731 if (pseudoId == BACKDROP && !parent.isInTopLayer()) | 767 if (pseudoId == BACKDROP && !parent.isInTopLayer()) |
732 return nullptr; | 768 return nullptr; |
733 | 769 |
734 if (!parentRenderer->canHaveGeneratedChildren()) | 770 if (!parentRenderer->canHaveGeneratedChildren()) |
735 return nullptr; | 771 return nullptr; |
736 | 772 |
737 RenderStyle* parentStyle = parentRenderer->style(); | 773 RenderStyle* parentStyle = parentRenderer->style(); |
738 if (RenderStyle* cachedStyle = parentStyle->getCachedPseudoStyle(pseudoId)) { | 774 if (RenderStyle* cachedStyle = parentStyle->getCachedPseudoStyle(pseudoId)) { |
739 if (!pseudoElementRendererIsNeeded(cachedStyle)) | 775 if (!pseudoElementRendererIsNeeded(cachedStyle)) |
740 return nullptr; | 776 return nullptr; |
741 return PseudoElement::create(&parent, pseudoId); | 777 return PseudoElement::create(&parent, pseudoId); |
742 } | 778 } |
743 | 779 |
744 StyleResolverState state(document(), &parent, parentStyle); | 780 StyleBasisContext styleContext(&parent, parentStyle, pseudoId); |
745 if (!pseudoStyleForElementInternal(parent, pseudoId, parentStyle, state)) | 781 StyleResolverState state(document(), styleContext, styleForContext(styleCont ext), parentStyleForContext(styleContext)); |
782 if (!pseudoStyleForElementInternal(pseudoId, state, styleContext)) | |
746 return nullptr; | 783 return nullptr; |
747 RefPtr<RenderStyle> style = state.takeStyle(); | 784 RefPtr<RenderStyle> style = state.takeStyle(); |
748 ASSERT(style); | 785 ASSERT(style); |
749 parentStyle->addCachedPseudoStyle(style); | 786 parentStyle->addCachedPseudoStyle(style); |
750 | 787 |
751 if (!pseudoElementRendererIsNeeded(style.get())) | 788 if (!pseudoElementRendererIsNeeded(style.get())) |
752 return nullptr; | 789 return nullptr; |
753 | 790 |
754 RefPtrWillBeRawPtr<PseudoElement> pseudo = PseudoElement::create(&parent, ps eudoId); | 791 RefPtrWillBeRawPtr<PseudoElement> pseudo = PseudoElement::create(&parent, ps eudoId); |
755 | 792 |
756 setAnimationUpdateIfNeeded(state, *pseudo); | 793 setAnimationUpdateIfNeeded(state, *pseudo); |
757 if (ActiveAnimations* activeAnimations = pseudo->activeAnimations()) | 794 if (ActiveAnimations* activeAnimations = pseudo->activeAnimations()) |
758 activeAnimations->cssAnimations().maybeApplyPendingUpdate(pseudo.get()); | 795 activeAnimations->cssAnimations().maybeApplyPendingUpdate(pseudo.get()); |
759 return pseudo.release(); | 796 return pseudo.release(); |
760 } | 797 } |
761 | 798 |
762 bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo StyleRequest& pseudoStyleRequest, RenderStyle* parentStyle, StyleResolverState& state) | 799 bool StyleResolver::pseudoStyleForElementInternal(const PseudoStyleRequest& pseu doStyleRequest, StyleResolverState& state, const StyleBasisContext& styleContext ) |
763 { | 800 { |
764 ASSERT(document().frame()); | 801 ASSERT(document().frame()); |
765 ASSERT(document().settings()); | 802 ASSERT(document().settings()); |
766 ASSERT(pseudoStyleRequest.pseudoId != FIRST_LINE_INHERITED); | 803 ASSERT(pseudoStyleRequest.pseudoId != FIRST_LINE_INHERITED); |
767 ASSERT(state.parentStyle()); | 804 ASSERT(state.parentStyle()); |
768 | 805 |
769 StyleResolverParentScope::ensureParentStackIsPushed(); | 806 StyleResolverParentScope::ensureParentStackIsPushed(); |
770 | 807 |
771 Element* pseudoElement = element.pseudoElement(pseudoStyleRequest.pseudoId); | 808 if (!styleContext.baseRenderStyle() && styleContext.allowsInheritance()) |
772 | 809 state.style()->inheritFrom(styleContext.parentStyle()); |
773 ActiveAnimations* activeAnimations = pseudoElement ? pseudoElement->activeAn imations() : nullptr; | |
774 const RenderStyle* baseRenderStyle = activeAnimations ? activeAnimations->ba seRenderStyle() : nullptr; | |
775 | |
776 if (baseRenderStyle) { | |
777 state.setStyle(RenderStyle::clone(baseRenderStyle)); | |
778 } else if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { | |
779 state.setStyle(RenderStyle::create()); | |
780 state.style()->inheritFrom(state.parentStyle()); | |
781 } else { | |
782 state.setStyle(defaultStyleForElement()); | |
783 state.setParentStyle(RenderStyle::clone(state.style())); | |
784 } | |
785 | 810 |
786 state.style()->setStyleType(pseudoStyleRequest.pseudoId); | 811 state.style()->setStyleType(pseudoStyleRequest.pseudoId); |
787 | 812 |
788 // Since we don't use pseudo-elements in any of our quirk/print | 813 // Since we don't use pseudo-elements in any of our quirk/print |
789 // user agent rules, don't waste time walking those rules. | 814 // user agent rules, don't waste time walking those rules. |
790 | 815 |
791 if (!baseRenderStyle) { | 816 if (!styleContext.baseRenderStyle()) { |
817 | |
792 // Check UA, user and author rules. | 818 // Check UA, user and author rules. |
793 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style()); | 819 ElementRuleCollector collector(styleContext, m_selectorFilter, state.sty le()); |
794 collector.setPseudoStyleRequest(pseudoStyleRequest); | 820 collector.setPseudoStyleRequest(pseudoStyleRequest); |
795 | 821 |
796 matchUARules(collector); | 822 matchUARules(collector); |
797 matchAuthorRules(state.element(), collector, false); | 823 matchAuthorRules(state.element(), collector, false); |
798 | 824 |
799 if (collector.matchedResult().matchedProperties.isEmpty()) | 825 if (collector.matchedResult().matchedProperties.isEmpty()) |
800 return false; | 826 return false; |
801 | 827 |
802 applyMatchedProperties(state, collector.matchedResult()); | 828 applyMatchedProperties(state, collector.matchedResult()); |
803 applyCallbackSelectors(state); | 829 applyCallbackSelectors(state); |
804 | 830 |
805 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); | 831 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); |
806 | 832 |
807 // Cache our original display. | 833 // Cache our original display. |
808 state.style()->setOriginalDisplay(state.style()->display()); | 834 state.style()->setOriginalDisplay(state.style()->display()); |
809 | 835 |
810 // FIXME: Passing 0 as the Element* introduces a lot of complexity | 836 // FIXME: Passing 0 as the Element* introduces a lot of complexity |
811 // in the adjustRenderStyle code. | 837 // in the adjustRenderStyle code. |
812 adjustRenderStyle(state, 0); | 838 adjustRenderStyle(state, 0); |
813 | 839 |
814 if (activeAnimations) | 840 if (styleContext.activeAnimations()) |
815 activeAnimations->updateBaseRenderStyle(state.style()); | 841 styleContext.activeAnimations()->updateBaseRenderStyle(state.style() ); |
816 } | 842 } |
817 | 843 |
818 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before | 844 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before |
819 // important rules, but this currently happens here as we require adjustment to have happened | 845 // important rules, but this currently happens here as we require adjustment to have happened |
820 // before deciding which properties to transition. | 846 // before deciding which properties to transition. |
821 if (applyAnimatedProperties(state, pseudoElement)) | 847 if (applyAnimatedProperties(state, styleContext.pseudoElement())) |
822 adjustRenderStyle(state, 0); | 848 adjustRenderStyle(state, 0); |
823 | 849 |
824 didAccess(); | 850 didAccess(); |
825 | 851 |
826 if (state.style()->hasViewportUnits()) | 852 if (state.style()->hasViewportUnits()) |
827 document().setHasViewportUnits(); | 853 document().setHasViewportUnits(); |
828 | 854 |
829 return true; | 855 return true; |
830 } | 856 } |
831 | 857 |
832 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* element, c onst PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle) | 858 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* element, c onst PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle) |
833 { | 859 { |
834 ASSERT(parentStyle); | 860 ASSERT(parentStyle); |
835 if (!element) | 861 if (!element) |
836 return nullptr; | 862 return nullptr; |
837 | 863 |
838 StyleResolverState state(document(), element, parentStyle); | 864 StyleBasisContext styleContext(element, parentStyle, pseudoStyleRequest); |
839 if (!pseudoStyleForElementInternal(*element, pseudoStyleRequest, parentStyle , state)) { | 865 StyleResolverState state(document(), styleContext, styleForContext(styleCont ext), parentStyleForContext(styleContext)); |
866 if (!pseudoStyleForElementInternal(pseudoStyleRequest, state, styleContext)) { | |
840 if (pseudoStyleRequest.type == PseudoStyleRequest::ForRenderer) | 867 if (pseudoStyleRequest.type == PseudoStyleRequest::ForRenderer) |
841 return nullptr; | 868 return nullptr; |
842 return state.takeStyle(); | 869 return state.takeStyle(); |
843 } | 870 } |
844 | 871 |
845 if (PseudoElement* pseudoElement = element->pseudoElement(pseudoStyleRequest .pseudoId)) | 872 if (PseudoElement* pseudoElement = element->pseudoElement(pseudoStyleRequest .pseudoId)) |
846 setAnimationUpdateIfNeeded(state, *pseudoElement); | 873 setAnimationUpdateIfNeeded(state, *pseudoElement); |
847 | 874 |
848 // Now return the style. | 875 // Now return the style. |
849 return state.takeStyle(); | 876 return state.takeStyle(); |
850 } | 877 } |
851 | 878 |
852 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) | 879 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) |
853 { | 880 { |
854 ASSERT(!hasPendingAuthorStyleSheets()); | 881 ASSERT(!hasPendingAuthorStyleSheets()); |
855 resetDirectionAndWritingModeOnDocument(document()); | 882 resetDirectionAndWritingModeOnDocument(document()); |
856 StyleResolverState state(document(), document().documentElement()); // m_roo tElementStyle will be set to the document style. | 883 StyleResolverState state(document(), document().documentElement(), RenderSty le::create()); // m_rootElementStyle will be set to the document style. |
857 | 884 |
858 state.setStyle(RenderStyle::create()); | |
859 const RenderStyle* rootElementStyle = state.rootElementStyle() ? state.rootE lementStyle() : document().renderStyle(); | 885 const RenderStyle* rootElementStyle = state.rootElementStyle() ? state.rootE lementStyle() : document().renderStyle(); |
860 ASSERT(rootElementStyle); | 886 ASSERT(rootElementStyle); |
861 state.style()->inheritFrom(rootElementStyle); | 887 state.style()->inheritFrom(rootElementStyle); |
862 | 888 |
863 PageRuleCollector collector(rootElementStyle, pageIndex); | 889 PageRuleCollector collector(rootElementStyle, pageIndex); |
864 | 890 |
865 collector.matchPageRules(CSSDefaultStyleSheets::instance().defaultPrintStyle ()); | 891 collector.matchPageRules(CSSDefaultStyleSheets::instance().defaultPrintStyle ()); |
866 | 892 |
867 if (ScopedStyleResolver* scopedResolver = document().scopedStyleResolver()) | 893 if (ScopedStyleResolver* scopedResolver = document().scopedStyleResolver()) |
868 scopedResolver->matchPageRules(collector); | 894 scopedResolver->matchPageRules(collector); |
(...skipping 28 matching lines...) Expand all Loading... | |
897 | 923 |
898 if (document().isMobileDocument()) | 924 if (document().isMobileDocument()) |
899 viewportStyleResolver()->collectViewportRules(defaultStyleSheets.default XHTMLMobileProfileStyle(), ViewportStyleResolver::UserAgentOrigin); | 925 viewportStyleResolver()->collectViewportRules(defaultStyleSheets.default XHTMLMobileProfileStyle(), ViewportStyleResolver::UserAgentOrigin); |
900 | 926 |
901 if (ScopedStyleResolver* scopedResolver = document().scopedStyleResolver()) | 927 if (ScopedStyleResolver* scopedResolver = document().scopedStyleResolver()) |
902 scopedResolver->collectViewportRulesTo(this); | 928 scopedResolver->collectViewportRulesTo(this); |
903 | 929 |
904 viewportStyleResolver()->resolve(); | 930 viewportStyleResolver()->resolve(); |
905 } | 931 } |
906 | 932 |
907 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() | 933 PassRefPtr<RenderStyle> StyleResolver::initialRenderStyle() |
908 { | 934 { |
909 StyleResolverState state(document(), 0); | 935 RefPtr<RenderStyle> style = RenderStyle::create(); |
910 state.setStyle(RenderStyle::create()); | 936 FontBuilder fontBuilder(document(), style.get()); |
911 state.fontBuilder().setInitial(state.style()->effectiveZoom()); | 937 fontBuilder.setInitial(style->effectiveZoom()); |
912 state.style()->font().update(document().styleEngine()->fontSelector()); | 938 style->font().update(document().styleEngine()->fontSelector()); |
913 return state.takeStyle(); | 939 return style.release(); |
914 } | 940 } |
915 | 941 |
916 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode) | 942 PassRefPtr<RenderStyle> StyleResolver::styleForText(Text* textNode) |
917 { | 943 { |
918 ASSERT(textNode); | 944 ASSERT(textNode); |
919 | 945 |
920 Node* parentNode = NodeRenderingTraversal::parent(textNode); | 946 Node* parentNode = NodeRenderingTraversal::parent(textNode); |
921 if (!parentNode || !parentNode->renderStyle()) | 947 if (!parentNode || !parentNode->renderStyle()) |
922 return defaultStyleForElement(); | 948 return initialRenderStyle(); |
923 return parentNode->renderStyle(); | 949 return parentNode->renderStyle(); |
924 } | 950 } |
925 | 951 |
926 void StyleResolver::updateFont(StyleResolverState& state) | 952 void StyleResolver::updateFont(StyleResolverState& state) |
927 { | 953 { |
928 state.fontBuilder().createFont(document().styleEngine()->fontSelector(), sta te.parentStyle(), state.style()); | 954 state.fontBuilder().createFont(document().styleEngine()->fontSelector(), sta te.parentStyle(), state.style()); |
929 } | 955 } |
930 | 956 |
931 PassRefPtrWillBeRawPtr<StyleRuleList> StyleResolver::styleRulesForElement(Elemen t* element, unsigned rulesToInclude) | 957 PassRefPtrWillBeRawPtr<StyleRuleList> StyleResolver::styleRulesForElement(Elemen t* element, unsigned rulesToInclude) |
932 { | 958 { |
933 ASSERT(element); | 959 ASSERT(element); |
934 StyleResolverState state(document(), element); | 960 ElementResolveContext elementContext(*element, nullptr); |
935 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta te.style()); | 961 ElementRuleCollector collector(elementContext, m_selectorFilter, nullptr); |
936 collector.setMode(SelectorChecker::CollectingStyleRules); | 962 collector.setMode(SelectorChecker::CollectingStyleRules); |
937 collectPseudoRulesForElement(element, collector, NOPSEUDO, rulesToInclude); | 963 collectPseudoRulesForElement(element, collector, NOPSEUDO, rulesToInclude); |
938 return collector.matchedStyleRuleList(); | 964 return collector.matchedStyleRuleList(); |
939 } | 965 } |
940 | 966 |
941 PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::pseudoCSSRulesForElement(Elem ent* element, PseudoId pseudoId, unsigned rulesToInclude) | 967 PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::pseudoCSSRulesForElement(Elem ent* element, PseudoId pseudoId, unsigned rulesToInclude) |
942 { | 968 { |
943 ASSERT(element); | 969 ASSERT(element); |
944 StyleResolverState state(document(), element); | 970 ElementResolveContext elementContext(*element, nullptr); |
945 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta te.style()); | 971 ElementRuleCollector collector(elementContext, m_selectorFilter, nullptr); |
946 collector.setMode(SelectorChecker::CollectingCSSRules); | 972 collector.setMode(SelectorChecker::CollectingCSSRules); |
947 collectPseudoRulesForElement(element, collector, pseudoId, rulesToInclude); | 973 collectPseudoRulesForElement(element, collector, pseudoId, rulesToInclude); |
948 return collector.matchedCSSRuleList(); | 974 return collector.matchedCSSRuleList(); |
949 } | 975 } |
950 | 976 |
951 PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::cssRulesForElement(Element* e lement, unsigned rulesToInclude) | 977 PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::cssRulesForElement(Element* e lement, unsigned rulesToInclude) |
952 { | 978 { |
953 return pseudoCSSRulesForElement(element, NOPSEUDO, rulesToInclude); | 979 return pseudoCSSRulesForElement(element, NOPSEUDO, rulesToInclude); |
954 } | 980 } |
955 | 981 |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1524 if (!m_styleResolverStats) | 1550 if (!m_styleResolverStats) |
1525 return; | 1551 return; |
1526 fprintf(stderr, "=== Style Resolver Stats (resolve #%u) (%s) ===\n", ++m_sty leResolverStatsSequence, document().url().string().utf8().data()); | 1552 fprintf(stderr, "=== Style Resolver Stats (resolve #%u) (%s) ===\n", ++m_sty leResolverStatsSequence, document().url().string().utf8().data()); |
1527 fprintf(stderr, "%s\n", m_styleResolverStats->report().utf8().data()); | 1553 fprintf(stderr, "%s\n", m_styleResolverStats->report().utf8().data()); |
1528 fprintf(stderr, "== Totals ==\n"); | 1554 fprintf(stderr, "== Totals ==\n"); |
1529 fprintf(stderr, "%s\n", m_styleResolverStatsTotals->report().utf8().data()); | 1555 fprintf(stderr, "%s\n", m_styleResolverStatsTotals->report().utf8().data()); |
1530 } | 1556 } |
1531 | 1557 |
1532 void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s ize_t count, RenderStyle* style) | 1558 void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s ize_t count, RenderStyle* style) |
1533 { | 1559 { |
1534 StyleResolverState state(document(), document().documentElement(), style); | 1560 StyleResolverState state(document(), document().documentElement(), style, st yle); |
1535 state.setStyle(style); | |
1536 | 1561 |
1537 for (size_t i = 0; i < count; ++i) { | 1562 for (size_t i = 0; i < count; ++i) { |
1538 if (properties[i].value) { | 1563 if (properties[i].value) { |
1539 // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call, | 1564 // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call, |
1540 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122). | 1565 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122). |
1541 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height. | 1566 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height. |
1542 switch (properties[i].property) { | 1567 switch (properties[i].property) { |
1543 case CSSPropertyFontSize: | 1568 case CSSPropertyFontSize: |
1544 case CSSPropertyLineHeight: | 1569 case CSSPropertyLineHeight: |
1545 updateFont(state); | 1570 updateFont(state); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1580 visitor->trace(m_uncommonAttributeRuleSet); | 1605 visitor->trace(m_uncommonAttributeRuleSet); |
1581 visitor->trace(m_watchedSelectorsRules); | 1606 visitor->trace(m_watchedSelectorsRules); |
1582 visitor->trace(m_treeBoundaryCrossingRules); | 1607 visitor->trace(m_treeBoundaryCrossingRules); |
1583 visitor->trace(m_styleSharingLists); | 1608 visitor->trace(m_styleSharingLists); |
1584 visitor->trace(m_pendingStyleSheets); | 1609 visitor->trace(m_pendingStyleSheets); |
1585 visitor->trace(m_document); | 1610 visitor->trace(m_document); |
1586 #endif | 1611 #endif |
1587 } | 1612 } |
1588 | 1613 |
1589 } // namespace blink | 1614 } // namespace blink |
OLD | NEW |