michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * style sheet and style rule processor representing data from presentational michael@0: * HTML attributes michael@0: */ michael@0: michael@0: #ifndef nsHTMLStyleSheet_h_ michael@0: #define nsHTMLStyleSheet_h_ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsColor.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIStyleRule.h" michael@0: #include "nsIStyleRuleProcessor.h" michael@0: #include "pldhash.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "nsString.h" michael@0: michael@0: class nsIDocument; michael@0: class nsMappedAttributes; michael@0: michael@0: class nsHTMLStyleSheet MOZ_FINAL : public nsIStyleRuleProcessor michael@0: { michael@0: public: michael@0: nsHTMLStyleSheet(nsIDocument* aDocument); michael@0: michael@0: void SetOwningDocument(nsIDocument* aDocument); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsIStyleRuleProcessor API michael@0: virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: #ifdef MOZ_XUL michael@0: virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: #endif michael@0: virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: virtual nsRestyleHint michael@0: HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE; michael@0: virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE; michael@0: virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) michael@0: const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; michael@0: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) michael@0: const MOZ_MUST_OVERRIDE MOZ_OVERRIDE; michael@0: size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: michael@0: void Reset(); michael@0: nsresult SetLinkColor(nscolor aColor); michael@0: nsresult SetActiveLinkColor(nscolor aColor); michael@0: nsresult SetVisitedLinkColor(nscolor aColor); michael@0: michael@0: // Mapped Attribute management methods michael@0: already_AddRefed michael@0: UniqueMappedAttributes(nsMappedAttributes* aMapped); michael@0: void DropMappedAttributes(nsMappedAttributes* aMapped); michael@0: michael@0: nsIStyleRule* LangRuleFor(const nsString& aLanguage); michael@0: michael@0: private: michael@0: nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) MOZ_DELETE; michael@0: nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) MOZ_DELETE; michael@0: michael@0: ~nsHTMLStyleSheet(); michael@0: michael@0: class HTMLColorRule; michael@0: friend class HTMLColorRule; michael@0: class HTMLColorRule MOZ_FINAL : public nsIStyleRule { michael@0: public: michael@0: HTMLColorRule() {} michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsIStyleRule interface michael@0: virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; michael@0: #ifdef DEBUG michael@0: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: nscolor mColor; michael@0: }; michael@0: michael@0: // Implementation of SetLink/VisitedLink/ActiveLinkColor michael@0: nsresult ImplLinkColorSetter(nsRefPtr& aRule, nscolor aColor); michael@0: michael@0: class GenericTableRule; michael@0: friend class GenericTableRule; michael@0: class GenericTableRule : public nsIStyleRule { michael@0: public: michael@0: GenericTableRule() {} michael@0: virtual ~GenericTableRule() {} michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsIStyleRule interface michael@0: virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE = 0; michael@0: #ifdef DEBUG michael@0: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; michael@0: #endif michael@0: }; michael@0: michael@0: // this rule handles inheritance michael@0: class TableTHRule; michael@0: friend class TableTHRule; michael@0: class TableTHRule MOZ_FINAL : public GenericTableRule { michael@0: public: michael@0: TableTHRule() {} michael@0: michael@0: virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: // Rule to handle quirk table colors michael@0: class TableQuirkColorRule MOZ_FINAL : public GenericTableRule { michael@0: public: michael@0: TableQuirkColorRule() {} michael@0: michael@0: virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: public: // for mLangRuleTable structures only michael@0: michael@0: // Rule to handle xml:lang attributes, of which we have exactly one michael@0: // per language string, maintained in mLangRuleTable. michael@0: class LangRule MOZ_FINAL : public nsIStyleRule { michael@0: public: michael@0: LangRule(const nsSubstring& aLang) : mLang(aLang) {} michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsIStyleRule interface michael@0: virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; michael@0: #ifdef DEBUG michael@0: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: nsString mLang; michael@0: }; michael@0: michael@0: private: michael@0: nsIDocument* mDocument; michael@0: nsRefPtr mLinkRule; michael@0: nsRefPtr mVisitedRule; michael@0: nsRefPtr mActiveRule; michael@0: nsRefPtr mTableQuirkColorRule; michael@0: nsRefPtr mTableTHRule; michael@0: michael@0: PLDHashTable mMappedAttrTable; michael@0: PLDHashTable mLangRuleTable; michael@0: }; michael@0: michael@0: #endif /* !defined(nsHTMLStyleSheet_h_) */