Bumping manifests a=b2g-bump
[gecko.git] / dom / base / nsStyleLinkElement.h
blobbe0a613a087322372a79ff201f05aa5feccc32bc
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/. */
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).
13 #ifndef nsStyleLinkElement_h___
14 #define nsStyleLinkElement_h___
16 #include "mozilla/Attributes.h"
17 #include "mozilla/CORSMode.h"
18 #include "mozilla/CSSStyleSheet.h"
19 #include "nsCOMPtr.h"
20 #include "nsIStyleSheetLinkingElement.h"
21 #include "nsTArray.h"
23 class nsIDocument;
24 class nsIURI;
26 namespace mozilla {
27 namespace dom {
28 class ShadowRoot;
29 } // namespace dom
30 } // namespace mozilla
32 class nsStyleLinkElement : public nsIStyleSheetLinkingElement
34 public:
35 nsStyleLinkElement();
36 virtual ~nsStyleLinkElement();
38 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE = 0;
40 mozilla::CSSStyleSheet* GetSheet() const { return mStyleSheet; }
42 // nsIStyleSheetLinkingElement
43 NS_IMETHOD SetStyleSheet(mozilla::CSSStyleSheet* aStyleSheet) MOZ_OVERRIDE;
44 NS_IMETHOD_(mozilla::CSSStyleSheet*) GetStyleSheet() MOZ_OVERRIDE;
45 NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) MOZ_OVERRIDE;
46 NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
47 bool* aWillNotify,
48 bool* aIsAlternate,
49 bool aForceReload) MOZ_OVERRIDE;
50 NS_IMETHOD SetEnableUpdates(bool aEnableUpdates) MOZ_OVERRIDE;
51 NS_IMETHOD GetCharset(nsAString& aCharset) MOZ_OVERRIDE;
53 virtual void OverrideBaseURI(nsIURI* aNewBaseURI) MOZ_OVERRIDE;
54 virtual void SetLineNumber(uint32_t aLineNumber) MOZ_OVERRIDE;
56 enum RelValue {
57 ePREFETCH = 0x00000001,
58 eDNS_PREFETCH = 0x00000002,
59 eSTYLESHEET = 0x00000004,
60 eNEXT = 0x00000008,
61 eALTERNATE = 0x00000010,
62 eHTMLIMPORT = 0x00000020
65 // The return value is a bitwise or of 0 or more RelValues.
66 // aPrincipal is used to check if HTML imports is enabled for the
67 // provided principal.
68 static uint32_t ParseLinkTypes(const nsAString& aTypes,
69 nsIPrincipal* aPrincipal);
71 static bool IsImportEnabled(nsIPrincipal* aPrincipal);
73 void UpdateStyleSheetInternal()
75 UpdateStyleSheetInternal(nullptr, nullptr);
77 protected:
78 /**
79 * @param aOldDocument should be non-null only if we're updating because we
80 * removed the node from the document.
81 * @param aForceUpdate true will force the update even if the URI has not
82 * changed. This should be used in cases when something
83 * about the content that affects the resulting sheet
84 * changed but the URI may not have changed.
86 nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument,
87 mozilla::dom::ShadowRoot *aOldShadowRoot,
88 bool aForceUpdate = false);
90 void UpdateStyleSheetScopedness(bool aIsNowScoped);
92 virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0;
93 virtual void GetStyleSheetInfo(nsAString& aTitle,
94 nsAString& aType,
95 nsAString& aMedia,
96 bool* aIsScoped,
97 bool* aIsAlternate) = 0;
99 virtual mozilla::CORSMode GetCORSMode() const
101 // Default to no CORS
102 return mozilla::CORS_NONE;
105 // CC methods
106 void Unlink();
107 void Traverse(nsCycleCollectionTraversalCallback &cb);
109 private:
111 * @param aOldDocument should be non-null only if we're updating because we
112 * removed the node from the document.
113 * @param aOldShadowRoot The ShadowRoot that used to contain the style.
114 * Passed as a parameter because on an update, the node
115 * is removed from the tree before the sheet is removed
116 * from the ShadowRoot.
117 * @param aForceUpdate true will force the update even if the URI has not
118 * changed. This should be used in cases when something
119 * about the content that affects the resulting sheet
120 * changed but the URI may not have changed.
122 nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument,
123 mozilla::dom::ShadowRoot* aOldShadowRoot,
124 nsICSSLoaderObserver* aObserver,
125 bool* aWillNotify,
126 bool* aIsAlternate,
127 bool aForceUpdate);
129 nsRefPtr<mozilla::CSSStyleSheet> mStyleSheet;
130 protected:
131 bool mDontLoadStyle;
132 bool mUpdatesEnabled;
133 uint32_t mLineNumber;
136 #endif /* nsStyleLinkElement_h___ */