Attachment #355458: CSS3 rem units support for bug #472195

View | Details | Raw Unified | Return to bug 472195
Collapse All | Expand All

(-)a/content/base/src/nsGkAtomList.h (+1 lines)
Line     Link Here 
 Lines 754-769   GK_ATOM(radio, "radio") Link Here 
754
GK_ATOM(radio, "radio")
754
GK_ATOM(radio, "radio")
755
GK_ATOM(radiogroup, "radiogroup")
755
GK_ATOM(radiogroup, "radiogroup")
756
GK_ATOM(readonly, "readonly")
756
GK_ATOM(readonly, "readonly")
757
GK_ATOM(rect, "rect")
757
GK_ATOM(rect, "rect")
758
GK_ATOM(rectangle, "rectangle")
758
GK_ATOM(rectangle, "rectangle")
759
GK_ATOM(ref, "ref")
759
GK_ATOM(ref, "ref")
760
GK_ATOM(refresh, "refresh")
760
GK_ATOM(refresh, "refresh")
761
GK_ATOM(rel, "rel")
761
GK_ATOM(rel, "rel")
762
GK_ATOM(rem, "rem")
762
GK_ATOM(removeelement, "removeelement")
763
GK_ATOM(removeelement, "removeelement")
763
GK_ATOM(repeat, "repeat")
764
GK_ATOM(repeat, "repeat")
764
GK_ATOM(replace, "replace")
765
GK_ATOM(replace, "replace")
765
GK_ATOM(reset, "reset")
766
GK_ATOM(reset, "reset")
766
GK_ATOM(resizeafter, "resizeafter")
767
GK_ATOM(resizeafter, "resizeafter")
767
GK_ATOM(resizebefore, "resizebefore")
768
GK_ATOM(resizebefore, "resizebefore")
768
GK_ATOM(resizer, "resizer")
769
GK_ATOM(resizer, "resizer")
769
GK_ATOM(resolution, "resolution")
770
GK_ATOM(resolution, "resolution")
(-)a/layout/style/nsCSSDeclaration.cpp (+1 lines)
Line     Link Here 
 Lines 469-484   nsCSSDeclaration::AppendCSSValueToString Link Here 
469
    case eCSSUnit_Point:        aResult.AppendLiteral("pt");   break;
469
    case eCSSUnit_Point:        aResult.AppendLiteral("pt");   break;
470
    case eCSSUnit_Pica:         aResult.AppendLiteral("pc");   break;
470
    case eCSSUnit_Pica:         aResult.AppendLiteral("pc");   break;
471
    case eCSSUnit_Didot:        aResult.AppendLiteral("dt");   break;
471
    case eCSSUnit_Didot:        aResult.AppendLiteral("dt");   break;
472
    case eCSSUnit_Cicero:       aResult.AppendLiteral("cc");   break;
472
    case eCSSUnit_Cicero:       aResult.AppendLiteral("cc");   break;
473
473
474
    case eCSSUnit_EM:           aResult.AppendLiteral("em");   break;
474
    case eCSSUnit_EM:           aResult.AppendLiteral("em");   break;
475
    case eCSSUnit_XHeight:      aResult.AppendLiteral("ex");   break;
475
    case eCSSUnit_XHeight:      aResult.AppendLiteral("ex");   break;
476
    case eCSSUnit_Char:         aResult.AppendLiteral("ch");   break;
476
    case eCSSUnit_Char:         aResult.AppendLiteral("ch");   break;
477
    case eCSSUnit_REM:          aResult.AppendLiteral("rem");  break;
477
478
478
    case eCSSUnit_Pixel:        aResult.AppendLiteral("px");   break;
479
    case eCSSUnit_Pixel:        aResult.AppendLiteral("px");   break;
479
480
480
    case eCSSUnit_Degree:       aResult.AppendLiteral("deg");  break;
481
    case eCSSUnit_Degree:       aResult.AppendLiteral("deg");  break;
481
    case eCSSUnit_Grad:         aResult.AppendLiteral("grad"); break;
482
    case eCSSUnit_Grad:         aResult.AppendLiteral("grad"); break;
482
    case eCSSUnit_Radian:       aResult.AppendLiteral("rad");  break;
483
    case eCSSUnit_Radian:       aResult.AppendLiteral("rad");  break;
483
484
484
    case eCSSUnit_Hertz:        aResult.AppendLiteral("Hz");   break;
485
    case eCSSUnit_Hertz:        aResult.AppendLiteral("Hz");   break;
(-)a/layout/style/nsCSSParser.cpp (+1 lines)
Line     Link Here 
 Lines 4199-4214   const UnitInfo UnitData[] = { Link Here 
4199
const UnitInfo UnitData[] = {
4199
const UnitInfo UnitData[] = {
4200
  { STR_WITH_LEN("px"), eCSSUnit_Pixel, VARIANT_LENGTH },
4200
  { STR_WITH_LEN("px"), eCSSUnit_Pixel, VARIANT_LENGTH },
4201
  { STR_WITH_LEN("em"), eCSSUnit_EM, VARIANT_LENGTH },
4201
  { STR_WITH_LEN("em"), eCSSUnit_EM, VARIANT_LENGTH },
4202
  { STR_WITH_LEN("ex"), eCSSUnit_XHeight, VARIANT_LENGTH },
4202
  { STR_WITH_LEN("ex"), eCSSUnit_XHeight, VARIANT_LENGTH },
4203
  { STR_WITH_LEN("pt"), eCSSUnit_Point, VARIANT_LENGTH },
4203
  { STR_WITH_LEN("pt"), eCSSUnit_Point, VARIANT_LENGTH },
4204
  { STR_WITH_LEN("in"), eCSSUnit_Inch, VARIANT_LENGTH },
4204
  { STR_WITH_LEN("in"), eCSSUnit_Inch, VARIANT_LENGTH },
4205
  { STR_WITH_LEN("cm"), eCSSUnit_Centimeter, VARIANT_LENGTH },
4205
  { STR_WITH_LEN("cm"), eCSSUnit_Centimeter, VARIANT_LENGTH },
4206
  { STR_WITH_LEN("ch"), eCSSUnit_Char, VARIANT_LENGTH },
4206
  { STR_WITH_LEN("ch"), eCSSUnit_Char, VARIANT_LENGTH },
4207
  { STR_WITH_LEN("rem"), eCSSUnit_REM, VARIANT_LENGTH },
4207
  { STR_WITH_LEN("mm"), eCSSUnit_Millimeter, VARIANT_LENGTH },
4208
  { STR_WITH_LEN("mm"), eCSSUnit_Millimeter, VARIANT_LENGTH },
4208
  { STR_WITH_LEN("pc"), eCSSUnit_Pica, VARIANT_LENGTH },
4209
  { STR_WITH_LEN("pc"), eCSSUnit_Pica, VARIANT_LENGTH },
4209
  { STR_WITH_LEN("deg"), eCSSUnit_Degree, VARIANT_ANGLE },
4210
  { STR_WITH_LEN("deg"), eCSSUnit_Degree, VARIANT_ANGLE },
4210
  { STR_WITH_LEN("grad"), eCSSUnit_Grad, VARIANT_ANGLE },
4211
  { STR_WITH_LEN("grad"), eCSSUnit_Grad, VARIANT_ANGLE },
4211
  { STR_WITH_LEN("rad"), eCSSUnit_Radian, VARIANT_ANGLE },
4212
  { STR_WITH_LEN("rad"), eCSSUnit_Radian, VARIANT_ANGLE },
4212
  { STR_WITH_LEN("hz"), eCSSUnit_Hertz, VARIANT_FREQUENCY },
4213
  { STR_WITH_LEN("hz"), eCSSUnit_Hertz, VARIANT_FREQUENCY },
4213
  { STR_WITH_LEN("khz"), eCSSUnit_Kilohertz, VARIANT_FREQUENCY },
4214
  { STR_WITH_LEN("khz"), eCSSUnit_Kilohertz, VARIANT_FREQUENCY },
4214
  { STR_WITH_LEN("s"), eCSSUnit_Seconds, VARIANT_TIME },
4215
  { STR_WITH_LEN("s"), eCSSUnit_Seconds, VARIANT_TIME },
(-)a/layout/style/nsCSSValue.h (+1 lines)
Line     Link Here 
 Lines 137-152   enum nsCSSUnit { Link Here 
137
  eCSSUnit_Didot        = 400,    // (float) 15 didots == 16 points
137
  eCSSUnit_Didot        = 400,    // (float) 15 didots == 16 points
138
  eCSSUnit_Cicero       = 401,    // (float) 12 didots
138
  eCSSUnit_Cicero       = 401,    // (float) 12 didots
139
139
140
  // Length units - relative
140
  // Length units - relative
141
  // Font relative measure
141
  // Font relative measure
142
  eCSSUnit_EM           = 800,    // (float) == current font size
142
  eCSSUnit_EM           = 800,    // (float) == current font size
143
  eCSSUnit_XHeight      = 801,    // (float) distance from top of lower case x to baseline
143
  eCSSUnit_XHeight      = 801,    // (float) distance from top of lower case x to baseline
144
  eCSSUnit_Char         = 802,    // (float) number of characters, used for width with monospace font
144
  eCSSUnit_Char         = 802,    // (float) number of characters, used for width with monospace font
145
  eCSSUnit_REM          = 803,    // (float) == root element font size
145
146
146
  // Screen relative measure
147
  // Screen relative measure
147
  eCSSUnit_Pixel        = 900,    // (float) CSS pixel unit
148
  eCSSUnit_Pixel        = 900,    // (float) CSS pixel unit
148
149
149
  // Angular units
150
  // Angular units
150
  eCSSUnit_Degree       = 1000,    // (float) 360 per circle
151
  eCSSUnit_Degree       = 1000,    // (float) 360 per circle
151
  eCSSUnit_Grad         = 1001,    // (float) 400 per circle
152
  eCSSUnit_Grad         = 1001,    // (float) 400 per circle
152
  eCSSUnit_Radian       = 1002,    // (float) 2*pi per circle
153
  eCSSUnit_Radian       = 1002,    // (float) 2*pi per circle
(-)a/layout/style/nsRuleNode.cpp (+14 lines)
Line     Link Here 
 Lines 190-205   static nscoord CalcLengthWith(const nsCS Link Here 
190
    aStyleFont = aStyleContext->GetStyleFont();
190
    aStyleFont = aStyleContext->GetStyleFont();
191
  }
191
  }
192
  if (aFontSize == -1) {
192
  if (aFontSize == -1) {
193
    // XXX Should this be aStyleFont->mSize instead to avoid taking minfontsize
193
    // XXX Should this be aStyleFont->mSize instead to avoid taking minfontsize
194
    // prefs into account?
194
    // prefs into account?
195
    aFontSize = aStyleFont->mFont.size;
195
    aFontSize = aStyleFont->mFont.size;
196
  }
196
  }
197
  switch (unit) {
197
  switch (unit) {
198
    case eCSSUnit_REM: {
199
      //nsStyleContext* rootStyle;
200
      nsRefPtr<nsStyleContext> rootStyle;
201
202
      //NS_WARNING("calculating rem %s\n", aValue);
203
      nsIContent* docElement = aPresContext->Document()->GetRootContent();
204
205
      rootStyle = aPresContext->StyleSet()->ResolveStyleFor(docElement, nsnull);
206
      if (rootStyle) {
207
        aStyleFont = rootStyle->GetStyleFont();
208
        aFontSize = aStyleFont->mFont.size;
209
      }
210
    }
211
    // Fall through...
198
    case eCSSUnit_EM: {
212
    case eCSSUnit_EM: {
199
      return NSToCoordRoundWithClamp(aValue.GetFloatValue() * float(aFontSize));
213
      return NSToCoordRoundWithClamp(aValue.GetFloatValue() * float(aFontSize));
200
      // XXX scale against font metrics height instead?
214
      // XXX scale against font metrics height instead?
201
    }
215
    }
202
    case eCSSUnit_XHeight: {
216
    case eCSSUnit_XHeight: {
203
      nsFont font = aStyleFont->mFont;
217
      nsFont font = aStyleFont->mFont;
204
      font.size = aFontSize;
218
      font.size = aFontSize;
205
      nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
219
      nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);

Return to bug 472195