1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_DOMRECT_H_
7 #define MOZILLA_DOMRECT_H_
9 #include "nsIDOMClientRect.h"
10 #include "nsIDOMClientRectList.h"
13 #include "nsAutoPtr.h"
14 #include "nsWrapperCache.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "mozilla/Attributes.h"
23 class DOMRect MOZ_FINAL
: public nsIDOMClientRect
24 , public nsWrapperCache
27 DOMRect(nsISupports
* aParent
)
28 : mParent(aParent
), mX(0.0), mY(0.0), mWidth(0.0), mHeight(0.0)
34 void SetRect(float aX
, float aY
, float aWidth
, float aHeight
) {
35 mX
= aX
; mY
= aY
; mWidth
= aWidth
; mHeight
= aHeight
;
37 void SetLayoutRect(const nsRect
& aLayoutRect
);
40 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
41 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRect
)
42 NS_DECL_NSIDOMCLIENTRECT
45 nsISupports
* GetParentObject() const
50 virtual JSObject
* WrapObject(JSContext
* aCx
,
51 JS::Handle
<JSObject
*> aScope
) MOZ_OVERRIDE
;
85 nsCOMPtr
<nsISupports
> mParent
;
86 float mX
, mY
, mWidth
, mHeight
;
89 class DOMRectList MOZ_FINAL
: public nsIDOMClientRectList
,
93 DOMRectList(nsISupports
*aParent
) : mParent(aParent
)
98 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
99 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectList
)
101 NS_DECL_NSIDOMCLIENTRECTLIST
103 virtual JSObject
* WrapObject(JSContext
*cx
,
104 JS::Handle
<JSObject
*> scope
) MOZ_OVERRIDE
;
106 nsISupports
* GetParentObject()
111 void Append(DOMRect
* aElement
) { mArray
.AppendElement(aElement
); }
113 static DOMRectList
* FromSupports(nsISupports
* aSupports
)
117 nsCOMPtr
<nsIDOMClientRectList
> list_qi
= do_QueryInterface(aSupports
);
119 // If this assertion fires the QI implementation for the object in
120 // question doesn't use the nsIDOMClientRectList pointer as the nsISupports
121 // pointer. That must be fixed, or we'll crash...
122 NS_ASSERTION(list_qi
== static_cast<nsIDOMClientRectList
*>(aSupports
),
127 return static_cast<DOMRectList
*>(aSupports
);
132 return mArray
.Length();
134 DOMRect
* Item(uint32_t aIndex
)
136 return mArray
.SafeElementAt(aIndex
);
138 DOMRect
* IndexedGetter(uint32_t aIndex
, bool& aFound
)
140 aFound
= aIndex
< mArray
.Length();
144 return mArray
[aIndex
];
148 virtual ~DOMRectList() {}
150 nsTArray
< nsRefPtr
<DOMRect
> > mArray
;
151 nsCOMPtr
<nsISupports
> mParent
;
157 #endif /*MOZILLA_DOMRECT_H_*/