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: */
|
2014-03-12 05:11: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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/DOMPoint.h"
|
|
|
|
|
2020-11-23 19:06:52 +03:00
|
|
|
#include <cstdint>
|
|
|
|
#include "js/StructuredClone.h"
|
|
|
|
#include "mozilla/Casting.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/MacroForEach.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2014-03-12 05:11:37 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2020-11-23 19:06:52 +03:00
|
|
|
#include "mozilla/dom/DOMMatrix.h"
|
|
|
|
#include "mozilla/dom/DOMPointBinding.h"
|
|
|
|
#include "nsIGlobalObject.h"
|
2014-03-12 05:11:37 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2014-11-01 16:10:59 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMPointReadOnly, mParent)
|
2014-03-12 05:11:37 +04:00
|
|
|
|
2014-11-01 16:10:59 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMPointReadOnly, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMPointReadOnly, Release)
|
2014-03-12 05:11:37 +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
|
|
|
already_AddRefed<DOMPointReadOnly> DOMPointReadOnly::FromPoint(
|
|
|
|
const GlobalObject& aGlobal, const DOMPointInit& aParams) {
|
|
|
|
RefPtr<DOMPointReadOnly> obj = new DOMPointReadOnly(
|
|
|
|
aGlobal.GetAsSupports(), aParams.mX, aParams.mY, aParams.mZ, aParams.mW);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMPointReadOnly> DOMPointReadOnly::Constructor(
|
2019-09-12 14:01:17 +03:00
|
|
|
const GlobalObject& aGlobal, double aX, double aY, double aZ, double aW) {
|
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
|
|
|
RefPtr<DOMPointReadOnly> obj =
|
|
|
|
new DOMPointReadOnly(aGlobal.GetAsSupports(), aX, aY, aZ, aW);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* DOMPointReadOnly::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return DOMPointReadOnly_Binding::Wrap(aCx, this, aGivenProto);
|
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
|
|
|
}
|
|
|
|
|
2019-07-06 09:55:53 +03:00
|
|
|
already_AddRefed<DOMPoint> DOMPointReadOnly::MatrixTransform(
|
|
|
|
const DOMMatrixInit& aInit, ErrorResult& aRv) {
|
|
|
|
RefPtr<DOMMatrixReadOnly> matrix =
|
|
|
|
DOMMatrixReadOnly::FromMatrix(mParent, aInit, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
DOMPointInit init;
|
|
|
|
init.mX = this->mX;
|
|
|
|
init.mY = this->mY;
|
|
|
|
init.mZ = this->mZ;
|
|
|
|
init.mW = this->mW;
|
|
|
|
RefPtr<DOMPoint> point = matrix->TransformPoint(init);
|
|
|
|
return point.forget();
|
|
|
|
}
|
|
|
|
|
2019-06-15 20:26:25 +03:00
|
|
|
// https://drafts.fxtf.org/geometry/#structured-serialization
|
|
|
|
bool DOMPointReadOnly::WriteStructuredClone(
|
2019-06-25 09:46:20 +03:00
|
|
|
JSContext* aCx, JSStructuredCloneWriter* aWriter) const {
|
2019-06-15 20:26:25 +03:00
|
|
|
#define WriteDouble(d) \
|
|
|
|
JS_WriteUint32Pair(aWriter, (BitwiseCast<uint64_t>(d) >> 32) & 0xffffffff, \
|
|
|
|
BitwiseCast<uint64_t>(d) & 0xffffffff)
|
|
|
|
|
|
|
|
return WriteDouble(mX) && WriteDouble(mY) && WriteDouble(mZ) &&
|
|
|
|
WriteDouble(mW);
|
|
|
|
|
|
|
|
#undef WriteDouble
|
|
|
|
}
|
|
|
|
|
2019-06-25 09:46:20 +03:00
|
|
|
// static
|
|
|
|
already_AddRefed<DOMPointReadOnly> DOMPointReadOnly::ReadStructuredClone(
|
|
|
|
JSContext* aCx, nsIGlobalObject* aGlobal,
|
|
|
|
JSStructuredCloneReader* aReader) {
|
|
|
|
RefPtr<DOMPointReadOnly> retval = new DOMPointReadOnly(aGlobal);
|
|
|
|
if (!retval->ReadStructuredClone(aReader)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return retval.forget();
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2019-06-15 20:26:25 +03:00
|
|
|
bool DOMPointReadOnly::ReadStructuredClone(JSStructuredCloneReader* aReader) {
|
|
|
|
uint32_t high;
|
|
|
|
uint32_t low;
|
|
|
|
|
|
|
|
#define ReadDouble(d) \
|
|
|
|
if (!JS_ReadUint32Pair(aReader, &high, &low)) { \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
(*(d) = BitwiseCast<double>(static_cast<uint64_t>(high) << 32 | low))
|
|
|
|
|
|
|
|
ReadDouble(&mX);
|
|
|
|
ReadDouble(&mY);
|
|
|
|
ReadDouble(&mZ);
|
|
|
|
ReadDouble(&mW);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#undef ReadDouble
|
|
|
|
}
|
|
|
|
|
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
|
|
|
already_AddRefed<DOMPoint> DOMPoint::FromPoint(const GlobalObject& aGlobal,
|
|
|
|
const DOMPointInit& aParams) {
|
2014-03-12 05:11:37 +04:00
|
|
|
RefPtr<DOMPoint> obj = new DOMPoint(aGlobal.GetAsSupports(), aParams.mX,
|
|
|
|
aParams.mY, aParams.mZ, aParams.mW);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMPoint> DOMPoint::Constructor(const GlobalObject& aGlobal,
|
|
|
|
double aX, double aY,
|
2019-09-12 14:01:17 +03:00
|
|
|
double aZ, double aW) {
|
2014-03-12 05:11:37 +04:00
|
|
|
RefPtr<DOMPoint> obj = new DOMPoint(aGlobal.GetAsSupports(), aX, aY, aZ, aW);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* DOMPoint::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return DOMPoint_Binding::Wrap(aCx, this, aGivenProto);
|
2014-03-12 05:11:37 +04:00
|
|
|
}
|
2019-06-25 09:46:20 +03:00
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<DOMPoint> DOMPoint::ReadStructuredClone(
|
|
|
|
JSContext* aCx, nsIGlobalObject* aGlobal,
|
|
|
|
JSStructuredCloneReader* aReader) {
|
|
|
|
RefPtr<DOMPoint> retval = new DOMPoint(aGlobal);
|
|
|
|
if (!retval->ReadStructuredClone(aReader)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return retval.forget();
|
|
|
|
;
|
|
|
|
}
|