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 #include "nsIFrameInlines.h"
11
CanUse(const nsIFrame * aFrame)12 static bool CanUse(const nsIFrame* aFrame) {
13 return aFrame->IsFlexOrGridContainer() || aFrame->IsXULBoxFrame() ||
14 (aFrame->GetContent() &&
15 aFrame->GetContent()->IsXULElement(nsGkAtoms::treecols));
16 }
17
18 namespace mozilla {
19
20 template <>
CanUse(const nsIFrame * aFrame)21 bool CSSOrderAwareFrameIterator::CanUse(const nsIFrame* aFrame) {
22 return ::CanUse(aFrame);
23 }
24
25 template <>
CanUse(const nsIFrame * aFrame)26 bool ReverseCSSOrderAwareFrameIterator::CanUse(const nsIFrame* aFrame) {
27 return ::CanUse(aFrame);
28 }
29
30 template <>
CSSOrderComparator(nsIFrame * const & a,nsIFrame * const & b)31 int CSSOrderAwareFrameIterator::CSSOrderComparator(nsIFrame* const& a,
32 nsIFrame* const& b) {
33 return a->StylePosition()->mOrder - b->StylePosition()->mOrder;
34 }
35
36 template <>
CSSBoxOrdinalGroupComparator(nsIFrame * const & a,nsIFrame * const & b)37 int CSSOrderAwareFrameIterator::CSSBoxOrdinalGroupComparator(
38 nsIFrame* const& a, nsIFrame* const& b) {
39 return a->StyleXUL()->mBoxOrdinal - b->StyleXUL()->mBoxOrdinal;
40 }
41
42 template <>
IsForward() const43 bool CSSOrderAwareFrameIterator::IsForward() const {
44 return true;
45 }
46
47 template <>
begin(const nsFrameList & aList)48 nsFrameList::iterator CSSOrderAwareFrameIterator::begin(
49 const nsFrameList& aList) {
50 return aList.begin();
51 }
52
53 template <>
end(const nsFrameList & aList)54 nsFrameList::iterator CSSOrderAwareFrameIterator::end(
55 const nsFrameList& aList) {
56 return aList.end();
57 }
58
59 template <>
CSSOrderComparator(nsIFrame * const & a,nsIFrame * const & b)60 int ReverseCSSOrderAwareFrameIterator::CSSOrderComparator(nsIFrame* const& a,
61 nsIFrame* const& b) {
62 return b->StylePosition()->mOrder - a->StylePosition()->mOrder;
63 }
64
65 template <>
CSSBoxOrdinalGroupComparator(nsIFrame * const & a,nsIFrame * const & b)66 int ReverseCSSOrderAwareFrameIterator::CSSBoxOrdinalGroupComparator(
67 nsIFrame* const& a, nsIFrame* const& b) {
68 return b->StyleXUL()->mBoxOrdinal - a->StyleXUL()->mBoxOrdinal;
69 }
70
71 template <>
IsForward() const72 bool ReverseCSSOrderAwareFrameIterator::IsForward() const {
73 return false;
74 }
75
76 template <>
begin(const nsFrameList & aList)77 nsFrameList::reverse_iterator ReverseCSSOrderAwareFrameIterator::begin(
78 const nsFrameList& aList) {
79 return aList.rbegin();
80 }
81
82 template <>
end(const nsFrameList & aList)83 nsFrameList::reverse_iterator ReverseCSSOrderAwareFrameIterator::end(
84 const nsFrameList& aList) {
85 return aList.rend();
86 }
87
88 } // namespace mozilla
89