1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla MathML Project.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * The University Of Queensland.
19 : * Portions created by the Initial Developer are Copyright (C) 1999
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Roger B. Sidje <rbs@maths.uq.edu.au>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 :
40 : #include "nsCOMPtr.h"
41 : #include "nsFrame.h"
42 : #include "nsPresContext.h"
43 : #include "nsStyleContext.h"
44 : #include "nsStyleConsts.h"
45 :
46 : #include "nsMathMLmspaceFrame.h"
47 :
48 :
49 : //
50 : // <mspace> -- space - implementation
51 : //
52 :
53 : nsIFrame*
54 0 : NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
55 : {
56 0 : return new (aPresShell) nsMathMLmspaceFrame(aContext);
57 : }
58 :
59 0 : NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame)
60 :
61 0 : nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
62 : {
63 0 : }
64 :
65 : bool
66 0 : nsMathMLmspaceFrame::IsLeaf() const
67 : {
68 0 : return true;
69 : }
70 :
71 : void
72 0 : nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext)
73 : {
74 : /*
75 : parse the attributes
76 :
77 : width = number h-unit
78 : height = number v-unit
79 : depth = number v-unit
80 : */
81 :
82 0 : nsAutoString value;
83 0 : nsCSSValue cssValue;
84 :
85 : // width
86 0 : mWidth = 0;
87 : GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::width,
88 0 : value);
89 0 : if (!value.IsEmpty()) {
90 0 : if ((ParseNumericValue(value, cssValue) ||
91 0 : ParseNamedSpaceValue(mPresentationData.mstyle, value, cssValue)) &&
92 0 : cssValue.IsLengthUnit()) {
93 0 : mWidth = CalcLength(aPresContext, mStyleContext, cssValue);
94 : }
95 : }
96 :
97 : // height
98 0 : mHeight = 0;
99 : GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::height,
100 0 : value);
101 0 : if (!value.IsEmpty()) {
102 0 : if ((ParseNumericValue(value, cssValue) ||
103 0 : ParseNamedSpaceValue(mPresentationData.mstyle, value, cssValue)) &&
104 0 : cssValue.IsLengthUnit()) {
105 0 : mHeight = CalcLength(aPresContext, mStyleContext, cssValue);
106 : }
107 : }
108 :
109 : // depth
110 0 : mDepth = 0;
111 : GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::depth_,
112 0 : value);
113 0 : if (!value.IsEmpty()) {
114 0 : if ((ParseNumericValue(value, cssValue) ||
115 0 : ParseNamedSpaceValue(mPresentationData.mstyle, value, cssValue)) &&
116 0 : cssValue.IsLengthUnit()) {
117 0 : mDepth = CalcLength(aPresContext, mStyleContext, cssValue);
118 : }
119 : }
120 0 : }
121 :
122 : NS_IMETHODIMP
123 0 : nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext,
124 : nsHTMLReflowMetrics& aDesiredSize,
125 : const nsHTMLReflowState& aReflowState,
126 : nsReflowStatus& aStatus)
127 : {
128 0 : ProcessAttributes(aPresContext);
129 :
130 0 : mBoundingMetrics = nsBoundingMetrics();
131 0 : mBoundingMetrics.width = mWidth;
132 0 : mBoundingMetrics.ascent = mHeight;
133 0 : mBoundingMetrics.descent = mDepth;
134 0 : mBoundingMetrics.leftBearing = 0;
135 0 : mBoundingMetrics.rightBearing = mWidth;
136 :
137 0 : aDesiredSize.ascent = mHeight;
138 0 : aDesiredSize.width = mWidth;
139 0 : aDesiredSize.height = aDesiredSize.ascent + mDepth;
140 : // Also return our bounding metrics
141 0 : aDesiredSize.mBoundingMetrics = mBoundingMetrics;
142 :
143 0 : aStatus = NS_FRAME_COMPLETE;
144 0 : NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
145 0 : return NS_OK;
146 : }
|