2015-05-03 22:32:37 +03: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: */
|
2013-10-02 15:40:07 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsIContentInlines_h
|
|
|
|
#define nsIContentInlines_h
|
|
|
|
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#include "nsBindingManager.h"
|
2016-06-28 17:24:48 +03:00
|
|
|
#include "nsContentUtils.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2017-09-17 18:21:32 +03:00
|
|
|
#include "nsIFrame.h"
|
2016-08-19 05:30:53 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2017-12-31 22:57:32 +03:00
|
|
|
#include "mozilla/dom/HTMLSlotElement.h"
|
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2013-10-02 15:40:07 +04:00
|
|
|
|
|
|
|
inline bool
|
|
|
|
nsIContent::IsInHTMLDocument() const
|
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
return OwnerDoc()->IsHTMLDocument();
|
2013-10-02 15:40:07 +04:00
|
|
|
}
|
|
|
|
|
2016-06-28 17:24:48 +03:00
|
|
|
inline bool
|
2016-10-18 07:29:03 +03:00
|
|
|
nsIContent::IsInChromeDocument() const
|
2016-06-28 17:24:48 +03:00
|
|
|
{
|
|
|
|
return nsContentUtils::IsChromeDoc(OwnerDoc());
|
|
|
|
}
|
|
|
|
|
2017-09-17 18:21:32 +03:00
|
|
|
inline void
|
|
|
|
nsIContent::SetPrimaryFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInUncomposedDoc() || IsInShadowTree(), "This will end badly!");
|
2017-11-06 04:01:56 +03:00
|
|
|
|
|
|
|
// FIXME bug 749326
|
|
|
|
NS_ASSERTION(!aFrame || !mPrimaryFrame || aFrame == mPrimaryFrame,
|
|
|
|
"Losing track of existing primary frame");
|
2017-09-17 18:21:32 +03:00
|
|
|
|
|
|
|
if (aFrame) {
|
2017-11-07 03:20:34 +03:00
|
|
|
if (MOZ_LIKELY(!IsHTMLElement(nsGkAtoms::area)) ||
|
|
|
|
aFrame->GetContent() == this) {
|
|
|
|
aFrame->SetIsPrimaryFrame(true);
|
|
|
|
}
|
2017-09-17 18:21:32 +03:00
|
|
|
} else if (nsIFrame* currentPrimaryFrame = GetPrimaryFrame()) {
|
2017-11-07 03:20:34 +03:00
|
|
|
if (MOZ_LIKELY(!IsHTMLElement(nsGkAtoms::area)) ||
|
|
|
|
currentPrimaryFrame->GetContent() == this) {
|
|
|
|
currentPrimaryFrame->SetIsPrimaryFrame(false);
|
|
|
|
}
|
2017-09-17 18:21:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mPrimaryFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
2016-08-19 05:30:53 +03:00
|
|
|
inline mozilla::dom::ShadowRoot* nsIContent::GetShadowRoot() const
|
|
|
|
{
|
|
|
|
if (!IsElement()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
return AsElement()->GetShadowRoot();
|
2016-08-19 05:30:53 +03:00
|
|
|
}
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
template<nsINode::FlattenedParentType aType>
|
|
|
|
static inline nsINode*
|
|
|
|
GetFlattenedTreeParentNode(const nsINode* aNode)
|
2016-08-19 03:03:49 +03:00
|
|
|
{
|
2017-12-31 22:57:32 +03:00
|
|
|
if (!aNode->IsContent()) {
|
|
|
|
return nullptr;
|
2017-02-01 23:37:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
nsINode* parent = aNode->GetParentNode();
|
|
|
|
if (!parent || !parent->IsContent()) {
|
|
|
|
return parent;
|
2017-02-01 23:37:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
const nsIContent* content = aNode->AsContent();
|
|
|
|
nsIContent* parentAsContent = parent->AsContent();
|
|
|
|
|
|
|
|
if (aType == nsINode::eForStyle &&
|
|
|
|
content->IsRootOfNativeAnonymousSubtree() &&
|
Bug 1440258: Flag doc level anonymous content instead of guessing. r=bholley
Poking at the frame tree has problems: If we poke in negative (using
eSkipNativeAnonymousContent), as we were doing, we mess up the case where we're
actually _not_ doc-level, and _not_ ::before or ::after. This can't happen for
content documents, but can happen for chrome (since nsDocElementBoxFrame
implements nsIAnonymousContentCreator).
If we poke in positive, as we used to, you get that right, but mess up the
root scrollbar case.
Instead, use a node property to mark doc level anon content. This is a case rare
enough that it seems worth to not steal a node bit.
To recap the failure:
* The initial value of -moz-control-character-visiblity is different on beta
and nightly.
* XUL has a global rule setting -moz-control-character-visibility on the root,
to a value so that it's the initial one on nightly, but the non-initial one
on beta.
* Changes to this property cause a reframe.
* Reframes of a nsIAnonymousContentCreator anon content reframe the container.
* We were failing to inherit correctly for the nsIAnonymousContentCreator
content for the root XUL element on the initial styling, inheriting from the
default computed values instead, since we failed to reach the root element's
primary frame from GetFlattenedTreeParentForDocumentElementNAC ->
AppendDocumentLevelNativeAnonymousContentTo, since the primary frame is set
_after_ processing children.
This seems somewhat risky to change, and inconsistent with any other stuff
the frame constructor does, see bug 973390.
* Given that, the next restyle of the root element, in this case caused due to
the customizable UI, we _found_ the actual correct parent, recomputed the
style, saw that -moz-control-character-visiblity had changed, and reframed.
But we were reframing the whole window, not just the NAC, because of the
fourth bullet point. Reframing the whole window caused us to lose the popup
state (that's bug 1440506).
Worse than that is the fact that given we reframe and reconstruct the
anonymous countent again, we go back to the initial bogus state, just
awaiting for the next restyle to reframe the whole window.
I wish there was a bullet-proof way to test it that isn't just counting reframes
and relying on which properties reframe or not, but due to the nature of
nsIAnonymousContentCreator's NAC, it's not possible in any easy way I can think
of.
MozReview-Commit-ID: IPYB5trsN8R
2018-02-23 04:30:00 +03:00
|
|
|
parentAsContent == content->OwnerDoc()->GetRootElement()) {
|
|
|
|
const bool docLevel =
|
|
|
|
content->GetProperty(nsGkAtoms::docLevelNativeAnonymousContent);
|
|
|
|
return docLevel ? content->OwnerDocAsNode() : parent;
|
2017-02-01 23:37:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
if (content->IsRootOfAnonymousSubtree()) {
|
|
|
|
return parent;
|
|
|
|
}
|
2017-02-01 23:37:00 +03:00
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
if (parentAsContent->GetShadowRoot()) {
|
|
|
|
// If it's not assigned to any slot it's not part of the flat tree, and thus
|
|
|
|
// we return null.
|
|
|
|
return content->GetAssignedSlot();
|
2016-08-19 03:03:49 +03:00
|
|
|
}
|
2017-02-01 23:37:00 +03:00
|
|
|
|
2017-12-31 22:57:32 +03:00
|
|
|
if (parentAsContent->IsInShadowTree()) {
|
2018-03-22 00:39:04 +03:00
|
|
|
if (auto* slot = mozilla::dom::HTMLSlotElement::FromNode(parentAsContent)) {
|
2017-12-31 22:57:32 +03:00
|
|
|
// If the assigned nodes list is empty, we're fallback content which is
|
|
|
|
// active, otherwise we are not part of the flat tree.
|
|
|
|
return slot->AssignedNodes().IsEmpty()
|
|
|
|
? parent
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto* shadowRoot = mozilla::dom::ShadowRoot::FromNode(parentAsContent)) {
|
|
|
|
return shadowRoot->GetHost();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR) ||
|
|
|
|
parent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
|
|
|
if (nsIContent* xblInsertionPoint = content->GetXBLInsertionPoint()) {
|
|
|
|
return xblInsertionPoint->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->OwnerDoc()->BindingManager()->GetBindingWithContent(parentAsContent)) {
|
|
|
|
// This is an unassigned node child of the bound element, so it isn't part
|
|
|
|
// of the flat tree.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!parentAsContent->IsActiveChildrenElement(),
|
|
|
|
"<xbl:children> isn't in the flattened tree");
|
|
|
|
|
|
|
|
// Common case.
|
|
|
|
return parent;
|
2016-08-19 03:03:49 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 09:55:09 +03:00
|
|
|
inline nsINode*
|
|
|
|
nsINode::GetFlattenedTreeParentNode() const
|
|
|
|
{
|
2017-12-31 22:57:32 +03:00
|
|
|
return ::GetFlattenedTreeParentNode<nsINode::eNotForStyle>(this);
|
2016-12-01 09:55:09 +03:00
|
|
|
}
|
|
|
|
|
2016-08-19 03:03:49 +03:00
|
|
|
inline nsIContent*
|
|
|
|
nsIContent::GetFlattenedTreeParent() const
|
|
|
|
{
|
|
|
|
nsINode* parent = GetFlattenedTreeParentNode();
|
|
|
|
return (parent && parent->IsContent()) ? parent->AsContent() : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-04 23:54:30 +03:00
|
|
|
inline bool
|
2017-10-03 01:05:19 +03:00
|
|
|
nsIContent::IsEventAttributeName(nsAtom* aName)
|
2017-07-04 23:54:30 +03:00
|
|
|
{
|
|
|
|
const char16_t* name = aName->GetUTF16String();
|
|
|
|
if (name[0] != 'o' || name[1] != 'n') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IsEventAttributeNameInternal(aName);
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:55:09 +03:00
|
|
|
inline nsINode*
|
|
|
|
nsINode::GetFlattenedTreeParentNodeForStyle() const
|
|
|
|
{
|
2017-12-31 22:57:32 +03:00
|
|
|
return ::GetFlattenedTreeParentNode<nsINode::eForStyle>(this);
|
2016-12-01 09:55:09 +03:00
|
|
|
}
|
2016-08-19 05:30:53 +03:00
|
|
|
|
2017-06-20 06:24:59 +03:00
|
|
|
inline bool
|
|
|
|
nsINode::NodeOrAncestorHasDirAuto() const
|
|
|
|
{
|
|
|
|
return AncestorHasDirAuto() || (IsElement() && AsElement()->HasDirAuto());
|
|
|
|
}
|
|
|
|
|
2018-04-13 17:32:50 +03:00
|
|
|
inline bool
|
|
|
|
nsIContent::IsActiveChildrenElement() const
|
|
|
|
{
|
|
|
|
if (!mNodeInfo->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* bindingParent = GetBindingParent();
|
|
|
|
if (!bindingParent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-14 13:04:08 +03:00
|
|
|
// We reuse the binding parent machinery for Shadow DOM too, so prevent that
|
|
|
|
// from getting us confused in this case.
|
2018-04-13 17:32:50 +03:00
|
|
|
return !bindingParent->GetShadowRoot();
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:13:10 +03:00
|
|
|
inline bool
|
|
|
|
nsIContent::IsInAnonymousSubtree() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!IsInNativeAnonymousSubtree() || GetBindingParent() ||
|
|
|
|
(!IsInUncomposedDoc() &&
|
|
|
|
static_cast<nsIContent*>(SubtreeRoot())->IsInNativeAnonymousSubtree()),
|
|
|
|
"Must have binding parent when in native anonymous subtree which is in document.\n"
|
|
|
|
"Native anonymous subtree which is not in document must have native anonymous root.");
|
|
|
|
|
|
|
|
if (IsInNativeAnonymousSubtree()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* bindingParent = GetBindingParent();
|
|
|
|
if (!bindingParent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-14 13:04:08 +03:00
|
|
|
// We reuse the binding parent machinery for Shadow DOM too, so prevent that
|
|
|
|
// from getting us confused in this case.
|
2018-04-13 21:13:10 +03:00
|
|
|
return !bindingParent->GetShadowRoot();
|
|
|
|
}
|
|
|
|
|
2013-10-02 15:40:07 +04:00
|
|
|
#endif // nsIContentInlines_h
|