@@ -148,6 +148,7 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
148
148
aDesiredSize.SetBlockStartAscent (0 );
149
149
150
150
nsBoundingMetrics bmSqr, bmBase, bmIndex;
151
+ nsMargin baseMargin, indexMargin;
151
152
DrawTarget* drawTarget = aReflowInput.mRenderingContext ->GetDrawTarget ();
152
153
153
154
// ////////////////
@@ -175,11 +176,13 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
175
176
baseFrame = childFrame;
176
177
baseSize = childDesiredSize;
177
178
bmBase = childDesiredSize.mBoundingMetrics ;
179
+ baseMargin = baseFrame->GetUsedMargin ();
178
180
} else if (1 == count) {
179
181
// index
180
182
indexFrame = childFrame;
181
183
indexSize = childDesiredSize;
182
184
bmIndex = childDesiredSize.mBoundingMetrics ;
185
+ indexMargin = indexFrame->GetUsedMargin ();
183
186
}
184
187
count++;
185
188
childFrame = childFrame->GetNextSibling ();
@@ -201,7 +204,9 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
201
204
char16_t one = ' 1' ;
202
205
nsBoundingMetrics bmOne =
203
206
nsLayoutUtils::AppUnitBoundsOfString (&one, 1 , *fm, drawTarget);
204
- if (bmOne.ascent > bmBase.ascent ) psi += bmOne.ascent - bmBase.ascent ;
207
+ if (bmOne.ascent > bmBase.ascent + baseMargin.top ) {
208
+ psi += bmOne.ascent - bmBase.ascent - baseMargin.top ;
209
+ }
205
210
206
211
// make sure that the rule appears on on screen
207
212
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits (1 );
@@ -217,7 +222,8 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
217
222
// Stretch the radical symbol to the appropriate height if it is not big
218
223
// enough.
219
224
nsBoundingMetrics contSize = bmBase;
220
- contSize.descent = bmBase.ascent + bmBase.descent + psi;
225
+ contSize.descent =
226
+ bmBase.ascent + bmBase.descent + baseMargin.TopBottom () + psi;
221
227
contSize.ascent = ruleThickness;
222
228
223
229
// height(radical) should be >= height(base) + psi + ruleThickness
@@ -232,15 +238,18 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
232
238
233
239
// Update the desired size for the container (like msqrt, index is not yet
234
240
// included) the baseline will be that of the base.
235
- mBoundingMetrics .ascent = bmBase.ascent + psi + ruleThickness;
236
- mBoundingMetrics .descent = std::max (
237
- bmBase.descent , (bmSqr.ascent + bmSqr.descent - mBoundingMetrics .ascent ));
238
- mBoundingMetrics .width = bmSqr.width + bmBase.width ;
241
+ mBoundingMetrics .ascent =
242
+ bmBase.ascent + baseMargin.top + psi + ruleThickness;
243
+ mBoundingMetrics .descent =
244
+ std::max (bmBase.descent + baseMargin.bottom ,
245
+ (bmSqr.ascent + bmSqr.descent - mBoundingMetrics .ascent ));
246
+ mBoundingMetrics .width = bmSqr.width + bmBase.width + baseMargin.LeftRight ();
239
247
mBoundingMetrics .leftBearing = bmSqr.leftBearing ;
240
248
mBoundingMetrics .rightBearing =
241
249
bmSqr.width +
242
- std::max (bmBase.width ,
243
- bmBase.rightBearing ); // take also care of the rule
250
+ std::max (
251
+ bmBase.width + baseMargin.LeftRight (),
252
+ bmBase.rightBearing + baseMargin.left ); // take also care of the rule
244
253
245
254
aDesiredSize.SetBlockStartAscent (mBoundingMetrics .ascent + leading);
246
255
aDesiredSize.Height () =
@@ -265,8 +274,8 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
265
274
nscoord indexRaisedAscent =
266
275
mBoundingMetrics .ascent // top of radical
267
276
- (bmSqr.ascent + bmSqr.descent ) // to bottom of radical
268
- + raiseIndexDelta + bmIndex.ascent +
269
- bmIndex. descent ; // to top of raised index
277
+ + raiseIndexDelta + bmIndex.ascent + bmIndex. descent +
278
+ indexMargin. TopBottom () ; // to top of raised index
270
279
271
280
nscoord indexClearance = 0 ;
272
281
if (mBoundingMetrics .ascent < indexRaisedAscent) {
@@ -280,37 +289,54 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
280
289
}
281
290
282
291
nscoord dxIndex, dxSqr;
283
- GetRadicalXOffsets (bmIndex.width , bmSqr.width , fm, &dxIndex, &dxSqr);
292
+ GetRadicalXOffsets (bmIndex.width + indexMargin.LeftRight (), bmSqr.width , fm,
293
+ &dxIndex, &dxSqr);
284
294
285
- mBoundingMetrics .width = dxSqr + bmSqr.width + bmBase.width ;
295
+ mBoundingMetrics .width =
296
+ dxSqr + bmSqr.width + bmBase.width + baseMargin.LeftRight ();
286
297
mBoundingMetrics .leftBearing =
287
298
std::min (dxIndex + bmIndex.leftBearing , dxSqr + bmSqr.leftBearing );
288
299
mBoundingMetrics .rightBearing =
289
- dxSqr + bmSqr.width + std::max (bmBase.width , bmBase.rightBearing );
300
+ dxSqr + bmSqr.width +
301
+ std::max (bmBase.width + baseMargin.LeftRight (),
302
+ bmBase.rightBearing + baseMargin.left );
290
303
291
304
aDesiredSize.Width () = mBoundingMetrics .width ;
292
305
aDesiredSize.mBoundingMetrics = mBoundingMetrics ;
306
+
307
+ // Add padding+border around the final layout.
308
+ auto borderPadding = GetUsedBorderAndPadding ();
309
+ InflateReflowAndBoundingMetrics (borderPadding, aDesiredSize,
310
+ mBoundingMetrics );
311
+
293
312
GatherAndStoreOverflow (&aDesiredSize);
294
313
295
314
// place the index
296
- nscoord dx = dxIndex;
315
+ const bool isRTL = StyleVisibility ()->mDirection == StyleDirection::Rtl;
316
+ nscoord borderPaddingInlineStart =
317
+ isRTL ? borderPadding.right : borderPadding.left ;
318
+ nscoord dx = borderPaddingInlineStart + dxIndex +
319
+ indexMargin.Side (isRTL ? eSideRight : eSideLeft);
297
320
nscoord dy =
298
321
aDesiredSize.BlockStartAscent () -
299
322
(indexRaisedAscent + indexSize.BlockStartAscent () - bmIndex.ascent );
300
323
FinishReflowChild (indexFrame, aPresContext, indexSize, nullptr ,
301
324
MirrorIfRTL (aDesiredSize.Width (), indexSize.Width (), dx),
302
- dy, ReflowChildFlags::Default);
325
+ dy + indexMargin. top , ReflowChildFlags::Default);
303
326
304
327
// place the radical symbol and the radical bar
305
- dx = dxSqr;
306
- dy = indexClearance + leading; // leave a leading at the top
328
+ dx = borderPaddingInlineStart + dxSqr;
329
+ dy = borderPadding.top + indexClearance +
330
+ leading; // leave a leading at the top
307
331
mSqrChar .SetRect (nsRect (MirrorIfRTL (aDesiredSize.Width (), bmSqr.width , dx),
308
332
dy, bmSqr.width , bmSqr.ascent + bmSqr.descent ));
309
333
dx += bmSqr.width ;
310
- mBarRect .SetRect (MirrorIfRTL (aDesiredSize.Width (), bmBase.width , dx), dy,
311
- bmBase.width , ruleThickness);
334
+ mBarRect .SetRect (MirrorIfRTL (aDesiredSize.Width (),
335
+ bmBase.width + baseMargin.LeftRight (), dx),
336
+ dy, bmBase.width + baseMargin.LeftRight (), ruleThickness);
312
337
313
338
// place the base
339
+ dx += isRTL ? baseMargin.right : baseMargin.left ;
314
340
dy = aDesiredSize.BlockStartAscent () - baseSize.BlockStartAscent ();
315
341
FinishReflowChild (baseFrame, aPresContext, baseSize, nullptr ,
316
342
MirrorIfRTL (aDesiredSize.Width (), baseSize.Width (), dx), dy,
@@ -321,12 +347,11 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
321
347
}
322
348
323
349
/* virtual */
324
- void nsMathMLmrootFrame::GetIntrinsicISizeMetrics (gfxContext* aRenderingContext,
325
- ReflowOutput& aDesiredSize) {
350
+ nsresult nsMathMLmrootFrame::MeasureForWidth (DrawTarget* aDrawTarget,
351
+ ReflowOutput& aDesiredSize) {
352
+ const PlaceFlags flags (PlaceFlag::IntrinsicSize, PlaceFlag::MeasureOnly);
326
353
if (ShouldUseRowFallback ()) {
327
- nsMathMLContainerFrame::GetIntrinsicISizeMetrics (aRenderingContext,
328
- aDesiredSize);
329
- return ;
354
+ return PlaceAsMrow (aDrawTarget, flags, aDesiredSize);
330
355
}
331
356
332
357
// ShouldUseRowFallback() returned false so there are exactly two children.
@@ -336,25 +361,38 @@ void nsMathMLmrootFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext,
336
361
MOZ_ASSERT (indexFrame);
337
362
MOZ_ASSERT (!indexFrame->GetNextSibling ());
338
363
364
+ nsBoundingMetrics bmBase, bmIndex;
365
+ ReflowOutput baseSize (aDesiredSize.GetWritingMode ());
366
+ ReflowOutput indexSize (aDesiredSize.GetWritingMode ());
339
367
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor (this );
340
- nscoord baseWidth = nsLayoutUtils::IntrinsicForContainer (
341
- aRenderingContext, baseFrame, IntrinsicISizeType::PrefISize);
342
- nscoord indexWidth = nsLayoutUtils::IntrinsicForContainer (
343
- aRenderingContext, indexFrame, IntrinsicISizeType::PrefISize);
344
- nscoord sqrWidth = mSqrChar .GetMaxWidth (
345
- this , aRenderingContext->GetDrawTarget (), fontSizeInflation);
346
-
347
- nscoord dxSqr;
368
+ GetReflowAndBoundingMetricsFor (baseFrame, baseSize, bmBase);
369
+ GetReflowAndBoundingMetricsFor (indexFrame, indexSize, bmIndex);
370
+ nscoord baseMargin = baseFrame->IntrinsicISizeOffsets ().margin ,
371
+ indexMargin = indexFrame->IntrinsicISizeOffsets ().margin ;
372
+ nscoord sqrWidth = mSqrChar .GetMaxWidth (this , aDrawTarget, fontSizeInflation);
373
+
374
+ nscoord dxIndex, dxSqr;
348
375
RefPtr<nsFontMetrics> fm =
349
376
nsLayoutUtils::GetFontMetricsForFrame (this , fontSizeInflation);
350
- GetRadicalXOffsets (indexWidth, sqrWidth, fm, nullptr , &dxSqr);
377
+ GetRadicalXOffsets (bmIndex.width + indexMargin, sqrWidth, fm, &dxIndex,
378
+ &dxSqr);
351
379
352
- nscoord width = dxSqr + sqrWidth + baseWidth;
380
+ mBoundingMetrics .width = dxSqr + sqrWidth + bmBase.width + baseMargin;
381
+ mBoundingMetrics .leftBearing =
382
+ std::min (dxIndex + bmIndex.leftBearing + indexMargin, dxSqr);
383
+ mBoundingMetrics .rightBearing =
384
+ dxSqr + sqrWidth +
385
+ std::max (bmBase.width + baseMargin, bmBase.rightBearing + baseMargin);
386
+
387
+ aDesiredSize.Width () = mBoundingMetrics .width ;
388
+ aDesiredSize.mBoundingMetrics = mBoundingMetrics ;
389
+
390
+ // Add border+padding.
391
+ nsMargin borderPadding = GetBorderPaddingForPlace (flags);
392
+ InflateReflowAndBoundingMetrics (borderPadding, aDesiredSize,
393
+ mBoundingMetrics );
353
394
354
- aDesiredSize.Width () = width;
355
- aDesiredSize.mBoundingMetrics .width = width;
356
- aDesiredSize.mBoundingMetrics .leftBearing = 0 ;
357
- aDesiredSize.mBoundingMetrics .rightBearing = width;
395
+ return NS_OK;
358
396
}
359
397
360
398
void nsMathMLmrootFrame::DidSetComputedStyle (ComputedStyle* aOldStyle) {
0 commit comments