2017-10-27 17:33:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-25 05:47:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* style sheet and style rule processor representing data from presentational
|
|
|
|
* HTML attributes
|
|
|
|
*/
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
#ifndef nsHTMLStyleSheet_h_
|
|
|
|
#define nsHTMLStyleSheet_h_
|
|
|
|
|
2013-03-22 00:05:20 +00:00
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2017-10-02 22:05:19 +00:00
|
|
|
#include "nsAtom.h"
|
2004-04-12 21:56:09 +00:00
|
|
|
#include "nsIStyleRule.h"
|
2013-03-22 00:05:20 +00:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
2015-09-16 03:49:53 +00:00
|
|
|
#include "PLDHashTable.h"
|
2012-06-19 03:26:34 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-05-30 08:00:20 +00:00
|
|
|
#include "nsString.h"
|
2012-06-19 03:26:34 +00:00
|
|
|
|
2013-09-16 01:06:52 +00:00
|
|
|
class nsIDocument;
|
2004-04-12 21:56:09 +00:00
|
|
|
class nsMappedAttributes;
|
2017-06-01 18:37:02 +00:00
|
|
|
struct RawServoDeclarationBlock;
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsHTMLStyleSheet final : public nsIStyleRuleProcessor
|
2012-06-19 03:26:34 +00:00
|
|
|
{
|
2004-04-12 21:56:09 +00:00
|
|
|
public:
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit nsHTMLStyleSheet(nsIDocument* aDocument);
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2013-06-14 05:34:37 +00:00
|
|
|
void SetOwningDocument(nsIDocument* aDocument);
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2013-06-14 05:34:37 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2004-04-12 21:56:09 +00:00
|
|
|
|
|
|
|
// nsIStyleRuleProcessor API
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void RulesMatching(ElementRuleProcessorData* aData) override;
|
|
|
|
virtual void RulesMatching(PseudoElementRuleProcessorData* aData) override;
|
|
|
|
virtual void RulesMatching(AnonBoxRuleProcessorData* aData) override;
|
2009-12-11 07:37:40 +00:00
|
|
|
#ifdef MOZ_XUL
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void RulesMatching(XULTreeRuleProcessorData* aData) override;
|
2009-12-11 07:37:40 +00:00
|
|
|
#endif
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override;
|
|
|
|
virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override;
|
|
|
|
virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override;
|
2010-04-01 00:43:32 +00:00
|
|
|
virtual nsRestyleHint
|
2015-08-05 12:42:21 +00:00
|
|
|
HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
|
|
|
|
mozilla::RestyleHintData& aRestyleHintDataResult) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) override;
|
2013-06-23 12:03:39 +00:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2015-03-21 16:28:04 +00:00
|
|
|
const MOZ_MUST_OVERRIDE override;
|
2013-06-23 12:03:39 +00:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2015-03-21 16:28:04 +00:00
|
|
|
const MOZ_MUST_OVERRIDE override;
|
2013-06-23 12:03:39 +00:00
|
|
|
size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2013-06-14 05:34:37 +00:00
|
|
|
void Reset();
|
2004-04-12 21:56:09 +00:00
|
|
|
nsresult SetLinkColor(nscolor aColor);
|
|
|
|
nsresult SetActiveLinkColor(nscolor aColor);
|
|
|
|
nsresult SetVisitedLinkColor(nscolor aColor);
|
|
|
|
|
2017-06-01 18:37:02 +00:00
|
|
|
const RefPtr<RawServoDeclarationBlock>& GetServoUnvisitedLinkDecl() const {
|
|
|
|
return mServoUnvisitedLinkDecl;
|
|
|
|
}
|
|
|
|
const RefPtr<RawServoDeclarationBlock>& GetServoVisitedLinkDecl() const {
|
|
|
|
return mServoVisitedLinkDecl;
|
|
|
|
}
|
|
|
|
const RefPtr<RawServoDeclarationBlock>& GetServoActiveLinkDecl() const {
|
|
|
|
return mServoActiveLinkDecl;
|
|
|
|
}
|
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
// Mapped Attribute management methods
|
|
|
|
already_AddRefed<nsMappedAttributes>
|
|
|
|
UniqueMappedAttributes(nsMappedAttributes* aMapped);
|
|
|
|
void DropMappedAttributes(nsMappedAttributes* aMapped);
|
2017-01-19 23:56:53 +00:00
|
|
|
// For each mapped presentation attribute in the cache, resolve
|
|
|
|
// the attached ServoDeclarationBlock by running the mapping
|
|
|
|
// and converting the ruledata to Servo specified values.
|
2017-04-08 14:42:43 +00:00
|
|
|
void CalculateMappedServoDeclarations(nsPresContext* aPresContext);
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsIStyleRule* LangRuleFor(const nsAtom* aLanguage);
|
2013-05-30 08:00:20 +00:00
|
|
|
|
2017-06-16 21:59:08 +00:00
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) = delete;
|
|
|
|
nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) = delete;
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2015-05-19 03:43:18 +00:00
|
|
|
~nsHTMLStyleSheet() {}
|
2004-04-12 21:56:09 +00:00
|
|
|
|
|
|
|
class HTMLColorRule;
|
|
|
|
friend class HTMLColorRule;
|
2015-03-21 16:28:04 +00:00
|
|
|
class HTMLColorRule final : public nsIStyleRule {
|
2014-06-23 22:40:01 +00:00
|
|
|
private:
|
|
|
|
~HTMLColorRule() {}
|
2004-04-12 21:56:09 +00:00
|
|
|
public:
|
2017-05-03 15:40:23 +00:00
|
|
|
explicit HTMLColorRule(nscolor aColor)
|
|
|
|
: mColor(aColor)
|
|
|
|
{}
|
2004-04-12 21:56:09 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2004-10-31 17:33:50 +00:00
|
|
|
// nsIStyleRule interface
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
|
2015-11-17 04:09:55 +00:00
|
|
|
virtual bool MightMapInheritedStyleData() override;
|
2016-08-17 01:37:48 +00:00
|
|
|
virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
|
2016-08-16 05:29:21 +00:00
|
|
|
nsCSSValue* aValue) override;
|
2004-04-12 21:56:09 +00:00
|
|
|
#ifdef DEBUG
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
|
2004-04-12 21:56:09 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-03 15:40:23 +00:00
|
|
|
nscolor mColor;
|
2004-04-12 21:56:09 +00:00
|
|
|
};
|
|
|
|
|
2010-06-18 16:23:05 +00:00
|
|
|
// Implementation of SetLink/VisitedLink/ActiveLinkColor
|
2017-06-01 18:37:02 +00:00
|
|
|
nsresult ImplLinkColorSetter(RefPtr<HTMLColorRule>& aRule,
|
|
|
|
RefPtr<RawServoDeclarationBlock>& aDecl,
|
|
|
|
nscolor aColor);
|
2006-05-14 13:34:32 +00:00
|
|
|
|
2004-04-12 21:56:09 +00:00
|
|
|
class GenericTableRule;
|
|
|
|
friend class GenericTableRule;
|
2012-06-19 03:26:34 +00:00
|
|
|
class GenericTableRule : public nsIStyleRule {
|
2014-06-23 22:40:01 +00:00
|
|
|
protected:
|
|
|
|
virtual ~GenericTableRule() {}
|
2004-04-12 21:56:09 +00:00
|
|
|
public:
|
2004-10-31 17:33:50 +00:00
|
|
|
GenericTableRule() {}
|
2004-04-12 21:56:09 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2004-10-31 17:33:50 +00:00
|
|
|
// nsIStyleRule interface
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override = 0;
|
2015-11-17 04:09:55 +00:00
|
|
|
virtual bool MightMapInheritedStyleData() override = 0;
|
2016-08-17 01:37:48 +00:00
|
|
|
virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
|
2016-08-16 05:29:21 +00:00
|
|
|
nsCSSValue* aValue) override = 0;
|
2004-04-12 21:56:09 +00:00
|
|
|
#ifdef DEBUG
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
|
2004-04-12 21:56:09 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
// this rule handles <th> inheritance
|
|
|
|
class TableTHRule;
|
|
|
|
friend class TableTHRule;
|
2015-03-21 16:28:04 +00:00
|
|
|
class TableTHRule final : public GenericTableRule {
|
2004-04-12 21:56:09 +00:00
|
|
|
public:
|
2004-10-31 17:33:50 +00:00
|
|
|
TableTHRule() {}
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
|
2015-11-17 04:09:55 +00:00
|
|
|
virtual bool MightMapInheritedStyleData() override;
|
2016-08-17 01:37:48 +00:00
|
|
|
virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
|
2016-08-16 05:29:21 +00:00
|
|
|
nsCSSValue* aValue) override;
|
2004-04-12 21:56:09 +00:00
|
|
|
};
|
|
|
|
|
2011-06-01 11:43:31 +00:00
|
|
|
// Rule to handle quirk table colors
|
2015-03-21 16:28:04 +00:00
|
|
|
class TableQuirkColorRule final : public GenericTableRule {
|
2011-06-01 11:43:31 +00:00
|
|
|
public:
|
|
|
|
TableQuirkColorRule() {}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
|
2015-11-17 04:09:55 +00:00
|
|
|
virtual bool MightMapInheritedStyleData() override;
|
2016-08-17 01:37:48 +00:00
|
|
|
virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
|
2016-08-16 05:29:21 +00:00
|
|
|
nsCSSValue* aValue) override;
|
2011-06-01 11:43:31 +00:00
|
|
|
};
|
|
|
|
|
2013-05-30 08:00:20 +00:00
|
|
|
public: // for mLangRuleTable structures only
|
|
|
|
|
|
|
|
// Rule to handle xml:lang attributes, of which we have exactly one
|
|
|
|
// per language string, maintained in mLangRuleTable.
|
2015-05-25 00:40:00 +00:00
|
|
|
// We also create one extra rule for the "x-math" language string, used on
|
|
|
|
// <math> elements.
|
2015-03-21 16:28:04 +00:00
|
|
|
class LangRule final : public nsIStyleRule {
|
2014-06-23 22:40:01 +00:00
|
|
|
private:
|
|
|
|
~LangRule() {}
|
2013-05-30 08:00:20 +00:00
|
|
|
public:
|
2017-10-02 22:05:19 +00:00
|
|
|
explicit LangRule(nsAtom* aLang) : mLang(aLang) {}
|
2013-05-30 08:00:20 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleRule interface
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
|
2015-11-17 04:09:55 +00:00
|
|
|
virtual bool MightMapInheritedStyleData() override;
|
2016-08-17 01:37:48 +00:00
|
|
|
virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
|
2016-08-16 05:29:21 +00:00
|
|
|
nsCSSValue* aValue) override;
|
2013-05-30 08:00:20 +00:00
|
|
|
#ifdef DEBUG
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
|
2013-05-30 08:00:20 +00:00
|
|
|
#endif
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
RefPtr<nsAtom> mLang;
|
2013-05-30 08:00:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2010-05-18 04:00:39 +00:00
|
|
|
nsIDocument* mDocument;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HTMLColorRule> mLinkRule;
|
|
|
|
RefPtr<HTMLColorRule> mVisitedRule;
|
|
|
|
RefPtr<HTMLColorRule> mActiveRule;
|
2017-06-01 18:37:02 +00:00
|
|
|
RefPtr<RawServoDeclarationBlock> mServoUnvisitedLinkDecl;
|
|
|
|
RefPtr<RawServoDeclarationBlock> mServoVisitedLinkDecl;
|
|
|
|
RefPtr<RawServoDeclarationBlock> mServoActiveLinkDecl;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TableQuirkColorRule> mTableQuirkColorRule;
|
|
|
|
RefPtr<TableTHRule> mTableTHRule;
|
2004-04-12 21:56:09 +00:00
|
|
|
|
2015-05-19 23:46:17 +00:00
|
|
|
PLDHashTable mMappedAttrTable;
|
2017-01-19 23:56:53 +00:00
|
|
|
// Whether or not the mapped attributes table
|
|
|
|
// has been changed since the last call to
|
|
|
|
// CalculateMappedServoDeclarations()
|
|
|
|
bool mMappedAttrsDirty;
|
2015-05-19 23:46:17 +00:00
|
|
|
PLDHashTable mLangRuleTable;
|
2004-04-12 21:56:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsHTMLStyleSheet_h_) */
|