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
|
|
|
#include "mozilla/dom/DOMRect.h"
|
2008-03-12 03:51:12 +03:00
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2013-09-20 14:21:03 +04:00
|
|
|
#include "mozilla/dom/DOMRectListBinding.h"
|
|
|
|
#include "mozilla/dom/DOMRectBinding.h"
|
2008-09-18 13:47:21 +04:00
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMRectReadOnly, mParent)
|
2013-09-20 14:21:03 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectReadOnly)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectReadOnly)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRectReadOnly)
|
2013-03-17 11:55:17 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2008-03-12 03:51:12 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
JSObject*
|
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
|
|
|
DOMRectReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mParent);
|
2018-06-26 00:20:54 +03:00
|
|
|
return DOMRectReadOnly_Binding::Wrap(aCx, this, aGivenProto);
|
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
|
|
|
already_AddRefed<DOMRectReadOnly>
|
|
|
|
DOMRectReadOnly::Constructor(const GlobalObject& aGlobal, double aX, double aY,
|
|
|
|
double aWidth, double aHeight, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
RefPtr<DOMRectReadOnly> obj =
|
|
|
|
new DOMRectReadOnly(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
JSObject*
|
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
|
|
|
DOMRect::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2008-03-12 03:51:12 +03:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
MOZ_ASSERT(mParent);
|
2018-06-26 00:20:54 +03:00
|
|
|
return DOMRect_Binding::Wrap(aCx, this, aGivenProto);
|
2008-03-12 03:51:12 +03:00
|
|
|
}
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
already_AddRefed<DOMRect>
|
|
|
|
DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY,
|
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 aWidth, double aHeight, ErrorResult& aRv)
|
2013-09-20 14:21:03 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRect> obj =
|
2013-09-20 14:21:03 +04:00
|
|
|
new DOMRect(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
// -----------------------------------------------------------------------------
|
2008-08-16 02:26:37 +04:00
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMRectList, mParent, mArray)
|
2011-08-22 13:14:13 +04:00
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
NS_INTERFACE_TABLE_HEAD(DOMRectList)
|
2014-08-26 03:21:35 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2018-03-01 19:14:26 +03:00
|
|
|
NS_INTERFACE_TABLE0(DOMRectList)
|
2013-09-20 14:21:03 +04:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(DOMRectList)
|
2008-03-12 03:51:12 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-09-20 14:21:03 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectList)
|
2008-03-12 03:51:12 +03:00
|
|
|
|
2011-08-22 13:14:13 +04:00
|
|
|
JSObject*
|
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
|
|
|
DOMRectList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2011-08-22 13:14:13 +04:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return mozilla::dom::DOMRectList_Binding::Wrap(cx, this, aGivenProto);
|
2011-08-22 13:14:13 +04:00
|
|
|
}
|
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
static double
|
|
|
|
RoundFloat(double aValue)
|
|
|
|
{
|
|
|
|
return floor(aValue + 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-20 14:21:03 +04:00
|
|
|
DOMRect::SetLayoutRect(const nsRect& aLayoutRect)
|
2008-09-18 13:47:21 +04:00
|
|
|
{
|
|
|
|
double scale = 65536.0;
|
|
|
|
// Round to the nearest 1/scale units. We choose scale so it can be represented
|
|
|
|
// exactly by machine floating point.
|
|
|
|
double scaleInv = 1/scale;
|
2018-08-11 07:46:23 +03:00
|
|
|
double t2pScaled = scale/AppUnitsPerCSSPixel();
|
2018-02-19 23:15:23 +03:00
|
|
|
double x = RoundFloat(aLayoutRect.x*t2pScaled)*scaleInv;
|
|
|
|
double y = RoundFloat(aLayoutRect.y*t2pScaled)*scaleInv;
|
2008-09-18 13:47:21 +04:00
|
|
|
SetRect(x, y, RoundFloat(aLayoutRect.XMost()*t2pScaled)*scaleInv - x,
|
|
|
|
RoundFloat(aLayoutRect.YMost()*t2pScaled)*scaleInv - y);
|
|
|
|
}
|