1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/FrameChildList.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,126 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef FrameChildList_h_ 1.11 +#define FrameChildList_h_ 1.12 + 1.13 +#include "nsFrameList.h" 1.14 +#include "nsTArray.h" 1.15 + 1.16 +class nsIFrame; 1.17 + 1.18 +namespace mozilla { 1.19 +namespace layout { 1.20 + 1.21 +// enum FrameChildListID lives in nsFrameList.h to solve circular dependencies. 1.22 + 1.23 +#ifdef DEBUG_FRAME_DUMP 1.24 +extern const char* ChildListName(FrameChildListID aListID); 1.25 +#endif 1.26 + 1.27 +class FrameChildListIDs { 1.28 +friend class FrameChildListIterator; 1.29 + public: 1.30 + FrameChildListIDs() : mIDs(0) {} 1.31 + FrameChildListIDs(const FrameChildListIDs& aOther) : mIDs(aOther.mIDs) {} 1.32 + FrameChildListIDs(FrameChildListID aListID) : mIDs(aListID) {} 1.33 + 1.34 + FrameChildListIDs operator|(FrameChildListIDs aOther) const { 1.35 + return FrameChildListIDs(mIDs | aOther.mIDs); 1.36 + } 1.37 + FrameChildListIDs& operator|=(FrameChildListIDs aOther) { 1.38 + mIDs |= aOther.mIDs; 1.39 + return *this; 1.40 + } 1.41 + bool operator==(FrameChildListIDs aOther) const { 1.42 + return mIDs == aOther.mIDs; 1.43 + } 1.44 + bool operator!=(FrameChildListIDs aOther) const { 1.45 + return !(*this == aOther); 1.46 + } 1.47 + bool Contains(FrameChildListIDs aOther) const { 1.48 + return (mIDs & aOther.mIDs) == aOther.mIDs; 1.49 + } 1.50 + 1.51 + protected: 1.52 + FrameChildListIDs(uint32_t aIDs) : mIDs(aIDs) {} 1.53 + uint32_t mIDs; 1.54 +}; 1.55 + 1.56 +class FrameChildList { 1.57 + public: 1.58 + FrameChildList(const nsFrameList& aList, FrameChildListID aID) 1.59 + : mList(aList), mID(aID) {} 1.60 + nsFrameList mList; 1.61 + FrameChildListID mID; 1.62 +}; 1.63 + 1.64 +/** 1.65 + * A class to iterate frame child lists. 1.66 + */ 1.67 +class MOZ_STACK_CLASS FrameChildListArrayIterator { 1.68 + public: 1.69 + FrameChildListArrayIterator(const nsTArray<FrameChildList>& aLists) 1.70 + : mLists(aLists), mCurrentIndex(0) {} 1.71 + bool IsDone() const { return mCurrentIndex >= mLists.Length(); } 1.72 + FrameChildListID CurrentID() const { 1.73 + NS_ASSERTION(!IsDone(), "CurrentID(): iterator at end"); 1.74 + return mLists[mCurrentIndex].mID; 1.75 + } 1.76 + const nsFrameList& CurrentList() const { 1.77 + NS_ASSERTION(!IsDone(), "CurrentList(): iterator at end"); 1.78 + return mLists[mCurrentIndex].mList; 1.79 + } 1.80 + void Next() { 1.81 + NS_ASSERTION(!IsDone(), "Next(): iterator at end"); 1.82 + ++mCurrentIndex; 1.83 + } 1.84 + 1.85 +protected: 1.86 + const nsTArray<FrameChildList>& mLists; 1.87 + uint32_t mCurrentIndex; 1.88 +}; 1.89 + 1.90 +/** 1.91 + * A class for retrieving a frame's child lists and iterate them. 1.92 + */ 1.93 +class MOZ_STACK_CLASS FrameChildListIterator 1.94 + : public FrameChildListArrayIterator { 1.95 + public: 1.96 + FrameChildListIterator(const nsIFrame* aFrame); 1.97 + 1.98 +protected: 1.99 + nsAutoTArray<FrameChildList,4> mLists; 1.100 +}; 1.101 + 1.102 +inline mozilla::layout::FrameChildListIDs 1.103 +operator|(mozilla::layout::FrameChildListID aLeftOp, 1.104 + mozilla::layout::FrameChildListID aRightOp) 1.105 +{ 1.106 + return mozilla::layout::FrameChildListIDs(aLeftOp) | 1.107 + mozilla::layout::FrameChildListIDs(aRightOp); 1.108 +} 1.109 + 1.110 +inline mozilla::layout::FrameChildListIDs 1.111 +operator|(mozilla::layout::FrameChildListID aLeftOp, 1.112 + mozilla::layout::FrameChildListIDs aRightOp) 1.113 +{ 1.114 + return mozilla::layout::FrameChildListIDs(aLeftOp) | aRightOp; 1.115 +} 1.116 + 1.117 +} // namespace layout 1.118 +} // namespace mozilla 1.119 + 1.120 +inline void nsFrameList::AppendIfNonempty( 1.121 + nsTArray<mozilla::layout::FrameChildList>* aLists, 1.122 + mozilla::layout::FrameChildListID aListID) const 1.123 +{ 1.124 + if (NotEmpty()) { 1.125 + aLists->AppendElement(mozilla::layout::FrameChildList(*this, aListID)); 1.126 + } 1.127 +} 1.128 + 1.129 +#endif /* !defined(FrameChildList_h_) */