|
|
9 |
#include "nsIDOMClientRect.h" |
9 |
#include "nsIDOMClientRect.h" |
10 |
#include "nsIDOMClientRectList.h" |
10 |
#include "nsIDOMClientRectList.h" |
11 |
#include "nsTArray.h" |
11 |
#include "nsTArray.h" |
12 |
#include "nsCOMPtr.h" |
12 |
#include "nsCOMPtr.h" |
13 |
#include "nsAutoPtr.h" |
13 |
#include "nsAutoPtr.h" |
14 |
#include "nsWrapperCache.h" |
14 |
#include "nsWrapperCache.h" |
15 |
#include "nsCycleCollectionParticipant.h" |
15 |
#include "nsCycleCollectionParticipant.h" |
16 |
#include "mozilla/Attributes.h" |
16 |
#include "mozilla/Attributes.h" |
|
|
17 |
#include "mozilla/dom/BindingDeclarations.h" |
18 |
#include "mozilla/ErrorResult.h" |
19 |
#include <algorithm> |
17 |
|
20 |
|
18 |
struct nsRect; |
21 |
struct nsRect; |
19 |
|
22 |
|
20 |
namespace mozilla { |
23 |
namespace mozilla { |
21 |
namespace dom { |
24 |
namespace dom { |
22 |
|
25 |
|
23 |
class DOMRect MOZ_FINAL : public nsIDOMClientRect |
26 |
class DOMRectReadOnly : public nsISupports |
24 |
, public nsWrapperCache |
27 |
, public nsWrapperCache |
25 |
{ |
28 |
{ |
26 |
public: |
29 |
public: |
27 |
DOMRect(nsISupports* aParent) |
30 |
NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
28 |
: mParent(aParent), mX(0.0), mY(0.0), mWidth(0.0), mHeight(0.0) |
31 |
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectReadOnly) |
|
|
32 |
|
33 |
virtual ~DOMRectReadOnly() {} |
34 |
|
35 |
DOMRectReadOnly(nsISupports* aParent) |
36 |
: mParent(aParent) |
29 |
{ |
37 |
{ |
30 |
SetIsDOMBinding(); |
38 |
SetIsDOMBinding(); |
31 |
} |
39 |
} |
32 |
virtual ~DOMRect() {} |
|
|
33 |
|
34 |
void SetRect(float aX, float aY, float aWidth, float aHeight) { |
35 |
mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight; |
36 |
} |
37 |
void SetLayoutRect(const nsRect& aLayoutRect); |
38 |
|
39 |
|
40 |
NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
41 |
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRect) |
42 |
NS_DECL_NSIDOMCLIENTRECT |
43 |
|
44 |
|
40 |
|
45 |
nsISupports* GetParentObject() const |
41 |
nsISupports* GetParentObject() const |
46 |
{ |
42 |
{ |
47 |
MOZ_ASSERT(mParent); |
43 |
MOZ_ASSERT(mParent); |
48 |
return mParent; |
44 |
return mParent; |
49 |
} |
45 |
} |
50 |
virtual JSObject* WrapObject(JSContext* aCx, |
46 |
virtual JSObject* WrapObject(JSContext* aCx, |
51 |
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE; |
47 |
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE; |
52 |
|
48 |
|
|
|
49 |
virtual double X() const = 0; |
50 |
virtual double Y() const = 0; |
51 |
virtual double Width() const = 0; |
52 |
virtual double Height() const = 0; |
53 |
|
53 |
|
54 |
float Left() const |
54 |
double Left() const |
|
|
55 |
{ |
56 |
double x = X(), w = Width(); |
57 |
return std::min(x, x + w); |
58 |
} |
59 |
double Top() const |
60 |
{ |
61 |
double y = Y(), h = Height(); |
62 |
return std::min(y, y + h); |
63 |
} |
64 |
double Right() const |
65 |
{ |
66 |
double x = X(), w = Width(); |
67 |
return std::max(x, x + w); |
68 |
} |
69 |
double Bottom() const |
70 |
{ |
71 |
double y = Y(), h = Height(); |
72 |
return std::max(y, y + h); |
73 |
} |
74 |
|
75 |
protected: |
76 |
nsCOMPtr<nsISupports> mParent; |
77 |
}; |
78 |
|
79 |
class DOMRect MOZ_FINAL : public DOMRectReadOnly |
80 |
, public nsIDOMClientRect |
81 |
{ |
82 |
public: |
83 |
DOMRect(nsISupports* aParent, double aX = 0, double aY = 0, |
84 |
double aWidth = 0, double aHeight = 0) |
85 |
: DOMRectReadOnly(aParent) |
86 |
, mX(aX) |
87 |
, mY(aY) |
88 |
, mWidth(aWidth) |
89 |
, mHeight(aHeight) |
90 |
{ |
91 |
} |
92 |
|
93 |
NS_DECL_ISUPPORTS_INHERITED |
94 |
NS_DECL_NSIDOMCLIENTRECT |
95 |
|
96 |
static already_AddRefed<DOMRect> |
97 |
Constructor(const GlobalObject& aGlobal, ErrorResult& aRV); |
98 |
static already_AddRefed<DOMRect> |
99 |
Constructor(const GlobalObject& aGlobal, double aX, double aY, |
100 |
double aWidth, double aHeight, ErrorResult& aRV); |
101 |
|
102 |
virtual JSObject* WrapObject(JSContext* aCx, |
103 |
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE; |
104 |
|
105 |
void SetRect(float aX, float aY, float aWidth, float aHeight) { |
106 |
mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight; |
107 |
} |
108 |
void SetLayoutRect(const nsRect& aLayoutRect); |
109 |
|
110 |
virtual double X() const MOZ_OVERRIDE |
55 |
{ |
111 |
{ |
56 |
return mX; |
112 |
return mX; |
57 |
} |
113 |
} |
58 |
|
114 |
virtual double Y() const MOZ_OVERRIDE |
59 |
float Top() const |
|
|
60 |
{ |
115 |
{ |
61 |
return mY; |
116 |
return mY; |
62 |
} |
117 |
} |
63 |
|
118 |
virtual double Width() const MOZ_OVERRIDE |
64 |
float Right() const |
|
|
65 |
{ |
66 |
return mX + mWidth; |
67 |
} |
68 |
|
69 |
float Bottom() const |
70 |
{ |
71 |
return mY + mHeight; |
72 |
} |
73 |
|
74 |
float Width() const |
75 |
{ |
119 |
{ |
76 |
return mWidth; |
120 |
return mWidth; |
77 |
} |
121 |
} |
78 |
|
122 |
virtual double Height() const MOZ_OVERRIDE |
79 |
float Height() const |
|
|
80 |
{ |
123 |
{ |
81 |
return mHeight; |
124 |
return mHeight; |
82 |
} |
125 |
} |
83 |
|
126 |
|
|
|
127 |
void SetX(double aX) |
128 |
{ |
129 |
mX = aX; |
130 |
} |
131 |
void SetY(double aY) |
132 |
{ |
133 |
mY = aY; |
134 |
} |
135 |
void SetWidth(double aWidth) |
136 |
{ |
137 |
mWidth = aWidth; |
138 |
} |
139 |
void SetHeight(double aHeight) |
140 |
{ |
141 |
mHeight = aHeight; |
142 |
} |
143 |
|
84 |
protected: |
144 |
protected: |
85 |
nsCOMPtr<nsISupports> mParent; |
145 |
double mX, mY, mWidth, mHeight; |
86 |
float mX, mY, mWidth, mHeight; |
|
|
87 |
}; |
146 |
}; |
88 |
|
147 |
|
89 |
class DOMRectList MOZ_FINAL : public nsIDOMClientRectList, |
148 |
class DOMRectList MOZ_FINAL : public nsIDOMClientRectList, |
90 |
public nsWrapperCache |
149 |
public nsWrapperCache |
91 |
{ |
150 |
{ |
92 |
public: |
151 |
public: |
93 |
DOMRectList(nsISupports *aParent) : mParent(aParent) |
152 |
DOMRectList(nsISupports *aParent) : mParent(aParent) |
94 |
{ |
153 |
{ |
Lines 140-157
public:
|
Link Here
|
---|
|
140 |
aFound = aIndex < mArray.Length(); |
199 |
aFound = aIndex < mArray.Length(); |
141 |
if (!aFound) { |
200 |
if (!aFound) { |
142 |
return nullptr; |
201 |
return nullptr; |
143 |
} |
202 |
} |
144 |
return mArray[aIndex]; |
203 |
return mArray[aIndex]; |
145 |
} |
204 |
} |
146 |
|
205 |
|
147 |
protected: |
206 |
protected: |
148 |
virtual ~DOMRectList() {} |
207 |
nsTArray<nsRefPtr<DOMRect> > mArray; |
149 |
|
|
|
150 |
nsTArray< nsRefPtr<DOMRect> > mArray; |
151 |
nsCOMPtr<nsISupports> mParent; |
208 |
nsCOMPtr<nsISupports> mParent; |
152 |
}; |
209 |
}; |
153 |
|
210 |
|
154 |
} |
211 |
} |
155 |
} |
212 |
} |
156 |
|
213 |
|
157 |
#endif /*MOZILLA_DOMRECT_H_*/ |
214 |
#endif /*MOZILLA_DOMRECT_H_*/ |