DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d38398e5144e)

VCS Links

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/* -*- 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/. */

#ifndef nsIContentInlines_h
#define nsIContentInlines_h

#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsContentUtils.h"
#include "mozilla/dom/Element.h"

inline bool
nsIContent::IsInHTMLDocument() const
{
  return OwnerDoc()->IsHTMLDocument();
}

inline bool
nsIContent::IsInChromeDocument() const
{
  return nsContentUtils::IsChromeDoc(OwnerDoc());
}

inline mozilla::dom::ShadowRoot* nsIContent::GetShadowRoot() const
{
  if (!IsElement()) {
    return nullptr;
  }

  return AsElement()->FastGetShadowRoot();
}

template<nsIContent::FlattenedParentType Type>
static inline bool FlattenedTreeParentIsParent(const nsINode* aNode)
{
  // Try to short-circuit past the complicated and not-exactly-fast logic for
  // computing the flattened parent.
  //
  // 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();
  }

  MOZ_ASSERT(aNode->IsContent());
  return aNode->AsContent()->GetFlattenedTreeParentNodeInternal(Type);
}

inline nsINode*
nsINode::GetFlattenedTreeParentNode() const
{
  return ::GetFlattenedTreeParentNode<nsIContent::eNotForStyle>(this);
}

inline nsIContent*
nsIContent::GetFlattenedTreeParent() const
{
  nsINode* parent = GetFlattenedTreeParentNode();
  return (parent && parent->IsContent()) ? parent->AsContent() : nullptr;
}

inline nsINode*
nsINode::GetFlattenedTreeParentNodeForStyle() const
{
  return ::GetFlattenedTreeParentNode<nsIContent::eForStyle>(this);
}

#endif // nsIContentInlines_h