Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp

Issue 2450093005: Support display: contents for elements, first-line and first-letter pseudos. (Closed)
Patch Set: Allow text as child of the LayoutView, since it can happen with display: contents Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 documentStyle->setDisplay(EDisplay::Block); 621 documentStyle->setDisplay(EDisplay::Block);
622 documentStyle->setPosition(AbsolutePosition); 622 documentStyle->setPosition(AbsolutePosition);
623 623
624 document.setupFontBuilder(*documentStyle); 624 document.setupFontBuilder(*documentStyle);
625 625
626 return documentStyle.release(); 626 return documentStyle.release();
627 } 627 }
628 628
629 void StyleResolver::adjustComputedStyle(StyleResolverState& state, 629 void StyleResolver::adjustComputedStyle(StyleResolverState& state,
630 Element* element) { 630 Element* element) {
631 DCHECK(state.layoutParentStyle());
632 DCHECK(state.parentStyle());
631 StyleAdjuster::adjustComputedStyle(state.mutableStyleRef(), 633 StyleAdjuster::adjustComputedStyle(state.mutableStyleRef(),
632 *state.parentStyle(), element); 634 *state.parentStyle(),
635 *state.layoutParentStyle(), element);
633 } 636 }
634 637
635 // Start loading resources referenced by this style. 638 // Start loading resources referenced by this style.
636 void StyleResolver::loadPendingResources(StyleResolverState& state) { 639 void StyleResolver::loadPendingResources(StyleResolverState& state) {
637 state.elementStyleResources().loadPendingResources(state.style()); 640 state.elementStyleResources().loadPendingResources(state.style());
638 } 641 }
639 642
640 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( 643 PassRefPtr<ComputedStyle> StyleResolver::styleForElement(
641 Element* element, 644 Element* element,
642 const ComputedStyle* defaultParent, 645 const ComputedStyle* defaultParent,
646 const ComputedStyle* defaultLayoutParent,
643 StyleSharingBehavior sharingBehavior, 647 StyleSharingBehavior sharingBehavior,
644 RuleMatchingBehavior matchingBehavior) { 648 RuleMatchingBehavior matchingBehavior) {
645 DCHECK(document().frame()); 649 DCHECK(document().frame());
646 DCHECK(document().settings()); 650 DCHECK(document().settings());
647 DCHECK(!hasPendingAuthorStyleSheets()); 651 DCHECK(!hasPendingAuthorStyleSheets());
648 652
649 // Once an element has a layoutObject, we don't try to destroy it, since 653 // Once an element has a layoutObject, we don't try to destroy it, since
650 // otherwise the layoutObject will vanish if a style recalc happens during 654 // otherwise the layoutObject will vanish if a style recalc happens during
651 // loading. 655 // loading.
652 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() && 656 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() &&
(...skipping 17 matching lines...) Expand all
670 ElementResolveContext elementContext(*element); 674 ElementResolveContext elementContext(*element);
671 675
672 if (RuntimeEnabledFeatures::styleSharingEnabled() && 676 if (RuntimeEnabledFeatures::styleSharingEnabled() &&
673 sharingBehavior == AllowStyleSharing && 677 sharingBehavior == AllowStyleSharing &&
674 (defaultParent || elementContext.parentStyle())) { 678 (defaultParent || elementContext.parentStyle())) {
675 if (RefPtr<ComputedStyle> sharedStyle = 679 if (RefPtr<ComputedStyle> sharedStyle =
676 document().styleEngine().findSharedStyle(elementContext)) 680 document().styleEngine().findSharedStyle(elementContext))
677 return sharedStyle.release(); 681 return sharedStyle.release();
678 } 682 }
679 683
680 StyleResolverState state(document(), elementContext, defaultParent); 684 StyleResolverState state(document(), elementContext, defaultParent,
685 defaultLayoutParent);
681 686
682 ElementAnimations* elementAnimations = element->elementAnimations(); 687 ElementAnimations* elementAnimations = element->elementAnimations();
683 const ComputedStyle* baseComputedStyle = 688 const ComputedStyle* baseComputedStyle =
684 elementAnimations ? elementAnimations->baseComputedStyle() : nullptr; 689 elementAnimations ? elementAnimations->baseComputedStyle() : nullptr;
685 690
686 if (baseComputedStyle) { 691 if (baseComputedStyle) {
687 state.setStyle(ComputedStyle::clone(*baseComputedStyle)); 692 state.setStyle(ComputedStyle::clone(*baseComputedStyle));
688 if (!state.parentStyle()) 693 if (!state.parentStyle()) {
689 state.setParentStyle(initialStyleForElement()); 694 state.setParentStyle(initialStyleForElement());
695 state.setLayoutParentStyle(state.parentStyle());
696 }
690 } else { 697 } else {
691 if (state.parentStyle()) { 698 if (state.parentStyle()) {
692 RefPtr<ComputedStyle> style = ComputedStyle::create(); 699 RefPtr<ComputedStyle> style = ComputedStyle::create();
693 style->inheritFrom(*state.parentStyle(), 700 style->inheritFrom(*state.parentStyle(),
694 isAtShadowBoundary(element) 701 isAtShadowBoundary(element)
695 ? ComputedStyleBase::AtShadowBoundary 702 ? ComputedStyleBase::AtShadowBoundary
696 : ComputedStyleBase::NotAtShadowBoundary); 703 : ComputedStyleBase::NotAtShadowBoundary);
697 state.setStyle(style.release()); 704 state.setStyle(style.release());
698 } else { 705 } else {
699 state.setStyle(initialStyleForElement()); 706 state.setStyle(initialStyleForElement());
700 state.setParentStyle(ComputedStyle::clone(*state.style())); 707 state.setParentStyle(ComputedStyle::clone(*state.style()));
708 state.setLayoutParentStyle(state.parentStyle());
701 } 709 }
702 } 710 }
703 711
704 // contenteditable attribute (implemented by -webkit-user-modify) should 712 // contenteditable attribute (implemented by -webkit-user-modify) should
705 // be propagated from shadow host to distributed node. 713 // be propagated from shadow host to distributed node.
706 if (state.distributedToInsertionPoint()) { 714 if (state.distributedToInsertionPoint()) {
707 if (Element* parent = element->parentElement()) { 715 if (Element* parent = element->parentElement()) {
708 if (ComputedStyle* styleOfShadowHost = parent->mutableComputedStyle()) 716 if (ComputedStyle* styleOfShadowHost = parent->mutableComputedStyle())
709 state.style()->setUserModify(styleOfShadowHost->userModify()); 717 state.style()->setUserModify(styleOfShadowHost->userModify());
710 } 718 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 // TODO(alancutter): Create compositor keyframe values directly instead of 813 // TODO(alancutter): Create compositor keyframe values directly instead of
806 // intermediate AnimatableValues. 814 // intermediate AnimatableValues.
807 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot( 815 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(
808 Element& element, 816 Element& element,
809 const ComputedStyle& baseStyle, 817 const ComputedStyle& baseStyle,
810 const ComputedStyle* parentStyle, 818 const ComputedStyle* parentStyle,
811 CSSPropertyID property, 819 CSSPropertyID property,
812 const CSSValue* value) { 820 const CSSValue* value) {
813 // TODO(alancutter): Avoid creating a StyleResolverState just to apply a 821 // TODO(alancutter): Avoid creating a StyleResolverState just to apply a
814 // single value on a ComputedStyle. 822 // single value on a ComputedStyle.
815 StyleResolverState state(element.document(), &element, parentStyle); 823 StyleResolverState state(element.document(), &element, parentStyle,
824 parentStyle);
816 state.setStyle(ComputedStyle::clone(baseStyle)); 825 state.setStyle(ComputedStyle::clone(baseStyle));
817 if (value) { 826 if (value) {
818 StyleBuilder::applyProperty(property, state, *value); 827 StyleBuilder::applyProperty(property, state, *value);
819 state.fontBuilder().createFont( 828 state.fontBuilder().createFont(
820 state.document().styleEngine().fontSelector(), state.mutableStyleRef()); 829 state.document().styleEngine().fontSelector(), state.mutableStyleRef());
821 } 830 }
822 return CSSAnimatableValueFactory::create(property, *state.style()); 831 return CSSAnimatableValueFactory::create(property, *state.style());
823 } 832 }
824 833
825 PseudoElement* StyleResolver::createPseudoElement(Element* parent, 834 PseudoElement* StyleResolver::createPseudoElement(Element* parent,
(...skipping 27 matching lines...) Expand all
853 return nullptr; 862 return nullptr;
854 863
855 ComputedStyle* parentStyle = parentLayoutObject->mutableStyle(); 864 ComputedStyle* parentStyle = parentLayoutObject->mutableStyle();
856 if (ComputedStyle* cachedStyle = 865 if (ComputedStyle* cachedStyle =
857 parentStyle->getCachedPseudoStyle(pseudoId)) { 866 parentStyle->getCachedPseudoStyle(pseudoId)) {
858 if (!pseudoElementLayoutObjectIsNeeded(cachedStyle)) 867 if (!pseudoElementLayoutObjectIsNeeded(cachedStyle))
859 return nullptr; 868 return nullptr;
860 return createPseudoElement(&parent, pseudoId); 869 return createPseudoElement(&parent, pseudoId);
861 } 870 }
862 871
863 StyleResolverState state(document(), &parent, parentStyle); 872 StyleResolverState state(document(), &parent, parentStyle, parentStyle);
864 if (!pseudoStyleForElementInternal(parent, pseudoId, parentStyle, state)) 873 if (!pseudoStyleForElementInternal(parent, pseudoId, parentStyle, state))
865 return nullptr; 874 return nullptr;
866 RefPtr<ComputedStyle> style = state.takeStyle(); 875 RefPtr<ComputedStyle> style = state.takeStyle();
867 DCHECK(style); 876 DCHECK(style);
868 parentStyle->addCachedPseudoStyle(style); 877 parentStyle->addCachedPseudoStyle(style);
869 878
870 if (!pseudoElementLayoutObjectIsNeeded(style.get())) 879 if (!pseudoElementLayoutObjectIsNeeded(style.get()))
871 return nullptr; 880 return nullptr;
872 881
873 PseudoElement* pseudo = createPseudoElement(&parent, pseudoId); 882 PseudoElement* pseudo = createPseudoElement(&parent, pseudoId);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 965
957 if (state.style()->hasViewportUnits()) 966 if (state.style()->hasViewportUnits())
958 document().setHasViewportUnits(); 967 document().setHasViewportUnits();
959 968
960 return true; 969 return true;
961 } 970 }
962 971
963 PassRefPtr<ComputedStyle> StyleResolver::pseudoStyleForElement( 972 PassRefPtr<ComputedStyle> StyleResolver::pseudoStyleForElement(
964 Element* element, 973 Element* element,
965 const PseudoStyleRequest& pseudoStyleRequest, 974 const PseudoStyleRequest& pseudoStyleRequest,
966 const ComputedStyle* parentStyle) { 975 const ComputedStyle* parentStyle,
976 const ComputedStyle* parentLayoutObjectStyle) {
967 DCHECK(parentStyle); 977 DCHECK(parentStyle);
968 if (!element) 978 if (!element)
969 return nullptr; 979 return nullptr;
970 980
971 StyleResolverState state(document(), element, parentStyle); 981 StyleResolverState state(document(), element, parentStyle,
982 parentLayoutObjectStyle);
972 if (!pseudoStyleForElementInternal(*element, pseudoStyleRequest, parentStyle, 983 if (!pseudoStyleForElementInternal(*element, pseudoStyleRequest, parentStyle,
973 state)) { 984 state)) {
974 if (pseudoStyleRequest.type == PseudoStyleRequest::ForRenderer) 985 if (pseudoStyleRequest.type == PseudoStyleRequest::ForRenderer)
975 return nullptr; 986 return nullptr;
976 return state.takeStyle(); 987 return state.takeStyle();
977 } 988 }
978 989
979 if (PseudoElement* pseudoElement = 990 if (PseudoElement* pseudoElement =
980 element->pseudoElement(pseudoStyleRequest.pseudoId)) 991 element->pseudoElement(pseudoStyleRequest.pseudoId))
981 setAnimationUpdateIfNeeded(state, *pseudoElement); 992 setAnimationUpdateIfNeeded(state, *pseudoElement);
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 1828
1818 void StyleResolver::computeFont(ComputedStyle* style, 1829 void StyleResolver::computeFont(ComputedStyle* style,
1819 const StylePropertySet& propertySet) { 1830 const StylePropertySet& propertySet) {
1820 CSSPropertyID properties[] = { 1831 CSSPropertyID properties[] = {
1821 CSSPropertyFontSize, CSSPropertyFontFamily, CSSPropertyFontStretch, 1832 CSSPropertyFontSize, CSSPropertyFontFamily, CSSPropertyFontStretch,
1822 CSSPropertyFontStyle, CSSPropertyFontVariantCaps, CSSPropertyFontWeight, 1833 CSSPropertyFontStyle, CSSPropertyFontVariantCaps, CSSPropertyFontWeight,
1823 CSSPropertyLineHeight, 1834 CSSPropertyLineHeight,
1824 }; 1835 };
1825 1836
1826 // TODO(timloh): This is weird, the style is being used as its own parent 1837 // TODO(timloh): This is weird, the style is being used as its own parent
1827 StyleResolverState state(document(), nullptr, style); 1838 StyleResolverState state(document(), nullptr, style, style);
1828 state.setStyle(style); 1839 state.setStyle(style);
1829 1840
1830 for (CSSPropertyID property : properties) { 1841 for (CSSPropertyID property : properties) {
1831 if (property == CSSPropertyLineHeight) 1842 if (property == CSSPropertyLineHeight)
1832 updateFont(state); 1843 updateFont(state);
1833 StyleBuilder::applyProperty(property, state, 1844 StyleBuilder::applyProperty(property, state,
1834 *propertySet.getPropertyCSSValue(property)); 1845 *propertySet.getPropertyCSSValue(property));
1835 } 1846 }
1836 } 1847 }
1837 1848
1838 void StyleResolver::updateMediaType() { 1849 void StyleResolver::updateMediaType() {
1839 if (FrameView* view = document().view()) { 1850 if (FrameView* view = document().view()) {
1840 m_printMediaType = 1851 m_printMediaType =
1841 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); 1852 equalIgnoringCase(view->mediaType(), MediaTypeNames::print);
1842 } 1853 }
1843 } 1854 }
1844 1855
1845 DEFINE_TRACE(StyleResolver) { 1856 DEFINE_TRACE(StyleResolver) {
1846 visitor->trace(m_matchedPropertiesCache); 1857 visitor->trace(m_matchedPropertiesCache);
1847 visitor->trace(m_selectorFilter); 1858 visitor->trace(m_selectorFilter);
1848 visitor->trace(m_styleSharingLists); 1859 visitor->trace(m_styleSharingLists);
1849 visitor->trace(m_pendingStyleSheets); 1860 visitor->trace(m_pendingStyleSheets);
1850 visitor->trace(m_document); 1861 visitor->trace(m_document);
1851 visitor->trace(m_tracker); 1862 visitor->trace(m_tracker);
1852 } 1863 }
1853 1864
1854 } // namespace blink 1865 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698