1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsHTMLStyleSheet.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,159 @@ 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 + * style sheet and style rule processor representing data from presentational 1.12 + * HTML attributes 1.13 + */ 1.14 + 1.15 +#ifndef nsHTMLStyleSheet_h_ 1.16 +#define nsHTMLStyleSheet_h_ 1.17 + 1.18 +#include "nsAutoPtr.h" 1.19 +#include "nsColor.h" 1.20 +#include "nsCOMPtr.h" 1.21 +#include "nsIStyleRule.h" 1.22 +#include "nsIStyleRuleProcessor.h" 1.23 +#include "pldhash.h" 1.24 +#include "mozilla/Attributes.h" 1.25 +#include "mozilla/MemoryReporting.h" 1.26 +#include "nsString.h" 1.27 + 1.28 +class nsIDocument; 1.29 +class nsMappedAttributes; 1.30 + 1.31 +class nsHTMLStyleSheet MOZ_FINAL : public nsIStyleRuleProcessor 1.32 +{ 1.33 +public: 1.34 + nsHTMLStyleSheet(nsIDocument* aDocument); 1.35 + 1.36 + void SetOwningDocument(nsIDocument* aDocument); 1.37 + 1.38 + NS_DECL_ISUPPORTS 1.39 + 1.40 + // nsIStyleRuleProcessor API 1.41 + virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE; 1.42 + virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE; 1.43 + virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE; 1.44 +#ifdef MOZ_XUL 1.45 + virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE; 1.46 +#endif 1.47 + virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; 1.48 + virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) MOZ_OVERRIDE; 1.49 + virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; 1.50 + virtual nsRestyleHint 1.51 + HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE; 1.52 + virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE; 1.53 + virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) 1.54 + const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; 1.55 + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) 1.56 + const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; 1.57 + size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 1.58 + 1.59 + void Reset(); 1.60 + nsresult SetLinkColor(nscolor aColor); 1.61 + nsresult SetActiveLinkColor(nscolor aColor); 1.62 + nsresult SetVisitedLinkColor(nscolor aColor); 1.63 + 1.64 + // Mapped Attribute management methods 1.65 + already_AddRefed<nsMappedAttributes> 1.66 + UniqueMappedAttributes(nsMappedAttributes* aMapped); 1.67 + void DropMappedAttributes(nsMappedAttributes* aMapped); 1.68 + 1.69 + nsIStyleRule* LangRuleFor(const nsString& aLanguage); 1.70 + 1.71 +private: 1.72 + nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) MOZ_DELETE; 1.73 + nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) MOZ_DELETE; 1.74 + 1.75 + ~nsHTMLStyleSheet(); 1.76 + 1.77 + class HTMLColorRule; 1.78 + friend class HTMLColorRule; 1.79 + class HTMLColorRule MOZ_FINAL : public nsIStyleRule { 1.80 + public: 1.81 + HTMLColorRule() {} 1.82 + 1.83 + NS_DECL_ISUPPORTS 1.84 + 1.85 + // nsIStyleRule interface 1.86 + virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; 1.87 + #ifdef DEBUG 1.88 + virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; 1.89 + #endif 1.90 + 1.91 + nscolor mColor; 1.92 + }; 1.93 + 1.94 + // Implementation of SetLink/VisitedLink/ActiveLinkColor 1.95 + nsresult ImplLinkColorSetter(nsRefPtr<HTMLColorRule>& aRule, nscolor aColor); 1.96 + 1.97 + class GenericTableRule; 1.98 + friend class GenericTableRule; 1.99 + class GenericTableRule : public nsIStyleRule { 1.100 + public: 1.101 + GenericTableRule() {} 1.102 + virtual ~GenericTableRule() {} 1.103 + 1.104 + NS_DECL_ISUPPORTS 1.105 + 1.106 + // nsIStyleRule interface 1.107 + virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE = 0; 1.108 + #ifdef DEBUG 1.109 + virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; 1.110 + #endif 1.111 + }; 1.112 + 1.113 + // this rule handles <th> inheritance 1.114 + class TableTHRule; 1.115 + friend class TableTHRule; 1.116 + class TableTHRule MOZ_FINAL : public GenericTableRule { 1.117 + public: 1.118 + TableTHRule() {} 1.119 + 1.120 + virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; 1.121 + }; 1.122 + 1.123 + // Rule to handle quirk table colors 1.124 + class TableQuirkColorRule MOZ_FINAL : public GenericTableRule { 1.125 + public: 1.126 + TableQuirkColorRule() {} 1.127 + 1.128 + virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; 1.129 + }; 1.130 + 1.131 +public: // for mLangRuleTable structures only 1.132 + 1.133 + // Rule to handle xml:lang attributes, of which we have exactly one 1.134 + // per language string, maintained in mLangRuleTable. 1.135 + class LangRule MOZ_FINAL : public nsIStyleRule { 1.136 + public: 1.137 + LangRule(const nsSubstring& aLang) : mLang(aLang) {} 1.138 + 1.139 + NS_DECL_ISUPPORTS 1.140 + 1.141 + // nsIStyleRule interface 1.142 + virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; 1.143 + #ifdef DEBUG 1.144 + virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; 1.145 + #endif 1.146 + 1.147 + nsString mLang; 1.148 + }; 1.149 + 1.150 +private: 1.151 + nsIDocument* mDocument; 1.152 + nsRefPtr<HTMLColorRule> mLinkRule; 1.153 + nsRefPtr<HTMLColorRule> mVisitedRule; 1.154 + nsRefPtr<HTMLColorRule> mActiveRule; 1.155 + nsRefPtr<TableQuirkColorRule> mTableQuirkColorRule; 1.156 + nsRefPtr<TableTHRule> mTableTHRule; 1.157 + 1.158 + PLDHashTable mMappedAttrTable; 1.159 + PLDHashTable mLangRuleTable; 1.160 +}; 1.161 + 1.162 +#endif /* !defined(nsHTMLStyleSheet_h_) */