|
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 |
|
6 #include "nsMathMLmspaceFrame.h" |
|
7 #include "nsMathMLElement.h" |
|
8 #include "mozilla/gfx/2D.h" |
|
9 #include <algorithm> |
|
10 |
|
11 |
|
12 // |
|
13 // <mspace> -- space - implementation |
|
14 // |
|
15 |
|
16 nsIFrame* |
|
17 NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
|
18 { |
|
19 return new (aPresShell) nsMathMLmspaceFrame(aContext); |
|
20 } |
|
21 |
|
22 NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame) |
|
23 |
|
24 nsMathMLmspaceFrame::~nsMathMLmspaceFrame() |
|
25 { |
|
26 } |
|
27 |
|
28 bool |
|
29 nsMathMLmspaceFrame::IsLeaf() const |
|
30 { |
|
31 return true; |
|
32 } |
|
33 |
|
34 void |
|
35 nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext) |
|
36 { |
|
37 nsAutoString value; |
|
38 |
|
39 // width |
|
40 // |
|
41 // "Specifies the desired width of the space." |
|
42 // |
|
43 // values: length |
|
44 // default: 0em |
|
45 // |
|
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. |
|
50 // |
|
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); |
|
57 } |
|
58 |
|
59 // height |
|
60 // |
|
61 // "Specifies the desired height (above the baseline) of the space." |
|
62 // |
|
63 // values: length |
|
64 // default: 0ex |
|
65 // |
|
66 // The default value is "0ex", so unitless values can be ignored. |
|
67 // We do not allow negative values. See bug 716349. |
|
68 // |
|
69 mHeight = 0; |
|
70 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value); |
|
71 if (!value.IsEmpty()) { |
|
72 ParseNumericValue(value, &mHeight, 0, |
|
73 aPresContext, mStyleContext); |
|
74 } |
|
75 |
|
76 // depth |
|
77 // |
|
78 // "Specifies the desired depth (below the baseline) of the space." |
|
79 // |
|
80 // values: length |
|
81 // default: 0ex |
|
82 // |
|
83 // The default value is "0ex", so unitless values can be ignored. |
|
84 // We do not allow negative values. See bug 716349. |
|
85 // |
|
86 mDepth = 0; |
|
87 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value); |
|
88 if (!value.IsEmpty()) { |
|
89 ParseNumericValue(value, &mDepth, 0, |
|
90 aPresContext, mStyleContext); |
|
91 } |
|
92 } |
|
93 |
|
94 nsresult |
|
95 nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext, |
|
96 nsHTMLReflowMetrics& aDesiredSize, |
|
97 const nsHTMLReflowState& aReflowState, |
|
98 nsReflowStatus& aStatus) |
|
99 { |
|
100 ProcessAttributes(aPresContext); |
|
101 |
|
102 mBoundingMetrics = nsBoundingMetrics(); |
|
103 mBoundingMetrics.width = mWidth; |
|
104 mBoundingMetrics.ascent = mHeight; |
|
105 mBoundingMetrics.descent = mDepth; |
|
106 mBoundingMetrics.leftBearing = 0; |
|
107 mBoundingMetrics.rightBearing = mBoundingMetrics.width; |
|
108 |
|
109 aDesiredSize.SetTopAscent(mHeight); |
|
110 aDesiredSize.Width() = std::max(0, mBoundingMetrics.width); |
|
111 aDesiredSize.Height() = aDesiredSize.TopAscent() + mDepth; |
|
112 // Also return our bounding metrics |
|
113 aDesiredSize.mBoundingMetrics = mBoundingMetrics; |
|
114 |
|
115 aStatus = NS_FRAME_COMPLETE; |
|
116 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); |
|
117 return NS_OK; |
|
118 } |
|
119 |
|
120 /* virtual */ nsresult |
|
121 nsMathMLmspaceFrame::MeasureForWidth(nsRenderingContext& aRenderingContext, |
|
122 nsHTMLReflowMetrics& aDesiredSize) |
|
123 { |
|
124 ProcessAttributes(PresContext()); |
|
125 mBoundingMetrics = nsBoundingMetrics(); |
|
126 mBoundingMetrics.width = mWidth; |
|
127 aDesiredSize.Width() = std::max(0, mBoundingMetrics.width); |
|
128 aDesiredSize.mBoundingMetrics = mBoundingMetrics; |
|
129 return NS_OK; |
|
130 } |