| 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) 2007 David Smith (catfish.man@gmail.com) | 4 * (C) 2007 David Smith (catfish.man@gmail.com) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 LayoutObject* parentLayoutObject = 0; | 101 LayoutObject* parentLayoutObject = 0; |
| 102 | 102 |
| 103 // If we are looking at a first letter element then we need to find the | 103 // If we are looking at a first letter element then we need to find the |
| 104 // first letter text layoutObject from the parent node, and not ourselves. | 104 // first letter text layoutObject from the parent node, and not ourselves. |
| 105 if (element.isFirstLetterPseudoElement()) | 105 if (element.isFirstLetterPseudoElement()) |
| 106 parentLayoutObject = element.parentOrShadowHostElement()->layoutObject()
; | 106 parentLayoutObject = element.parentOrShadowHostElement()->layoutObject()
; |
| 107 else | 107 else |
| 108 parentLayoutObject = element.layoutObject(); | 108 parentLayoutObject = element.layoutObject(); |
| 109 | 109 |
| 110 if (!parentLayoutObject | 110 if (!parentLayoutObject |
| 111 || !parentLayoutObject->style()->hasPseudoStyle(FIRST_LETTER) | 111 || !parentLayoutObject->style()->hasPseudoStyle(PseudoIdFirstLetter) |
| 112 || !canHaveGeneratedChildren(*parentLayoutObject) | 112 || !canHaveGeneratedChildren(*parentLayoutObject) |
| 113 || !parentLayoutObject->canHaveFirstLineOrFirstLetterStyle()) | 113 || !parentLayoutObject->canHaveFirstLineOrFirstLetterStyle()) |
| 114 return nullptr; | 114 return nullptr; |
| 115 | 115 |
| 116 // Drill down into our children and look for our first text child. | 116 // Drill down into our children and look for our first text child. |
| 117 LayoutObject* firstLetterTextLayoutObject = parentLayoutObject->slowFirstChi
ld(); | 117 LayoutObject* firstLetterTextLayoutObject = parentLayoutObject->slowFirstChi
ld(); |
| 118 while (firstLetterTextLayoutObject) { | 118 while (firstLetterTextLayoutObject) { |
| 119 // This can be called when the first letter layoutObject is already in t
he tree. We do not | 119 // This can be called when the first letter layoutObject is already in t
he tree. We do not |
| 120 // want to consider that layoutObject for our text layoutObject so we go
to the sibling (which is | 120 // want to consider that layoutObject for our text layoutObject so we go
to the sibling (which is |
| 121 // the LayoutTextFragment for the remaining text). | 121 // the LayoutTextFragment for the remaining text). |
| 122 if (firstLetterTextLayoutObject->style() && firstLetterTextLayoutObject-
>style()->styleType() == FIRST_LETTER) { | 122 if (firstLetterTextLayoutObject->style() && firstLetterTextLayoutObject-
>style()->styleType() == PseudoIdFirstLetter) { |
| 123 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); | 123 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); |
| 124 } else if (firstLetterTextLayoutObject->isText()) { | 124 } else if (firstLetterTextLayoutObject->isText()) { |
| 125 // FIXME: If there is leading punctuation in a different LayoutText
than | 125 // FIXME: If there is leading punctuation in a different LayoutText
than |
| 126 // the first letter, we'll not apply the correct style to it. | 126 // the first letter, we'll not apply the correct style to it. |
| 127 RefPtr<StringImpl> str = toLayoutText(firstLetterTextLayoutObject)->
isTextFragment() ? | 127 RefPtr<StringImpl> str = toLayoutText(firstLetterTextLayoutObject)->
isTextFragment() ? |
| 128 toLayoutTextFragment(firstLetterTextLayoutObject)->completeText(
) : | 128 toLayoutTextFragment(firstLetterTextLayoutObject)->completeText(
) : |
| 129 toLayoutText(firstLetterTextLayoutObject)->originalText(); | 129 toLayoutText(firstLetterTextLayoutObject)->originalText(); |
| 130 if (firstLetterLength(str.get()) || isInvalidFirstLetterLayoutObject
(firstLetterTextLayoutObject)) | 130 if (firstLetterLength(str.get()) || isInvalidFirstLetterLayoutObject
(firstLetterTextLayoutObject)) |
| 131 break; | 131 break; |
| 132 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); | 132 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); |
| 133 } else if (firstLetterTextLayoutObject->isListMarker()) { | 133 } else if (firstLetterTextLayoutObject->isListMarker()) { |
| 134 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); | 134 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); |
| 135 } else if (firstLetterTextLayoutObject->isFloatingOrOutOfFlowPositioned(
)) { | 135 } else if (firstLetterTextLayoutObject->isFloatingOrOutOfFlowPositioned(
)) { |
| 136 if (firstLetterTextLayoutObject->style()->styleType() == FIRST_LETTE
R) { | 136 if (firstLetterTextLayoutObject->style()->styleType() == PseudoIdFir
stLetter) { |
| 137 firstLetterTextLayoutObject = firstLetterTextLayoutObject->slowF
irstChild(); | 137 firstLetterTextLayoutObject = firstLetterTextLayoutObject->slowF
irstChild(); |
| 138 break; | 138 break; |
| 139 } | 139 } |
| 140 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); | 140 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); |
| 141 } else if (firstLetterTextLayoutObject->isAtomicInlineLevel() || firstLe
tterTextLayoutObject->isLayoutButton() | 141 } else if (firstLetterTextLayoutObject->isAtomicInlineLevel() || firstLe
tterTextLayoutObject->isLayoutButton() |
| 142 || firstLetterTextLayoutObject->isMenuList()) { | 142 || firstLetterTextLayoutObject->isMenuList()) { |
| 143 return nullptr; | 143 return nullptr; |
| 144 } else if (firstLetterTextLayoutObject->isFlexibleBoxIncludingDeprecated
() || firstLetterTextLayoutObject->isLayoutGrid()) { | 144 } else if (firstLetterTextLayoutObject->isFlexibleBoxIncludingDeprecated
() || firstLetterTextLayoutObject->isLayoutGrid()) { |
| 145 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); | 145 firstLetterTextLayoutObject = firstLetterTextLayoutObject->nextSibli
ng(); |
| 146 } else if (!firstLetterTextLayoutObject->isInline() | 146 } else if (!firstLetterTextLayoutObject->isInline() |
| 147 && firstLetterTextLayoutObject->style()->hasPseudoStyle(FIRST_LETTER
) | 147 && firstLetterTextLayoutObject->style()->hasPseudoStyle(PseudoIdFirs
tLetter) |
| 148 && canHaveGeneratedChildren(*firstLetterTextLayoutObject)) { | 148 && canHaveGeneratedChildren(*firstLetterTextLayoutObject)) { |
| 149 // There is a layoutObject further down the tree which has FIRST_LET
TER set. When that node | 149 // There is a layoutObject further down the tree which has PseudoIdF
irstLetter set. When that node |
| 150 // is attached we will handle setting up the first letter then. | 150 // is attached we will handle setting up the first letter then. |
| 151 return nullptr; | 151 return nullptr; |
| 152 } else { | 152 } else { |
| 153 firstLetterTextLayoutObject = firstLetterTextLayoutObject->slowFirst
Child(); | 153 firstLetterTextLayoutObject = firstLetterTextLayoutObject->slowFirst
Child(); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 // No first letter text to display, we're done. | 157 // No first letter text to display, we're done. |
| 158 // FIXME: This black-list of disallowed LayoutText subclasses is fragile. cr
bug.com/422336. | 158 // FIXME: This black-list of disallowed LayoutText subclasses is fragile. cr
bug.com/422336. |
| 159 // Should counter be on this list? What about LayoutTextFragment? | 159 // Should counter be on this list? What about LayoutTextFragment? |
| 160 if (!firstLetterTextLayoutObject || !firstLetterTextLayoutObject->isText() |
| isInvalidFirstLetterLayoutObject(firstLetterTextLayoutObject)) | 160 if (!firstLetterTextLayoutObject || !firstLetterTextLayoutObject->isText() |
| isInvalidFirstLetterLayoutObject(firstLetterTextLayoutObject)) |
| 161 return nullptr; | 161 return nullptr; |
| 162 | 162 |
| 163 return firstLetterTextLayoutObject; | 163 return firstLetterTextLayoutObject; |
| 164 } | 164 } |
| 165 | 165 |
| 166 FirstLetterPseudoElement::FirstLetterPseudoElement(Element* parent) | 166 FirstLetterPseudoElement::FirstLetterPseudoElement(Element* parent) |
| 167 : PseudoElement(parent, FIRST_LETTER) | 167 : PseudoElement(parent, PseudoIdFirstLetter) |
| 168 , m_remainingTextLayoutObject(nullptr) | 168 , m_remainingTextLayoutObject(nullptr) |
| 169 { | 169 { |
| 170 } | 170 } |
| 171 | 171 |
| 172 FirstLetterPseudoElement::~FirstLetterPseudoElement() | 172 FirstLetterPseudoElement::~FirstLetterPseudoElement() |
| 173 { | 173 { |
| 174 ASSERT(!m_remainingTextLayoutObject); | 174 ASSERT(!m_remainingTextLayoutObject); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void FirstLetterPseudoElement::updateTextFragments() | 177 void FirstLetterPseudoElement::updateTextFragments() |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 ComputedStyle* FirstLetterPseudoElement::styleForFirstLetter(LayoutObject* layou
tObjectContainer) | 236 ComputedStyle* FirstLetterPseudoElement::styleForFirstLetter(LayoutObject* layou
tObjectContainer) |
| 237 { | 237 { |
| 238 ASSERT(layoutObjectContainer); | 238 ASSERT(layoutObjectContainer); |
| 239 | 239 |
| 240 LayoutObject* styleContainer = parentOrShadowHostElement()->layoutObject(); | 240 LayoutObject* styleContainer = parentOrShadowHostElement()->layoutObject(); |
| 241 ASSERT(styleContainer); | 241 ASSERT(styleContainer); |
| 242 | 242 |
| 243 // We always force the pseudo style to recompute as the first-letter style | 243 // We always force the pseudo style to recompute as the first-letter style |
| 244 // computed by the style container may not have taken the layoutObjects styl
es | 244 // computed by the style container may not have taken the layoutObjects styl
es |
| 245 // into account. | 245 // into account. |
| 246 styleContainer->mutableStyle()->removeCachedPseudoStyle(FIRST_LETTER); | 246 styleContainer->mutableStyle()->removeCachedPseudoStyle(PseudoIdFirstLetter)
; |
| 247 | 247 |
| 248 ComputedStyle* pseudoStyle = styleContainer->getCachedPseudoStyle(FIRST_LETT
ER, layoutObjectContainer->firstLineStyle()); | 248 ComputedStyle* pseudoStyle = styleContainer->getCachedPseudoStyle(PseudoIdFi
rstLetter, layoutObjectContainer->firstLineStyle()); |
| 249 ASSERT(pseudoStyle); | 249 ASSERT(pseudoStyle); |
| 250 | 250 |
| 251 return pseudoStyle; | 251 return pseudoStyle; |
| 252 } | 252 } |
| 253 | 253 |
| 254 void FirstLetterPseudoElement::attachFirstLetterTextLayoutObjects() | 254 void FirstLetterPseudoElement::attachFirstLetterTextLayoutObjects() |
| 255 { | 255 { |
| 256 LayoutObject* nextLayoutObject = FirstLetterPseudoElement::firstLetterTextLa
youtObject(*this); | 256 LayoutObject* nextLayoutObject = FirstLetterPseudoElement::firstLetterTextLa
youtObject(*this); |
| 257 ASSERT(nextLayoutObject); | 257 ASSERT(nextLayoutObject); |
| 258 ASSERT(nextLayoutObject->isText()); | 258 ASSERT(nextLayoutObject->isText()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 { | 298 { |
| 299 if (!layoutObject()) | 299 if (!layoutObject()) |
| 300 return; | 300 return; |
| 301 | 301 |
| 302 // The layoutObjects inside pseudo elements are anonymous so they don't get
notified of recalcStyle and must have | 302 // The layoutObjects inside pseudo elements are anonymous so they don't get
notified of recalcStyle and must have |
| 303 // the style propagated downward manually similar to LayoutObject::propagate
StyleToAnonymousChildren. | 303 // the style propagated downward manually similar to LayoutObject::propagate
StyleToAnonymousChildren. |
| 304 LayoutObject* layoutObject = this->layoutObject(); | 304 LayoutObject* layoutObject = this->layoutObject(); |
| 305 for (LayoutObject* child = layoutObject->nextInPreOrder(layoutObject); child
; child = child->nextInPreOrder(layoutObject)) { | 305 for (LayoutObject* child = layoutObject->nextInPreOrder(layoutObject); child
; child = child->nextInPreOrder(layoutObject)) { |
| 306 // We need to re-calculate the correct style for the first letter elemen
t | 306 // We need to re-calculate the correct style for the first letter elemen
t |
| 307 // and then apply that to the container and the text fragment inside. | 307 // and then apply that to the container and the text fragment inside. |
| 308 if (child->style()->styleType() == FIRST_LETTER && m_remainingTextLayout
Object) { | 308 if (child->style()->styleType() == PseudoIdFirstLetter && m_remainingTex
tLayoutObject) { |
| 309 if (ComputedStyle* pseudoStyle = styleForFirstLetter(m_remainingText
LayoutObject->parent())) | 309 if (ComputedStyle* pseudoStyle = styleForFirstLetter(m_remainingText
LayoutObject->parent())) |
| 310 child->setPseudoStyle(pseudoStyle); | 310 child->setPseudoStyle(pseudoStyle); |
| 311 continue; | 311 continue; |
| 312 } | 312 } |
| 313 | 313 |
| 314 // We only manage the style for the generated content items. | 314 // We only manage the style for the generated content items. |
| 315 if (!child->isText() && !child->isQuote() && !child->isImage()) | 315 if (!child->isText() && !child->isQuote() && !child->isImage()) |
| 316 continue; | 316 continue; |
| 317 | 317 |
| 318 child->setPseudoStyle(layoutObject->mutableStyle()); | 318 child->setPseudoStyle(layoutObject->mutableStyle()); |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 } // namespace blink | 322 } // namespace blink |
| OLD | NEW |