content/base/src/ChildIterator.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 sw=2 et tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef ChildIterator_h
michael@0 8 #define ChildIterator_h
michael@0 9
michael@0 10 /**
michael@0 11 * Iterates over the children on a node. If a child is an insertion point,
michael@0 12 * iterates over the children inserted there instead, or the default content
michael@0 13 * if no children are inserted there.
michael@0 14 *
michael@0 15 * The FlattenedChildIterator expands any anonymous content bound from an XBL
michael@0 16 * binding's <xbl:content> element.
michael@0 17 */
michael@0 18
michael@0 19 #include "nsIContent.h"
michael@0 20
michael@0 21 namespace mozilla {
michael@0 22 namespace dom {
michael@0 23
michael@0 24 // This class iterates normal DOM child nodes of a given DOM node with
michael@0 25 // <xbl:children> nodes replaced by the elements that have been filtered into that
michael@0 26 // insertion point. Any bindings on the given element are ignored for purposes
michael@0 27 // of determining which insertion point children are filtered into. The iterator
michael@0 28 // can be initialized to start at the end by providing false for aStartAtBeginning
michael@0 29 // in order to start iterating in reverse from the last child.
michael@0 30 class ExplicitChildIterator
michael@0 31 {
michael@0 32 public:
michael@0 33 ExplicitChildIterator(nsIContent* aParent, bool aStartAtBeginning = true)
michael@0 34 : mParent(aParent),
michael@0 35 mChild(nullptr),
michael@0 36 mDefaultChild(nullptr),
michael@0 37 mIndexInInserted(0),
michael@0 38 mIsFirst(aStartAtBeginning)
michael@0 39 {
michael@0 40 }
michael@0 41
michael@0 42 nsIContent* GetNextChild();
michael@0 43
michael@0 44 // Looks for aChildToFind respecting insertion points until aChildToFind
michael@0 45 // or aBound is found. If aBound is nullptr then the seek is unbounded. Returns
michael@0 46 // whether aChildToFind was found as an explicit child prior to encountering
michael@0 47 // aBound.
michael@0 48 bool Seek(nsIContent* aChildToFind, nsIContent* aBound = nullptr)
michael@0 49 {
michael@0 50 // It would be nice to assert that we find aChildToFind, but bz thinks that
michael@0 51 // we might not find aChildToFind when called from ContentInserted
michael@0 52 // if first-letter frames are about.
michael@0 53
michael@0 54 nsIContent* child;
michael@0 55 do {
michael@0 56 child = GetNextChild();
michael@0 57 } while (child && child != aChildToFind && child != aBound);
michael@0 58
michael@0 59 return child == aChildToFind;
michael@0 60 }
michael@0 61
michael@0 62 // Returns the current target of this iterator (which might be an explicit
michael@0 63 // child of the node, fallback content of an insertion point or
michael@0 64 // a node distributed to an insertion point.
michael@0 65 nsIContent* Get();
michael@0 66
michael@0 67 // The inverse of GetNextChild. Properly steps in and out of insertion
michael@0 68 // points.
michael@0 69 nsIContent* GetPreviousChild();
michael@0 70
michael@0 71 protected:
michael@0 72 // The parent of the children being iterated. For the FlattenedChildIterator,
michael@0 73 // if there is a binding attached to the original parent, mParent points to
michael@0 74 // the <xbl:content> element for the binding.
michael@0 75 nsIContent* mParent;
michael@0 76
michael@0 77 // The current child. When we encounter an insertion point,
michael@0 78 // mChild remains as the insertion point whose content we're iterating (and
michael@0 79 // our state is controled by mDefaultChild or mIndexInInserted depending on
michael@0 80 // whether the insertion point expands to its default content or not).
michael@0 81 nsIContent* mChild;
michael@0 82
michael@0 83 // If non-null, this points to the current default content for the current
michael@0 84 // insertion point that we're iterating (i.e. mChild, which must be an
michael@0 85 // nsXBLChildrenElement or HTMLContentElement). Once this transitions back
michael@0 86 // to null, we continue iterating at mChild's next sibling.
michael@0 87 nsIContent* mDefaultChild;
michael@0 88
michael@0 89 // If non-null, this points to an iterator of the explicit children of
michael@0 90 // the ShadowRoot projected by the current shadow element that we're
michael@0 91 // iterating.
michael@0 92 nsAutoPtr<ExplicitChildIterator> mShadowIterator;
michael@0 93
michael@0 94 // If not zero, we're iterating inserted children for an insertion point. This
michael@0 95 // is an index into mChild's inserted children array (mChild must be an
michael@0 96 // nsXBLChildrenElement). The index is one past the "current" child (as
michael@0 97 // opposed to mChild which represents the "current" child).
michael@0 98 uint32_t mIndexInInserted;
michael@0 99
michael@0 100 // A flag to let us know that we haven't started iterating yet.
michael@0 101 bool mIsFirst;
michael@0 102 };
michael@0 103
michael@0 104 // Iterates over the flattened children of a node, which accounts for anonymous
michael@0 105 // children and nodes moved by insertion points. If a node has anonymous
michael@0 106 // children, those are iterated over.
michael@0 107 class FlattenedChildIterator : public ExplicitChildIterator
michael@0 108 {
michael@0 109 public:
michael@0 110 FlattenedChildIterator(nsIContent* aParent);
michael@0 111
michael@0 112 bool XBLInvolved() { return mXBLInvolved; }
michael@0 113
michael@0 114 private:
michael@0 115 // For certain optimizations, nsCSSFrameConstructor needs to know if the
michael@0 116 // child list of the element that we're iterating matches its .childNodes.
michael@0 117 bool mXBLInvolved;
michael@0 118 };
michael@0 119
michael@0 120 } // namespace dom
michael@0 121 } // namespace mozilla
michael@0 122
michael@0 123 #endif

mercurial