1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Communicator client code, released
17 : * March 31, 1998.
18 : *
19 : * The Initial Developer of the Original Code is
20 : * Netscape Communications Corporation.
21 : * Portions created by the Initial Developer are Copyright (C) 1998-1999
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Contributor(s):
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : /*
41 : * A base class which implements nsIStyleSheetLinkingElement and can
42 : * be subclassed by various content nodes that want to load
43 : * stylesheets (<style>, <link>, processing instructions, etc).
44 : */
45 :
46 : #ifndef nsStyleLinkElement_h___
47 : #define nsStyleLinkElement_h___
48 :
49 : #include "nsCOMPtr.h"
50 : #include "nsIDOMLinkStyle.h"
51 : #include "nsIStyleSheetLinkingElement.h"
52 : #include "nsIStyleSheet.h"
53 : #include "nsIURI.h"
54 : #include "nsTArray.h"
55 :
56 : #define PREFETCH 0x00000001
57 : #define DNS_PREFETCH 0x00000002
58 : #define STYLESHEET 0x00000004
59 : #define NEXT 0x00000008
60 : #define ALTERNATE 0x00000010
61 :
62 : class nsIDocument;
63 :
64 : class nsStyleLinkElement : public nsIDOMLinkStyle,
65 : public nsIStyleSheetLinkingElement
66 : {
67 : public:
68 : nsStyleLinkElement();
69 : virtual ~nsStyleLinkElement();
70 :
71 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) = 0;
72 :
73 : // nsIDOMLinkStyle
74 : NS_DECL_NSIDOMLINKSTYLE
75 :
76 : // nsIStyleSheetLinkingElement
77 : NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet);
78 : NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet);
79 : NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle);
80 : NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
81 : bool* aWillNotify,
82 : bool* aIsAlternate);
83 : NS_IMETHOD SetEnableUpdates(bool aEnableUpdates);
84 : NS_IMETHOD GetCharset(nsAString& aCharset);
85 :
86 : virtual void OverrideBaseURI(nsIURI* aNewBaseURI);
87 : virtual void SetLineNumber(PRUint32 aLineNumber);
88 :
89 : static PRUint32 ParseLinkTypes(const nsAString& aTypes);
90 :
91 62 : void UpdateStyleSheetInternal() { UpdateStyleSheetInternal(nsnull); }
92 : protected:
93 : /**
94 : * @param aOldDocument should be non-null only if we're updating because we
95 : * removed the node from the document.
96 : * @param aForceUpdate true will force the update even if the URI has not
97 : * changed. This should be used in cases when something
98 : * about the content that affects the resulting sheet
99 : * changed but the URI may not have changed.
100 : */
101 : nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument,
102 : bool aForceUpdate = false);
103 :
104 : virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0;
105 : virtual void GetStyleSheetInfo(nsAString& aTitle,
106 : nsAString& aType,
107 : nsAString& aMedia,
108 : bool* aIsAlternate) = 0;
109 :
110 0 : nsIStyleSheet* GetStyleSheet() { return mStyleSheet; }
111 :
112 : private:
113 : /**
114 : * @param aOldDocument should be non-null only if we're updating because we
115 : * removed the node from the document.
116 : * @param aForceUpdate true will force the update even if the URI has not
117 : * changed. This should be used in cases when something
118 : * about the content that affects the resulting sheet
119 : * changed but the URI may not have changed.
120 : */
121 : nsresult DoUpdateStyleSheet(nsIDocument *aOldDocument,
122 : nsICSSLoaderObserver* aObserver,
123 : bool* aWillNotify,
124 : bool* aIsAlternate,
125 : bool aForceUpdate);
126 :
127 : nsCOMPtr<nsIStyleSheet> mStyleSheet;
128 : protected:
129 : bool mDontLoadStyle;
130 : bool mUpdatesEnabled;
131 : PRUint32 mLineNumber;
132 : };
133 :
134 : #endif /* nsStyleLinkElement_h___ */
135 :
|