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"
|
2016-06-28 17:24:48 +03:00
|
|
|
#include "nsContentUtils.h"
|
2016-08-19 05:30:53 +03:00
|
|
|
#include "mozilla/dom/Element.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());
|
|
|
|
}
|
|
|
|
|
2016-08-19 05:30:53 +03:00
|
|
|
inline mozilla::dom::ShadowRoot* nsIContent::GetShadowRoot() const
|
|
|
|
{
|
|
|
|
if (!IsElement()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AsElement()->FastGetShadowRoot();
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:55:09 +03:00
|
|
|
template<nsIContent::FlattenedParentType Type>
|
2017-02-01 23:37:00 +03:00
|
|
|
static inline bool FlattenedTreeParentIsParent(const nsINode* aNode)
|
2016-08-19 03:03:49 +03:00
|
|
|
{
|
|
|
|
// Try to short-circuit past the complicated and not-exactly-fast logic for
|
|
|
|
// computing the flattened parent.
|
|
|
|
//
|
2017-02-01 23:37:00 +03:00
|
|
|
// WARNING! This logic is replicated in Servo to avoid out of line calls.
|
|
|
|
// If you change the cases here, you need to change them in Servo as well!
|
|
|
|
|
|
|
|
// Check if the node is an explicit child of an XBL-bound element, re-bound to
|
|
|
|
// an XBL insertion point, or is a top-level element in a shadow tree, whose
|
|
|
|
// flattened parent is the host element (as opposed to the actual parent which
|
|
|
|
// is the shadow root).
|
|
|
|
if (aNode->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR | NODE_IS_IN_SHADOW_TREE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we want the flattened parent for style, and the node is the root
|
|
|
|
// of a native anonymous content subtree parented to the document's root element.
|
|
|
|
if (Type == nsIContent::eForStyle && aNode->HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT) &&
|
|
|
|
aNode->OwnerDoc()->GetRootElement() == aNode->GetParentNode())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the node is an explicit child of an element with a shadow root,
|
|
|
|
// re-bound to an insertion point.
|
|
|
|
nsIContent* parent = aNode->GetParent();
|
|
|
|
if (parent && parent->GetShadowRoot()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Common case.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<nsIContent::FlattenedParentType Type>
|
|
|
|
static inline nsINode*
|
|
|
|
GetFlattenedTreeParentNode(const nsINode* aNode)
|
|
|
|
{
|
|
|
|
if (MOZ_LIKELY(FlattenedTreeParentIsParent<Type>(aNode))) {
|
|
|
|
return aNode->GetParentNode();
|
2016-08-19 03:03:49 +03:00
|
|
|
}
|
2017-02-01 23:37:00 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(aNode->IsContent());
|
|
|
|
return aNode->AsContent()->GetFlattenedTreeParentNodeInternal(Type);
|
2016-08-19 03:03:49 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 09:55:09 +03:00
|
|
|
inline nsINode*
|
|
|
|
nsINode::GetFlattenedTreeParentNode() const
|
|
|
|
{
|
|
|
|
return ::GetFlattenedTreeParentNode<nsIContent::eNotForStyle>(this);
|
|
|
|
}
|
|
|
|
|
2016-08-19 03:03:49 +03:00
|
|
|
inline nsIContent*
|
|
|
|
nsIContent::GetFlattenedTreeParent() const
|
|
|
|
{
|
|
|
|
nsINode* parent = GetFlattenedTreeParentNode();
|
|
|
|
return (parent && parent->IsContent()) ? parent->AsContent() : nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:55:09 +03:00
|
|
|
inline nsINode*
|
|
|
|
nsINode::GetFlattenedTreeParentNodeForStyle() const
|
|
|
|
{
|
|
|
|
return ::GetFlattenedTreeParentNode<nsIContent::eForStyle>(this);
|
|
|
|
}
|
2016-08-19 05:30:53 +03:00
|
|
|
|
2013-10-02 15:40:07 +04:00
|
|
|
#endif // nsIContentInlines_h
|