nsMathMLmfracFrame.h 4.1 KB

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