Bug 1287951: stylo: Know if a snapshot belongs to a HTML element in an HTML document at construction time. r=heycam
MozReview-Commit-ID: eN0j8vnesa
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -301,18 +301,16 @@ ServoRestyleManager::ReparentStyleContex
{
NS_WARNING("stylo: ServoRestyleManager::ReparentStyleContext not implemented");
return NS_OK;
}
ServoElementSnapshot*
ServoRestyleManager::SnapshotForElement(Element* aElement)
{
- ServoElementSnapshot* snapshot = mModifiedElements.LookupOrAdd(aElement);
- if (!snapshot->HasAny(
- ServoElementSnapshot::Flags::HTMLElementInHTMLDocument)) {
- snapshot->SetIsHTMLElementInHTMLDocument(
- aElement->IsHTMLElement() && aElement->OwnerDoc()->IsHTMLDocument());
+ auto* entry = mModifiedElements.PutEntry(aElement);
+ if (!entry->mData) {
+ entry->mData = new ServoElementSnapshot(aElement);
}
- return snapshot;
+ return entry->mData;
}
} // namespace mozilla
--- a/layout/style/ServoElementSnapshot.cpp
+++ b/layout/style/ServoElementSnapshot.cpp
@@ -1,19 +1,30 @@
/* -*- 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/. */
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/dom/Element.h"
+#include "nsIContentInlines.h"
namespace mozilla {
+ServoElementSnapshot::ServoElementSnapshot(Element* aElement)
+ : mContains(Flags(0))
+ , mState(0)
+ , mExplicitRestyleHint(nsRestyleHint(0))
+ , mExplicitChangeHint(nsChangeHint(0))
+{
+ mIsHTMLElementInHTMLDocument =
+ aElement->IsHTMLElement() && aElement->IsInHTMLDocument();
+}
+
void
ServoElementSnapshot::AddAttrs(Element* aElement)
{
MOZ_ASSERT(aElement);
if (!HasAny(Flags::Attributes)) {
return;
}
--- a/layout/style/ServoElementSnapshot.h
+++ b/layout/style/ServoElementSnapshot.h
@@ -41,18 +41,17 @@ struct ServoAttrSnapshot
/**
* A bitflags enum class used to determine what data does a ServoElementSnapshot
* contains.
*/
enum class ServoElementSnapshotFlags : uint8_t
{
State = 1 << 0,
Attributes = 1 << 1,
- HTMLElementInHTMLDocument = 1 << 2,
- All = State | Attributes | HTMLElementInHTMLDocument
+ All = State | Attributes
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ServoElementSnapshotFlags)
/**
* This class holds all non-tree-structural state of an element that might be
* used for selector matching eventually.
*
@@ -63,27 +62,17 @@ class ServoElementSnapshot
{
typedef dom::BorrowedAttrInfo BorrowedAttrInfo;
typedef dom::Element Element;
typedef EventStates::ServoType ServoStateType;
public:
typedef ServoElementSnapshotFlags Flags;
- /**
- * Empty snapshot, with no data at all.
- */
- ServoElementSnapshot()
- : mContains(Flags(0))
- , mState(0)
- , mExplicitRestyleHint(nsRestyleHint(0))
- , mExplicitChangeHint(nsChangeHint(0))
- , mIsHTMLElementInHTMLDocument(false)
- {
- }
+ explicit ServoElementSnapshot(Element* aElement);
bool HasAttrs() { return HasAny(Flags::Attributes); }
bool HasState() { return HasAny(Flags::State); }
/**
* Captures the given state (if not previously captured).
*/
@@ -149,24 +138,16 @@ public:
if (mAttrs[i].mName.Equals(aLocalName, aNamespaceID)) {
return &mAttrs[i].mValue;
}
}
return nullptr;
}
- void SetIsHTMLElementInHTMLDocument(bool aIs)
- {
- MOZ_ASSERT(!HasAny(Flags::HTMLElementInHTMLDocument),
- "Only expected to be set once!");
- mContains |= Flags::HTMLElementInHTMLDocument;
- mIsHTMLElementInHTMLDocument = aIs;
- }
-
bool HasAny(Flags aFlags) { return bool(mContains & aFlags); }
private:
// TODO: Profile, a 1 or 2 element AutoTArray could be worth it, given we know
// we're dealing with attribute changes when we take snapshots of attributes,
// though it can be wasted space if we deal with a lot of state-only
// snapshots.
Flags mContains;