Bug 1309868 part 1 - Use const nsIContent pointer in some DOM utils. r?bholley
MozReview-Commit-ID: H4g2VbWJUba
--- a/dom/base/ChildIterator.cpp
+++ b/dom/base/ChildIterator.cpp
@@ -557,17 +557,17 @@ IsNativeAnonymousImplementationOfPseudoE
// Finally check the actual pseudo type.
bool isImpl = pseudoType != CSSPseudoElementType::NotPseudo;
MOZ_ASSERT_IF(isImpl, aContent->IsRootOfNativeAnonymousSubtree());
return isImpl;
}
/* static */ bool
-StyleChildrenIterator::IsNeeded(Element* aElement)
+StyleChildrenIterator::IsNeeded(const Element* aElement)
{
// If the node is in an anonymous subtree, we conservatively return true to
// handle insertion points.
if (aElement->IsInAnonymousSubtree()) {
return true;
}
// If the node has an XBL binding with anonymous content return true.
--- a/dom/base/ChildIterator.h
+++ b/dom/base/ChildIterator.h
@@ -30,17 +30,18 @@ namespace dom {
// <xbl:children> nodes replaced by the elements that have been filtered into that
// insertion point. Any bindings on the given element are ignored for purposes
// of determining which insertion point children are filtered into. The iterator
// can be initialized to start at the end by providing false for aStartAtBeginning
// in order to start iterating in reverse from the last child.
class ExplicitChildIterator
{
public:
- explicit ExplicitChildIterator(nsIContent* aParent, bool aStartAtBeginning = true)
+ explicit ExplicitChildIterator(const nsIContent* aParent,
+ bool aStartAtBeginning = true)
: mParent(aParent),
mChild(nullptr),
mDefaultChild(nullptr),
mIndexInInserted(0),
mIsFirst(aStartAtBeginning)
{
}
@@ -94,17 +95,17 @@ public:
// The inverse of GetNextChild. Properly steps in and out of insertion
// points.
nsIContent* GetPreviousChild();
protected:
// The parent of the children being iterated. For the FlattenedChildIterator,
// if there is a binding attached to the original parent, mParent points to
// the <xbl:content> element for the binding.
- nsIContent* mParent;
+ const nsIContent* mParent;
// The current child. When we encounter an insertion point,
// mChild remains as the insertion point whose content we're iterating (and
// our state is controled by mDefaultChild or mIndexInInserted depending on
// whether the insertion point expands to its default content or not).
nsIContent* mChild;
// If non-null, this points to the current default content for the current
@@ -131,17 +132,18 @@ protected:
// Iterates over the flattened children of a node, which accounts for anonymous
// children and nodes moved by insertion points. If a node has anonymous
// children, those are iterated over. The iterator can be initialized to start
// at the end by providing false for aStartAtBeginning in order to start
// iterating in reverse from the last child.
class FlattenedChildIterator : public ExplicitChildIterator
{
public:
- explicit FlattenedChildIterator(nsIContent* aParent, bool aStartAtBeginning = true)
+ explicit FlattenedChildIterator(const nsIContent* aParent,
+ bool aStartAtBeginning = true)
: ExplicitChildIterator(aParent, aStartAtBeginning), mXBLInvolved(false)
{
Init(false);
}
FlattenedChildIterator(FlattenedChildIterator&& aOther)
: ExplicitChildIterator(Move(aOther)), mXBLInvolved(aOther.mXBLInvolved) {}
@@ -150,17 +152,18 @@ public:
bool XBLInvolved() { return mXBLInvolved; }
protected:
/**
* This constructor is a hack to help AllChildrenIterator which sometimes
* doesn't want to consider XBL.
*/
- FlattenedChildIterator(nsIContent* aParent, uint32_t aFlags, bool aStartAtBeginning = true)
+ FlattenedChildIterator(const nsIContent* aParent, uint32_t aFlags,
+ bool aStartAtBeginning = true)
: ExplicitChildIterator(aParent, aStartAtBeginning), mXBLInvolved(false)
{
bool ignoreXBL = aFlags & nsIContent::eAllButXBL;
Init(ignoreXBL);
}
void Init(bool aIgnoreXBL);
@@ -176,17 +179,18 @@ protected:
* start iterating in reverse from the last child.
*
* Note: it assumes that no mutation of the DOM or frame tree takes place during
* iteration, and will break horribly if that is not true.
*/
class AllChildrenIterator : private FlattenedChildIterator
{
public:
- AllChildrenIterator(nsIContent* aNode, uint32_t aFlags, bool aStartAtBeginning = true) :
+ AllChildrenIterator(const nsIContent* aNode, uint32_t aFlags,
+ bool aStartAtBeginning = true) :
FlattenedChildIterator(aNode, aFlags, aStartAtBeginning),
mOriginalContent(aNode), mAnonKidsIdx(aStartAtBeginning ? UINT32_MAX : 0),
mFlags(aFlags), mPhase(aStartAtBeginning ? eAtBegin : eAtEnd) { }
AllChildrenIterator(AllChildrenIterator&& aOther)
: FlattenedChildIterator(Move(aOther)),
mOriginalContent(aOther.mOriginalContent),
mAnonKids(Move(aOther.mAnonKids)), mAnonKidsIdx(aOther.mAnonKidsIdx),
@@ -206,17 +210,17 @@ public:
// Seeks the given node in children of a parent element, starting from
// the current iterator's position, and sets the iterator at the given child
// node if it was found.
bool Seek(nsIContent* aChildToFind);
nsIContent* GetNextChild();
nsIContent* GetPreviousChild();
- nsIContent* Parent() const { return mOriginalContent; }
+ const nsIContent* Parent() const { return mOriginalContent; }
enum IteratorPhase
{
eAtBegin,
eAtBeforeKid,
eAtExplicitKids,
eAtAnonKids,
eAtAfterKid,
@@ -224,17 +228,17 @@ public:
};
IteratorPhase Phase() const { return mPhase; }
private:
// Helpers.
void AppendNativeAnonymousChildren();
void AppendNativeAnonymousChildrenFromFrame(nsIFrame* aFrame);
- nsIContent* mOriginalContent;
+ const nsIContent* mOriginalContent;
// mAnonKids is an array of native anonymous children, mAnonKidsIdx is index
// in the array. If mAnonKidsIdx < mAnonKids.Length() and mPhase is
// eAtAnonKids then the iterator points at a child at mAnonKidsIdx index. If
// mAnonKidsIdx == mAnonKids.Length() then the iterator is somewhere after
// the last native anon child. If mAnonKidsIdx == UINT32_MAX then the iterator
// is somewhere before the first native anon child.
nsTArray<nsIContent*> mAnonKids;
@@ -257,26 +261,26 @@ private:
* to implement pseudo-elements (since the style system needs to cascade those
* using different algorithms).
*
* Note: it assumes that no mutation of the DOM or frame tree takes place during
* iteration, and will break horribly if that is not true.
*/
class StyleChildrenIterator : private AllChildrenIterator {
public:
- explicit StyleChildrenIterator(nsIContent* aContent)
+ explicit StyleChildrenIterator(const nsIContent* aContent)
: AllChildrenIterator(aContent, nsIContent::eAllChildren)
{
MOZ_COUNT_CTOR(StyleChildrenIterator);
}
~StyleChildrenIterator() { MOZ_COUNT_DTOR(StyleChildrenIterator); }
nsIContent* GetNextChild();
// Returns true if we cannot find all the children we need to style by
// traversing the siblings of the first child.
- static bool IsNeeded(Element* aParent);
+ static bool IsNeeded(const Element* aParent);
};
} // namespace dom
} // namespace mozilla
#endif
--- a/dom/base/nsIContent.h
+++ b/dom/base/nsIContent.h
@@ -242,17 +242,17 @@ public:
* the term, i.e. not in an XHTML/XML document).
*/
inline bool IsInHTMLDocument() const;
/**
* Returns true if in a chrome document
*/
- virtual bool IsInChromeDocument();
+ virtual bool IsInChromeDocument() const;
/**
* Get the namespace that this element's tag is defined in
* @return the namespace
*/
inline int32_t GetNameSpaceID() const
{
return mNodeInfo->NamespaceID();
--- a/dom/base/nsIContentInlines.h
+++ b/dom/base/nsIContentInlines.h
@@ -14,17 +14,17 @@
inline bool
nsIContent::IsInHTMLDocument() const
{
return OwnerDoc()->IsHTMLDocument();
}
inline bool
-nsIContent::IsInChromeDocument()
+nsIContent::IsInChromeDocument() const
{
return nsContentUtils::IsChromeDoc(OwnerDoc());
}
inline mozilla::dom::ShadowRoot* nsIContent::GetShadowRoot() const
{
if (!IsElement()) {
return nullptr;
--- a/dom/xbl/nsBindingManager.cpp
+++ b/dom/xbl/nsBindingManager.cpp
@@ -120,17 +120,17 @@ nsBindingManager::nsBindingManager(nsIDo
}
nsBindingManager::~nsBindingManager(void)
{
mDestroyed = true;
}
nsXBLBinding*
-nsBindingManager::GetBindingWithContent(nsIContent* aContent)
+nsBindingManager::GetBindingWithContent(const nsIContent* aContent)
{
nsXBLBinding* binding = aContent ? aContent->GetXBLBinding() : nullptr;
return binding ? binding->GetBindingWithContent() : nullptr;
}
void
nsBindingManager::AddBoundContent(nsIContent* aContent)
{
--- a/dom/xbl/nsBindingManager.h
+++ b/dom/xbl/nsBindingManager.h
@@ -41,17 +41,17 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
explicit nsBindingManager(nsIDocument* aDocument);
- nsXBLBinding* GetBindingWithContent(nsIContent* aContent);
+ nsXBLBinding* GetBindingWithContent(const nsIContent* aContent);
void AddBoundContent(nsIContent* aContent);
void RemoveBoundContent(nsIContent* aContent);
/**
* Notify the binding manager that an element
* has been removed from its document,
* so that it can update any bindings or
--- a/layout/style/ServoElementSnapshot.h
+++ b/layout/style/ServoElementSnapshot.h
@@ -138,17 +138,17 @@ public:
if (mAttrs[i].mName.Equals(aLocalName, aNamespaceID)) {
return &mAttrs[i].mValue;
}
}
return nullptr;
}
- bool IsInChromeDocument()
+ bool IsInChromeDocument() const
{
return mIsInChromeDocument;
}
bool HasAny(Flags aFlags) { return bool(mContains & aFlags); }
private:
// TODO: Profile, a 1 or 2 element AutoTArray could be worth it, given we know