Bug 1331322 - Allow tagging of pseudo-implementing native anonymous content with the pseudo type at creation time

* Stop using a node bit for HasExplicitBaseURI
* Move MAY_HAVE_CLASS to mBoolFlags
* Add a flag to indicate that a node is native anonymous content
* Allow tagging of pseudo-implementing native anonymous content with the pseudo type at creation time, and eliminate explicit style contexts in nsIAnonymousContentCreator::ContentInfo

Tag #1375
This commit is contained in:
Matt A. Tobin 2020-04-16 16:37:28 -04:00 committed by Roy Tam
commit b723a5c8c4
25 changed files with 267 additions and 128 deletions

View file

@ -126,9 +126,28 @@ enum {
NODE_IS_EDITABLE = NODE_FLAG_BIT(7),
// For all Element nodes, NODE_MAY_HAVE_CLASS is guaranteed to be set if the
// node in fact has a class, but may be set even if it doesn't.
NODE_MAY_HAVE_CLASS = NODE_FLAG_BIT(8),
// This node was created by layout as native anonymous content. This
// generally corresponds to things created by nsIAnonymousContentCreator,
// though there are exceptions (svg:use content does not have this flag
// set, and any non-nsIAnonymousContentCreator callers of
// SetIsNativeAnonymousRoot also get this flag).
//
// One very important aspect here is that this node is not transitive over
// the subtree (if you want that, use NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE).
// If Gecko code somewhere attaches children to a node with this bit set,
// the children will not have the bit themselves unless the calling code sets
// it explicitly. This means that XBL content bound to NAC doesn't get this
// bit, nor do nodes inserted by editor.
//
// For now, this bit exists primarily to control style inheritance behavior,
// since the nodes for which we set it are often used to implement pseudo-
// elements, which need to inherit style from a script-visible element.
//
// A more general principle for this bit might be this: If the node is entirely
// a detail of layout, is not script-observable in any way, and other engines
// might accomplish the same task with a nodeless layout frame, then the node
// should have this bit set.
NODE_IS_NATIVE_ANONYMOUS = NODE_FLAG_BIT(8),
// Whether the node participates in a shadow tree.
NODE_IS_IN_SHADOW_TREE = NODE_FLAG_BIT(9),
@ -1211,6 +1230,15 @@ public:
#endif
}
/**
* Returns true if |this| is native anonymous (i.e. created by
* nsIAnonymousContentCreator);
*/
bool IsNativeAnonymous() const
{
return HasFlag(NODE_IS_NATIVE_ANONYMOUS);
}
/**
* Returns true if |this| or any of its ancestors is native anonymous.
*/
@ -1343,10 +1371,11 @@ public:
protected:
nsIURI* GetExplicitBaseURI() const {
if (HasExplicitBaseURI()) {
return static_cast<nsIURI*>(GetProperty(nsGkAtoms::baseURIProperty));
if (!HasProperties()) {
return nullptr;
}
return nullptr;
return static_cast<nsIURI*>(GetProperty(nsGkAtoms::baseURIProperty));
}
public:
@ -1549,6 +1578,8 @@ private:
// cases lie for nsXMLElement, such as when the node has been moved between
// documents with different id mappings.
ElementHasID,
// Set if the element might have a class.
ElementMayHaveClass,
// Set if the element might have inline style.
ElementMayHaveStyle,
// Set if the element has a name attribute set.
@ -1567,8 +1598,6 @@ private:
// Maybe set if the node is a root of a subtree
// which needs to be kept in the purple buffer.
NodeIsPurpleRoot,
// Set if the node has an explicit base URI stored
NodeHasExplicitBaseURI,
// Set if the element has some style states locked
ElementHasLockedStyleStates,
// Set if element has pointer locked
@ -1645,6 +1674,8 @@ public:
{ SetBoolFlag(NodeHasRenderingObservers, aValue); }
bool IsContent() const { return GetBoolFlag(NodeIsContent); }
bool HasID() const { return GetBoolFlag(ElementHasID); }
bool MayHaveClass() const { return GetBoolFlag(ElementMayHaveClass); }
void SetMayHaveClass() { SetBoolFlag(ElementMayHaveClass); }
bool MayHaveStyle() const { return GetBoolFlag(ElementMayHaveStyle); }
bool HasName() const { return GetBoolFlag(ElementHasName); }
bool MayHaveContentEditableAttr() const
@ -1774,8 +1805,6 @@ protected:
void ClearHasName() { ClearBoolFlag(ElementHasName); }
void SetMayHaveContentEditableAttr()
{ SetBoolFlag(ElementMayHaveContentEditableAttr); }
bool HasExplicitBaseURI() const { return GetBoolFlag(NodeHasExplicitBaseURI); }
void SetHasExplicitBaseURI() { SetBoolFlag(NodeHasExplicitBaseURI); }
void SetHasLockedStyleStates() { SetBoolFlag(ElementHasLockedStyleStates); }
void ClearHasLockedStyleStates() { ClearBoolFlag(ElementHasLockedStyleStates); }
bool HasLockedStyleStates() const