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 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1991 if (localChange != NoChange) { | 1991 if (localChange != NoChange) { |
1992 layoutObject->setStyle(newStyle.get()); | 1992 layoutObject->setStyle(newStyle.get()); |
1993 } else { | 1993 } else { |
1994 // Although no change occurred, we use the new style so that the cousin | 1994 // Although no change occurred, we use the new style so that the cousin |
1995 // style sharing code won't get fooled into believing this style is the | 1995 // style sharing code won't get fooled into believing this style is the |
1996 // same. | 1996 // same. |
1997 // FIXME: We may be able to remove this hack, see discussion in | 1997 // FIXME: We may be able to remove this hack, see discussion in |
1998 // https://codereview.chromium.org/30453002/ | 1998 // https://codereview.chromium.org/30453002/ |
1999 layoutObject->setStyleInternal(newStyle.get()); | 1999 layoutObject->setStyleInternal(newStyle.get()); |
2000 } | 2000 } |
2001 } else if (localChange != NoChange && | 2001 } else { |
2002 shouldStoreNonLayoutObjectComputedStyle(*newStyle)) { | 2002 if (localChange != NoChange) { |
2003 storeNonLayoutObjectComputedStyle(newStyle); | 2003 if (shouldStoreNonLayoutObjectComputedStyle(*newStyle)) |
2004 storeNonLayoutObjectComputedStyle(newStyle); | |
2005 else if (hasRareData()) | |
2006 elementRareData()->clearComputedStyle(); | |
2007 } | |
2004 } | 2008 } |
2005 | 2009 |
2006 if (getStyleChangeType() >= SubtreeStyleChange) | 2010 if (getStyleChangeType() >= SubtreeStyleChange) |
2007 return Force; | 2011 return Force; |
2008 | 2012 |
2009 if (change > Inherit || localChange > Inherit) | 2013 if (change > Inherit || localChange > Inherit) |
2010 return max(localChange, change); | 2014 return max(localChange, change); |
2011 | 2015 |
2012 if (localChange < IndependentInherit) { | 2016 if (localChange < IndependentInherit) { |
2013 if (oldStyle->hasChildDependentFlags()) { | 2017 if (oldStyle->hasChildDependentFlags()) { |
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3163 ElementRareData& rareData = ensureElementRareData(); | 3167 ElementRareData& rareData = ensureElementRareData(); |
3164 if (!rareData.computedStyle()) | 3168 if (!rareData.computedStyle()) |
3165 rareData.setComputedStyle( | 3169 rareData.setComputedStyle( |
3166 document().styleForElementIgnoringPendingStylesheets(this)); | 3170 document().styleForElementIgnoringPendingStylesheets(this)); |
3167 elementStyle = rareData.computedStyle(); | 3171 elementStyle = rareData.computedStyle(); |
3168 } | 3172 } |
3169 | 3173 |
3170 if (!pseudoElementSpecifier) | 3174 if (!pseudoElementSpecifier) |
3171 return elementStyle; | 3175 return elementStyle; |
3172 | 3176 |
3173 if (ComputedStyle* pseudoElementStyle = | 3177 if (ComputedStyle* cached = |
3174 elementStyle->getCachedPseudoStyle(pseudoElementSpecifier)) | 3178 elementStyle->getCachedPseudoStyle(pseudoElementSpecifier)) |
3175 return pseudoElementStyle; | 3179 return cached; |
3176 | 3180 |
3177 // TODO(ecobos): Passing two times elementStyle may be wrong, though we don't | 3181 const ComputedStyle* layoutParentStyle = elementStyle; |
3178 // support display: contents elements' pseudo-elements yet, so this is not a | 3182 if (hasDisplayContentsStyle()) { |
3179 // problem for now. | 3183 LayoutObject* parentLayoutObject = |
3184 LayoutTreeBuilderTraversal::parentLayoutObject(*this); | |
3185 if (parentLayoutObject) | |
3186 layoutParentStyle = parentLayoutObject->style(); | |
3187 } | |
3188 | |
3180 RefPtr<ComputedStyle> result = | 3189 RefPtr<ComputedStyle> result = |
3181 document().ensureStyleResolver().pseudoStyleForElement( | 3190 document().ensureStyleResolver().pseudoStyleForElement( |
3182 this, PseudoStyleRequest(pseudoElementSpecifier, | 3191 this, |
3183 PseudoStyleRequest::ForComputedStyle), | 3192 PseudoStyleRequest(pseudoElementSpecifier, |
3184 elementStyle, elementStyle); | 3193 PseudoStyleRequest::ForComputedStyle), |
3194 elementStyle, layoutParentStyle); | |
3185 DCHECK(result); | 3195 DCHECK(result); |
3186 return elementStyle->addCachedPseudoStyle(result.release()); | 3196 return elementStyle->addCachedPseudoStyle(result.release()); |
3187 } | 3197 } |
3188 | 3198 |
3189 const ComputedStyle* Element::nonLayoutObjectComputedStyle() const { | 3199 const ComputedStyle* Element::nonLayoutObjectComputedStyle() const { |
3190 if (layoutObject() || !hasRareData()) | 3200 if (layoutObject() || !hasRareData()) |
3191 return nullptr; | 3201 return nullptr; |
3192 | 3202 |
3193 return elementRareData()->computedStyle(); | 3203 return elementRareData()->computedStyle(); |
3194 } | 3204 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3270 // PseudoElement styles hang off their parent element's style so if we | 3280 // PseudoElement styles hang off their parent element's style so if we |
3271 // needed a style recalc we should Force one on the pseudo. FIXME: We | 3281 // needed a style recalc we should Force one on the pseudo. FIXME: We |
3272 // should figure out the right text sibling to pass. | 3282 // should figure out the right text sibling to pass. |
3273 element->recalcStyle(change == UpdatePseudoElements ? Force : change); | 3283 element->recalcStyle(change == UpdatePseudoElements ? Force : change); |
3274 | 3284 |
3275 // Wait until our parent is not displayed or | 3285 // Wait until our parent is not displayed or |
3276 // pseudoElementLayoutObjectIsNeeded is false, otherwise we could | 3286 // pseudoElementLayoutObjectIsNeeded is false, otherwise we could |
3277 // continuously create and destroy PseudoElements when | 3287 // continuously create and destroy PseudoElements when |
3278 // LayoutObject::isChildAllowed on our parent returns false for the | 3288 // LayoutObject::isChildAllowed on our parent returns false for the |
3279 // PseudoElement's layoutObject for each style recalc. | 3289 // PseudoElement's layoutObject for each style recalc. |
3280 if (!layoutObject() || !pseudoElementLayoutObjectIsNeeded( | 3290 if (!canHaveGeneratedPseudo(pseudoId) || |
3281 pseudoStyle(PseudoStyleRequest(pseudoId)))) | 3291 !pseudoElementLayoutObjectIsNeeded( |
3292 pseudoStyle(PseudoStyleRequest(pseudoId)))) | |
3282 elementRareData()->setPseudoElement(pseudoId, nullptr); | 3293 elementRareData()->setPseudoElement(pseudoId, nullptr); |
3283 } else if (pseudoId == PseudoIdFirstLetter && element && | 3294 } else if (pseudoId == PseudoIdFirstLetter && element && |
3284 change >= UpdatePseudoElements && | 3295 change >= UpdatePseudoElements && |
3285 !FirstLetterPseudoElement::firstLetterTextLayoutObject(*element)) { | 3296 !FirstLetterPseudoElement::firstLetterTextLayoutObject(*element)) { |
3286 // This can happen if we change to a float, for example. We need to cleanup | 3297 // This can happen if we change to a float, for example. We need to cleanup |
3287 // the first-letter pseudoElement and then fix the text of the original | 3298 // the first-letter pseudoElement and then fix the text of the original |
3288 // remaining text layoutObject. This can be seen in Test 7 of | 3299 // remaining text layoutObject. This can be seen in Test 7 of |
3289 // fast/css/first-letter-removed-added.html | 3300 // fast/css/first-letter-removed-added.html |
3290 elementRareData()->setPseudoElement(pseudoId, nullptr); | 3301 elementRareData()->setPseudoElement(pseudoId, nullptr); |
3291 } else if (change >= UpdatePseudoElements) { | 3302 } else if (change >= UpdatePseudoElements) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3398 document().ensureStyleResolver().styleForElement( | 3409 document().ensureStyleResolver().styleForElement( |
3399 this, parentStyle, parentStyle, DisallowStyleSharing); | 3410 this, parentStyle, parentStyle, DisallowStyleSharing); |
3400 result->setStyleType(PseudoIdFirstLineInherited); | 3411 result->setStyleType(PseudoIdFirstLineInherited); |
3401 return result.release(); | 3412 return result.release(); |
3402 } | 3413 } |
3403 | 3414 |
3404 return document().ensureStyleResolver().pseudoStyleForElement( | 3415 return document().ensureStyleResolver().pseudoStyleForElement( |
3405 this, request, parentStyle, parentStyle); | 3416 this, request, parentStyle, parentStyle); |
3406 } | 3417 } |
3407 | 3418 |
3419 // For display: contents elements, we still need to generate ::before and | |
3420 // ::after, but the rest of the pseudo-elements should only be used for elements | |
3421 // with an actual layout object. | |
3422 bool Element::canHaveGeneratedPseudo(PseudoId pseudoId) const { | |
rune
2017/04/04 14:23:41
canHavePseudoElement() or canGeneratePseudoElement
emilio
2017/04/04 15:09:18
Acknowledged.
| |
3423 if (hasDisplayContentsStyle()) | |
3424 return pseudoId == PseudoIdBefore || pseudoId == PseudoIdAfter; | |
3425 return !!layoutObject(); | |
3426 } | |
3427 | |
3408 bool Element::matches(const AtomicString& selectors, | 3428 bool Element::matches(const AtomicString& selectors, |
3409 ExceptionState& exceptionState) { | 3429 ExceptionState& exceptionState) { |
3410 SelectorQuery* selectorQuery = document().selectorQueryCache().add( | 3430 SelectorQuery* selectorQuery = document().selectorQueryCache().add( |
3411 selectors, document(), exceptionState); | 3431 selectors, document(), exceptionState); |
3412 if (!selectorQuery) | 3432 if (!selectorQuery) |
3413 return false; | 3433 return false; |
3414 return selectorQuery->matches(*this); | 3434 return selectorQuery->matches(*this); |
3415 } | 3435 } |
3416 | 3436 |
3417 Element* Element::closest(const AtomicString& selectors, | 3437 Element* Element::closest(const AtomicString& selectors, |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4252 } | 4272 } |
4253 | 4273 |
4254 DEFINE_TRACE_WRAPPERS(Element) { | 4274 DEFINE_TRACE_WRAPPERS(Element) { |
4255 if (hasRareData()) { | 4275 if (hasRareData()) { |
4256 visitor->traceWrappers(elementRareData()); | 4276 visitor->traceWrappers(elementRareData()); |
4257 } | 4277 } |
4258 ContainerNode::traceWrappers(visitor); | 4278 ContainerNode::traceWrappers(visitor); |
4259 } | 4279 } |
4260 | 4280 |
4261 } // namespace blink | 4281 } // namespace blink |
OLD | NEW |