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 namespace mozilla {
12 
13 template <>
CSSOrderComparator(nsIFrame * const & a,nsIFrame * const & b)14 bool CSSOrderAwareFrameIterator::CSSOrderComparator(nsIFrame* const& a,
15                                                     nsIFrame* const& b) {
16   return a->StylePosition()->mOrder < b->StylePosition()->mOrder;
17 }
18 
19 template <>
CSSBoxOrdinalGroupComparator(nsIFrame * const & a,nsIFrame * const & b)20 bool CSSOrderAwareFrameIterator::CSSBoxOrdinalGroupComparator(
21     nsIFrame* const& a, nsIFrame* const& b) {
22   return a->StyleXUL()->mBoxOrdinal < b->StyleXUL()->mBoxOrdinal;
23 }
24 
25 template <>
IsForward() const26 bool CSSOrderAwareFrameIterator::IsForward() const {
27   return true;
28 }
29 
30 template <>
begin(const nsFrameList & aList)31 nsFrameList::iterator CSSOrderAwareFrameIterator::begin(
32     const nsFrameList& aList) {
33   return aList.begin();
34 }
35 
36 template <>
end(const nsFrameList & aList)37 nsFrameList::iterator CSSOrderAwareFrameIterator::end(
38     const nsFrameList& aList) {
39   return aList.end();
40 }
41 
42 template <>
CSSOrderComparator(nsIFrame * const & a,nsIFrame * const & b)43 bool ReverseCSSOrderAwareFrameIterator::CSSOrderComparator(nsIFrame* const& a,
44                                                            nsIFrame* const& b) {
45   return a->StylePosition()->mOrder > b->StylePosition()->mOrder;
46 }
47 
48 template <>
CSSBoxOrdinalGroupComparator(nsIFrame * const & a,nsIFrame * const & b)49 bool ReverseCSSOrderAwareFrameIterator::CSSBoxOrdinalGroupComparator(
50     nsIFrame* const& a, nsIFrame* const& b) {
51   return a->StyleXUL()->mBoxOrdinal > b->StyleXUL()->mBoxOrdinal;
52 }
53 
54 template <>
IsForward() const55 bool ReverseCSSOrderAwareFrameIterator::IsForward() const {
56   return false;
57 }
58 
59 template <>
begin(const nsFrameList & aList)60 nsFrameList::reverse_iterator ReverseCSSOrderAwareFrameIterator::begin(
61     const nsFrameList& aList) {
62   return aList.rbegin();
63 }
64 
65 template <>
end(const nsFrameList & aList)66 nsFrameList::reverse_iterator ReverseCSSOrderAwareFrameIterator::end(
67     const nsFrameList& aList) {
68   return aList.rend();
69 }
70 
71 }  // namespace mozilla
72