Backed out 35 changesets (bug 941158, bug 972518, bug 959520, bug 986063, bug 948895...
[gecko.git] / content / base / src / nsStyleLinkElement.h
blobe2ff714e210bd548c1aed14265120061d87d7255
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 "nsCOMPtr.h"
18 #include "nsIStyleSheetLinkingElement.h"
19 #include "nsCSSStyleSheet.h"
20 #include "nsTArray.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
29 class nsIDocument;
30 class nsIURI;
32 namespace mozilla {
33 namespace dom {
34 class ShadowRoot;
35 } // namespace dom
36 } // namespace mozilla
38 class nsStyleLinkElement : public nsIStyleSheetLinkingElement
40 public:
41 nsStyleLinkElement();
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,
53 bool* aWillNotify,
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);
67 protected:
68 /**
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,
84 nsAString& aType,
85 nsAString& aMedia,
86 bool* aIsScoped,
87 bool* aIsAlternate) = 0;
89 virtual mozilla::CORSMode GetCORSMode() const
91 // Default to no CORS
92 return mozilla::CORS_NONE;
95 // CC methods
96 void Unlink();
97 void Traverse(nsCycleCollectionTraversalCallback &cb);
99 private:
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,
115 bool* aWillNotify,
116 bool* aIsAlternate,
117 bool aForceUpdate);
119 nsRefPtr<nsCSSStyleSheet> mStyleSheet;
120 protected:
121 bool mDontLoadStyle;
122 bool mUpdatesEnabled;
123 uint32_t mLineNumber;
126 #endif /* nsStyleLinkElement_h___ */