Title: [172513] trunk
Revision
172513
Author
[email protected]
Date
2014-08-12 20:53:47 -0700 (Tue, 12 Aug 2014)

Log Message

Elements whose contents start with an astral Unicode symbol disappear when CSS `::first-letter` is applied to them
https://bugs.webkit.org/show_bug.cgi?id=135756

Reviewed by Darin Adler.

Source/WebCore:

The previous code assumed that all "characters" are exactly 1 16-bit code unit wide. Instead, use numCharactersInGraphemeClusters().

This patch also modifies the signature of numCharactersInGraphemeClusters() to take a StringView instead
of a string, which will avoid a copy.

Test: css1/pseudo/firstletter-surrogate.html

* platform/text/TextBreakIterator.cpp:
(WebCore::numCharactersInGraphemeClusters): Update numCharactersInGraphemeClusters() to take a StringView.
* platform/text/TextBreakIterator.h: Ditto.
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::createFirstLetterRenderer): Use numCharactersInGraphemeClusters() to determine the length
of the first letter, rather than assuming it has length of 1 code unit
(WebCore::RenderBlock::updateFirstLetter): Add a FIXME comment.

Source/WTF:

Add a method to StringView which passes through contains() to find().

* wtf/text/StringView.h:
(WTF::StringView::contains):

LayoutTests:

Make sure the pseudoclass matches manually wrapping a <span> around the character.

* css1/pseudo/firstletter-surrogate-expected.html: Added.
* css1/pseudo/firstletter-surrogate.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (172512 => 172513)


--- trunk/LayoutTests/ChangeLog	2014-08-13 03:02:35 UTC (rev 172512)
+++ trunk/LayoutTests/ChangeLog	2014-08-13 03:53:47 UTC (rev 172513)
@@ -1,3 +1,15 @@
+2014-08-11  Myles C. Maxfield  <[email protected]>
+
+        Elements whose contents start with an astral Unicode symbol disappear when CSS `::first-letter` is applied to them
+        https://bugs.webkit.org/show_bug.cgi?id=135756
+
+        Reviewed by Darin Adler.
+
+        Make sure the pseudoclass matches manually wrapping a <span> around the character.
+
+        * css1/pseudo/firstletter-surrogate-expected.html: Added.
+        * css1/pseudo/firstletter-surrogate.html: Added.
+
 2014-08-12  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r172494.

Added: trunk/LayoutTests/css1/pseudo/firstletter-surrogate-expected.html (0 => 172513)


--- trunk/LayoutTests/css1/pseudo/firstletter-surrogate-expected.html	                        (rev 0)
+++ trunk/LayoutTests/css1/pseudo/firstletter-surrogate-expected.html	2014-08-13 03:53:47 UTC (rev 172513)
@@ -0,0 +1,3 @@
+This test makes sure that the ::first-letter pseudoclass works with first
+letters that require surrogates when written in UTF-16.
+<p><span style="background: red;">&#x1D306;</span>Lorem ipsum (1)</p>

Added: trunk/LayoutTests/css1/pseudo/firstletter-surrogate.html (0 => 172513)


--- trunk/LayoutTests/css1/pseudo/firstletter-surrogate.html	                        (rev 0)
+++ trunk/LayoutTests/css1/pseudo/firstletter-surrogate.html	2014-08-13 03:53:47 UTC (rev 172513)
@@ -0,0 +1,8 @@
+<style>
+p::first-letter {
+    background: red;
+}
+</style>
+This test makes sure that the ::first-letter pseudoclass works with first
+letters that require surrogates when written in UTF-16.
+<p>&#x1D306;Lorem ipsum (1)</p>

Modified: trunk/Source/WTF/ChangeLog (172512 => 172513)


--- trunk/Source/WTF/ChangeLog	2014-08-13 03:02:35 UTC (rev 172512)
+++ trunk/Source/WTF/ChangeLog	2014-08-13 03:53:47 UTC (rev 172513)
@@ -1,3 +1,15 @@
+2014-08-12  Myles C. Maxfield  <[email protected]>
+
+        Elements whose contents start with an astral Unicode symbol disappear when CSS `::first-letter` is applied to them
+        https://bugs.webkit.org/show_bug.cgi?id=135756
+
+        Reviewed by Darin Adler.
+
+        Add a method to StringView which passes through contains() to find().
+
+        * wtf/text/StringView.h:
+        (WTF::StringView::contains):
+
 2014-08-12  Pratik Solanki  <[email protected]>
 
         Enable didReceiveDataArray callback on Mac

Modified: trunk/Source/WTF/wtf/text/StringView.h (172512 => 172513)


--- trunk/Source/WTF/wtf/text/StringView.h	2014-08-13 03:02:35 UTC (rev 172512)
+++ trunk/Source/WTF/wtf/text/StringView.h	2014-08-13 03:53:47 UTC (rev 172513)
@@ -179,6 +179,8 @@
         return WTF::find(characters16(), length(), character, start);
     }
 
+    bool contains(UChar c) const { return find(c) != notFound; }
+
 #if USE(CF)
     // This function converts null strings to empty strings.
     WTF_EXPORT_STRING_API RetainPtr<CFStringRef> createCFStringWithoutCopying() const;

Modified: trunk/Source/WebCore/ChangeLog (172512 => 172513)


--- trunk/Source/WebCore/ChangeLog	2014-08-13 03:02:35 UTC (rev 172512)
+++ trunk/Source/WebCore/ChangeLog	2014-08-13 03:53:47 UTC (rev 172513)
@@ -1,3 +1,25 @@
+2014-08-11  Myles C. Maxfield  <[email protected]>
+
+        Elements whose contents start with an astral Unicode symbol disappear when CSS `::first-letter` is applied to them
+        https://bugs.webkit.org/show_bug.cgi?id=135756
+
+        Reviewed by Darin Adler.
+
+        The previous code assumed that all "characters" are exactly 1 16-bit code unit wide. Instead, use numCharactersInGraphemeClusters().
+
+        This patch also modifies the signature of numCharactersInGraphemeClusters() to take a StringView instead
+        of a string, which will avoid a copy.
+
+        Test: css1/pseudo/firstletter-surrogate.html
+
+        * platform/text/TextBreakIterator.cpp:
+        (WebCore::numCharactersInGraphemeClusters): Update numCharactersInGraphemeClusters() to take a StringView.
+        * platform/text/TextBreakIterator.h: Ditto.
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::createFirstLetterRenderer): Use numCharactersInGraphemeClusters() to determine the length
+        of the first letter, rather than assuming it has length of 1 code unit
+        (WebCore::RenderBlock::updateFirstLetter): Add a FIXME comment.
+
 2014-08-12  Jer Noble  <[email protected]>
 
         [MSE][Mac] Seeking to the very beginning of a buffered range stalls video playback

Modified: trunk/Source/WebCore/platform/text/TextBreakIterator.cpp (172512 => 172513)


--- trunk/Source/WebCore/platform/text/TextBreakIterator.cpp	2014-08-13 03:02:35 UTC (rev 172512)
+++ trunk/Source/WebCore/platform/text/TextBreakIterator.cpp	2014-08-13 03:53:47 UTC (rev 172513)
@@ -377,7 +377,7 @@
     return num;
 }
 
-unsigned numCharactersInGraphemeClusters(const String& s, unsigned numGraphemeClusters)
+unsigned numCharactersInGraphemeClusters(const StringView& s, unsigned numGraphemeClusters)
 {
     unsigned stringLength = s.length();
 

Modified: trunk/Source/WebCore/platform/text/TextBreakIterator.h (172512 => 172513)


--- trunk/Source/WebCore/platform/text/TextBreakIterator.h	2014-08-13 03:02:35 UTC (rev 172512)
+++ trunk/Source/WebCore/platform/text/TextBreakIterator.h	2014-08-13 03:53:47 UTC (rev 172513)
@@ -183,7 +183,7 @@
 unsigned numGraphemeClusters(const String&);
 // Returns the number of characters which will be less than or equal to
 // the specified grapheme cluster length.
-unsigned numCharactersInGraphemeClusters(const String&, unsigned);
+unsigned numCharactersInGraphemeClusters(const StringView&, unsigned);
 
 }
 

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (172512 => 172513)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2014-08-13 03:02:35 UTC (rev 172512)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2014-08-13 03:53:47 UTC (rev 172513)
@@ -63,6 +63,7 @@
 #include "SVGTextRunRenderingContext.h"
 #include "Settings.h"
 #include "ShadowRoot.h"
+#include "TextBreakIterator.h"
 #include "TransformState.h"
 #include <wtf/NeverDestroyed.h>
 #include <wtf/StackStats.h>
@@ -3585,8 +3586,8 @@
         while (length < oldText.length() && shouldSkipForFirstLetter(oldText[length]))
             length++;
 
-        // Account for first letter.
-        length++;
+        // Account for first grapheme cluster.
+        length += numCharactersInGraphemeClusters(StringView(oldText).substring(length), 1);
         
         // Keep looking for whitespace and allowed punctuation, but avoid
         // accumulating just whitespace into the :first-letter.
@@ -3686,6 +3687,8 @@
 {
     RenderObject* firstLetterObj;
     RenderElement* firstLetterContainer;
+    // FIXME: The first letter might be composed of a variety of code units, and therefore might
+    // be contained within multiple RenderElements.
     getFirstLetter(firstLetterObj, firstLetterContainer);
 
     if (!firstLetterObj)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to