1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
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).
13 #ifndef nsStyleLinkElement_h___
14 #define nsStyleLinkElement_h___
16 #include "mozilla/Attributes.h"
18 #include "nsIStyleSheetLinkingElement.h"
19 #include "nsCSSStyleSheet.h"
21 #include "mozilla/CORSMode.h"
23 #define PREFETCH 0x00000001
24 #define DNS_PREFETCH 0x00000002
25 #define STYLESHEET 0x00000004
26 #define NEXT 0x00000008
27 #define ALTERNATE 0x00000010
36 } // namespace mozilla
38 class nsStyleLinkElement
: public nsIStyleSheetLinkingElement
42 virtual ~nsStyleLinkElement();
44 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
) MOZ_OVERRIDE
= 0;
46 nsCSSStyleSheet
* GetSheet() const { return mStyleSheet
; }
48 // nsIStyleSheetLinkingElement
49 NS_IMETHOD
SetStyleSheet(nsCSSStyleSheet
* aStyleSheet
) MOZ_OVERRIDE
;
50 NS_IMETHOD
GetStyleSheet(nsIStyleSheet
*& aStyleSheet
) MOZ_OVERRIDE
;
51 NS_IMETHOD
InitStyleLinkElement(bool aDontLoadStyle
) MOZ_OVERRIDE
;
52 NS_IMETHOD
UpdateStyleSheet(nsICSSLoaderObserver
* aObserver
,
54 bool* aIsAlternate
) MOZ_OVERRIDE
;
55 NS_IMETHOD
SetEnableUpdates(bool aEnableUpdates
) MOZ_OVERRIDE
;
56 NS_IMETHOD
GetCharset(nsAString
& aCharset
) MOZ_OVERRIDE
;
58 virtual void OverrideBaseURI(nsIURI
* aNewBaseURI
) MOZ_OVERRIDE
;
59 virtual void SetLineNumber(uint32_t aLineNumber
) MOZ_OVERRIDE
;
61 static uint32_t ParseLinkTypes(const nsAString
& aTypes
);
63 void UpdateStyleSheetInternal()
65 UpdateStyleSheetInternal(nullptr, nullptr);
69 * @param aOldDocument should be non-null only if we're updating because we
70 * removed the node from the document.
71 * @param aForceUpdate true will force the update even if the URI has not
72 * changed. This should be used in cases when something
73 * about the content that affects the resulting sheet
74 * changed but the URI may not have changed.
76 nsresult
UpdateStyleSheetInternal(nsIDocument
*aOldDocument
,
77 mozilla::dom::ShadowRoot
*aOldShadowRoot
,
78 bool aForceUpdate
= false);
80 void UpdateStyleSheetScopedness(bool aIsNowScoped
);
82 virtual already_AddRefed
<nsIURI
> GetStyleSheetURL(bool* aIsInline
) = 0;
83 virtual void GetStyleSheetInfo(nsAString
& aTitle
,
87 bool* aIsAlternate
) = 0;
89 virtual mozilla::CORSMode
GetCORSMode() const
92 return mozilla::CORS_NONE
;
97 void Traverse(nsCycleCollectionTraversalCallback
&cb
);
101 * @param aOldDocument should be non-null only if we're updating because we
102 * removed the node from the document.
103 * @param aOldShadowRoot The ShadowRoot that used to contain the style.
104 * Passed as a parameter because on an update, the node
105 * is removed from the tree before the sheet is removed
106 * from the ShadowRoot.
107 * @param aForceUpdate true will force the update even if the URI has not
108 * changed. This should be used in cases when something
109 * about the content that affects the resulting sheet
110 * changed but the URI may not have changed.
112 nsresult
DoUpdateStyleSheet(nsIDocument
* aOldDocument
,
113 mozilla::dom::ShadowRoot
* aOldShadowRoot
,
114 nsICSSLoaderObserver
* aObserver
,
119 nsRefPtr
<nsCSSStyleSheet
> mStyleSheet
;
122 bool mUpdatesEnabled
;
123 uint32_t mLineNumber
;
126 #endif /* nsStyleLinkElement_h___ */