Put the 'normal' values for 'font-weight' and 'font-stretch' into the keyword tables. (Bug 522320) r=dholbert
authorL. David Baron <dbaron@dbaron.org>
Sat, 14 Nov 2009 19:16:59 -0800
changeset 34871 40713937700b28cba5f732fce3874999cc02031c
parent 34870 fa53068a3db579abad0e97249fbded96d8217fae
child 34872 2dd63d12d6bcb6ad181ecae8ce4ae73086761693
push idunknown
push userunknown
push dateunknown
reviewersdholbert
bugs522320
milestone1.9.3a1pre
Put the 'normal' values for 'font-weight' and 'font-stretch' into the keyword tables. (Bug 522320) r=dholbert
layout/style/nsCSSDeclaration.cpp
layout/style/nsCSSParser.cpp
layout/style/nsCSSProps.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleNode.cpp
layout/style/test/test_transitions_per_property.html
--- a/layout/style/nsCSSDeclaration.cpp
+++ b/layout/style/nsCSSDeclaration.cpp
@@ -1002,32 +1002,34 @@ nsCSSDeclaration::GetValue(nsCSSProperty
           return NS_OK;
         }
         AppendCSSValueToString(eCSSProperty__x_system_font, *systemFont,
                                aValue);
       } else {
         // The font-stretch and font-size-adjust
         // properties are reset by this shorthand property to their
         // initial values, but can't be represented in its syntax.
-        if (stretch.GetUnit() != eCSSUnit_Normal ||
+        if (stretch.GetUnit() != eCSSUnit_Enumerated ||
+            stretch.GetIntValue() != NS_STYLE_FONT_STRETCH_NORMAL ||
             sizeAdjust.GetUnit() != eCSSUnit_None) {
           return NS_OK;
         }
 
         if (style.GetUnit() != eCSSUnit_Enumerated ||
             style.GetIntValue() != NS_FONT_STYLE_NORMAL) {
           AppendCSSValueToString(eCSSProperty_font_style, style, aValue);
           aValue.Append(PRUnichar(' '));
         }
         if (variant.GetUnit() != eCSSUnit_Enumerated ||
             variant.GetIntValue() != NS_FONT_VARIANT_NORMAL) {
           AppendCSSValueToString(eCSSProperty_font_variant, variant, aValue);
           aValue.Append(PRUnichar(' '));
         }
-        if (weight.GetUnit() != eCSSUnit_Normal) {
+        if (weight.GetUnit() != eCSSUnit_Enumerated ||
+            weight.GetIntValue() != NS_FONT_WEIGHT_NORMAL) {
           AppendCSSValueToString(eCSSProperty_font_weight, weight, aValue);
           aValue.Append(PRUnichar(' '));
         }
         AppendCSSValueToString(eCSSProperty_font_size, size, aValue);
         if (lh.GetUnit() != eCSSUnit_Normal) {
           aValue.Append(PRUnichar('/'));
           AppendCSSValueToString(eCSSProperty_line_height, lh, aValue);
         }
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -122,27 +122,27 @@
 #define VARIANT_AHLP (VARIANT_AH | VARIANT_LP)
 #define VARIANT_AHI  (VARIANT_AH | VARIANT_INTEGER)
 #define VARIANT_AHK  (VARIANT_AH | VARIANT_KEYWORD)
 #define VARIANT_AHKLP (VARIANT_AHLP | VARIANT_KEYWORD)
 #define VARIANT_AHL  (VARIANT_AH | VARIANT_LENGTH)
 #define VARIANT_AHKL (VARIANT_AHK | VARIANT_LENGTH)
 #define VARIANT_HK   (VARIANT_INHERIT | VARIANT_KEYWORD)
 #define VARIANT_HKF  (VARIANT_HK | VARIANT_FREQUENCY)
+#define VARIANT_HKI  (VARIANT_HK | VARIANT_INTEGER)
 #define VARIANT_HKL  (VARIANT_HK | VARIANT_LENGTH)
 #define VARIANT_HKLP (VARIANT_HK | VARIANT_LP)
 #define VARIANT_HKLPO (VARIANT_HKLP | VARIANT_NONE)
 #define VARIANT_HL   (VARIANT_INHERIT | VARIANT_LENGTH)
 #define VARIANT_HI   (VARIANT_INHERIT | VARIANT_INTEGER)
 #define VARIANT_HLP  (VARIANT_HL | VARIANT_PERCENT)
 #define VARIANT_HLPN (VARIANT_HLP | VARIANT_NUMBER)
 #define VARIANT_HLPO (VARIANT_HLP | VARIANT_NONE)
 #define VARIANT_HTP  (VARIANT_INHERIT | VARIANT_TIME | VARIANT_PERCENT)
 #define VARIANT_HMK  (VARIANT_HK | VARIANT_NORMAL)
-#define VARIANT_HMKI (VARIANT_HMK | VARIANT_INTEGER)
 #define VARIANT_HC   (VARIANT_INHERIT | VARIANT_COLOR)
 #define VARIANT_HCK  (VARIANT_HK | VARIANT_COLOR)
 #define VARIANT_HUK  (VARIANT_HK | VARIANT_URL)
 #define VARIANT_HUO  (VARIANT_INHERIT | VARIANT_URL | VARIANT_NONE)
 #define VARIANT_AHUO (VARIANT_AUTO | VARIANT_HUO)
 #define VARIANT_HPN  (VARIANT_INHERIT | VARIANT_PERCENT | VARIANT_NUMBER)
 #define VARIANT_HN   (VARIANT_INHERIT | VARIANT_NUMBER)
 #define VARIANT_HON  (VARIANT_HN | VARIANT_NONE)
@@ -5878,17 +5878,17 @@ CSSParserImpl::ParseSingleValueProperty(
   case eCSSProperty_font_size:
     return ParseNonNegativeVariant(aValue,
                                    VARIANT_HKLP | VARIANT_SYSFONT,
                                    nsCSSProps::kFontSizeKTable);
   case eCSSProperty_font_size_adjust:
     return ParseVariant(aValue, VARIANT_HON | VARIANT_SYSFONT,
                         nsnull);
   case eCSSProperty_font_stretch:
-    return ParseVariant(aValue, VARIANT_HMK | VARIANT_SYSFONT,
+    return ParseVariant(aValue, VARIANT_HK | VARIANT_SYSFONT,
                         nsCSSProps::kFontStretchKTable);
   case eCSSProperty_font_style:
     return ParseVariant(aValue, VARIANT_HK | VARIANT_SYSFONT,
                         nsCSSProps::kFontStyleKTable);
   case eCSSProperty_font_variant:
     return ParseVariant(aValue, VARIANT_HK | VARIANT_SYSFONT,
                         nsCSSProps::kFontVariantKTable);
   case eCSSProperty_font_weight:
@@ -6130,22 +6130,21 @@ CSSParserImpl::ParseFontDescriptorValue(
     return (ParseFontWeight(aValue) &&
             aValue.GetUnit() != eCSSUnit_Inherit &&
             aValue.GetUnit() != eCSSUnit_Initial &&
             (aValue.GetUnit() != eCSSUnit_Enumerated ||
              (aValue.GetIntValue() != NS_STYLE_FONT_WEIGHT_BOLDER &&
               aValue.GetIntValue() != NS_STYLE_FONT_WEIGHT_LIGHTER)));
 
   case eCSSFontDesc_Stretch:
-    // property is VARIANT_HMK|VARIANT_SYSFONT
-    return (ParseVariant(aValue, VARIANT_KEYWORD | VARIANT_NORMAL,
+    // property is VARIANT_HK|VARIANT_SYSFONT
+    return (ParseVariant(aValue, VARIANT_KEYWORD,
                          nsCSSProps::kFontStretchKTable) &&
-            (aValue.GetUnit() != eCSSUnit_Enumerated ||
-             (aValue.GetIntValue() != NS_STYLE_FONT_STRETCH_WIDER &&
-              aValue.GetIntValue() != NS_STYLE_FONT_STRETCH_NARROWER)));
+            (aValue.GetIntValue() != NS_STYLE_FONT_STRETCH_WIDER &&
+             aValue.GetIntValue() != NS_STYLE_FONT_STRETCH_NARROWER));
 
     // These two are unique to @font-face and have their own special grammar.
   case eCSSFontDesc_Src:
     return ParseFontSrc(aValue);
 
   case eCSSFontDesc_UnicodeRange:
     return ParseFontRanges(aValue);
 
@@ -7377,17 +7376,17 @@ CSSParserImpl::ParseFont()
     values[0].SetIntValue(NS_FONT_STYLE_NORMAL, eCSSUnit_Enumerated);
   }
   if ((found & 2) == 0) {
     // Provide default font-variant
     values[1].SetIntValue(NS_FONT_VARIANT_NORMAL, eCSSUnit_Enumerated);
   }
   if ((found & 4) == 0) {
     // Provide default font-weight
-    values[2].SetNormalValue();
+    values[2].SetIntValue(NS_FONT_WEIGHT_NORMAL, eCSSUnit_Enumerated);
   }
 
   // Get mandatory font-size
   nsCSSValue  size;
   if (! ParseVariant(size, VARIANT_KEYWORD | VARIANT_LP, nsCSSProps::kFontSizeKTable)) {
     return PR_FALSE;
   }
 
@@ -7411,28 +7410,30 @@ CSSParserImpl::ParseFont()
         ExpectEndProperty()) {
       AppendValue(eCSSProperty__x_system_font, nsCSSValue(eCSSUnit_None));
       AppendValue(eCSSProperty_font_family, family);
       AppendValue(eCSSProperty_font_style, values[0]);
       AppendValue(eCSSProperty_font_variant, values[1]);
       AppendValue(eCSSProperty_font_weight, values[2]);
       AppendValue(eCSSProperty_font_size, size);
       AppendValue(eCSSProperty_line_height, lineHeight);
-      AppendValue(eCSSProperty_font_stretch, nsCSSValue(eCSSUnit_Normal));
+      AppendValue(eCSSProperty_font_stretch,
+                  nsCSSValue(NS_FONT_STRETCH_NORMAL, eCSSUnit_Enumerated));
       AppendValue(eCSSProperty_font_size_adjust, nsCSSValue(eCSSUnit_None));
       return PR_TRUE;
     }
   }
   return PR_FALSE;
 }
 
 PRBool
 CSSParserImpl::ParseFontWeight(nsCSSValue& aValue)
 {
-  if (ParseVariant(aValue, VARIANT_HMKI | VARIANT_SYSFONT, nsCSSProps::kFontWeightKTable)) {
+  if (ParseVariant(aValue, VARIANT_HKI | VARIANT_SYSFONT,
+                   nsCSSProps::kFontWeightKTable)) {
     if (eCSSUnit_Integer == aValue.GetUnit()) { // ensure unit value
       PRInt32 intValue = aValue.GetIntValue();
       if ((100 <= intValue) &&
           (intValue <= 900) &&
           (0 == (intValue % 100))) {
         return PR_TRUE;
       } else {
         UngetToken();
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -843,16 +843,17 @@ const PRInt32 nsCSSProps::kFontSizeKTabl
 
 const PRInt32 nsCSSProps::kFontStretchKTable[] = {
   eCSSKeyword_wider, NS_STYLE_FONT_STRETCH_WIDER,
   eCSSKeyword_narrower, NS_STYLE_FONT_STRETCH_NARROWER,
   eCSSKeyword_ultra_condensed, NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED,
   eCSSKeyword_extra_condensed, NS_STYLE_FONT_STRETCH_EXTRA_CONDENSED,
   eCSSKeyword_condensed, NS_STYLE_FONT_STRETCH_CONDENSED,
   eCSSKeyword_semi_condensed, NS_STYLE_FONT_STRETCH_SEMI_CONDENSED,
+  eCSSKeyword_normal, NS_STYLE_FONT_STRETCH_NORMAL,
   eCSSKeyword_semi_expanded, NS_STYLE_FONT_STRETCH_SEMI_EXPANDED,
   eCSSKeyword_expanded, NS_STYLE_FONT_STRETCH_EXPANDED,
   eCSSKeyword_extra_expanded, NS_STYLE_FONT_STRETCH_EXTRA_EXPANDED,
   eCSSKeyword_ultra_expanded, NS_STYLE_FONT_STRETCH_ULTRA_EXPANDED,
   eCSSKeyword_UNKNOWN,-1
 };
 
 const PRInt32 nsCSSProps::kFontStyleKTable[] = {
@@ -864,16 +865,17 @@ const PRInt32 nsCSSProps::kFontStyleKTab
 
 const PRInt32 nsCSSProps::kFontVariantKTable[] = {
   eCSSKeyword_normal, NS_STYLE_FONT_VARIANT_NORMAL,
   eCSSKeyword_small_caps, NS_STYLE_FONT_VARIANT_SMALL_CAPS,
   eCSSKeyword_UNKNOWN,-1
 };
 
 const PRInt32 nsCSSProps::kFontWeightKTable[] = {
+  eCSSKeyword_normal, NS_STYLE_FONT_WEIGHT_NORMAL,
   eCSSKeyword_bold, NS_STYLE_FONT_WEIGHT_BOLD,
   eCSSKeyword_bolder, NS_STYLE_FONT_WEIGHT_BOLDER,
   eCSSKeyword_lighter, NS_STYLE_FONT_WEIGHT_LIGHTER,
   eCSSKeyword_UNKNOWN,-1
 };
 
 const PRInt32 nsCSSProps::kIMEModeKTable[] = {
   eCSSKeyword_normal, NS_STYLE_IME_MODE_NORMAL,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -1220,19 +1220,17 @@ nsComputedDOMStyle::GetFontStretch(nsIDO
   // The computed value space isn't actually representable in string
   // form, so just represent anything with widers or narrowers in it as
   // 'wider' or 'narrower'.
   PR_STATIC_ASSERT(NS_FONT_STRETCH_NARROWER % 2 == 0);
   PR_STATIC_ASSERT(NS_FONT_STRETCH_WIDER % 2 == 0);
   PR_STATIC_ASSERT(NS_FONT_STRETCH_NARROWER + NS_FONT_STRETCH_WIDER == 0);
   PR_STATIC_ASSERT(NS_FONT_STRETCH_NARROWER < 0);
   PRInt16 stretch = font->mFont.stretch;
-  if (stretch == NS_FONT_STRETCH_NORMAL) {
-    val->SetIdent(eCSSKeyword_normal);
-  } else if (stretch <= NS_FONT_STRETCH_NARROWER / 2) {
+  if (stretch <= NS_FONT_STRETCH_NARROWER / 2) {
     val->SetIdent(eCSSKeyword_narrower);
   } else if (stretch >= NS_FONT_STRETCH_WIDER / 2) {
     val->SetIdent(eCSSKeyword_wider);
   } else {
     val->SetIdent(
       nsCSSProps::ValueToKeywordEnum(stretch, nsCSSProps::kFontStretchKTable));
   }
 
@@ -1258,18 +1256,16 @@ nsComputedDOMStyle::GetFontWeight(nsIDOM
   NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
 
   const nsStyleFont* font = GetStyleFont();
 
   // XXX This doesn't deal with bolder/lighter very well.
   const nsCSSKeyword enum_weight =
     nsCSSProps::ValueToKeywordEnum(font->mFont.weight,
                                    nsCSSProps::kFontWeightKTable);
-  // FIXME: Since 'normal' isn't in the keyword table, we serialize 700
-  // to bold but 400 as-is.
   if (enum_weight != eCSSKeyword_UNKNOWN) {
     val->SetIdent(enum_weight);
   } else {
     val->SetNumber(font->mFont.weight);
   }
 
   return CallQueryInterface(val, aValue);
 }
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -2820,59 +2820,57 @@ nsRuleNode::SetFont(nsPresContext* aPres
 
   // font-variant: enum, inherit, initial, -moz-system-font
   SetDiscrete(aFontData.mVariant, aFont->mFont.variant, aCanStoreInRuleTree,
               SETDSC_ENUMERATED | SETDSC_SYSTEM_FONT,
               aParentFont->mFont.variant,
               defaultVariableFont->variant,
               0, 0, 0, systemFont.variant);
 
-  // font-weight: int, enum, normal, inherit, initial, -moz-system-font
+  // font-weight: int, enum, inherit, initial, -moz-system-font
   // special handling for enum
   if (eCSSUnit_Enumerated == aFontData.mWeight.GetUnit()) {
     PRInt32 value = aFontData.mWeight.GetIntValue();
     switch (value) {
       case NS_STYLE_FONT_WEIGHT_NORMAL:
       case NS_STYLE_FONT_WEIGHT_BOLD:
         aFont->mFont.weight = value;
         break;
       case NS_STYLE_FONT_WEIGHT_BOLDER:
       case NS_STYLE_FONT_WEIGHT_LIGHTER:
         aCanStoreInRuleTree = PR_FALSE;
         aFont->mFont.weight = nsStyleUtil::ConstrainFontWeight(aParentFont->mFont.weight + value);
         break;
     }
   } else
     SetDiscrete(aFontData.mWeight, aFont->mFont.weight, aCanStoreInRuleTree,
-                SETDSC_INTEGER | SETDSC_NORMAL | SETDSC_SYSTEM_FONT,
+                SETDSC_INTEGER | SETDSC_SYSTEM_FONT,
                 aParentFont->mFont.weight,
                 defaultVariableFont->weight,
-                0, 0,
-                NS_STYLE_FONT_WEIGHT_NORMAL,
-                systemFont.weight);
-
-  // font-stretch: enum, normal, inherit
+                0, 0, 0, systemFont.weight);
+
+  // font-stretch: enum, inherit
   if (eCSSUnit_Enumerated == aFontData.mStretch.GetUnit()) {
     PRInt32 value = aFontData.mStretch.GetIntValue();
     switch (value) {
       case NS_FONT_STRETCH_WIDER:
       case NS_FONT_STRETCH_NARROWER:
         aCanStoreInRuleTree = PR_FALSE;
         aFont->mFont.stretch = aParentFont->mFont.stretch + value;
         break;
       default:
         aFont->mFont.stretch = value;
         break;
     }
   } else
     SetDiscrete(aFontData.mStretch, aFont->mFont.stretch, aCanStoreInRuleTree,
-                SETDSC_NORMAL | SETDSC_SYSTEM_FONT,
+                SETDSC_SYSTEM_FONT,
                 aParentFont->mFont.stretch,
                 defaultVariableFont->stretch,
-                0, 0, NS_FONT_STRETCH_NORMAL, systemFont.stretch);
+                0, 0, 0, systemFont.stretch);
 
 #ifdef MOZ_MATHML
   // Compute scriptlevel, scriptminsize and scriptsizemultiplier now so
   // they're available for font-size computation.
 
   // -moz-script-min-size: length
   if (aFontData.mScriptMinSize.IsLengthUnit()) {
     // scriptminsize in font units (em, ex) has to be interpreted relative
--- a/layout/style/test/test_transitions_per_property.html
+++ b/layout/style/test/test_transitions_per_property.html
@@ -455,34 +455,30 @@ function test_font_stretch(prop) {
      "font-stretch property " + prop + ": interpolation of font-stretches");
 }
 
 function test_font_weight(prop) {
   is(prop, "font-weight", "only designed for one property");
 
   div.style.setProperty("-moz-transition-property", "none", "");
   div.style.setProperty(prop, "normal", "");
-  // FIXME: Why does this give 400 but bold gives bold?
-  // (Yes, it's normal not being in the prop table...)
-  is(cs.getPropertyValue(prop), "400",
+  is(cs.getPropertyValue(prop), "normal",
      "font-weight property " + prop + ": computed value before transition");
   div.style.setProperty("-moz-transition-property", prop, "");
   div.style.setProperty(prop, "900", "");
   is(cs.getPropertyValue(prop), "600",
      "font-weight property " + prop + ": interpolation of font-weights");
   div.style.setProperty(prop, "lighter", "");
   // We currently get 399; mark this as todo.
   todo_is(cs.getPropertyValue(prop), "lighter",
      "font-weight property " + prop + ": can't interpolate bolder/lighter");
   div.style.setProperty(prop, "700", "");
   is(cs.getPropertyValue(prop), "bold",
      "font-weight property " + prop + ": computed value before transition");
   div.style.setProperty(prop, "100", "");
-  // FIXME: Why does this give 400 but bold gives bold?
-  // (Yes, it's normal not being in the prop table...)
-  is(cs.getPropertyValue(prop), "400",
+  is(cs.getPropertyValue(prop), "normal",
      "font-weight property " + prop + ": interpolation of font-weights");
 }
 
 </script>
 </pre>
 </body>
 </html>