2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-05-19 03:15:10 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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/
|
1999-05-19 03:15:10 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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.
|
1999-05-19 03:15:10 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* loading of CSS style sheets using the network APIs */
|
|
|
|
|
1999-05-19 03:15:10 +04:00
|
|
|
#ifndef nsICSSLoader_h___
|
|
|
|
#define nsICSSLoader_h___
|
|
|
|
|
|
|
|
#include "nsISupports.h"
|
2005-03-30 04:36:57 +04:00
|
|
|
#include "nsSubstring.h"
|
2002-06-26 01:16:17 +04:00
|
|
|
#include "nsCompatibility.h"
|
1999-05-19 03:15:10 +04:00
|
|
|
|
|
|
|
class nsIAtom;
|
1999-06-23 07:29:44 +04:00
|
|
|
class nsIURI;
|
1999-05-19 03:15:10 +04:00
|
|
|
class nsICSSParser;
|
|
|
|
class nsICSSStyleSheet;
|
2004-08-01 03:15:21 +04:00
|
|
|
class nsPresContext;
|
1999-05-27 03:51:25 +04:00
|
|
|
class nsIContent;
|
1999-05-19 03:15:10 +04:00
|
|
|
class nsIDocument;
|
|
|
|
class nsIUnicharInputStream;
|
1999-12-04 04:27:14 +03:00
|
|
|
class nsICSSLoaderObserver;
|
2005-03-30 04:36:57 +04:00
|
|
|
class nsMediaList;
|
2005-04-14 19:27:16 +04:00
|
|
|
class nsICSSImportRule;
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
// IID for the nsICSSLoader interface
|
2007-04-21 02:59:18 +04:00
|
|
|
// 5da3a869-270c-4f10-97d1-99eaa150eb4e
|
1999-05-19 03:15:10 +04:00
|
|
|
#define NS_ICSS_LOADER_IID \
|
2007-04-21 02:59:18 +04:00
|
|
|
{ 0x5da3a869, 0x270c, 0x4f10, \
|
|
|
|
{ 0x97, 0xd1, 0x99, 0xea, 0xa1, 0x50, 0xeb, 0x4e } }
|
1999-05-19 03:15:10 +04:00
|
|
|
|
1999-12-04 04:27:14 +03:00
|
|
|
typedef void (*nsCSSLoaderCallbackFunc)(nsICSSStyleSheet* aSheet, void *aData, PRBool aDidNotify);
|
1999-05-27 03:51:25 +04:00
|
|
|
|
1999-05-19 03:15:10 +04:00
|
|
|
class nsICSSLoader : public nsISupports {
|
|
|
|
public:
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_LOADER_IID)
|
1999-05-19 03:15:10 +04:00
|
|
|
|
|
|
|
NS_IMETHOD Init(nsIDocument* aDocument) = 0;
|
1999-05-27 03:51:25 +04:00
|
|
|
NS_IMETHOD DropDocumentReference(void) = 0; // notification that doc is going away
|
1999-05-19 03:15:10 +04:00
|
|
|
|
|
|
|
NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive) = 0;
|
2002-06-26 01:16:17 +04:00
|
|
|
NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode) = 0;
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_IMETHOD SetPreferredSheet(const nsAString& aTitle) = 0;
|
2004-08-05 15:38:42 +04:00
|
|
|
NS_IMETHOD GetPreferredSheet(nsAString& aTitle) = 0;
|
1999-05-19 03:15:10 +04:00
|
|
|
|
1999-05-27 03:51:25 +04:00
|
|
|
// Get/Recycle a CSS parser for general use
|
1999-05-19 03:15:10 +04:00
|
|
|
NS_IMETHOD GetParserFor(nsICSSStyleSheet* aSheet,
|
|
|
|
nsICSSParser** aParser) = 0;
|
|
|
|
NS_IMETHOD RecycleParser(nsICSSParser* aParser) = 0;
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
// XXXbz sort out what the deal is with events! When should they fire?
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
/**
|
|
|
|
* Load an inline style sheet. If a successful result is returned and
|
|
|
|
* *aCompleted is false, then aObserver is guaranteed to be notified
|
|
|
|
* asynchronously once the sheet is marked complete. If an error is
|
|
|
|
* returned, or if *aCompleted is true, aObserver will not be notified. In
|
|
|
|
* addition to parsing the sheet, this method will insert it into the
|
|
|
|
* stylesheet list of this CSSLoader's document.
|
|
|
|
*
|
|
|
|
* @param aElement the element linking to the stylesheet. This must not be
|
|
|
|
* null and must implement nsIStyleSheetLinkingElement.
|
|
|
|
* @param aStream the character stream that holds the stylesheet data.
|
|
|
|
* @param aLineNumber the line number at which the stylesheet data started.
|
|
|
|
* @param aTitle the title of the sheet.
|
|
|
|
* @param aMedia the media string for the sheet.
|
|
|
|
* @param aObserver the observer to notify when the load completes.
|
|
|
|
* May be null.
|
|
|
|
* @param [out] aCompleted whether parsing of the sheet completed.
|
|
|
|
* @param [out] aIsAlternate whether the stylesheet ended up being an
|
|
|
|
* alternate sheet.
|
|
|
|
*/
|
1999-05-27 03:51:25 +04:00
|
|
|
NS_IMETHOD LoadInlineStyle(nsIContent* aElement,
|
2002-12-03 08:48:14 +03:00
|
|
|
nsIUnicharInputStream* aStream,
|
2004-09-09 21:32:35 +04:00
|
|
|
PRUint32 aLineNumber,
|
2005-09-12 22:41:15 +04:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aMedia,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
PRBool* aCompleted,
|
|
|
|
PRBool* aIsAlternate) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a linked (document) stylesheet. If a successful result is returned,
|
|
|
|
* aObserver is guaranteed to be notified asynchronously once the sheet is
|
|
|
|
* loaded and marked complete. If an error is returned, aObserver will not
|
|
|
|
* be notified. In addition to loading the sheet, this method will insert it
|
|
|
|
* into the stylesheet list of this CSSLoader's document.
|
|
|
|
*
|
|
|
|
* @param aElement the element linking to the the stylesheet. May be null.
|
|
|
|
* @param aURL the URL of the sheet.
|
|
|
|
* @param aTitle the title of the sheet.
|
|
|
|
* @param aMedia the media string for the sheet.
|
|
|
|
* @param aHasAlternateRel whether the rel for this link included
|
|
|
|
* "alternate".
|
|
|
|
* @param aObserver the observer to notify when the load completes.
|
|
|
|
* May be null.
|
|
|
|
* @param [out] aIsAlternate whether the stylesheet actually ended up beinga
|
|
|
|
* an alternate sheet. Note that this need not match
|
|
|
|
* aHasAlternateRel.
|
|
|
|
*/
|
1999-05-27 03:51:25 +04:00
|
|
|
NS_IMETHOD LoadStyleLink(nsIContent* aElement,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aURL,
|
2005-09-12 22:41:15 +04:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aMedia,
|
|
|
|
PRBool aHasAlternateRel,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
PRBool* aIsAlternate) = 0;
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
/**
|
|
|
|
* Load a child (@import-ed) style sheet. In addition to loading the sheet,
|
|
|
|
* this method will insert it into the child sheet list of aParentSheet. If
|
|
|
|
* there is no sheet currently being parsed and the child sheet is not
|
|
|
|
* complete when this method returns, then when the child sheet becomes
|
|
|
|
* complete aParentSheet will be QIed to nsICSSLoaderObserver and
|
|
|
|
* asynchronously notified, just like for LoadStyleLink. Note that if the
|
|
|
|
* child sheet is already complete when this method returns, no
|
|
|
|
* nsICSSLoaderObserver notification will be sent.
|
|
|
|
*
|
|
|
|
* @param aParentSheet the parent of this child sheet
|
|
|
|
* @param aURL the URL of the child sheet
|
|
|
|
* @param aMedia the already-parsed media list for the child sheet
|
|
|
|
* @param aRule the @import rule importing this child. This is used to
|
|
|
|
* properly order the child sheet list of aParentSheet.
|
|
|
|
*/
|
1999-05-19 03:15:10 +04:00
|
|
|
NS_IMETHOD LoadChildSheet(nsICSSStyleSheet* aParentSheet,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aURL,
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList* aMedia,
|
2001-08-05 01:19:53 +04:00
|
|
|
nsICSSImportRule* aRule) = 0;
|
1999-05-27 03:51:25 +04:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
/**
|
|
|
|
* Synchronously load and return the stylesheet at aURL. Any child sheets
|
|
|
|
* will also be loaded synchronously. Note that synchronous loads over some
|
|
|
|
* protocols may involve spinning up a new event loop, so use of this method
|
|
|
|
* does NOT guarantee not receiving any events before the sheet loads. This
|
|
|
|
* method can be used to load sheets not associated with a document.
|
|
|
|
*
|
|
|
|
* @param aURL the URL of the sheet to load
|
|
|
|
* @param [out] aSheet the loaded, complete sheet.
|
2006-06-15 07:20:19 +04:00
|
|
|
* @param aEnableUnsafeRules whether unsafe rules are enabled for this
|
|
|
|
* sheet load
|
|
|
|
* Unsafe rules are rules that can violate key Gecko invariants if misused.
|
|
|
|
* In particular, most anonymous box pseudoelements must be very carefully
|
|
|
|
* styled or we will have severe problems. Therefore unsafe rules should
|
|
|
|
* never be enabled for stylesheets controlled by untrusted sites; preferably
|
|
|
|
* unsafe rules should only be enabled for agent sheets.
|
2005-09-12 22:41:15 +04:00
|
|
|
*
|
|
|
|
* NOTE: At the moment, this method assumes the sheet will be UTF-8, but
|
|
|
|
* ideally it would allow arbitrary encodings. Callers should NOT depend on
|
|
|
|
* non-UTF8 sheets being treated as UTF-8 by this method.
|
|
|
|
*
|
|
|
|
* NOTE: A successful return from this method doesn't indicate anything about
|
|
|
|
* whether the data could be parsed as CSS and doesn't indicate anything
|
|
|
|
* about the status of child sheets of the returned sheet.
|
|
|
|
*/
|
2006-06-15 07:20:19 +04:00
|
|
|
NS_IMETHOD LoadSheetSync(nsIURI* aURL, PRBool aEnableUnsafeRules,
|
|
|
|
nsICSSStyleSheet** aSheet) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* As above, but aEnableUnsafeRules is assumed false.
|
|
|
|
*/
|
|
|
|
nsresult LoadSheetSync(nsIURI* aURL, nsICSSStyleSheet** aSheet) {
|
|
|
|
return LoadSheetSync(aURL, PR_FALSE, aSheet);
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously load the stylesheet at aURL. If a successful result is
|
|
|
|
* returned, aObserver is guaranteed to be notified asynchronously once the
|
|
|
|
* sheet is loaded and marked complete. This method can be used to load
|
|
|
|
* sheets not associated with a document.
|
|
|
|
*
|
|
|
|
* @param aURL the URL of the sheet to load
|
|
|
|
* @param aObserver the observer to notify when the load completes.
|
|
|
|
* Must not be null.
|
2006-11-12 01:27:00 +03:00
|
|
|
* @param [out] aSheet the sheet to load. Note that the sheet may well
|
|
|
|
* not be loaded by the time this method returns.
|
|
|
|
*/
|
2007-03-23 02:01:14 +03:00
|
|
|
NS_IMETHOD LoadSheet(nsIURI* aURL, nsICSSLoaderObserver* aObserver,
|
2006-11-12 01:27:00 +03:00
|
|
|
nsICSSStyleSheet** aSheet) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as above, to be used when the caller doesn't care about the
|
|
|
|
* not-yet-loaded sheet.
|
2005-09-12 22:41:15 +04:00
|
|
|
*/
|
2007-03-23 02:01:14 +03:00
|
|
|
NS_IMETHOD LoadSheet(nsIURI* aURL, nsICSSLoaderObserver* aObserver) = 0;
|
2000-04-23 06:01:40 +04:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
/**
|
|
|
|
* Stop loading all sheets. All nsICSSLoaderObservers involved will be
|
|
|
|
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
|
|
|
|
*/
|
2001-05-19 06:59:15 +04:00
|
|
|
NS_IMETHOD Stop(void) = 0;
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
/**
|
|
|
|
* Stop loading one sheet. The nsICSSLoaderObserver involved will be
|
|
|
|
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
|
|
|
|
*/
|
2001-05-19 06:59:15 +04:00
|
|
|
NS_IMETHOD StopLoadingSheet(nsIURI* aURL) = 0;
|
2002-10-11 04:38:29 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the loader is enabled or not.
|
|
|
|
* When disabled, processing of new styles is disabled and an attempt
|
|
|
|
* to do so will fail with a return code of
|
|
|
|
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
|
|
|
|
* currently loading styles or already processed styles.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD GetEnabled(PRBool *aEnabled) = 0;
|
|
|
|
NS_IMETHOD SetEnabled(PRBool aEnabled) = 0;
|
1999-05-19 03:15:10 +04:00
|
|
|
};
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSLoader, NS_ICSS_LOADER_IID)
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
1999-05-19 03:15:10 +04:00
|
|
|
NS_NewCSSLoader(nsIDocument* aDocument, nsICSSLoader** aLoader);
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
1999-05-19 03:15:10 +04:00
|
|
|
NS_NewCSSLoader(nsICSSLoader** aLoader);
|
|
|
|
|
|
|
|
#endif /* nsICSSLoader_h___ */
|