Bug 1845707 - Remove preferences for invalid markup. r=emilio

This commit removes the preference
mathml.error_message_layout_for_invalid_markup.disabled that controls
whether we layout invalid markup with the special "invalid-markup"
message. It has been set to true since Firefox 106. For now, this
"invalid-markup" layout is still used for the legacy implementation
of the <maction> element and will be removed in bug 1788223.

Differential Revision: https://phabricator.services.mozilla.com/D184691
This commit is contained in:
Frederic Wang 2023-07-28 05:43:16 +00:00
parent 0209ed8be9
commit f3aa470836
13 changed files with 78 additions and 97 deletions

View File

@ -10,7 +10,6 @@
#include "gfxUtils.h"
#include "mozilla/Likely.h"
#include "mozilla/PresShell.h"
#include "mozilla/StaticPrefs_mathml.h"
#include "mozilla/dom/MutationEventBinding.h"
#include "mozilla/gfx/2D.h"
#include "nsLayoutUtils.h"
@ -36,39 +35,6 @@ NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
// =============================================================================
// error handlers
// provide a feedback to the user when a frame with bad markup can not be
// rendered
nsresult nsMathMLContainerFrame::ReflowError(DrawTarget* aDrawTarget,
ReflowOutput& aDesiredSize) {
// clear all other flags and record that there is an error with this frame
mEmbellishData.flags = 0;
mPresentationData.flags = NS_MATHML_ERROR;
///////////////
// Set font
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
// bounding metrics
nsAutoString errorMsg;
errorMsg.AssignLiteral("invalid-markup");
mBoundingMetrics = nsLayoutUtils::AppUnitBoundsOfString(
errorMsg.get(), errorMsg.Length(), *fm, aDrawTarget);
// reflow metrics
WritingMode wm = aDesiredSize.GetWritingMode();
aDesiredSize.SetBlockStartAscent(fm->MaxAscent());
nscoord descent = fm->MaxDescent();
aDesiredSize.BSize(wm) = aDesiredSize.BlockStartAscent() + descent;
aDesiredSize.ISize(wm) = mBoundingMetrics.width;
// Also return our bounding metrics
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
return NS_OK;
}
namespace mozilla {
class nsDisplayMathMLError : public nsPaintedDisplayItem {
@ -992,7 +958,7 @@ void nsMathMLContainerFrame::GetIntrinsicISizeMetrics(
nsresult rv =
MeasureForWidth(aRenderingContext->GetDrawTarget(), aDesiredSize);
if (NS_FAILED(rv)) {
PlaceForError(aRenderingContext->GetDrawTarget(), false, aDesiredSize);
PlaceAsMrow(aRenderingContext->GetDrawTarget(), false, aDesiredSize);
}
ClearSavedChildMetrics();
@ -1244,13 +1210,10 @@ nsresult nsMathMLContainerFrame::Place(DrawTarget* aDrawTarget,
return NS_OK;
}
nsresult nsMathMLContainerFrame::PlaceForError(DrawTarget* aDrawTarget,
bool aPlaceOrigin,
ReflowOutput& aDesiredSize) {
return StaticPrefs::mathml_error_message_layout_for_invalid_markup_disabled()
? nsMathMLContainerFrame::Place(aDrawTarget, aPlaceOrigin,
aDesiredSize)
: ReflowError(aDrawTarget, aDesiredSize);
nsresult nsMathMLContainerFrame::PlaceAsMrow(DrawTarget* aDrawTarget,
bool aPlaceOrigin,
ReflowOutput& aDesiredSize) {
return nsMathMLContainerFrame::Place(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
void nsMathMLContainerFrame::PositionRowChildFrames(nscoord aOffsetX,

View File

@ -205,16 +205,13 @@ class nsMathMLContainerFrame : public nsContainerFrame, public nsMathMLFrame {
public:
/*
* Helper to render the frame as a default mrow-like container or as a visual
* feedback to the user when an error (typically invalid markup) was
* encountered during reflow. Parameters are the same as Place().
* Helper to render the frame as a default mrow-like container when an error
* (typically invalid markup) was encountered during reflow. Parameters are
* the same as Place().
*/
nsresult PlaceForError(DrawTarget* aDrawTarget, bool aPlaceOrigin,
ReflowOutput& aDesiredSize);
nsresult PlaceAsMrow(DrawTarget* aDrawTarget, bool aPlaceOrigin,
ReflowOutput& aDesiredSize);
// error handlers to provide a visual feedback to the user when an error
// (typically invalid markup) was encountered during reflow.
nsresult ReflowError(DrawTarget* aDrawTarget, ReflowOutput& aDesiredSize);
/*
* Helper to call ReportErrorToConsole for parse errors involving
* attribute/value pairs.

View File

@ -5,7 +5,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMathMLSelectedFrame.h"
#include "mozilla/RefPtr.h"
#include "mozilla/ReflowOutput.h"
#include "mozilla/WritingModes.h"
#include "nsCoord.h"
#include "nsDisplayList.h"
#include "nsFontMetrics.h"
#include "nsLayoutUtils.h"
#include "nsStringFwd.h"
using namespace mozilla;
@ -102,6 +110,36 @@ nsIFrame::SizeComputationResult nsMathMLSelectedFrame::ComputeSize(
return {LogicalSize(aWM), AspectRatioUsage::None};
}
nsresult nsMathMLSelectedFrame::ReflowError(DrawTarget* aDrawTarget,
ReflowOutput& aDesiredSize) {
// clear all other flags and record that there is an error with this frame
mEmbellishData.flags = 0;
mPresentationData.flags = NS_MATHML_ERROR;
///////////////
// Set font
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
// bounding metrics
nsAutoString errorMsg;
errorMsg.AssignLiteral("invalid-markup");
mBoundingMetrics = nsLayoutUtils::AppUnitBoundsOfString(
errorMsg.get(), errorMsg.Length(), *fm, aDrawTarget);
// reflow metrics
WritingMode wm = aDesiredSize.GetWritingMode();
aDesiredSize.SetBlockStartAscent(fm->MaxAscent());
nscoord descent = fm->MaxDescent();
aDesiredSize.BSize(wm) = aDesiredSize.BlockStartAscent() + descent;
aDesiredSize.ISize(wm) = mBoundingMetrics.width;
// Also return our bounding metrics
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
return NS_OK;
}
// Only reflow the selected child ...
void nsMathMLSelectedFrame::Reflow(nsPresContext* aPresContext,
ReflowOutput& aDesiredSize,
@ -138,11 +176,11 @@ nsresult nsMathMLSelectedFrame::Place(DrawTarget* aDrawTarget,
nsIFrame* childFrame = GetSelectedFrame();
if (mInvalidMarkup) {
// Calling PlaceForError when mathml.error_message_layout_for_invalid_markup
// is disabled causes assertion failures because nsMathMLSelectedFrame only
// performs layout of the selected child. However, this code is only reached
// when mathml.legacy_maction_and_semantics_implementations is enabled, so
// it is out the scope of the mrow fallback described in MathML Core and
// Calling PlaceAsMrow causes assertion failures because
// nsMathMLSelectedFrame only performs layout of the selected child.
// However, this code is only reached when
// mathml.legacy_maction_and_semantics_implementations is enabled, so it is
// out the scope of the mrow fallback described in MathML Core and
// nsMathMLSelectedFrame will go away in the future. So for now let's
// continue to always layout this case as an 'invalid-markup' message.
return ReflowError(aDrawTarget, aDesiredSize);

View File

@ -47,6 +47,10 @@ class nsMathMLSelectedFrame : public nsMathMLContainerFrame {
mInvalidMarkup(false) {}
virtual ~nsMathMLSelectedFrame();
// error handlers to provide a visual feedback to the user when an error
// (typically invalid markup) was encountered during reflow.
nsresult ReflowError(DrawTarget* aDrawTarget, ReflowOutput& aDesiredSize);
virtual nsIFrame* GetSelectedFrame() = 0;
nsIFrame* mSelectedFrame;

View File

@ -159,7 +159,7 @@ nsresult nsMathMLmfracFrame::PlaceInternal(DrawTarget* aDrawTarget,
if (aPlaceOrigin) {
ReportChildCountError();
}
return PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
return PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum);
GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen);

View File

@ -139,7 +139,7 @@ nsresult nsMathMLmmultiscriptsFrame::PlaceMultiScript(
aFrame->ReportErrorToConsole("NoBase");
else
aFrame->ReportChildCountError();
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
// get x-height (an ex)
@ -293,7 +293,7 @@ nsresult nsMathMLmmultiscriptsFrame::PlaceMultiScript(
if (aPlaceOrigin) {
aFrame->ReportInvalidChildError(nsGkAtoms::mprescripts_);
}
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
if (prescriptsFrame) {
// duplicate <mprescripts/> found
@ -301,13 +301,13 @@ nsresult nsMathMLmmultiscriptsFrame::PlaceMultiScript(
if (aPlaceOrigin) {
aFrame->ReportErrorToConsole("DuplicateMprescripts");
}
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
if (!isSubScript) {
if (aPlaceOrigin) {
aFrame->ReportErrorToConsole("SubSupMismatch");
}
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
prescriptsFrame = childFrame;
@ -492,7 +492,7 @@ nsresult nsMathMLmmultiscriptsFrame::PlaceMultiScript(
aFrame->ReportErrorToConsole("SubSupMismatch");
}
}
return aFrame->PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
return aFrame->PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
// we left out the width of prescripts, so ...

View File

@ -7,7 +7,6 @@
#include "nsMathMLmrootFrame.h"
#include "mozilla/PresShell.h"
#include "mozilla/StaticPrefs_mathml.h"
#include "nsLayoutUtils.h"
#include "nsPresContext.h"
#include <algorithm>
@ -48,9 +47,6 @@ void nsMathMLmrootFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
}
bool nsMathMLmrootFrame::ShouldUseRowFallback() {
if (!StaticPrefs::mathml_error_message_layout_for_invalid_markup_disabled()) {
return false;
}
nsIFrame* baseFrame = mFrames.FirstChild();
if (!baseFrame) {
return true;
@ -209,16 +205,6 @@ void nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
count++;
childFrame = childFrame->GetNextSibling();
}
// FIXME: Bug 1788223: Remove this code when the preference
// mathml.error_message_layout_for_invalid_markup.disabled no longer needed.
if (2 != count) {
// report an error, encourage people to get their markups in order
ReportChildCountError();
ReflowError(drawTarget, aDesiredSize);
// Call DidReflow() for the child frames we successfully did reflow.
DidReflowChildren(mFrames.FirstChild(), childFrame);
return;
}
////////////
// Prepare the radical symbol and the overline bar
@ -364,13 +350,12 @@ void nsMathMLmrootFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext,
return;
}
// ShouldUseRowFallback() returned false so there are exactly two children.
nsIFrame* baseFrame = mFrames.FirstChild();
nsIFrame* indexFrame = nullptr;
if (baseFrame) indexFrame = baseFrame->GetNextSibling();
if (!indexFrame || indexFrame->GetNextSibling()) {
ReflowError(aRenderingContext->GetDrawTarget(), aDesiredSize);
return;
}
MOZ_ASSERT(baseFrame);
nsIFrame* indexFrame = baseFrame->GetNextSibling();
MOZ_ASSERT(indexFrame);
MOZ_ASSERT(!indexFrame->GetNextSibling());
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
nscoord baseWidth = nsLayoutUtils::IntrinsicForContainer(

View File

@ -430,7 +430,7 @@ nsresult nsMathMLmunderoverFrame::Place(DrawTarget* aDrawTarget,
if (aPlaceOrigin) {
ReportChildCountError();
}
return PlaceForError(aDrawTarget, aPlaceOrigin, aDesiredSize);
return PlaceAsMrow(aDrawTarget, aPlaceOrigin, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
if (underFrame) {

View File

@ -35,7 +35,7 @@
<math>
<mstyle style="font-family: 'dtls-1';">
<mover accent="true">
<mo>b</mo>
<mo mathvariant="fraktur">a</mo>
<!-- deliberately invalid -->
</mover>
</mstyle>

View File

@ -35,7 +35,7 @@
<math>
<mstyle style="font-family: 'dtls-1';">
<mover accent="true">
<mo>&#x1d51f;</mo>
<mo mathvariant="fraktur">a</mo>
<!-- deliberately invalid -->
</mover>
</mstyle>

View File

@ -8,15 +8,15 @@
<!-- This element generates an invalid markup error. -->
<!-- We are assuming here that all invalid MathML markups look the same. -->
<p><math><msup><mi>x</mi></msup></math></p>
<p><math><maction actiontype="toggle" selection="0"></maction></math></p>
<p><math><mtext>--1--</mtext></math></p>
<p><math><mtext>--1--</mtext></math></p>
<p><math><msup><mi>x</mi></msup></math></p>
<p><math><maction actiontype="toggle" selection="0"></maction></math></p>
<p><math><msup><mi>x</mi></msup></math></p>
<p><math><maction actiontype="toggle" selection="0"></maction></math></p>
<p><math><mtext>--1--</mtext></math></p>
@ -30,7 +30,7 @@
<p><math><mtext>--1--</mtext></math></p>
<p><math><msup><mi>x</mi></msup></math></p>
<p><math><maction actiontype="toggle" selection="0"></maction></math></p>
</body>
</html>

View File

@ -151,7 +151,7 @@ pref(mathml.legacy_maction_and_semantics_implementations.disabled,false) == mact
== mo-invisibleoperators.html mo-invisibleoperators-ref.html
== mo-invisibleoperators-2.html mo-invisibleoperators-2-ref.html
random-if(gtkWidget) == mo-glyph-size.html mo-glyph-size-ref.html # bug 1309426
pref(mathml.error_message_layout_for_invalid_markup.disabled,false) pref(mathml.legacy_maction_and_semantics_implementations.disabled,false) == maction-dynamic-3.html maction-dynamic-3-ref.html # bug 773482
pref(mathml.legacy_maction_and_semantics_implementations.disabled,false) == maction-dynamic-3.html maction-dynamic-3-ref.html # bug 773482
== whitespace-trim-1.html whitespace-trim-1-ref.html
== whitespace-trim-2.html whitespace-trim-2-ref.html
== whitespace-trim-3.html whitespace-trim-3-ref.html
@ -246,8 +246,8 @@ pref(mathml.legacy_mathvariant_attribute.disabled,false) fails-if(Android&&emula
pref(mathml.legacy_mathvariant_attribute.disabled,false) == mathvariant-4.html mathvariant-4-ref.html
pref(mathml.legacy_mathvariant_attribute.disabled,false) == mathvariant-5.html mathvariant-5-ref.html
== dtls-1.html dtls-1-ref.html
pref(mathml.error_message_layout_for_invalid_markup.disabled,false) == dtls-2.html dtls-2-ref.html
pref(mathml.legacy_mathvariant_attribute.disabled,false) pref(mathml.error_message_layout_for_invalid_markup.disabled,false) == dtls-3.html dtls-3-ref.html
== dtls-2.html dtls-2-ref.html
pref(mathml.legacy_mathvariant_attribute.disabled,false) == dtls-3.html dtls-3-ref.html
== ssty-1.html ssty-1-ref.html
== ssty-2.html ssty-2-ref.html
== mathscript-1.html mathscript-1-ref.html

View File

@ -9389,12 +9389,6 @@
# Prefs starting with "mathml."
#---------------------------------------------------------------------------
# Whether to disable layout of invalid markup as an error message.
- name: mathml.error_message_layout_for_invalid_markup.disabled
type: bool
value: true
mirror: always
# Whether to disable MathML3 implementations for maction and semantics.
- name: mathml.legacy_maction_and_semantics_implementations.disabled
type: bool