diff --git a/content/base/src/DOMRect.cpp b/content/base/src/DOMRect.cpp index f0d5a8f7120..6223c158d85 100644 --- a/content/base/src/DOMRect.cpp +++ b/content/base/src/DOMRect.cpp @@ -3,7 +3,7 @@ * 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/DOMRect.h" +#include "DOMRect.h" #include "nsPresContext.h" #include "mozilla/dom/DOMRectListBinding.h" @@ -12,30 +12,20 @@ using namespace mozilla; using namespace mozilla::dom; -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMRectReadOnly, mParent) -NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectReadOnly) -NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectReadOnly) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRectReadOnly) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMRect, mParent) +NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRect) +NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRect) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMRect) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsIDOMClientRect) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -JSObject* -DOMRectReadOnly::WrapObject(JSContext* aCx, JS::Handle aScope) -{ - MOZ_ASSERT(mParent); - return DOMRectReadOnlyBinding::Wrap(aCx, aScope, this); -} - -// ----------------------------------------------------------------------------- - -NS_IMPL_ISUPPORTS_INHERITED1(DOMRect, DOMRectReadOnly, nsIDOMClientRect) - #define FORWARD_GETTER(_name) \ NS_IMETHODIMP \ DOMRect::Get ## _name(float* aResult) \ { \ - *aResult = float(_name()); \ + *aResult = _name(); \ return NS_OK; \ } @@ -53,23 +43,6 @@ DOMRect::WrapObject(JSContext* aCx, JS::Handle aScope) return DOMRectBinding::Wrap(aCx, aScope, this); } -already_AddRefed -DOMRect::Constructor(const GlobalObject& aGlobal, ErrorResult& aRV) -{ - nsRefPtr obj = - new DOMRect(aGlobal.GetAsSupports(), 0.0, 0.0, 0.0, 0.0); - return obj.forget(); -} - -already_AddRefed -DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY, - double aWidth, double aHeight, ErrorResult& aRV) -{ - nsRefPtr obj = - new DOMRect(aGlobal.GetAsSupports(), aX, aY, aWidth, aHeight); - return obj.forget(); -} - // ----------------------------------------------------------------------------- NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(DOMRectList, mParent, mArray) @@ -84,7 +57,7 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMRectList) NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMRectList) -NS_IMETHODIMP +NS_IMETHODIMP DOMRectList::GetLength(uint32_t* aLength) { *aLength = Length(); diff --git a/content/base/src/DOMRect.h b/content/base/src/DOMRect.h index bdef9ce37c2..ae3db528683 100644 --- a/content/base/src/DOMRect.h +++ b/content/base/src/DOMRect.h @@ -14,29 +14,33 @@ #include "nsWrapperCache.h" #include "nsCycleCollectionParticipant.h" #include "mozilla/Attributes.h" -#include "mozilla/dom/BindingDeclarations.h" -#include "mozilla/ErrorResult.h" -#include struct nsRect; namespace mozilla { namespace dom { -class DOMRectReadOnly : public nsISupports - , public nsWrapperCache +class DOMRect MOZ_FINAL : public nsIDOMClientRect + , public nsWrapperCache { public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRectReadOnly) - - virtual ~DOMRectReadOnly() {} - - DOMRectReadOnly(nsISupports* aParent) - : mParent(aParent) + DOMRect(nsISupports* aParent) + : mParent(aParent), mX(0.0), mY(0.0), mWidth(0.0), mHeight(0.0) { SetIsDOMBinding(); } + virtual ~DOMRect() {} + + void SetRect(float aX, float aY, float aWidth, float aHeight) { + mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight; + } + void SetLayoutRect(const nsRect& aLayoutRect); + + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMRect) + NS_DECL_NSIDOMCLIENTRECT + nsISupports* GetParentObject() const { @@ -46,103 +50,40 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; - virtual double X() const = 0; - virtual double Y() const = 0; - virtual double Width() const = 0; - virtual double Height() const = 0; - double Left() const - { - double x = X(), w = Width(); - return std::min(x, x + w); - } - double Top() const - { - double y = Y(), h = Height(); - return std::min(y, y + h); - } - double Right() const - { - 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); - } - -protected: - nsCOMPtr mParent; -}; - -class DOMRect MOZ_FINAL : public DOMRectReadOnly - , public nsIDOMClientRect -{ -public: - DOMRect(nsISupports* aParent, double aX = 0, double aY = 0, - double aWidth = 0, double aHeight = 0) - : DOMRectReadOnly(aParent) - , mX(aX) - , mY(aY) - , mWidth(aWidth) - , mHeight(aHeight) - { - } - - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIDOMCLIENTRECT - - static already_AddRefed - Constructor(const GlobalObject& aGlobal, ErrorResult& aRV); - static already_AddRefed - Constructor(const GlobalObject& aGlobal, double aX, double aY, - double aWidth, double aHeight, ErrorResult& aRV); - - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aScope) MOZ_OVERRIDE; - - void SetRect(float aX, float aY, float aWidth, float aHeight) { - mX = aX; mY = aY; mWidth = aWidth; mHeight = aHeight; - } - void SetLayoutRect(const nsRect& aLayoutRect); - - virtual double X() const MOZ_OVERRIDE + float Left() const { return mX; } - virtual double Y() const MOZ_OVERRIDE + + float Top() const { return mY; } - virtual double Width() const MOZ_OVERRIDE + + float Right() const + { + return mX + mWidth; + } + + float Bottom() const + { + return mY + mHeight; + } + + float Width() const { return mWidth; } - virtual double Height() const MOZ_OVERRIDE + + float Height() const { return mHeight; } - void SetX(double aX) - { - mX = aX; - } - void SetY(double aY) - { - mY = aY; - } - void SetWidth(double aWidth) - { - mWidth = aWidth; - } - void SetHeight(double aHeight) - { - mHeight = aHeight; - } - protected: - double mX, mY, mWidth, mHeight; + nsCOMPtr mParent; + float mX, mY, mWidth, mHeight; }; class DOMRectList MOZ_FINAL : public nsIDOMClientRectList, @@ -204,7 +145,9 @@ public: } protected: - nsTArray > mArray; + virtual ~DOMRectList() {} + + nsTArray< nsRefPtr > mArray; nsCOMPtr mParent; }; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index fe5551723b2..ffd8cc4bb97 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -220,6 +220,16 @@ DOMInterfaces = { 'nativeType': 'mozilla::dom::workers::ChromeWorkerPrivate', }, +'DOMRectList': { + 'headerFile': 'mozilla/dom/DOMRect.h', + 'resultNotAddRefed': [ 'item' ] +}, + +'DOMPointReadOnly': { + 'headerFile': 'mozilla/dom/DOMPoint.h', + 'concrete': False, +}, + 'Console': { 'implicitJSContext': [ 'trace', 'time', 'timeEnd' ], }, @@ -328,20 +338,6 @@ DOMInterfaces = { }, }, -'DOMPointReadOnly': { - 'headerFile': 'mozilla/dom/DOMPoint.h', - 'concrete': False, -}, - -'DOMRectList': { - 'headerFile': 'mozilla/dom/DOMRect.h', - 'resultNotAddRefed': [ 'item' ] -}, - -'DOMRectReadOnly': { - 'headerFile': 'mozilla/dom/DOMRect.h', -}, - 'DOMSettableTokenList': { 'nativeType': 'nsDOMSettableTokenList', }, diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 0586480cbe4..3297a19e283 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -315,8 +315,6 @@ var interfaceNamesInGlobalScope = "DOMRect", // IMPORTANT: Do not change this list without review from a DOM peer! "DOMRectList", -// IMPORTANT: Do not change this list without review from a DOM peer! - "DOMRectReadOnly", // IMPORTANT: Do not change this list without review from a DOM peer! "DOMRequest", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/DOMRect.webidl b/dom/webidl/DOMRect.webidl index 1e817106cdb..73adf4a4bed 100644 --- a/dom/webidl/DOMRect.webidl +++ b/dom/webidl/DOMRect.webidl @@ -1,32 +1,14 @@ /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. - * - * The origin of this IDL file is - * http://dev.w3.org/fxtf/geometry/ - * - * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C - * liability, trademark and document use rules apply. - */ + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -[Constructor, - Constructor(unrestricted double x, unrestricted double y, - unrestricted double width, unrestricted double height)] -interface DOMRect : DOMRectReadOnly { - inherit attribute unrestricted double x; - inherit attribute unrestricted double y; - inherit attribute unrestricted double width; - inherit attribute unrestricted double height; +interface DOMRect +{ + readonly attribute float left; + readonly attribute float top; + readonly attribute float right; + readonly attribute float bottom; + readonly attribute float width; + readonly attribute float height; }; - -interface DOMRectReadOnly { - readonly attribute unrestricted double x; - readonly attribute unrestricted double y; - readonly attribute unrestricted double width; - readonly attribute unrestricted double height; - readonly attribute unrestricted double top; - readonly attribute unrestricted double right; - readonly attribute unrestricted double bottom; - readonly attribute unrestricted double left; -}; \ No newline at end of file diff --git a/dom/webidl/LegacyQueryInterface.webidl b/dom/webidl/LegacyQueryInterface.webidl index 20d70c5d6f3..fbe00d2c9f8 100644 --- a/dom/webidl/LegacyQueryInterface.webidl +++ b/dom/webidl/LegacyQueryInterface.webidl @@ -24,6 +24,8 @@ CSSStyleDeclaration implements LegacyQueryInterface; CSSValueList implements LegacyQueryInterface; DOMImplementation implements LegacyQueryInterface; DOMParser implements LegacyQueryInterface; +DOMRect implements LegacyQueryInterface; +DOMRectList implements LegacyQueryInterface; DOMStringMap implements LegacyQueryInterface; DOMTokenList implements LegacyQueryInterface; Document implements LegacyQueryInterface;