⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 183996 in webkit


Ignore:
Timestamp:
May 8, 2015, 10:18:00 AM (11 years ago)
Author:
mmaxfield@apple.com
Message:

Remove convenience constructors for TextRun
https://bugs.webkit.org/show_bug.cgi?id=144752

Source/WebCore:

These convenience constructors are unnecessary. Moving the code that makes the StringView
back to the call site will also help us make things more elegant in future refactoring.

Reviewed by Darin Adler.

No new tests because there is no behavior change.

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText): Remove ambiguous call.

  • platform/graphics/StringTruncator.cpp:

(WebCore::stringWidth):

  • platform/graphics/TextRun.h:

(WebCore::TextRun::TextRun):

  • platform/mac/DragImageMac.mm:

(WebCore::widthWithFont):
(WebCore::drawAtPoint):

  • rendering/SimpleLineLayout.cpp:

(WebCore::SimpleLineLayout::canUseFor):

  • rendering/SimpleLineLayoutTextFragmentIterator.cpp:

(WebCore::SimpleLineLayout::TextFragmentIterator::Style::Style):
(WebCore::SimpleLineLayout::TextFragmentIterator::runWidth):

  • rendering/TextPainter.cpp:

(WebCore::TextPainter::paintText):

Source/WebKit/mac:

These convenience constructors are unnecessary. Moving the code that makes the StringView
back to the call site will also help us make things more elegant in future refactoring.

Reviewed by Darin Adler.

No new tests because there is no behavior change.

  • Misc/WebKitNSStringExtras.mm:

(-[NSString _web_drawAtPoint:font:textColor:allowingFontSmoothing:]):
(-[NSString _web_widthWithFont:]):

Source/WTF:

Reviewed by Anders Carlsson.

No reason why StringView shouldn't have a StringImpl* constructor.

Test: StringView8Bit in TestWebKitAPI

  • wtf/text/StringView.h: Add the constructor.

Tools:

Reviewed by Anders Carlsson.

Test the StringView which takes a StringImpl*.

  • TestWebKitAPI/Tests/WTF/StringView.cpp:

(StringView8Bit): Testing is8Bit() on StringView

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r183988 r183996  
     12015-05-08  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Remove convenience constructors for TextRun
     4        https://bugs.webkit.org/show_bug.cgi?id=144752
     5
     6        Reviewed by Anders Carlsson.
     7
     8        No reason why StringView shouldn't have a StringImpl* constructor.
     9
     10        Test: StringView8Bit in TestWebKitAPI
     11
     12        * wtf/text/StringView.h: Add the constructor.
     13
    1142015-05-08  Andreas Kling  <akling@apple.com>
    215
  • trunk/Source/WTF/wtf/text/StringView.h

    r181845 r183996  
    5959    StringView(const String&);
    6060    StringView(const StringImpl&);
     61    StringView(const StringImpl*);
    6162    StringView(const LChar*, unsigned length);
    6263    StringView(const UChar*, unsigned length);
     
    270271    else
    271272        initialize(string.characters16(), string.length());
     273}
     274
     275inline StringView::StringView(const StringImpl* string)
     276{
     277    if (!string)
     278        return;
     279
     280    setUnderlyingString(string);
     281    if (string->is8Bit())
     282        initialize(string->characters8(), string->length());
     283    else
     284        initialize(string->characters16(), string->length());
    272285}
    273286
  • trunk/Source/WebCore/ChangeLog

    r183991 r183996  
     12015-05-08  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Remove convenience constructors for TextRun
     4        https://bugs.webkit.org/show_bug.cgi?id=144752
     5
     6        These convenience constructors are unnecessary. Moving the code that makes the StringView
     7        back to the call site will also help us make things more elegant in future refactoring.
     8
     9        Reviewed by Darin Adler.
     10
     11        No new tests because there is no behavior change.
     12
     13        * css/CSSPrimitiveValue.cpp:
     14        (WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText): Remove ambiguous call.
     15        * platform/graphics/StringTruncator.cpp:
     16        (WebCore::stringWidth):
     17        * platform/graphics/TextRun.h:
     18        (WebCore::TextRun::TextRun):
     19        * platform/mac/DragImageMac.mm:
     20        (WebCore::widthWithFont):
     21        (WebCore::drawAtPoint):
     22        * rendering/SimpleLineLayout.cpp:
     23        (WebCore::SimpleLineLayout::canUseFor):
     24        * rendering/SimpleLineLayoutTextFragmentIterator.cpp:
     25        (WebCore::SimpleLineLayout::TextFragmentIterator::Style::Style):
     26        (WebCore::SimpleLineLayout::TextFragmentIterator::runWidth):
     27        * rendering/TextPainter.cpp:
     28        (WebCore::TextPainter::paintText):
     29
    1302015-05-08  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr>
    231
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r182354 r183996  
    10521052        result.reserveCapacity(6 + m_value.string->length());
    10531053        result.appendLiteral("attr(");
    1054         result.append(m_value.string);
     1054        result.append(String(m_value.string));
    10551055        result.append(')');
    10561056
  • trunk/Source/WebCore/platform/graphics/StringTruncator.cpp

    r178510 r183996  
    195195static float stringWidth(const FontCascade& renderer, const UChar* characters, unsigned length, bool disableRoundingHacks)
    196196{
    197     TextRun run(characters, length);
     197    TextRun run(StringView(characters, length));
    198198    if (disableRoundingHacks)
    199199        run.disableRoundingHacks();
  • trunk/Source/WebCore/platform/graphics/TextRun.h

    r183904 r183996  
    5353    typedef unsigned RoundingHacks;
    5454
    55     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)
    56         : m_text(s)
    57         , m_charactersLength(s.length())
     55    explicit TextRun(StringView text, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
     56        : m_text(text)
     57        , m_charactersLength(text.length())
    5858        , m_tabSize(0)
    5959        , m_xpos(xpos)
     
    6868        , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks)
    6969        , m_disableSpacing(false)
    70     {
    71     }
    72 
    73     explicit TextRun(const String& s)
    74         : TextRun(StringView(s))
    75     {
    76     }
    77 
    78     TextRun(const LChar* c, unsigned len)
    79         : TextRun(StringView(c, len))
    80     {
    81     }
    82 
    83     TextRun(const UChar* c, unsigned len)
    84         : TextRun(StringView(c, len))
    8570    {
    8671    }
  • trunk/Source/WebCore/platform/mac/DragImageMac.mm

    r183269 r183996  
    193193    if (canUseFastRenderer(buffer.data(), length)) {
    194194        FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
    195         TextRun run(buffer.data(), length);
     195        TextRun run(StringView(buffer.data(), length));
    196196        run.disableRoundingHacks();
    197197        return webCoreFont.width(run);
     
    225225           
    226226        FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]), Antialiased);
    227         TextRun run(buffer.data(), length);
     227        TextRun run(StringView(buffer.data(), length));
    228228        run.disableRoundingHacks();
    229229
  • trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp

    r183576 r183996  
    4141    , wrapLines(style.autoWrap())
    4242    , breakWordOnOverflow(style.overflowWrap() == BreakOverflowWrap && (wrapLines || preserveNewline))
    43     , spaceWidth(font.width(TextRun(&space, 1)))
     43    , spaceWidth(font.width(TextRun(StringView(&space, 1))))
    4444    , tabWidth(collapseWhitespace ? 0 : style.tabSize())
    4545    , locale(style.locale())
     
    198198    if (measureWithEndSpace)
    199199        ++segmentTo;
    200     TextRun run(segment.text.characters<CharacterType>() + segmentFrom, segmentTo - segmentFrom);
     200    TextRun run(StringView(segment.text.substring(segmentFrom, segmentTo - segmentFrom)));
    201201    run.setXPos(xPosition);
    202202    run.setTabSize(!!m_style.tabWidth, m_style.tabWidth);
  • trunk/Source/WebCore/rendering/TextPainter.cpp

    r178510 r183996  
    171171            updateGraphicsContext(m_context, m_textPaintStyle, UseEmphasisMarkColor);
    172172
    173             static NeverDestroyed<TextRun> objectReplacementCharacterTextRun(&objectReplacementCharacter, 1);
     173            static NeverDestroyed<TextRun> objectReplacementCharacterTextRun(StringView(&objectReplacementCharacter, 1));
    174174            TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun.get() : m_textRun;
    175175            FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + m_boxRect.width() / 2, boxOrigin.y() + m_font.fontMetrics().ascent()) : m_textOrigin;
     
    197197            updateGraphicsContext(m_context, m_selectionPaintStyle, UseEmphasisMarkColor);
    198198
    199             DEPRECATED_DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
     199            DEPRECATED_DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (StringView(&objectReplacementCharacter, 1)));
    200200            TextRun& emphasisMarkTextRun = m_combinedText ? objectReplacementCharacterTextRun : m_textRun;
    201201            FloatPoint emphasisMarkTextOrigin = m_combinedText ? FloatPoint(boxOrigin.x() + m_boxRect.width() / 2, boxOrigin.y() + m_font.fontMetrics().ascent()) : m_textOrigin;
  • trunk/Source/WebKit/mac/ChangeLog

    r183976 r183996  
     12015-05-08  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Remove convenience constructors for TextRun
     4        https://bugs.webkit.org/show_bug.cgi?id=144752
     5
     6        These convenience constructors are unnecessary. Moving the code that makes the StringView
     7        back to the call site will also help us make things more elegant in future refactoring.
     8
     9        Reviewed by Darin Adler.
     10
     11        No new tests because there is no behavior change.
     12
     13        * Misc/WebKitNSStringExtras.mm:
     14        (-[NSString _web_drawAtPoint:font:textColor:allowingFontSmoothing:]):
     15        (-[NSString _web_widthWithFont:]):
     16
    1172015-05-07  Anders Carlsson  <andersca@apple.com>
    218
  • trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm

    r183269 r183996  
    9494
    9595        FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]), fontSmoothingIsAllowed ? AutoSmoothing : Antialiased);
    96         TextRun run(buffer.data(), length);
     96        TextRun run(StringView(buffer.data(), length));
    9797        run.disableRoundingHacks();
    9898
     
    140140    if (canUseFastRenderer(buffer.data(), length)) {
    141141        FontCascade webCoreFont(FontPlatformData(reinterpret_cast<CTFontRef>(font), [font pointSize]));
    142         TextRun run(buffer.data(), length);
     142        TextRun run(StringView(buffer.data(), length));
    143143        run.disableRoundingHacks();
    144144        return webCoreFont.width(run);
  • trunk/Tools/ChangeLog

    r183995 r183996  
     12015-05-08  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Remove convenience constructors for TextRun
     4        https://bugs.webkit.org/show_bug.cgi?id=144752
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Test the StringView which takes a StringImpl*.
     9
     10        * TestWebKitAPI/Tests/WTF/StringView.cpp:
     11        (StringView8Bit): Testing is8Bit() on StringView
     12
    1132015-05-08  Carlos Garcia Campos  <cgarcia@igalia.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp

    r181845 r183996  
    698698}
    699699
     700TEST(WTF, StringView8Bit)
     701{
     702    StringView nullView;
     703    StringView emptyView = StringView::empty();
     704    EXPECT_TRUE(StringView().is8Bit());
     705    EXPECT_TRUE(StringView::empty().is8Bit());
     706
     707    LChar* lcharPtr = nullptr;
     708    UChar* ucharPtr = nullptr;
     709    EXPECT_TRUE(StringView(lcharPtr, 0).is8Bit());
     710    EXPECT_FALSE(StringView(ucharPtr, 0).is8Bit());
     711
     712    EXPECT_TRUE(StringView(String(lcharPtr, 0)).is8Bit());
     713    EXPECT_TRUE(StringView(String(ucharPtr, 0)).is8Bit());
     714
     715    EXPECT_TRUE(StringView(String().impl()).is8Bit());
     716    EXPECT_TRUE(StringView(emptyString().impl()).is8Bit());
     717}
     718
    700719} // namespace TestWebKitAPI
Note: See TracChangeset for help on using the changeset viewer.