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