2013-03-17 00:55:17 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-03-11 17:51:12 -07:00
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
#ifndef MOZILLA_DOMRECT_H_
|
|
|
|
#define MOZILLA_DOMRECT_H_
|
2008-03-11 17:51:12 -07:00
|
|
|
|
|
|
|
#include "nsIDOMClientRect.h"
|
|
|
|
#include "nsIDOMClientRectList.h"
|
2013-03-17 00:55:17 -07:00
|
|
|
#include "nsTArray.h"
|
2008-10-22 07:31:14 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2013-03-17 00:55:17 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2011-08-22 02:14:13 -07:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-03-17 00:55:17 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2013-09-06 19:15:49 -07:00
|
|
|
struct nsRect;
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class DOMRect MOZ_FINAL : public nsIDOMClientRect
|
|
|
|
, public nsWrapperCache
|
2008-03-11 17:51:12 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-09-20 03:21:03 -07:00
|
|
|
DOMRect(nsISupports* aParent)
|
2013-03-17 00:55:17 -07:00
|
|
|
: mParent(aParent), mX(0.0), mY(0.0), mWidth(0.0), mHeight(0.0)
|
|
|
|
{
|
|
|
|
SetIsDOMBinding();
|
|
|
|
}
|
2013-09-20 03:21:03 -07:00
|
|
|
virtual ~DOMRect() {}
|
2013-03-17 00:55:17 -07:00
|
|
|
|
2008-03-11 17:51:12 -07:00
|
|
|
void SetRect(float aX, float aY, float aWidth, float aHeight) {
|
|
|
|
mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight;
|
|
|
|
}
|
2013-03-17 00:55:17 -07:00
|
|
|
void SetLayoutRect(const nsRect& aLayoutRect);
|
|
|
|
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-09-20 03:21:03 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRect)
|
2008-03-11 17:51:12 -07:00
|
|
|
NS_DECL_NSIDOMCLIENTRECT
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
|
|
|
|
nsISupports* GetParentObject() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mParent);
|
|
|
|
return mParent;
|
|
|
|
}
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
2013-03-17 00:55:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
float Left() const
|
|
|
|
{
|
|
|
|
return mX;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Top() const
|
|
|
|
{
|
|
|
|
return mY;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Right() const
|
|
|
|
{
|
|
|
|
return mX + mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Bottom() const
|
|
|
|
{
|
|
|
|
return mY + mHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Width() const
|
|
|
|
{
|
|
|
|
return mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Height() const
|
|
|
|
{
|
|
|
|
return mHeight;
|
|
|
|
}
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2008-03-11 17:51:12 -07:00
|
|
|
protected:
|
2013-03-17 00:55:17 -07:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2008-03-11 17:51:12 -07:00
|
|
|
float mX, mY, mWidth, mHeight;
|
|
|
|
};
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
class DOMRectList MOZ_FINAL : public nsIDOMClientRectList,
|
|
|
|
public nsWrapperCache
|
2008-03-11 17:51:12 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-09-20 03:21:03 -07:00
|
|
|
DOMRectList(nsISupports *aParent) : mParent(aParent)
|
2011-08-22 02:14:13 -07:00
|
|
|
{
|
2012-03-16 08:44:09 -07:00
|
|
|
SetIsDOMBinding();
|
2011-08-22 02:14:13 -07:00
|
|
|
}
|
2008-03-11 17:51:12 -07:00
|
|
|
|
2011-08-22 02:14:13 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-09-20 03:21:03 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectList)
|
2008-03-11 17:51:12 -07:00
|
|
|
|
|
|
|
NS_DECL_NSIDOMCLIENTRECTLIST
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx,
|
|
|
|
JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
|
2008-03-11 17:51:12 -07:00
|
|
|
|
2011-08-22 02:14:13 -07:00
|
|
|
nsISupports* GetParentObject()
|
2008-10-22 07:31:14 -07:00
|
|
|
{
|
2011-08-22 02:14:13 -07:00
|
|
|
return mParent;
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
void Append(DOMRect* aElement) { mArray.AppendElement(aElement); }
|
2011-08-22 02:14:13 -07:00
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
static DOMRectList* FromSupports(nsISupports* aSupports)
|
2008-10-22 07:31:14 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMClientRectList> list_qi = do_QueryInterface(aSupports);
|
|
|
|
|
|
|
|
// If this assertion fires the QI implementation for the object in
|
|
|
|
// question doesn't use the nsIDOMClientRectList pointer as the nsISupports
|
|
|
|
// pointer. That must be fixed, or we'll crash...
|
|
|
|
NS_ASSERTION(list_qi == static_cast<nsIDOMClientRectList*>(aSupports),
|
|
|
|
"Uh, fix QI!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
return static_cast<DOMRectList*>(aSupports);
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
uint32_t Length()
|
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return mArray.Length();
|
2012-09-05 13:49:53 -07:00
|
|
|
}
|
2013-09-20 03:21:03 -07:00
|
|
|
DOMRect* Item(uint32_t aIndex)
|
2012-09-05 13:49:53 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return mArray.SafeElementAt(aIndex);
|
2012-09-05 13:49:53 -07:00
|
|
|
}
|
2013-09-20 03:21:03 -07:00
|
|
|
DOMRect* IndexedGetter(uint32_t aIndex, bool& aFound)
|
2012-09-05 13:49:53 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
aFound = aIndex < mArray.Length();
|
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mArray[aIndex];
|
2012-09-05 13:49:53 -07:00
|
|
|
}
|
|
|
|
|
2008-03-11 17:51:12 -07:00
|
|
|
protected:
|
2013-09-20 03:21:03 -07:00
|
|
|
virtual ~DOMRectList() {}
|
2008-03-11 17:51:12 -07:00
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
nsTArray< nsRefPtr<DOMRect> > mArray;
|
2011-08-22 02:14:13 -07:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2008-03-11 17:51:12 -07:00
|
|
|
};
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /*MOZILLA_DOMRECT_H_*/
|