Bug 1285474: stylo: Add dirtiness-tracking hooks for Servo and convenient methods. r=bholley

Also, guard with asserts the access to the new shared flags.

MozReview-Commit-ID: H9UFFHRPmiu
This commit is contained in:
Emilio Cobos Álvarez
2016-07-08 00:07:06 -07:00
parent 6fdfeb30ce
commit 948a479bad
9 changed files with 77 additions and 36 deletions

View File

@@ -1526,7 +1526,7 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
ClearSubtreeRootPointer();
// Being added to a document.
SetInDocument();
SetIsInDocument();
// Unset this flag since we now really are in a document.
UnsetFlags(NODE_FORCE_XBL_BINDINGS |

View File

@@ -1450,6 +1450,13 @@ inline const mozilla::dom::Element* nsINode::AsElement() const
return static_cast<const mozilla::dom::Element*>(this);
}
inline void nsINode::UnsetRestyleFlagsIfGecko()
{
if (IsElement() && !IsStyledByServo()) {
UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS);
}
}
/**
* Macros to implement Clone(). _elementName is the class for which to implement
* Clone.

View File

@@ -1460,7 +1460,10 @@ nsIDocument::nsIDocument()
mHasScrollLinkedEffect(false),
mUserHasInteracted(false)
{
SetInDocument();
SetIsDocument();
if (IsStyledByServo()) {
SetFlags(NODE_IS_DIRTY_FOR_SERVO | NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO);
}
PR_INIT_CLIST(&mDOMMediaQueryLists);
}

View File

@@ -540,7 +540,7 @@ nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
ClearSubtreeRootPointer();
// XXX See the comment in Element::BindToTree
SetInDocument();
SetIsInDocument();
if (mText.IsBidi()) {
aDocument->SetBidiEnabled();
}

View File

@@ -1003,6 +1003,7 @@ public:
SetFlags(NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO | NODE_IS_DIRTY_FOR_SERVO);
}
inline void UnsetRestyleFlagsIfGecko();
/**
* Adds a mutation observer to be notified when this node, or any of its
@@ -1726,7 +1727,17 @@ public:
}
protected:
void SetParentIsContent(bool aValue) { SetBoolFlag(ParentIsContent, aValue); }
void SetInDocument() { SetBoolFlag(IsInDocument); }
/**
* This is a special case of SetIsInDocument used to special-case it for the
* document constructor (which can't do the IsStyledByServo() check).
*/
void SetIsDocument() { SetBoolFlag(IsInDocument); }
void SetIsInDocument() {
if (IsStyledByServo()) {
SetIsDirtyAndHasDirtyDescendantsForServo();
}
SetBoolFlag(IsInDocument);
}
void SetNodeIsContent() { SetBoolFlag(NodeIsContent); }
void ClearInDocument() { ClearBoolFlag(IsInDocument); }
void SetIsElement() { SetBoolFlag(NodeIsElement); }

View File

@@ -2430,7 +2430,7 @@ nsCSSFrameConstructor::ConstructDocElementFrame(Element* aDocEle
// this document. Unlike in AddFrameConstructionItems, it's safe to
// unset all element restyle flags, since we don't have any
// siblings.
aDocElement->UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS);
aDocElement->UnsetRestyleFlagsIfGecko();
// --------- CREATE AREA OR BOX FRAME -------
// FIXME: Should this use ResolveStyleContext? (The calls in this
@@ -5513,7 +5513,7 @@ nsCSSFrameConstructor::ShouldCreateItemsForChild(nsFrameConstructorState& aState
nsContainerFrame* aParentFrame)
{
aContent->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME);
if (aContent->IsElement()) {
if (aContent->IsElement() && !aContent->IsStyledByServo()) {
// We can't just remove our pending restyle flags, since we may
// have restyle-later-siblings set on us. But we _can_ remove the
// "is possible restyle root" flags, and need to. Otherwise we can
@@ -10542,13 +10542,16 @@ nsCSSFrameConstructor::AddFCItemsForAnonymousContent(
"CreateAnonymousFrames manually and not follow the standard "
"ProcessChildren() codepath for this frame");
#endif
// Anything restyled by servo should already have the style data.
MOZ_ASSERT_IF(content->IsStyledByServo(), !!content->GetServoNodeData());
// Gecko-styled nodes should have no pending restyle flags.
MOZ_ASSERT_IF(!content->IsStyledByServo(),
!content->IsElement() ||
!(content->GetFlags() & ELEMENT_ALL_RESTYLE_FLAGS));
// Assert some things about this content
MOZ_ASSERT(!(content->GetFlags() &
(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME)),
"Should not be marked as needing frames");
MOZ_ASSERT(!content->IsElement() ||
!(content->GetFlags() & ELEMENT_ALL_RESTYLE_FLAGS),
"Should have no pending restyle flags");
MOZ_ASSERT(!content->GetPrimaryFrame(),
"Should have no existing frame");
MOZ_ASSERT(!content->IsNodeOfType(nsINode::eCOMMENT) &&
@@ -10696,9 +10699,7 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState,
// Frame construction item construction should not post
// restyles, so removing restyle flags here is safe.
if (child->IsElement()) {
child->UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS);
}
child->UnsetRestyleFlagsIfGecko();
if (addChildItems) {
AddFrameConstructionItems(aState, child, iter.XBLInvolved(), insertion,
itemsToConstruct);
@@ -12008,13 +12009,12 @@ nsCSSFrameConstructor::BuildInlineChildItems(nsFrameConstructorState& aState,
content->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
continue;
}
if (content->IsElement()) {
// See comment explaining why we need to remove the "is possible
// restyle root" flags in AddFrameConstructionItems. But note
// that we can remove all restyle flags, just like in
// ProcessChildren and for the same reason.
content->UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS);
}
content->UnsetRestyleFlagsIfGecko();
RefPtr<nsStyleContext> childContext =
ResolveStyleContext(parentStyleContext, content, &aState);

View File

@@ -279,9 +279,7 @@ nsHTMLFramesetFrame::Init(nsIContent* aContent,
for (uint32_t i = childX; i < numChildren; i++) {
nsIContent *child = mContent->GetChildAt(i);
child->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME);
if (child->IsElement()) {
child->UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS);
}
child->UnsetRestyleFlagsIfGecko();
}
break;
}
@@ -289,9 +287,7 @@ nsHTMLFramesetFrame::Init(nsIContent* aContent,
child->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME);
// Also clear the restyle flags in the child like
// nsCSSFrameConstructor::ProcessChildren does.
if (child->IsElement()) {
child->UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS);
}
child->UnsetRestyleFlagsIfGecko();
// IMPORTANT: This must match the conditions in
// nsCSSFrameConstructor::ContentAppended/Inserted/Removed

View File

@@ -164,6 +164,25 @@ Gecko_GetElementId(RawGeckoElement* aElement)
return attr ? attr->GetAtomValue() : nullptr;
}
// Dirtiness tracking.
uint32_t
Gecko_GetNodeFlags(RawGeckoNode* aNode)
{
return aNode->GetFlags();
}
void
Gecko_SetNodeFlags(RawGeckoNode* aNode, uint32_t aFlags)
{
aNode->SetFlags(aFlags);
}
void
Gecko_UnsetNodeFlags(RawGeckoNode* aNode, uint32_t aFlags)
{
aNode->UnsetFlags(aFlags);
}
template<class MatchFn>
bool
DoMatch(RawGeckoElement* aElement, nsIAtom* aNS, nsIAtom* aName, MatchFn aMatch)

View File

@@ -176,6 +176,11 @@ void Gecko_SetMozBinding(nsStyleDisplay* style_struct,
ThreadSafePrincipalHolder* principal);
void Gecko_CopyMozBindingFrom(nsStyleDisplay* des, const nsStyleDisplay* src);
// Dirtiness tracking.
uint32_t Gecko_GetNodeFlags(RawGeckoNode* node);
void Gecko_SetNodeFlags(RawGeckoNode* node, uint32_t flags);
void Gecko_UnsetNodeFlags(RawGeckoNode* node, uint32_t flags);
// Styleset and Stylesheet management.
//
// TODO: Make these return already_AddRefed and UniquePtr when the binding