1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/nsStyleLinkElement.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* 1.11 + * A base class which implements nsIStyleSheetLinkingElement and can 1.12 + * be subclassed by various content nodes that want to load 1.13 + * stylesheets (<style>, <link>, processing instructions, etc). 1.14 + */ 1.15 + 1.16 +#ifndef nsStyleLinkElement_h___ 1.17 +#define nsStyleLinkElement_h___ 1.18 + 1.19 +#include "mozilla/Attributes.h" 1.20 +#include "nsCOMPtr.h" 1.21 +#include "nsIStyleSheetLinkingElement.h" 1.22 +#include "nsCSSStyleSheet.h" 1.23 +#include "nsTArray.h" 1.24 +#include "mozilla/CORSMode.h" 1.25 + 1.26 +class nsIDocument; 1.27 +class nsIURI; 1.28 + 1.29 +namespace mozilla { 1.30 +namespace dom { 1.31 +class ShadowRoot; 1.32 +} // namespace dom 1.33 +} // namespace mozilla 1.34 + 1.35 +class nsStyleLinkElement : public nsIStyleSheetLinkingElement 1.36 +{ 1.37 +public: 1.38 + nsStyleLinkElement(); 1.39 + virtual ~nsStyleLinkElement(); 1.40 + 1.41 + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE = 0; 1.42 + 1.43 + nsCSSStyleSheet* GetSheet() const { return mStyleSheet; } 1.44 + 1.45 + // nsIStyleSheetLinkingElement 1.46 + NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aStyleSheet) MOZ_OVERRIDE; 1.47 + NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet) MOZ_OVERRIDE; 1.48 + NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) MOZ_OVERRIDE; 1.49 + NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver, 1.50 + bool* aWillNotify, 1.51 + bool* aIsAlternate) MOZ_OVERRIDE; 1.52 + NS_IMETHOD SetEnableUpdates(bool aEnableUpdates) MOZ_OVERRIDE; 1.53 + NS_IMETHOD GetCharset(nsAString& aCharset) MOZ_OVERRIDE; 1.54 + 1.55 + virtual void OverrideBaseURI(nsIURI* aNewBaseURI) MOZ_OVERRIDE; 1.56 + virtual void SetLineNumber(uint32_t aLineNumber) MOZ_OVERRIDE; 1.57 + 1.58 + enum RelValue { 1.59 + ePREFETCH = 0x00000001, 1.60 + eDNS_PREFETCH = 0x00000002, 1.61 + eSTYLESHEET = 0x00000004, 1.62 + eNEXT = 0x00000008, 1.63 + eALTERNATE = 0x00000010, 1.64 + }; 1.65 + 1.66 + // The return value is a bitwise or of 0 or more RelValues 1.67 + static uint32_t ParseLinkTypes(const nsAString& aTypes); 1.68 + 1.69 + void UpdateStyleSheetInternal() 1.70 + { 1.71 + UpdateStyleSheetInternal(nullptr, nullptr); 1.72 + } 1.73 +protected: 1.74 + /** 1.75 + * @param aOldDocument should be non-null only if we're updating because we 1.76 + * removed the node from the document. 1.77 + * @param aForceUpdate true will force the update even if the URI has not 1.78 + * changed. This should be used in cases when something 1.79 + * about the content that affects the resulting sheet 1.80 + * changed but the URI may not have changed. 1.81 + */ 1.82 + nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument, 1.83 + mozilla::dom::ShadowRoot *aOldShadowRoot, 1.84 + bool aForceUpdate = false); 1.85 + 1.86 + void UpdateStyleSheetScopedness(bool aIsNowScoped); 1.87 + 1.88 + virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0; 1.89 + virtual void GetStyleSheetInfo(nsAString& aTitle, 1.90 + nsAString& aType, 1.91 + nsAString& aMedia, 1.92 + bool* aIsScoped, 1.93 + bool* aIsAlternate) = 0; 1.94 + 1.95 + virtual mozilla::CORSMode GetCORSMode() const 1.96 + { 1.97 + // Default to no CORS 1.98 + return mozilla::CORS_NONE; 1.99 + } 1.100 + 1.101 + // CC methods 1.102 + void Unlink(); 1.103 + void Traverse(nsCycleCollectionTraversalCallback &cb); 1.104 + 1.105 +private: 1.106 + /** 1.107 + * @param aOldDocument should be non-null only if we're updating because we 1.108 + * removed the node from the document. 1.109 + * @param aOldShadowRoot The ShadowRoot that used to contain the style. 1.110 + * Passed as a parameter because on an update, the node 1.111 + * is removed from the tree before the sheet is removed 1.112 + * from the ShadowRoot. 1.113 + * @param aForceUpdate true will force the update even if the URI has not 1.114 + * changed. This should be used in cases when something 1.115 + * about the content that affects the resulting sheet 1.116 + * changed but the URI may not have changed. 1.117 + */ 1.118 + nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument, 1.119 + mozilla::dom::ShadowRoot* aOldShadowRoot, 1.120 + nsICSSLoaderObserver* aObserver, 1.121 + bool* aWillNotify, 1.122 + bool* aIsAlternate, 1.123 + bool aForceUpdate); 1.124 + 1.125 + nsRefPtr<nsCSSStyleSheet> mStyleSheet; 1.126 +protected: 1.127 + bool mDontLoadStyle; 1.128 + bool mUpdatesEnabled; 1.129 + uint32_t mLineNumber; 1.130 +}; 1.131 + 1.132 +#endif /* nsStyleLinkElement_h___ */ 1.133 +