2013-03-17 07:55:17 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 00:51:12 +00:00
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
2008-03-12 00:51:12 +00:00
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2013-09-20 10:21:03 +00:00
|
|
|
#include "mozilla/dom/DOMRectListBinding.h"
|
|
|
|
#include "mozilla/dom/DOMRectBinding.h"
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2010-01-12 13:08:43 +00:00
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMRectReadOnly, mParent)
|
2013-09-20 10:21:03 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectReadOnly)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectReadOnly)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRectReadOnly)
|
2013-03-17 07:55:17 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2008-03-12 00:51:12 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
DOMRectReadOnly::WrapObject(JSContext* aCx)
|
2013-09-20 10:21:03 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mParent);
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return DOMRectReadOnlyBinding::Wrap(aCx, this);
|
2013-09-20 10:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(DOMRect, DOMRectReadOnly, nsIDOMClientRect)
|
2013-09-20 10:21:03 +00:00
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
#define FORWARD_GETTER(_name) \
|
|
|
|
NS_IMETHODIMP \
|
2013-09-20 10:21:03 +00:00
|
|
|
DOMRect::Get ## _name(float* aResult) \
|
2013-03-17 07:55:17 +00:00
|
|
|
{ \
|
2013-09-20 10:21:03 +00:00
|
|
|
*aResult = float(_name()); \
|
2013-03-17 07:55:17 +00:00
|
|
|
return NS_OK; \
|
|
|
|
}
|
|
|
|
|
|
|
|
FORWARD_GETTER(Left)
|
|
|
|
FORWARD_GETTER(Top)
|
|
|
|
FORWARD_GETTER(Right)
|
|
|
|
FORWARD_GETTER(Bottom)
|
|
|
|
FORWARD_GETTER(Width)
|
|
|
|
FORWARD_GETTER(Height)
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
DOMRect::WrapObject(JSContext* aCx)
|
2008-03-12 00:51:12 +00:00
|
|
|
{
|
2013-03-17 07:55:17 +00:00
|
|
|
MOZ_ASSERT(mParent);
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return DOMRectBinding::Wrap(aCx, this);
|
2008-03-12 00:51:12 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
already_AddRefed<DOMRect>
|
|
|
|
DOMRect::Constructor(const GlobalObject& aGlobal, ErrorResult& aRV)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMRect> obj =
|
|
|
|
new DOMRect(aGlobal.GetAsSupports(), 0.0, 0.0, 0.0, 0.0);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMRect>
|
|
|
|
DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY,
|
|
|
|
double aWidth, double aHeight, ErrorResult& aRV)
|
|
|
|
{
|
|
|
|
nsRefPtr<DOMRect> obj =
|
|
|
|
new DOMRect(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight);
|
|
|
|
return obj.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2008-08-15 22:26:37 +00:00
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMRectList, mParent, mArray)
|
2011-08-22 09:14:13 +00:00
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
NS_INTERFACE_TABLE_HEAD(DOMRectList)
|
2014-08-25 23:21:35 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE(DOMRectList, nsIDOMClientRectList)
|
2013-09-20 10:21:03 +00:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(DOMRectList)
|
2008-03-12 00:51:12 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectList)
|
2008-03-12 00:51:12 +00:00
|
|
|
|
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
NS_IMETHODIMP
|
2013-09-20 10:21:03 +00:00
|
|
|
DOMRectList::GetLength(uint32_t* aLength)
|
2008-03-12 00:51:12 +00:00
|
|
|
{
|
2012-09-05 20:49:53 +00:00
|
|
|
*aLength = Length();
|
2008-03-12 00:51:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-09-20 10:21:03 +00:00
|
|
|
DOMRectList::Item(uint32_t aIndex, nsIDOMClientRect** aReturn)
|
2008-03-12 00:51:12 +00:00
|
|
|
{
|
2012-09-05 20:49:53 +00:00
|
|
|
NS_IF_ADDREF(*aReturn = Item(aIndex));
|
2008-03-12 00:51:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2011-08-22 09:14:13 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
DOMRectList::WrapObject(JSContext *cx)
|
2011-08-22 09:14:13 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return mozilla::dom::DOMRectListBinding::Wrap(cx, this);
|
2011-08-22 09:14:13 +00:00
|
|
|
}
|
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
static double
|
|
|
|
RoundFloat(double aValue)
|
|
|
|
{
|
|
|
|
return floor(aValue + 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-20 10:21:03 +00:00
|
|
|
DOMRect::SetLayoutRect(const nsRect& aLayoutRect)
|
2008-09-18 09:47:21 +00: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;
|
2009-09-04 04:49:18 +00:00
|
|
|
double t2pScaled = scale/nsPresContext::AppUnitsPerCSSPixel();
|
2008-09-18 09:47:21 +00:00
|
|
|
double x = RoundFloat(aLayoutRect.x*t2pScaled)*scaleInv;
|
|
|
|
double y = RoundFloat(aLayoutRect.y*t2pScaled)*scaleInv;
|
|
|
|
SetRect(x, y, RoundFloat(aLayoutRect.XMost()*t2pScaled)*scaleInv - x,
|
|
|
|
RoundFloat(aLayoutRect.YMost()*t2pScaled)*scaleInv - y);
|
|
|
|
}
|