Bug 1260366 - Include the punctuation classes Pd and Pc in ::first-letter because the CSS Pseudo-Elements spec says so. r=jfkthame
authorMats Palmgren <mats@mozilla.com>
Fri, 01 Apr 2016 02:08:15 +0200
changeset 291126 3766631a655f561cb8122c8d788c00b8b96661d1
parent 291125 74f7a5eba75e2364785703d46d3dae6c9f8e5af9
child 291127 f76979736a41aa110d1f87ba17f14efb06e46707
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1260366
milestone48.0a1
Bug 1260366 - Include the punctuation classes Pd and Pc in ::first-letter because the CSS Pseudo-Elements spec says so. r=jfkthame https://www.w3.org/TR/css-pseudo-4/#first-letter-pseudo "Punctuation (i.e, characters that belong to the Punctuation (P*) Unicode general category [UAX44]) that precedes or follows the first typographic letter unit must also be included in the ::first-letter pseudo-element."
dom/base/nsContentUtils.cpp
layout/reftests/first-letter/399941-2-ref.html
layout/reftests/first-letter/399941-2.html
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -1523,33 +1523,42 @@ nsContentUtils::CopyNewlineNormalizedUni
   aDest.BeginWriting(iter);
   sink_traits dest_traits(iter);
   CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits);
   copy_string(aSrcStart, aSrcEnd, normalizer);
   return normalizer.GetCharsWritten();
 }
 
 /**
- * This is used to determine whether a character is in one of the punctuation
- * mark classes which CSS says should be part of the first-letter.
- * See http://www.w3.org/TR/CSS2/selector.html#first-letter and
- *     http://www.w3.org/TR/selectors/#first-letter
+ * This is used to determine whether a character is in one of the classes
+ * which CSS says should be part of the first-letter.  Currently, that is
+ * all punctuation classes (P*).  Note that this is a change from CSS2
+ * which excluded Pc and Pd.
+ *
+ * https://www.w3.org/TR/css-pseudo-4/#first-letter-pseudo
+ * "Punctuation (i.e, characters that belong to the Punctuation (P*) Unicode
+ *  general category [UAX44]) [...]"
  */
 
 // static
 bool
 nsContentUtils::IsFirstLetterPunctuation(uint32_t aChar)
 {
-  uint8_t cat = mozilla::unicode::GetGeneralCategory(aChar);
-
-  return (cat == HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION ||     // Ps
-          cat == HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION ||    // Pe
-          cat == HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION ||  // Pi
-          cat == HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION ||    // Pf
-          cat == HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION);     // Po
+  switch (mozilla::unicode::GetGeneralCategory(aChar)) {
+    case HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION: /* Pc */
+    case HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION:    /* Pd */
+    case HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION:   /* Pe */
+    case HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION:   /* Pf */
+    case HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION: /* Pi */
+    case HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION:   /* Po */
+    case HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION:    /* Ps */
+      return true;
+    default:
+      return false;
+  }
 }
 
 // static
 bool
 nsContentUtils::IsFirstLetterPunctuationAt(const nsTextFragment* aFrag, uint32_t aOffset)
 {
   char16_t h = aFrag->CharAt(aOffset);
   if (!IS_SURROGATE(h)) {
--- a/layout/reftests/first-letter/399941-2-ref.html
+++ b/layout/reftests/first-letter/399941-2-ref.html
@@ -1,17 +1,19 @@
 <!DOCTYPE html>
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
-  <title>Test case for bug 399941.html</title>
+  <title>Test case for bug 399941, revised in bug 1260366 due to spec changes</title>
   <style type="text/css">
    span.fake-first-letter {
      color: lime;
      background-color: olive;
    }
   </style>
  </head>
  <body>
- <!-- Punctuation in class Pc should not be included: there is no first-letter here -->
-  <p>_I_, said the Fly,</p>
+ <!-- Punctuation in class Pc should be included: there is a first-letter here -->
+  <p><span class="fake-first-letter">_I_,</span> said the Fly,</p>
+ <!-- Punctuation in class Pd should be included: there is a first-letter here -->
+  <p><span class="fake-first-letter">-I-,</span> said the Fly,</p>
  </body>
 </html>
--- a/layout/reftests/first-letter/399941-2.html
+++ b/layout/reftests/first-letter/399941-2.html
@@ -1,17 +1,19 @@
 <!DOCTYPE html>
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
-  <title>Test case for bug 399941.html</title>
+  <title>Reference: Test case for bug 399941, revised in bug 1260366 due to spec changes</title>
   <style type="text/css">
    p:first-letter {
      color: lime;
      background-color: olive;
    }
   </style>
  </head>
  <body>
- <!-- Punctuation in class Pc should not be included: there is no first-letter here -->
+ <!-- Punctuation in class Pc should be included: there is a first-letter here -->
   <p>_I_, said the Fly,</p>
+ <!-- Punctuation in class Pd should be included: there is a first-letter here -->
+  <p>-I-, said the Fly,</p>
  </body>
 </html>