Attachment #356148: CSS3 rem units support (work in progress) for bug #472195

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

(-)a/content/base/src/nsGkAtomList.h (-1 / +1 lines)
Line     Link Here 
 Lines 754-769    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")
 Lines 1390-1406    Link Here 
1390
GK_ATOM(other_, "other")
1391
GK_ATOM(other_, "other")
1391
GK_ATOM(partialdiff_, "partialdiff")
1392
GK_ATOM(partialdiff_, "partialdiff")
1392
GK_ATOM(plus_, "plus")
1393
GK_ATOM(plus_, "plus")
1393
GK_ATOM(power_, "power")
1394
GK_ATOM(power_, "power")
1394
GK_ATOM(product_, "product")
1395
GK_ATOM(product_, "product")
1395
GK_ATOM(prsubset_, "prsubset")
1396
GK_ATOM(prsubset_, "prsubset")
1396
GK_ATOM(quotient_, "quotient")
1397
GK_ATOM(quotient_, "quotient")
1397
GK_ATOM(reln_, "reln")
1398
GK_ATOM(reln_, "reln")
1398
GK_ATOM(rem_, "rem")
1399
GK_ATOM(root_, "root")
1399
GK_ATOM(root_, "root")
1400
GK_ATOM(rowalign_, "rowalign")
1400
GK_ATOM(rowalign_, "rowalign")
1401
GK_ATOM(rowlines_, "rowlines")
1401
GK_ATOM(rowlines_, "rowlines")
1402
GK_ATOM(rowspacing_, "rowspacing")
1402
GK_ATOM(rowspacing_, "rowspacing")
1403
GK_ATOM(rquote_, "rquote")
1403
GK_ATOM(rquote_, "rquote")
1404
GK_ATOM(rspace_, "rspace")
1404
GK_ATOM(rspace_, "rspace")
1405
GK_ATOM(scriptlevel_, "scriptlevel")
1405
GK_ATOM(scriptlevel_, "scriptlevel")
1406
GK_ATOM(scriptminsize_, "scriptminsize")
1406
GK_ATOM(scriptminsize_, "scriptminsize")
(-)a/layout/style/nsCSSDeclaration.cpp (+1 lines)
Line     Link Here 
 Lines 469-484    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_RootEM:       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    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_RootEM, 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    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_RootEM       = 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 / +52 lines)
Line     Link Here 
 Lines 161-181    Link Here 
161
       (start == PRUnichar('\'')))) {
161
       (start == PRUnichar('\'')))) {
162
    PRInt32 length = aString.Length();
162
    PRInt32 length = aString.Length();
163
    aString.Truncate(length - 1);
163
    aString.Truncate(length - 1);
164
    aString.Cut(0, 1);
164
    aString.Cut(0, 1);
165
  }
165
  }
166
  return aString;
166
  return aString;
167
}
167
}
168
168
169
static inline nscoord ScaleCoord(const nsCSSValue &aValue, float factor)
170
{
171
  return NSToCoordRoundWithClamp(aValue.GetFloatValue() * factor);
172
}
173
169
static nscoord CalcLengthWith(const nsCSSValue& aValue,
174
static nscoord CalcLengthWith(const nsCSSValue& aValue,
170
                              nscoord aFontSize,
175
                              nscoord aFontSize,
171
                              const nsStyleFont* aStyleFont,
176
                              const nsStyleFont* aStyleFont,
172
                              nsStyleContext* aStyleContext,
177
                              nsStyleContext* aStyleContext,
173
                              nsPresContext* aPresContext,
178
                              nsPresContext* aPresContext,
179
                              PRBool useProvidedRootEmSize,
174
                              PRBool& aInherited)
180
                              PRBool& aInherited)
175
{
181
{
176
  NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
182
  NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
177
  NS_ASSERTION(aStyleFont || aStyleContext, "Must have style data");
183
  NS_ASSERTION(aStyleFont || aStyleContext, "Must have style data");
178
  NS_ASSERTION(aPresContext, "Must have prescontext");
184
  NS_ASSERTION(aPresContext, "Must have prescontext");
179
185
180
  if (aValue.IsFixedLengthUnit()) {
186
  if (aValue.IsFixedLengthUnit()) {
181
    return aPresContext->TwipsToAppUnits(aValue.GetLengthTwips());
187
    return aPresContext->TwipsToAppUnits(aValue.GetLengthTwips());
 Lines 190-245    Link Here 
190
    aStyleFont = aStyleContext->GetStyleFont();
196
    aStyleFont = aStyleContext->GetStyleFont();
191
  }
197
  }
192
  if (aFontSize == -1) {
198
  if (aFontSize == -1) {
193
    // XXX Should this be aStyleFont->mSize instead to avoid taking minfontsize
199
    // XXX Should this be aStyleFont->mSize instead to avoid taking minfontsize
194
    // prefs into account?
200
    // prefs into account?
195
    aFontSize = aStyleFont->mFont.size;
201
    aFontSize = aStyleFont->mFont.size;
196
  }
202
  }
197
  switch (unit) {
203
  switch (unit) {
204
    case eCSSUnit_RootEM: {
205
      nscoord rootFontSize;
206
207
      if (useProvidedRootEmSize) {
208
        // We should use the provided aFontSize as the reference length to
209
        // scale. This only happens when we are calculating something on the
210
        // root element, in which case aFontSize is already the value we want.
211
        rootFontSize = aFontSize;
212
      } else {
213
        // This is not the root element or we are calculating something other
214
        // than font size, so rem is relative to the root element's font size.
215
        nsRefPtr<nsStyleContext> rootStyle;
216
        const nsStyleFont *rootStyleFont = aStyleFont;
217
        nsIContent* docElement = aPresContext->Document()->GetRootContent();
218
219
        rootStyle = aPresContext->StyleSet()->ResolveStyleFor(docElement,
220
                                                              nsnull);
221
        if (rootStyle) {
222
          rootStyleFont = rootStyle->GetStyleFont();
223
          rootFontSize = rootStyleFont->mFont.size;
224
        }
225
      }
226
227
      return ScaleCoord(aValue, float(rootFontSize));
228
    }
198
    case eCSSUnit_EM: {
229
    case eCSSUnit_EM: {
199
      return NSToCoordRoundWithClamp(aValue.GetFloatValue() * float(aFontSize));
230
      return ScaleCoord(aValue, float(aFontSize));
200
      // XXX scale against font metrics height instead?
231
      // XXX scale against font metrics height instead?
201
    }
232
    }
202
    case eCSSUnit_XHeight: {
233
    case eCSSUnit_XHeight: {
203
      nsFont font = aStyleFont->mFont;
234
      nsFont font = aStyleFont->mFont;
204
      font.size = aFontSize;
235
      font.size = aFontSize;
205
      nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
236
      nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
206
      nscoord xHeight;
237
      nscoord xHeight;
207
      fm->GetXHeight(xHeight);
238
      fm->GetXHeight(xHeight);
208
      return NSToCoordRoundWithClamp(aValue.GetFloatValue() * float(xHeight));
239
      return ScaleCoord(aValue, float(xHeight));
209
    }
240
    }
210
    case eCSSUnit_Char: {
241
    case eCSSUnit_Char: {
211
      nsFont font = aStyleFont->mFont;
242
      nsFont font = aStyleFont->mFont;
212
      font.size = aFontSize;
243
      font.size = aFontSize;
213
      nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
244
      nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
214
      nsCOMPtr<nsIThebesFontMetrics> tfm(do_QueryInterface(fm));
245
      nsCOMPtr<nsIThebesFontMetrics> tfm(do_QueryInterface(fm));
215
      gfxFloat zeroWidth = (tfm->GetThebesFontGroup()->GetFontAt(0)
246
      gfxFloat zeroWidth = (tfm->GetThebesFontGroup()->GetFontAt(0)
216
                            ->GetMetrics().zeroOrAveCharWidth);
247
                            ->GetMetrics().zeroOrAveCharWidth);
217
248
218
      return NSToCoordRoundWithClamp(aValue.GetFloatValue() *
249
      return ScaleCoord(aValue, NS_ceil(aPresContext->AppUnitsPerDevPixel() *
219
                            NS_ceil(aPresContext->AppUnitsPerDevPixel() *
250
                                        zeroWidth));
220
                                    zeroWidth));
221
    }
251
    }
222
    default:
252
    default:
223
      NS_NOTREACHED("unexpected unit");
253
      NS_NOTREACHED("unexpected unit");
224
      break;
254
      break;
225
  }
255
  }
226
  return 0;
256
  return 0;
227
}
257
}
228
258
229
/* static */ nscoord
259
/* static */ nscoord
230
nsRuleNode::CalcLength(const nsCSSValue& aValue,
260
nsRuleNode::CalcLength(const nsCSSValue& aValue,
231
                       nsStyleContext* aStyleContext,
261
                       nsStyleContext* aStyleContext,
232
                       nsPresContext* aPresContext,
262
                       nsPresContext* aPresContext,
233
                       PRBool& aInherited)
263
                       PRBool& aInherited)
234
{
264
{
235
  NS_ASSERTION(aStyleContext, "Must have style data");
265
  NS_ASSERTION(aStyleContext, "Must have style data");
236
266
237
  return CalcLengthWith(aValue, -1, nsnull, aStyleContext, aPresContext, aInherited);
267
  return CalcLengthWith(aValue, -1, nsnull, aStyleContext, aPresContext,
268
                        PR_FALSE, aInherited);
238
}
269
}
239
270
240
/* Inline helper function to redirect requests to CalcLength. */
271
/* Inline helper function to redirect requests to CalcLength. */
241
static inline nscoord CalcLength(const nsCSSValue& aValue,
272
static inline nscoord CalcLength(const nsCSSValue& aValue,
242
                                 nsStyleContext* aStyleContext,
273
                                 nsStyleContext* aStyleContext,
243
                                 nsPresContext* aPresContext,
274
                                 nsPresContext* aPresContext,
244
                                 PRBool& aInherited)
275
                                 PRBool& aInherited)
245
{
276
{
 Lines 249-265    Link Here 
249
280
250
/* static */ nscoord
281
/* static */ nscoord
251
nsRuleNode::CalcLengthWithInitialFont(nsPresContext* aPresContext,
282
nsRuleNode::CalcLengthWithInitialFont(nsPresContext* aPresContext,
252
                                      const nsCSSValue& aValue)
283
                                      const nsCSSValue& aValue)
253
{
284
{
254
  nsStyleFont defaultFont(aPresContext);
285
  nsStyleFont defaultFont(aPresContext);
255
  PRBool inherited;
286
  PRBool inherited;
256
  return CalcLengthWith(aValue, -1, &defaultFont, nsnull, aPresContext,
287
  return CalcLengthWith(aValue, -1, &defaultFont, nsnull, aPresContext,
257
                        inherited);
288
                        PR_FALSE, inherited);
258
}
289
}
259
290
260
#define SETCOORD_NORMAL                 0x01   // N
291
#define SETCOORD_NORMAL                 0x01   // N
261
#define SETCOORD_AUTO                   0x02   // A
292
#define SETCOORD_AUTO                   0x02   // A
262
#define SETCOORD_INHERIT                0x04   // H
293
#define SETCOORD_INHERIT                0x04   // H
263
#define SETCOORD_PERCENT                0x08   // P
294
#define SETCOORD_PERCENT                0x08   // P
264
#define SETCOORD_FACTOR                 0x10   // F
295
#define SETCOORD_FACTOR                 0x10   // F
265
#define SETCOORD_LENGTH                 0x20   // L
296
#define SETCOORD_LENGTH                 0x20   // L
 Lines 2277-2292    Link Here 
2277
                        const nsRuleDataFont& aFontData,
2308
                        const nsRuleDataFont& aFontData,
2278
                        const nsStyleFont* aFont,
2309
                        const nsStyleFont* aFont,
2279
                        const nsStyleFont* aParentFont,
2310
                        const nsStyleFont* aParentFont,
2280
                        nscoord* aSize,
2311
                        nscoord* aSize,
2281
                        const nsFont& aSystemFont,
2312
                        const nsFont& aSystemFont,
2282
                        nscoord aParentSize,
2313
                        nscoord aParentSize,
2283
                        nscoord aScriptLevelAdjustedParentSize,
2314
                        nscoord aScriptLevelAdjustedParentSize,
2284
                        PRBool aUsedStartStruct,
2315
                        PRBool aUsedStartStruct,
2316
                        PRBool atRoot,
2285
                        PRBool& aInherited)
2317
                        PRBool& aInherited)
2286
{
2318
{
2287
  PRBool zoom = PR_FALSE;
2319
  PRBool zoom = PR_FALSE;
2288
  PRInt32 baseSize = (PRInt32) aPresContext->
2320
  PRInt32 baseSize = (PRInt32) aPresContext->
2289
    GetDefaultFont(aFont->mGenericID)->size;
2321
    GetDefaultFont(aFont->mGenericID)->size;
2290
  if (eCSSUnit_Enumerated == aFontData.mSize.GetUnit()) {
2322
  if (eCSSUnit_Enumerated == aFontData.mSize.GetUnit()) {
2291
    PRInt32 value = aFontData.mSize.GetIntValue();
2323
    PRInt32 value = aFontData.mSize.GetIntValue();
2292
    PRInt32 scaler = aPresContext->FontScaler();
2324
    PRInt32 scaler = aPresContext->FontScaler();
 Lines 2332-2348    Link Here 
2332
      NS_NOTREACHED("unexpected value");
2364
      NS_NOTREACHED("unexpected value");
2333
    }
2365
    }
2334
  }
2366
  }
2335
  else if (aFontData.mSize.IsLengthUnit()) {
2367
  else if (aFontData.mSize.IsLengthUnit()) {
2336
    // Note that font-based length units use the parent's size unadjusted
2368
    // Note that font-based length units use the parent's size unadjusted
2337
    // for scriptlevel changes. A scriptlevel change between us and the parent
2369
    // for scriptlevel changes. A scriptlevel change between us and the parent
2338
    // is simply ignored.
2370
    // is simply ignored.
2339
    *aSize = CalcLengthWith(aFontData.mSize, aParentSize, aParentFont, nsnull,
2371
    *aSize = CalcLengthWith(aFontData.mSize, aParentSize, aParentFont, nsnull,
2340
                        aPresContext, aInherited);
2372
                        aPresContext, atRoot, aInherited);
2341
    zoom = aFontData.mSize.IsFixedLengthUnit() ||
2373
    zoom = aFontData.mSize.IsFixedLengthUnit() ||
2342
           aFontData.mSize.GetUnit() == eCSSUnit_Pixel;
2374
           aFontData.mSize.GetUnit() == eCSSUnit_Pixel;
2343
  }
2375
  }
2344
  else if (eCSSUnit_Percent == aFontData.mSize.GetUnit()) {
2376
  else if (eCSSUnit_Percent == aFontData.mSize.GetUnit()) {
2345
    aInherited = PR_TRUE;
2377
    aInherited = PR_TRUE;
2346
    // Note that % units use the parent's size unadjusted for scriptlevel
2378
    // Note that % units use the parent's size unadjusted for scriptlevel
2347
    // changes. A scriptlevel change between us and the parent is simply
2379
    // changes. A scriptlevel change between us and the parent is simply
2348
    // ignored.
2380
    // ignored.
 Lines 2402-2418    Link Here 
2402
}
2434
}
2403
2435
2404
/* static */ void
2436
/* static */ void
2405
nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
2437
nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
2406
                    nscoord aMinFontSize,
2438
                    nscoord aMinFontSize,
2407
                    PRUint8 aGenericFontID, const nsRuleDataFont& aFontData,
2439
                    PRUint8 aGenericFontID, const nsRuleDataFont& aFontData,
2408
                    const nsStyleFont* aParentFont,
2440
                    const nsStyleFont* aParentFont,
2409
                    nsStyleFont* aFont, PRBool aUsedStartStruct,
2441
                    nsStyleFont* aFont, PRBool aUsedStartStruct,
2410
                    PRBool& aInherited)
2442
                    PRBool atRoot, PRBool& aInherited)
2411
{
2443
{
2412
  const nsFont* defaultVariableFont =
2444
  const nsFont* defaultVariableFont =
2413
    aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID);
2445
    aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID);
2414
2446
2415
  // -moz-system-font: enum (never inherit!)
2447
  // -moz-system-font: enum (never inherit!)
2416
  nsFont systemFont;
2448
  nsFont systemFont;
2417
  if (eCSSUnit_Enumerated == aFontData.mSystemFont.GetUnit()) {
2449
  if (eCSSUnit_Enumerated == aFontData.mSystemFont.GetUnit()) {
2418
    nsSystemFontID sysID;
2450
    nsSystemFontID sysID;
 Lines 2575-2591    Link Here 
2575
2607
2576
  // -moz-script-min-size: length
2608
  // -moz-script-min-size: length
2577
  if (aFontData.mScriptMinSize.IsLengthUnit()) {
2609
  if (aFontData.mScriptMinSize.IsLengthUnit()) {
2578
    // scriptminsize in font units (em, ex) has to be interpreted relative
2610
    // scriptminsize in font units (em, ex) has to be interpreted relative
2579
    // to the parent font, or the size definitions are circular and we
2611
    // to the parent font, or the size definitions are circular and we
2580
    // 
2612
    // 
2581
    aFont->mScriptMinSize =
2613
    aFont->mScriptMinSize =
2582
      CalcLengthWith(aFontData.mScriptMinSize, aParentFont->mSize, aParentFont, nsnull,
2614
      CalcLengthWith(aFontData.mScriptMinSize, aParentFont->mSize, aParentFont, nsnull,
2583
                     aPresContext, aInherited);
2615
                     aPresContext, atRoot, aInherited);
2584
  }
2616
  }
2585
2617
2586
  // -moz-script-size-multiplier: factor, inherit, initial
2618
  // -moz-script-size-multiplier: factor, inherit, initial
2587
  SetFactor(aFontData.mScriptSizeMultiplier, aFont->mScriptSizeMultiplier,
2619
  SetFactor(aFontData.mScriptSizeMultiplier, aFont->mScriptSizeMultiplier,
2588
            aInherited, aParentFont->mScriptSizeMultiplier,
2620
            aInherited, aParentFont->mScriptSizeMultiplier,
2589
            NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER,
2621
            NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER,
2590
            SETFCT_POSITIVE);
2622
            SETFCT_POSITIVE);
2591
  
2623
  
 Lines 2614-2645    Link Here 
2614
  scriptLevelAdjustedParentSize =
2646
  scriptLevelAdjustedParentSize =
2615
    ComputeScriptLevelSize(aFont, aParentFont, aPresContext,
2647
    ComputeScriptLevelSize(aFont, aParentFont, aPresContext,
2616
                           &scriptLevelAdjustedUnconstrainedParentSize);
2648
                           &scriptLevelAdjustedUnconstrainedParentSize);
2617
  NS_ASSERTION(!aUsedStartStruct || aFont->mScriptUnconstrainedSize == aFont->mSize,
2649
  NS_ASSERTION(!aUsedStartStruct || aFont->mScriptUnconstrainedSize == aFont->mSize,
2618
               "If we have a start struct, we should have reset everything coming in here");
2650
               "If we have a start struct, we should have reset everything coming in here");
2619
#endif
2651
#endif
2620
  SetFontSize(aPresContext, aFontData, aFont, aParentFont, &aFont->mSize,
2652
  SetFontSize(aPresContext, aFontData, aFont, aParentFont, &aFont->mSize,
2621
              systemFont, aParentFont->mSize, scriptLevelAdjustedParentSize,
2653
              systemFont, aParentFont->mSize, scriptLevelAdjustedParentSize,
2622
              aUsedStartStruct, aInherited);
2654
              aUsedStartStruct, atRoot, aInherited);
2623
#ifdef MOZ_MATHML
2655
#ifdef MOZ_MATHML
2624
  if (aParentFont->mSize == aParentFont->mScriptUnconstrainedSize &&
2656
  if (aParentFont->mSize == aParentFont->mScriptUnconstrainedSize &&
2625
      scriptLevelAdjustedParentSize == scriptLevelAdjustedUnconstrainedParentSize) {
2657
      scriptLevelAdjustedParentSize == scriptLevelAdjustedUnconstrainedParentSize) {
2626
    // Fast path: we have not been affected by scriptminsize so we don't
2658
    // Fast path: we have not been affected by scriptminsize so we don't
2627
    // need to call SetFontSize again to compute the
2659
    // need to call SetFontSize again to compute the
2628
    // scriptminsize-unconstrained size. This is OK even if we have a
2660
    // scriptminsize-unconstrained size. This is OK even if we have a
2629
    // start struct, because if we have a start struct then 'font-size'
2661
    // start struct, because if we have a start struct then 'font-size'
2630
    // was specified and so scriptminsize has no effect.
2662
    // was specified and so scriptminsize has no effect.
2631
    aFont->mScriptUnconstrainedSize = aFont->mSize;
2663
    aFont->mScriptUnconstrainedSize = aFont->mSize;
2632
  } else {
2664
  } else {
2633
    SetFontSize(aPresContext, aFontData, aFont, aParentFont,
2665
    SetFontSize(aPresContext, aFontData, aFont, aParentFont,
2634
                &aFont->mScriptUnconstrainedSize, systemFont,
2666
                &aFont->mScriptUnconstrainedSize, systemFont,
2635
                aParentFont->mScriptUnconstrainedSize,
2667
                aParentFont->mScriptUnconstrainedSize,
2636
                scriptLevelAdjustedUnconstrainedParentSize,
2668
                scriptLevelAdjustedUnconstrainedParentSize,
2637
                aUsedStartStruct, aInherited);
2669
                aUsedStartStruct, atRoot, aInherited);
2638
  }
2670
  }
2639
  NS_ASSERTION(aFont->mScriptUnconstrainedSize <= aFont->mSize,
2671
  NS_ASSERTION(aFont->mScriptUnconstrainedSize <= aFont->mSize,
2640
               "scriptminsize should never be making things bigger");
2672
               "scriptminsize should never be making things bigger");
2641
#endif
2673
#endif
2642
2674
2643
  // enforce the user' specified minimum font-size on the value that we expose
2675
  // enforce the user' specified minimum font-size on the value that we expose
2644
  // (but don't change font-size:0)
2676
  // (but don't change font-size:0)
2645
  if (0 < aFont->mSize && aFont->mSize < aMinFontSize)
2677
  if (0 < aFont->mSize && aFont->mSize < aMinFontSize)
 Lines 2660-2675    Link Here 
2660
//    up to the root where default values come from the presentation context)
2692
//    up to the root where default values come from the presentation context)
2661
//  - re-apply cascading rules from there without caching intermediate values
2693
//  - re-apply cascading rules from there without caching intermediate values
2662
/* static */ void
2694
/* static */ void
2663
nsRuleNode::SetGenericFont(nsPresContext* aPresContext,
2695
nsRuleNode::SetGenericFont(nsPresContext* aPresContext,
2664
                           nsStyleContext* aContext,
2696
                           nsStyleContext* aContext,
2665
                           PRUint8 aGenericFontID, nscoord aMinFontSize,
2697
                           PRUint8 aGenericFontID, nscoord aMinFontSize,
2666
                           nsStyleFont* aFont)
2698
                           nsStyleFont* aFont)
2667
{
2699
{
2700
  PRBool atRoot;
2701
2668
  // walk up the contexts until a context with the desired generic font
2702
  // walk up the contexts until a context with the desired generic font
2669
  nsAutoVoidArray contextPath;
2703
  nsAutoVoidArray contextPath;
2670
  contextPath.AppendElement(aContext);
2704
  contextPath.AppendElement(aContext);
2671
  nsStyleContext* higherContext = aContext->GetParent();
2705
  nsStyleContext* higherContext = aContext->GetParent();
2672
  while (higherContext) {
2706
  while (higherContext) {
2673
    if (higherContext->GetStyleFont()->mGenericID == aGenericFontID) {
2707
    if (higherContext->GetStyleFont()->mGenericID == aGenericFontID) {
2674
      // done walking up the higher contexts
2708
      // done walking up the higher contexts
2675
      break;
2709
      break;
 Lines 2680-2698    Link Here 
2680
2714
2681
  // re-apply the cascading rules, starting from the higher context
2715
  // re-apply the cascading rules, starting from the higher context
2682
2716
2683
  // If we stopped earlier because we reached the root of the style tree,
2717
  // If we stopped earlier because we reached the root of the style tree,
2684
  // we will start with the default generic font from the presentation
2718
  // we will start with the default generic font from the presentation
2685
  // context. Otherwise we start with the higher context.
2719
  // context. Otherwise we start with the higher context.
2686
  const nsFont* defaultFont = aPresContext->GetDefaultFont(aGenericFontID);
2720
  const nsFont* defaultFont = aPresContext->GetDefaultFont(aGenericFontID);
2687
  nsStyleFont parentFont(*defaultFont, aPresContext);
2721
  nsStyleFont parentFont(*defaultFont, aPresContext);
2722
  atRoot = PR_TRUE;
2688
  if (higherContext) {
2723
  if (higherContext) {
2689
    const nsStyleFont* tmpFont = higherContext->GetStyleFont();
2724
    const nsStyleFont* tmpFont = higherContext->GetStyleFont();
2690
    parentFont = *tmpFont;
2725
    parentFont = *tmpFont;
2726
    atRoot = PR_FALSE;
2691
  }
2727
  }
2692
  *aFont = parentFont;
2728
  *aFont = parentFont;
2693
2729
2694
  PRBool dummy;
2730
  PRBool dummy;
2695
  PRUint32 fontBit = nsCachedStyleData::GetBitForSID(eStyleStruct_Font);
2731
  PRUint32 fontBit = nsCachedStyleData::GetBitForSID(eStyleStruct_Font);
2696
  
2732
  
2697
  for (PRInt32 i = contextPath.Count() - 1; i >= 0; --i) {
2733
  for (PRInt32 i = contextPath.Count() - 1; i >= 0; --i) {
2698
    nsStyleContext* context = (nsStyleContext*)contextPath[i];
2734
    nsStyleContext* context = (nsStyleContext*)contextPath[i];
 Lines 2722-2738    Link Here 
2722
2758
2723
    // Avoid unnecessary operations in SetFont().  But we care if it's
2759
    // Avoid unnecessary operations in SetFont().  But we care if it's
2724
    // the final value that we're computing.
2760
    // the final value that we're computing.
2725
    if (i != 0)
2761
    if (i != 0)
2726
      fontData.mFamily.Reset();
2762
      fontData.mFamily.Reset();
2727
2763
2728
    nsRuleNode::SetFont(aPresContext, context, aMinFontSize,
2764
    nsRuleNode::SetFont(aPresContext, context, aMinFontSize,
2729
                        aGenericFontID, fontData, &parentFont, aFont,
2765
                        aGenericFontID, fontData, &parentFont, aFont,
2730
                        PR_FALSE, dummy);
2766
                        PR_FALSE, atRoot, dummy);
2731
2767
2732
    // XXX Not sure if we need to do this here
2768
    // XXX Not sure if we need to do this here
2733
    // If we have a post-resolve callback, handle that now.
2769
    // If we have a post-resolve callback, handle that now.
2734
    if (ruleData.mPostResolveCallback)
2770
    if (ruleData.mPostResolveCallback)
2735
      (ruleData.mPostResolveCallback)(aFont, &ruleData);
2771
      (ruleData.mPostResolveCallback)(aFont, &ruleData);
2736
2772
2737
    parentFont = *aFont;
2773
    parentFont = *aFont;
2738
  }
2774
  }
 Lines 2754-2769    Link Here 
2754
nsRuleNode::ComputeFontData(void* aStartStruct,
2790
nsRuleNode::ComputeFontData(void* aStartStruct,
2755
                            const nsRuleDataStruct& aData, 
2791
                            const nsRuleDataStruct& aData, 
2756
                            nsStyleContext* aContext, 
2792
                            nsStyleContext* aContext, 
2757
                            nsRuleNode* aHighestNode,
2793
                            nsRuleNode* aHighestNode,
2758
                            const RuleDetail aRuleDetail, PRBool aInherited)
2794
                            const RuleDetail aRuleDetail, PRBool aInherited)
2759
{
2795
{
2760
  COMPUTE_START_INHERITED(Font, (mPresContext), font, parentFont,
2796
  COMPUTE_START_INHERITED(Font, (mPresContext), font, parentFont,
2761
                          Font, fontData)
2797
                          Font, fontData)
2798
2799
  PRBool atRoot = (parentFont == font);
2762
2800
2763
  // NOTE:  The |aRuleDetail| passed in is a little bit conservative due
2801
  // NOTE:  The |aRuleDetail| passed in is a little bit conservative due
2764
  // to the -moz-system-font property.  We really don't need to consider
2802
  // to the -moz-system-font property.  We really don't need to consider
2765
  // it here in determining whether to cache in the rule tree.  However,
2803
  // it here in determining whether to cache in the rule tree.  However,
2766
  // we do need to consider it in WalkRuleTree when deciding whether to
2804
  // we do need to consider it in WalkRuleTree when deciding whether to
2767
  // walk further up the tree.  So this means that when the font struct
2805
  // walk further up the tree.  So this means that when the font struct
2768
  // is fully specified using *longhand* properties (excluding
2806
  // is fully specified using *longhand* properties (excluding
2769
  // -moz-system-font), we won't cache in the rule tree even though we
2807
  // -moz-system-font), we won't cache in the rule tree even though we
 Lines 2826-2842    Link Here 
2826
    }
2864
    }
2827
  }
2865
  }
2828
2866
2829
  // Now compute our font struct
2867
  // Now compute our font struct
2830
  if (generic == kGenericFont_NONE) {
2868
  if (generic == kGenericFont_NONE) {
2831
    // continue the normal processing
2869
    // continue the normal processing
2832
    nsRuleNode::SetFont(mPresContext, aContext, minimumFontSize, generic,
2870
    nsRuleNode::SetFont(mPresContext, aContext, minimumFontSize, generic,
2833
                        fontData, parentFont, font,
2871
                        fontData, parentFont, font,
2834
                        aStartStruct != nsnull, inherited);
2872
                        aStartStruct != nsnull, atRoot, inherited);
2835
  }
2873
  }
2836
  else {
2874
  else {
2837
    // re-calculate the font as a generic font
2875
    // re-calculate the font as a generic font
2838
    inherited = PR_TRUE;
2876
    inherited = PR_TRUE;
2839
    nsRuleNode::SetGenericFont(mPresContext, aContext, generic,
2877
    nsRuleNode::SetGenericFont(mPresContext, aContext, generic,
2840
                               minimumFontSize, font);
2878
                               minimumFontSize, font);
2841
  }
2879
  }
2842
2880
(-)a/layout/style/nsRuleNode.h (-1 / +3 lines)
Line     Link Here 
 Lines 617-642    Link Here 
617
                                      const nsRuleDataFont& aFontData,
617
                                      const nsRuleDataFont& aFontData,
618
                                      const nsStyleFont* aFont,
618
                                      const nsStyleFont* aFont,
619
                                      const nsStyleFont* aParentFont,
619
                                      const nsStyleFont* aParentFont,
620
                                      nscoord* aSize,
620
                                      nscoord* aSize,
621
                                      const nsFont& aSystemFont,
621
                                      const nsFont& aSystemFont,
622
                                      nscoord aParentSize,
622
                                      nscoord aParentSize,
623
                                      nscoord aScriptLevelAdjustedParentSize,
623
                                      nscoord aScriptLevelAdjustedParentSize,
624
                                      PRBool aUsedStartStruct,
624
                                      PRBool aUsedStartStruct,
625
                                      PRBool atRoot,
625
                                      PRBool& aInherited);
626
                                      PRBool& aInherited);
626
627
627
  static NS_HIDDEN_(void) SetFont(nsPresContext* aPresContext,
628
  static NS_HIDDEN_(void) SetFont(nsPresContext* aPresContext,
628
                                  nsStyleContext* aContext,
629
                                  nsStyleContext* aContext,
629
                                  nscoord aMinFontSize,
630
                                  nscoord aMinFontSize,
630
                                  PRUint8 aGenericFontID,
631
                                  PRUint8 aGenericFontID,
631
                                  const nsRuleDataFont& aFontData,
632
                                  const nsRuleDataFont& aFontData,
632
                                  const nsStyleFont* aParentFont,
633
                                  const nsStyleFont* aParentFont,
633
                                  nsStyleFont* aFont,
634
                                  nsStyleFont* aFont,
634
                                  PRBool aStartStruct, PRBool& aInherited);
635
                                  PRBool aStartStruct,
636
                                  PRBool atRoot, PRBool& aInherited);
635
637
636
  static NS_HIDDEN_(void) SetGenericFont(nsPresContext* aPresContext,
638
  static NS_HIDDEN_(void) SetGenericFont(nsPresContext* aPresContext,
637
                                         nsStyleContext* aContext,
639
                                         nsStyleContext* aContext,
638
                                         PRUint8 aGenericFontID,
640
                                         PRUint8 aGenericFontID,
639
                                         nscoord aMinFontSize,
641
                                         nscoord aMinFontSize,
640
                                         nsStyleFont* aFont);
642
                                         nsStyleFont* aFont);
641
643
642
  NS_HIDDEN_(void) AdjustLogicalBoxProp(nsStyleContext* aContext,
644
  NS_HIDDEN_(void) AdjustLogicalBoxProp(nsStyleContext* aContext,

Return to bug 472195