Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
| 5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 6 * (C) 2007 David Smith (catfish.man@gmail.com) | 6 * (C) 2007 David Smith (catfish.man@gmail.com) |
| 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. |
| 8 * All rights reserved. | 8 * All rights reserved. |
| 9 * (C) 2007 Eric Seidel (eric@webkit.org) | 9 * (C) 2007 Eric Seidel (eric@webkit.org) |
| 10 * | 10 * |
| (...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1522 return parent->locateNamespacePrefix(namespaceToLocate); | 1522 return parent->locateNamespacePrefix(namespaceToLocate); |
| 1523 | 1523 |
| 1524 return nullAtom; | 1524 return nullAtom; |
| 1525 } | 1525 } |
| 1526 | 1526 |
| 1527 const AtomicString Element::imageSourceURL() const { | 1527 const AtomicString Element::imageSourceURL() const { |
| 1528 return getAttribute(srcAttr); | 1528 return getAttribute(srcAttr); |
| 1529 } | 1529 } |
| 1530 | 1530 |
| 1531 bool Element::layoutObjectIsNeeded(const ComputedStyle& style) { | 1531 bool Element::layoutObjectIsNeeded(const ComputedStyle& style) { |
| 1532 return style.display() != EDisplay::None; | 1532 return style.display() != EDisplay::None && |
| 1533 style.display() != EDisplay::Contents; | |
| 1533 } | 1534 } |
| 1534 | 1535 |
| 1535 LayoutObject* Element::createLayoutObject(const ComputedStyle& style) { | 1536 LayoutObject* Element::createLayoutObject(const ComputedStyle& style) { |
| 1536 return LayoutObject::createObject(this, style); | 1537 return LayoutObject::createObject(this, style); |
| 1537 } | 1538 } |
| 1538 | 1539 |
| 1539 Node::InsertionNotificationRequest Element::insertedInto( | 1540 Node::InsertionNotificationRequest Element::insertedInto( |
| 1540 ContainerNode* insertionPoint) { | 1541 ContainerNode* insertionPoint) { |
| 1541 // need to do superclass processing first so isConnected() is true | 1542 // need to do superclass processing first so isConnected() is true |
| 1542 // by the time we reach updateId | 1543 // by the time we reach updateId |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1660 void Element::attachLayoutTree(const AttachContext& context) { | 1661 void Element::attachLayoutTree(const AttachContext& context) { |
| 1661 DCHECK(document().inStyleRecalc()); | 1662 DCHECK(document().inStyleRecalc()); |
| 1662 | 1663 |
| 1663 // We've already been through detach when doing an attach, but we might | 1664 // We've already been through detach when doing an attach, but we might |
| 1664 // need to clear any state that's been added since then. | 1665 // need to clear any state that's been added since then. |
| 1665 if (hasRareData() && getStyleChangeType() == NeedsReattachStyleChange) { | 1666 if (hasRareData() && getStyleChangeType() == NeedsReattachStyleChange) { |
| 1666 ElementRareData* data = elementRareData(); | 1667 ElementRareData* data = elementRareData(); |
| 1667 data->clearComputedStyle(); | 1668 data->clearComputedStyle(); |
| 1668 } | 1669 } |
| 1669 | 1670 |
| 1670 if (!isActiveSlotOrActiveInsertionPoint()) | 1671 if (!isActiveSlotOrActiveInsertionPoint()) { |
| 1671 LayoutTreeBuilderForElement(*this, context.resolvedStyle) | 1672 LayoutTreeBuilderForElement builder(*this, context.resolvedStyle); |
| 1672 .createLayoutObjectIfNeeded(); | 1673 builder.createLayoutObjectIfNeeded(); |
| 1674 | |
| 1675 if (ComputedStyle* style = builder.resolvedStyle()) { | |
| 1676 if (!layoutObject() && shouldStoreNonLayoutObjectComputedStyle(*style)) | |
| 1677 storeNonLayoutObjectComputedStyle(style); | |
| 1678 } | |
| 1679 } | |
| 1673 | 1680 |
| 1674 addCallbackSelectors(); | 1681 addCallbackSelectors(); |
| 1675 | 1682 |
| 1676 if (hasRareData() && !layoutObject()) { | 1683 if (hasRareData() && !layoutObject()) { |
| 1677 if (ElementAnimations* elementAnimations = | 1684 if (ElementAnimations* elementAnimations = |
| 1678 elementRareData()->elementAnimations()) { | 1685 elementRareData()->elementAnimations()) { |
| 1679 elementAnimations->cssAnimations().cancel(); | 1686 elementAnimations->cssAnimations().cancel(); |
| 1680 elementAnimations->setAnimationStyleChange(false); | 1687 elementAnimations->setAnimationStyleChange(false); |
| 1681 } | 1688 } |
| 1682 } | 1689 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1839 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); | 1846 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); |
| 1840 DCHECK(inActiveDocument()); | 1847 DCHECK(inActiveDocument()); |
| 1841 | 1848 |
| 1842 if (hasCustomStyleCallbacks()) | 1849 if (hasCustomStyleCallbacks()) |
| 1843 willRecalcStyle(change); | 1850 willRecalcStyle(change); |
| 1844 | 1851 |
| 1845 if (change >= IndependentInherit || needsStyleRecalc()) { | 1852 if (change >= IndependentInherit || needsStyleRecalc()) { |
| 1846 if (hasRareData()) { | 1853 if (hasRareData()) { |
| 1847 ElementRareData* data = elementRareData(); | 1854 ElementRareData* data = elementRareData(); |
| 1848 if (change != IndependentInherit) | 1855 if (change != IndependentInherit) |
| 1849 data->clearComputedStyle(); | 1856 data->clearComputedStyle(); |
|
rune
2016/12/01 15:28:53
Don't you need to avoid doing this before recalcOw
emilio
2016/12/01 17:32:56
Hmm, right, otherwise we can end up recomputing to
| |
| 1850 | 1857 |
| 1851 if (change >= IndependentInherit) { | 1858 if (change >= IndependentInherit) { |
| 1852 if (ElementAnimations* elementAnimations = data->elementAnimations()) | 1859 if (ElementAnimations* elementAnimations = data->elementAnimations()) |
| 1853 elementAnimations->setAnimationStyleChange(false); | 1860 elementAnimations->setAnimationStyleChange(false); |
| 1854 } | 1861 } |
| 1855 } | 1862 } |
| 1856 if (parentComputedStyle()) | 1863 if (parentComputedStyle()) |
| 1857 change = recalcOwnStyle(change, nextTextSibling); | 1864 change = recalcOwnStyle(change, nextTextSibling); |
| 1858 clearNeedsStyleRecalc(); | 1865 clearNeedsStyleRecalc(); |
| 1859 clearNeedsReattachLayoutTree(); | 1866 clearNeedsReattachLayoutTree(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1961 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { | 1968 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { |
| 1962 layoutObject->setStyle(newStyle.get()); | 1969 layoutObject->setStyle(newStyle.get()); |
| 1963 } else { | 1970 } else { |
| 1964 // Although no change occurred, we use the new style so that the cousin | 1971 // Although no change occurred, we use the new style so that the cousin |
| 1965 // style sharing code won't get fooled into believing this style is the | 1972 // style sharing code won't get fooled into believing this style is the |
| 1966 // same. | 1973 // same. |
| 1967 // FIXME: We may be able to remove this hack, see discussion in | 1974 // FIXME: We may be able to remove this hack, see discussion in |
| 1968 // https://codereview.chromium.org/30453002/ | 1975 // https://codereview.chromium.org/30453002/ |
| 1969 layoutObject->setStyleInternal(newStyle.get()); | 1976 layoutObject->setStyleInternal(newStyle.get()); |
| 1970 } | 1977 } |
| 1978 } else if (localChange != NoChange && | |
| 1979 shouldStoreNonLayoutObjectComputedStyle(*newStyle)) { | |
| 1980 storeNonLayoutObjectComputedStyle(newStyle); | |
| 1971 } | 1981 } |
| 1972 | 1982 |
| 1973 if (getStyleChangeType() >= SubtreeStyleChange) | 1983 if (getStyleChangeType() >= SubtreeStyleChange) |
| 1974 return Force; | 1984 return Force; |
| 1975 | 1985 |
| 1976 if (change > Inherit || localChange > Inherit) | 1986 if (change > Inherit || localChange > Inherit) |
| 1977 return max(localChange, change); | 1987 return max(localChange, change); |
| 1978 | 1988 |
| 1979 if (localChange < IndependentInherit) { | 1989 if (localChange < IndependentInherit) { |
| 1980 if (oldStyle->hasChildDependentFlags()) { | 1990 if (oldStyle->hasChildDependentFlags()) { |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3113 elementStyle = rareData.computedStyle(); | 3123 elementStyle = rareData.computedStyle(); |
| 3114 } | 3124 } |
| 3115 | 3125 |
| 3116 if (!pseudoElementSpecifier) | 3126 if (!pseudoElementSpecifier) |
| 3117 return elementStyle; | 3127 return elementStyle; |
| 3118 | 3128 |
| 3119 if (ComputedStyle* pseudoElementStyle = | 3129 if (ComputedStyle* pseudoElementStyle = |
| 3120 elementStyle->getCachedPseudoStyle(pseudoElementSpecifier)) | 3130 elementStyle->getCachedPseudoStyle(pseudoElementSpecifier)) |
| 3121 return pseudoElementStyle; | 3131 return pseudoElementStyle; |
| 3122 | 3132 |
| 3133 // FIXME(ecobos): Passing two times elementStyle may be wrong, though we don't | |
| 3134 // support display: contents pseudo-elements yet, so this is not a problem for | |
| 3135 // now. | |
|
rune
2016/12/01 15:28:53
FIXME -> TODO.
It is wrong, but it's not about di
emilio
2016/12/01 17:32:56
Right, should've clarified.
| |
| 3123 RefPtr<ComputedStyle> result = | 3136 RefPtr<ComputedStyle> result = |
| 3124 document().ensureStyleResolver().pseudoStyleForElement( | 3137 document().ensureStyleResolver().pseudoStyleForElement( |
| 3125 this, PseudoStyleRequest(pseudoElementSpecifier, | 3138 this, PseudoStyleRequest(pseudoElementSpecifier, |
| 3126 PseudoStyleRequest::ForComputedStyle), | 3139 PseudoStyleRequest::ForComputedStyle), |
| 3127 elementStyle); | 3140 elementStyle, elementStyle); |
| 3128 DCHECK(result); | 3141 DCHECK(result); |
| 3129 return elementStyle->addCachedPseudoStyle(result.release()); | 3142 return elementStyle->addCachedPseudoStyle(result.release()); |
| 3130 } | 3143 } |
| 3131 | 3144 |
| 3145 const ComputedStyle* Element::nonLayoutObjectComputedStyle() const { | |
| 3146 if (layoutObject() || !hasRareData()) | |
| 3147 return nullptr; | |
| 3148 | |
| 3149 return elementRareData()->computedStyle(); | |
| 3150 } | |
| 3151 | |
| 3152 bool Element::hasDisplayContentsStyle() const { | |
| 3153 if (const ComputedStyle* style = nonLayoutObjectComputedStyle()) | |
| 3154 return style->display() == EDisplay::Contents; | |
| 3155 return false; | |
| 3156 } | |
| 3157 | |
| 3158 bool Element::shouldStoreNonLayoutObjectComputedStyle( | |
| 3159 const ComputedStyle& style) const { | |
| 3160 #if DCHECK_IS_ON() | |
| 3161 if (style.display() == EDisplay::Contents) | |
| 3162 DCHECK(!layoutObject()); | |
| 3163 #endif | |
| 3164 | |
| 3165 return style.display() == EDisplay::Contents || | |
| 3166 isHTMLOptGroupElement(*this) || isHTMLOptionElement(*this); | |
| 3167 } | |
| 3168 | |
| 3169 void Element::storeNonLayoutObjectComputedStyle( | |
| 3170 PassRefPtr<ComputedStyle> style) { | |
| 3171 DCHECK(style); | |
| 3172 DCHECK(shouldStoreNonLayoutObjectComputedStyle(*style)); | |
| 3173 ensureElementRareData().setComputedStyle(std::move(style)); | |
| 3174 } | |
| 3175 | |
| 3132 AtomicString Element::computeInheritedLanguage() const { | 3176 AtomicString Element::computeInheritedLanguage() const { |
| 3133 const Node* n = this; | 3177 const Node* n = this; |
| 3134 AtomicString value; | 3178 AtomicString value; |
| 3135 // The language property is inherited, so we iterate over the parents to find | 3179 // The language property is inherited, so we iterate over the parents to find |
| 3136 // the first language. | 3180 // the first language. |
| 3137 do { | 3181 do { |
| 3138 if (n->isElementNode()) { | 3182 if (n->isElementNode()) { |
| 3139 if (const ElementData* elementData = toElement(n)->elementData()) { | 3183 if (const ElementData* elementData = toElement(n)->elementData()) { |
| 3140 AttributeCollection attributes = elementData->attributes(); | 3184 AttributeCollection attributes = elementData->attributes(); |
| 3141 // Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7 | 3185 // Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7 |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3855 StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange)); | 3899 StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange)); |
| 3856 InspectorInstrumentation::didInvalidateStyleAttr(this); | 3900 InspectorInstrumentation::didInvalidateStyleAttr(this); |
| 3857 } | 3901 } |
| 3858 | 3902 |
| 3859 void Element::inlineStyleChanged() { | 3903 void Element::inlineStyleChanged() { |
| 3860 DCHECK(isStyledElement()); | 3904 DCHECK(isStyledElement()); |
| 3861 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create( | 3905 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create( |
| 3862 StyleChangeReason::Inline)); | 3906 StyleChangeReason::Inline)); |
| 3863 DCHECK(elementData()); | 3907 DCHECK(elementData()); |
| 3864 elementData()->m_styleAttributeIsDirty = true; | 3908 elementData()->m_styleAttributeIsDirty = true; |
| 3909 | |
| 3865 InspectorInstrumentation::didInvalidateStyleAttr(this); | 3910 InspectorInstrumentation::didInvalidateStyleAttr(this); |
| 3866 | 3911 |
| 3867 if (MutationObserverInterestGroup* recipients = | 3912 if (MutationObserverInterestGroup* recipients = |
| 3868 MutationObserverInterestGroup::createForAttributesMutation( | 3913 MutationObserverInterestGroup::createForAttributesMutation( |
| 3869 *this, styleAttr)) { | 3914 *this, styleAttr)) { |
| 3870 // We don't use getAttribute() here to get a style attribute value | 3915 // We don't use getAttribute() here to get a style attribute value |
| 3871 // before the change. | 3916 // before the change. |
| 3872 AtomicString oldValue; | 3917 AtomicString oldValue; |
| 3873 if (const Attribute* attribute = | 3918 if (const Attribute* attribute = |
| 3874 elementData()->attributes().find(styleAttr)) | 3919 elementData()->attributes().find(styleAttr)) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4089 } | 4134 } |
| 4090 | 4135 |
| 4091 DEFINE_TRACE_WRAPPERS(Element) { | 4136 DEFINE_TRACE_WRAPPERS(Element) { |
| 4092 if (hasRareData()) { | 4137 if (hasRareData()) { |
| 4093 visitor->traceWrappers(elementRareData()); | 4138 visitor->traceWrappers(elementRareData()); |
| 4094 } | 4139 } |
| 4095 ContainerNode::traceWrappers(visitor); | 4140 ContainerNode::traceWrappers(visitor); |
| 4096 } | 4141 } |
| 4097 | 4142 |
| 4098 } // namespace blink | 4143 } // namespace blink |
| OLD | NEW |