mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 06:09:19 +00:00
Bug 1839255 - Clean up a bit the mapped attribute set-up. r=smaug
This doesn't change behavior on its own. It could be split up a bit more if needed though over all it shouldn't be hard to follow. Unify nsHTMLStyleSheet and nsHTMLCSSStyleSheet into AttributeStyles because the fact that we have two right now is pretty silly. They are also not stylesheets (they used to be pre-stylo). Differential Revision: https://phabricator.services.mozilla.com/D181414
This commit is contained in:
parent
ff25e3fe9e
commit
1c92ed74cb
@ -11,6 +11,7 @@
|
||||
|
||||
#include "AttrArray.h"
|
||||
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
@ -18,7 +19,6 @@
|
||||
|
||||
#include "nsMappedAttributeElement.h"
|
||||
#include "nsString.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsContentUtils.h" // nsAutoScriptBlocker
|
||||
@ -186,11 +186,8 @@ nsresult AttrArray::RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<nsMappedAttributes> mapped =
|
||||
GetModifiableMapped(nullptr, nullptr, false);
|
||||
|
||||
RefPtr<nsMappedAttributes> mapped = ModifiableMapped(nullptr, false);
|
||||
mapped->RemoveAttrAt(aPos - nonmapped, aValue);
|
||||
|
||||
return MakeMappedUnique(mapped);
|
||||
}
|
||||
|
||||
@ -289,33 +286,29 @@ int32_t AttrArray::IndexOfAttr(const nsAtom* aLocalName,
|
||||
nsresult AttrArray::SetAndSwapMappedAttr(nsAtom* aLocalName,
|
||||
nsAttrValue& aValue,
|
||||
nsMappedAttributeElement* aContent,
|
||||
nsHTMLStyleSheet* aSheet,
|
||||
bool* aHadValue) {
|
||||
bool willAdd = true;
|
||||
if (mImpl && mImpl->mMappedAttrs) {
|
||||
willAdd = !mImpl->mMappedAttrs->GetAttr(aLocalName);
|
||||
}
|
||||
|
||||
RefPtr<nsMappedAttributes> mapped =
|
||||
GetModifiableMapped(aContent, aSheet, willAdd);
|
||||
RefPtr<nsMappedAttributes> mapped = ModifiableMapped(aContent, willAdd);
|
||||
|
||||
mapped->SetAndSwapAttr(aLocalName, aValue, aHadValue);
|
||||
|
||||
return MakeMappedUnique(mapped);
|
||||
}
|
||||
|
||||
nsresult AttrArray::DoSetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet) {
|
||||
nsresult AttrArray::SetMappedAttributeStyles(
|
||||
mozilla::AttributeStyles* aNewStyles) {
|
||||
MOZ_ASSERT(mImpl && mImpl->mMappedAttrs, "Should have mapped attrs here!");
|
||||
if (aSheet == mImpl->mMappedAttrs->GetStyleSheet()) {
|
||||
if (aNewStyles == mImpl->mMappedAttrs->GetAttributeStyles()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<nsMappedAttributes> mapped =
|
||||
GetModifiableMapped(nullptr, nullptr, false);
|
||||
|
||||
mapped->DropStyleSheetReference();
|
||||
mapped->SetStyleSheet(aSheet);
|
||||
|
||||
RefPtr<nsMappedAttributes> mapped = ModifiableMapped(nullptr, false);
|
||||
mapped->DropAttributeStylesReference();
|
||||
mapped->SetAttributeStyles(aNewStyles);
|
||||
return MakeMappedUnique(mapped);
|
||||
}
|
||||
|
||||
@ -324,8 +317,7 @@ nsresult AttrArray::DoUpdateMappedAttrRuleMapper(
|
||||
MOZ_ASSERT(mImpl && mImpl->mMappedAttrs, "Should have mapped attrs here!");
|
||||
|
||||
// First two args don't matter if the assert holds.
|
||||
RefPtr<nsMappedAttributes> mapped =
|
||||
GetModifiableMapped(nullptr, nullptr, false);
|
||||
RefPtr<nsMappedAttributes> mapped = ModifiableMapped(nullptr, false);
|
||||
|
||||
mapped->SetRuleMapper(aElement.GetAttributeMappingFunction());
|
||||
|
||||
@ -360,11 +352,8 @@ uint32_t AttrArray::DoGetMappedAttrCount() const {
|
||||
return static_cast<uint32_t>(mImpl->mMappedAttrs->Count());
|
||||
}
|
||||
|
||||
nsresult AttrArray::ForceMapped(nsMappedAttributeElement* aContent,
|
||||
Document* aDocument) {
|
||||
nsHTMLStyleSheet* sheet = aDocument->GetAttributeStyleSheet();
|
||||
RefPtr<nsMappedAttributes> mapped =
|
||||
GetModifiableMapped(aContent, sheet, false, 0);
|
||||
nsresult AttrArray::ForceMapped(nsMappedAttributeElement* aContent) {
|
||||
RefPtr<nsMappedAttributes> mapped = ModifiableMapped(aContent, false, 0);
|
||||
return MakeMappedUnique(mapped);
|
||||
}
|
||||
|
||||
@ -374,9 +363,8 @@ void AttrArray::ClearMappedServoStyle() {
|
||||
}
|
||||
}
|
||||
|
||||
nsMappedAttributes* AttrArray::GetModifiableMapped(
|
||||
nsMappedAttributeElement* aContent, nsHTMLStyleSheet* aSheet,
|
||||
bool aWillAddAttr, int32_t aAttrCount) {
|
||||
nsMappedAttributes* AttrArray::ModifiableMapped(
|
||||
nsMappedAttributeElement* aContent, bool aWillAddAttr, int32_t aAttrCount) {
|
||||
if (mImpl && mImpl->mMappedAttrs) {
|
||||
return mImpl->mMappedAttrs->Clone(aWillAddAttr);
|
||||
}
|
||||
@ -385,7 +373,8 @@ nsMappedAttributes* AttrArray::GetModifiableMapped(
|
||||
|
||||
nsMapRuleToAttributesFunc mapRuleFunc =
|
||||
aContent->GetAttributeMappingFunction();
|
||||
return new (aAttrCount) nsMappedAttributes(aSheet, mapRuleFunc);
|
||||
return new (aAttrCount) nsMappedAttributes(
|
||||
aContent->OwnerDoc()->GetAttributeStyles(), mapRuleFunc);
|
||||
}
|
||||
|
||||
nsresult AttrArray::MakeMappedUnique(nsMappedAttributes* aAttributes) {
|
||||
@ -395,36 +384,30 @@ nsresult AttrArray::MakeMappedUnique(nsMappedAttributes* aAttributes) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (!aAttributes->GetStyleSheet()) {
|
||||
if (!aAttributes->GetAttributeStyles()) {
|
||||
// This doesn't currently happen, but it could if we do loading right
|
||||
|
||||
RefPtr<nsMappedAttributes> mapped(aAttributes);
|
||||
mapped.swap(mImpl->mMappedAttrs);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<nsMappedAttributes> mapped =
|
||||
aAttributes->GetStyleSheet()->UniqueMappedAttributes(aAttributes);
|
||||
aAttributes->GetAttributeStyles()->UniqueMappedAttributes(aAttributes);
|
||||
NS_ENSURE_TRUE(mapped, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
if (mapped != aAttributes) {
|
||||
// Reset the stylesheet of aAttributes so that it doesn't spend time
|
||||
// trying to remove itself from the hash. There is no risk that aAttributes
|
||||
// is in the hash since it will always have come from GetModifiableMapped,
|
||||
// is in the hash since it will always have come from ModifiableMapped,
|
||||
// which never returns maps that are in the hash (such hashes are by
|
||||
// nature not modifiable).
|
||||
aAttributes->DropStyleSheetReference();
|
||||
aAttributes->DropAttributeStylesReference();
|
||||
}
|
||||
mapped.swap(mImpl->mMappedAttrs);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsMappedAttributes* AttrArray::GetMapped() const {
|
||||
return mImpl ? mImpl->mMappedAttrs : nullptr;
|
||||
}
|
||||
|
||||
nsresult AttrArray::EnsureCapacityToClone(const AttrArray& aOther) {
|
||||
MOZ_ASSERT(!mImpl,
|
||||
"AttrArray::EnsureCapacityToClone requires the array be empty "
|
||||
|
@ -22,13 +22,13 @@
|
||||
#include "nsAttrValue.h"
|
||||
#include "nsCaseTreatment.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIContent;
|
||||
class nsMappedAttributes;
|
||||
class nsHTMLStyleSheet;
|
||||
class nsRuleWalker;
|
||||
class nsMappedAttributeElement;
|
||||
|
||||
namespace mozilla {
|
||||
class AttributeStyles;
|
||||
}
|
||||
|
||||
class AttrArray {
|
||||
using BorrowedAttrInfo = mozilla::dom::BorrowedAttrInfo;
|
||||
|
||||
@ -84,13 +84,7 @@ class AttrArray {
|
||||
// true.
|
||||
nsresult SetAndSwapMappedAttr(nsAtom* aLocalName, nsAttrValue& aValue,
|
||||
nsMappedAttributeElement* aContent,
|
||||
nsHTMLStyleSheet* aSheet, bool* aHadValue);
|
||||
nsresult SetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet) {
|
||||
if (!mImpl || !mImpl->mMappedAttrs) {
|
||||
return NS_OK;
|
||||
}
|
||||
return DoSetMappedAttrStyleSheet(aSheet);
|
||||
}
|
||||
bool* aHadValue);
|
||||
|
||||
// Update the rule mapping function on our mapped attributes, if we have any.
|
||||
// We take a nsMappedAttributeElement, not a nsMapRuleToAttributesFunc,
|
||||
@ -105,12 +99,13 @@ class AttrArray {
|
||||
void Compact();
|
||||
|
||||
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
bool HasMappedAttrs() const { return MappedAttrCount(); }
|
||||
const nsMappedAttributes* GetMapped() const;
|
||||
bool HasMappedAttrs() const { return !!GetMapped(); }
|
||||
const nsMappedAttributes* GetMapped() const {
|
||||
return mImpl ? mImpl->mMappedAttrs : nullptr;
|
||||
}
|
||||
|
||||
// Force this to have mapped attributes, even if those attributes are empty.
|
||||
nsresult ForceMapped(nsMappedAttributeElement* aContent,
|
||||
mozilla::dom::Document* aDocument);
|
||||
nsresult ForceMapped(nsMappedAttributeElement* aContent);
|
||||
|
||||
// Clear the servo declaration block on the mapped attributes, if any
|
||||
// Will assert off main thread
|
||||
@ -163,15 +158,17 @@ class AttrArray {
|
||||
return val && val->Equals(aValue, aCaseSensitive);
|
||||
}
|
||||
|
||||
nsresult SetMappedAttributeStyles(mozilla::AttributeStyles* aNewStyles);
|
||||
|
||||
struct InternalAttr {
|
||||
nsAttrName mName;
|
||||
nsAttrValue mValue;
|
||||
};
|
||||
|
||||
private:
|
||||
AttrArray(const AttrArray& aOther) = delete;
|
||||
AttrArray& operator=(const AttrArray& aOther) = delete;
|
||||
|
||||
private:
|
||||
uint32_t NonMappedAttrCount() const { return mImpl ? mImpl->mAttrCount : 0; }
|
||||
|
||||
uint32_t MappedAttrCount() const {
|
||||
@ -181,10 +178,9 @@ class AttrArray {
|
||||
uint32_t DoGetMappedAttrCount() const;
|
||||
|
||||
// Returns a non-null zero-refcount object.
|
||||
nsMappedAttributes* GetModifiableMapped(nsMappedAttributeElement* aContent,
|
||||
nsHTMLStyleSheet* aSheet,
|
||||
bool aWillAddAttr,
|
||||
int32_t aAttrCount = 1);
|
||||
nsMappedAttributes* ModifiableMapped(nsMappedAttributeElement* aContent,
|
||||
bool aWillAddAttr,
|
||||
int32_t aAttrCount = 1);
|
||||
nsresult MakeMappedUnique(nsMappedAttributes* aAttributes);
|
||||
|
||||
bool GrowBy(uint32_t aGrowSize);
|
||||
@ -199,11 +195,6 @@ class AttrArray {
|
||||
template <typename Name>
|
||||
nsresult AddNewAttribute(Name*, nsAttrValue&);
|
||||
|
||||
/**
|
||||
* Guts of SetMappedAttrStyleSheet for the rare case when we have mapped attrs
|
||||
*/
|
||||
nsresult DoSetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet);
|
||||
|
||||
/**
|
||||
* Guts of UpdateMappedAttrRuleMapper for the case when we have mapped attrs.
|
||||
*/
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include "mozilla/CycleCollectedJSContext.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/DocLoadingTimelineMarker.h"
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/DocumentStyleRootIterator.h"
|
||||
#include "mozilla/EditorBase.h"
|
||||
#include "mozilla/EditorCommands.h"
|
||||
@ -295,9 +296,7 @@
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsGlobalWindowInner.h"
|
||||
#include "nsGlobalWindowOuter.h"
|
||||
#include "nsHTMLCSSStyleSheet.h"
|
||||
#include "nsHTMLDocument.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsHtml5Module.h"
|
||||
#include "nsHtml5Parser.h"
|
||||
#include "nsHtml5TreeOpExecutor.h"
|
||||
@ -2379,8 +2378,8 @@ Document::~Document() {
|
||||
UnlinkStyleSheets(sheets);
|
||||
}
|
||||
|
||||
if (mAttrStyleSheet) {
|
||||
mAttrStyleSheet->SetOwningDocument(nullptr);
|
||||
if (mAttributeStyles) {
|
||||
mAttributeStyles->SetOwningDocument(nullptr);
|
||||
}
|
||||
|
||||
if (mListenerManager) {
|
||||
@ -3122,15 +3121,11 @@ void Document::ResetStylesheetsToURI(nsIURI* aURI) {
|
||||
}
|
||||
|
||||
// Now reset our inline style and attribute sheets.
|
||||
if (mAttrStyleSheet) {
|
||||
mAttrStyleSheet->Reset();
|
||||
mAttrStyleSheet->SetOwningDocument(this);
|
||||
if (mAttributeStyles) {
|
||||
mAttributeStyles->Reset();
|
||||
mAttributeStyles->SetOwningDocument(this);
|
||||
} else {
|
||||
mAttrStyleSheet = new nsHTMLStyleSheet(this);
|
||||
}
|
||||
|
||||
if (!mStyleAttrStyleSheet) {
|
||||
mStyleAttrStyleSheet = new nsHTMLCSSStyleSheet();
|
||||
mAttributeStyles = new AttributeStyles(this);
|
||||
}
|
||||
|
||||
if (mStyleSetFilled) {
|
||||
@ -15716,10 +15711,11 @@ void Document::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const {
|
||||
mResizeObserverController->AddSizeOfIncludingThis(aWindowSizes);
|
||||
}
|
||||
|
||||
aWindowSizes.mDOMSizes.mDOMOtherSize +=
|
||||
mAttrStyleSheet ? mAttrStyleSheet->DOMSizeOfIncludingThis(
|
||||
aWindowSizes.mState.mMallocSizeOf)
|
||||
: 0;
|
||||
if (mAttributeStyles) {
|
||||
aWindowSizes.mDOMSizes.mDOMOtherSize +=
|
||||
mAttributeStyles->DOMSizeOfIncludingThis(
|
||||
aWindowSizes.mState.mMallocSizeOf);
|
||||
}
|
||||
|
||||
aWindowSizes.mDOMSizes.mDOMOtherSize +=
|
||||
mStyledLinks.ShallowSizeOfExcludingThis(
|
||||
|
@ -143,9 +143,7 @@ class nsFrameLoader;
|
||||
class nsFrameLoaderOwner;
|
||||
class nsGenericHTMLElement;
|
||||
class nsGlobalWindowInner;
|
||||
class nsHTMLCSSStyleSheet;
|
||||
class nsHTMLDocument;
|
||||
class nsHTMLStyleSheet;
|
||||
class nsHtml5TreeOpExecutor;
|
||||
class nsIAppWindow;
|
||||
class nsIAsyncVerifyRedirectCallback;
|
||||
@ -188,6 +186,7 @@ struct nsFont;
|
||||
|
||||
namespace mozilla {
|
||||
class AbstractThread;
|
||||
class AttributeStyles;
|
||||
class StyleSheet;
|
||||
class EditorBase;
|
||||
class EditorCommand;
|
||||
@ -1733,15 +1732,7 @@ class Document : public nsINode,
|
||||
* Get this document's attribute stylesheet. May return null if
|
||||
* there isn't one.
|
||||
*/
|
||||
nsHTMLStyleSheet* GetAttributeStyleSheet() const { return mAttrStyleSheet; }
|
||||
|
||||
/**
|
||||
* Get this document's inline style sheet. May return null if there
|
||||
* isn't one
|
||||
*/
|
||||
nsHTMLCSSStyleSheet* GetInlineStyleSheet() const {
|
||||
return mStyleAttrStyleSheet;
|
||||
}
|
||||
AttributeStyles* GetAttributeStyles() const { return mAttributeStyles.get(); }
|
||||
|
||||
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject);
|
||||
|
||||
@ -4487,8 +4478,10 @@ class Document : public nsINode,
|
||||
nsNodeInfoManager* mNodeInfoManager;
|
||||
RefPtr<css::Loader> mCSSLoader;
|
||||
RefPtr<css::ImageLoader> mStyleImageLoader;
|
||||
RefPtr<nsHTMLStyleSheet> mAttrStyleSheet;
|
||||
RefPtr<nsHTMLCSSStyleSheet> mStyleAttrStyleSheet;
|
||||
|
||||
// The object that contains link color declarations (from the <body> mapped
|
||||
// attributes), mapped attribute caches, and inline style attribute caches.
|
||||
RefPtr<AttributeStyles> mAttributeStyles;
|
||||
|
||||
// Tracking for images in the document.
|
||||
RefPtr<dom::ImageTracker> mImageTracker;
|
||||
|
@ -2151,16 +2151,10 @@ DeclarationBlock* Element::GetInlineStyleDeclaration() const {
|
||||
return nullptr;
|
||||
}
|
||||
const nsAttrValue* attrVal = mAttrs.GetAttr(nsGkAtoms::style);
|
||||
|
||||
if (attrVal && attrVal->Type() == nsAttrValue::eCSSDeclaration) {
|
||||
return attrVal->GetCSSDeclarationValue();
|
||||
if (!attrVal || attrVal->Type() != nsAttrValue::eCSSDeclaration) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const nsMappedAttributes* Element::GetMappedAttributes() const {
|
||||
return mAttrs.GetMapped();
|
||||
return attrVal->GetCSSDeclarationValue();
|
||||
}
|
||||
|
||||
void Element::InlineStyleDeclarationWillChange(MutationClosureData& aData) {
|
||||
|
@ -387,7 +387,9 @@ class Element : public FragmentOrElement {
|
||||
/**
|
||||
* Get the mapped attributes, if any, for this element.
|
||||
*/
|
||||
const nsMappedAttributes* GetMappedAttributes() const;
|
||||
const nsMappedAttributes* GetMappedAttributes() const {
|
||||
return mAttrs.GetMapped();
|
||||
}
|
||||
|
||||
void ClearMappedServoStyle() { mAttrs.ClearMappedServoStyle(); }
|
||||
|
||||
|
@ -12,24 +12,24 @@
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/HashFunctions.h"
|
||||
|
||||
#include "mozilla/URLExtraData.h"
|
||||
#include "nsAttrValue.h"
|
||||
#include "nsAttrValueInlines.h"
|
||||
#include "nsAtom.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/BloomFilter.h"
|
||||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/DeclarationBlock.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/ServoBindingTypes.h"
|
||||
#include "mozilla/ServoUtils.h"
|
||||
#include "mozilla/ShadowParts.h"
|
||||
#include "mozilla/SVGAttrValueWrapper.h"
|
||||
#include "mozilla/DeclarationBlock.h"
|
||||
#include "mozilla/URLExtraData.h"
|
||||
#include "mozilla/dom/CSSRuleBinding.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsHTMLCSSStyleSheet.h"
|
||||
#include "nsStyledElement.h"
|
||||
#include "nsIURI.h"
|
||||
#include "ReferrerInfo.h"
|
||||
@ -103,8 +103,8 @@ void MiscContainer::Cache() {
|
||||
MOZ_ASSERT(mValue.mRefCount > 0);
|
||||
MOZ_ASSERT(!mValue.mCached);
|
||||
|
||||
nsHTMLCSSStyleSheet* sheet = mValue.mCSSDeclaration->GetHTMLCSSStyleSheet();
|
||||
if (!sheet) {
|
||||
AttributeStyles* attrStyles = mValue.mCSSDeclaration->GetAttributeStyles();
|
||||
if (!attrStyles) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ void MiscContainer::Cache() {
|
||||
return;
|
||||
}
|
||||
|
||||
sheet->CacheStyleAttr(str, this);
|
||||
attrStyles->CacheStyleAttr(str, this);
|
||||
mValue.mCached = 1;
|
||||
|
||||
// This has to be immutable once it goes into the cache.
|
||||
@ -134,14 +134,14 @@ void MiscContainer::Evict() {
|
||||
return;
|
||||
}
|
||||
|
||||
nsHTMLCSSStyleSheet* sheet = mValue.mCSSDeclaration->GetHTMLCSSStyleSheet();
|
||||
MOZ_ASSERT(sheet);
|
||||
AttributeStyles* attrStyles = mValue.mCSSDeclaration->GetAttributeStyles();
|
||||
MOZ_ASSERT(attrStyles);
|
||||
|
||||
nsString str;
|
||||
DebugOnly<bool> gotString = GetString(str);
|
||||
MOZ_ASSERT(gotString);
|
||||
|
||||
sheet->EvictStyleAttr(str, this);
|
||||
attrStyles->EvictStyleAttr(str, this);
|
||||
mValue.mCached = 0;
|
||||
}
|
||||
|
||||
@ -1704,7 +1704,7 @@ bool nsAttrValue::ParseStyleAttribute(const nsAString& aString,
|
||||
nsIPrincipal* aMaybeScriptedPrincipal,
|
||||
nsStyledElement* aElement) {
|
||||
dom::Document* doc = aElement->OwnerDoc();
|
||||
nsHTMLCSSStyleSheet* sheet = doc->GetInlineStyleSheet();
|
||||
AttributeStyles* attrStyles = doc->GetAttributeStyles();
|
||||
NS_ASSERTION(aElement->NodePrincipal() == doc->NodePrincipal(),
|
||||
"This is unexpected");
|
||||
|
||||
@ -1719,12 +1719,11 @@ bool nsAttrValue::ParseStyleAttribute(const nsAString& aString,
|
||||
// Similarly, if the triggering principal does not match the node principal,
|
||||
// do not cache the rule, since the principal will be encoded in any parsed
|
||||
// URLs in the rule.
|
||||
const bool cachingAllowed = sheet &&
|
||||
const bool cachingAllowed = attrStyles &&
|
||||
doc->GetDocumentURI() == data->BaseURI() &&
|
||||
principal == aElement->NodePrincipal();
|
||||
if (cachingAllowed) {
|
||||
MiscContainer* cont = sheet->LookupStyleAttr(aString);
|
||||
if (cont) {
|
||||
if (MiscContainer* cont = attrStyles->LookupStyleAttr(aString)) {
|
||||
// Set our MiscContainer to the cached one.
|
||||
NS_ADDREF(cont);
|
||||
SetPtrValueAndType(cont, eOtherBase);
|
||||
@ -1738,7 +1737,7 @@ bool nsAttrValue::ParseStyleAttribute(const nsAString& aString,
|
||||
if (!decl) {
|
||||
return false;
|
||||
}
|
||||
decl->SetHTMLCSSStyleSheet(sheet);
|
||||
decl->SetAttributeStyles(attrStyles);
|
||||
SetTo(decl.forget(), &aString);
|
||||
|
||||
if (cachingAllowed) {
|
||||
|
@ -5,15 +5,14 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsMappedAttributeElement.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
|
||||
bool nsMappedAttributeElement::SetAndSwapMappedAttribute(nsAtom* aName,
|
||||
nsAttrValue& aValue,
|
||||
bool* aValueWasSet,
|
||||
nsresult* aRetval) {
|
||||
nsHTMLStyleSheet* sheet = OwnerDoc()->GetAttributeStyleSheet();
|
||||
*aRetval =
|
||||
mAttrs.SetAndSwapMappedAttr(aName, aValue, this, sheet, aValueWasSet);
|
||||
*aRetval = mAttrs.SetAndSwapMappedAttr(aName, aValue, this, aValueWasSet);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -26,7 +25,8 @@ void nsMappedAttributeElement::MapNoAttributesInto(
|
||||
const nsMappedAttributes*, mozilla::MappedDeclarations&) {}
|
||||
|
||||
void nsMappedAttributeElement::NodeInfoChanged(Document* aOldDoc) {
|
||||
nsHTMLStyleSheet* sheet = OwnerDoc()->GetAttributeStyleSheet();
|
||||
mAttrs.SetMappedAttrStyleSheet(sheet);
|
||||
if (mAttrs.HasMappedAttrs()) {
|
||||
mAttrs.SetMappedAttributeStyles(OwnerDoc()->GetAttributeStyles());
|
||||
}
|
||||
nsMappedAttributeElementBase::NodeInfoChanged(aOldDoc);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/DeclarationBlock.h"
|
||||
#include "mozilla/HashFunctions.h"
|
||||
#include "mozilla/MappedDeclarations.h"
|
||||
@ -36,10 +36,10 @@ void nsMappedAttributes::Shutdown() {
|
||||
sCachedMappedAttributeAllocations = nullptr;
|
||||
}
|
||||
|
||||
nsMappedAttributes::nsMappedAttributes(nsHTMLStyleSheet* aSheet,
|
||||
nsMappedAttributes::nsMappedAttributes(AttributeStyles* aAttrStyles,
|
||||
nsMapRuleToAttributesFunc aMapRuleFunc)
|
||||
: mAttrCount(0),
|
||||
mSheet(aSheet),
|
||||
mAttrStyles(aAttrStyles),
|
||||
mRuleMapper(aMapRuleFunc),
|
||||
mServoStyle(nullptr) {
|
||||
MOZ_ASSERT(mRefCnt == 0); // Ensure caching works as expected.
|
||||
@ -47,7 +47,7 @@ nsMappedAttributes::nsMappedAttributes(nsHTMLStyleSheet* aSheet,
|
||||
|
||||
nsMappedAttributes::nsMappedAttributes(const nsMappedAttributes& aCopy)
|
||||
: mAttrCount(aCopy.mAttrCount),
|
||||
mSheet(aCopy.mSheet),
|
||||
mAttrStyles(aCopy.mAttrStyles),
|
||||
mRuleMapper(aCopy.mRuleMapper),
|
||||
// This is only called by ::Clone, which is used to create independent
|
||||
// nsMappedAttributes objects which should not share a DeclarationBlock
|
||||
@ -62,8 +62,8 @@ nsMappedAttributes::nsMappedAttributes(const nsMappedAttributes& aCopy)
|
||||
}
|
||||
|
||||
nsMappedAttributes::~nsMappedAttributes() {
|
||||
if (mSheet) {
|
||||
mSheet->DropMappedAttributes(this);
|
||||
if (mAttrStyles) {
|
||||
mAttrStyles->DropMappedAttributes(this);
|
||||
}
|
||||
|
||||
for (InternalAttr& attr : Attrs()) {
|
||||
@ -199,11 +199,11 @@ PLDHashNumber nsMappedAttributes::HashValue() const {
|
||||
return hash;
|
||||
}
|
||||
|
||||
void nsMappedAttributes::SetStyleSheet(nsHTMLStyleSheet* aSheet) {
|
||||
MOZ_ASSERT(!mSheet,
|
||||
void nsMappedAttributes::SetAttributeStyles(AttributeStyles* aAttrStyles) {
|
||||
MOZ_ASSERT(!mAttrStyles,
|
||||
"Should either drop the sheet reference manually, "
|
||||
"or drop the mapped attributes");
|
||||
mSheet = aSheet; // not ref counted
|
||||
mAttrStyles = aAttrStyles; // not ref counted
|
||||
}
|
||||
|
||||
void nsMappedAttributes::RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue) {
|
||||
@ -217,14 +217,8 @@ void nsMappedAttributes::RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue) {
|
||||
const nsAttrName* nsMappedAttributes::GetExistingAttrNameFromQName(
|
||||
const nsAString& aName) const {
|
||||
for (const InternalAttr& attr : Attrs()) {
|
||||
if (attr.mName.IsAtom()) {
|
||||
if (attr.mName.Atom()->Equals(aName)) {
|
||||
return &attr.mName;
|
||||
}
|
||||
} else {
|
||||
if (attr.mName.NodeInfo()->QualifiedNameEquals(aName)) {
|
||||
return &attr.mName;
|
||||
}
|
||||
if (attr.mName.Atom()->Equals(aName)) {
|
||||
return &attr.mName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,16 @@
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
||||
class nsAtom;
|
||||
class nsHTMLStyleSheet;
|
||||
|
||||
namespace mozilla {
|
||||
class AttributeStyles;
|
||||
}
|
||||
|
||||
class nsMappedAttributes final {
|
||||
using InternalAttr = AttrArray::InternalAttr;
|
||||
|
||||
public:
|
||||
nsMappedAttributes(nsHTMLStyleSheet* aSheet,
|
||||
nsMapRuleToAttributesFunc aMapRuleFunc);
|
||||
nsMappedAttributes(mozilla::AttributeStyles*, nsMapRuleToAttributesFunc);
|
||||
|
||||
// Do not return null.
|
||||
void* operator new(size_t size, uint32_t aAttrCount = 1) noexcept(true);
|
||||
@ -44,9 +46,9 @@ class nsMappedAttributes final {
|
||||
bool Equals(const nsMappedAttributes* aAttributes) const;
|
||||
PLDHashNumber HashValue() const;
|
||||
|
||||
void DropStyleSheetReference() { mSheet = nullptr; }
|
||||
void SetStyleSheet(nsHTMLStyleSheet* aSheet);
|
||||
nsHTMLStyleSheet* GetStyleSheet() { return mSheet; }
|
||||
void DropAttributeStylesReference() { mAttrStyles = nullptr; }
|
||||
void SetAttributeStyles(mozilla::AttributeStyles*);
|
||||
mozilla::AttributeStyles* GetAttributeStyles() { return mAttrStyles; }
|
||||
|
||||
void SetRuleMapper(nsMapRuleToAttributesFunc aRuleMapper) {
|
||||
mRuleMapper = aRuleMapper;
|
||||
@ -100,7 +102,7 @@ class nsMappedAttributes final {
|
||||
#ifdef DEBUG
|
||||
uint16_t mBufferSize;
|
||||
#endif
|
||||
nsHTMLStyleSheet* mSheet; // weak
|
||||
mozilla::AttributeStyles* mAttrStyles; // weak
|
||||
nsMapRuleToAttributesFunc mRuleMapper;
|
||||
RefPtr<mozilla::StyleLockedDeclarationBlock> mServoStyle;
|
||||
InternalAttr mBuffer[0];
|
||||
|
@ -5,20 +5,21 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "HTMLBodyElement.h"
|
||||
#include "mozilla/dom/BindContext.h"
|
||||
#include "mozilla/dom/HTMLBodyElementBinding.h"
|
||||
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/EditorBase.h"
|
||||
#include "mozilla/MappedDeclarations.h"
|
||||
#include "mozilla/HTMLEditor.h"
|
||||
#include "mozilla/MappedDeclarations.h"
|
||||
#include "mozilla/TextEditor.h"
|
||||
#include "mozilla/dom/BindContext.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsAttrValueInlines.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "DocumentInlines.h"
|
||||
#include "nsDocShell.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
@ -191,22 +192,21 @@ void HTMLBodyElement::MapAttributesIntoRule(
|
||||
}
|
||||
|
||||
// When display if first asked for, go ahead and get our colors set up.
|
||||
if (nsHTMLStyleSheet* styleSheet =
|
||||
aDecls.Document()->GetAttributeStyleSheet()) {
|
||||
if (AttributeStyles* attrStyles = aDecls.Document()->GetAttributeStyles()) {
|
||||
nscolor color;
|
||||
value = aAttributes->GetAttr(nsGkAtoms::link);
|
||||
if (value && value->GetColorValue(color)) {
|
||||
styleSheet->SetLinkColor(color);
|
||||
attrStyles->SetLinkColor(color);
|
||||
}
|
||||
|
||||
value = aAttributes->GetAttr(nsGkAtoms::alink);
|
||||
if (value && value->GetColorValue(color)) {
|
||||
styleSheet->SetActiveLinkColor(color);
|
||||
attrStyles->SetActiveLinkColor(color);
|
||||
}
|
||||
|
||||
value = aAttributes->GetAttr(nsGkAtoms::vlink);
|
||||
if (value && value->GetColorValue(color)) {
|
||||
styleSheet->SetVisitedLinkColor(color);
|
||||
attrStyles->SetVisitedLinkColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,7 +283,7 @@ bool HTMLBodyElement::IsEventAttributeNameInternal(nsAtom* aName) {
|
||||
nsresult HTMLBodyElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
||||
nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return mAttrs.ForceMapped(this, &aContext.OwnerDoc());
|
||||
return mAttrs.ForceMapped(this);
|
||||
}
|
||||
|
||||
void HTMLBodyElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
||||
@ -296,8 +296,11 @@ void HTMLBodyElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
||||
// If the last mapped attribute was removed, don't clear the
|
||||
// nsMappedAttributes, our style can still depend on the containing frame
|
||||
// element.
|
||||
//
|
||||
// FIXME(emilio, bug 1839333): Is this true? We don't store containing frame
|
||||
// stuff in nsMappedAttributes / AttributeStyles, maybe we can remove this?
|
||||
if (!aValue && IsAttributeMapped(aName)) {
|
||||
Unused << mAttrs.ForceMapped(this, OwnerDoc());
|
||||
Unused << mAttrs.ForceMapped(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@
|
||||
#include "mozilla/dom/MediaSource.h"
|
||||
|
||||
#include "mozilla/dom/BlobURLProtocolHandler.h"
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
|
||||
NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
|
||||
@ -188,9 +188,11 @@ void HTMLSourceElement::BuildMappedAttributesForImage() {
|
||||
mMappedAttributesForImage = nullptr;
|
||||
|
||||
Document* document = GetComposedDoc();
|
||||
nsHTMLStyleSheet* sheet =
|
||||
document ? document->GetAttributeStyleSheet() : nullptr;
|
||||
if (!sheet) {
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
AttributeStyles* attrStyles = document->GetAttributeStyles();
|
||||
if (!attrStyles) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -202,7 +204,7 @@ void HTMLSourceElement::BuildMappedAttributesForImage() {
|
||||
|
||||
const size_t count = (width ? 1 : 0) + (height ? 1 : 0);
|
||||
RefPtr<nsMappedAttributes> modifiableMapped(new (count) nsMappedAttributes(
|
||||
sheet, nsGenericHTMLElement::MapPictureSourceSizeAttributesInto));
|
||||
attrStyles, nsGenericHTMLElement::MapPictureSourceSizeAttributesInto));
|
||||
MOZ_ASSERT(modifiableMapped);
|
||||
|
||||
auto maybeSetAttr = [&](nsAtom* aName, const nsAttrValue* aValue) {
|
||||
@ -217,16 +219,16 @@ void HTMLSourceElement::BuildMappedAttributesForImage() {
|
||||
maybeSetAttr(nsGkAtoms::height, height);
|
||||
|
||||
RefPtr<nsMappedAttributes> newAttrs =
|
||||
sheet->UniqueMappedAttributes(modifiableMapped);
|
||||
attrStyles->UniqueMappedAttributes(modifiableMapped);
|
||||
NS_ENSURE_TRUE_VOID(newAttrs);
|
||||
|
||||
if (newAttrs != modifiableMapped) {
|
||||
// Reset the stylesheet of modifiableMapped so that it doesn't
|
||||
// spend time trying to remove itself from the hash. There is no
|
||||
// risk that modifiableMapped is in the hash since we created
|
||||
// it ourselves and it didn't come from the stylesheet (in which
|
||||
// case it would not have been modifiable).
|
||||
modifiableMapped->DropStyleSheetReference();
|
||||
// Reset the stylesheet of modifiableMapped so that it doesn't spend time
|
||||
// trying to remove itself from the hash. There is no risk that
|
||||
// modifiableMapped is in the hash since we created it ourselves and it
|
||||
// didn't come from the stylesheet (in which case it would not have been
|
||||
// modifiable).
|
||||
modifiableMapped->DropAttributeStylesReference();
|
||||
}
|
||||
|
||||
mMappedAttributesForImage = std::move(newAttrs);
|
||||
|
@ -5,9 +5,9 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/HTMLTableElement.h"
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/MappedDeclarations.h"
|
||||
#include "nsAttrValueInlines.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsWrapperCacheInlines.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
@ -955,36 +955,38 @@ void HTMLTableElement::BuildInheritedAttributes() {
|
||||
"potential leak, plus waste of work");
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
Document* document = GetComposedDoc();
|
||||
nsHTMLStyleSheet* sheet =
|
||||
document ? document->GetAttributeStyleSheet() : nullptr;
|
||||
RefPtr<nsMappedAttributes> newAttrs;
|
||||
if (sheet) {
|
||||
const nsAttrValue* value = mAttrs.GetAttr(nsGkAtoms::cellpadding);
|
||||
if (value) {
|
||||
RefPtr<nsMappedAttributes> modifiableMapped =
|
||||
new nsMappedAttributes(sheet, MapInheritedTableAttributesIntoRule);
|
||||
|
||||
if (modifiableMapped) {
|
||||
nsAttrValue val(*value);
|
||||
bool oldValueSet;
|
||||
modifiableMapped->SetAndSwapAttr(nsGkAtoms::cellpadding, val,
|
||||
&oldValueSet);
|
||||
}
|
||||
newAttrs = sheet->UniqueMappedAttributes(modifiableMapped);
|
||||
NS_ASSERTION(newAttrs, "out of memory, but handling gracefully");
|
||||
|
||||
if (newAttrs != modifiableMapped) {
|
||||
// Reset the stylesheet of modifiableMapped so that it doesn't
|
||||
// spend time trying to remove itself from the hash. There is no
|
||||
// risk that modifiableMapped is in the hash since we created
|
||||
// it ourselves and it didn't come from the stylesheet (in which
|
||||
// case it would not have been modifiable).
|
||||
modifiableMapped->DropStyleSheetReference();
|
||||
}
|
||||
}
|
||||
mTableInheritedAttributes = newAttrs;
|
||||
NS_IF_ADDREF(mTableInheritedAttributes);
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
AttributeStyles* attrStyles = document->GetAttributeStyles();
|
||||
if (!attrStyles) {
|
||||
return;
|
||||
}
|
||||
RefPtr<nsMappedAttributes> newAttrs;
|
||||
if (const nsAttrValue* value = mAttrs.GetAttr(nsGkAtoms::cellpadding)) {
|
||||
RefPtr<nsMappedAttributes> modifiableMapped =
|
||||
new nsMappedAttributes(attrStyles, MapInheritedTableAttributesIntoRule);
|
||||
|
||||
if (modifiableMapped) {
|
||||
nsAttrValue val(*value);
|
||||
bool oldValueSet;
|
||||
modifiableMapped->SetAndSwapAttr(nsGkAtoms::cellpadding, val,
|
||||
&oldValueSet);
|
||||
}
|
||||
newAttrs = attrStyles->UniqueMappedAttributes(modifiableMapped);
|
||||
NS_ASSERTION(newAttrs, "out of memory, but handling gracefully");
|
||||
|
||||
if (newAttrs != modifiableMapped) {
|
||||
// Reset the stylesheet of modifiableMapped so that it doesn't spend time
|
||||
// trying to remove itself from the hash. There is no risk that
|
||||
// modifiableMapped is in the hash since we created it ourselves and it
|
||||
// didn't come from the attrStyles (in which case it would not have been
|
||||
// modifiable).
|
||||
modifiableMapped->DropAttributeStylesReference();
|
||||
}
|
||||
}
|
||||
mTableInheritedAttributes = newAttrs;
|
||||
NS_IF_ADDREF(mTableInheritedAttributes);
|
||||
}
|
||||
|
||||
void HTMLTableElement::ReleaseInheritedAttributes() {
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "mozilla/dom/BindContext.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIFrameInlines.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIXMLContentSink.h"
|
||||
#include "nsHTMLParts.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
@ -1282,10 +1282,6 @@ void SVGElement::UpdateContentDeclarationBlock() {
|
||||
mContentDeclarationBlock = mappedAttrParser.TakeDeclarationBlock();
|
||||
}
|
||||
|
||||
const DeclarationBlock* SVGElement::GetContentDeclarationBlock() const {
|
||||
return mContentDeclarationBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper methods for the type-specific WillChangeXXX methods.
|
||||
*
|
||||
|
@ -332,7 +332,9 @@ class SVGElement : public SVGElementBase // nsIContent
|
||||
already_AddRefed<mozilla::dom::DOMSVGAnimatedString> ClassName();
|
||||
|
||||
void UpdateContentDeclarationBlock();
|
||||
const mozilla::DeclarationBlock* GetContentDeclarationBlock() const;
|
||||
const mozilla::DeclarationBlock* GetContentDeclarationBlock() const {
|
||||
return mContentDeclarationBlock.get();
|
||||
}
|
||||
|
||||
bool Autofocus() const { return GetBoolAttr(nsGkAtoms::autofocus); }
|
||||
void SetAutofocus(bool aAutofocus, ErrorResult& aRv) {
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsIContentSink.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsIFormControl.h"
|
||||
|
@ -4,31 +4,31 @@
|
||||
* 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/. */
|
||||
|
||||
/*
|
||||
* style sheet and style rule processor representing data from presentational
|
||||
* HTML attributes
|
||||
*/
|
||||
/* Data from presentational HTML attributes and style attributes */
|
||||
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/dom/DocumentInlines.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsError.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "mozilla/DeclarationBlock.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/OperatorNewExtensions.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/RestyleManager.h"
|
||||
#include "mozilla/ServoBindings.h"
|
||||
#include "mozilla/ServoStyleSet.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
struct MappedAttrTableEntry : public PLDHashEntryHdr {
|
||||
@ -45,8 +45,7 @@ static PLDHashNumber MappedAttrTable_HashKey(const void* key) {
|
||||
static void MappedAttrTable_ClearEntry(PLDHashTable* table,
|
||||
PLDHashEntryHdr* hdr) {
|
||||
MappedAttrTableEntry* entry = static_cast<MappedAttrTableEntry*>(hdr);
|
||||
|
||||
entry->mAttributes->DropStyleSheetReference();
|
||||
entry->mAttributes->DropAttributeStylesReference();
|
||||
memset(entry, 0, sizeof(MappedAttrTableEntry));
|
||||
}
|
||||
|
||||
@ -68,18 +67,17 @@ static const PLDHashTableOps MappedAttrTable_Ops = {
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
nsHTMLStyleSheet::nsHTMLStyleSheet(Document* aDocument)
|
||||
AttributeStyles::AttributeStyles(Document* aDocument)
|
||||
: mDocument(aDocument),
|
||||
mMappedAttrTable(&MappedAttrTable_Ops, sizeof(MappedAttrTableEntry)),
|
||||
mMappedAttrsDirty(false) {
|
||||
mMappedAttrTable(&MappedAttrTable_Ops, sizeof(MappedAttrTableEntry)) {
|
||||
MOZ_ASSERT(aDocument);
|
||||
}
|
||||
|
||||
void nsHTMLStyleSheet::SetOwningDocument(Document* aDocument) {
|
||||
void AttributeStyles::SetOwningDocument(Document* aDocument) {
|
||||
mDocument = aDocument; // not refcounted
|
||||
}
|
||||
|
||||
void nsHTMLStyleSheet::Reset() {
|
||||
void AttributeStyles::Reset() {
|
||||
mServoUnvisitedLinkDecl = nullptr;
|
||||
mServoVisitedLinkDecl = nullptr;
|
||||
mServoActiveLinkDecl = nullptr;
|
||||
@ -88,7 +86,7 @@ void nsHTMLStyleSheet::Reset() {
|
||||
mMappedAttrsDirty = false;
|
||||
}
|
||||
|
||||
nsresult nsHTMLStyleSheet::ImplLinkColorSetter(
|
||||
nsresult AttributeStyles::ImplLinkColorSetter(
|
||||
RefPtr<StyleLockedDeclarationBlock>& aDecl, nscolor aColor) {
|
||||
if (!mDocument || !mDocument->GetPresShell()) {
|
||||
return NS_OK;
|
||||
@ -107,24 +105,26 @@ nsresult nsHTMLStyleSheet::ImplLinkColorSetter(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsHTMLStyleSheet::SetLinkColor(nscolor aColor) {
|
||||
nsresult AttributeStyles::SetLinkColor(nscolor aColor) {
|
||||
return ImplLinkColorSetter(mServoUnvisitedLinkDecl, aColor);
|
||||
}
|
||||
|
||||
nsresult nsHTMLStyleSheet::SetActiveLinkColor(nscolor aColor) {
|
||||
nsresult AttributeStyles::SetActiveLinkColor(nscolor aColor) {
|
||||
return ImplLinkColorSetter(mServoActiveLinkDecl, aColor);
|
||||
}
|
||||
|
||||
nsresult nsHTMLStyleSheet::SetVisitedLinkColor(nscolor aColor) {
|
||||
nsresult AttributeStyles::SetVisitedLinkColor(nscolor aColor) {
|
||||
return ImplLinkColorSetter(mServoVisitedLinkDecl, aColor);
|
||||
}
|
||||
|
||||
already_AddRefed<nsMappedAttributes> nsHTMLStyleSheet::UniqueMappedAttributes(
|
||||
already_AddRefed<nsMappedAttributes> AttributeStyles::UniqueMappedAttributes(
|
||||
nsMappedAttributes* aMapped) {
|
||||
mMappedAttrsDirty = true;
|
||||
auto entry = static_cast<MappedAttrTableEntry*>(
|
||||
mMappedAttrTable.Add(aMapped, fallible));
|
||||
if (!entry) return nullptr;
|
||||
if (!entry) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!entry->mAttributes) {
|
||||
// We added a new entry to the hashtable, so we have a new unique set.
|
||||
entry->mAttributes = aMapped;
|
||||
@ -133,7 +133,7 @@ already_AddRefed<nsMappedAttributes> nsHTMLStyleSheet::UniqueMappedAttributes(
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
void nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped) {
|
||||
void AttributeStyles::DropMappedAttributes(nsMappedAttributes* aMapped) {
|
||||
NS_ENSURE_TRUE_VOID(aMapped);
|
||||
#ifdef DEBUG
|
||||
uint32_t entryCount = mMappedAttrTable.EntryCount() - 1;
|
||||
@ -144,7 +144,7 @@ void nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped) {
|
||||
NS_ASSERTION(entryCount == mMappedAttrTable.EntryCount(), "not removed");
|
||||
}
|
||||
|
||||
void nsHTMLStyleSheet::CalculateMappedServoDeclarations() {
|
||||
void AttributeStyles::CalculateMappedServoDeclarations() {
|
||||
for (auto iter = mMappedAttrTable.ConstIter(); !iter.Done(); iter.Next()) {
|
||||
MappedAttrTableEntry* attr = static_cast<MappedAttrTableEntry*>(iter.Get());
|
||||
if (attr->mAttributes->GetServoStyle()) {
|
||||
@ -155,7 +155,7 @@ void nsHTMLStyleSheet::CalculateMappedServoDeclarations() {
|
||||
}
|
||||
}
|
||||
|
||||
size_t nsHTMLStyleSheet::DOMSizeOfIncludingThis(
|
||||
size_t AttributeStyles::DOMSizeOfIncludingThis(
|
||||
MallocSizeOf aMallocSizeOf) const {
|
||||
size_t n = aMallocSizeOf(this);
|
||||
|
||||
@ -167,16 +167,34 @@ size_t nsHTMLStyleSheet::DOMSizeOfIncludingThis(
|
||||
|
||||
// Measurement of the following members may be added later if DMD finds it is
|
||||
// worthwhile:
|
||||
// - mURL
|
||||
// - mLinkRule
|
||||
// - mVisitedRule
|
||||
// - mActiveRule
|
||||
// - mTableQuirkColorRule
|
||||
// - mTableTHRule
|
||||
// - mLangRuleTable
|
||||
// - mServoUnvisitedLinkDecl;
|
||||
// - mServoVisitedLinkDecl;
|
||||
// - mServoActiveLinkDecl;
|
||||
//
|
||||
// The following members are not measured:
|
||||
// - mDocument, because it's non-owning
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
AttributeStyles::~AttributeStyles() {
|
||||
// We may go away before all of our cached style attributes do, so clean up
|
||||
// any that are left.
|
||||
for (auto iter = mCachedStyleAttrs.Iter(); !iter.Done(); iter.Next()) {
|
||||
MiscContainer*& value = iter.Data();
|
||||
|
||||
// Ideally we'd just call MiscContainer::Evict, but we can't do that since
|
||||
// we're iterating the hashtable.
|
||||
if (value->mType == nsAttrValue::eCSSDeclaration) {
|
||||
DeclarationBlock* declaration = value->mValue.mCSSDeclaration;
|
||||
declaration->SetAttributeStyles(nullptr);
|
||||
} else {
|
||||
MOZ_ASSERT_UNREACHABLE("unexpected cached nsAttrValue type");
|
||||
}
|
||||
|
||||
value->mValue.mCached = 0;
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
@ -9,8 +9,8 @@
|
||||
* HTML attributes
|
||||
*/
|
||||
|
||||
#ifndef nsHTMLStyleSheet_h_
|
||||
#define nsHTMLStyleSheet_h_
|
||||
#ifndef mozilla_AttributeStyles_h_
|
||||
#define mozilla_AttributeStyles_h_
|
||||
|
||||
#include "nsColor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@ -18,27 +18,25 @@
|
||||
#include "PLDHashTable.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "nsTHashMap.h"
|
||||
#include "nsString.h"
|
||||
|
||||
struct MiscContainer;
|
||||
class nsMappedAttributes;
|
||||
namespace mozilla {
|
||||
struct StyleLockedDeclarationBlock;
|
||||
namespace dom {
|
||||
class Document;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
class nsHTMLStyleSheet final {
|
||||
using StyleLockedDeclarationBlock = mozilla::StyleLockedDeclarationBlock;
|
||||
|
||||
class AttributeStyles final {
|
||||
public:
|
||||
explicit nsHTMLStyleSheet(mozilla::dom::Document* aDocument);
|
||||
explicit AttributeStyles(dom::Document* aDocument);
|
||||
void SetOwningDocument(dom::Document* aDocument);
|
||||
|
||||
void SetOwningDocument(mozilla::dom::Document* aDocument);
|
||||
NS_INLINE_DECL_REFCOUNTING(AttributeStyles)
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(nsHTMLStyleSheet)
|
||||
|
||||
size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
size_t DOMSizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
void Reset();
|
||||
nsresult SetLinkColor(nscolor aColor);
|
||||
@ -51,7 +49,7 @@ class nsHTMLStyleSheet final {
|
||||
const StyleLockedDeclarationBlock* GetServoVisitedLinkDecl() const {
|
||||
return mServoVisitedLinkDecl;
|
||||
}
|
||||
const mozilla::StyleLockedDeclarationBlock* GetServoActiveLinkDecl() const {
|
||||
const StyleLockedDeclarationBlock* GetServoActiveLinkDecl() const {
|
||||
return mServoActiveLinkDecl;
|
||||
}
|
||||
|
||||
@ -59,33 +57,45 @@ class nsHTMLStyleSheet final {
|
||||
already_AddRefed<nsMappedAttributes> UniqueMappedAttributes(
|
||||
nsMappedAttributes* aMapped);
|
||||
void DropMappedAttributes(nsMappedAttributes* aMapped);
|
||||
// For each mapped presentation attribute in the cache, resolve
|
||||
// the attached DeclarationBlock by running the mapping
|
||||
// and converting the ruledata to Servo specified values.
|
||||
// For each mapped presentation attribute in the cache, resolve the attached
|
||||
// DeclarationBlock by running the mapping to Servo specified values.
|
||||
void CalculateMappedServoDeclarations();
|
||||
|
||||
private:
|
||||
nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) = delete;
|
||||
nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) = delete;
|
||||
void CacheStyleAttr(const nsAString& aSerialized, MiscContainer* aValue) {
|
||||
mCachedStyleAttrs.InsertOrUpdate(aSerialized, aValue);
|
||||
}
|
||||
void EvictStyleAttr(const nsAString& aSerialized, MiscContainer* aValue) {
|
||||
NS_ASSERTION(LookupStyleAttr(aSerialized) == aValue,
|
||||
"Cached value doesn't match?");
|
||||
mCachedStyleAttrs.Remove(aSerialized);
|
||||
}
|
||||
MiscContainer* LookupStyleAttr(const nsAString& aSerialized) {
|
||||
return mCachedStyleAttrs.Get(aSerialized);
|
||||
}
|
||||
|
||||
~nsHTMLStyleSheet() = default;
|
||||
AttributeStyles(const AttributeStyles& aCopy) = delete;
|
||||
AttributeStyles& operator=(const AttributeStyles& aCopy) = delete;
|
||||
|
||||
private:
|
||||
~AttributeStyles();
|
||||
|
||||
// Implementation of SetLink/VisitedLink/ActiveLinkColor
|
||||
nsresult ImplLinkColorSetter(
|
||||
RefPtr<mozilla::StyleLockedDeclarationBlock>& aDecl, nscolor aColor);
|
||||
nsresult ImplLinkColorSetter(RefPtr<StyleLockedDeclarationBlock>& aDecl,
|
||||
nscolor aColor);
|
||||
|
||||
public: // for mLangRuleTable structures only
|
||||
private:
|
||||
mozilla::dom::Document* mDocument;
|
||||
dom::Document* mDocument;
|
||||
RefPtr<StyleLockedDeclarationBlock> mServoUnvisitedLinkDecl;
|
||||
RefPtr<StyleLockedDeclarationBlock> mServoVisitedLinkDecl;
|
||||
RefPtr<StyleLockedDeclarationBlock> mServoActiveLinkDecl;
|
||||
|
||||
PLDHashTable mMappedAttrTable;
|
||||
nsTHashMap<nsStringHashKey, MiscContainer*> mCachedStyleAttrs;
|
||||
// Whether or not the mapped attributes table
|
||||
// has been changed since the last call to
|
||||
// CalculateMappedServoDeclarations()
|
||||
bool mMappedAttrsDirty;
|
||||
bool mMappedAttrsDirty = false;
|
||||
};
|
||||
|
||||
#endif /* !defined(nsHTMLStyleSheet_h_) */
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
@ -18,10 +18,9 @@
|
||||
#include "nsCSSPropertyID.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsHTMLCSSStyleSheet;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class AttributeStyles;
|
||||
namespace css {
|
||||
class Declaration;
|
||||
class Rule;
|
||||
@ -124,22 +123,22 @@ class DeclarationBlock final {
|
||||
return mContainer.mOwningRule;
|
||||
}
|
||||
|
||||
void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aHTMLCSSStyleSheet) {
|
||||
MOZ_ASSERT(!mContainer.mHTMLCSSStyleSheet || !aHTMLCSSStyleSheet,
|
||||
void SetAttributeStyles(AttributeStyles* aAttributeStyles) {
|
||||
MOZ_ASSERT(!mContainer.mAttributeStyles || !aAttributeStyles,
|
||||
"should never overwrite one sheet with another");
|
||||
mContainer.mHTMLCSSStyleSheet = aHTMLCSSStyleSheet;
|
||||
if (aHTMLCSSStyleSheet) {
|
||||
mContainer.mAttributeStyles = aAttributeStyles;
|
||||
if (aAttributeStyles) {
|
||||
mContainer.mRaw |= uintptr_t(1);
|
||||
}
|
||||
}
|
||||
|
||||
nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() const {
|
||||
AttributeStyles* GetAttributeStyles() const {
|
||||
if (!(mContainer.mRaw & 0x1)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto c = mContainer;
|
||||
c.mRaw &= ~uintptr_t(1);
|
||||
return c.mHTMLCSSStyleSheet;
|
||||
return c.mAttributeStyles;
|
||||
}
|
||||
|
||||
bool IsReadOnly() const;
|
||||
@ -208,20 +207,18 @@ class DeclarationBlock final {
|
||||
bool OwnerIsReadOnly() const;
|
||||
|
||||
union {
|
||||
// We only ever have one of these since we have an
|
||||
// nsHTMLCSSStyleSheet only for style attributes, and style
|
||||
// attributes never have an owning rule.
|
||||
|
||||
// It's an nsHTMLCSSStyleSheet if the low bit is set.
|
||||
// We only ever have one of these since we have a AttributeStyles only for
|
||||
// style attributes, and style attributes never have an owning rule. It's a
|
||||
// AttributeStyles if the low bit is set.
|
||||
|
||||
uintptr_t mRaw;
|
||||
|
||||
// The style rule that owns this declaration. May be null.
|
||||
css::Rule* mOwningRule;
|
||||
|
||||
// The nsHTMLCSSStyleSheet that is responsible for this declaration.
|
||||
// Only non-null for style attributes.
|
||||
nsHTMLCSSStyleSheet* mHTMLCSSStyleSheet;
|
||||
// The AttributeStyles that is responsible for this declaration. Only
|
||||
// non-null for style attributes.
|
||||
AttributeStyles* mAttributeStyles;
|
||||
} mContainer;
|
||||
|
||||
RefPtr<StyleLockedDeclarationBlock> mRaw;
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "nsINode.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsFontMetrics.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsNameSpaceManager.h"
|
||||
#include "nsNetUtil.h"
|
||||
@ -45,6 +44,7 @@
|
||||
|
||||
#include "mozilla/css/ImageLoader.h"
|
||||
#include "mozilla/DeclarationBlock.h"
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/EffectCompositor.h"
|
||||
#include "mozilla/EffectSet.h"
|
||||
#include "mozilla/FontPropertyTypes.h"
|
||||
@ -391,17 +391,16 @@ void Gecko_UnsetDirtyStyleAttr(const Element* aElement) {
|
||||
|
||||
const StyleLockedDeclarationBlock*
|
||||
Gecko_GetHTMLPresentationAttrDeclarationBlock(const Element* aElement) {
|
||||
const nsMappedAttributes* attrs = aElement->GetMappedAttributes();
|
||||
if (!attrs) {
|
||||
if (auto* svg = SVGElement::FromNodeOrNull(aElement)) {
|
||||
if (const auto* decl = svg->GetContentDeclarationBlock()) {
|
||||
return decl->Raw();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
if (const nsMappedAttributes* attrs = aElement->GetMappedAttributes()) {
|
||||
MOZ_ASSERT(!aElement->IsSVGElement(), "SVG doesn't use nsMappedAttributes");
|
||||
return attrs->GetServoStyle();
|
||||
}
|
||||
|
||||
return attrs->GetServoStyle();
|
||||
if (const auto* svg = SVGElement::FromNode(aElement)) {
|
||||
if (const auto* decl = svg->GetContentDeclarationBlock()) {
|
||||
return decl->Raw();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const StyleLockedDeclarationBlock* Gecko_GetExtraContentStyleDeclarations(
|
||||
@ -421,12 +420,12 @@ const StyleLockedDeclarationBlock* Gecko_GetExtraContentStyleDeclarations(
|
||||
|
||||
const StyleLockedDeclarationBlock* Gecko_GetUnvisitedLinkAttrDeclarationBlock(
|
||||
const Element* aElement) {
|
||||
nsHTMLStyleSheet* sheet = aElement->OwnerDoc()->GetAttributeStyleSheet();
|
||||
if (!sheet) {
|
||||
AttributeStyles* attrStyles = aElement->OwnerDoc()->GetAttributeStyles();
|
||||
if (!attrStyles) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sheet->GetServoUnvisitedLinkDecl();
|
||||
return attrStyles->GetServoUnvisitedLinkDecl();
|
||||
}
|
||||
|
||||
StyleSheet* Gecko_StyleSheet_Clone(const StyleSheet* aSheet,
|
||||
@ -458,22 +457,20 @@ void Gecko_StyleSheet_Release(const StyleSheet* aSheet) {
|
||||
|
||||
const StyleLockedDeclarationBlock* Gecko_GetVisitedLinkAttrDeclarationBlock(
|
||||
const Element* aElement) {
|
||||
nsHTMLStyleSheet* sheet = aElement->OwnerDoc()->GetAttributeStyleSheet();
|
||||
if (!sheet) {
|
||||
AttributeStyles* attrStyles = aElement->OwnerDoc()->GetAttributeStyles();
|
||||
if (!attrStyles) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sheet->GetServoVisitedLinkDecl();
|
||||
return attrStyles->GetServoVisitedLinkDecl();
|
||||
}
|
||||
|
||||
const StyleLockedDeclarationBlock* Gecko_GetActiveLinkAttrDeclarationBlock(
|
||||
const Element* aElement) {
|
||||
nsHTMLStyleSheet* sheet = aElement->OwnerDoc()->GetAttributeStyleSheet();
|
||||
if (!sheet) {
|
||||
AttributeStyles* attrStyles = aElement->OwnerDoc()->GetAttributeStyles();
|
||||
if (!attrStyles) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sheet->GetServoActiveLinkDecl();
|
||||
return attrStyles->GetServoActiveLinkDecl();
|
||||
}
|
||||
|
||||
bool Gecko_GetAnimationRule(const Element* aElement,
|
||||
|
@ -16,10 +16,8 @@
|
||||
#include "nsISupports.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
struct nsRuleData;
|
||||
template <class T>
|
||||
struct already_AddRefed;
|
||||
class nsHTMLCSSStyleSheet;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "gfxPlatformFontList.h"
|
||||
#include "mozilla/AutoRestyleTimelineMarker.h"
|
||||
#include "mozilla/DocumentStyleRootIterator.h"
|
||||
#include "mozilla/AttributeStyles.h"
|
||||
#include "mozilla/EffectCompositor.h"
|
||||
#include "mozilla/IntegerRange.h"
|
||||
#include "mozilla/Keyframe.h"
|
||||
@ -48,7 +49,6 @@
|
||||
#include "nsCSSFrameConstructor.h"
|
||||
#include "nsCSSPseudoElements.h"
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsHTMLStyleSheet.h"
|
||||
#include "nsIAnonymousContentCreator.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
#include "mozilla/dom/DocumentInlines.h"
|
||||
@ -322,8 +322,8 @@ const ServoElementSnapshotTable& ServoStyleSet::Snapshots() {
|
||||
}
|
||||
|
||||
void ServoStyleSet::ResolveMappedAttrDeclarationBlocks() {
|
||||
if (nsHTMLStyleSheet* sheet = mDocument->GetAttributeStyleSheet()) {
|
||||
sheet->CalculateMappedServoDeclarations();
|
||||
if (AttributeStyles* attrStyles = mDocument->GetAttributeStyles()) {
|
||||
attrStyles->CalculateMappedServoDeclarations();
|
||||
}
|
||||
|
||||
mDocument->ResolveScheduledSVGPresAttrs();
|
||||
|
@ -68,6 +68,7 @@ EXPORTS += [
|
||||
EXPORTS.mozilla += [
|
||||
"!ServoCSSPropList.h",
|
||||
"AnimationCollection.h",
|
||||
"AttributeStyles.h",
|
||||
"CachedInheritingStyles.h",
|
||||
"ComputedStyle.h",
|
||||
"ComputedStyleInlines.h",
|
||||
@ -166,6 +167,7 @@ EXPORTS.mozilla.css += [
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"AnimationCollection.cpp",
|
||||
"AttributeStyles.cpp",
|
||||
"CachedInheritingStyles.cpp",
|
||||
"ComputedStyle.cpp",
|
||||
"CounterStyleManager.cpp",
|
||||
@ -220,8 +222,6 @@ UNIFIED_SOURCES += [
|
||||
"nsDOMCSSValueList.cpp",
|
||||
"nsFontFaceLoader.cpp",
|
||||
"nsFontFaceUtils.cpp",
|
||||
"nsHTMLCSSStyleSheet.cpp",
|
||||
"nsHTMLStyleSheet.cpp",
|
||||
"nsICSSDeclaration.cpp",
|
||||
"nsMediaFeatures.cpp",
|
||||
"nsROCSSPrimitiveValue.cpp",
|
||||
|
@ -1,65 +0,0 @@
|
||||
/* -*- 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
|
||||
* 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/. */
|
||||
|
||||
/*
|
||||
* style sheet and style rule processor representing style attributes
|
||||
*/
|
||||
|
||||
#include "nsHTMLCSSStyleSheet.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/DeclarationBlock.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsAttrValue.h"
|
||||
#include "nsAttrValueInlines.h"
|
||||
#include "nsCSSPseudoElements.h"
|
||||
#include "mozilla/RestyleManager.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet() = default;
|
||||
|
||||
nsHTMLCSSStyleSheet::~nsHTMLCSSStyleSheet() {
|
||||
// We may go away before all of our cached style attributes do,
|
||||
// so clean up any that are left.
|
||||
for (auto iter = mCachedStyleAttrs.Iter(); !iter.Done(); iter.Next()) {
|
||||
MiscContainer*& value = iter.Data();
|
||||
|
||||
// Ideally we'd just call MiscContainer::Evict, but we can't do that since
|
||||
// we're iterating the hashtable.
|
||||
if (value->mType == nsAttrValue::eCSSDeclaration) {
|
||||
DeclarationBlock* declaration = value->mValue.mCSSDeclaration;
|
||||
declaration->SetHTMLCSSStyleSheet(nullptr);
|
||||
} else {
|
||||
MOZ_ASSERT_UNREACHABLE("unexpected cached nsAttrValue type");
|
||||
}
|
||||
|
||||
value->mValue.mCached = 0;
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
void nsHTMLCSSStyleSheet::CacheStyleAttr(const nsAString& aSerialized,
|
||||
MiscContainer* aValue) {
|
||||
mCachedStyleAttrs.InsertOrUpdate(aSerialized, aValue);
|
||||
}
|
||||
|
||||
void nsHTMLCSSStyleSheet::EvictStyleAttr(const nsAString& aSerialized,
|
||||
MiscContainer* aValue) {
|
||||
#ifdef DEBUG
|
||||
{
|
||||
NS_ASSERTION(aValue == mCachedStyleAttrs.Get(aSerialized),
|
||||
"Cached value does not match?!");
|
||||
}
|
||||
#endif
|
||||
mCachedStyleAttrs.Remove(aSerialized);
|
||||
}
|
||||
|
||||
MiscContainer* nsHTMLCSSStyleSheet::LookupStyleAttr(
|
||||
const nsAString& aSerialized) {
|
||||
return mCachedStyleAttrs.Get(aSerialized);
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/* -*- 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
|
||||
* 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/. */
|
||||
|
||||
/*
|
||||
* style sheet and style rule processor representing style attributes
|
||||
*/
|
||||
|
||||
#ifndef nsHTMLCSSStyleSheet_h_
|
||||
#define nsHTMLCSSStyleSheet_h_
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
||||
#include "nsTHashMap.h"
|
||||
|
||||
class nsRuleWalker;
|
||||
struct MiscContainer;
|
||||
|
||||
namespace mozilla {
|
||||
enum class PseudoStyleType : uint8_t;
|
||||
namespace dom {
|
||||
class Element;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
class nsHTMLCSSStyleSheet final {
|
||||
public:
|
||||
nsHTMLCSSStyleSheet();
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(nsHTMLCSSStyleSheet)
|
||||
|
||||
void CacheStyleAttr(const nsAString& aSerialized, MiscContainer* aValue);
|
||||
void EvictStyleAttr(const nsAString& aSerialized, MiscContainer* aValue);
|
||||
MiscContainer* LookupStyleAttr(const nsAString& aSerialized);
|
||||
|
||||
private:
|
||||
~nsHTMLCSSStyleSheet();
|
||||
|
||||
nsHTMLCSSStyleSheet(const nsHTMLCSSStyleSheet& aCopy) = delete;
|
||||
nsHTMLCSSStyleSheet& operator=(const nsHTMLCSSStyleSheet& aCopy) = delete;
|
||||
|
||||
protected:
|
||||
nsTHashMap<nsStringHashKey, MiscContainer*> mCachedStyleAttrs;
|
||||
};
|
||||
|
||||
#endif /* !defined(nsHTMLCSSStyleSheet_h_) */
|
Loading…
x
Reference in New Issue
Block a user