Title: [174297] trunk/Source/WebCore
Revision
174297
Author
[email protected]
Date
2014-10-03 15:07:42 -0700 (Fri, 03 Oct 2014)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174296 => 174297)


--- trunk/Source/WebCore/ChangeLog	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/ChangeLog	2014-10-03 22:07:42 UTC (rev 174297)
@@ -1,3 +1,37 @@
+2014-10-03  Myles C. Maxfield  <[email protected]>
+
+        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  <[email protected]>
 
         [Win] Unreviewed build fix for MSVC 2013 SP 3.

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (174296 => 174297)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2014-10-03 22:07:42 UTC (rev 174297)
@@ -968,7 +968,7 @@
     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 @@
     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 @@
     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))

Modified: trunk/Source/WebCore/platform/graphics/Font.h (174296 => 174297)


--- trunk/Source/WebCore/platform/graphics/Font.h	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2014-10-03 22:07:42 UTC (rev 174297)
@@ -201,8 +201,7 @@
     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 @@
     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;
 

Modified: trunk/Source/WebCore/platform/graphics/WidthIterator.cpp (174296 => 174297)


--- trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2014-10-03 22:07:42 UTC (rev 174297)
@@ -57,7 +57,7 @@
         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--;
 

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp (174296 => 174297)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2014-10-03 22:07:42 UTC (rev 174297)
@@ -144,11 +144,7 @@
         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--;
 

Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (174296 => 174297)


--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2014-10-03 22:07:42 UTC (rev 174297)
@@ -682,11 +682,7 @@
             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;
             }

Modified: trunk/Source/WebCore/rendering/RenderText.cpp (174296 => 174297)


--- trunk/Source/WebCore/rendering/RenderText.cpp	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/rendering/RenderText.cpp	2014-10-03 22:07:42 UTC (rev 174297)
@@ -1525,4 +1525,11 @@
     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

Modified: trunk/Source/WebCore/rendering/RenderText.h (174296 => 174297)


--- trunk/Source/WebCore/rendering/RenderText.h	2014-10-03 22:05:22 UTC (rev 174296)
+++ trunk/Source/WebCore/rendering/RenderText.h	2014-10-03 22:07:42 UTC (rev 174297)
@@ -156,6 +156,8 @@
     void deleteLineBoxesBeforeSimpleLineLayout();
     const SimpleLineLayout::Layout* simpleLineLayout() const;
 
+    StringView stringView(int start, int stop) const;
+
 protected:
     virtual void computePreferredLogicalWidths(float leadWidth);
     virtual void willBeDestroyed() override;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to