/work/obj-fuzz/dist/include/mozilla/dom/DOMRect.h
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef MOZILLA_DOMRECT_H_ |
8 | | #define MOZILLA_DOMRECT_H_ |
9 | | |
10 | | #include "nsTArray.h" |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsWrapperCache.h" |
13 | | #include "nsCycleCollectionParticipant.h" |
14 | | #include "mozilla/Attributes.h" |
15 | | #include "mozilla/dom/BindingDeclarations.h" |
16 | | #include "mozilla/ErrorResult.h" |
17 | | #include <algorithm> |
18 | | |
19 | | struct nsRect; |
20 | | |
21 | | namespace mozilla { |
22 | | namespace dom { |
23 | | |
24 | | class DOMRectReadOnly : public nsISupports |
25 | | , public nsWrapperCache |
26 | | { |
27 | | protected: |
28 | 0 | virtual ~DOMRectReadOnly() {} |
29 | | |
30 | | public: |
31 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
32 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectReadOnly) |
33 | | |
34 | | explicit DOMRectReadOnly(nsISupports* aParent, double aX = 0, double aY = 0, |
35 | | double aWidth = 0, double aHeight = 0) |
36 | | : mParent(aParent) |
37 | | , mX(aX) |
38 | | , mY(aY) |
39 | | , mWidth(aWidth) |
40 | | , mHeight(aHeight) |
41 | 0 | { |
42 | 0 | } |
43 | | |
44 | | nsISupports* GetParentObject() const |
45 | 0 | { |
46 | 0 | MOZ_ASSERT(mParent); |
47 | 0 | return mParent; |
48 | 0 | } |
49 | | |
50 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
51 | | |
52 | | static already_AddRefed<DOMRectReadOnly> |
53 | | Constructor(const GlobalObject& aGlobal, double aX, double aY, |
54 | | double aWidth, double aHeight, ErrorResult& aRv); |
55 | | |
56 | | double X() const |
57 | 0 | { |
58 | 0 | return mX; |
59 | 0 | } |
60 | | double Y() const |
61 | 0 | { |
62 | 0 | return mY; |
63 | 0 | } |
64 | | double Width() const |
65 | 0 | { |
66 | 0 | return mWidth; |
67 | 0 | } |
68 | | double Height() const |
69 | 0 | { |
70 | 0 | return mHeight; |
71 | 0 | } |
72 | | |
73 | | double Left() const |
74 | 0 | { |
75 | 0 | double x = X(), w = Width(); |
76 | 0 | return std::min(x, x + w); |
77 | 0 | } |
78 | | double Top() const |
79 | 0 | { |
80 | 0 | double y = Y(), h = Height(); |
81 | 0 | return std::min(y, y + h); |
82 | 0 | } |
83 | | double Right() const |
84 | 0 | { |
85 | 0 | double x = X(), w = Width(); |
86 | 0 | return std::max(x, x + w); |
87 | 0 | } |
88 | | double Bottom() const |
89 | 0 | { |
90 | 0 | double y = Y(), h = Height(); |
91 | 0 | return std::max(y, y + h); |
92 | 0 | } |
93 | | |
94 | | protected: |
95 | | nsCOMPtr<nsISupports> mParent; |
96 | | double mX, mY, mWidth, mHeight; |
97 | | }; |
98 | | |
99 | | class DOMRect final : public DOMRectReadOnly |
100 | | { |
101 | | public: |
102 | | explicit DOMRect(nsISupports* aParent, double aX = 0, double aY = 0, |
103 | | double aWidth = 0, double aHeight = 0) |
104 | | : DOMRectReadOnly(aParent, aX, aY, aWidth, aHeight) |
105 | 0 | { |
106 | 0 | } |
107 | | |
108 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(DOMRect, DOMRectReadOnly) |
109 | | |
110 | | static already_AddRefed<DOMRect> |
111 | | Constructor(const GlobalObject& aGlobal, double aX, double aY, |
112 | | double aWidth, double aHeight, ErrorResult& aRv); |
113 | | |
114 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
115 | | |
116 | 0 | void SetRect(float aX, float aY, float aWidth, float aHeight) { |
117 | 0 | mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight; |
118 | 0 | } |
119 | | void SetLayoutRect(const nsRect& aLayoutRect); |
120 | | |
121 | | void SetX(double aX) |
122 | 0 | { |
123 | 0 | mX = aX; |
124 | 0 | } |
125 | | void SetY(double aY) |
126 | 0 | { |
127 | 0 | mY = aY; |
128 | 0 | } |
129 | | void SetWidth(double aWidth) |
130 | 0 | { |
131 | 0 | mWidth = aWidth; |
132 | 0 | } |
133 | | void SetHeight(double aHeight) |
134 | 0 | { |
135 | 0 | mHeight = aHeight; |
136 | 0 | } |
137 | | |
138 | | static DOMRect* FromSupports(nsISupports* aSupports) |
139 | 0 | { |
140 | 0 | return static_cast<DOMRect*>(aSupports); |
141 | 0 | } |
142 | | |
143 | | private: |
144 | 0 | ~DOMRect() {} |
145 | | }; |
146 | | |
147 | | class DOMRectList final : public nsISupports, |
148 | | public nsWrapperCache |
149 | | { |
150 | 0 | ~DOMRectList() {} |
151 | | |
152 | | public: |
153 | | explicit DOMRectList(nsISupports *aParent) : mParent(aParent) |
154 | 0 | { |
155 | 0 | } |
156 | | |
157 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
158 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectList) |
159 | | |
160 | | virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override; |
161 | | |
162 | | nsISupports* GetParentObject() |
163 | 0 | { |
164 | 0 | return mParent; |
165 | 0 | } |
166 | | |
167 | 0 | void Append(DOMRect* aElement) { mArray.AppendElement(aElement); } |
168 | | |
169 | | uint32_t Length() |
170 | 0 | { |
171 | 0 | return mArray.Length(); |
172 | 0 | } |
173 | | DOMRect* Item(uint32_t aIndex) |
174 | 0 | { |
175 | 0 | return mArray.SafeElementAt(aIndex); |
176 | 0 | } |
177 | | DOMRect* IndexedGetter(uint32_t aIndex, bool& aFound) |
178 | 0 | { |
179 | 0 | aFound = aIndex < mArray.Length(); |
180 | 0 | if (!aFound) { |
181 | 0 | return nullptr; |
182 | 0 | } |
183 | 0 | return mArray[aIndex]; |
184 | 0 | } |
185 | | |
186 | | protected: |
187 | | nsTArray<RefPtr<DOMRect> > mArray; |
188 | | nsCOMPtr<nsISupports> mParent; |
189 | | }; |
190 | | |
191 | | } // namespace dom |
192 | | } // namespace mozilla |
193 | | |
194 | | #endif /*MOZILLA_DOMRECT_H_*/ |