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. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. |
6 * All rights reserved. | 6 * All rights reserved. |
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
10 * (http://www.torchmobile.com/) | 10 * (http://www.torchmobile.com/) |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 documentStyle->setOverflowX(EOverflow::Auto); | 572 documentStyle->setOverflowX(EOverflow::Auto); |
573 documentStyle->setOverflowY(EOverflow::Auto); | 573 documentStyle->setOverflowY(EOverflow::Auto); |
574 | 574 |
575 document.setupFontBuilder(*documentStyle); | 575 document.setupFontBuilder(*documentStyle); |
576 | 576 |
577 return documentStyle.release(); | 577 return documentStyle.release(); |
578 } | 578 } |
579 | 579 |
580 void StyleResolver::adjustComputedStyle(StyleResolverState& state, | 580 void StyleResolver::adjustComputedStyle(StyleResolverState& state, |
581 Element* element) { | 581 Element* element) { |
582 DCHECK(state.layoutParentStyle()); | |
583 DCHECK(state.parentStyle()); | |
582 StyleAdjuster::adjustComputedStyle(state.mutableStyleRef(), | 584 StyleAdjuster::adjustComputedStyle(state.mutableStyleRef(), |
583 *state.parentStyle(), element); | 585 *state.parentStyle(), |
586 *state.layoutParentStyle(), element); | |
584 } | 587 } |
585 | 588 |
586 // Start loading resources referenced by this style. | 589 // Start loading resources referenced by this style. |
587 void StyleResolver::loadPendingResources(StyleResolverState& state) { | 590 void StyleResolver::loadPendingResources(StyleResolverState& state) { |
588 state.elementStyleResources().loadPendingResources(state.style()); | 591 state.elementStyleResources().loadPendingResources(state.style()); |
589 } | 592 } |
590 | 593 |
591 static const ComputedStyle* calculateBaseComputedStyle( | 594 static const ComputedStyle* calculateBaseComputedStyle( |
592 StyleResolverState& state, | 595 StyleResolverState& state, |
593 const Element* animatingElement) { | 596 const Element* animatingElement) { |
(...skipping 21 matching lines...) Expand all Loading... | |
615 return; | 618 return; |
616 | 619 |
617 ElementAnimations* elementAnimations = animatingElement->elementAnimations(); | 620 ElementAnimations* elementAnimations = animatingElement->elementAnimations(); |
618 if (elementAnimations) | 621 if (elementAnimations) |
619 elementAnimations->updateBaseComputedStyle(state.style()); | 622 elementAnimations->updateBaseComputedStyle(state.style()); |
620 } | 623 } |
621 | 624 |
622 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( | 625 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( |
623 Element* element, | 626 Element* element, |
624 const ComputedStyle* defaultParent, | 627 const ComputedStyle* defaultParent, |
628 const ComputedStyle* defaultLayoutParent, | |
625 StyleSharingBehavior sharingBehavior, | 629 StyleSharingBehavior sharingBehavior, |
626 RuleMatchingBehavior matchingBehavior) { | 630 RuleMatchingBehavior matchingBehavior) { |
627 DCHECK(document().frame()); | 631 DCHECK(document().frame()); |
628 DCHECK(document().settings()); | 632 DCHECK(document().settings()); |
629 | 633 |
630 // Once an element has a layoutObject, we don't try to destroy it, since | 634 // Once an element has a layoutObject, we don't try to destroy it, since |
631 // otherwise the layoutObject will vanish if a style recalc happens during | 635 // otherwise the layoutObject will vanish if a style recalc happens during |
632 // loading. | 636 // loading. |
633 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() && | 637 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() && |
634 !element->layoutObject()) { | 638 !element->layoutObject()) { |
(...skipping 16 matching lines...) Expand all Loading... | |
651 ElementResolveContext elementContext(*element); | 655 ElementResolveContext elementContext(*element); |
652 | 656 |
653 if (RuntimeEnabledFeatures::styleSharingEnabled() && | 657 if (RuntimeEnabledFeatures::styleSharingEnabled() && |
654 sharingBehavior == AllowStyleSharing && | 658 sharingBehavior == AllowStyleSharing && |
655 (defaultParent || elementContext.parentStyle())) { | 659 (defaultParent || elementContext.parentStyle())) { |
656 if (RefPtr<ComputedStyle> sharedStyle = | 660 if (RefPtr<ComputedStyle> sharedStyle = |
657 document().styleEngine().findSharedStyle(elementContext)) | 661 document().styleEngine().findSharedStyle(elementContext)) |
658 return sharedStyle.release(); | 662 return sharedStyle.release(); |
659 } | 663 } |
660 | 664 |
661 StyleResolverState state(document(), elementContext, defaultParent); | 665 StyleResolverState state(document(), elementContext, defaultParent, |
666 defaultLayoutParent); | |
662 | 667 |
663 const ComputedStyle* baseComputedStyle = | 668 const ComputedStyle* baseComputedStyle = |
664 calculateBaseComputedStyle(state, element); | 669 calculateBaseComputedStyle(state, element); |
665 | 670 |
666 if (baseComputedStyle) { | 671 if (baseComputedStyle) { |
667 state.setStyle(ComputedStyle::clone(*baseComputedStyle)); | 672 state.setStyle(ComputedStyle::clone(*baseComputedStyle)); |
668 if (!state.parentStyle()) | 673 if (!state.parentStyle()) { |
669 state.setParentStyle(initialStyleForElement()); | 674 state.setParentStyle(initialStyleForElement()); |
675 state.setLayoutParentStyle(state.parentStyle()); | |
676 } | |
670 } else { | 677 } else { |
671 if (state.parentStyle()) { | 678 if (state.parentStyle()) { |
672 RefPtr<ComputedStyle> style = ComputedStyle::create(); | 679 RefPtr<ComputedStyle> style = ComputedStyle::create(); |
673 style->inheritFrom(*state.parentStyle(), | 680 style->inheritFrom(*state.parentStyle(), |
674 isAtShadowBoundary(element) | 681 isAtShadowBoundary(element) |
675 ? ComputedStyleBase::AtShadowBoundary | 682 ? ComputedStyleBase::AtShadowBoundary |
676 : ComputedStyleBase::NotAtShadowBoundary); | 683 : ComputedStyleBase::NotAtShadowBoundary); |
677 state.setStyle(std::move(style)); | 684 state.setStyle(std::move(style)); |
678 } else { | 685 } else { |
679 state.setStyle(initialStyleForElement()); | 686 state.setStyle(initialStyleForElement()); |
680 state.setParentStyle(ComputedStyle::clone(*state.style())); | 687 state.setParentStyle(ComputedStyle::clone(*state.style())); |
688 state.setLayoutParentStyle(state.parentStyle()); | |
681 } | 689 } |
682 } | 690 } |
683 | 691 |
684 // contenteditable attribute (implemented by -webkit-user-modify) should | 692 // contenteditable attribute (implemented by -webkit-user-modify) should |
685 // be propagated from shadow host to distributed node. | 693 // be propagated from shadow host to distributed node. |
686 if (state.distributedToInsertionPoint()) { | 694 if (state.distributedToInsertionPoint()) { |
687 if (Element* parent = element->parentElement()) { | 695 if (Element* parent = element->parentElement()) { |
688 if (ComputedStyle* styleOfShadowHost = parent->mutableComputedStyle()) | 696 if (ComputedStyle* styleOfShadowHost = parent->mutableComputedStyle()) |
689 state.style()->setUserModify(styleOfShadowHost->userModify()); | 697 state.style()->setUserModify(styleOfShadowHost->userModify()); |
690 } | 698 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 // TODO(alancutter): Create compositor keyframe values directly instead of | 793 // TODO(alancutter): Create compositor keyframe values directly instead of |
786 // intermediate AnimatableValues. | 794 // intermediate AnimatableValues. |
787 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot( | 795 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot( |
788 Element& element, | 796 Element& element, |
789 const ComputedStyle& baseStyle, | 797 const ComputedStyle& baseStyle, |
790 const ComputedStyle* parentStyle, | 798 const ComputedStyle* parentStyle, |
791 CSSPropertyID property, | 799 CSSPropertyID property, |
792 const CSSValue* value) { | 800 const CSSValue* value) { |
793 // TODO(alancutter): Avoid creating a StyleResolverState just to apply a | 801 // TODO(alancutter): Avoid creating a StyleResolverState just to apply a |
794 // single value on a ComputedStyle. | 802 // single value on a ComputedStyle. |
795 StyleResolverState state(element.document(), &element, parentStyle); | 803 StyleResolverState state(element.document(), &element, parentStyle, |
804 parentStyle); | |
rune
2017/01/27 13:09:23
Is it correct to use parentStyle both places here?
emilio
2017/01/27 22:13:15
We only use it to apply a given property as far as
rune
2017/02/06 22:40:43
Right, these are for compositor animations which d
| |
796 state.setStyle(ComputedStyle::clone(baseStyle)); | 805 state.setStyle(ComputedStyle::clone(baseStyle)); |
797 if (value) { | 806 if (value) { |
798 StyleBuilder::applyProperty(property, state, *value); | 807 StyleBuilder::applyProperty(property, state, *value); |
799 state.fontBuilder().createFont( | 808 state.fontBuilder().createFont( |
800 state.document().styleEngine().fontSelector(), state.mutableStyleRef()); | 809 state.document().styleEngine().fontSelector(), state.mutableStyleRef()); |
801 } | 810 } |
802 return CSSAnimatableValueFactory::create(property, *state.style()); | 811 return CSSAnimatableValueFactory::create(property, *state.style()); |
803 } | 812 } |
804 | 813 |
805 PseudoElement* StyleResolver::createPseudoElement(Element* parent, | 814 PseudoElement* StyleResolver::createPseudoElement(Element* parent, |
(...skipping 27 matching lines...) Expand all Loading... | |
833 return nullptr; | 842 return nullptr; |
834 | 843 |
835 ComputedStyle* parentStyle = parentLayoutObject->mutableStyle(); | 844 ComputedStyle* parentStyle = parentLayoutObject->mutableStyle(); |
836 if (ComputedStyle* cachedStyle = | 845 if (ComputedStyle* cachedStyle = |
837 parentStyle->getCachedPseudoStyle(pseudoId)) { | 846 parentStyle->getCachedPseudoStyle(pseudoId)) { |
838 if (!pseudoElementLayoutObjectIsNeeded(cachedStyle)) | 847 if (!pseudoElementLayoutObjectIsNeeded(cachedStyle)) |
839 return nullptr; | 848 return nullptr; |
840 return createPseudoElement(&parent, pseudoId); | 849 return createPseudoElement(&parent, pseudoId); |
841 } | 850 } |
842 | 851 |
843 StyleResolverState state(document(), &parent, parentStyle); | 852 StyleResolverState state(document(), &parent, parentStyle, parentStyle); |
844 if (!pseudoStyleForElementInternal(parent, pseudoId, parentStyle, state)) | 853 if (!pseudoStyleForElementInternal(parent, pseudoId, parentStyle, state)) |
845 return nullptr; | 854 return nullptr; |
846 RefPtr<ComputedStyle> style = state.takeStyle(); | 855 RefPtr<ComputedStyle> style = state.takeStyle(); |
847 DCHECK(style); | 856 DCHECK(style); |
848 parentStyle->addCachedPseudoStyle(style); | 857 parentStyle->addCachedPseudoStyle(style); |
849 | 858 |
850 if (!pseudoElementLayoutObjectIsNeeded(style.get())) | 859 if (!pseudoElementLayoutObjectIsNeeded(style.get())) |
851 return nullptr; | 860 return nullptr; |
852 | 861 |
853 PseudoElement* pseudo = createPseudoElement(&parent, pseudoId); | 862 PseudoElement* pseudo = createPseudoElement(&parent, pseudoId); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 | 943 |
935 if (state.style()->hasViewportUnits()) | 944 if (state.style()->hasViewportUnits()) |
936 document().setHasViewportUnits(); | 945 document().setHasViewportUnits(); |
937 | 946 |
938 return true; | 947 return true; |
939 } | 948 } |
940 | 949 |
941 PassRefPtr<ComputedStyle> StyleResolver::pseudoStyleForElement( | 950 PassRefPtr<ComputedStyle> StyleResolver::pseudoStyleForElement( |
942 Element* element, | 951 Element* element, |
943 const PseudoStyleRequest& pseudoStyleRequest, | 952 const PseudoStyleRequest& pseudoStyleRequest, |
944 const ComputedStyle* parentStyle) { | 953 const ComputedStyle* parentStyle, |
954 const ComputedStyle* parentLayoutObjectStyle) { | |
945 DCHECK(parentStyle); | 955 DCHECK(parentStyle); |
946 if (!element) | 956 if (!element) |
947 return nullptr; | 957 return nullptr; |
948 | 958 |
949 StyleResolverState state(document(), element, parentStyle); | 959 StyleResolverState state(document(), element, parentStyle, |
960 parentLayoutObjectStyle); | |
950 if (!pseudoStyleForElementInternal(*element, pseudoStyleRequest, parentStyle, | 961 if (!pseudoStyleForElementInternal(*element, pseudoStyleRequest, parentStyle, |
951 state)) { | 962 state)) { |
952 if (pseudoStyleRequest.type == PseudoStyleRequest::ForRenderer) | 963 if (pseudoStyleRequest.type == PseudoStyleRequest::ForRenderer) |
953 return nullptr; | 964 return nullptr; |
954 return state.takeStyle(); | 965 return state.takeStyle(); |
955 } | 966 } |
956 | 967 |
957 if (PseudoElement* pseudoElement = | 968 if (PseudoElement* pseudoElement = |
958 element->pseudoElement(pseudoStyleRequest.pseudoId)) | 969 element->pseudoElement(pseudoStyleRequest.pseudoId)) |
959 setAnimationUpdateIfNeeded(state, *pseudoElement); | 970 setAnimationUpdateIfNeeded(state, *pseudoElement); |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1905 | 1916 |
1906 void StyleResolver::computeFont(ComputedStyle* style, | 1917 void StyleResolver::computeFont(ComputedStyle* style, |
1907 const StylePropertySet& propertySet) { | 1918 const StylePropertySet& propertySet) { |
1908 CSSPropertyID properties[] = { | 1919 CSSPropertyID properties[] = { |
1909 CSSPropertyFontSize, CSSPropertyFontFamily, CSSPropertyFontStretch, | 1920 CSSPropertyFontSize, CSSPropertyFontFamily, CSSPropertyFontStretch, |
1910 CSSPropertyFontStyle, CSSPropertyFontVariantCaps, CSSPropertyFontWeight, | 1921 CSSPropertyFontStyle, CSSPropertyFontVariantCaps, CSSPropertyFontWeight, |
1911 CSSPropertyLineHeight, | 1922 CSSPropertyLineHeight, |
1912 }; | 1923 }; |
1913 | 1924 |
1914 // TODO(timloh): This is weird, the style is being used as its own parent | 1925 // TODO(timloh): This is weird, the style is being used as its own parent |
1915 StyleResolverState state(document(), nullptr, style); | 1926 StyleResolverState state(document(), nullptr, style, style); |
1916 state.setStyle(style); | 1927 state.setStyle(style); |
1917 | 1928 |
1918 for (CSSPropertyID property : properties) { | 1929 for (CSSPropertyID property : properties) { |
1919 if (property == CSSPropertyLineHeight) | 1930 if (property == CSSPropertyLineHeight) |
1920 updateFont(state); | 1931 updateFont(state); |
1921 StyleBuilder::applyProperty(property, state, | 1932 StyleBuilder::applyProperty(property, state, |
1922 *propertySet.getPropertyCSSValue(property)); | 1933 *propertySet.getPropertyCSSValue(property)); |
1923 } | 1934 } |
1924 } | 1935 } |
1925 | 1936 |
1926 void StyleResolver::updateMediaType() { | 1937 void StyleResolver::updateMediaType() { |
1927 if (FrameView* view = document().view()) { | 1938 if (FrameView* view = document().view()) { |
1928 bool wasPrint = m_printMediaType; | 1939 bool wasPrint = m_printMediaType; |
1929 m_printMediaType = | 1940 m_printMediaType = |
1930 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); | 1941 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); |
1931 if (wasPrint != m_printMediaType) | 1942 if (wasPrint != m_printMediaType) |
1932 m_matchedPropertiesCache.clearViewportDependent(); | 1943 m_matchedPropertiesCache.clearViewportDependent(); |
1933 } | 1944 } |
1934 } | 1945 } |
1935 | 1946 |
1936 DEFINE_TRACE(StyleResolver) { | 1947 DEFINE_TRACE(StyleResolver) { |
1937 visitor->trace(m_matchedPropertiesCache); | 1948 visitor->trace(m_matchedPropertiesCache); |
1938 visitor->trace(m_selectorFilter); | 1949 visitor->trace(m_selectorFilter); |
1939 visitor->trace(m_styleSharingLists); | 1950 visitor->trace(m_styleSharingLists); |
1940 visitor->trace(m_document); | 1951 visitor->trace(m_document); |
1941 visitor->trace(m_tracker); | 1952 visitor->trace(m_tracker); |
1942 } | 1953 } |
1943 | 1954 |
1944 } // namespace blink | 1955 } // namespace blink |
OLD | NEW |