Commit e17f77ca authored by robhogan's avatar robhogan Committed by Commit bot

Apply first-line transform-text style

A third go at https://crrev.com/3c64df1fc98aa06eabfc18d1f5c2f2b0aec1a658

Although I still can't reproduce the clusterfuzz reports locally I'm confident
this will cure the specific crashes because I'm no longer transforming the
first line's text unless it has a distinct first-line style (:/).

BUG=129669,644733

Review-Url: https://codereview.chromium.org/2339683004
Cr-Commit-Position: refs/heads/master@{#418840}
parent 7928011b
<!DOCTYPE html>
<style>
p { width: 140px }
p::first-line { text-transform: capitalize; }
</style>
<p>This is a somewhat long HTML paragraph.</p>
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
<!DOCTYPE html>
<style>
p { width: 140px }
p::first-line { text-transform: lowercase; }
</style>
<p>This is a somewhat long HTML paragraph.</p>
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
<!DOCTYPE html>
<style>
p { width: 140px }
p::first-line { text-transform: uppercase; }
</style>
<p>This is a somewhat long HTML paragraph.</p>
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
...@@ -1414,6 +1414,33 @@ void applyTextTransform(const ComputedStyle* style, String& text, UChar previous ...@@ -1414,6 +1414,33 @@ void applyTextTransform(const ComputedStyle* style, String& text, UChar previous
} }
} }
void LayoutText::applyTextTransformFromTo(int from, int len, const ComputedStyle* style)
{
if (!style)
return;
if (m_text.isEmpty())
return;
String textToTransform = m_text.substring(from, len);
if (textToTransform.isEmpty())
return;
switch (style->textTransform()) {
case TTNONE:
break;
case CAPITALIZE:
makeCapitalized(&textToTransform, previousCharacter());
m_text.replace(from, len, textToTransform);
break;
case UPPERCASE:
m_text.replace(from, len, textToTransform.upper(style->locale()));
break;
case LOWERCASE:
m_text.replace(from, len, textToTransform.lower(style->locale()));
break;
}
}
void LayoutText::setTextInternal(PassRefPtr<StringImpl> text) void LayoutText::setTextInternal(PassRefPtr<StringImpl> text)
{ {
ASSERT(text); ASSERT(text);
......
...@@ -181,6 +181,7 @@ public: ...@@ -181,6 +181,7 @@ public:
float hyphenWidth(const Font&, TextDirection); float hyphenWidth(const Font&, TextDirection);
void applyTextTransformFromTo(int from, int len, const ComputedStyle*);
protected: protected:
void willBeDestroyed() override; void willBeDestroyed() override;
......
...@@ -154,6 +154,11 @@ public: ...@@ -154,6 +154,11 @@ public:
return toText()->minLogicalWidth(); return toText()->minLogicalWidth();
} }
void applyTextTransformFromTo(int from, int len, const ComputedStyle* style)
{
toText()->applyTextTransformFromTo(from, len, style);
}
private: private:
LayoutText* toText() { return toLayoutText(layoutObject()); } LayoutText* toText() { return toLayoutText(layoutObject()); }
const LayoutText* toText() const { return toLayoutText(layoutObject()); } const LayoutText* toText() const { return toLayoutText(layoutObject()); }
......
...@@ -125,6 +125,8 @@ void InlineFlowBox::addToLine(InlineBox* child) ...@@ -125,6 +125,8 @@ void InlineFlowBox::addToLine(InlineBox* child)
} }
if (childStyle.hasTextCombine() || childStyle.getTextEmphasisMark() != TextEmphasisMarkNone) if (childStyle.hasTextCombine() || childStyle.getTextEmphasisMark() != TextEmphasisMarkNone)
shouldClearDescendantsHaveSameLineHeightAndBaseline = true; shouldClearDescendantsHaveSameLineHeightAndBaseline = true;
if (child->isInlineTextBox() && isFirstLineStyle() && childStyle.textTransform() != child->getLineLayoutItem().styleRef(false).textTransform())
toInlineTextBox(child)->transformText();
} else { } else {
if (child->getLineLayoutItem().isBR()) { if (child->getLineLayoutItem().isBR()) {
// FIXME: This is dumb. We only turn off because current layout test results expect the <br> to be 0-height on the baseline. // FIXME: This is dumb. We only turn off because current layout test results expect the <br> to be 0-height on the baseline.
......
...@@ -607,6 +607,11 @@ String InlineTextBox::text() const ...@@ -607,6 +607,11 @@ String InlineTextBox::text() const
return getLineLayoutItem().text().substring(start(), len()); return getLineLayoutItem().text().substring(start(), len());
} }
void InlineTextBox::transformText()
{
getLineLayoutItem().applyTextTransformFromTo(start(), len(), getLineLayoutItem().style(isFirstLineStyle()));
}
#ifndef NDEBUG #ifndef NDEBUG
void InlineTextBox::showBox(int printedCharacters) const void InlineTextBox::showBox(int printedCharacters) const
......
...@@ -100,6 +100,7 @@ public: ...@@ -100,6 +100,7 @@ public:
String text() const; String text() const;
void transformText();
public: public:
TextRun constructTextRunForInspector(const ComputedStyle&) const; TextRun constructTextRunForInspector(const ComputedStyle&) const;
LayoutRect calculateBoundaries() const override { return LayoutRect(x(), y(), width(), height()); } LayoutRect calculateBoundaries() const override { return LayoutRect(x(), y(), width(), height()); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment