2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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-12 03:51:12 +03:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
#ifndef MOZILLA_DOMRECT_H_
|
|
|
|
#define MOZILLA_DOMRECT_H_
|
2008-03-12 03:51:12 +03:00
|
|
|
|
|
|
|
#include "nsIDOMClientRect.h"
|
|
|
|
#include "nsIDOMClientRectList.h"
|
2013-03-17 11:55:17 +04:00
|
|
|
#include "nsTArray.h"
|
2008-10-22 18:31:14 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2011-08-22 13:14:13 +04:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-03-17 11:55:17 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-20 14:21:03 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include <algorithm>
|
2008-09-18 13:47:21 +04:00
|
|
|
|
2013-09-07 06:15:49 +04:00
|
|
|
struct nsRect;
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
class DOMRectReadOnly : public nsISupports
|
|
|
|
, public nsWrapperCache
|
2008-03-12 03:51:12 +03:00
|
|
|
{
|
2014-06-25 06:09:15 +04:00
|
|
|
protected:
|
|
|
|
virtual ~DOMRectReadOnly() {}
|
|
|
|
|
2008-03-12 03:51:12 +03:00
|
|
|
public:
|
2013-09-20 14:21:03 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectReadOnly)
|
|
|
|
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit DOMRectReadOnly(nsISupports* aParent)
|
2013-09-20 14:21:03 +04:00
|
|
|
: mParent(aParent)
|
2013-03-17 11:55:17 +04:00
|
|
|
{
|
|
|
|
}
|
2013-09-20 14:21:03 +04:00
|
|
|
|
2014-03-21 00:34:25 +04:00
|
|
|
nsISupports* GetParentObject() const
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
2014-03-21 00:34:25 +04:00
|
|
|
MOZ_ASSERT(mParent);
|
|
|
|
return mParent;
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-09-20 14:21:03 +04:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
virtual double X() const = 0;
|
|
|
|
virtual double Y() const = 0;
|
|
|
|
virtual double Width() const = 0;
|
|
|
|
virtual double Height() const = 0;
|
2014-03-19 12:46:09 +04:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
double Left() const
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
2013-09-20 14:21:03 +04:00
|
|
|
double x = X(), w = Width();
|
|
|
|
return std::min(x, x + w);
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2013-09-20 14:21:03 +04:00
|
|
|
double Top() const
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
2013-09-20 14:21:03 +04:00
|
|
|
double y = Y(), h = Height();
|
|
|
|
return std::min(y, y + h);
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2013-09-20 14:21:03 +04:00
|
|
|
double Right() const
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
2013-09-20 14:21:03 +04:00
|
|
|
double x = X(), w = Width();
|
|
|
|
return std::max(x, x + w);
|
|
|
|
}
|
|
|
|
double Bottom() const
|
|
|
|
{
|
|
|
|
double y = Y(), h = Height();
|
|
|
|
return std::max(y, y + h);
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2014-03-21 00:34:25 +04:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsISupports> mParent;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMRect final : public DOMRectReadOnly
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsIDOMClientRect
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit DOMRect(nsISupports* aParent, double aX = 0, double aY = 0,
|
|
|
|
double aWidth = 0, double aHeight = 0)
|
2013-09-20 14:21:03 +04:00
|
|
|
: DOMRectReadOnly(aParent)
|
|
|
|
, mX(aX)
|
|
|
|
, mY(aY)
|
|
|
|
, mWidth(aWidth)
|
|
|
|
, mHeight(aHeight)
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIDOMCLIENTRECT
|
|
|
|
|
|
|
|
static already_AddRefed<DOMRect>
|
|
|
|
Constructor(const GlobalObject& aGlobal, ErrorResult& aRV);
|
|
|
|
static already_AddRefed<DOMRect>
|
|
|
|
Constructor(const GlobalObject& aGlobal, double aX, double aY,
|
|
|
|
double aWidth, double aHeight, ErrorResult& aRV);
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-09-20 14:21:03 +04:00
|
|
|
|
|
|
|
void SetRect(float aX, float aY, float aWidth, float aHeight) {
|
|
|
|
mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight;
|
|
|
|
}
|
|
|
|
void SetLayoutRect(const nsRect& aLayoutRect);
|
2014-03-21 00:34:25 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual double X() const override
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
|
|
|
return mX;
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual double Y() const override
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
|
|
|
return mY;
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual double Width() const override
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
2014-03-21 00:34:25 +04:00
|
|
|
return mWidth;
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual double Height() const override
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
2014-03-21 00:34:25 +04:00
|
|
|
return mHeight;
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
void SetX(double aX)
|
|
|
|
{
|
|
|
|
mX = aX;
|
|
|
|
}
|
|
|
|
void SetY(double aY)
|
|
|
|
{
|
|
|
|
mY = aY;
|
|
|
|
}
|
|
|
|
void SetWidth(double aWidth)
|
|
|
|
{
|
|
|
|
mWidth = aWidth;
|
|
|
|
}
|
|
|
|
void SetHeight(double aHeight)
|
|
|
|
{
|
|
|
|
mHeight = aHeight;
|
|
|
|
}
|
|
|
|
|
2008-03-12 03:51:12 +03:00
|
|
|
protected:
|
2013-09-20 14:21:03 +04:00
|
|
|
double mX, mY, mWidth, mHeight;
|
2014-09-02 19:47:00 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~DOMRect() {};
|
2008-03-12 03:51:12 +03:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMRectList final : public nsIDOMClientRectList,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsWrapperCache
|
2008-03-12 03:51:12 +03:00
|
|
|
{
|
2014-06-25 06:09:15 +04:00
|
|
|
~DOMRectList() {}
|
|
|
|
|
2008-03-12 03:51:12 +03:00
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit DOMRectList(nsISupports *aParent) : mParent(aParent)
|
2011-08-22 13:14:13 +04:00
|
|
|
{
|
|
|
|
}
|
2008-03-12 03:51:12 +03:00
|
|
|
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-09-20 14:21:03 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectList)
|
2008-03-12 03:51:12 +03:00
|
|
|
|
|
|
|
NS_DECL_NSIDOMCLIENTRECTLIST
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2008-03-12 03:51:12 +03:00
|
|
|
|
2011-08-22 13:14:13 +04:00
|
|
|
nsISupports* GetParentObject()
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
2011-08-22 13:14:13 +04:00
|
|
|
return mParent;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
void Append(DOMRect* aElement) { mArray.AppendElement(aElement); }
|
2011-08-22 13:14:13 +04:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
static DOMRectList* FromSupports(nsISupports* aSupports)
|
2008-10-22 18:31:14 +04: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 14:21:03 +04:00
|
|
|
return static_cast<DOMRectList*>(aSupports);
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
uint32_t Length()
|
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
return mArray.Length();
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
2013-09-20 14:21:03 +04:00
|
|
|
DOMRect* Item(uint32_t aIndex)
|
2012-09-06 00:49:53 +04:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
return mArray.SafeElementAt(aIndex);
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
2013-09-20 14:21:03 +04:00
|
|
|
DOMRect* IndexedGetter(uint32_t aIndex, bool& aFound)
|
2012-09-06 00:49:53 +04:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
aFound = aIndex < mArray.Length();
|
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mArray[aIndex];
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
|
|
|
|
2008-03-12 03:51:12 +03:00
|
|
|
protected:
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<DOMRect> > mArray;
|
2011-08-22 13:14:13 +04:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2008-03-12 03:51:12 +03:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-09-20 14:21:03 +04:00
|
|
|
|
|
|
|
#endif /*MOZILLA_DOMRECT_H_*/
|