gecko-dev/layout/mathml/nsMathMLmfracFrame.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
4.0 KiB
C
Raw Normal View History

/* -*- 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/. */
#ifndef nsMathMLmfracFrame_h___
#define nsMathMLmfracFrame_h___
#include "mozilla/Attributes.h"
#include "nsMathMLContainerFrame.h"
namespace mozilla {
class PresShell;
} // namespace mozilla
//
// <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
nested fractions.
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>
element.
*/
class nsMathMLmfracFrame final : public nsMathMLContainerFrame {
public:
NS_DECL_FRAMEARENA_HELPERS(nsMathMLmfracFrame)
friend nsIFrame* NS_NewMathMLmfracFrame(mozilla::PresShell* aPresShell,
ComputedStyle* aStyle);
eMathMLFrameType GetMathMLFrameType() override;
Bug 1908069 - Introduce PlaceFlags parameter to MathML layout methods. r=emilio MathML classes has a few Place*() methods used for layout and intrinsic size calculation. These methods have a parameter "aPlaceOrigin" indicating whether the children and other painted objects should have their final positions set, or if the method is only called for measuring. This parameter is typically set to false when doing intrinsic size calculation or when performing some non-final measurement for operator stretching. For intrinsic size calculation, it is generally enough to perform placement with aPlaceOrigin=false and ignoring the vertical metrics. Some Place*() methods also have a parameter "aWidthOnly" for special handling. For example, msqrt stretches a radical symbol vertically to match the height of the content but when doing intrinsic size calculation this is approximated to nsMathMLChar::GetMaxWidth() instead. When we implement border/padding/margin we should also be able to choose between using IntrinsicISizeOffsets() or GetUsed*() methods. Finally, some Place*() methods initially call a place routing of a parent class before further tweaking the layout. For example, msqrt uses mrow layout on children and adds some radical symbol on top of them. When we implement border/padding, we should make sure we don't add the border/padding before the final result. In order to handle all these placement behaviors, a new EnumSet is introduced. This commit does not change behavior. Handling of padding, border and margin will be handled in follow-up patches. Differential Revision: https://phabricator.services.mozilla.com/D216669
2024-08-07 06:00:43 +00:00
nsresult Place(DrawTarget* aDrawTarget, const PlaceFlags& aFlags,
ReflowOutput& aDesiredSize) override;
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) override;
nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
int32_t aModType) override;
NS_IMETHOD
TransmitAutomaticData() override;
// override the base method so that we can deal with the fraction line
nscoord FixInterFrameSpacing(ReflowOutput& aDesiredSize) override;
2000-03-28 09:38:24 +00:00
// helper to translate the thickness attribute into a usable form
nscoord CalcLineThickness(nsPresContext* aPresContext,
ComputedStyle* aComputedStyle,
nsString& aThicknessAttribute, nscoord onePixel,
nscoord aDefaultRuleThickness,
float aFontSizeInflation);
uint8_t ScriptIncrement(nsIFrame* aFrame) override;
protected:
explicit nsMathMLmfracFrame(ComputedStyle* aStyle,
nsPresContext* aPresContext)
: nsMathMLContainerFrame(aStyle, aPresContext, kClassID),
mSlashChar(nullptr),
mLineThickness(0) {}
virtual ~nsMathMLmfracFrame();
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; }
// Display a slash
void DisplaySlash(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
nscoord aThickness, const nsDisplayListSet& aLists);
nsRect mLineRect;
nsMathMLChar* mSlashChar;
nscoord mLineThickness;
};
#endif /* nsMathMLmfracFrame_h___ */