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

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2450093005: Support display: contents for elements, first-line and first-letter pseudos. (Closed)
Patch Set: Rebased Created 3 years, 11 months 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) 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 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 return parent->locateNamespacePrefix(namespaceToLocate); 1563 return parent->locateNamespacePrefix(namespaceToLocate);
1564 1564
1565 return nullAtom; 1565 return nullAtom;
1566 } 1566 }
1567 1567
1568 const AtomicString Element::imageSourceURL() const { 1568 const AtomicString Element::imageSourceURL() const {
1569 return getAttribute(srcAttr); 1569 return getAttribute(srcAttr);
1570 } 1570 }
1571 1571
1572 bool Element::layoutObjectIsNeeded(const ComputedStyle& style) { 1572 bool Element::layoutObjectIsNeeded(const ComputedStyle& style) {
1573 return style.display() != EDisplay::None; 1573 return style.display() != EDisplay::None &&
1574 style.display() != EDisplay::Contents;
1574 } 1575 }
1575 1576
1576 LayoutObject* Element::createLayoutObject(const ComputedStyle& style) { 1577 LayoutObject* Element::createLayoutObject(const ComputedStyle& style) {
1577 return LayoutObject::createObject(this, style); 1578 return LayoutObject::createObject(this, style);
1578 } 1579 }
1579 1580
1580 Node::InsertionNotificationRequest Element::insertedInto( 1581 Node::InsertionNotificationRequest Element::insertedInto(
1581 ContainerNode* insertionPoint) { 1582 ContainerNode* insertionPoint) {
1582 // need to do superclass processing first so isConnected() is true 1583 // need to do superclass processing first so isConnected() is true
1583 // by the time we reach updateId 1584 // by the time we reach updateId
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 void Element::attachLayoutTree(const AttachContext& context) { 1702 void Element::attachLayoutTree(const AttachContext& context) {
1702 DCHECK(document().inStyleRecalc()); 1703 DCHECK(document().inStyleRecalc());
1703 1704
1704 // We've already been through detach when doing an attach, but we might 1705 // We've already been through detach when doing an attach, but we might
1705 // need to clear any state that's been added since then. 1706 // need to clear any state that's been added since then.
1706 if (hasRareData() && needsAttach()) { 1707 if (hasRareData() && needsAttach()) {
1707 ElementRareData* data = elementRareData(); 1708 ElementRareData* data = elementRareData();
1708 data->clearComputedStyle(); 1709 data->clearComputedStyle();
1709 } 1710 }
1710 1711
1711 if (!isActiveSlotOrActiveInsertionPoint()) 1712 if (!isActiveSlotOrActiveInsertionPoint()) {
1712 LayoutTreeBuilderForElement(*this, context.resolvedStyle) 1713 LayoutTreeBuilderForElement builder(*this, context.resolvedStyle);
1713 .createLayoutObjectIfNeeded(); 1714 builder.createLayoutObjectIfNeeded();
1715
1716 if (ComputedStyle* style = builder.resolvedStyle()) {
1717 if (!layoutObject() && shouldStoreNonLayoutObjectComputedStyle(*style))
1718 storeNonLayoutObjectComputedStyle(style);
1719 }
1720 }
1714 1721
1715 addCallbackSelectors(); 1722 addCallbackSelectors();
1716 1723
1717 if (hasRareData() && !layoutObject()) { 1724 if (hasRareData() && !layoutObject()) {
1718 if (ElementAnimations* elementAnimations = 1725 if (ElementAnimations* elementAnimations =
1719 elementRareData()->elementAnimations()) { 1726 elementRareData()->elementAnimations()) {
1720 elementAnimations->cssAnimations().cancel(); 1727 elementAnimations->cssAnimations().cancel();
1721 elementAnimations->setAnimationStyleChange(false); 1728 elementAnimations->setAnimationStyleChange(false);
1722 } 1729 }
1723 } 1730 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 DCHECK(!document().lifecycle().inDetach()); 1886 DCHECK(!document().lifecycle().inDetach());
1880 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc()); 1887 DCHECK(!parentOrShadowHostNode()->needsStyleRecalc());
1881 DCHECK(inActiveDocument()); 1888 DCHECK(inActiveDocument());
1882 1889
1883 if (hasCustomStyleCallbacks()) 1890 if (hasCustomStyleCallbacks())
1884 willRecalcStyle(change); 1891 willRecalcStyle(change);
1885 1892
1886 if (change >= IndependentInherit || needsStyleRecalc()) { 1893 if (change >= IndependentInherit || needsStyleRecalc()) {
1887 if (hasRareData()) { 1894 if (hasRareData()) {
1888 ElementRareData* data = elementRareData(); 1895 ElementRareData* data = elementRareData();
1889 if (change != IndependentInherit) 1896 if (change != IndependentInherit && !nonLayoutObjectComputedStyle())
1890 data->clearComputedStyle(); 1897 data->clearComputedStyle();
1891 1898
1892 if (change >= IndependentInherit) { 1899 if (change >= IndependentInherit) {
1893 if (ElementAnimations* elementAnimations = data->elementAnimations()) 1900 if (ElementAnimations* elementAnimations = data->elementAnimations())
1894 elementAnimations->setAnimationStyleChange(false); 1901 elementAnimations->setAnimationStyleChange(false);
1895 } 1902 }
1896 } 1903 }
1897 if (parentComputedStyle()) 1904 if (parentComputedStyle())
1898 change = recalcOwnStyle(change, nextTextSibling); 1905 change = recalcOwnStyle(change, nextTextSibling);
1899 clearNeedsStyleRecalc(); 1906 clearNeedsStyleRecalc();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) { 2009 pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get())) {
2003 layoutObject->setStyle(newStyle.get()); 2010 layoutObject->setStyle(newStyle.get());
2004 } else { 2011 } else {
2005 // Although no change occurred, we use the new style so that the cousin 2012 // Although no change occurred, we use the new style so that the cousin
2006 // style sharing code won't get fooled into believing this style is the 2013 // style sharing code won't get fooled into believing this style is the
2007 // same. 2014 // same.
2008 // FIXME: We may be able to remove this hack, see discussion in 2015 // FIXME: We may be able to remove this hack, see discussion in
2009 // https://codereview.chromium.org/30453002/ 2016 // https://codereview.chromium.org/30453002/
2010 layoutObject->setStyleInternal(newStyle.get()); 2017 layoutObject->setStyleInternal(newStyle.get());
2011 } 2018 }
2019 } else if (localChange != NoChange &&
2020 shouldStoreNonLayoutObjectComputedStyle(*newStyle)) {
2021 storeNonLayoutObjectComputedStyle(newStyle);
2012 } 2022 }
2013 2023
2014 if (getStyleChangeType() >= SubtreeStyleChange) 2024 if (getStyleChangeType() >= SubtreeStyleChange)
2015 return Force; 2025 return Force;
2016 2026
2017 if (change > Inherit || localChange > Inherit) 2027 if (change > Inherit || localChange > Inherit)
2018 return max(localChange, change); 2028 return max(localChange, change);
2019 2029
2020 if (localChange < IndependentInherit) { 2030 if (localChange < IndependentInherit) {
2021 if (oldStyle->hasChildDependentFlags()) { 2031 if (oldStyle->hasChildDependentFlags()) {
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 elementStyle = rareData.computedStyle(); 3163 elementStyle = rareData.computedStyle();
3154 } 3164 }
3155 3165
3156 if (!pseudoElementSpecifier) 3166 if (!pseudoElementSpecifier)
3157 return elementStyle; 3167 return elementStyle;
3158 3168
3159 if (ComputedStyle* pseudoElementStyle = 3169 if (ComputedStyle* pseudoElementStyle =
3160 elementStyle->getCachedPseudoStyle(pseudoElementSpecifier)) 3170 elementStyle->getCachedPseudoStyle(pseudoElementSpecifier))
3161 return pseudoElementStyle; 3171 return pseudoElementStyle;
3162 3172
3173 // TODO(ecobos): Passing two times elementStyle may be wrong, though we don't
3174 // support display: contents elements' pseudo-elements yet, so this is not a
3175 // problem for now.
3163 RefPtr<ComputedStyle> result = 3176 RefPtr<ComputedStyle> result =
3164 document().ensureStyleResolver().pseudoStyleForElement( 3177 document().ensureStyleResolver().pseudoStyleForElement(
3165 this, PseudoStyleRequest(pseudoElementSpecifier, 3178 this, PseudoStyleRequest(pseudoElementSpecifier,
3166 PseudoStyleRequest::ForComputedStyle), 3179 PseudoStyleRequest::ForComputedStyle),
3167 elementStyle); 3180 elementStyle, elementStyle);
3168 DCHECK(result); 3181 DCHECK(result);
3169 return elementStyle->addCachedPseudoStyle(result.release()); 3182 return elementStyle->addCachedPseudoStyle(result.release());
3170 } 3183 }
3171 3184
3185 const ComputedStyle* Element::nonLayoutObjectComputedStyle() const {
3186 if (layoutObject() || !hasRareData())
3187 return nullptr;
3188
3189 return elementRareData()->computedStyle();
3190 }
3191
3192 bool Element::hasDisplayContentsStyle() const {
3193 if (const ComputedStyle* style = nonLayoutObjectComputedStyle())
3194 return style->display() == EDisplay::Contents;
3195 return false;
3196 }
3197
3198 bool Element::shouldStoreNonLayoutObjectComputedStyle(
3199 const ComputedStyle& style) const {
3200 #if DCHECK_IS_ON()
3201 if (style.display() == EDisplay::Contents)
3202 DCHECK(!layoutObject());
3203 #endif
3204
3205 return style.display() == EDisplay::Contents ||
3206 isHTMLOptGroupElement(*this) || isHTMLOptionElement(*this);
3207 }
3208
3209 void Element::storeNonLayoutObjectComputedStyle(
3210 PassRefPtr<ComputedStyle> style) {
3211 DCHECK(style);
3212 DCHECK(shouldStoreNonLayoutObjectComputedStyle(*style));
3213 ensureElementRareData().setComputedStyle(std::move(style));
3214 }
3215
3172 AtomicString Element::computeInheritedLanguage() const { 3216 AtomicString Element::computeInheritedLanguage() const {
3173 const Node* n = this; 3217 const Node* n = this;
3174 AtomicString value; 3218 AtomicString value;
3175 // The language property is inherited, so we iterate over the parents to find 3219 // The language property is inherited, so we iterate over the parents to find
3176 // the first language. 3220 // the first language.
3177 do { 3221 do {
3178 if (n->isElementNode()) { 3222 if (n->isElementNode()) {
3179 if (const ElementData* elementData = toElement(n)->elementData()) { 3223 if (const ElementData* elementData = toElement(n)->elementData()) {
3180 AttributeCollection attributes = elementData->attributes(); 3224 AttributeCollection attributes = elementData->attributes();
3181 // Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7 3225 // Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
3902 StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange)); 3946 StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange));
3903 InspectorInstrumentation::didInvalidateStyleAttr(this); 3947 InspectorInstrumentation::didInvalidateStyleAttr(this);
3904 } 3948 }
3905 3949
3906 void Element::inlineStyleChanged() { 3950 void Element::inlineStyleChanged() {
3907 DCHECK(isStyledElement()); 3951 DCHECK(isStyledElement());
3908 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create( 3952 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create(
3909 StyleChangeReason::Inline)); 3953 StyleChangeReason::Inline));
3910 DCHECK(elementData()); 3954 DCHECK(elementData());
3911 elementData()->m_styleAttributeIsDirty = true; 3955 elementData()->m_styleAttributeIsDirty = true;
3956
rune 2017/01/27 13:09:23 Stray newline?
3912 InspectorInstrumentation::didInvalidateStyleAttr(this); 3957 InspectorInstrumentation::didInvalidateStyleAttr(this);
3913 3958
3914 if (MutationObserverInterestGroup* recipients = 3959 if (MutationObserverInterestGroup* recipients =
3915 MutationObserverInterestGroup::createForAttributesMutation( 3960 MutationObserverInterestGroup::createForAttributesMutation(
3916 *this, styleAttr)) { 3961 *this, styleAttr)) {
3917 // We don't use getAttribute() here to get a style attribute value 3962 // We don't use getAttribute() here to get a style attribute value
3918 // before the change. 3963 // before the change.
3919 AtomicString oldValue; 3964 AtomicString oldValue;
3920 if (const Attribute* attribute = 3965 if (const Attribute* attribute =
3921 elementData()->attributes().find(styleAttr)) 3966 elementData()->attributes().find(styleAttr))
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
4130 } 4175 }
4131 4176
4132 DEFINE_TRACE_WRAPPERS(Element) { 4177 DEFINE_TRACE_WRAPPERS(Element) {
4133 if (hasRareData()) { 4178 if (hasRareData()) {
4134 visitor->traceWrappers(elementRareData()); 4179 visitor->traceWrappers(elementRareData());
4135 } 4180 }
4136 ContainerNode::traceWrappers(visitor); 4181 ContainerNode::traceWrappers(visitor);
4137 } 4182 }
4138 4183
4139 } // namespace blink 4184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698