Bumping manifests a=b2g-bump
[gecko.git] / layout / mathml / nsMathMLmspaceFrame.cpp
blobf4a34434be6d46e265916a702f7dd9958f1f3177
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"
9 #include <algorithm>
13 // <mspace> -- space - implementation
16 nsIFrame*
17 NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
19 return new (aPresShell) nsMathMLmspaceFrame(aContext);
22 NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame)
24 nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
28 bool
29 nsMathMLmspaceFrame::IsLeaf() const
31 return true;
34 void
35 nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext)
37 nsAutoString value;
39 // width
41 // "Specifies the desired width of the space."
43 // values: length
44 // default: 0em
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.
51 mWidth = 0;
52 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value);
53 if (!value.IsEmpty()) {
54 ParseNumericValue(value, &mWidth,
55 nsMathMLElement::PARSE_ALLOW_NEGATIVE,
56 aPresContext, mStyleContext);
59 // height
61 // "Specifies the desired height (above the baseline) of the space."
63 // values: length
64 // default: 0ex
66 // The default value is "0ex", so unitless values can be ignored.
67 // We do not allow negative values. See bug 716349.
69 mHeight = 0;
70 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value);
71 if (!value.IsEmpty()) {
72 ParseNumericValue(value, &mHeight, 0,
73 aPresContext, mStyleContext);
76 // depth
78 // "Specifies the desired depth (below the baseline) of the space."
80 // values: length
81 // default: 0ex
83 // The default value is "0ex", so unitless values can be ignored.
84 // We do not allow negative values. See bug 716349.
86 mDepth = 0;
87 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value);
88 if (!value.IsEmpty()) {
89 ParseNumericValue(value, &mDepth, 0,
90 aPresContext, mStyleContext);
94 void
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;
128 return NS_OK;