Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit a7d7959

Browse files
committed
Backed out changeset c6981d9b3b12 (bug 1845707) for causing bustage in nsMathMLSelectedFrame.cpp
1 parent 7d7e663 commit a7d7959

13 files changed

+95
-70
lines changed

layout/mathml/nsMathMLContainerFrame.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,39 @@ NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
3636

3737
// =============================================================================
3838

39+
// error handlers
40+
// provide a feedback to the user when a frame with bad markup can not be
41+
// rendered
42+
nsresult nsMathMLContainerFrame::ReflowError(DrawTarget* aDrawTarget,
43+
ReflowOutput& aDesiredSize) {
44+
// clear all other flags and record that there is an error with this frame
45+
mEmbellishData.flags = 0;
46+
mPresentationData.flags = NS_MATHML_ERROR;
47+
48+
///////////////
49+
// Set font
50+
RefPtr<nsFontMetrics> fm =
51+
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
52+
53+
// bounding metrics
54+
nsAutoString errorMsg;
55+
errorMsg.AssignLiteral("invalid-markup");
56+
mBoundingMetrics = nsLayoutUtils::AppUnitBoundsOfString(
57+
errorMsg.get(), errorMsg.Length(), *fm, aDrawTarget);
58+
59+
// reflow metrics
60+
WritingMode wm = aDesiredSize.GetWritingMode();
61+
aDesiredSize.SetBlockStartAscent(fm->MaxAscent());
62+
nscoord descent = fm->MaxDescent();
63+
aDesiredSize.BSize(wm) = aDesiredSize.BlockStartAscent() + descent;
64+
aDesiredSize.ISize(wm) = mBoundingMetrics.width;
65+
66+
// Also return our bounding metrics
67+
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
68+
69+
return NS_OK;
70+
}
71+
3972
namespace mozilla {
4073

4174
class nsDisplayMathMLError : public nsPaintedDisplayItem {
@@ -959,7 +992,7 @@ void nsMathMLContainerFrame::GetIntrinsicISizeMetrics(
959992
nsresult rv =
960993
MeasureForWidth(aRenderingContext->GetDrawTarget(), aDesiredSize);
961994
if (NS_FAILED(rv)) {
962-
PlaceAsMrow(aRenderingContext->GetDrawTarget(), false, aDesiredSize);
995+
PlaceForError(aRenderingContext->GetDrawTarget(), false, aDesiredSize);
963996
}
964997

965998
ClearSavedChildMetrics();
@@ -1211,10 +1244,13 @@ nsresult nsMathMLContainerFrame::Place(DrawTarget* aDrawTarget,
12111244
return NS_OK;
12121245
}
12131246

1214-
nsresult nsMathMLContainerFrame::PlaceAsMrow(DrawTarget* aDrawTarget,
1215-
bool aPlaceOrigin,
1216-
ReflowOutput& aDesiredSize) {
1217-
return nsMathMLContainerFrame::Place(aDrawTarget, aPlaceOrigin, aDesiredSize);
1247+
nsresult nsMathMLContainerFrame::PlaceForError(DrawTarget* aDrawTarget,
1248+
bool aPlaceOrigin,
1249+
ReflowOutput& aDesiredSize) {
1250+
return StaticPrefs::mathml_error_message_layout_for_invalid_markup_disabled()
1251+
? nsMathMLContainerFrame::Place(aDrawTarget, aPlaceOrigin,
1252+
aDesiredSize)
1253+
: ReflowError(aDrawTarget, aDesiredSize);
12181254
}
12191255

12201256
void nsMathMLContainerFrame::PositionRowChildFrames(nscoord aOffsetX,

layout/mathml/nsMathMLContainerFrame.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,16 @@ class nsMathMLContainerFrame : public nsContainerFrame, public nsMathMLFrame {
205205

206206
public:
207207
/*
208-
* Helper to render the frame as a default mrow-like container when an error
209-
* (typically invalid markup) was encountered during reflow. Parameters are
210-
* the same as Place().
208+
* Helper to render the frame as a default mrow-like container or as a visual
209+
* feedback to the user when an error (typically invalid markup) was
210+
* encountered during reflow. Parameters are the same as Place().
211211
*/
212-
nsresult PlaceAsMrow(DrawTarget* aDrawTarget, bool aPlaceOrigin,
213-
ReflowOutput& aDesiredSize);
212+
nsresult PlaceForError(DrawTarget* aDrawTarget, bool aPlaceOrigin,
213+
ReflowOutput& aDesiredSize);
214214

215+
// error handlers to provide a visual feedback to the user when an error
216+
// (typically invalid markup) was encountered during reflow.
217+
nsresult ReflowError(DrawTarget* aDrawTarget, ReflowOutput& aDesiredSize);
215218
/*
216219
* Helper to call ReportErrorToConsole for parse errors involving
217220
* attribute/value pairs.

layout/mathml/nsMathMLSelectedFrame.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -102,36 +102,6 @@ nsIFrame::SizeComputationResult nsMathMLSelectedFrame::ComputeSize(
102102
return {LogicalSize(aWM), AspectRatioUsage::None};
103103
}
104104

105-
nsresult nsMathMLSelectedFrame::ReflowError(DrawTarget* aDrawTarget,
106-
ReflowOutput& aDesiredSize) {
107-
// clear all other flags and record that there is an error with this frame
108-
mEmbellishData.flags = 0;
109-
mPresentationData.flags = NS_MATHML_ERROR;
110-
111-
///////////////
112-
// Set font
113-
RefPtr<nsFontMetrics> fm =
114-
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
115-
116-
// bounding metrics
117-
nsAutoString errorMsg;
118-
errorMsg.AssignLiteral("invalid-markup");
119-
mBoundingMetrics = nsLayoutUtils::AppUnitBoundsOfString(
120-
errorMsg.get(), errorMsg.Length(), *fm, aDrawTarget);
121-
122-
// reflow metrics
123-
WritingMode wm = aDesiredSize.GetWritingMode();
124-
aDesiredSize.SetBlockStartAscent(fm->MaxAscent());
125-
nscoord descent = fm->MaxDescent();
126-
aDesiredSize.BSize(wm) = aDesiredSize.BlockStartAscent() + descent;
127-
aDesiredSize.ISize(wm) = mBoundingMetrics.width;
128-
129-
// Also return our bounding metrics
130-
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
131-
132-
return NS_OK;
133-
}
134-
135105
// Only reflow the selected child ...
136106
void nsMathMLSelectedFrame::Reflow(nsPresContext* aPresContext,
137107
ReflowOutput& aDesiredSize,
@@ -168,11 +138,11 @@ nsresult nsMathMLSelectedFrame::Place(DrawTarget* aDrawTarget,
168138
nsIFrame* childFrame = GetSelectedFrame();
169139

170140
if (mInvalidMarkup) {
171-
// Calling PlaceAsMrow causes assertion failures because
172-
// nsMathMLSelectedFrame only performs layout of the selected child.
173-
// However, this code is only reached when
174-
// mathml.legacy_maction_and_semantics_implementations is enabled, so it is
175-
// out the scope of the mrow fallback described in MathML Core and
141+
// Calling PlaceForError when mathml.error_message_layout_for_invalid_markup
142+
// is disabled causes assertion failures because nsMathMLSelectedFrame only
143+
// performs layout of the selected child. However, this code is only reached
144+
// when mathml.legacy_maction_and_semantics_implementations is enabled, so
145+
// it is out the scope of the mrow fallback described in MathML Core and
176146
// nsMathMLSelectedFrame will go away in the future. So for now let's
177147
// continue to always layout this case as an 'invalid-markup' message.
178148
return ReflowError(aDrawTarget, aDesiredSize);

layout/mathml/nsMathMLSelectedFrame.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ class nsMathMLSelectedFrame : public nsMathMLContainerFrame {
4747
mInvalidMarkup(false) {}
4848
virtual ~nsMathMLSelectedFrame();
4949

50-
// error handlers to provide a visual feedback to the user when an error
51-
// (typically invalid markup) was encountered during reflow.
52-
nsresult ReflowError(DrawTarget* aDrawTarget, ReflowOutput& aDesiredSize);
53-
5450
virtual nsIFrame* GetSelectedFrame() = 0;
5551
nsIFrame* mSelectedFrame;
5652

layout/mathml/nsMathMLmfracFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ nsresult nsMathMLmfracFrame::PlaceInternal(DrawTarget* aDrawTarget,
159159
if (aPlaceOrigin) {
160160
ReportChildCountError();
161161
}
162-
return PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
162+
return PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
163163
}
164164
GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum);
165165
GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen);

layout/mathml/nsMathMLmmultiscriptsFrame.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ nsresult nsMathMLmmultiscriptsFrame::PlaceMultiScript(
139139
aFrame->ReportErrorToConsole("NoBase");
140140
else
141141
aFrame->ReportChildCountError();
142-
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
142+
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
143143
}
144144

145145
// get x-height (an ex)
@@ -293,21 +293,21 @@ nsresult nsMathMLmmultiscriptsFrame::PlaceMultiScript(
293293
if (aPlaceOrigin) {
294294
aFrame->ReportInvalidChildError(nsGkAtoms::mprescripts_);
295295
}
296-
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
296+
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
297297
}
298298
if (prescriptsFrame) {
299299
// duplicate <mprescripts/> found
300300
// report an error, encourage people to get their markups in order
301301
if (aPlaceOrigin) {
302302
aFrame->ReportErrorToConsole("DuplicateMprescripts");
303303
}
304-
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
304+
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
305305
}
306306
if (!isSubScript) {
307307
if (aPlaceOrigin) {
308308
aFrame->ReportErrorToConsole("SubSupMismatch");
309309
}
310-
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
310+
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
311311
}
312312

313313
prescriptsFrame = childFrame;
@@ -492,7 +492,7 @@ nsresult nsMathMLmmultiscriptsFrame::PlaceMultiScript(
492492
aFrame->ReportErrorToConsole("SubSupMismatch");
493493
}
494494
}
495-
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
495+
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
496496
}
497497

498498
// we left out the width of prescripts, so ...

layout/mathml/nsMathMLmrootFrame.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ void nsMathMLmrootFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
4848
}
4949

5050
bool nsMathMLmrootFrame::ShouldUseRowFallback() {
51+
if (!StaticPrefs::mathml_error_message_layout_for_invalid_markup_disabled()) {
52+
return false;
53+
}
5154
nsIFrame* baseFrame = mFrames.FirstChild();
5255
if (!baseFrame) {
5356
return true;
@@ -206,6 +209,16 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
206209
count++;
207210
childFrame = childFrame->GetNextSibling();
208211
}
212+
// FIXME: Bug 1788223: Remove this code when the preference
213+
// mathml.error_message_layout_for_invalid_markup.disabled no longer needed.
214+
if (2 != count) {
215+
// report an error, encourage people to get their markups in order
216+
ReportChildCountError();
217+
ReflowError(drawTarget, aDesiredSize);
218+
// Call DidReflow() for the child frames we successfully did reflow.
219+
DidReflowChildren(mFrames.FirstChild(), childFrame);
220+
return;
221+
}
209222

210223
////////////
211224
// Prepare the radical symbol and the overline bar
@@ -351,12 +364,13 @@ void nsMathMLmrootFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext,
351364
return;
352365
}
353366

354-
// ShouldUseRowFallback() returned false so there are exactly two children.
355367
nsIFrame* baseFrame = mFrames.FirstChild();
356-
MOZ_ASSERT(baseFrame);
357-
nsIFrame* indexFrame = baseFrame->GetNextSibling();
358-
MOZ_ASSERT(indexFrame);
359-
MOZ_ASSERT(!indexFrame->GetNextSibling());
368+
nsIFrame* indexFrame = nullptr;
369+
if (baseFrame) indexFrame = baseFrame->GetNextSibling();
370+
if (!indexFrame || indexFrame->GetNextSibling()) {
371+
ReflowError(aRenderingContext->GetDrawTarget(), aDesiredSize);
372+
return;
373+
}
360374

361375
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
362376
nscoord baseWidth = nsLayoutUtils::IntrinsicForContainer(

layout/mathml/nsMathMLmunderoverFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ nsresult nsMathMLmunderoverFrame::Place(DrawTarget* aDrawTarget,
430430
if (aPlaceOrigin) {
431431
ReportChildCountError();
432432
}
433-
return PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
433+
return PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
434434
}
435435
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
436436
if (underFrame) {

layout/reftests/mathml/dtls-2-ref.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<math>
3636
<mstyle style="font-family: 'dtls-1';">
3737
<mover accent="true">
38-
<mo mathvariant="fraktur">a</mo>
38+
<mo>b</mo>
3939
<!-- deliberately invalid -->
4040
</mover>
4141
</mstyle>

layout/reftests/mathml/dtls-3-ref.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<math>
3636
<mstyle style="font-family: 'dtls-1';">
3737
<mover accent="true">
38-
<mo mathvariant="fraktur">a</mo>
38+
<mo>&#x1d51f;</mo>
3939
<!-- deliberately invalid -->
4040
</mover>
4141
</mstyle>

0 commit comments

Comments
 (0)