|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 /* |
|
8 * A base class which implements nsIStyleSheetLinkingElement and can |
|
9 * be subclassed by various content nodes that want to load |
|
10 * stylesheets (<style>, <link>, processing instructions, etc). |
|
11 */ |
|
12 |
|
13 #ifndef nsStyleLinkElement_h___ |
|
14 #define nsStyleLinkElement_h___ |
|
15 |
|
16 #include "mozilla/Attributes.h" |
|
17 #include "nsCOMPtr.h" |
|
18 #include "nsIStyleSheetLinkingElement.h" |
|
19 #include "nsCSSStyleSheet.h" |
|
20 #include "nsTArray.h" |
|
21 #include "mozilla/CORSMode.h" |
|
22 |
|
23 class nsIDocument; |
|
24 class nsIURI; |
|
25 |
|
26 namespace mozilla { |
|
27 namespace dom { |
|
28 class ShadowRoot; |
|
29 } // namespace dom |
|
30 } // namespace mozilla |
|
31 |
|
32 class nsStyleLinkElement : public nsIStyleSheetLinkingElement |
|
33 { |
|
34 public: |
|
35 nsStyleLinkElement(); |
|
36 virtual ~nsStyleLinkElement(); |
|
37 |
|
38 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE = 0; |
|
39 |
|
40 nsCSSStyleSheet* GetSheet() const { return mStyleSheet; } |
|
41 |
|
42 // nsIStyleSheetLinkingElement |
|
43 NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aStyleSheet) MOZ_OVERRIDE; |
|
44 NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet) MOZ_OVERRIDE; |
|
45 NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) MOZ_OVERRIDE; |
|
46 NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver, |
|
47 bool* aWillNotify, |
|
48 bool* aIsAlternate) MOZ_OVERRIDE; |
|
49 NS_IMETHOD SetEnableUpdates(bool aEnableUpdates) MOZ_OVERRIDE; |
|
50 NS_IMETHOD GetCharset(nsAString& aCharset) MOZ_OVERRIDE; |
|
51 |
|
52 virtual void OverrideBaseURI(nsIURI* aNewBaseURI) MOZ_OVERRIDE; |
|
53 virtual void SetLineNumber(uint32_t aLineNumber) MOZ_OVERRIDE; |
|
54 |
|
55 enum RelValue { |
|
56 ePREFETCH = 0x00000001, |
|
57 eDNS_PREFETCH = 0x00000002, |
|
58 eSTYLESHEET = 0x00000004, |
|
59 eNEXT = 0x00000008, |
|
60 eALTERNATE = 0x00000010, |
|
61 }; |
|
62 |
|
63 // The return value is a bitwise or of 0 or more RelValues |
|
64 static uint32_t ParseLinkTypes(const nsAString& aTypes); |
|
65 |
|
66 void UpdateStyleSheetInternal() |
|
67 { |
|
68 UpdateStyleSheetInternal(nullptr, nullptr); |
|
69 } |
|
70 protected: |
|
71 /** |
|
72 * @param aOldDocument should be non-null only if we're updating because we |
|
73 * removed the node from the document. |
|
74 * @param aForceUpdate true will force the update even if the URI has not |
|
75 * changed. This should be used in cases when something |
|
76 * about the content that affects the resulting sheet |
|
77 * changed but the URI may not have changed. |
|
78 */ |
|
79 nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument, |
|
80 mozilla::dom::ShadowRoot *aOldShadowRoot, |
|
81 bool aForceUpdate = false); |
|
82 |
|
83 void UpdateStyleSheetScopedness(bool aIsNowScoped); |
|
84 |
|
85 virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0; |
|
86 virtual void GetStyleSheetInfo(nsAString& aTitle, |
|
87 nsAString& aType, |
|
88 nsAString& aMedia, |
|
89 bool* aIsScoped, |
|
90 bool* aIsAlternate) = 0; |
|
91 |
|
92 virtual mozilla::CORSMode GetCORSMode() const |
|
93 { |
|
94 // Default to no CORS |
|
95 return mozilla::CORS_NONE; |
|
96 } |
|
97 |
|
98 // CC methods |
|
99 void Unlink(); |
|
100 void Traverse(nsCycleCollectionTraversalCallback &cb); |
|
101 |
|
102 private: |
|
103 /** |
|
104 * @param aOldDocument should be non-null only if we're updating because we |
|
105 * removed the node from the document. |
|
106 * @param aOldShadowRoot The ShadowRoot that used to contain the style. |
|
107 * Passed as a parameter because on an update, the node |
|
108 * is removed from the tree before the sheet is removed |
|
109 * from the ShadowRoot. |
|
110 * @param aForceUpdate true will force the update even if the URI has not |
|
111 * changed. This should be used in cases when something |
|
112 * about the content that affects the resulting sheet |
|
113 * changed but the URI may not have changed. |
|
114 */ |
|
115 nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument, |
|
116 mozilla::dom::ShadowRoot* aOldShadowRoot, |
|
117 nsICSSLoaderObserver* aObserver, |
|
118 bool* aWillNotify, |
|
119 bool* aIsAlternate, |
|
120 bool aForceUpdate); |
|
121 |
|
122 nsRefPtr<nsCSSStyleSheet> mStyleSheet; |
|
123 protected: |
|
124 bool mDontLoadStyle; |
|
125 bool mUpdatesEnabled; |
|
126 uint32_t mLineNumber; |
|
127 }; |
|
128 |
|
129 #endif /* nsStyleLinkElement_h___ */ |
|
130 |