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/. */
6 #include "nsMathMLmspaceFrame.h"
7 #include "nsMathMLElement.h"
8 #include "mozilla/gfx/2D.h"
13 // <mspace> -- space - implementation
17 NS_NewMathMLmspaceFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
19 return new (aPresShell
) nsMathMLmspaceFrame(aContext
);
22 NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame
)
24 nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
29 nsMathMLmspaceFrame::IsLeaf() const
35 nsMathMLmspaceFrame::ProcessAttributes(nsPresContext
* aPresContext
)
41 // "Specifies the desired width of the space."
46 // The default value is "0em", so unitless values can be ignored.
47 // <mspace/> is listed among MathML elements allowing negative spacing and
48 // the MathML test suite contains "Presentation/TokenElements/mspace/mspace2"
49 // as an example. Hence we allow negative values.
52 mContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::width
, value
);
53 if (!value
.IsEmpty()) {
54 ParseNumericValue(value
, &mWidth
,
55 nsMathMLElement::PARSE_ALLOW_NEGATIVE
,
56 aPresContext
, mStyleContext
);
61 // "Specifies the desired height (above the baseline) of the space."
66 // The default value is "0ex", so unitless values can be ignored.
67 // We do not allow negative values. See bug 716349.
70 mContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::height
, value
);
71 if (!value
.IsEmpty()) {
72 ParseNumericValue(value
, &mHeight
, 0,
73 aPresContext
, mStyleContext
);
78 // "Specifies the desired depth (below the baseline) of the space."
83 // The default value is "0ex", so unitless values can be ignored.
84 // We do not allow negative values. See bug 716349.
87 mContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::depth_
, value
);
88 if (!value
.IsEmpty()) {
89 ParseNumericValue(value
, &mDepth
, 0,
90 aPresContext
, mStyleContext
);
95 nsMathMLmspaceFrame::Reflow(nsPresContext
* aPresContext
,
96 nsHTMLReflowMetrics
& aDesiredSize
,
97 const nsHTMLReflowState
& aReflowState
,
98 nsReflowStatus
& aStatus
)
100 ProcessAttributes(aPresContext
);
102 mBoundingMetrics
= nsBoundingMetrics();
103 mBoundingMetrics
.width
= mWidth
;
104 mBoundingMetrics
.ascent
= mHeight
;
105 mBoundingMetrics
.descent
= mDepth
;
106 mBoundingMetrics
.leftBearing
= 0;
107 mBoundingMetrics
.rightBearing
= mBoundingMetrics
.width
;
109 aDesiredSize
.SetBlockStartAscent(mHeight
);
110 aDesiredSize
.Width() = std::max(0, mBoundingMetrics
.width
);
111 aDesiredSize
.Height() = aDesiredSize
.BlockStartAscent() + mDepth
;
112 // Also return our bounding metrics
113 aDesiredSize
.mBoundingMetrics
= mBoundingMetrics
;
115 aStatus
= NS_FRAME_COMPLETE
;
116 NS_FRAME_SET_TRUNCATION(aStatus
, aReflowState
, aDesiredSize
);
119 /* virtual */ nsresult
120 nsMathMLmspaceFrame::MeasureForWidth(nsRenderingContext
& aRenderingContext
,
121 nsHTMLReflowMetrics
& aDesiredSize
)
123 ProcessAttributes(PresContext());
124 mBoundingMetrics
= nsBoundingMetrics();
125 mBoundingMetrics
.width
= mWidth
;
126 aDesiredSize
.Width() = std::max(0, mBoundingMetrics
.width
);
127 aDesiredSize
.mBoundingMetrics
= mBoundingMetrics
;