2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:tabstop=2:expandtab:shiftwidth=2:
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* representation of a CSS style sheet */
|
|
|
|
|
|
|
|
#ifndef nsCSSStyleSheet_h_
|
|
|
|
#define nsCSSStyleSheet_h_
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
|
|
|
#include "nsICSSLoaderObserver.h"
|
2009-02-03 06:42:18 -08:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
|
|
|
|
class nsIURI;
|
|
|
|
class nsMediaList;
|
2008-07-26 09:14:48 -07:00
|
|
|
class nsMediaQueryResultCacheKey;
|
2008-09-09 11:08:11 -07:00
|
|
|
class nsCSSStyleSheet;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet Inner Data Container
|
|
|
|
//
|
|
|
|
|
|
|
|
class nsCSSStyleSheetInner {
|
|
|
|
public:
|
2010-01-07 05:51:16 -08:00
|
|
|
friend class nsCSSStyleSheet;
|
|
|
|
friend class nsCSSRuleProcessor;
|
|
|
|
friend nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
|
|
|
|
private:
|
2008-09-09 11:32:27 -07:00
|
|
|
nsCSSStyleSheetInner(nsICSSStyleSheet* aPrimarySheet);
|
|
|
|
nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy,
|
|
|
|
nsCSSStyleSheet* aPrimarySheet);
|
2008-10-15 13:24:45 -07:00
|
|
|
~nsCSSStyleSheetInner();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-15 13:24:45 -07:00
|
|
|
nsCSSStyleSheetInner* CloneFor(nsCSSStyleSheet* aPrimarySheet);
|
|
|
|
void AddSheet(nsICSSStyleSheet* aSheet);
|
|
|
|
void RemoveSheet(nsICSSStyleSheet* aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-15 13:24:45 -07:00
|
|
|
void RebuildNameSpaces();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-15 13:23:21 -07:00
|
|
|
// Create a new namespace map
|
|
|
|
nsresult CreateNamespaceMap();
|
|
|
|
|
2009-02-03 06:42:18 -08:00
|
|
|
nsAutoTArray<nsICSSStyleSheet*, 8> mSheets;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mSheetURI; // for error reports, etc.
|
2007-10-23 14:56:41 -07:00
|
|
|
nsCOMPtr<nsIURI> mOriginalSheetURI; // for GetHref. Can be null.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mBaseURI; // for resolving relative URIs
|
2007-05-01 12:26:15 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMArray<nsICSSRule> mOrderedRules;
|
|
|
|
nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
|
2008-09-09 11:08:11 -07:00
|
|
|
// Linked list of child sheets. This is al fundamentally broken, because
|
|
|
|
// each of the child sheets has a unique parent... We can only hope (and
|
|
|
|
// currently this is the case) that any time page JS can get ts hands on a
|
|
|
|
// child sheet that means we've already ensured unique inners throughout its
|
|
|
|
// parent chain and things are good.
|
|
|
|
nsRefPtr<nsCSSStyleSheet> mFirstChild;
|
2009-05-13 01:26:48 -07:00
|
|
|
PRBool mComplete;
|
2007-05-01 12:26:15 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool mPrincipalSet;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
|
|
|
|
|
|
|
class CSSRuleListImpl;
|
2008-09-09 11:08:11 -07:00
|
|
|
struct ChildSheetListBuilder;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsCSSStyleSheet : public nsICSSStyleSheet,
|
|
|
|
public nsIDOMCSSStyleSheet,
|
|
|
|
public nsICSSLoaderObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsCSSStyleSheet();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleSheet interface
|
|
|
|
NS_IMETHOD GetSheetURI(nsIURI** aSheetURI) const;
|
|
|
|
NS_IMETHOD GetBaseURI(nsIURI** aBaseURI) const;
|
|
|
|
NS_IMETHOD GetTitle(nsString& aTitle) const;
|
|
|
|
NS_IMETHOD GetType(nsString& aType) const;
|
|
|
|
NS_IMETHOD_(PRBool) HasRules() const;
|
|
|
|
NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
|
|
|
|
NS_IMETHOD SetEnabled(PRBool aEnabled);
|
|
|
|
NS_IMETHOD GetComplete(PRBool& aComplete) const;
|
|
|
|
NS_IMETHOD SetComplete();
|
|
|
|
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // may be null
|
|
|
|
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const; // may be null
|
|
|
|
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
|
|
|
|
#ifdef DEBUG
|
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// nsICSSStyleSheet interface
|
|
|
|
NS_IMETHOD AppendStyleSheet(nsICSSStyleSheet* aSheet);
|
|
|
|
NS_IMETHOD InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex);
|
|
|
|
NS_IMETHOD PrependStyleRule(nsICSSRule* aRule);
|
|
|
|
NS_IMETHOD AppendStyleRule(nsICSSRule* aRule);
|
|
|
|
NS_IMETHOD ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew);
|
|
|
|
NS_IMETHOD StyleRuleCount(PRInt32& aCount) const;
|
|
|
|
NS_IMETHOD GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
|
|
|
|
NS_IMETHOD DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex);
|
|
|
|
NS_IMETHOD InsertRuleIntoGroup(const nsAString& aRule, nsICSSGroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval);
|
|
|
|
NS_IMETHOD ReplaceRuleInGroup(nsICSSGroupRule* aGroup, nsICSSRule* aOld, nsICSSRule* aNew);
|
|
|
|
NS_IMETHOD StyleSheetCount(PRInt32& aCount) const;
|
|
|
|
NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
|
2007-10-23 14:56:41 -07:00
|
|
|
NS_IMETHOD SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
|
|
|
|
nsIURI* aBaseURI);
|
2007-05-01 12:26:15 -07:00
|
|
|
virtual NS_HIDDEN_(void) SetPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
virtual NS_HIDDEN_(nsIPrincipal*) Principal() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD SetTitle(const nsAString& aTitle);
|
|
|
|
NS_IMETHOD SetMedia(nsMediaList* aMedia);
|
|
|
|
NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode);
|
|
|
|
NS_IMETHOD SetOwnerRule(nsICSSImportRule* aOwnerRule);
|
|
|
|
NS_IMETHOD GetOwnerRule(nsICSSImportRule** aOwnerRule);
|
|
|
|
virtual NS_HIDDEN_(nsXMLNameSpaceMap*) GetNameSpaceMap() const;
|
|
|
|
NS_IMETHOD Clone(nsICSSStyleSheet* aCloneParent,
|
|
|
|
nsICSSImportRule* aCloneOwnerRule,
|
|
|
|
nsIDocument* aCloneDocument,
|
|
|
|
nsIDOMNode* aCloneOwningNode,
|
|
|
|
nsICSSStyleSheet** aClone) const;
|
|
|
|
NS_IMETHOD IsModified(PRBool* aSheetModified) const;
|
|
|
|
NS_IMETHOD SetModified(PRBool aModified);
|
|
|
|
NS_IMETHOD AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
|
|
|
|
NS_IMETHOD DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
|
2008-01-17 21:23:44 -08:00
|
|
|
NS_IMETHOD InsertRuleInternal(const nsAString& aRule,
|
2009-03-10 06:52:23 -07:00
|
|
|
PRUint32 aIndex, PRUint32* aReturn);
|
|
|
|
NS_IMETHOD_(nsIURI*) GetOriginalURI() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsICSSLoaderObserver interface
|
|
|
|
NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
|
|
|
|
nsresult aStatus);
|
2009-12-31 07:56:33 -08:00
|
|
|
|
|
|
|
enum EnsureUniqueInnerResult {
|
|
|
|
// No work was needed to ensure a unique inner.
|
|
|
|
eUniqueInner_AlreadyUnique,
|
|
|
|
// A clone was done to ensure a unique inner (which means the style
|
|
|
|
// rules in this sheet have changed).
|
|
|
|
eUniqueInner_ClonedInner,
|
|
|
|
// A clone was attempted, but it failed.
|
|
|
|
eUniqueInner_CloneFailed
|
|
|
|
};
|
|
|
|
EnsureUniqueInnerResult EnsureUniqueInner();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-31 07:56:33 -08:00
|
|
|
// Append all of this sheet's child sheets to aArray. Return PR_TRUE
|
|
|
|
// on success and PR_FALSE on allocation failure.
|
|
|
|
PRBool AppendAllChildSheets(nsTArray<nsCSSStyleSheet*>& aArray);
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
PRBool UseForPresentation(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey) const;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_DECL_NSIDOMSTYLESHEET
|
|
|
|
|
|
|
|
// nsIDOMCSSStyleSheet interface
|
|
|
|
NS_DECL_NSIDOMCSSSTYLESHEET
|
|
|
|
|
2009-05-26 12:40:49 -07:00
|
|
|
// Function used as a callback to rebuild our inner's child sheet
|
|
|
|
// list after we clone a unique inner for ourselves.
|
|
|
|
static PRBool RebuildChildList(nsICSSRule* aRule, void* aBuilder);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
|
|
|
|
nsICSSStyleSheet* aParentToUse,
|
|
|
|
nsICSSImportRule* aOwnerRuleToUse,
|
|
|
|
nsIDocument* aDocumentToUse,
|
|
|
|
nsIDOMNode* aOwningNodeToUse);
|
|
|
|
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
nsCSSStyleSheet(const nsCSSStyleSheet& aCopy);
|
|
|
|
nsCSSStyleSheet& operator=(const nsCSSStyleSheet& aCopy);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsCSSStyleSheet();
|
|
|
|
|
|
|
|
void ClearRuleCascades();
|
|
|
|
|
|
|
|
nsresult WillDirty();
|
|
|
|
void DidDirty();
|
|
|
|
|
2007-07-03 11:45:39 -07:00
|
|
|
// Return success if the subject principal subsumes the principal of our
|
|
|
|
// inner, error otherwise. This will also succeed if the subject has
|
|
|
|
// UniversalBrowserWrite.
|
|
|
|
nsresult SubjectSubsumesInnerPrincipal() const;
|
|
|
|
|
2008-10-15 13:23:21 -07:00
|
|
|
// Add the namespace mapping from this @namespace rule to our namespace map
|
|
|
|
nsresult RegisterNamespaceRule(nsICSSRule* aRule);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
nsString mTitle;
|
|
|
|
nsCOMPtr<nsMediaList> mMedia;
|
2008-09-09 11:08:11 -07:00
|
|
|
nsRefPtr<nsCSSStyleSheet> mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsICSSStyleSheet* mParent; // weak ref
|
|
|
|
nsICSSImportRule* mOwnerRule; // weak ref
|
|
|
|
|
|
|
|
CSSRuleListImpl* mRuleCollection;
|
|
|
|
nsIDocument* mDocument; // weak ref; parents maintain this for their children
|
|
|
|
nsIDOMNode* mOwningNode; // weak ref
|
|
|
|
PRPackedBool mDisabled;
|
|
|
|
PRPackedBool mDirty; // has been modified
|
|
|
|
|
|
|
|
nsCSSStyleSheetInner* mInner;
|
|
|
|
|
2009-02-03 06:42:18 -08:00
|
|
|
nsAutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
friend class nsMediaList;
|
2008-10-07 15:10:19 -07:00
|
|
|
friend class nsCSSRuleProcessor;
|
2007-05-01 12:26:15 -07:00
|
|
|
friend nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
|
2008-09-09 11:08:11 -07:00
|
|
|
friend struct ChildSheetListBuilder;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsCSSStyleSheet_h_) */
|