Back to index

lightning-sunbird  0.9+nobinonly
nsStyleContext.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  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   David Hyatt <hyatt@netscape.com>
00024  *   Pierre Phaneuf <pp@ludusdesign.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef _nsStyleContext_h_
00041 #define _nsStyleContext_h_
00042 
00043 #include "nsRuleNode.h"
00044 #include "nsIAtom.h"
00045 
00046 class nsPresContext;
00047 
00070 class nsStyleContext
00071 {
00072 public:
00073   nsStyleContext(nsStyleContext* aParent, nsIAtom* aPseudoTag, 
00074                  nsRuleNode* aRuleNode, nsPresContext* aPresContext) NS_HIDDEN;
00075   ~nsStyleContext() NS_HIDDEN;
00076 
00077   NS_HIDDEN_(void*) operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW;
00078   NS_HIDDEN_(void) Destroy();
00079 
00080   nsrefcnt AddRef() {
00081     ++mRefCnt;
00082     NS_LOG_ADDREF(this, mRefCnt, "nsStyleContext", sizeof(nsStyleContext));
00083     return mRefCnt;
00084   }
00085 
00086   nsrefcnt Release() {
00087     --mRefCnt;
00088     NS_LOG_RELEASE(this, mRefCnt, "nsStyleContext");
00089     if (mRefCnt == 0) {
00090       Destroy();
00091       return 0;
00092     }
00093     return mRefCnt;
00094   }
00095 
00096   nsPresContext* PresContext() const { return mRuleNode->GetPresContext(); }
00097 
00098   nsStyleContext* GetParent() const { return mParent; }
00099 
00100   nsStyleContext* GetFirstChild() const { return mChild; }
00101 
00102   nsIAtom* GetPseudoType() const { return mPseudoTag; }
00103 
00104   NS_HIDDEN_(already_AddRefed<nsStyleContext>)
00105   FindChildWithRules(const nsIAtom* aPseudoTag, nsRuleNode* aRules);
00106 
00107   NS_HIDDEN_(PRBool)    Equals(const nsStyleContext* aOther) const;
00108   PRBool    HasTextDecorations() { return mBits & NS_STYLE_HAS_TEXT_DECORATIONS; };
00109 
00110   NS_HIDDEN_(void) GetBorderPaddingFor(nsStyleBorderPadding& aBorderPadding);
00111 
00112   NS_HIDDEN_(void) SetStyle(nsStyleStructID aSID, nsStyleStruct* aStruct);
00113 
00114   nsRuleNode* GetRuleNode() { return mRuleNode; }
00115   void AddStyleBit(const PRUint32& aBit) { mBits |= aBit; }
00116 
00117   /*
00118    * Mark this style context's rule node (and its ancestors) to prevent
00119    * it from being garbage collected.
00120    */
00121   NS_HIDDEN_(void) Mark();
00122 
00123   /*
00124    * Get the style data for a style struct.  This is the most important
00125    * member function of nsIStyleContext.  It fills in a const pointer
00126    * to a style data struct that is appropriate for the style context's
00127    * frame.  This struct may be shared with other contexts (either in
00128    * the rule tree or the style context tree), so it should not be
00129    * modified.
00130    *
00131    * This function will NOT return null (even when out of memory) when
00132    * given a valid style struct ID, so the result does not need to be
00133    * null-checked.
00134    *
00135    * The typesafe functions below are preferred to the use of this
00136    * function.
00137    *
00138    * See also |nsIFrame::GetStyleData| and the other global
00139    * |GetStyleData| in nsIFrame.h.
00140    */
00141   NS_HIDDEN_(const nsStyleStruct*) NS_FASTCALL GetStyleData(nsStyleStructID aSID);
00142 
00151   #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_)                      \
00152     const nsStyle##name_ * GetStyle##name_() {                                \
00153       return NS_STATIC_CAST(const nsStyle##name_*,                            \
00154                             GetStyleData(eStyleStruct_##name_));              \
00155     }
00156   #include "nsStyleStructList.h"
00157   #undef STYLE_STRUCT
00158 
00159 
00160   NS_HIDDEN_(const nsStyleStruct*) PeekStyleData(nsStyleStructID aSID);
00161 
00162   NS_HIDDEN_(nsStyleStruct*) GetUniqueStyleData(const nsStyleStructID& aSID);
00163 
00164   NS_HIDDEN_(void) ClearStyleData(nsPresContext* aPresContext);
00165 
00166   NS_HIDDEN_(nsChangeHint) CalcStyleDifference(nsStyleContext* aOther);
00167 
00168 #ifdef DEBUG
00169   NS_HIDDEN_(void) DumpRegressionData(nsPresContext* aPresContext, FILE* out,
00170                                       PRInt32 aIndent);
00171 
00172   NS_HIDDEN_(void) List(FILE* out, PRInt32 aIndent);
00173 #endif
00174 
00175 protected:
00176   NS_HIDDEN_(void) AppendChild(nsStyleContext* aChild);
00177   NS_HIDDEN_(void) RemoveChild(nsStyleContext* aChild);
00178 
00179   NS_HIDDEN_(void) ApplyStyleFixups(nsPresContext* aPresContext);
00180 
00181   nsStyleContext* mParent;
00182 
00183   // children are maintained in two circular doubly-linked lists,
00184   // mEmptyChild for children whose rule node is the root rule node, and
00185   // mChild for other children.  The order of children is not
00186   // meaningful.
00187   nsStyleContext* mChild;
00188   nsStyleContext* mEmptyChild;
00189   nsStyleContext* mPrevSibling;
00190   nsStyleContext* mNextSibling;
00191 
00192   // If this style context is for a pseudo-element, the pseudo-element
00193   // atom.  Otherwise, null.
00194   nsCOMPtr<nsIAtom> mPseudoTag;
00195 
00196   // The rule node is the node in the lexicographic tree of rule nodes
00197   // (the "rule tree") that indicates which style rules are used to
00198   // compute the style data, and in what cascading order.  The least
00199   // specific rule matched is the one whose rule node is a child of the
00200   // root of the rule tree, and the most specific rule matched is the
00201   // |mRule| member of |mRuleNode|.
00202   nsRuleNode* const       mRuleNode;
00203 
00204   // |mCachedStyleData| points to both structs that are owned by this
00205   // style context and structs that are owned by one of this style
00206   // context's ancestors (which are indirectly owned since this style
00207   // context owns a reference to its parent).  If the bit in |mBits| is
00208   // set for a struct, that means that the pointer for that struct is
00209   // owned by an ancestor rather than by this style context.
00210   nsCachedStyleData       mCachedStyleData; // Our cached style data.
00211   PRUint32                mBits; // Which structs are inherited from the
00212                                  // parent context.
00213   PRUint32                mRefCnt;
00214 };
00215 
00216 NS_HIDDEN_(already_AddRefed<nsStyleContext>)
00217 NS_NewStyleContext(nsStyleContext* aParentContext,
00218                    nsIAtom* aPseudoTag,
00219                    nsRuleNode* aRuleNode,
00220                    nsPresContext* aPresContext);
00221 #endif