2017-10-27 17:33:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-09-21 02:12:01 +00:00
|
|
|
|
|
|
|
#ifndef nsMathMLmfracFrame_h___
|
|
|
|
#define nsMathMLmfracFrame_h___
|
|
|
|
|
2012-09-14 16:10:08 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
1999-09-21 02:12:01 +00:00
|
|
|
#include "nsMathMLContainerFrame.h"
|
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
namespace mozilla {
|
|
|
|
class PresShell;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
//
|
|
|
|
// <mfrac> -- form a fraction from two subexpressions
|
|
|
|
//
|
|
|
|
|
|
|
|
/*
|
|
|
|
The MathML REC describes:
|
|
|
|
|
|
|
|
The <mfrac> element is used for fractions. It can also be used to mark up
|
|
|
|
fraction-like objects such as binomial coefficients and Legendre symbols.
|
|
|
|
The syntax for <mfrac> is:
|
|
|
|
<mfrac> numerator denominator </mfrac>
|
|
|
|
|
|
|
|
Attributes of <mfrac>:
|
|
|
|
Name values default
|
|
|
|
linethickness number [ v-unit ] | thin | medium | thick 1
|
|
|
|
|
|
|
|
E.g.,
|
|
|
|
linethickness=2 actually means that linethickness=2*DEFAULT_THICKNESS
|
|
|
|
(DEFAULT_THICKNESS is not specified by MathML, see below.)
|
|
|
|
|
|
|
|
The linethickness attribute indicates the thickness of the horizontal
|
|
|
|
"fraction bar", or "rule", typically used to render fractions. A fraction
|
|
|
|
with linethickness="0" renders without the bar, and might be used within
|
|
|
|
binomial coefficients. A linethickness greater than one might be used with
|
2000-01-26 06:49:38 +00:00
|
|
|
nested fractions.
|
1999-09-21 02:12:01 +00:00
|
|
|
|
|
|
|
In general, the value of linethickness can be a number, as a multiplier
|
|
|
|
of the default thickness of the fraction bar (the default thickness is
|
|
|
|
not specified by MathML), or a number with a unit of vertical length (see
|
|
|
|
Section 2.3.3), or one of the keywords medium (same as 1), thin (thinner
|
|
|
|
than 1, otherwise up to the renderer), or thick (thicker than 1, otherwise
|
|
|
|
up to the renderer).
|
|
|
|
|
|
|
|
The <mfrac> element sets displaystyle to "false", or if it was already
|
|
|
|
false increments scriptlevel by 1, within numerator and denominator.
|
|
|
|
These attributes are inherited by every element from its rendering
|
|
|
|
environment, but can be set explicitly only on the <mstyle>
|
2000-01-26 06:49:38 +00:00
|
|
|
element.
|
1999-09-21 02:12:01 +00:00
|
|
|
*/
|
|
|
|
|
2018-09-06 01:23:14 +00:00
|
|
|
class nsMathMLmfracFrame final : public nsMathMLContainerFrame {
|
1999-09-21 02:12:01 +00:00
|
|
|
public:
|
2017-05-26 10:11:11 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsMathMLmfracFrame)
|
2009-09-12 16:49:24 +00:00
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
friend nsIFrame* NS_NewMathMLmfracFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 18:20:41 +00:00
|
|
|
ComputedStyle* aStyle);
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2024-10-18 12:08:48 +00:00
|
|
|
eMathMLFrameType GetMathMLFrameType() override;
|
2005-09-06 23:47:01 +00:00
|
|
|
|
2024-08-07 06:00:43 +00:00
|
|
|
nsresult Place(DrawTarget* aDrawTarget, const PlaceFlags& aFlags,
|
|
|
|
ReflowOutput& aDesiredSize) override;
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2024-10-18 12:08:48 +00:00
|
|
|
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) override;
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2024-10-18 12:08:48 +00:00
|
|
|
nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
|
|
|
|
int32_t aModType) override;
|
2016-03-31 01:59:00 +00:00
|
|
|
|
2002-02-01 15:10:50 +00:00
|
|
|
NS_IMETHOD
|
2015-03-21 16:28:04 +00:00
|
|
|
TransmitAutomaticData() override;
|
2002-02-01 15:10:50 +00:00
|
|
|
|
2005-09-16 00:39:27 +00:00
|
|
|
// override the base method so that we can deal with the fraction line
|
2024-10-18 12:08:48 +00:00
|
|
|
nscoord FixInterFrameSpacing(ReflowOutput& aDesiredSize) override;
|
2005-09-16 00:39:27 +00:00
|
|
|
|
2000-03-28 09:38:24 +00:00
|
|
|
// helper to translate the thickness attribute into a usable form
|
2019-08-22 06:29:26 +00:00
|
|
|
nscoord CalcLineThickness(nsPresContext* aPresContext,
|
|
|
|
ComputedStyle* aComputedStyle,
|
|
|
|
nsString& aThicknessAttribute, nscoord onePixel,
|
|
|
|
nscoord aDefaultRuleThickness,
|
|
|
|
float aFontSizeInflation);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
uint8_t ScriptIncrement(nsIFrame* aFrame) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
protected:
|
2019-02-05 16:45:54 +00:00
|
|
|
explicit nsMathMLmfracFrame(ComputedStyle* aStyle,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
: nsMathMLContainerFrame(aStyle, aPresContext, kClassID),
|
2016-12-01 08:06:50 +00:00
|
|
|
mSlashChar(nullptr),
|
2022-08-27 07:22:22 +00:00
|
|
|
mLineThickness(0) {}
|
1999-09-21 02:12:01 +00:00
|
|
|
virtual ~nsMathMLmfracFrame();
|
2015-12-15 21:56:41 +00:00
|
|
|
|
Bug 1916988 - Support CSS width/height properties on MathML elements. r=emilio
This patch implements support for the width/height properties on
MathML elements [1]. The general algorithm from the spec is as
follows:
(1) The outcome of the math layout is a "math content box".
(2) The content box sets its size from computed width/height values. If
auto, it's the one of the "math content box". This patch ignores
percentage values for now [2] [3].
(3) math content box is shifted so that its inline-start and top edges
aligns with the ones of the content box. There are exceptions
elements like mfrac and munder/mover/munderover which instead
horizontally center the math content box within the content box.
For baseline adjustment, we follow what Chromium does, see [4].
(4) Padding+border are added around the content box. Note that we
ignore the box-sizing property for now [5].
The patch essentially tweaks the various MathML layout algorithms to
perform steps (3) and (4) before the calls to
GetBorderPaddingForPlace and InflateReflowAndBoundingMetrics.
[1] https://w3c.github.io/mathml-core/#layout-algorithms
[2] https://github.com/w3c/mathml-core/issues/76
[3] https://github.com/w3c/mathml-core/issues/77
[4] https://github.com/w3c/mathml-core/issues/259
[5] https://github.com/w3c/mathml-core/issues/257
Below is more information about test coverage:
- width-height-001: Verify that width, height, inline-size and block-size
properties sets the size of the content box. This test used to verify
they are ignored, this patch fixes the `<meta name="assert">` tag.
It also adds a test for the case the specified size is smaller than the
content (we force non empty descendants to make sure this content is
large enough) and to verify the width is used for the preferred width.
- width-height-002, width-height-003: These are reftests visually checking
offsets of the math content box within a larger content box (specified
by width/height) for the mtext, mrow, mpadded, mfrac, msqrt, mroot,
in LTR/RTL modes. In particular they allow to verify some painted
elements like fraction bar and radical symbols.
- width-height-004: This test more directly checks that the math content
box is horizontally centered within a larger content box for munder,
mover, munderover and mfrac. This patch extends the test to cover the
case when the math content box is wider (i.e. overflowing outside the
content box) and removes unnecessary specified height.
- width-height-005: New test for other layout algorithm that don't
center the math content box, checking inline-start edges of children
when a width is specified. We check both LTR/RTL modes and
wider/narrower content boxes.
- width-height-006: Same but checking the top edges for larger/smaller
height and verifying that baseline is perserved.
Differential Revision: https://phabricator.services.mozilla.com/D221436
2024-09-30 12:18:39 +00:00
|
|
|
bool IsMathContentBoxHorizontallyCentered() const final { return true; }
|
|
|
|
|
2009-10-07 09:31:45 +00:00
|
|
|
// Display a slash
|
2020-01-24 11:46:14 +00:00
|
|
|
void DisplaySlash(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
nscoord aThickness, const nsDisplayListSet& aLists);
|
2009-10-07 09:31:45 +00:00
|
|
|
|
|
|
|
nsRect mLineRect;
|
2002-01-05 01:15:04 +00:00
|
|
|
nsMathMLChar* mSlashChar;
|
2009-10-07 09:31:45 +00:00
|
|
|
nscoord mLineThickness;
|
1999-09-21 02:12:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsMathMLmfracFrame_h___ */
|