Back to index

lightning-sunbird  0.9+nobinonly
nsIStyleRuleProcessor.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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsIStyleRuleProcessor_h___
00038 #define nsIStyleRuleProcessor_h___
00039 
00040 #include <stdio.h>
00041 
00042 #include "nsISupports.h"
00043 #include "nsPresContext.h" // for nsCompatability
00044 #include "nsILinkHandler.h"
00045 #include "nsString.h"
00046 #include "nsChangeHint.h"
00047 
00048 class nsIStyleSheet;
00049 class nsPresContext;
00050 class nsIContent;
00051 class nsIStyledContent;
00052 class nsISupportsArray;
00053 class nsIAtom;
00054 class nsICSSPseudoComparator;
00055 class nsRuleWalker;
00056 
00057 // The implementation of the constructor and destructor are currently in
00058 // nsCSSStyleSheet.cpp.
00059 
00060 struct RuleProcessorData {
00061   RuleProcessorData(nsPresContext* aPresContext,
00062                     nsIContent* aContent, 
00063                     nsRuleWalker* aRuleWalker,
00064                     nsCompatibility* aCompat = nsnull);
00065   
00066   // NOTE: not |virtual|
00067   ~RuleProcessorData();
00068 
00069   void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
00070     return aContext->AllocateFromShell(sz);
00071   }
00072   void Destroy(nsPresContext* aContext) {
00073     this->~RuleProcessorData();
00074     aContext->FreeToShell(sizeof(RuleProcessorData), this);
00075   };
00076 
00077   const nsString* GetLang();
00078 
00079   nsPresContext*   mPresContext;
00080   nsIContent*       mContent;       // weak ref
00081   nsIContent*       mParentContent; // if content, content->GetParent(); weak ref
00082   nsRuleWalker*     mRuleWalker; // Used to add rules to our results.
00083   nsIContent*       mScopedRoot;    // Root of scoped stylesheet (set and unset by the supplier of the scoped stylesheet
00084   
00085   nsIAtom*          mContentTag;    // if content, then content->GetTag()
00086   nsIAtom*          mContentID;     // if styled content, then weak reference to styledcontent->GetID()
00087   nsIStyledContent* mStyledContent; // if content, content->QI(nsIStyledContent)
00088   PRPackedBool      mIsHTMLContent; // if content, then does QI on HTMLContent, true or false
00089   PRPackedBool      mIsHTMLLink;    // if content, calls nsStyleUtil::IsHTMLLink
00090   PRPackedBool      mIsSimpleXLink; // if content, calls nsStyleUtil::IsSimpleXLink
00091   nsCompatibility   mCompatMode;    // Possibly remove use of this in SelectorMatches?
00092   PRPackedBool      mHasAttributes; // if content, content->GetAttrCount() > 0
00093   nsLinkState       mLinkState;     // if a link, this is the state, otherwise unknown
00094   PRInt32           mEventState;    // if content, eventStateMgr->GetContentState()
00095   PRInt32           mNameSpaceID;   // if content, content->GetNameSapce()
00096   // mPreviousSiblingData and mParentData are always RuleProcessorData
00097   // and never a derived class.  They are allocated lazily, when
00098   // selectors require matching of prior siblings or ancestors.
00099   RuleProcessorData* mPreviousSiblingData;
00100   RuleProcessorData* mParentData;
00101 
00102 protected:
00103   nsAutoString *mLanguage; // NULL means we haven't found out the language yet
00104 };
00105 
00106 struct ElementRuleProcessorData : public RuleProcessorData {
00107   ElementRuleProcessorData(nsPresContext* aPresContext,
00108                            nsIContent* aContent, 
00109                            nsRuleWalker* aRuleWalker)
00110   : RuleProcessorData(aPresContext,aContent,aRuleWalker)
00111   {
00112     NS_PRECONDITION(aContent, "null pointer");
00113     NS_PRECONDITION(aRuleWalker, "null pointer");
00114   }
00115 };
00116 
00117 struct PseudoRuleProcessorData : public RuleProcessorData {
00118   PseudoRuleProcessorData(nsPresContext* aPresContext,
00119                           nsIContent* aParentContent,
00120                           nsIAtom* aPseudoTag,
00121                           nsICSSPseudoComparator* aComparator,
00122                           nsRuleWalker* aRuleWalker)
00123   : RuleProcessorData(aPresContext, aParentContent, aRuleWalker)
00124   {
00125     NS_PRECONDITION(aPseudoTag, "null pointer");
00126     NS_PRECONDITION(aRuleWalker, "null pointer");
00127     mPseudoTag = aPseudoTag;
00128     mComparator = aComparator;
00129   }
00130 
00131   nsIAtom*                 mPseudoTag;
00132   nsICSSPseudoComparator*  mComparator;
00133 };
00134 
00135 struct StateRuleProcessorData : public RuleProcessorData {
00136   StateRuleProcessorData(nsPresContext* aPresContext,
00137                          nsIContent* aContent,
00138                          PRInt32 aStateMask)
00139     : RuleProcessorData(aPresContext, aContent, nsnull),
00140       mStateMask(aStateMask)
00141   {
00142     NS_PRECONDITION(aContent, "null pointer");
00143   }
00144   const PRInt32 mStateMask; // |HasStateDependentStyle| for which state(s)?
00145                             //  Constants defined in nsIEventStateManager.h .
00146 };
00147 
00148 struct AttributeRuleProcessorData : public RuleProcessorData {
00149   AttributeRuleProcessorData(nsPresContext* aPresContext,
00150                          nsIContent* aContent,
00151                          nsIAtom* aAttribute,
00152                          PRInt32 aModType)
00153     : RuleProcessorData(aPresContext, aContent, nsnull),
00154       mAttribute(aAttribute),
00155       mModType(aModType)
00156   {
00157     NS_PRECONDITION(aContent, "null pointer");
00158   }
00159   nsIAtom* mAttribute; // |HasAttributeDependentStyle| for which attribute?
00160   PRInt32 mModType;    // The type of modification (see nsIDOMMutationEvent).
00161 };
00162 
00163 
00164 // IID for the nsIStyleRuleProcessor interface {015575fe-7b6c-11d3-ba05-001083023c2b}
00165 #define NS_ISTYLE_RULE_PROCESSOR_IID     \
00166 {0x015575fe, 0x7b6c, 0x11d3, {0xba, 0x05, 0x00, 0x10, 0x83, 0x02, 0x3c, 0x2b}}
00167 
00168 /* The style rule processor interface is a mechanism to separate the matching
00169  * of style rules from style sheet instances.
00170  * Simple style sheets can and will act as their own processor. 
00171  * Sheets where rule ordering interlaces between multiple sheets, will need to 
00172  * share a single rule processor between them (CSS sheets do this for cascading order)
00173  *
00174  * @see nsIStyleRule (for significantly more detailed comments)
00175  */
00176 class nsIStyleRuleProcessor : public nsISupports {
00177 public:
00178   NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_PROCESSOR_IID)
00179 
00180   // Shorthand for:
00181   //  nsCOMArray<nsIStyleRuleProcessor>::nsCOMArrayEnumFunc
00182   typedef PRBool (* PR_CALLBACK EnumFunc)(nsIStyleRuleProcessor*, void*);
00183 
00190   NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData) = 0;
00191 
00196   NS_IMETHOD RulesMatching(PseudoRuleProcessorData* aData) = 0;
00197 
00206   NS_IMETHOD HasStateDependentStyle(StateRuleProcessorData* aData,
00207                                     nsReStyleHint* aResult) = 0;
00208 
00215   NS_IMETHOD HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
00216                                         nsReStyleHint* aResult) = 0;
00217 };
00218 
00219 #endif /* nsIStyleRuleProcessor_h___ */