/src/mozilla-central/layout/mathml/nsMathMLmspaceFrame.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "nsMathMLmspaceFrame.h" |
8 | | #include "nsMathMLElement.h" |
9 | | #include "mozilla/gfx/2D.h" |
10 | | #include <algorithm> |
11 | | |
12 | | |
13 | | // |
14 | | // <mspace> -- space - implementation |
15 | | // |
16 | | |
17 | | nsIFrame* |
18 | | NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) |
19 | 0 | { |
20 | 0 | return new (aPresShell) nsMathMLmspaceFrame(aStyle); |
21 | 0 | } |
22 | | |
23 | | NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame) |
24 | | |
25 | | nsMathMLmspaceFrame::~nsMathMLmspaceFrame() |
26 | 0 | { |
27 | 0 | } |
28 | | |
29 | | void |
30 | | nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext) |
31 | 0 | { |
32 | 0 | nsAutoString value; |
33 | 0 | float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this); |
34 | 0 |
|
35 | 0 | // width |
36 | 0 | // |
37 | 0 | // "Specifies the desired width of the space." |
38 | 0 | // |
39 | 0 | // values: length |
40 | 0 | // default: 0em |
41 | 0 | // |
42 | 0 | // The default value is "0em", so unitless values can be ignored. |
43 | 0 | // <mspace/> is listed among MathML elements allowing negative spacing and |
44 | 0 | // the MathML test suite contains "Presentation/TokenElements/mspace/mspace2" |
45 | 0 | // as an example. Hence we allow negative values. |
46 | 0 | // |
47 | 0 | mWidth = 0; |
48 | 0 | mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value); |
49 | 0 | if (!value.IsEmpty()) { |
50 | 0 | ParseNumericValue(value, &mWidth, |
51 | 0 | nsMathMLElement::PARSE_ALLOW_NEGATIVE, |
52 | 0 | aPresContext, mComputedStyle, fontSizeInflation); |
53 | 0 | } |
54 | 0 |
|
55 | 0 | // height |
56 | 0 | // |
57 | 0 | // "Specifies the desired height (above the baseline) of the space." |
58 | 0 | // |
59 | 0 | // values: length |
60 | 0 | // default: 0ex |
61 | 0 | // |
62 | 0 | // The default value is "0ex", so unitless values can be ignored. |
63 | 0 | // We do not allow negative values. See bug 716349. |
64 | 0 | // |
65 | 0 | mHeight = 0; |
66 | 0 | mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value); |
67 | 0 | if (!value.IsEmpty()) { |
68 | 0 | ParseNumericValue(value, &mHeight, 0, |
69 | 0 | aPresContext, mComputedStyle, fontSizeInflation); |
70 | 0 | } |
71 | 0 |
|
72 | 0 | // depth |
73 | 0 | // |
74 | 0 | // "Specifies the desired depth (below the baseline) of the space." |
75 | 0 | // |
76 | 0 | // values: length |
77 | 0 | // default: 0ex |
78 | 0 | // |
79 | 0 | // The default value is "0ex", so unitless values can be ignored. |
80 | 0 | // We do not allow negative values. See bug 716349. |
81 | 0 | // |
82 | 0 | mDepth = 0; |
83 | 0 | mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value); |
84 | 0 | if (!value.IsEmpty()) { |
85 | 0 | ParseNumericValue(value, &mDepth, 0, |
86 | 0 | aPresContext, mComputedStyle, fontSizeInflation); |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | void |
91 | | nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext, |
92 | | ReflowOutput& aDesiredSize, |
93 | | const ReflowInput& aReflowInput, |
94 | | nsReflowStatus& aStatus) |
95 | 0 | { |
96 | 0 | MarkInReflow(); |
97 | 0 | MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!"); |
98 | 0 |
|
99 | 0 | mPresentationData.flags &= ~NS_MATHML_ERROR; |
100 | 0 | ProcessAttributes(aPresContext); |
101 | 0 |
|
102 | 0 | mBoundingMetrics = nsBoundingMetrics(); |
103 | 0 | mBoundingMetrics.width = mWidth; |
104 | 0 | mBoundingMetrics.ascent = mHeight; |
105 | 0 | mBoundingMetrics.descent = mDepth; |
106 | 0 | mBoundingMetrics.leftBearing = 0; |
107 | 0 | mBoundingMetrics.rightBearing = mBoundingMetrics.width; |
108 | 0 |
|
109 | 0 | aDesiredSize.SetBlockStartAscent(mHeight); |
110 | 0 | aDesiredSize.Width() = std::max(0, mBoundingMetrics.width); |
111 | 0 | aDesiredSize.Height() = aDesiredSize.BlockStartAscent() + mDepth; |
112 | 0 | // Also return our bounding metrics |
113 | 0 | aDesiredSize.mBoundingMetrics = mBoundingMetrics; |
114 | 0 |
|
115 | 0 | NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize); |
116 | 0 | } |
117 | | |
118 | | /* virtual */ nsresult |
119 | | nsMathMLmspaceFrame::MeasureForWidth(DrawTarget* aDrawTarget, |
120 | | ReflowOutput& aDesiredSize) |
121 | 0 | { |
122 | 0 | ProcessAttributes(PresContext()); |
123 | 0 | mBoundingMetrics = nsBoundingMetrics(); |
124 | 0 | mBoundingMetrics.width = mWidth; |
125 | 0 | aDesiredSize.Width() = std::max(0, mBoundingMetrics.width); |
126 | 0 | aDesiredSize.mBoundingMetrics = mBoundingMetrics; |
127 | 0 | return NS_OK; |
128 | 0 | } |