@@ -129,64 +129,26 @@ void nsMathMLmrootFrame::GetRadicalXOffsets(nscoord aIndexWidth,
129
129
if (aSqrOffset) *aSqrOffset = dxSqr;
130
130
}
131
131
132
- void nsMathMLmrootFrame::Reflow (nsPresContext* aPresContext,
133
- ReflowOutput& aDesiredSize,
134
- const ReflowInput& aReflowInput,
135
- nsReflowStatus& aStatus) {
132
+ nsresult nsMathMLmrootFrame::Place (DrawTarget* aDrawTarget,
133
+ const PlaceFlags& aFlags,
134
+ ReflowOutput& aDesiredSize) {
136
135
if (ShouldUseRowFallback ()) {
137
- ReportChildCountError ();
138
- nsMathMLContainerFrame::Reflow (aPresContext, aDesiredSize, aReflowInput,
139
- aStatus);
140
- return ;
136
+ // report an error, encourage people to get their markups in order
137
+ if (!aFlags.contains (PlaceFlag::MeasureOnly)) {
138
+ ReportChildCountError ();
139
+ }
140
+ return PlaceAsMrow (aDrawTarget, aFlags, aDesiredSize);
141
141
}
142
142
143
- MarkInReflow ();
144
- MOZ_ASSERT (aStatus.IsEmpty (), " Caller should pass a fresh reflow status!" );
145
-
146
- nsReflowStatus childStatus;
147
- aDesiredSize.ClearSize ();
148
- aDesiredSize.SetBlockStartAscent (0 );
149
-
150
143
nsBoundingMetrics bmSqr, bmBase, bmIndex;
151
- nsMargin baseMargin, indexMargin;
152
- DrawTarget* drawTarget = aReflowInput.mRenderingContext ->GetDrawTarget ();
153
-
154
- // ////////////////
155
- // Reflow Children
156
-
157
- int32_t count = 0 ;
158
- nsIFrame* baseFrame = nullptr ;
159
- nsIFrame* indexFrame = nullptr ;
160
- ReflowOutput baseSize (aReflowInput);
161
- ReflowOutput indexSize (aReflowInput);
162
- nsIFrame* childFrame = mFrames .FirstChild ();
163
- while (childFrame) {
164
- // ask our children to compute their bounding metrics
165
- ReflowOutput childDesiredSize (aReflowInput);
166
- WritingMode wm = childFrame->GetWritingMode ();
167
- LogicalSize availSize = aReflowInput.ComputedSize (wm);
168
- availSize.BSize (wm) = NS_UNCONSTRAINEDSIZE;
169
- ReflowInput childReflowInput (aPresContext, aReflowInput, childFrame,
170
- availSize);
171
- ReflowChild (childFrame, aPresContext, childDesiredSize, childReflowInput,
172
- childStatus);
173
- // NS_ASSERTION(childStatus.IsComplete(), "bad status");
174
- if (0 == count) {
175
- // base
176
- baseFrame = childFrame;
177
- baseSize = childDesiredSize;
178
- bmBase = childDesiredSize.mBoundingMetrics ;
179
- baseMargin = baseFrame->GetUsedMargin ();
180
- } else if (1 == count) {
181
- // index
182
- indexFrame = childFrame;
183
- indexSize = childDesiredSize;
184
- bmIndex = childDesiredSize.mBoundingMetrics ;
185
- indexMargin = indexFrame->GetUsedMargin ();
186
- }
187
- count++;
188
- childFrame = childFrame->GetNextSibling ();
189
- }
144
+ nsIFrame* baseFrame = mFrames .FirstChild ();
145
+ nsIFrame* indexFrame = baseFrame->GetNextSibling ();
146
+ nsMargin baseMargin = GetMarginForPlace (aFlags, baseFrame),
147
+ indexMargin = GetMarginForPlace (aFlags, indexFrame);
148
+ ReflowOutput baseSize (aDesiredSize.GetWritingMode ());
149
+ ReflowOutput indexSize (aDesiredSize.GetWritingMode ());
150
+ GetReflowAndBoundingMetricsFor (baseFrame, baseSize, bmBase);
151
+ GetReflowAndBoundingMetricsFor (indexFrame, indexSize, bmIndex);
190
152
191
153
// //////////
192
154
// Prepare the radical symbol and the overline bar
@@ -203,7 +165,7 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
203
165
// p.131)
204
166
char16_t one = ' 1' ;
205
167
nsBoundingMetrics bmOne =
206
- nsLayoutUtils::AppUnitBoundsOfString (&one, 1 , *fm, drawTarget );
168
+ nsLayoutUtils::AppUnitBoundsOfString (&one, 1 , *fm, aDrawTarget );
207
169
if (bmOne.ascent > bmBase.ascent + baseMargin.top ) {
208
170
psi += bmOne.ascent - bmBase.ascent - baseMargin.top ;
209
171
}
@@ -228,13 +190,22 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
228
190
229
191
// height(radical) should be >= height(base) + psi + ruleThickness
230
192
nsBoundingMetrics radicalSize;
231
- mSqrChar .Stretch (this , drawTarget, fontSizeInflation,
232
- NS_STRETCH_DIRECTION_VERTICAL, contSize, radicalSize,
233
- NS_STRETCH_LARGER,
234
- StyleVisibility ()->mDirection == StyleDirection::Rtl);
235
- // radicalSize have changed at this point, and should match with
236
- // the bounding metrics of the char
237
- mSqrChar .GetBoundingMetrics (bmSqr);
193
+ if (aFlags.contains (PlaceFlag::IntrinsicSize)) {
194
+ nscoord radical_width =
195
+ mSqrChar .GetMaxWidth (this , aDrawTarget, fontSizeInflation);
196
+ bmSqr.leftBearing = 0 ;
197
+ bmSqr.rightBearing = radical_width;
198
+ bmSqr.width = radical_width;
199
+ bmSqr.ascent = bmSqr.descent = 0 ;
200
+ } else {
201
+ mSqrChar .Stretch (this , aDrawTarget, fontSizeInflation,
202
+ NS_STRETCH_DIRECTION_VERTICAL, contSize, radicalSize,
203
+ NS_STRETCH_LARGER,
204
+ StyleVisibility ()->mDirection == StyleDirection::Rtl);
205
+ // radicalSize have changed at this point, and should match with
206
+ // the bounding metrics of the char
207
+ mSqrChar .GetBoundingMetrics (bmSqr);
208
+ }
238
209
239
210
// Update the desired size for the container (like msqrt, index is not yet
240
211
// included) the baseline will be that of the base.
@@ -305,92 +276,46 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
305
276
aDesiredSize.mBoundingMetrics = mBoundingMetrics ;
306
277
307
278
// Add padding+border around the final layout.
308
- auto borderPadding = GetUsedBorderAndPadding ( );
279
+ auto borderPadding = GetBorderPaddingForPlace (aFlags );
309
280
InflateReflowAndBoundingMetrics (borderPadding, aDesiredSize,
310
281
mBoundingMetrics );
311
282
312
- GatherAndStoreOverflow (&aDesiredSize);
313
-
314
- // place the index
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);
320
- nscoord dy =
321
- aDesiredSize.BlockStartAscent () -
322
- (indexRaisedAscent + indexSize.BlockStartAscent () - bmIndex.ascent );
323
- FinishReflowChild (indexFrame, aPresContext, indexSize, nullptr ,
324
- MirrorIfRTL (aDesiredSize.Width (), indexSize.Width (), dx),
325
- dy + indexMargin.top , ReflowChildFlags::Default);
326
-
327
- // place the radical symbol and the radical bar
328
- dx = borderPaddingInlineStart + dxSqr;
329
- dy = borderPadding.top + indexClearance +
330
- leading; // leave a leading at the top
331
- mSqrChar .SetRect (nsRect (MirrorIfRTL (aDesiredSize.Width (), bmSqr.width , dx),
332
- dy, bmSqr.width , bmSqr.ascent + bmSqr.descent ));
333
- dx += bmSqr.width ;
334
- mBarRect .SetRect (MirrorIfRTL (aDesiredSize.Width (),
335
- bmBase.width + baseMargin.LeftRight (), dx),
336
- dy, bmBase.width + baseMargin.LeftRight (), ruleThickness);
337
-
338
- // place the base
339
- dx += isRTL ? baseMargin.right : baseMargin.left ;
340
- dy = aDesiredSize.BlockStartAscent () - baseSize.BlockStartAscent ();
341
- FinishReflowChild (baseFrame, aPresContext, baseSize, nullptr ,
342
- MirrorIfRTL (aDesiredSize.Width (), baseSize.Width (), dx), dy,
343
- ReflowChildFlags::Default);
283
+ if (!aFlags.contains (PlaceFlag::MeasureOnly)) {
284
+ nsPresContext* presContext = PresContext ();
285
+ // place the index
286
+ const bool isRTL = StyleVisibility ()->mDirection == StyleDirection::Rtl;
287
+ nscoord borderPaddingInlineStart =
288
+ isRTL ? borderPadding.right : borderPadding.left ;
289
+ nscoord dx = borderPaddingInlineStart + dxIndex +
290
+ indexMargin.Side (isRTL ? eSideRight : eSideLeft);
291
+ nscoord dy =
292
+ aDesiredSize.BlockStartAscent () -
293
+ (indexRaisedAscent + indexSize.BlockStartAscent () - bmIndex.ascent );
294
+ FinishReflowChild (indexFrame, presContext, indexSize, nullptr ,
295
+ MirrorIfRTL (aDesiredSize.Width (), indexSize.Width (), dx),
296
+ dy + indexMargin.top , ReflowChildFlags::Default);
297
+
298
+ // place the radical symbol and the radical bar
299
+ dx = borderPaddingInlineStart + dxSqr;
300
+ dy = borderPadding.top + indexClearance +
301
+ leading; // leave a leading at the top
302
+ mSqrChar .SetRect (nsRect (MirrorIfRTL (aDesiredSize.Width (), bmSqr.width , dx),
303
+ dy, bmSqr.width , bmSqr.ascent + bmSqr.descent ));
304
+ dx += bmSqr.width ;
305
+ mBarRect .SetRect (MirrorIfRTL (aDesiredSize.Width (),
306
+ bmBase.width + baseMargin.LeftRight (), dx),
307
+ dy, bmBase.width + baseMargin.LeftRight (), ruleThickness);
308
+
309
+ // place the base
310
+ dx += isRTL ? baseMargin.right : baseMargin.left ;
311
+ dy = aDesiredSize.BlockStartAscent () - baseSize.BlockStartAscent ();
312
+ FinishReflowChild (baseFrame, presContext, baseSize, nullptr ,
313
+ MirrorIfRTL (aDesiredSize.Width (), baseSize.Width (), dx),
314
+ dy, ReflowChildFlags::Default);
315
+ }
344
316
345
317
mReference .x = 0 ;
346
318
mReference .y = aDesiredSize.BlockStartAscent ();
347
- }
348
-
349
- /* virtual */
350
- nsresult nsMathMLmrootFrame::MeasureForWidth (DrawTarget* aDrawTarget,
351
- ReflowOutput& aDesiredSize) {
352
- const PlaceFlags flags (PlaceFlag::IntrinsicSize, PlaceFlag::MeasureOnly);
353
- if (ShouldUseRowFallback ()) {
354
- return PlaceAsMrow (aDrawTarget, flags, aDesiredSize);
355
- }
356
-
357
- // ShouldUseRowFallback() returned false so there are exactly two children.
358
- nsIFrame* baseFrame = mFrames .FirstChild ();
359
- MOZ_ASSERT (baseFrame);
360
- nsIFrame* indexFrame = baseFrame->GetNextSibling ();
361
- MOZ_ASSERT (indexFrame);
362
- MOZ_ASSERT (!indexFrame->GetNextSibling ());
363
-
364
- nsBoundingMetrics bmBase, bmIndex;
365
- ReflowOutput baseSize (aDesiredSize.GetWritingMode ());
366
- ReflowOutput indexSize (aDesiredSize.GetWritingMode ());
367
- float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor (this );
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;
375
- RefPtr<nsFontMetrics> fm =
376
- nsLayoutUtils::GetFontMetricsForFrame (this , fontSizeInflation);
377
- GetRadicalXOffsets (bmIndex.width + indexMargin, sqrWidth, fm, &dxIndex,
378
- &dxSqr);
379
-
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 );
394
319
395
320
return NS_OK;
396
321
}
0 commit comments