Back to index

lightning-sunbird  0.9+nobinonly
nsComputedDOMStyle.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Christopher A. Aillon <christopher@aillon.com>
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Christopher A. Aillon <christopher@aillon.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsComputedDOMStyle_h__
00040 #define nsComputedDOMStyle_h__
00041 
00042 #include "nsIComputedDOMStyle.h"
00043 
00044 #include "nsROCSSPrimitiveValue.h"
00045 #include "nsDOMCSSDeclaration.h"
00046 #include "nsDOMCSSRGBColor.h"
00047 #include "nsDOMCSSValueList.h"
00048 #include "nsCSSProps.h"
00049 
00050 #include "nsIPresShell.h"
00051 #include "nsIContent.h"
00052 #include "nsIFrame.h"
00053 #include "nsCOMPtr.h"
00054 #include "nsWeakReference.h"
00055 #include "nsAutoPtr.h"
00056 
00057 class nsComputedDOMStyle : public nsIComputedDOMStyle
00058 {
00059 public:
00060   NS_DECL_ISUPPORTS
00061 
00062   NS_IMETHOD Init(nsIDOMElement *aElement,
00063                   const nsAString& aPseudoElt,
00064                   nsIPresShell *aPresShell);
00065 
00066   NS_DECL_NSICSSDECLARATION
00067 
00068   NS_DECL_NSIDOMCSSSTYLEDECLARATION
00069 
00070   nsComputedDOMStyle();
00071   virtual ~nsComputedDOMStyle();
00072 
00073   static void Shutdown();
00074 
00075 private:
00076   void FlushPendingReflows();
00077   
00078   nsresult GetStyleData(nsStyleStructID aID,
00079                         const nsStyleStruct*& aStyleStruct,
00080                         nsIFrame* aFrame=0);
00081 
00082   nsresult GetOffsetWidthFor(PRUint8 aSide,
00083                              nsIFrame *aFrame,
00084                              nsIDOMCSSValue** aValue);
00085 
00086   nsresult GetAbsoluteOffset(PRUint8 aSide,
00087                              nsIFrame *aFrame,
00088                              nsIDOMCSSValue** aValue);
00089 
00090   nsresult GetRelativeOffset(PRUint8 aSide,
00091                              nsIFrame *aFrame,
00092                              nsIDOMCSSValue** aValue);
00093 
00094   nsresult GetStaticOffset(PRUint8 aSide,
00095                            nsIFrame *aFrame,
00096                            nsIDOMCSSValue** aValue);
00097 
00098   nsresult GetPaddingWidthFor(PRUint8 aSide,
00099                               nsIFrame *aFrame,
00100                               nsIDOMCSSValue** aValue);
00101 
00102   nscoord GetPaddingWidthCoordFor(PRUint8 aSide,
00103                                   nsIFrame *aFrame);
00104 
00105   nsresult GetBorderColorsFor(PRUint8 aSide,
00106                               nsIFrame *aFrame,
00107                               nsIDOMCSSValue** aValue);
00108 
00109   nsresult GetBorderStyleFor(PRUint8 aSide,
00110                              nsIFrame *aFrame,
00111                              nsIDOMCSSValue** aValue);
00112 
00113   nsresult GetBorderRadiusFor(PRUint8 aSide,
00114                               nsIFrame *aFrame,
00115                               nsIDOMCSSValue** aValue);
00116 
00117   nsresult GetBorderWidthFor(PRUint8 aSide,
00118                              nsIFrame *aFrame,
00119                              nsIDOMCSSValue** aValue);
00120 
00121   nscoord GetBorderWidthCoordFor(PRUint8 aSide,
00122                                  nsIFrame *aFrame);
00123 
00124   nsresult GetBorderColorFor(PRUint8 aSide,
00125                              nsIFrame *aFrame,
00126                              nsIDOMCSSValue** aValue);
00127 
00128   nsresult GetOutlineRadiusFor(PRUint8 aSide,
00129                               nsIFrame *aFrame,
00130                               nsIDOMCSSValue** aValue);
00131 
00132   nsresult GetMarginWidthFor(PRUint8 aSide,
00133                              nsIFrame *aFrame,
00134                              nsIDOMCSSValue** aValue);
00135 
00136   nscoord GetMarginWidthCoordFor(PRUint8 aSide,
00137                                  nsIFrame *aFrame);
00138 
00139   nsresult GetLineHeightCoord(nsIFrame *aFrame,
00140                               const nsStyleText *aText,
00141                               nscoord& aCoord);
00142 
00143   /* Properties Queryable as CSSValues */
00144 
00145   nsresult GetAppearance(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00146 
00147   /* Box properties */
00148   nsresult GetBoxAlign(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00149   nsresult GetBoxDirection(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00150   nsresult GetBoxFlex(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00151   nsresult GetBoxOrdinalGroup(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00152   nsresult GetBoxOrient(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00153   nsresult GetBoxPack(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00154   nsresult GetBoxSizing(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00155 
00156   nsresult GetWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00157   nsresult GetHeight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00158   nsresult GetMaxHeight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00159   nsresult GetMaxWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00160   nsresult GetMinHeight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00161   nsresult GetMinWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00162   nsresult GetLeft(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00163   nsresult GetTop(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00164   nsresult GetRight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00165   nsresult GetBottom(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00166 
00167   /* Font properties */
00168   nsresult GetColor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00169   nsresult GetFontFamily(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00170   nsresult GetFontStyle(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00171   nsresult GetFontSize(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00172   nsresult GetFontSizeAdjust(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00173   nsresult GetFontWeight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00174   nsresult GetFontVariant(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00175 
00176   /* Background properties */
00177   nsresult GetBackgroundAttachment(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00178   nsresult GetBackgroundColor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00179   nsresult GetBackgroundImage(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00180   nsresult GetBackgroundRepeat(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00181   nsresult GetBackgroundClip(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00182   nsresult GetBackgroundInlinePolicy(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00183   nsresult GetBackgroundOrigin(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00184 
00185   /* Padding properties */
00186   nsresult GetPadding(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00187   nsresult GetPaddingTop(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00188   nsresult GetPaddingBottom(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00189   nsresult GetPaddingLeft(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00190   nsresult GetPaddingRight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00191 
00192   /* Table Properties */
00193   nsresult GetBorderCollapse(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00194   nsresult GetBorderSpacing(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00195   nsresult GetCaptionSide(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00196   nsresult GetEmptyCells(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00197   nsresult GetTableLayout(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00198   nsresult GetVerticalAlign(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00199 
00200   /* Border Properties */
00201   nsresult GetBorderStyle(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00202   nsresult GetBorderWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00203   nsresult GetBorderTopStyle(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00204   nsresult GetBorderBottomStyle(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00205   nsresult GetBorderLeftStyle(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00206   nsresult GetBorderRightStyle(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00207   nsresult GetBorderTopWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00208   nsresult GetBorderBottomWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00209   nsresult GetBorderLeftWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00210   nsresult GetBorderRightWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00211   nsresult GetBorderTopColor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00212   nsresult GetBorderBottomColor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00213   nsresult GetBorderLeftColor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00214   nsresult GetBorderRightColor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00215   nsresult GetBorderBottomColors(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00216   nsresult GetBorderLeftColors(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00217   nsresult GetBorderRightColors(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00218   nsresult GetBorderTopColors(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00219   nsresult GetBorderRadiusBottomLeft(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00220   nsresult GetBorderRadiusBottomRight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00221   nsresult GetBorderRadiusTopLeft(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00222   nsresult GetBorderRadiusTopRight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00223   nsresult GetFloatEdge(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00224 
00225   /* Margin Properties */
00226   nsresult GetMarginWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00227   nsresult GetMarginTopWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00228   nsresult GetMarginBottomWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00229   nsresult GetMarginLeftWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00230   nsresult GetMarginRightWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00231 
00232   /* Outline Properties */
00233   nsresult GetOutline(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00234   nsresult GetOutlineWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00235   nsresult GetOutlineStyle(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00236   nsresult GetOutlineColor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00237   nsresult GetOutlineOffset(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00238   nsresult GetOutlineRadiusBottomLeft(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00239   nsresult GetOutlineRadiusBottomRight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00240   nsresult GetOutlineRadiusTopLeft(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00241   nsresult GetOutlineRadiusTopRight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00242 
00243   /* Content Properties */
00244   nsresult GetCounterIncrement(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00245   nsresult GetCounterReset(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00246   nsresult GetMarkerOffset(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00247 
00248   /* z-index */
00249   nsresult GetZIndex(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00250 
00251   /* List properties */
00252   nsresult GetListStyleImage(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00253   nsresult GetListStylePosition(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00254   nsresult GetListStyleType(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00255   nsresult GetImageRegion(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00256 
00257   /* Text Properties */
00258   nsresult GetLineHeight(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00259   nsresult GetTextAlign(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00260   nsresult GetTextDecoration(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00261   nsresult GetTextIndent(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00262   nsresult GetTextTransform(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00263   nsresult GetLetterSpacing(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00264   nsresult GetWordSpacing(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00265   nsresult GetWhiteSpace(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00266 
00267   /* Visibility properties */
00268   nsresult GetOpacity(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00269   nsresult GetVisibility(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00270 
00271   /* Direction properties */
00272   nsresult GetDirection(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00273   nsresult GetUnicodeBidi(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00274 
00275   /* Display properties */
00276   nsresult GetBinding(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00277   nsresult GetClear(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00278   nsresult GetCssFloat(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00279   nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00280   nsresult GetPosition(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00281   nsresult GetClip(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00282   nsresult GetOverflow(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00283   nsresult GetOverflowX(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00284   nsresult GetOverflowY(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00285 
00286   /* User interface properties */
00287   nsresult GetCursor(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00288   nsresult GetUserFocus(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00289   nsresult GetUserInput(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00290   nsresult GetUserModify(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00291   nsresult GetUserSelect(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00292 
00293   /* Column properties */
00294   nsresult GetColumnCount(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00295   nsresult GetColumnWidth(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00296   nsresult GetColumnGap(nsIFrame *aFrame, nsIDOMCSSValue** aValue);
00297 
00298   nsROCSSPrimitiveValue* GetROCSSPrimitiveValue();
00299   nsDOMCSSValueList* GetROCSSValueList(PRBool aCommaDelimited);
00300   nsDOMCSSRGBColor* GetDOMCSSRGBColor(nscolor aColor);
00301 
00302   struct ComputedStyleMapEntry
00303   {
00304     // Create a pointer-to-member-function type.
00305     typedef nsresult (nsComputedDOMStyle::*ComputeMethod)(nsIFrame*, nsIDOMCSSValue**);
00306 
00307     nsCSSProperty mProperty;
00308     ComputeMethod mGetter;
00309   };
00310 
00311   static const ComputedStyleMapEntry* GetQueryablePropertyMap(PRUint32* aLength);
00312 
00313   CSS2PropertiesTearoff mInner;
00314 
00315   // We don't really have a good immutable representation of "presentation".
00316   // Given the way GetComputedStyle is currently used, we should just grab the
00317   // 0th presshell, if any, from the document.
00318   nsWeakPtr mDocumentWeak;
00319   nsCOMPtr<nsIContent> mContent;
00320 
00321   /*
00322    * When a frame is unavailable, strong reference to the
00323    * style context while we're accessing the data from in.
00324    */
00325   nsRefPtr<nsStyleContext> mStyleContextHolder;
00326   nsCOMPtr<nsIAtom> mPseudo;
00327 
00328   float mT2P; /* For unit conversions */
00329 };
00330 
00331 #endif /* nsComputedDOMStyle_h__ */
00332