Title: [222532] trunk/Source/WebCore
Revision
222532
Author
[email protected]
Date
2017-09-26 16:05:29 -0700 (Tue, 26 Sep 2017)

Log Message

Make fontToUse() a member function of InlineTextBox
https://bugs.webkit.org/show_bug.cgi?id=177495

Reviewed by Myles C. Maxfield.

Following bug #177493 we can write fontToUse() in terms of InlineTextBox::combinedText().

No functionality changed. So, no new tests.

* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::lineFont const): Added; extracted from fontToUse().
(WebCore::InlineTextBox::combinedText const): Mark inline to give a hint to the compiler
that this function is small and seems reasonable to inline.
(WebCore::InlineTextBox::localSelectionRect const): Modified to call lineFont().
(WebCore::InlineTextBox::paint): Ditto.
(WebCore::InlineTextBox::offsetForPosition const): Ditto.
(WebCore::InlineTextBox::positionForOffset const): Ditto. Remove an extraneous
if-statement while I am here.
(WebCore::fontToUse): Deleted; moved logic to InlineTextBox::lineFont().
* rendering/InlineTextBox.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (222531 => 222532)


--- trunk/Source/WebCore/ChangeLog	2017-09-26 22:56:06 UTC (rev 222531)
+++ trunk/Source/WebCore/ChangeLog	2017-09-26 23:05:29 UTC (rev 222532)
@@ -1,3 +1,26 @@
+2017-09-26  Daniel Bates  <[email protected]>
+
+        Make fontToUse() a member function of InlineTextBox
+        https://bugs.webkit.org/show_bug.cgi?id=177495
+
+        Reviewed by Myles C. Maxfield.
+
+        Following bug #177493 we can write fontToUse() in terms of InlineTextBox::combinedText().
+
+        No functionality changed. So, no new tests.
+
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::lineFont const): Added; extracted from fontToUse().
+        (WebCore::InlineTextBox::combinedText const): Mark inline to give a hint to the compiler
+        that this function is small and seems reasonable to inline.
+        (WebCore::InlineTextBox::localSelectionRect const): Modified to call lineFont().
+        (WebCore::InlineTextBox::paint): Ditto.
+        (WebCore::InlineTextBox::offsetForPosition const): Ditto.
+        (WebCore::InlineTextBox::positionForOffset const): Ditto. Remove an extraneous
+        if-statement while I am here.
+        (WebCore::fontToUse): Deleted; moved logic to InlineTextBox::lineFont().
+        * rendering/InlineTextBox.h:
+
 2017-09-26  Said Abou-Hallawa  <[email protected]>
 
         Followup (r222427): SynchronizedFixedQueue should not have a public constructor

Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (222531 => 222532)


--- trunk/Source/WebCore/rendering/InlineTextBox.cpp	2017-09-26 22:56:06 UTC (rev 222531)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp	2017-09-26 23:05:29 UTC (rev 222532)
@@ -185,14 +185,9 @@
     return state;
 }
 
-static const FontCascade& fontToUse(const RenderStyle& style, const RenderText& renderer)
+inline const FontCascade& InlineTextBox::lineFont() const
 {
-    if (style.hasTextCombine() && is<RenderCombineText>(renderer)) {
-        const auto& textCombineRenderer = downcast<RenderCombineText>(renderer);
-        if (textCombineRenderer.isCombined())
-            return textCombineRenderer.textCombineFont();
-    }
-    return style.fontCascade();
+    return combinedText() ? combinedText()->textCombineFont() : lineStyle().fontCascade();
 }
 
 LayoutRect InlineTextBox::localSelectionRect(unsigned startPos, unsigned endPos) const
@@ -210,7 +205,7 @@
     LayoutUnit selectionTop = this->selectionTop();
     LayoutUnit selectionHeight = this->selectionHeight();
     const RenderStyle& lineStyle = this->lineStyle();
-    const FontCascade& font = fontToUse(lineStyle, renderer());
+    const FontCascade& font = lineFont();
 
     String hyphenatedString;
     bool respectHyphen = ePos == m_len && hasHyphen();
@@ -483,7 +478,7 @@
     TextPaintStyle selectionPaintStyle = haveSelection && !useCustomUnderlines ? computeTextSelectionPaintStyle(textPaintStyle, renderer(), lineStyle, paintInfo, paintSelectedTextOnly, paintSelectedTextSeparately, paintNonSelectedTextOnly, selectionShadow) : textPaintStyle;
 
     // Set our font.
-    const FontCascade& font = fontToUse(lineStyle, renderer());
+    const FontCascade& font = lineFont();
     // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection
     // and composition underlines.
     if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) {
@@ -1051,15 +1046,11 @@
 {
     if (isLineBreak())
         return 0;
-
     if (lineOffset - logicalLeft() > logicalWidth())
         return isLeftToRightDirection() ? len() : 0;
     if (lineOffset - logicalLeft() < 0)
         return isLeftToRightDirection() ? 0 : len();
-
-    const RenderStyle& lineStyle = this->lineStyle();
-    const FontCascade& font = fontToUse(lineStyle, renderer());
-    return font.offsetForPosition(constructTextRun(lineStyle), lineOffset - logicalLeft(), includePartialGlyphs);
+    return lineFont().offsetForPosition(constructTextRun(lineStyle()), lineOffset - logicalLeft(), includePartialGlyphs);
 }
 
 float InlineTextBox::positionForOffset(unsigned offset) const
@@ -1070,15 +1061,21 @@
     if (isLineBreak())
         return logicalLeft();
 
-    const RenderStyle& lineStyle = this->lineStyle();
-    const FontCascade& font = fontToUse(lineStyle, renderer());
-    unsigned from = !isLeftToRightDirection() ? clampedOffset(offset) : 0;
-    unsigned to = !isLeftToRightDirection() ? m_len : clampedOffset(offset);
+    unsigned startOffset;
+    unsigned endOffset;
+    if (isLeftToRightDirection()) {
+        startOffset = 0;
+        endOffset = clampedOffset(offset);
+    } else {
+        startOffset = clampedOffset(offset);
+        endOffset = m_len;
+    }
+
     // FIXME: Do we need to add rightBearing here?
     LayoutRect selectionRect = LayoutRect(logicalLeft(), 0, 0, 0);
-    TextRun run = constructTextRun(lineStyle);
-    font.adjustSelectionRectForText(run, selectionRect, from, to);
-    return snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), run.ltr()).maxX();
+    TextRun textRun = constructTextRun(lineStyle());
+    lineFont().adjustSelectionRectForText(textRun, selectionRect, startOffset, endOffset);
+    return snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), textRun.ltr()).maxX();
 }
 
 StringView InlineTextBox::substringToRender(std::optional<unsigned> overridingLength) const
@@ -1112,7 +1109,7 @@
     return run;
 }
 
-const RenderCombineText* InlineTextBox::combinedText() const
+inline const RenderCombineText* InlineTextBox::combinedText() const
 {
     return lineStyle().hasTextCombine() && is<RenderCombineText>(renderer()) && downcast<RenderCombineText>(renderer()).isCombined() ? &downcast<RenderCombineText>(renderer()) : nullptr;
 }

Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (222531 => 222532)


--- trunk/Source/WebCore/rendering/InlineTextBox.h	2017-09-26 22:56:06 UTC (rev 222531)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h	2017-09-26 23:05:29 UTC (rev 222532)
@@ -169,6 +169,7 @@
     void paintTextSubrangeBackground(GraphicsContext&, const FloatPoint& boxOrigin, const FontCascade&, const Color&, unsigned startOffset, unsigned endOffset);
 
     const RenderCombineText* combinedText() const;
+    const FontCascade& lineFont() const;
 
     ExpansionBehavior expansionBehavior() const;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to