1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:ts=8:et:sw=4:
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 /* a set of ranges on a number-line */
8 
9 #ifndef nsIntervalSet_h___
10 #define nsIntervalSet_h___
11 
12 #include "nsCoord.h"
13 
14 namespace mozilla {
15 class PresShell;
16 }  // namespace mozilla
17 
18 /*
19  * A list-based class (hopefully tree-based when I get around to it)
20  * for representing a set of ranges on a number-line.
21  */
22 class nsIntervalSet {
23  public:
24   typedef nscoord coord_type;
25 
26   explicit nsIntervalSet(mozilla::PresShell* aPresShell);
27   ~nsIntervalSet();
28 
29   /*
30    * Include the interval [aBegin, aEnd] in the set.
31    *
32    * Removal of intervals added is not supported because that would
33    * require keeping track of the individual intervals that were
34    * added (nsIntervalMap should do that).  It would be simple to
35    * implement ExcludeInterval if anyone wants it, though.
36    */
37   void IncludeInterval(coord_type aBegin, coord_type aEnd);
38 
39   /*
40    * Are _some_ points in [aBegin, aEnd] contained within the set
41    * of intervals?
42    */
43   bool Intersects(coord_type aBegin, coord_type aEnd) const;
44 
45   /*
46    * Are _all_ points in [aBegin, aEnd] contained within the set
47    * of intervals?
48    */
49   bool Contains(coord_type aBegin, coord_type aEnd) const;
50 
IsEmpty()51   bool IsEmpty() const { return !mList; }
52 
53  private:
54   class Interval {
55    public:
Interval(coord_type aBegin,coord_type aEnd)56     Interval(coord_type aBegin, coord_type aEnd)
57         : mBegin(aBegin), mEnd(aEnd), mPrev(nullptr), mNext(nullptr) {}
58 
59     coord_type mBegin;
60     coord_type mEnd;
61     Interval* mPrev;
62     Interval* mNext;
63   };
64 
65   void* AllocateInterval();
66   void FreeInterval(Interval* aInterval);
67 
68   Interval* mList;
69   mozilla::PresShell* mPresShell;
70 };
71 
72 #endif  // !defined(nsIntervalSet_h___)
73