Clean up TextRun-related code
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2016 07:37:19 +0000 (07:37 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2016 07:37:19 +0000 (07:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161473

Reviewed by Simon Fraser.

Source/WebCore:

Some assorted cleanup, including:
- Renaming "AllowTrailingExpansion | ForbidLeadingExpansion" to "DefaultExpansion"
- Migrating from pointers to references
- Migrating from ints to unsigneds
- Using proper character names from CharacterNames.h
- Simplifying CoreTextSPI.h

No new tests because there is no behavior change.

* platform/graphics/TextRun.h:
(WebCore::TextRun::TextRun):
* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::TextLayout::isNeeded):
(WebCore::TextLayout::constructTextRun):
* platform/spi/cocoa/CoreTextSPI.h:
* platform/text/TextFlags.h:
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::constructTextRun):
* rendering/RenderBlock.h:
* rendering/RenderListMarker.cpp:
(WebCore::RenderListMarker::computePreferredLogicalWidths):
(WebCore::RenderListMarker::getRelativeMarkerRect):
* rendering/RenderMenuList.cpp:
(RenderMenuList::updateOptionsWidth):
* rendering/RenderText.cpp:
(WebCore::RenderText::widthFromCache):
(WebCore::RenderText::trimmedPrefWidths):
(WebCore::hyphenWidth):
(WebCore::maxWordFragmentWidth):
(WebCore::RenderText::computePreferredLogicalWidths):
(WebCore::RenderText::width):
* rendering/RenderText.h:
* rendering/RenderThemeIOS.mm:
* rendering/line/BreakingContext.h:
(WebCore::textWidth):
(WebCore::tryHyphenating):
* rendering/svg/SVGInlineTextBox.cpp:
(WebCore::SVGInlineTextBox::offsetForPositionInFragment):
(WebCore::SVGInlineTextBox::selectionRectForTextFragment):
(WebCore::SVGInlineTextBox::localSelectionRect):
(WebCore::SVGInlineTextBox::paintSelectionBackground):
(WebCore::SVGInlineTextBox::paint):
(WebCore::SVGInlineTextBox::acquirePaintingResource):
(WebCore::SVGInlineTextBox::prepareGraphicsContextForTextPainting):
(WebCore::SVGInlineTextBox::constructTextRun):
(WebCore::SVGInlineTextBox::paintDecorationWithStyle):
(WebCore::SVGInlineTextBox::paintTextWithShadows):
(WebCore::SVGInlineTextBox::paintText):
* rendering/svg/SVGInlineTextBox.h:

Source/WebKit/mac:

Remove unused #includes.

* WebCoreSupport/WebDragClient.mm:
* WebView/WebView.mm:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205282 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/TextRun.h
Source/WebCore/platform/graphics/mac/ComplexTextController.cpp
Source/WebCore/platform/spi/cocoa/CoreTextSPI.h
Source/WebCore/platform/text/TextFlags.h
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBlock.h
Source/WebCore/rendering/RenderListMarker.cpp
Source/WebCore/rendering/RenderMenuList.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderText.h
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/line/BreakingContext.h
Source/WebCore/rendering/svg/SVGInlineTextBox.cpp
Source/WebCore/rendering/svg/SVGInlineTextBox.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebDragClient.mm
Source/WebKit/mac/WebView/WebView.mm

index f4b8ba4..146aa2e 100644 (file)
@@ -1,3 +1,60 @@
+2016-09-01  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Clean up TextRun-related code
+        https://bugs.webkit.org/show_bug.cgi?id=161473
+
+        Reviewed by Simon Fraser.
+
+        Some assorted cleanup, including:
+        - Renaming "AllowTrailingExpansion | ForbidLeadingExpansion" to "DefaultExpansion"
+        - Migrating from pointers to references
+        - Migrating from ints to unsigneds
+        - Using proper character names from CharacterNames.h
+        - Simplifying CoreTextSPI.h
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/TextRun.h:
+        (WebCore::TextRun::TextRun):
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::TextLayout::isNeeded):
+        (WebCore::TextLayout::constructTextRun):
+        * platform/spi/cocoa/CoreTextSPI.h:
+        * platform/text/TextFlags.h:
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::constructTextRun):
+        * rendering/RenderBlock.h:
+        * rendering/RenderListMarker.cpp:
+        (WebCore::RenderListMarker::computePreferredLogicalWidths):
+        (WebCore::RenderListMarker::getRelativeMarkerRect):
+        * rendering/RenderMenuList.cpp:
+        (RenderMenuList::updateOptionsWidth):
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::widthFromCache):
+        (WebCore::RenderText::trimmedPrefWidths):
+        (WebCore::hyphenWidth):
+        (WebCore::maxWordFragmentWidth):
+        (WebCore::RenderText::computePreferredLogicalWidths):
+        (WebCore::RenderText::width):
+        * rendering/RenderText.h:
+        * rendering/RenderThemeIOS.mm:
+        * rendering/line/BreakingContext.h:
+        (WebCore::textWidth):
+        (WebCore::tryHyphenating):
+        * rendering/svg/SVGInlineTextBox.cpp:
+        (WebCore::SVGInlineTextBox::offsetForPositionInFragment):
+        (WebCore::SVGInlineTextBox::selectionRectForTextFragment):
+        (WebCore::SVGInlineTextBox::localSelectionRect):
+        (WebCore::SVGInlineTextBox::paintSelectionBackground):
+        (WebCore::SVGInlineTextBox::paint):
+        (WebCore::SVGInlineTextBox::acquirePaintingResource):
+        (WebCore::SVGInlineTextBox::prepareGraphicsContextForTextPainting):
+        (WebCore::SVGInlineTextBox::constructTextRun):
+        (WebCore::SVGInlineTextBox::paintDecorationWithStyle):
+        (WebCore::SVGInlineTextBox::paintTextWithShadows):
+        (WebCore::SVGInlineTextBox::paintText):
+        * rendering/svg/SVGInlineTextBox.h:
+
 2016-08-31  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Move GObject DOM bindings to WebKit2 layer and stop auto generating them
index 77dee3b..a80fe7e 100644 (file)
@@ -45,7 +45,7 @@ struct WidthIterator;
 class TextRun {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit TextRun(StringView text, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true)
+    explicit TextRun(StringView text, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = DefaultExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true)
         : m_text(text)
         , m_charactersLength(text.length())
         , m_tabSize(0)
index 5f2b32f..b1369cb 100644 (file)
@@ -51,7 +51,7 @@ class TextLayout {
 public:
     static bool isNeeded(RenderText& text, const FontCascade& font)
     {
-        TextRun run = RenderBlock::constructTextRun(&text, text.style());
+        TextRun run = RenderBlock::constructTextRun(text, text.style());
         return font.codePath(run) == FontCascade::Complex;
     }
 
@@ -76,7 +76,7 @@ public:
 private:
     static TextRun constructTextRun(RenderText& text, float xPos)
     {
-        TextRun run = RenderBlock::constructTextRun(&text, text.style());
+        TextRun run = RenderBlock::constructTextRun(text, text.style());
         run.setCharactersLength(text.textLength());
         ASSERT(run.charactersLength() >= run.length());
         run.setXPos(xPos);
index 08d510d..ee5e22b 100644 (file)
@@ -42,6 +42,18 @@ enum {
     kCTFontUIFontSystemUltraLight = 104,
 };
 
+typedef CF_OPTIONS(uint32_t, CTFontTransformOptions)
+{
+    kCTFontTransformApplyShaping = (1 << 0),
+    kCTFontTransformApplyPositioning = (1 << 1)
+};
+
+typedef CF_OPTIONS(uint32_t, CTFontDescriptorOptions)
+{
+    kCTFontDescriptorOptionSystemUIFont = 1 << 1,
+    kCTFontDescriptorOptionPreferAppleSystemFont = kCTFontOptionsPreferSystemFont
+};
+
 #endif
 
 extern "C" {
@@ -52,16 +64,7 @@ typedef void (*CTUniCharDisposeCallback)(const UniChar* chars, void* refCon);
 extern const CFStringRef kCTFontReferenceURLAttribute;
 extern const CFStringRef kCTFontOpticalSizeAttribute;
 
-#if PLATFORM(COCOA)
-#if !USE(APPLE_INTERNAL_SDK)
-typedef CF_OPTIONS(uint32_t, CTFontTransformOptions)
-{
-    kCTFontTransformApplyShaping = (1 << 0),
-    kCTFontTransformApplyPositioning = (1 << 1)
-};
-#endif
 bool CTFontTransformGlyphs(CTFontRef, CGGlyph glyphs[], CGSize advances[], CFIndex count, CTFontTransformOptions);
-#endif
 
 CGSize CTRunGetInitialAdvance(CTRunRef run);
 CTLineRef CTLineCreateWithUniCharProvider(CTUniCharProviderCallback provide, CTUniCharDisposeCallback dispose, void* refCon);
@@ -73,26 +76,15 @@ CTFontDescriptorRef CTFontDescriptorCreateWithTextStyle(CFStringRef style, CFStr
 CTFontDescriptorRef CTFontDescriptorCreateCopyWithSymbolicTraits(CTFontDescriptorRef original, CTFontSymbolicTraits symTraitValue, CTFontSymbolicTraits symTraitMask);
 CFBitVectorRef CTFontCopyGlyphCoverageForFeature(CTFontRef, CFDictionaryRef feature);
 
-#if PLATFORM(COCOA)
-#if !USE(APPLE_INTERNAL_SDK)
-typedef CF_OPTIONS(uint32_t, CTFontDescriptorOptions)
-{
-    kCTFontDescriptorOptionSystemUIFont = 1 << 1,
-    kCTFontDescriptorOptionPreferAppleSystemFont = kCTFontOptionsPreferSystemFont
-};
-
 CTFontDescriptorRef CTFontDescriptorCreateWithAttributesAndOptions(CFDictionaryRef attributes, CTFontDescriptorOptions);
 
 extern const CFStringRef kCTFontDescriptorTextStyleAttribute;
 extern const CFStringRef kCTFontUIFontDesignTrait;
-#endif
-#endif
 
 bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
 CTFontRef CTFontCreateForCSS(CFStringRef name, uint16_t weight, CTFontSymbolicTraits, CGFloat size);
 CTFontRef CTFontCreateForCharactersWithLanguage(CTFontRef currentFont, const UTF16Char *characters, CFIndex length, CFStringRef language, CFIndex *coveredLength);
 
-#if PLATFORM(COCOA)
 extern const CFStringRef kCTUIFontTextStyleShortHeadline;
 extern const CFStringRef kCTUIFontTextStyleShortBody;
 extern const CFStringRef kCTUIFontTextStyleShortSubhead;
@@ -118,14 +110,11 @@ extern const CGFloat kCTFontWeightSemibold;
 extern const CGFloat kCTFontWeightBold;
 extern const CGFloat kCTFontWeightHeavy;
 extern const CGFloat kCTFontWeightBlack;
-#endif
 
-#if PLATFORM(IOS)
 extern const CFStringRef kCTUIFontTextStyleTitle1;
 extern const CFStringRef kCTUIFontTextStyleTitle2;
 extern const CFStringRef kCTUIFontTextStyleTitle3;
 CTFontDescriptorRef CTFontCreatePhysicalFontDescriptorForCharactersWithLanguage(CTFontRef currentFont, const UTF16Char* characters, CFIndex length, CFStringRef language, CFIndex* coveredLength);
-#endif
 
 CTFontRef CTFontCreatePhysicalFontForCharactersWithLanguage(CTFontRef, const UTF16Char* characters, CFIndex length, CFStringRef language, CFIndex* coveredLength);
 bool CTFontIsAppleColorEmoji(CTFontRef);
index f5dbee2..cd68e58 100644 (file)
@@ -52,6 +52,8 @@ enum ExpansionBehaviorFlags {
     AllowLeadingExpansion = 1 << 2,
     ForceLeadingExpansion = 2 << 2,
     LeadingExpansionMask = 3 << 2,
+
+    DefaultExpansion = AllowTrailingExpansion | ForbidLeadingExpansion,
 };
 typedef unsigned ExpansionBehavior;
 
index d264d2a..16d50dc 100644 (file)
@@ -3801,24 +3801,24 @@ TextRun RenderBlock::constructTextRun(const String& string, const RenderStyle& s
     return constructTextRun(StringView(string), style, expansion, flags);
 }
 
-TextRun RenderBlock::constructTextRun(const RenderText* text, const RenderStyle& style, ExpansionBehavior expansion)
+TextRun RenderBlock::constructTextRun(const RenderText& text, const RenderStyle& style, ExpansionBehavior expansion)
 {
-    return constructTextRun(text->stringView(), style, expansion);
+    return constructTextRun(text.stringView(), style, expansion);
 }
 
-TextRun RenderBlock::constructTextRun(const RenderText* text, unsigned offset, unsigned length, const RenderStyle& style, ExpansionBehavior expansion)
+TextRun RenderBlock::constructTextRun(const RenderText& text, unsigned offset, unsigned length, const RenderStyle& style, ExpansionBehavior expansion)
 {
     unsigned stop = offset + length;
-    ASSERT(stop <= text->textLength());
-    return constructTextRun(text->stringView(offset, stop), style, expansion);
+    ASSERT(stop <= text.textLength());
+    return constructTextRun(text.stringView(offset, stop), style, expansion);
 }
 
-TextRun RenderBlock::constructTextRun(const LChar* characters, int length, const RenderStyle& style, ExpansionBehavior expansion)
+TextRun RenderBlock::constructTextRun(const LChar* characters, unsigned length, const RenderStyle& style, ExpansionBehavior expansion)
 {
     return constructTextRun(StringView(characters, length), style, expansion);
 }
 
-TextRun RenderBlock::constructTextRun(const UChar* characters, int length, const RenderStyle& style, ExpansionBehavior expansion)
+TextRun RenderBlock::constructTextRun(const UChar* characters, unsigned length, const RenderStyle& style, ExpansionBehavior expansion)
 {
     return constructTextRun(StringView(characters, length), style, expansion);
 }
index d32fbed..71fb09d 100644 (file)
@@ -204,17 +204,17 @@ public:
     }
 
     static TextRun constructTextRun(StringView, const RenderStyle&,
-        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextRunFlags = DefaultTextRunFlags);
+        ExpansionBehavior = DefaultExpansion, TextRunFlags = DefaultTextRunFlags);
     static TextRun constructTextRun(const String&, const RenderStyle&,
-        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextRunFlags = DefaultTextRunFlags);
-    static TextRun constructTextRun(const RenderText*, const RenderStyle&,
-        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
-    static TextRun constructTextRun(const RenderText*, unsigned offset, unsigned length, const RenderStyle&,
-        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
-    static TextRun constructTextRun(const LChar* characters, int length, const RenderStyle&,
-        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
-    static TextRun constructTextRun(const UChar* characters, int length, const RenderStyle&,
-        ExpansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion);
+        ExpansionBehavior = DefaultExpansion, TextRunFlags = DefaultTextRunFlags);
+    static TextRun constructTextRun(const RenderText&, const RenderStyle&,
+        ExpansionBehavior = DefaultExpansion);
+    static TextRun constructTextRun(const RenderText&, unsigned offset, unsigned length, const RenderStyle&,
+        ExpansionBehavior = DefaultExpansion);
+    static TextRun constructTextRun(const LChar* characters, unsigned length, const RenderStyle&,
+        ExpansionBehavior = DefaultExpansion);
+    static TextRun constructTextRun(const UChar* characters, unsigned length, const RenderStyle&,
+        ExpansionBehavior = DefaultExpansion);
     
     LayoutUnit paginationStrut() const;
     void setPaginationStrut(LayoutUnit);
index fcb6021..d4e438a 100644 (file)
@@ -1543,7 +1543,7 @@ void RenderListMarker::computePreferredLogicalWidths()
             break;
         case Asterisks:
         case Footnotes: {
-            TextRun run = RenderBlock::constructTextRun(m_text, style(), AllowTrailingExpansion | ForbidLeadingExpansion, DefaultTextRunFlags);
+            TextRun run = RenderBlock::constructTextRun(m_text, style());
             logicalWidth = font.width(run); // no suffix for these types
         }
             break;
@@ -1630,7 +1630,7 @@ void RenderListMarker::computePreferredLogicalWidths()
             if (m_text.isEmpty())
                 logicalWidth = 0;
             else {
-                TextRun run = RenderBlock::constructTextRun(m_text, style(), AllowTrailingExpansion | ForbidLeadingExpansion, DefaultTextRunFlags);
+                TextRun run = RenderBlock::constructTextRun(m_text, style());
                 LayoutUnit itemWidth = font.width(run);
                 UChar suffixSpace[2] = { listMarkerSuffix(type, m_listItem.value()), ' ' };
                 LayoutUnit suffixSpaceWidth = font.width(RenderBlock::constructTextRun(suffixSpace, 2, style()));
@@ -1763,7 +1763,7 @@ FloatRect RenderListMarker::getRelativeMarkerRect()
         case Asterisks:
         case Footnotes: {
             const FontCascade& font = style().fontCascade();
-            TextRun run = RenderBlock::constructTextRun(m_text, style(), AllowTrailingExpansion | ForbidLeadingExpansion, DefaultTextRunFlags);
+            TextRun run = RenderBlock::constructTextRun(m_text, style());
             relativeRect = FloatRect(0, 0, font.width(run), font.fontMetrics().height());
             break;
         }
@@ -1857,7 +1857,7 @@ FloatRect RenderListMarker::getRelativeMarkerRect()
             if (m_text.isEmpty())
                 return FloatRect();
             const FontCascade& font = style().fontCascade();
-            TextRun run = RenderBlock::constructTextRun(m_text, style(), AllowTrailingExpansion | ForbidLeadingExpansion, DefaultTextRunFlags);
+            TextRun run = RenderBlock::constructTextRun(m_text, style());
             float itemWidth = font.width(run);
             UChar suffixSpace[2] = { listMarkerSuffix(type, m_listItem.value()), ' ' };
             float suffixSpaceWidth = font.width(RenderBlock::constructTextRun(suffixSpace, 2, style()));
index 23f09b2..89caec4 100644 (file)
@@ -219,13 +219,13 @@ void RenderMenuList::updateOptionsWidth()
                 optionWidth += minimumValueForLength(optionStyle->textIndent(), 0);
             if (!text.isEmpty()) {
                 const FontCascade& font = style().fontCascade();
-                TextRun run = RenderBlock::constructTextRun(text, style(), AllowTrailingExpansion | ForbidLeadingExpansion, DefaultTextRunFlags);
+                TextRun run = RenderBlock::constructTextRun(text, style());
                 optionWidth += font.width(run);
             }
             maxOptionWidth = std::max(maxOptionWidth, optionWidth);
         } else if (!text.isEmpty()) {
             const FontCascade& font = style().fontCascade();
-            TextRun run = RenderBlock::constructTextRun(text, style(), AllowTrailingExpansion | ForbidLeadingExpansion, DefaultTextRunFlags);
+            TextRun run = RenderBlock::constructTextRun(text, style());
             maxOptionWidth = std::max(maxOptionWidth, font.width(run));
         }
     }
index a6b5217..2398979 100644 (file)
@@ -452,7 +452,7 @@ LayoutRect RenderText::localCaretRect(InlineBox* inlineBox, unsigned caretOffset
     return box.root().computeCaretRect(left, caretWidth, extraWidthToEndOfLine);
 }
 
-ALWAYS_INLINE float RenderText::widthFromCache(const FontCascade& f, int start, int len, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow, const RenderStyle& style) const
+ALWAYS_INLINE float RenderText::widthFromCache(const FontCascade& f, unsigned start, unsigned len, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow, const RenderStyle& style) const
 {
     if (style.hasTextCombine() && is<RenderCombineText>(*this)) {
         const RenderCombineText& combineText = downcast<RenderCombineText>(*this);
@@ -466,7 +466,7 @@ ALWAYS_INLINE float RenderText::widthFromCache(const FontCascade& f, int start,
         bool isSpace;
         ASSERT(m_text);
         StringImpl& text = *m_text.impl();
-        for (int i = start; i < start + len; i++) {
+        for (unsigned i = start; i < start + len; i++) {
             char c = text[i];
             if (c <= ' ') {
                 if (c == ' ' || c == '\n') {
@@ -492,7 +492,7 @@ ALWAYS_INLINE float RenderText::widthFromCache(const FontCascade& f, int start,
         return w;
     }
 
-    TextRun run = RenderBlock::constructTextRun(this, start, len, style);
+    TextRun run = RenderBlock::constructTextRun(*this, start, len, style);
     run.setCharactersLength(textLength() - start);
     ASSERT(run.charactersLength() >= run.length());
 
@@ -608,7 +608,7 @@ void RenderText::trimmedPrefWidths(float leadWidth,
     beginWS = !stripFrontSpaces && m_hasBeginWS;
     endWS = m_hasEndWS;
 
-    int len = textLength();
+    unsigned len = textLength();
 
     if (!len || (stripFrontSpaces && text()->containsOnlyWhitespace())) {
         beginMinW = 0;
@@ -632,10 +632,9 @@ void RenderText::trimmedPrefWidths(float leadWidth,
 
     ASSERT(m_text);
     StringImpl& text = *m_text.impl();
-    if (text[0] == ' ' || (text[0] == '\n' && !style.preserveNewline()) || text[0] == '\t') {
+    if (text[0] == space || (text[0] == newlineCharacter && !style.preserveNewline()) || text[0] == '\t') {
         const FontCascade& font = style.fontCascade(); // FIXME: This ignores first-line.
         if (stripFrontSpaces) {
-            const UChar space = ' ';
             float spaceWidth = font.width(RenderBlock::constructTextRun(&space, 1, style));
             maxW -= spaceWidth;
         } else
@@ -653,8 +652,8 @@ void RenderText::trimmedPrefWidths(float leadWidth,
         bool firstLine = true;
         beginMaxW = maxW;
         endMaxW = maxW;
-        for (int i = 0; i < len; i++) {
-            int linelen = 0;
+        for (unsigned i = 0; i < len; i++) {
+            unsigned linelen = 0;
             while (i + linelen < len && text[i + linelen] != '\n')
                 linelen++;
 
@@ -726,20 +725,22 @@ void RenderText::computePreferredLogicalWidths(float leadWidth)
         m_knownToHaveNoOverflowAndNoFallbackFonts = true;
 }
 
-static inline float hyphenWidth(RenderText* renderer, const FontCascade& font)
+static inline float hyphenWidth(RenderText& renderer, const FontCascade& font)
 {
-    const RenderStyle& style = renderer->style();
-    return font.width(RenderBlock::constructTextRun(style.hyphenString().string(), style));
+    const RenderStyle& style = renderer.style();
+    auto textRun = RenderBlock::constructTextRun(style.hyphenString().string(), style);
+    return font.width(textRun);
 }
 
-static float maxWordFragmentWidth(RenderText* renderer, const RenderStyle& style, const FontCascade& font, StringView word, int minimumPrefixLength, unsigned minimumSuffixLength, int& suffixStart, HashSet<const Font*>& fallbackFonts, GlyphOverflow& glyphOverflow)
+static float maxWordFragmentWidth(RenderText& renderer, const RenderStyle& style, const FontCascade& font, StringView word, unsigned minimumPrefixLength, unsigned minimumSuffixLength, unsigned& suffixStart, HashSet<const Font*>& fallbackFonts, GlyphOverflow& glyphOverflow)
 {
     suffixStart = 0;
     if (word.length() <= minimumSuffixLength)
         return 0;
 
     Vector<int, 8> hyphenLocations;
-    int hyphenLocation = word.length() - minimumSuffixLength;
+    ASSERT(word.length() >= minimumSuffixLength);
+    unsigned hyphenLocation = word.length() - minimumSuffixLength;
     while ((hyphenLocation = lastHyphenLocation(word, hyphenLocation, style.locale())) >= minimumPrefixLength)
         hyphenLocations.append(hyphenLocation);
 
@@ -758,7 +759,7 @@ static float maxWordFragmentWidth(RenderText* renderer, const RenderStyle& style
 
         TextRun run = RenderBlock::constructTextRun(fragmentWithHyphen.toString(), style);
         run.setCharactersLength(fragmentWithHyphen.length());
-        run.setCharacterScanForCodePath(!renderer->canUseSimpleFontCodePath());
+        run.setCharacterScanForCodePath(!renderer.canUseSimpleFontCodePath());
         float fragmentWidth = font.width(run, &fallbackFonts, &glyphOverflow);
 
         // Narrow prefixes are ignored. See tryHyphenating in RenderBlockLineLayout.cpp.
@@ -807,19 +808,17 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Fo
     // If automatic hyphenation is allowed, we keep track of the width of the widest word (or word
     // fragment) encountered so far, and only try hyphenating words that are wider.
     float maxWordWidth = std::numeric_limits<float>::max();
-    int minimumPrefixLength = 0;
-    int minimumSuffixLength = 0;
+    unsigned minimumPrefixLength = 0;
+    unsigned minimumSuffixLength = 0;
     if (style.hyphens() == HyphensAuto && canHyphenate(style.locale())) {
         maxWordWidth = 0;
 
         // Map 'hyphenate-limit-{before,after}: auto;' to 2.
-        minimumPrefixLength = style.hyphenationLimitBefore();
-        if (minimumPrefixLength < 0)
-            minimumPrefixLength = 2;
+        auto before = style.hyphenationLimitBefore();
+        minimumPrefixLength = before < 0 ? 2 : before;
 
-        minimumSuffixLength = style.hyphenationLimitAfter();
-        if (minimumSuffixLength < 0)
-            minimumSuffixLength = 2;
+        auto after = style.hyphenationLimitAfter();
+        minimumSuffixLength = after < 0 ? 2 : after;
     }
 
     Optional<int> firstGlyphLeftOverflow;
@@ -906,12 +905,12 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Fo
             else {
                 w = widthFromCache(font, i, wordLen, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
                 if (c == softHyphen && style.hyphens() != HyphensNone)
-                    currMinWidth = hyphenWidth(this, font);
+                    currMinWidth = hyphenWidth(*this, font);
             }
 
             if (w > maxWordWidth) {
-                int suffixStart;
-                float maxFragmentWidth = maxWordFragmentWidth(this, style, font, StringView(m_text).substring(i, wordLen), minimumPrefixLength, minimumSuffixLength, suffixStart, fallbackFonts, glyphOverflow);
+                unsigned suffixStart;
+                float maxFragmentWidth = maxWordFragmentWidth(*this, style, font, StringView(m_text).substring(i, wordLen), minimumPrefixLength, minimumSuffixLength, suffixStart, fallbackFonts, glyphOverflow);
 
                 if (suffixStart) {
                     float suffixWidth;
@@ -985,7 +984,7 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const Fo
                     m_maxWidth = currMaxWidth;
                 currMaxWidth = 0;
             } else {
-                TextRun run = RenderBlock::constructTextRun(this, i, 1, style);
+                TextRun run = RenderBlock::constructTextRun(*this, i, 1, style);
                 run.setCharactersLength(len - i);
                 ASSERT(run.charactersLength() >= run.length());
                 run.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
@@ -1325,7 +1324,7 @@ float RenderText::width(unsigned from, unsigned len, const FontCascade& f, float
         } else
             w = widthFromCache(f, from, len, xPos, fallbackFonts, glyphOverflow, style);
     } else {
-        TextRun run = RenderBlock::constructTextRun(this, from, len, style);
+        TextRun run = RenderBlock::constructTextRun(*this, from, len, style);
         run.setCharactersLength(textLength() - from);
         ASSERT(run.charactersLength() >= run.length());
 
index eb0330f..81ae422 100644 (file)
@@ -196,7 +196,7 @@ private:
 
     bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction) final { ASSERT_NOT_REACHED(); return false; }
 
-    float widthFromCache(const FontCascade&, int start, int len, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow*, const RenderStyle&) const;
+    float widthFromCache(const FontCascade&, unsigned start, unsigned len, float xPos, HashSet<const Font*>* fallbackFonts, GlyphOverflow*, const RenderStyle&) const;
     bool isAllASCII() const { return m_isAllASCII; }
     bool computeUseBackslashAsYenSymbol() const;
 
index 8a2efa5..f9c9c91 100644 (file)
@@ -575,7 +575,7 @@ public:
     }
     float measureText(const String& string) const override
     {
-        TextRun run = RenderBlock::constructTextRun(string, m_style, AllowTrailingExpansion | ForbidLeadingExpansion, DefaultTextRunFlags);
+        TextRun run = RenderBlock::constructTextRun(string, m_style);
         return m_font.width(run);
     }
 private:
index 3b75377..89b16e3 100644 (file)
@@ -644,7 +644,7 @@ ALWAYS_INLINE float textWidth(RenderText& text, unsigned from, unsigned len, con
     if (layout)
         return FontCascade::width(*layout, from, len, &fallbackFonts);
 
-    TextRun run = RenderBlock::constructTextRun(&text, from, len, style);
+    TextRun run = RenderBlock::constructTextRun(text, from, len, style);
     run.setCharactersLength(text.textLength() - from);
     ASSERT(run.charactersLength() >= run.length());
 
@@ -693,7 +693,7 @@ inline void tryHyphenating(RenderText& text, const FontCascade& font, const Atom
         return;
 
     const RenderStyle& style = text.style();
-    TextRun run = RenderBlock::constructTextRun(&text, lastSpace, pos - lastSpace, style);
+    TextRun run = RenderBlock::constructTextRun(text, lastSpace, pos - lastSpace, style);
     run.setCharactersLength(text.textLength() - lastSpace);
     ASSERT(run.charactersLength() >= run.length());
 
index 75155c8..689164a 100644 (file)
@@ -88,7 +88,7 @@ int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragmen
    float scalingFactor = renderer().scalingFactor();
     ASSERT(scalingFactor);
 
-    TextRun textRun = constructTextRun(&renderer().style(), fragment);
+    TextRun textRun = constructTextRun(renderer().style(), fragment);
 
     // Eventually handle lengthAdjust="spacingAndGlyphs".
     // FIXME: Handle vertical text.
@@ -107,10 +107,9 @@ float SVGInlineTextBox::positionForOffset(unsigned) const
     return 0;
 }
 
-FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition, const RenderStyle* style) const
+FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition, const RenderStyle& style) const
 {
     ASSERT_WITH_SECURITY_IMPLICATION(startPosition < endPosition);
-    ASSERT(style);
 
     float scalingFactor = renderer().scalingFactor();
     ASSERT(scalingFactor);
@@ -157,7 +156,7 @@ LayoutRect SVGInlineTextBox::localSelectionRect(unsigned startPosition, unsigned
         if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
             continue;
 
-        FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, &style);
+        FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style);
         fragment.buildFragmentTransform(fragmentTransform);
         if (!fragmentTransform.isIdentity())
             fragmentRect = fragmentTransform.mapRect(fragmentRect);
@@ -225,7 +224,7 @@ void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
             paintInfo.context().concatCTM(fragmentTransform);
 
         paintInfo.context().setFillColor(backgroundColor);
-        paintInfo.context().fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, &style), backgroundColor);
+        paintInfo.context().fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor);
 
         m_paintingResourceMode = ApplyToDefaultMode;
     }
@@ -306,13 +305,15 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse
                 if (!hasFill)
                     continue;
                 m_paintingResourceMode = ApplyToFillMode | ApplyToTextMode;
-                paintText(paintInfo.context(), &style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
+                ASSERT(selectionStyle);
+                paintText(paintInfo.context(), style, *selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
                 break;
             case PaintTypeStroke:
                 if (!hasVisibleStroke)
                     continue;
                 m_paintingResourceMode = ApplyToStrokeMode | ApplyToTextMode;
-                paintText(paintInfo.context(), &style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
+                ASSERT(selectionStyle);
+                paintText(paintInfo.context(), style, *selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
                 break;
             case PaintTypeMarkers:
                 continue;
@@ -333,17 +334,16 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse
     ASSERT(!m_paintingResource);
 }
 
-bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float scalingFactor, RenderBoxModelObject& renderer, const RenderStyle* style)
+bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float scalingFactor, RenderBoxModelObject& renderer, const RenderStyle& style)
 {
     ASSERT(scalingFactor);
-    ASSERT(style);
     ASSERT(m_paintingResourceMode != ApplyToDefaultMode);
 
     Color fallbackColor;
     if (m_paintingResourceMode & ApplyToFillMode)
-        m_paintingResource = RenderSVGResource::fillPaintingResource(renderer, *style, fallbackColor);
+        m_paintingResource = RenderSVGResource::fillPaintingResource(renderer, style, fallbackColor);
     else if (m_paintingResourceMode & ApplyToStrokeMode)
-        m_paintingResource = RenderSVGResource::strokePaintingResource(renderer, *style, fallbackColor);
+        m_paintingResource = RenderSVGResource::strokePaintingResource(renderer, style, fallbackColor);
     else {
         // We're either called for stroking or filling.
         ASSERT_NOT_REACHED();
@@ -352,13 +352,13 @@ bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float
     if (!m_paintingResource)
         return false;
 
-    if (!m_paintingResource->applyResource(renderer, *style, context, m_paintingResourceMode)) {
+    if (!m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode)) {
         if (fallbackColor.isValid()) {
             RenderSVGResourceSolidColor* fallbackResource = RenderSVGResource::sharedSolidPaintingResource();
             fallbackResource->setColor(fallbackColor);
 
             m_paintingResource = fallbackResource;
-            m_paintingResource->applyResource(renderer, *style, context, m_paintingResourceMode);
+            m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode);
         }
     }
 
@@ -376,7 +376,7 @@ void SVGInlineTextBox::releasePaintingResource(GraphicsContext*& context, const
     m_paintingResource = nullptr;
 }
 
-bool SVGInlineTextBox::prepareGraphicsContextForTextPainting(GraphicsContext*& context, float scalingFactor, const RenderStyle* style)
+bool SVGInlineTextBox::prepareGraphicsContextForTextPainting(GraphicsContext*& context, float scalingFactor, const RenderStyle& style)
 {
     return acquirePaintingResource(context, scalingFactor, parent()->renderer(), style);
 }
@@ -386,16 +386,14 @@ void SVGInlineTextBox::restoreGraphicsContextAfterTextPainting(GraphicsContext*&
     releasePaintingResource(context, /* path */nullptr);
 }
 
-TextRun SVGInlineTextBox::constructTextRun(const RenderStyle* style, const SVGTextFragment& fragment) const
+TextRun SVGInlineTextBox::constructTextRun(const RenderStyle& style, const SVGTextFragment& fragment) const
 {
-    ASSERT(style);
-
     TextRun run(StringView(renderer().text()).substring(fragment.characterOffset, fragment.length)
                 , 0 /* xPos, only relevant with allowTabs=true */
                 , 0 /* padding, only relevant for justified text, not relevant for SVG */
                 , AllowTrailingExpansion
                 , direction()
-                , dirOverride() || style->rtlOrdering() == VisualOrder /* directionalOverride */);
+                , dirOverride() || style.rtlOrdering() == VisualOrder /* directionalOverride */);
 
     // We handle letter & word spacing ourselves.
     run.disableSpacing();
@@ -538,17 +536,17 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext& context, TextDe
     path.addRect(FloatRect(decorationOrigin, FloatSize(width, thickness)));
 
     GraphicsContext* contextPtr = &context;
-    if (acquirePaintingResource(contextPtr, scalingFactor, decorationRenderer, &decorationStyle))
+    if (acquirePaintingResource(contextPtr, scalingFactor, decorationRenderer, decorationStyle))
         releasePaintingResource(contextPtr, &path);
 }
 
-void SVGInlineTextBox::paintTextWithShadows(GraphicsContext& context, const RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition)
+void SVGInlineTextBox::paintTextWithShadows(GraphicsContext& context, const RenderStyle& style, TextRun& textRun, const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition)
 {
     float scalingFactor = renderer().scalingFactor();
     ASSERT(scalingFactor);
 
     const FontCascade& scaledFont = renderer().scaledFont();
-    const ShadowData* shadow = style->textShadow();
+    const ShadowData* shadow = style.textShadow();
 
     FloatPoint textOrigin(fragment.x, fragment.y);
     FloatSize textSize(fragment.width, fragment.height);
@@ -587,11 +585,8 @@ void SVGInlineTextBox::paintTextWithShadows(GraphicsContext& context, const Rend
     } while (shadow);
 }
 
-void SVGInlineTextBox::paintText(GraphicsContext& context, const RenderStyle* style, const RenderStyle* selectionStyle, const SVGTextFragment& fragment, bool hasSelection, bool paintSelectedTextOnly)
+void SVGInlineTextBox::paintText(GraphicsContext& context, const RenderStyle& style, const RenderStyle& selectionStyle, const SVGTextFragment& fragment, bool hasSelection, bool paintSelectedTextOnly)
 {
-    ASSERT(style);
-    ASSERT(selectionStyle);
-
     unsigned startPosition = 0;
     unsigned endPosition = 0;
     if (hasSelection) {
@@ -612,12 +607,12 @@ void SVGInlineTextBox::paintText(GraphicsContext& context, const RenderStyle* st
 
     // Draw text using selection style from the start to the end position of the selection
     if (style != selectionStyle)
-        SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, *selectionStyle);
+        SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, selectionStyle);
 
     paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition);
 
     if (style != selectionStyle)
-        SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, *style);
+        SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, style);
 
     // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part
     if (endPosition < fragment.length && !paintSelectedTextOnly)
index 1e32a42..66c4eae 100644 (file)
@@ -64,23 +64,23 @@ public:
     void setStartsNewTextChunk(bool newTextChunk) { m_startsNewTextChunk = newTextChunk; }
 
     int offsetForPositionInFragment(const SVGTextFragment&, float position, bool includePartialGlyphs) const;
-    FloatRect selectionRectForTextFragment(const SVGTextFragment&, unsigned fragmentStartPosition, unsigned fragmentEndPosition, const RenderStyle*) const;
+    FloatRect selectionRectForTextFragment(const SVGTextFragment&, unsigned fragmentStartPosition, unsigned fragmentEndPosition, const RenderStyle&) const;
 
 private:
     bool isSVGInlineTextBox() const override { return true; }
 
-    TextRun constructTextRun(const RenderStyle*, const SVGTextFragment&) const;
+    TextRun constructTextRun(const RenderStyle&, const SVGTextFragment&) const;
 
-    bool acquirePaintingResource(GraphicsContext*&, float scalingFactor, RenderBoxModelObject&, const RenderStyle*);
+    bool acquirePaintingResource(GraphicsContext*&, float scalingFactor, RenderBoxModelObject&, const RenderStyle&);
     void releasePaintingResource(GraphicsContext*&, const Path*);
 
-    bool prepareGraphicsContextForTextPainting(GraphicsContext*&, float scalingFactor, const RenderStyle*);
+    bool prepareGraphicsContextForTextPainting(GraphicsContext*&, float scalingFactor, const RenderStyle&);
     void restoreGraphicsContextAfterTextPainting(GraphicsContext*&);
 
     void paintDecoration(GraphicsContext&, TextDecoration, const SVGTextFragment&);
     void paintDecorationWithStyle(GraphicsContext&, TextDecoration, const SVGTextFragment&, RenderBoxModelObject& decorationRenderer);
-    void paintTextWithShadows(GraphicsContext&, const RenderStyle*, TextRun&, const SVGTextFragment&, unsigned startPosition, unsigned endPosition);
-    void paintText(GraphicsContext&, const RenderStyle*, const RenderStyle* selectionStyle, const SVGTextFragment&, bool hasSelection, bool paintSelectedTextOnly);
+    void paintTextWithShadows(GraphicsContext&, const RenderStyle&, TextRun&, const SVGTextFragment&, unsigned startPosition, unsigned endPosition);
+    void paintText(GraphicsContext&, const RenderStyle&, const RenderStyle& selectionStyle, const SVGTextFragment&, bool hasSelection, bool paintSelectedTextOnly);
 
     bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom, HitTestAction) override;
 
index 4a3a1dd..2ed0475 100644 (file)
@@ -1,3 +1,15 @@
+2016-09-01  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Clean up TextRun-related code
+        https://bugs.webkit.org/show_bug.cgi?id=161473
+
+        Reviewed by Simon Fraser.
+
+        Remove unused #includes.
+
+        * WebCoreSupport/WebDragClient.mm:
+        * WebView/WebView.mm:
+
 2016-08-31  Keith Rollin  <krollin@apple.com>
 
         WebKit should set a subsystem for os_log so it's easier to filter for WebKit log messages
index b740bff..a8d04c0 100644 (file)
@@ -38,7 +38,6 @@
 #import "WebKitNSStringExtras.h"
 #import "WebNSPasteboardExtras.h"
 #import "WebNSURLExtras.h"
-#import "WebStringTruncator.h"
 #import "WebUIDelegate.h"
 #import "WebUIDelegatePrivate.h"
 #import "WebViewInternal.h"
index 7b9083a..ec3019b 100644 (file)
 #import <WebCore/ResourceLoadStatisticsStore.h>
 #import <WebCore/SQLiteDatabaseTracker.h>
 #import <WebCore/SmartReplace.h>
-#import <WebCore/TextRun.h>
 #import <WebCore/TileControllerMemoryHandlerIOS.h>
 #import <WebCore/WAKWindow.h>
 #import <WebCore/WKView.h>