tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsMathMLmfracFrame.h (3897B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef nsMathMLmfracFrame_h___
      8 #define nsMathMLmfracFrame_h___
      9 
     10 #include "nsMathMLContainerFrame.h"
     11 
     12 namespace mozilla {
     13 class PresShell;
     14 }  // namespace mozilla
     15 
     16 //
     17 // <mfrac> -- form a fraction from two subexpressions
     18 //
     19 
     20 /*
     21 The MathML REC describes:
     22 
     23 The <mfrac> element is used for fractions. It can also be used to mark up
     24 fraction-like objects such as binomial coefficients and Legendre symbols.
     25 The syntax for <mfrac> is:
     26  <mfrac> numerator denominator </mfrac>
     27 
     28 Attributes of <mfrac>:
     29     Name                      values                     default
     30  linethickness  number [ v-unit ] | thin | medium | thick  1
     31 
     32 E.g.,
     33 linethickness=2 actually means that linethickness=2*DEFAULT_THICKNESS
     34 (DEFAULT_THICKNESS is not specified by MathML, see below.)
     35 
     36 The linethickness attribute indicates the thickness of the horizontal
     37 "fraction bar", or "rule", typically used to render fractions. A fraction
     38 with linethickness="0" renders without the bar, and might be used within
     39 binomial coefficients. A linethickness greater than one might be used with
     40 nested fractions.
     41 
     42 In general, the value of linethickness can be a number, as a multiplier
     43 of the default thickness of the fraction bar (the default thickness is
     44 not specified by MathML), or a number with a unit of vertical length (see
     45 Section 2.3.3), or one of the keywords medium (same as 1), thin (thinner
     46 than 1, otherwise up to the renderer), or thick (thicker than 1, otherwise
     47 up to the renderer).
     48 
     49 The <mfrac> element sets displaystyle to "false", or if it was already
     50 false increments scriptlevel by 1, within numerator and denominator.
     51 These attributes are inherited by every element from its rendering
     52 environment, but can be set explicitly only on the <mstyle>
     53 element.
     54 */
     55 
     56 class nsMathMLmfracFrame final : public nsMathMLContainerFrame {
     57 public:
     58  NS_DECL_FRAMEARENA_HELPERS(nsMathMLmfracFrame)
     59 
     60  friend nsIFrame* NS_NewMathMLmfracFrame(mozilla::PresShell* aPresShell,
     61                                          ComputedStyle* aStyle);
     62 
     63  MathMLFrameType GetMathMLFrameType() override;
     64 
     65  void Place(DrawTarget* aDrawTarget, const PlaceFlags& aFlags,
     66             ReflowOutput& aDesiredSize) override;
     67 
     68  void BuildDisplayList(nsDisplayListBuilder* aBuilder,
     69                        const nsDisplayListSet& aLists) override;
     70 
     71  nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
     72                            AttrModType aModType) override;
     73 
     74  NS_IMETHOD
     75  TransmitAutomaticData() override;
     76 
     77  // override the base method so that we can deal with the fraction line
     78  nscoord FixInterFrameSpacing(ReflowOutput& aDesiredSize) override;
     79 
     80  // helper to translate the thickness attribute into a usable form
     81  nscoord CalcLineThickness(nsString& aThicknessAttribute, nscoord onePixel,
     82                            nscoord aDefaultRuleThickness,
     83                            float aFontSizeInflation);
     84 
     85  uint8_t ScriptIncrement(nsIFrame* aFrame) override;
     86 
     87 protected:
     88  explicit nsMathMLmfracFrame(ComputedStyle* aStyle,
     89                              nsPresContext* aPresContext)
     90      : nsMathMLContainerFrame(aStyle, aPresContext, kClassID),
     91        mSlashChar(nullptr),
     92        mLineThickness(0) {}
     93  virtual ~nsMathMLmfracFrame();
     94 
     95  bool IsMathContentBoxHorizontallyCentered() const final { return true; }
     96 
     97  // Display a slash
     98  void DisplaySlash(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
     99                    nscoord aThickness, const nsDisplayListSet& aLists);
    100 
    101  nsRect mLineRect;
    102  nsMathMLChar* mSlashChar;
    103  nscoord mLineThickness;
    104 };
    105 
    106 #endif /* nsMathMLmfracFrame_h___ */