Chromium Code Reviews| Index: Source/core/rendering/RenderBlock.cpp |
| diff --git a/Source/core/rendering/RenderBlock.cpp b/Source/core/rendering/RenderBlock.cpp |
| index fbd1d494c7b239d82916e9157fdf4fbe33c34109..68f9dd836b69c8c30bac6af85947faedd2760367 100644 |
| --- a/Source/core/rendering/RenderBlock.cpp |
| +++ b/Source/core/rendering/RenderBlock.cpp |
| @@ -5741,6 +5741,10 @@ static inline unsigned firstLetterLength(const String& text) |
| while (length < text.length() && shouldSkipForFirstLetter((text)[length])) |
| length++; |
| + // Bail if we didn't find a letter |
| + if (text.length() && length == text.length()) |
|
eseidel
2013/10/07 22:27:25
So when you just have <div>F<div> and a first-lett
leviw_travelin_and_unemployed
2013/10/07 22:33:19
Yup :)
In that case length will simply be 0 here.
|
| + return 0; |
| + |
| // Account for first letter. |
| length++; |
| @@ -5759,8 +5763,11 @@ static inline unsigned firstLetterLength(const String& text) |
| return length; |
| } |
| -void RenderBlock::createFirstLetterRenderer(RenderObject* firstLetterBlock, RenderObject* currentChild) |
| +void RenderBlock::createFirstLetterRenderer(RenderObject* firstLetterBlock, RenderObject* currentChild, unsigned length) |
| { |
| + ASSERT(length); |
| + ASSERT(currentChild->isText() && !toRenderText(currentChild)->isTextFragment()); |
| + |
| RenderObject* firstLetterContainer = currentChild->parent(); |
| RenderStyle* pseudoStyle = styleForFirstLetter(firstLetterBlock, firstLetterContainer); |
| RenderObject* firstLetter = 0; |
| @@ -5779,11 +5786,6 @@ void RenderBlock::createFirstLetterRenderer(RenderObject* firstLetterBlock, Rend |
| String oldText = textObj->originalText(); |
| ASSERT(oldText.impl()); |
| - unsigned length = firstLetterLength(oldText); |
| - |
| - if (!length) |
| - return; |
| - |
| // Construct a text fragment for the text after the first letter. |
| // This text fragment might be empty. |
| RenderTextFragment* remainingText = |
| @@ -5820,12 +5822,18 @@ void RenderBlock::updateFirstLetter() |
| // Drill into inlines looking for our first text child. |
| RenderObject* currChild = firstLetterBlock->firstChild(); |
| + unsigned length = 0; |
| while (currChild) { |
| - if (currChild->isText()) |
| - break; |
| - if (currChild->isListMarker()) |
| + if (currChild->isText()) { |
| + // FIXME: If there is leading punctuation in a different RenderText than |
| + // the first letter, we'll not apply the correct style to it. |
| + length = firstLetterLength(toRenderText(currChild)->originalText()); |
| + if (length) |
| + break; |
| + currChild = currChild->nextSibling(); |
| + } else if (currChild->isListMarker()) { |
| currChild = currChild->nextSibling(); |
| - else if (currChild->isFloatingOrOutOfFlowPositioned()) { |
| + } else if (currChild->isFloatingOrOutOfFlowPositioned()) { |
| if (currChild->style()->styleType() == FIRST_LETTER) { |
| currChild = currChild->firstChild(); |
| break; |
| @@ -5851,12 +5859,18 @@ void RenderBlock::updateFirstLetter() |
| if (!remainingText->isText() || remainingText->isBR()) |
| return; |
| + RenderText* newFirstText = toRenderText(remainingText); |
| + length = firstLetterLength(newFirstText->originalText()); |
| + |
| + if (!length) |
| + return; |
| + |
| LayoutStateDisabler layoutStateDisabler(view()); |
| if (RenderObject* oldRemainingText = toRenderBoxModelObject(currChild->parent())->firstLetterRemainingText()) |
| toRenderText(oldRemainingText)->setText(toText(oldRemainingText->node())->data().impl()); |
| - createFirstLetterRenderer(firstLetterBlock, remainingText); |
| + createFirstLetterRenderer(firstLetterBlock, newFirstText, length); |
| return; |
| } |
| @@ -5873,7 +5887,7 @@ void RenderBlock::updateFirstLetter() |
| // adding and removing children of firstLetterContainer. |
| LayoutStateDisabler layoutStateDisabler(view()); |
| - createFirstLetterRenderer(firstLetterBlock, currChild); |
| + createFirstLetterRenderer(firstLetterBlock, currChild, length); |
| } |
| // Helper methods for obtaining the last line, computing line counts and heights for line counts |