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
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/
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
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Christopher A. Aillon <christopher@aillon.com>
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * Christopher A. Aillon <christopher@aillon.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * 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.
37 * ***** END LICENSE BLOCK ***** */
39 /* DOM object returned from element.getComputedStyle() */
41 #ifndef nsComputedDOMStyle_h__
42 #define nsComputedDOMStyle_h__
44 #include "nsIComputedDOMStyle.h"
46 #include "nsROCSSPrimitiveValue.h"
47 #include "nsDOMCSSDeclaration.h"
48 #include "nsDOMCSSRGBColor.h"
49 #include "nsDOMCSSValueList.h"
50 #include "nsCSSProps.h"
52 #include "nsIPresShell.h"
53 #include "nsIContent.h"
56 #include "nsWeakReference.h"
57 #include "nsAutoPtr.h"
59 class nsComputedDOMStyle
: public nsIComputedDOMStyle
62 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
63 NS_DECL_CYCLE_COLLECTION_CLASS(nsComputedDOMStyle
)
65 NS_IMETHOD
Init(nsIDOMElement
*aElement
,
66 const nsAString
& aPseudoElt
,
67 nsIPresShell
*aPresShell
);
69 NS_DECL_NSICSSDECLARATION
71 NS_DECL_NSIDOMCSSSTYLEDECLARATION
74 virtual ~nsComputedDOMStyle();
76 static void Shutdown();
79 void FlushPendingReflows();
81 #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_) \
82 const nsStyle##name_ * GetStyle##name_() { \
83 return mStyleContextHolder->GetStyle##name_(); \
85 #include "nsStyleStructList.h"
88 nsresult
GetEllipseRadii(const nsStyleCorners
& aRadius
,
90 nsIDOMCSSValue
** aValue
);
92 nsresult
GetOffsetWidthFor(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
94 nsresult
GetAbsoluteOffset(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
96 nsresult
GetRelativeOffset(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
98 nsresult
GetStaticOffset(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
100 nsresult
GetPaddingWidthFor(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
102 nsresult
GetBorderColorsFor(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
104 nsresult
GetBorderStyleFor(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
106 nsresult
GetBorderWidthFor(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
108 nsresult
GetBorderColorFor(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
110 nsresult
GetMarginWidthFor(PRUint8 aSide
, nsIDOMCSSValue
** aValue
);
112 PRBool
GetLineHeightCoord(nscoord
& aCoord
);
114 nsresult
GetCSSShadowArray(nsCSSShadowArray
* aArray
,
115 const nscolor
& aDefaultColor
,
117 nsIDOMCSSValue
** aValue
);
119 /* Properties Queryable as CSSValues */
121 nsresult
GetAppearance(nsIDOMCSSValue
** aValue
);
124 nsresult
GetBoxAlign(nsIDOMCSSValue
** aValue
);
125 nsresult
GetBoxDirection(nsIDOMCSSValue
** aValue
);
126 nsresult
GetBoxFlex(nsIDOMCSSValue
** aValue
);
127 nsresult
GetBoxOrdinalGroup(nsIDOMCSSValue
** aValue
);
128 nsresult
GetBoxOrient(nsIDOMCSSValue
** aValue
);
129 nsresult
GetBoxPack(nsIDOMCSSValue
** aValue
);
130 nsresult
GetBoxSizing(nsIDOMCSSValue
** aValue
);
132 nsresult
GetWidth(nsIDOMCSSValue
** aValue
);
133 nsresult
GetHeight(nsIDOMCSSValue
** aValue
);
134 nsresult
GetMaxHeight(nsIDOMCSSValue
** aValue
);
135 nsresult
GetMaxWidth(nsIDOMCSSValue
** aValue
);
136 nsresult
GetMinHeight(nsIDOMCSSValue
** aValue
);
137 nsresult
GetMinWidth(nsIDOMCSSValue
** aValue
);
138 nsresult
GetLeft(nsIDOMCSSValue
** aValue
);
139 nsresult
GetTop(nsIDOMCSSValue
** aValue
);
140 nsresult
GetRight(nsIDOMCSSValue
** aValue
);
141 nsresult
GetBottom(nsIDOMCSSValue
** aValue
);
142 nsresult
GetStackSizing(nsIDOMCSSValue
** aValue
);
144 /* Font properties */
145 nsresult
GetColor(nsIDOMCSSValue
** aValue
);
146 nsresult
GetFontFamily(nsIDOMCSSValue
** aValue
);
147 nsresult
GetFontStyle(nsIDOMCSSValue
** aValue
);
148 nsresult
GetFontSize(nsIDOMCSSValue
** aValue
);
149 nsresult
GetFontSizeAdjust(nsIDOMCSSValue
** aValue
);
150 nsresult
GetFontWeight(nsIDOMCSSValue
** aValue
);
151 nsresult
GetFontVariant(nsIDOMCSSValue
** aValue
);
153 /* Background properties */
154 nsresult
GetBackgroundAttachment(nsIDOMCSSValue
** aValue
);
155 nsresult
GetBackgroundColor(nsIDOMCSSValue
** aValue
);
156 nsresult
GetBackgroundImage(nsIDOMCSSValue
** aValue
);
157 nsresult
GetBackgroundPosition(nsIDOMCSSValue
** aValue
);
158 nsresult
GetBackgroundRepeat(nsIDOMCSSValue
** aValue
);
159 nsresult
GetBackgroundClip(nsIDOMCSSValue
** aValue
);
160 nsresult
GetBackgroundInlinePolicy(nsIDOMCSSValue
** aValue
);
161 nsresult
GetBackgroundOrigin(nsIDOMCSSValue
** aValue
);
163 /* Padding properties */
164 nsresult
GetPadding(nsIDOMCSSValue
** aValue
);
165 nsresult
GetPaddingTop(nsIDOMCSSValue
** aValue
);
166 nsresult
GetPaddingBottom(nsIDOMCSSValue
** aValue
);
167 nsresult
GetPaddingLeft(nsIDOMCSSValue
** aValue
);
168 nsresult
GetPaddingRight(nsIDOMCSSValue
** aValue
);
170 /* Table Properties */
171 nsresult
GetBorderCollapse(nsIDOMCSSValue
** aValue
);
172 nsresult
GetBorderSpacing(nsIDOMCSSValue
** aValue
);
173 nsresult
GetCaptionSide(nsIDOMCSSValue
** aValue
);
174 nsresult
GetEmptyCells(nsIDOMCSSValue
** aValue
);
175 nsresult
GetTableLayout(nsIDOMCSSValue
** aValue
);
176 nsresult
GetVerticalAlign(nsIDOMCSSValue
** aValue
);
178 /* Border Properties */
179 nsresult
GetBorderStyle(nsIDOMCSSValue
** aValue
);
180 nsresult
GetBorderWidth(nsIDOMCSSValue
** aValue
);
181 nsresult
GetBorderTopStyle(nsIDOMCSSValue
** aValue
);
182 nsresult
GetBorderBottomStyle(nsIDOMCSSValue
** aValue
);
183 nsresult
GetBorderLeftStyle(nsIDOMCSSValue
** aValue
);
184 nsresult
GetBorderRightStyle(nsIDOMCSSValue
** aValue
);
185 nsresult
GetBorderTopWidth(nsIDOMCSSValue
** aValue
);
186 nsresult
GetBorderBottomWidth(nsIDOMCSSValue
** aValue
);
187 nsresult
GetBorderLeftWidth(nsIDOMCSSValue
** aValue
);
188 nsresult
GetBorderRightWidth(nsIDOMCSSValue
** aValue
);
189 nsresult
GetBorderTopColor(nsIDOMCSSValue
** aValue
);
190 nsresult
GetBorderBottomColor(nsIDOMCSSValue
** aValue
);
191 nsresult
GetBorderLeftColor(nsIDOMCSSValue
** aValue
);
192 nsresult
GetBorderRightColor(nsIDOMCSSValue
** aValue
);
193 nsresult
GetBorderBottomColors(nsIDOMCSSValue
** aValue
);
194 nsresult
GetBorderLeftColors(nsIDOMCSSValue
** aValue
);
195 nsresult
GetBorderRightColors(nsIDOMCSSValue
** aValue
);
196 nsresult
GetBorderTopColors(nsIDOMCSSValue
** aValue
);
197 nsresult
GetBorderRadiusBottomLeft(nsIDOMCSSValue
** aValue
);
198 nsresult
GetBorderRadiusBottomRight(nsIDOMCSSValue
** aValue
);
199 nsresult
GetBorderRadiusTopLeft(nsIDOMCSSValue
** aValue
);
200 nsresult
GetBorderRadiusTopRight(nsIDOMCSSValue
** aValue
);
201 nsresult
GetFloatEdge(nsIDOMCSSValue
** aValue
);
202 nsresult
GetBorderImage(nsIDOMCSSValue
** aValue
);
205 nsresult
GetBoxShadow(nsIDOMCSSValue
** aValue
);
208 nsresult
GetWindowShadow(nsIDOMCSSValue
** aValue
);
210 /* Margin Properties */
211 nsresult
GetMarginWidth(nsIDOMCSSValue
** aValue
);
212 nsresult
GetMarginTopWidth(nsIDOMCSSValue
** aValue
);
213 nsresult
GetMarginBottomWidth(nsIDOMCSSValue
** aValue
);
214 nsresult
GetMarginLeftWidth(nsIDOMCSSValue
** aValue
);
215 nsresult
GetMarginRightWidth(nsIDOMCSSValue
** aValue
);
217 /* Outline Properties */
218 nsresult
GetOutline(nsIDOMCSSValue
** aValue
);
219 nsresult
GetOutlineWidth(nsIDOMCSSValue
** aValue
);
220 nsresult
GetOutlineStyle(nsIDOMCSSValue
** aValue
);
221 nsresult
GetOutlineColor(nsIDOMCSSValue
** aValue
);
222 nsresult
GetOutlineOffset(nsIDOMCSSValue
** aValue
);
223 nsresult
GetOutlineRadiusBottomLeft(nsIDOMCSSValue
** aValue
);
224 nsresult
GetOutlineRadiusBottomRight(nsIDOMCSSValue
** aValue
);
225 nsresult
GetOutlineRadiusTopLeft(nsIDOMCSSValue
** aValue
);
226 nsresult
GetOutlineRadiusTopRight(nsIDOMCSSValue
** aValue
);
228 /* Content Properties */
229 nsresult
GetContent(nsIDOMCSSValue
** aValue
);
230 nsresult
GetCounterIncrement(nsIDOMCSSValue
** aValue
);
231 nsresult
GetCounterReset(nsIDOMCSSValue
** aValue
);
232 nsresult
GetMarkerOffset(nsIDOMCSSValue
** aValue
);
234 /* Quotes Properties */
235 nsresult
GetQuotes(nsIDOMCSSValue
** aValue
);
238 nsresult
GetZIndex(nsIDOMCSSValue
** aValue
);
240 /* List properties */
241 nsresult
GetListStyleImage(nsIDOMCSSValue
** aValue
);
242 nsresult
GetListStylePosition(nsIDOMCSSValue
** aValue
);
243 nsresult
GetListStyleType(nsIDOMCSSValue
** aValue
);
244 nsresult
GetImageRegion(nsIDOMCSSValue
** aValue
);
246 /* Text Properties */
247 nsresult
GetLineHeight(nsIDOMCSSValue
** aValue
);
248 nsresult
GetTextAlign(nsIDOMCSSValue
** aValue
);
249 nsresult
GetTextDecoration(nsIDOMCSSValue
** aValue
);
250 nsresult
GetTextIndent(nsIDOMCSSValue
** aValue
);
251 nsresult
GetTextTransform(nsIDOMCSSValue
** aValue
);
252 nsresult
GetTextShadow(nsIDOMCSSValue
** aValue
);
253 nsresult
GetLetterSpacing(nsIDOMCSSValue
** aValue
);
254 nsresult
GetWordSpacing(nsIDOMCSSValue
** aValue
);
255 nsresult
GetWhiteSpace(nsIDOMCSSValue
** aValue
);
256 nsresult
GetWordWrap(nsIDOMCSSValue
** aValue
);
258 /* Visibility properties */
259 nsresult
GetOpacity(nsIDOMCSSValue
** aValue
);
260 nsresult
GetVisibility(nsIDOMCSSValue
** aValue
);
262 /* Direction properties */
263 nsresult
GetDirection(nsIDOMCSSValue
** aValue
);
264 nsresult
GetUnicodeBidi(nsIDOMCSSValue
** aValue
);
266 /* Display properties */
267 nsresult
GetBinding(nsIDOMCSSValue
** aValue
);
268 nsresult
GetClear(nsIDOMCSSValue
** aValue
);
269 nsresult
GetCssFloat(nsIDOMCSSValue
** aValue
);
270 nsresult
GetDisplay(nsIDOMCSSValue
** aValue
);
271 nsresult
GetPosition(nsIDOMCSSValue
** aValue
);
272 nsresult
GetClip(nsIDOMCSSValue
** aValue
);
273 nsresult
GetOverflow(nsIDOMCSSValue
** aValue
);
274 nsresult
GetOverflowX(nsIDOMCSSValue
** aValue
);
275 nsresult
GetOverflowY(nsIDOMCSSValue
** aValue
);
276 nsresult
GetPageBreakAfter(nsIDOMCSSValue
** aValue
);
277 nsresult
GetPageBreakBefore(nsIDOMCSSValue
** aValue
);
278 nsresult
GetMozTransform(nsIDOMCSSValue
** aValue
);
279 nsresult
GetMozTransformOrigin(nsIDOMCSSValue
**aValue
);
281 /* User interface properties */
282 nsresult
GetCursor(nsIDOMCSSValue
** aValue
);
283 nsresult
GetForceBrokenImageIcon(nsIDOMCSSValue
** aValue
);
284 nsresult
GetIMEMode(nsIDOMCSSValue
** aValue
);
285 nsresult
GetUserFocus(nsIDOMCSSValue
** aValue
);
286 nsresult
GetUserInput(nsIDOMCSSValue
** aValue
);
287 nsresult
GetUserModify(nsIDOMCSSValue
** aValue
);
288 nsresult
GetUserSelect(nsIDOMCSSValue
** aValue
);
290 /* Column properties */
291 nsresult
GetColumnCount(nsIDOMCSSValue
** aValue
);
292 nsresult
GetColumnWidth(nsIDOMCSSValue
** aValue
);
293 nsresult
GetColumnGap(nsIDOMCSSValue
** aValue
);
294 nsresult
GetColumnRuleWidth(nsIDOMCSSValue
** aValue
);
295 nsresult
GetColumnRuleStyle(nsIDOMCSSValue
** aValue
);
296 nsresult
GetColumnRuleColor(nsIDOMCSSValue
** aValue
);
300 nsresult
GetSVGPaintFor(PRBool aFill
, nsIDOMCSSValue
** aValue
);
302 nsresult
GetFill(nsIDOMCSSValue
** aValue
);
303 nsresult
GetStroke(nsIDOMCSSValue
** aValue
);
304 nsresult
GetMarkerEnd(nsIDOMCSSValue
** aValue
);
305 nsresult
GetMarkerMid(nsIDOMCSSValue
** aValue
);
306 nsresult
GetMarkerStart(nsIDOMCSSValue
** aValue
);
307 nsresult
GetStrokeDasharray(nsIDOMCSSValue
** aValue
);
309 nsresult
GetStrokeDashoffset(nsIDOMCSSValue
** aValue
);
310 nsresult
GetStrokeWidth(nsIDOMCSSValue
** aValue
);
312 nsresult
GetFillOpacity(nsIDOMCSSValue
** aValue
);
313 nsresult
GetFloodOpacity(nsIDOMCSSValue
** aValue
);
314 nsresult
GetStopOpacity(nsIDOMCSSValue
** aValue
);
315 nsresult
GetStrokeMiterlimit(nsIDOMCSSValue
** aValue
);
316 nsresult
GetStrokeOpacity(nsIDOMCSSValue
** aValue
);
318 nsresult
GetClipRule(nsIDOMCSSValue
** aValue
);
319 nsresult
GetFillRule(nsIDOMCSSValue
** aValue
);
320 nsresult
GetStrokeLinecap(nsIDOMCSSValue
** aValue
);
321 nsresult
GetStrokeLinejoin(nsIDOMCSSValue
** aValue
);
322 nsresult
GetTextAnchor(nsIDOMCSSValue
** aValue
);
324 nsresult
GetColorInterpolation(nsIDOMCSSValue
** aValue
);
325 nsresult
GetColorInterpolationFilters(nsIDOMCSSValue
** aValue
);
326 nsresult
GetDominantBaseline(nsIDOMCSSValue
** aValue
);
327 nsresult
GetPointerEvents(nsIDOMCSSValue
** aValue
);
328 nsresult
GetShapeRendering(nsIDOMCSSValue
** aValue
);
329 nsresult
GetTextRendering(nsIDOMCSSValue
** aValue
);
331 nsresult
GetFloodColor(nsIDOMCSSValue
** aValue
);
332 nsresult
GetLightingColor(nsIDOMCSSValue
** aValue
);
333 nsresult
GetStopColor(nsIDOMCSSValue
** aValue
);
335 nsresult
GetClipPath(nsIDOMCSSValue
** aValue
);
336 nsresult
GetFilter(nsIDOMCSSValue
** aValue
);
337 nsresult
GetMask(nsIDOMCSSValue
** aValue
);
340 nsROCSSPrimitiveValue
* GetROCSSPrimitiveValue();
341 nsDOMCSSValueList
* GetROCSSValueList(PRBool aCommaDelimited
);
342 nsresult
SetToRGBAColor(nsROCSSPrimitiveValue
* aValue
, nscolor aColor
);
345 * A method to get a percentage base for a percentage value. Returns PR_TRUE
346 * if a percentage base value was determined, PR_FALSE otherwise.
348 typedef PRBool (nsComputedDOMStyle::*PercentageBaseGetter
)(nscoord
&);
351 * Method to set aValue to aCoord. If aCoord is a percentage value and
352 * aPercentageBaseGetter is not null, aPercentageBaseGetter is called. If it
353 * returns PR_TRUE, the percentage base it outputs in its out param is used
354 * to compute an nscoord value. If the getter is null or returns PR_FALSE,
355 * the percent value of aCoord is set as a percent value on aValue. aTable,
356 * if not null, is the keyword table to handle eStyleUnit_Enumerated. When
357 * calling SetAppUnits on aValue (for coord or percent values), the value
358 * passed in will be PR_MAX of the value in aMinAppUnits and the PR_MIN of
359 * the actual value in aCoord and the value in aMaxAppUnits.
361 * XXXbz should caller pass in some sort of bitfield indicating which units
362 * can be expected or something?
364 void SetValueToCoord(nsROCSSPrimitiveValue
* aValue
,
365 const nsStyleCoord
& aCoord
,
366 PercentageBaseGetter aPercentageBaseGetter
= nsnull
,
367 const PRInt32 aTable
[] = nsnull
,
368 nscoord aMinAppUnits
= nscoord_MIN
,
369 nscoord aMaxAppUnits
= nscoord_MAX
);
372 * If aCoord is a eStyleUnit_Coord returns the nscoord. If it's
373 * eStyleUnit_Percent, attempts to resolve the percentage base and returns
374 * the resulting nscoord. If it's some other unit or a percentge base can't
375 * be determined, returns aDefaultValue.
377 nscoord
StyleCoordToNSCoord(const nsStyleCoord
& aCoord
,
378 PercentageBaseGetter aPercentageBaseGetter
,
379 nscoord aDefaultValue
);
381 PRBool
GetCBContentWidth(nscoord
& aWidth
);
382 PRBool
GetCBContentHeight(nscoord
& aWidth
);
383 PRBool
GetFrameBoundsWidthForTransform(nscoord
&aWidth
);
384 PRBool
GetFrameBoundsHeightForTransform(nscoord
&aHeight
);
385 PRBool
GetFrameBorderRectWidth(nscoord
& aWidth
);
387 struct ComputedStyleMapEntry
389 // Create a pointer-to-member-function type.
390 typedef nsresult (nsComputedDOMStyle::*ComputeMethod
)(nsIDOMCSSValue
**);
392 nsCSSProperty mProperty
;
393 ComputeMethod mGetter
;
396 static const ComputedStyleMapEntry
* GetQueryablePropertyMap(PRUint32
* aLength
);
398 CSS2PropertiesTearoff mInner
;
400 // We don't really have a good immutable representation of "presentation".
401 // Given the way GetComputedStyle is currently used, we should just grab the
402 // 0th presshell, if any, from the document.
403 nsWeakPtr mDocumentWeak
;
404 nsCOMPtr
<nsIContent
> mContent
;
407 * Strong reference to the style context while we're accessing the data from
408 * it. This can be either a style context we resolved ourselves or a style
409 * context we got from our frame.
411 nsRefPtr
<nsStyleContext
> mStyleContextHolder
;
412 nsCOMPtr
<nsIAtom
> mPseudo
;
415 * While computing style data, the primary frame for mContent --- named "outer"
416 * because we should use it to compute positioning data. Null
419 nsIFrame
* mOuterFrame
;
421 * While computing style data, the "inner frame" for mContent --- the frame
422 * which we should use to compute margin, border, padding and content data. Null
425 nsIFrame
* mInnerFrame
;
427 * While computing style data, the presshell we're working with. Null
430 nsIPresShell
* mPresShell
;
432 PRInt32 mAppUnitsPerInch
; /* For unit conversions */
435 #endif /* nsComputedDOMStyle_h__ */