layout/generic/FrameChildList.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
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
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef FrameChildList_h_
michael@0 8 #define FrameChildList_h_
michael@0 9
michael@0 10 #include "nsFrameList.h"
michael@0 11 #include "nsTArray.h"
michael@0 12
michael@0 13 class nsIFrame;
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace layout {
michael@0 17
michael@0 18 // enum FrameChildListID lives in nsFrameList.h to solve circular dependencies.
michael@0 19
michael@0 20 #ifdef DEBUG_FRAME_DUMP
michael@0 21 extern const char* ChildListName(FrameChildListID aListID);
michael@0 22 #endif
michael@0 23
michael@0 24 class FrameChildListIDs {
michael@0 25 friend class FrameChildListIterator;
michael@0 26 public:
michael@0 27 FrameChildListIDs() : mIDs(0) {}
michael@0 28 FrameChildListIDs(const FrameChildListIDs& aOther) : mIDs(aOther.mIDs) {}
michael@0 29 FrameChildListIDs(FrameChildListID aListID) : mIDs(aListID) {}
michael@0 30
michael@0 31 FrameChildListIDs operator|(FrameChildListIDs aOther) const {
michael@0 32 return FrameChildListIDs(mIDs | aOther.mIDs);
michael@0 33 }
michael@0 34 FrameChildListIDs& operator|=(FrameChildListIDs aOther) {
michael@0 35 mIDs |= aOther.mIDs;
michael@0 36 return *this;
michael@0 37 }
michael@0 38 bool operator==(FrameChildListIDs aOther) const {
michael@0 39 return mIDs == aOther.mIDs;
michael@0 40 }
michael@0 41 bool operator!=(FrameChildListIDs aOther) const {
michael@0 42 return !(*this == aOther);
michael@0 43 }
michael@0 44 bool Contains(FrameChildListIDs aOther) const {
michael@0 45 return (mIDs & aOther.mIDs) == aOther.mIDs;
michael@0 46 }
michael@0 47
michael@0 48 protected:
michael@0 49 FrameChildListIDs(uint32_t aIDs) : mIDs(aIDs) {}
michael@0 50 uint32_t mIDs;
michael@0 51 };
michael@0 52
michael@0 53 class FrameChildList {
michael@0 54 public:
michael@0 55 FrameChildList(const nsFrameList& aList, FrameChildListID aID)
michael@0 56 : mList(aList), mID(aID) {}
michael@0 57 nsFrameList mList;
michael@0 58 FrameChildListID mID;
michael@0 59 };
michael@0 60
michael@0 61 /**
michael@0 62 * A class to iterate frame child lists.
michael@0 63 */
michael@0 64 class MOZ_STACK_CLASS FrameChildListArrayIterator {
michael@0 65 public:
michael@0 66 FrameChildListArrayIterator(const nsTArray<FrameChildList>& aLists)
michael@0 67 : mLists(aLists), mCurrentIndex(0) {}
michael@0 68 bool IsDone() const { return mCurrentIndex >= mLists.Length(); }
michael@0 69 FrameChildListID CurrentID() const {
michael@0 70 NS_ASSERTION(!IsDone(), "CurrentID(): iterator at end");
michael@0 71 return mLists[mCurrentIndex].mID;
michael@0 72 }
michael@0 73 const nsFrameList& CurrentList() const {
michael@0 74 NS_ASSERTION(!IsDone(), "CurrentList(): iterator at end");
michael@0 75 return mLists[mCurrentIndex].mList;
michael@0 76 }
michael@0 77 void Next() {
michael@0 78 NS_ASSERTION(!IsDone(), "Next(): iterator at end");
michael@0 79 ++mCurrentIndex;
michael@0 80 }
michael@0 81
michael@0 82 protected:
michael@0 83 const nsTArray<FrameChildList>& mLists;
michael@0 84 uint32_t mCurrentIndex;
michael@0 85 };
michael@0 86
michael@0 87 /**
michael@0 88 * A class for retrieving a frame's child lists and iterate them.
michael@0 89 */
michael@0 90 class MOZ_STACK_CLASS FrameChildListIterator
michael@0 91 : public FrameChildListArrayIterator {
michael@0 92 public:
michael@0 93 FrameChildListIterator(const nsIFrame* aFrame);
michael@0 94
michael@0 95 protected:
michael@0 96 nsAutoTArray<FrameChildList,4> mLists;
michael@0 97 };
michael@0 98
michael@0 99 inline mozilla::layout::FrameChildListIDs
michael@0 100 operator|(mozilla::layout::FrameChildListID aLeftOp,
michael@0 101 mozilla::layout::FrameChildListID aRightOp)
michael@0 102 {
michael@0 103 return mozilla::layout::FrameChildListIDs(aLeftOp) |
michael@0 104 mozilla::layout::FrameChildListIDs(aRightOp);
michael@0 105 }
michael@0 106
michael@0 107 inline mozilla::layout::FrameChildListIDs
michael@0 108 operator|(mozilla::layout::FrameChildListID aLeftOp,
michael@0 109 mozilla::layout::FrameChildListIDs aRightOp)
michael@0 110 {
michael@0 111 return mozilla::layout::FrameChildListIDs(aLeftOp) | aRightOp;
michael@0 112 }
michael@0 113
michael@0 114 } // namespace layout
michael@0 115 } // namespace mozilla
michael@0 116
michael@0 117 inline void nsFrameList::AppendIfNonempty(
michael@0 118 nsTArray<mozilla::layout::FrameChildList>* aLists,
michael@0 119 mozilla::layout::FrameChildListID aListID) const
michael@0 120 {
michael@0 121 if (NotEmpty()) {
michael@0 122 aLists->AppendElement(mozilla::layout::FrameChildList(*this, aListID));
michael@0 123 }
michael@0 124 }
michael@0 125
michael@0 126 #endif /* !defined(FrameChildList_h_) */

mercurial