nsMathMLmfencedFrame.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 nsMathMLmfencedFrame_h
  6. #define nsMathMLmfencedFrame_h
  7. #include "mozilla/Attributes.h"
  8. #include "nsMathMLContainerFrame.h"
  9. class nsFontMetrics;
  10. //
  11. // <mfenced> -- surround content with a pair of fences
  12. //
  13. class nsMathMLmfencedFrame final : public nsMathMLContainerFrame {
  14. public:
  15. NS_DECL_FRAMEARENA_HELPERS
  16. friend nsIFrame* NS_NewMathMLmfencedFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
  17. virtual void
  18. SetAdditionalStyleContext(int32_t aIndex,
  19. nsStyleContext* aStyleContext) override;
  20. virtual nsStyleContext*
  21. GetAdditionalStyleContext(int32_t aIndex) const override;
  22. NS_IMETHOD
  23. InheritAutomaticData(nsIFrame* aParent) override;
  24. virtual void
  25. SetInitialChildList(ChildListID aListID,
  26. nsFrameList& aChildList) override;
  27. virtual void
  28. Reflow(nsPresContext* aPresContext,
  29. ReflowOutput& aDesiredSize,
  30. const ReflowInput& aReflowInput,
  31. nsReflowStatus& aStatus) override;
  32. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  33. const nsDisplayListSet& aLists) override;
  34. virtual void
  35. GetIntrinsicISizeMetrics(nsRenderingContext* aRenderingContext,
  36. ReflowOutput& aDesiredSize) override;
  37. virtual nsresult
  38. AttributeChanged(int32_t aNameSpaceID,
  39. nsIAtom* aAttribute,
  40. int32_t aModType) override;
  41. // override the base method because we must keep separators in sync
  42. virtual nsresult
  43. ChildListChanged(int32_t aModType) override;
  44. // override the base method so that we can deal with fences and separators
  45. virtual nscoord
  46. FixInterFrameSpacing(ReflowOutput& aDesiredSize) override;
  47. // helper routines to format the MathMLChars involved here
  48. static nsresult
  49. ReflowChar(nsPresContext* aPresContext,
  50. DrawTarget* aDrawTarget,
  51. nsFontMetrics& aFontMetrics,
  52. float aFontSizeInflation,
  53. nsMathMLChar* aMathMLChar,
  54. nsOperatorFlags aForm,
  55. int32_t aScriptLevel,
  56. nscoord axisHeight,
  57. nscoord leading,
  58. nscoord em,
  59. nsBoundingMetrics& aContainerSize,
  60. nscoord& aAscent,
  61. nscoord& aDescent,
  62. bool aRTL);
  63. static void
  64. PlaceChar(nsMathMLChar* aMathMLChar,
  65. nscoord aDesiredSize,
  66. nsBoundingMetrics& bm,
  67. nscoord& dx);
  68. virtual bool
  69. IsMrowLike() override
  70. {
  71. // Always treated as an mrow with > 1 child as
  72. // <mfenced> <mo>%</mo> </mfenced>
  73. // renders equivalently to
  74. // <mrow> <mo> ( </mo> <mo>%</mo> <mo> ) </mo> </mrow>
  75. // This also holds with multiple children. (MathML3 3.3.8.1)
  76. return true;
  77. }
  78. protected:
  79. explicit nsMathMLmfencedFrame(nsStyleContext* aContext) : nsMathMLContainerFrame(aContext) {}
  80. virtual ~nsMathMLmfencedFrame();
  81. nsMathMLChar* mOpenChar;
  82. nsMathMLChar* mCloseChar;
  83. nsMathMLChar* mSeparatorsChar;
  84. int32_t mSeparatorsCount;
  85. // clean up
  86. void
  87. RemoveFencesAndSeparators();
  88. // add fences and separators when all child frames are known
  89. void
  90. CreateFencesAndSeparators(nsPresContext* aPresContext);
  91. };
  92. #endif /* nsMathMLmfencedFrame_h */