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
|
|
|
|
2020-11-23 19:06:52 +03:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <new>
|
|
|
|
#include <utility>
|
2020-11-23 19:12:12 +03:00
|
|
|
#include "js/TypeDecls.h"
|
2020-11-23 19:06:52 +03:00
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/FloatingPoint.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2008-10-22 18:31:14 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2011-08-22 13:14:13 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2020-11-23 19:06:52 +03:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2008-09-18 13:47:21 +04:00
|
|
|
|
2020-11-23 19:06:52 +03:00
|
|
|
class JSObject;
|
2019-06-25 09:46:47 +03:00
|
|
|
class nsIGlobalObject;
|
2020-11-23 19:06:52 +03:00
|
|
|
struct JSContext;
|
|
|
|
struct JSStructuredCloneReader;
|
|
|
|
struct JSStructuredCloneWriter;
|
|
|
|
struct nsRect;
|
2013-09-07 06:15:49 +04:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2020-11-23 19:06:52 +03:00
|
|
|
class GlobalObject;
|
2019-07-03 08:51:30 +03:00
|
|
|
struct DOMRectInit;
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
class DOMRectReadOnly : public nsISupports, public nsWrapperCache {
|
2014-06-25 06:09:15 +04:00
|
|
|
protected:
|
2020-02-21 13:41:47 +03:00
|
|
|
virtual ~DOMRectReadOnly() = default;
|
2014-06-25 06:09:15 +04:00
|
|
|
|
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)
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
explicit DOMRectReadOnly(nsISupports* aParent, double aX = 0, double aY = 0,
|
|
|
|
double aWidth = 0, double aHeight = 0)
|
2013-09-20 14:21:03 +04:00
|
|
|
: mParent(aParent), mX(aX), mY(aY), mWidth(aWidth), mHeight(aHeight) {}
|
2013-09-20 14:21:03 +04:00
|
|
|
|
2014-03-21 00:34:25 +04:00
|
|
|
nsISupports* GetParentObject() const {
|
|
|
|
MOZ_ASSERT(mParent);
|
|
|
|
return mParent;
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03: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
|
|
|
|
2019-07-03 08:51:30 +03:00
|
|
|
static already_AddRefed<DOMRectReadOnly> FromRect(const GlobalObject& aGlobal,
|
|
|
|
const DOMRectInit& aInit);
|
|
|
|
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
static already_AddRefed<DOMRectReadOnly> Constructor(
|
|
|
|
const GlobalObject& aGlobal, double aX, double aY, double aWidth,
|
2019-09-12 14:01:17 +03:00
|
|
|
double aHeight);
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
|
|
|
|
double X() const { return mX; }
|
|
|
|
double Y() const { return mY; }
|
|
|
|
double Width() const { return mWidth; }
|
|
|
|
double Height() const { return mHeight; }
|
2014-03-19 12:46:09 +04:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
double Left() const {
|
|
|
|
double x = X(), w = Width();
|
2020-04-08 01:27:36 +03:00
|
|
|
return NaNSafeMin(x, x + w);
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2013-09-20 14:21:03 +04:00
|
|
|
double Top() const {
|
|
|
|
double y = Y(), h = Height();
|
2020-04-08 01:27:36 +03:00
|
|
|
return NaNSafeMin(y, y + h);
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2013-09-20 14:21:03 +04:00
|
|
|
double Right() const {
|
|
|
|
double x = X(), w = Width();
|
2020-04-08 01:27:36 +03:00
|
|
|
return NaNSafeMax(x, x + w);
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
|
|
|
double Bottom() const {
|
|
|
|
double y = Y(), h = Height();
|
2020-04-08 01:27:36 +03:00
|
|
|
return NaNSafeMax(y, y + h);
|
2013-09-20 14:21:03 +04:00
|
|
|
}
|
2014-03-21 00:34:25 +04:00
|
|
|
|
2019-06-25 09:46:47 +03:00
|
|
|
bool WriteStructuredClone(JSContext* aCx,
|
|
|
|
JSStructuredCloneWriter* aWriter) const;
|
2019-06-15 20:26:25 +03:00
|
|
|
|
2019-06-25 09:46:47 +03:00
|
|
|
static already_AddRefed<DOMRectReadOnly> ReadStructuredClone(
|
|
|
|
JSContext* aCx, nsIGlobalObject* aGlobal,
|
|
|
|
JSStructuredCloneReader* aReader);
|
2019-06-15 20:26:25 +03:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
protected:
|
2019-06-25 09:46:47 +03:00
|
|
|
// Shared implementation of ReadStructuredClone for DOMRect and
|
|
|
|
// DOMRectReadOnly.
|
|
|
|
bool ReadStructuredClone(JSStructuredCloneReader* aReader);
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
double mX, mY, mWidth, mHeight;
|
2013-09-20 14:21:03 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMRect final : public DOMRectReadOnly {
|
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)
|
Bug 1186265 - Partially update DOMPoint, DOMQuad, DOMRect, DOMMatrix. r=bz
Some notes: this does not fully bring us to compliance to the current spec.
Instead, these are the fixes that I needed to make in order to make
css/geometry/interfaces.html pass with the DOMPoint changes in the previous
patches. I don't fully understand why that patch caused the test to fail the
way it did, but it ended up being easier to fix our code than understand why
the harness was falling over.
The DOMQuad::QuadBounds class was the source of some confusion for me. Now
that DOMRectReadOnly is a concrete class with members, I wanted to avoid
wasting them. However, the spec is unclear as to whether a DOMQuad's bound's
should be live -- that is because DOMQuad exposes DOMPoint, we can set its
points after retrieving a QuadBounds object. Our current code is live, setting
the points changes the QuadBounds. Chromium's current behavior is to never
update the QuadBounds object. I've left our behavior untouched in this patch
(and waste 4 doubles per QuadBounds object), but I am intending to file a bug
to understand what the intent of the spec is. I wonder if the author intended
the points to be DOMPointReadOnly instead. If so, we could simplify the
DOMRectReadOnly code and get rid of the virtual getters, which would be nice.
I also wasn't thrilled to put the DOMMatrix setters on the DOMMatrixReadOnly
class, but for brevity and simplicity of implementation, I've made them
public. I briefly considered making the setters protected on the ReadOnly
version of the class, but I'm not convinced that having to explicitly make
them public on the derived class is worth the extra copies of the names.
MozReview-Commit-ID: CjdW4Nbnc6A
--HG--
extra : rebase_source : 44489693afebff571a415b487e29fa6153288421
2018-03-30 02:19:31 +03:00
|
|
|
: DOMRectReadOnly(aParent, aX, aY, aWidth, aHeight) {}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2018-03-13 16:19:17 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(DOMRect, DOMRectReadOnly)
|
2013-09-20 14:21:03 +04:00
|
|
|
|
2019-07-03 08:51:30 +03:00
|
|
|
static already_AddRefed<DOMRect> FromRect(const GlobalObject& aGlobal,
|
|
|
|
const DOMRectInit& aInit);
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
static already_AddRefed<DOMRect> Constructor(const GlobalObject& aGlobal,
|
|
|
|
double aX, double aY,
|
2019-09-12 14:01:17 +03:00
|
|
|
double aWidth, double aHeight);
|
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
|
|
|
|
2019-06-25 09:46:47 +03:00
|
|
|
static already_AddRefed<DOMRect> ReadStructuredClone(
|
|
|
|
JSContext* aCx, nsIGlobalObject* aGlobal,
|
|
|
|
JSStructuredCloneReader* aReader);
|
|
|
|
using DOMRectReadOnly::ReadStructuredClone;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void SetX(double aX) { mX = aX; }
|
|
|
|
void SetY(double aY) { mY = aY; }
|
|
|
|
void SetWidth(double aWidth) { mWidth = aWidth; }
|
|
|
|
void SetHeight(double aHeight) { mHeight = aHeight; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-13 16:19:17 +03:00
|
|
|
static DOMRect* FromSupports(nsISupports* aSupports) {
|
|
|
|
return static_cast<DOMRect*>(aSupports);
|
|
|
|
}
|
|
|
|
|
2014-09-02 19:47:00 +04:00
|
|
|
private:
|
2020-02-21 13:41:47 +03:00
|
|
|
~DOMRect() = default;
|
2008-03-12 03:51:12 +03:00
|
|
|
};
|
|
|
|
|
2018-03-01 19:14:26 +03:00
|
|
|
class DOMRectList final : public nsISupports, public nsWrapperCache {
|
2020-02-21 13:41:47 +03:00
|
|
|
~DOMRectList() = default;
|
2014-06-25 06:09:15 +04:00
|
|
|
|
2008-03-12 03:51:12 +03:00
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit DOMRectList(nsISupports* aParent) : mParent(aParent) {}
|
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
|
|
|
|
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() { 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-03-17 11:55:17 +04:00
|
|
|
uint32_t Length() { return mArray.Length(); }
|
|
|
|
DOMRect* Item(uint32_t aIndex) { return mArray.SafeElementAt(aIndex); }
|
2013-09-20 14:21:03 +04:00
|
|
|
DOMRect* IndexedGetter(uint32_t aIndex, bool& aFound) {
|
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_*/
|