CSSOrderAwareFrameIterator.cpp (2783B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* Iterator class for frame lists that respect CSS "order" during layout */ 8 9 #include "CSSOrderAwareFrameIterator.h" 10 11 #include "nsIFrameInlines.h" 12 13 static bool CanUse(const nsIFrame* aFrame) { 14 return aFrame->IsFlexOrGridContainer() || 15 (aFrame->GetContent() && aFrame->GetContent()->IsAnyOfXULElements( 16 nsGkAtoms::treecols, nsGkAtoms::treecol)); 17 } 18 19 namespace mozilla { 20 21 template <> 22 bool CSSOrderAwareFrameIterator::CanUse(const nsIFrame* aFrame) { 23 return ::CanUse(aFrame); 24 } 25 26 template <> 27 bool ReverseCSSOrderAwareFrameIterator::CanUse(const nsIFrame* aFrame) { 28 return ::CanUse(aFrame); 29 } 30 31 template <> 32 int CSSOrderAwareFrameIterator::CSSOrderComparator(nsIFrame* const& a, 33 nsIFrame* const& b) { 34 const auto o1 = a->StylePosition()->mOrder; 35 const auto o2 = b->StylePosition()->mOrder; 36 return (o1 > o2) - (o1 < o2); 37 } 38 39 template <> 40 int CSSOrderAwareFrameIterator::CSSBoxOrdinalGroupComparator( 41 nsIFrame* const& a, nsIFrame* const& b) { 42 const auto o1 = a->StyleXUL()->mBoxOrdinal; 43 const auto o2 = b->StyleXUL()->mBoxOrdinal; 44 return (o1 > o2) - (o1 < o2); 45 } 46 47 template <> 48 bool CSSOrderAwareFrameIterator::IsForward() const { 49 return true; 50 } 51 52 template <> 53 nsFrameList::iterator CSSOrderAwareFrameIterator::begin( 54 const nsFrameList& aList) { 55 return aList.begin(); 56 } 57 58 template <> 59 nsFrameList::iterator CSSOrderAwareFrameIterator::end( 60 const nsFrameList& aList) { 61 return aList.end(); 62 } 63 64 template <> 65 int ReverseCSSOrderAwareFrameIterator::CSSOrderComparator(nsIFrame* const& a, 66 nsIFrame* const& b) { 67 const auto o1 = a->StylePosition()->mOrder; 68 const auto o2 = b->StylePosition()->mOrder; 69 return (o2 > o1) - (o2 < o1); 70 } 71 72 template <> 73 int ReverseCSSOrderAwareFrameIterator::CSSBoxOrdinalGroupComparator( 74 nsIFrame* const& a, nsIFrame* const& b) { 75 const auto o1 = a->StyleXUL()->mBoxOrdinal; 76 const auto o2 = b->StyleXUL()->mBoxOrdinal; 77 return (o2 > o1) - (o2 < o1); 78 } 79 80 template <> 81 bool ReverseCSSOrderAwareFrameIterator::IsForward() const { 82 return false; 83 } 84 85 template <> 86 nsFrameList::reverse_iterator ReverseCSSOrderAwareFrameIterator::begin( 87 const nsFrameList& aList) { 88 return aList.rbegin(); 89 } 90 91 template <> 92 nsFrameList::reverse_iterator ReverseCSSOrderAwareFrameIterator::end( 93 const nsFrameList& aList) { 94 return aList.rend(); 95 } 96 97 } // namespace mozilla