|
|
|
|
| 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()); |
|
|
| 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 |
{ |
|
|
| 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 |
|
|
| 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(); |
|
|
| 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. |
|
|
| 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; |
|
|
| 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 |
|
|
|
| 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) |
|
|
| 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; |
|
|
| 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]; |
|
|
| 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 |
} |
|
|
| 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 |
|
|
| 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 |
|