Clean up interface to Font::expansionOpportunityCount()
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Oct 2014 22:07:42 +0000 (22:07 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Oct 2014 22:07:42 +0000 (22:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137355

Reviewed by Dean Jackson.

There are two overloads of Font::expansionOpportunityCount() which perform the same
operation. One overload takes a UChar*, the other takes an LChar*, and they both
take a length. This is the abstraction that StringView was designed to be. Instead
of forcing each caller to take a different overload based on if their data is
8 bit or not, allow the caller to construct a StringView and pass that into
Font::expansionOpportunityCount() instead of a raw pointer/length.

No new tests because there is no behavior change.

* platform/graphics/Font.cpp:
(WebCore::Font::expansionOpportunityCountInternal): Original two functions,
renamed.
(WebCore::Font::expansionOpportunityCount): Takes a StringView, calls
expansionOpportunityCountInternal().
* platform/graphics/Font.h: Update signatures.
* platform/graphics/WidthIterator.cpp:
(WebCore::WidthIterator::WidthIterator): Use new signature to
Font::expansionOpportunityCount().
* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::ComplexTextController::ComplexTextController): Ditto.
* rendering/RenderBlockLineLayout.cpp:
(WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): Ditto.
* rendering/RenderText.cpp:
(WebCore::RenderText::stringView): Accessor to encapsulate character pointer
and length.
* rendering/RenderText.h: Signature of new accessor.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/Font.cpp
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/graphics/WidthIterator.cpp
Source/WebCore/platform/graphics/mac/ComplexTextController.cpp
Source/WebCore/rendering/RenderBlockLineLayout.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderText.h

index fea6cd171a1c30eedc8a5244c2fceabc59f5f17b..b52867455d6fd665f135ef110117d78c7cc5f629 100644 (file)
@@ -1,3 +1,37 @@
+2014-10-03  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Clean up interface to Font::expansionOpportunityCount()
+        https://bugs.webkit.org/show_bug.cgi?id=137355
+
+        Reviewed by Dean Jackson.
+
+        There are two overloads of Font::expansionOpportunityCount() which perform the same
+        operation. One overload takes a UChar*, the other takes an LChar*, and they both
+        take a length. This is the abstraction that StringView was designed to be. Instead
+        of forcing each caller to take a different overload based on if their data is
+        8 bit or not, allow the caller to construct a StringView and pass that into
+        Font::expansionOpportunityCount() instead of a raw pointer/length.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::expansionOpportunityCountInternal): Original two functions,
+        renamed.
+        (WebCore::Font::expansionOpportunityCount): Takes a StringView, calls 
+        expansionOpportunityCountInternal().
+        * platform/graphics/Font.h: Update signatures.
+        * platform/graphics/WidthIterator.cpp:
+        (WebCore::WidthIterator::WidthIterator): Use new signature to
+        Font::expansionOpportunityCount().
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::ComplexTextController::ComplexTextController): Ditto.
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): Ditto.
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::stringView): Accessor to encapsulate character pointer
+        and length.
+        * rendering/RenderText.h: Signature of new accessor.
+
 2014-10-03  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Unreviewed build fix for MSVC 2013 SP 3.
index 5ec424ac6b4cd4ccd93a6a7ae5dccafbc3181938..a5b4d12c3b81c6fbe8a9b8f95109958a12a61e98 100644 (file)
@@ -968,7 +968,7 @@ bool Font::isCJKIdeographOrSymbol(UChar32 c)
     return isCJKIdeograph(c);
 }
 
-unsigned Font::expansionOpportunityCount(const LChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion)
+unsigned Font::expansionOpportunityCountInternal(const LChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion)
 {
     unsigned count = 0;
     if (direction == LTR) {
@@ -991,7 +991,7 @@ unsigned Font::expansionOpportunityCount(const LChar* characters, size_t length,
     return count;
 }
 
-unsigned Font::expansionOpportunityCount(const UChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion)
+unsigned Font::expansionOpportunityCountInternal(const UChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion)
 {
     static bool expandAroundIdeographs = canExpandAroundIdeographsInComplexText();
     unsigned count = 0;
@@ -1041,6 +1041,13 @@ unsigned Font::expansionOpportunityCount(const UChar* characters, size_t length,
     return count;
 }
 
+unsigned Font::expansionOpportunityCount(const StringView& stringView, TextDirection direction, bool& isAfterExpansion)
+{
+    if (stringView.is8Bit())
+        return expansionOpportunityCountInternal(stringView.characters8(), stringView.length(), direction, isAfterExpansion);
+    return expansionOpportunityCountInternal(stringView.characters16(), stringView.length(), direction, isAfterExpansion);
+}
+
 bool Font::canReceiveTextEmphasis(UChar32 c)
 {
     if (U_GET_GC_MASK(c) & (U_GC_Z_MASK | U_GC_CN_MASK | U_GC_CC_MASK | U_GC_CF_MASK))
index 58c40ab6f115f528747c84fb9f3305221ffae98f..d4559a7e8bc5fe43ca450d2f558e9c3e231b5f45 100644 (file)
@@ -201,8 +201,7 @@ public:
     static bool isCJKIdeograph(UChar32);
     static bool isCJKIdeographOrSymbol(UChar32);
 
-    static unsigned expansionOpportunityCount(const LChar*, size_t length, TextDirection, bool& isAfterExpansion);
-    static unsigned expansionOpportunityCount(const UChar*, size_t length, TextDirection, bool& isAfterExpansion);
+    static unsigned expansionOpportunityCount(const StringView&, TextDirection, bool& isAfterExpansion);
 
     WEBCORE_EXPORT static void setShouldUseSmoothing(bool);
     WEBCORE_EXPORT static bool shouldUseSmoothing();
@@ -240,6 +239,9 @@ private:
     int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const;
     void adjustSelectionRectForComplexText(const TextRun&, LayoutRect& selectionRect, int from, int to) const;
 
+    static unsigned expansionOpportunityCountInternal(const LChar*, size_t length, TextDirection, bool& isAfterExpansion);
+    static unsigned expansionOpportunityCountInternal(const UChar*, size_t length, TextDirection, bool& isAfterExpansion);
+
     friend struct WidthIterator;
     friend class SVGTextRunRenderingContext;
 
index 4136d1e3da7ed8e007beffbea6202b5c4712208f..f2c7c05e7d3295c2c76cb339a6930193c303caaa 100644 (file)
@@ -57,7 +57,7 @@ WidthIterator::WidthIterator(const Font* font, const TextRun& run, HashSet<const
         m_expansionPerOpportunity = 0;
     else {
         bool isAfterExpansion = m_isAfterExpansion;
-        unsigned expansionOpportunityCount = m_run.is8Bit() ? Font::expansionOpportunityCount(m_run.characters8(), m_run.length(), m_run.ltr() ? LTR : RTL, isAfterExpansion) : Font::expansionOpportunityCount(m_run.characters16(), m_run.length(), m_run.ltr() ? LTR : RTL, isAfterExpansion);
+        unsigned expansionOpportunityCount = Font::expansionOpportunityCount(m_run.text(), m_run.ltr() ? LTR : RTL, isAfterExpansion);
         if (isAfterExpansion && !m_run.allowsTrailingExpansion())
             expansionOpportunityCount--;
 
index 86d243b2394f4e4a5d1ff8c0fc8a061b6d373c71..35ca73644e9b712aa58a932ad2f5d222d07498bc 100644 (file)
@@ -144,11 +144,7 @@ ComplexTextController::ComplexTextController(const Font* font, const TextRun& ru
         m_expansionPerOpportunity = 0;
     else {
         bool isAfterExpansion = m_afterExpansion;
-        unsigned expansionOpportunityCount;
-        if (m_run.is8Bit())
-            expansionOpportunityCount = Font::expansionOpportunityCount(m_run.characters8(), m_end, m_run.ltr() ? LTR : RTL, isAfterExpansion);
-         else
-             expansionOpportunityCount = Font::expansionOpportunityCount(m_run.characters16(), m_end, m_run.ltr() ? LTR : RTL, isAfterExpansion);
+        unsigned expansionOpportunityCount = Font::expansionOpportunityCount(m_run.text(), m_run.ltr() ? LTR : RTL, isAfterExpansion);
         if (isAfterExpansion && !m_run.allowsTrailingExpansion())
             expansionOpportunityCount--;
 
index a47811ed3ea6a9707b33875ba816861baae6ef44..6127882f01fbf025e08b39a78a11748034900e0c 100644 (file)
@@ -682,11 +682,7 @@ BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBo
             if (textAlign == JUSTIFY && r != trailingSpaceRun) {
                 if (!isAfterExpansion)
                     toInlineTextBox(r->box())->setCanHaveLeadingExpansion(true);
-                unsigned opportunitiesInRun;
-                if (rt.is8Bit())
-                    opportunitiesInRun = Font::expansionOpportunityCount(rt.characters8() + r->m_start, r->m_stop - r->m_start, r->box()->direction(), isAfterExpansion);
-                else
-                    opportunitiesInRun = Font::expansionOpportunityCount(rt.characters16() + r->m_start, r->m_stop - r->m_start, r->box()->direction(), isAfterExpansion);
+                unsigned opportunitiesInRun = Font::expansionOpportunityCount(rt.stringView(r->m_start, r->m_stop), r->box()->direction(), isAfterExpansion);
                 expansionOpportunities.append(opportunitiesInRun);
                 expansionOpportunityCount += opportunitiesInRun;
             }
index 39012f2d3bf2ae7fc9040db4b7e53ba4312393e8..fc75302ba8427c98302364183a4431c93dc2c0cd 100644 (file)
@@ -1525,4 +1525,11 @@ void RenderText::momentarilyRevealLastTypedCharacter(unsigned lastTypedCharacter
     secureTextTimer->restartWithNewText(lastTypedCharacterOffset);
 }
 
+StringView RenderText::stringView(int start, int stop) const
+{
+    if (is8Bit())
+        return StringView(characters8() + start, stop - start);
+    return StringView(characters16() + start, stop - start);
+}
+
 } // namespace WebCore
index f024aa6e288a9de6ce445184429536d16a70279a..84115a33e2a145586f064f72ef558d23c009e506 100644 (file)
@@ -156,6 +156,8 @@ public:
     void deleteLineBoxesBeforeSimpleLineLayout();
     const SimpleLineLayout::Layout* simpleLineLayout() const;
 
+    StringView stringView(int start, int stop) const;
+
 protected:
     virtual void computePreferredLogicalWidths(float leadWidth);
     virtual void willBeDestroyed() override;