Title: [183904] trunk/Source/WebCore
Revision
183904
Author
mmaxfi...@apple.com
Date
2015-05-06 19:09:26 -0700 (Wed, 06 May 2015)

Log Message

Clean up TextRun constructors
https://bugs.webkit.org/show_bug.cgi?id=144712

Reviewed by Zalan Bujtas.

This patch uses constructor forwarding to make TextRun's constructors much simpler. It then
updates the implementations of RenderBlock::constructTextRun() to be more consistent with
TextRun (via using StringViews).

No new tests because there is no behavior change.

* mathml/MathMLMencloseElement.cpp:
(WebCore::MathMLMencloseElement::longDivLeftPadding):
* platform/graphics/TextRun.h:
(WebCore::TextRun::TextRun):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::constructTextRun):
(WebCore::constructTextRunInternal): Deleted.
* rendering/RenderBlock.h:
* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::paintReplaced):
(WebCore::RenderEmbeddedObject::unavailablePluginIndicatorBounds):
(WebCore::RenderEmbeddedObject::isInUnavailablePluginIndicator):
* rendering/svg/SVGTextMetricsBuilder.cpp:
(WebCore::SVGTextMetricsBuilder::SVGTextMetricsBuilder):
* platform/win/DragImageWin.cpp:
(WebCore::createDragImageForLink):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (183903 => 183904)


--- trunk/Source/WebCore/ChangeLog	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/ChangeLog	2015-05-07 02:09:26 UTC (rev 183904)
@@ -1,3 +1,33 @@
+2015-05-06  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Clean up TextRun constructors
+        https://bugs.webkit.org/show_bug.cgi?id=144712
+
+        Reviewed by Zalan Bujtas.
+
+        This patch uses constructor forwarding to make TextRun's constructors much simpler. It then
+        updates the implementations of RenderBlock::constructTextRun() to be more consistent with
+        TextRun (via using StringViews).
+
+        No new tests because there is no behavior change.
+
+        * mathml/MathMLMencloseElement.cpp:
+        (WebCore::MathMLMencloseElement::longDivLeftPadding):
+        * platform/graphics/TextRun.h:
+        (WebCore::TextRun::TextRun):
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::constructTextRun):
+        (WebCore::constructTextRunInternal): Deleted.
+        * rendering/RenderBlock.h:
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::paintReplaced):
+        (WebCore::RenderEmbeddedObject::unavailablePluginIndicatorBounds):
+        (WebCore::RenderEmbeddedObject::isInUnavailablePluginIndicator):
+        * rendering/svg/SVGTextMetricsBuilder.cpp:
+        (WebCore::SVGTextMetricsBuilder::SVGTextMetricsBuilder):
+        * platform/win/DragImageWin.cpp:
+        (WebCore::createDragImageForLink):
+
 2015-05-06  Sungmann Cho  <sungmann....@navercorp.com>
 
         Rename URL::copy() to URL::isolatedCopy() to match String.

Modified: trunk/Source/WebCore/mathml/MathMLMencloseElement.cpp (183903 => 183904)


--- trunk/Source/WebCore/mathml/MathMLMencloseElement.cpp	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/mathml/MathMLMencloseElement.cpp	2015-05-07 02:09:26 UTC (rev 183904)
@@ -129,8 +129,8 @@
 String MathMLMencloseElement::longDivLeftPadding() const
 {
     StringBuilder padding;
-    String closingBrace = ")";
-    TextRun run(closingBrace.impl(), closingBrace.length());
+    String closingBrace(")", String::ConstructFromLiteral);
+    TextRun run(closingBrace);
     Node* node = parentNode();
     if (node && node->renderer()) {
         const FontCascade& font = node->renderer()->style().fontCascade();

Modified: trunk/Source/WebCore/platform/graphics/TextRun.h (183903 => 183904)


--- trunk/Source/WebCore/platform/graphics/TextRun.h	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/platform/graphics/TextRun.h	2015-05-07 02:09:26 UTC (rev 183904)
@@ -52,9 +52,9 @@
 
     typedef unsigned RoundingHacks;
 
-    TextRun(const LChar* c, unsigned len, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
-        : m_text(c, len)
-        , m_charactersLength(len)
+    explicit TextRun(StringView s, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
+        : m_text(s)
+        , m_charactersLength(s.length())
         , m_tabSize(0)
         , m_xpos(xpos)
         , m_horizontalGlyphStretch(1)
@@ -70,57 +70,18 @@
     {
     }
 
-    TextRun(const UChar* c, unsigned len, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
-        : m_text(c, len)
-        , m_charactersLength(len)
-        , m_tabSize(0)
-        , m_xpos(xpos)
-        , m_horizontalGlyphStretch(1)
-        , m_expansion(expansion)
-        , m_expansionBehavior(expansionBehavior)
-        , m_allowTabs(false)
-        , m_direction(direction)
-        , m_directionalOverride(directionalOverride)
-        , m_characterScanForCodePath(characterScanForCodePath)
-        , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHacks)
-        , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks)
-        , m_disableSpacing(false)
+    explicit TextRun(const String& s)
+        : TextRun(StringView(s))
     {
     }
-    
-    explicit TextRun(const String& s, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
-        : m_text(StringView(s))
-        , m_charactersLength(s.length())
-        , m_tabSize(0)
-        , m_xpos(xpos)
-        , m_horizontalGlyphStretch(1)
-        , m_expansion(expansion)
-        , m_expansionBehavior(expansionBehavior)
-        , m_allowTabs(false)
-        , m_direction(direction)
-        , m_directionalOverride(directionalOverride)
-        , m_characterScanForCodePath(characterScanForCodePath)
-        , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHacks)
-        , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks)
-        , m_disableSpacing(false)
+
+    TextRun(const LChar* c, unsigned len)
+        : TextRun(StringView(c, len))
     {
     }
 
-    explicit TextRun(StringView s, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
-        : m_text(s)
-        , m_charactersLength(s.length())
-        , m_tabSize(0)
-        , m_xpos(xpos)
-        , m_horizontalGlyphStretch(1)
-        , m_expansion(expansion)
-        , m_expansionBehavior(expansionBehavior)
-        , m_allowTabs(false)
-        , m_direction(direction)
-        , m_directionalOverride(directionalOverride)
-        , m_characterScanForCodePath(characterScanForCodePath)
-        , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHacks)
-        , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks)
-        , m_disableSpacing(false)
+    TextRun(const UChar* c, unsigned len)
+        : TextRun(StringView(c, len))
     {
     }
 
@@ -213,7 +174,8 @@
 
     // m_xpos is the x position relative to the left start of the text line, not relative to the left
     // start of the containing block. In the case of right alignment or center alignment, left start of
-    // the text line is not the same as left start of the containing block.
+    // the text line is not the same as left start of the containing block. This variable is only used
+    // to calculate the width of \t
     float m_xpos;  
     float m_horizontalGlyphStretch;
 

Modified: trunk/Source/WebCore/platform/win/DragImageWin.cpp (183903 => 183904)


--- trunk/Source/WebCore/platform/win/DragImageWin.cpp	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/platform/win/DragImageWin.cpp	2015-05-07 02:09:26 UTC (rev 183904)
@@ -150,8 +150,8 @@
     }
 
     // First step in drawing the link drag image width.
-    TextRun labelRun(label.impl());
-    TextRun urlRun(urlString.impl());
+    TextRun labelRun(label);
+    TextRun urlRun(urlString);
     IntSize labelSize(labelFont->width(labelRun), labelFont->fontMetrics().ascent() + labelFont->fontMetrics().descent());
 
     if (labelSize.width() > MaxDragLabelStringWidth) {

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (183903 => 183904)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2015-05-07 02:09:26 UTC (rev 183904)
@@ -3674,33 +3674,17 @@
     return "RenderBlock";
 }
 
-template <typename CharacterType>
-static inline TextRun constructTextRunInternal(RenderObject* context, const FontCascade& font, const CharacterType* characters, int length, const RenderStyle& style, ExpansionBehavior expansion)
+TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, StringView stringView, const RenderStyle& style, ExpansionBehavior expansion, TextRunFlags flags)
 {
     TextDirection textDirection = LTR;
     bool directionalOverride = style.rtlOrdering() == VisualOrder;
-
-    TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
-    if (font.primaryFont().isSVGFont()) {
-        ASSERT(context); // FIXME: Thread a RenderObject& to this point so we don't have to dereference anything.
-        run.setRenderingContext(SVGTextRunRenderingContext::create(*context));
-    }
-
-    return run;
-}
-
-template <typename CharacterType>
-static inline TextRun constructTextRunInternal(RenderObject* context, const FontCascade& font, const CharacterType* characters, int length, const RenderStyle& style, ExpansionBehavior expansion, TextRunFlags flags)
-{
-    TextDirection textDirection = LTR;
-    bool directionalOverride = style.rtlOrdering() == VisualOrder;
     if (flags != DefaultTextRunFlags) {
         if (flags & RespectDirection)
             textDirection = style.direction();
         if (flags & RespectDirectionOverride)
             directionalOverride |= isOverride(style.unicodeBidi());
     }
-    TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
+    TextRun run(stringView, 0, 0, expansion, textDirection, directionalOverride);
     if (font.primaryFont().isSVGFont()) {
         ASSERT(context); // FIXME: Thread a RenderObject& to this point so we don't have to dereference anything.
         run.setRenderingContext(SVGTextRunRenderingContext::create(*context));
@@ -3709,38 +3693,31 @@
     return run;
 }
 
-TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const LChar* characters, int length, const RenderStyle& style, ExpansionBehavior expansion)
+TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const String& string, const RenderStyle& style, ExpansionBehavior expansion, TextRunFlags flags)
 {
-    return constructTextRunInternal(context, font, characters, length, style, expansion);
+    return constructTextRun(context, font, StringView(string), style, expansion, flags);
 }
 
-TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const UChar* characters, int length, const RenderStyle& style, ExpansionBehavior expansion)
-{
-    return constructTextRunInternal(context, font, characters, length, style, expansion);
-}
-
 TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const RenderText* text, const RenderStyle& style, ExpansionBehavior expansion)
 {
-    if (text->is8Bit())
-        return constructTextRunInternal(context, font, text->characters8(), text->textLength(), style, expansion);
-    return constructTextRunInternal(context, font, text->characters16(), text->textLength(), style, expansion);
+    return constructTextRun(context, font, text->stringView(), style, expansion);
 }
 
 TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const RenderText* text, unsigned offset, unsigned length, const RenderStyle& style, ExpansionBehavior expansion)
 {
-    ASSERT(offset + length <= text->textLength());
-    if (text->is8Bit())
-        return constructTextRunInternal(context, font, text->characters8() + offset, length, style, expansion);
-    return constructTextRunInternal(context, font, text->characters16() + offset, length, style, expansion);
+    unsigned stop = offset + length;
+    ASSERT(stop <= text->textLength());
+    return constructTextRun(context, font, text->stringView(offset, stop), style, expansion);
 }
 
-TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const String& string, const RenderStyle& style, ExpansionBehavior expansion, TextRunFlags flags)
+TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const LChar* characters, int length, const RenderStyle& style, ExpansionBehavior expansion)
 {
-    unsigned length = string.length();
+    return constructTextRun(context, font, StringView(characters, length), style, expansion);
+}
 
-    if (!length || string.is8Bit())
-        return constructTextRunInternal(context, font, string.characters8(), length, style, expansion, flags);
-    return constructTextRunInternal(context, font, string.characters16(), length, style, expansion, flags);
+TextRun RenderBlock::constructTextRun(RenderObject* context, const FontCascade& font, const UChar* characters, int length, const RenderStyle& style, ExpansionBehavior expansion)
+{
+    return constructTextRun(context, font, StringView(characters, length), style, expansion);
 }
 
 RenderBlock* RenderBlock::createAnonymousWithParentRendererAndDisplay(const RenderObject* parent, EDisplay display)

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (183903 => 183904)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2015-05-07 02:09:26 UTC (rev 183904)
@@ -204,21 +204,16 @@
         return obj->isFloating() || (obj->isOutOfFlowPositioned() && !obj->style().isOriginalDisplayInlineType() && !obj->container()->isRenderInline());
     }
 
+    static TextRun constructTextRun(RenderObject* context, const FontCascade&, StringView, const RenderStyle&,
+        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextRunFlags = DefaultTextRunFlags);
     static TextRun constructTextRun(RenderObject* context, const FontCascade&, const String&, const RenderStyle&,
         ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextRunFlags = DefaultTextRunFlags);
-
     static TextRun constructTextRun(RenderObject* context, const FontCascade&, const RenderText*, const RenderStyle&,
         ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
-
     static TextRun constructTextRun(RenderObject* context, const FontCascade&, const RenderText*, unsigned offset, unsigned length, const RenderStyle&,
         ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
-
-    static TextRun constructTextRun(RenderObject* context, const FontCascade&, const RenderText*, unsigned offset, const RenderStyle&,
-        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
-
     static TextRun constructTextRun(RenderObject* context, const FontCascade&, const LChar* characters, int length, const RenderStyle&,
         ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
-
     static TextRun constructTextRun(RenderObject* context, const FontCascade&, const UChar* characters, int length, const RenderStyle&,
         ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
     

Modified: trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp (183903 => 183904)


--- trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp	2015-05-07 02:09:26 UTC (rev 183904)
@@ -302,7 +302,7 @@
     FloatRect replacementTextRect;
     FloatRect arrowRect;
     FontCascade font;
-    TextRun run("");
+    TextRun run(emptyString());
     float textWidth;
     if (!getReplacementTextGeometry(paintOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
         return;
@@ -395,7 +395,7 @@
     FloatRect replacementTextRect;
     FloatRect arrowRect;
     FontCascade font;
-    TextRun run("", 0);
+    TextRun run(emptyString());
     float textWidth;
     if (getReplacementTextGeometry(accumulatedOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
         return LayoutRect(indicatorRect);
@@ -586,7 +586,7 @@
     FloatRect replacementTextRect;
     FloatRect arrowRect;
     FontCascade font;
-    TextRun run("");
+    TextRun run(emptyString());
     float textWidth;
     return getReplacementTextGeometry(IntPoint(), contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth)
         && indicatorRect.contains(point);

Modified: trunk/Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp (183903 => 183904)


--- trunk/Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp	2015-05-07 01:23:12 UTC (rev 183903)
+++ trunk/Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp	2015-05-07 02:09:26 UTC (rev 183904)
@@ -29,7 +29,7 @@
 
 SVGTextMetricsBuilder::SVGTextMetricsBuilder()
     : m_text(0)
-    , m_run(static_cast<const UChar*>(0), 0)
+    , m_run(StringView())
     , m_textPosition(0)
     , m_isComplexText(false)
     , m_totalWidth(0)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to