# HG changeset patch # User Jet Villegas # Date 1363691791 -3600 # Node ID 1eadead0d6ccbcedf6c2ef47d8f56a022a8ba249 # Parent b2636816c7fdd53110d877c57d7fcbb1c4396bdc Bug 850805 - Implement DOMPoint/WebKitPoint diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -232,16 +232,20 @@ DOMInterfaces = { 'DOMParser': { 'nativeType': 'nsDOMParser', }, 'DocumentFragment': { 'resultNotAddRefed': [ 'querySelector' ] }, +'DOMPoint': { + 'nativeOwnership': 'refcounted', +}, + 'DOMSettableTokenList': { 'nativeType': 'nsDOMSettableTokenList', }, 'DOMStringMap': { 'nativeType': 'nsDOMStringMap' }, diff --git a/dom/webidl/DOMPoint.webidl b/dom/webidl/DOMPoint.webidl new file mode 100644 --- /dev/null +++ b/dom/webidl/DOMPoint.webidl @@ -0,0 +1,15 @@ +/* -*- 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/. + */ + + +[Constructor(optional float x = 0, optional float y = 0), + NamedConstructor=WebKitPoint(optional float x = 0, optional float y = 0)] +interface DOMPoint { + + attribute float x; + attribute float y; +}; + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -39,16 +39,17 @@ webidl_files = \ CSSValueList.webidl \ DelayNode.webidl \ Document.webidl \ DocumentFragment.webidl \ DocumentType.webidl \ DOMCursor.webidl \ DOMImplementation.webidl \ DOMParser.webidl \ + DOMPoint.webidl \ DOMRequest.webidl \ DOMSettableTokenList.webidl \ DOMStringMap.webidl \ DOMTokenList.webidl \ DOMTransaction.webidl \ DummyBinding.webidl \ DynamicsCompressorNode.webidl \ Element.webidl \ diff --git a/layout/style/DOMPoint.cpp b/layout/style/DOMPoint.cpp new file mode 100644 --- /dev/null +++ b/layout/style/DOMPoint.cpp @@ -0,0 +1,62 @@ +/* -*- Mode: C++; 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/. */ + +/* DOM object representing a CSS pixel's position. */ + +#include "DOMPoint.h" +#include "nsContentUtils.h" +#include "mozilla/dom/DOMPointBinding.h" +#include "mozilla/Preferences.h" + +namespace mozilla { +namespace dom { + +/* static */ already_AddRefed +DOMPoint::Constructor(const GlobalObject& aGlobal, float aX, float aY, ErrorResult& aError) +{ + if (!PrefEnabled()) { + aError.Throw(NS_ERROR_UNEXPECTED); + return nullptr; + } + + nsRefPtr pt = new DOMPoint(aX, aY); + + return pt.forget(); +} + +/* static */ already_AddRefed +DOMPoint::WebKitPoint(const GlobalObject& aGlobal, float aX, float aY, ErrorResult& aError) +{ + return Constructor(aGlobal, aX, aY, aError); +} + +DOMPoint::DOMPoint(float aX, float aY) +: mX(aX), mY(aY) +{ + SetIsDOMBinding(); +} + +DOMPoint::~DOMPoint() +{ + +} + +JSObject* +DOMPoint::WrapObject(JSContext *aCx, JSObject *aScope) +{ + return dom::DOMPointBinding::Wrap(aCx, aScope, this); +} + +/* static */ bool +DOMPoint::PrefEnabled() +{ + return Preferences::GetBool("layout.css.dompoint.enabled", true); +} + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(DOMPoint) +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMPoint, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMPoint, Release) + +} // namespace dom +} // namespace mozilla diff --git a/layout/style/DOMPoint.h b/layout/style/DOMPoint.h new file mode 100644 --- /dev/null +++ b/layout/style/DOMPoint.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; 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/. */ + +/* DOM object representing a CSS pixel's position. */ + +#ifndef DOMPoint_h__ +#define DOMPoint_h__ + +#include "nsAutoPtr.h" +#include "mozilla/Attributes.h" +// #include "nsISupports.h" //NonRefcountedDOMObject.h" +#include "nsWrapperCache.h" + +namespace mozilla { + +class ErrorResult; + +namespace dom { + +class GlobalObject; + +class DOMPoint MOZ_FINAL : public nsWrapperCache +{ +public: + + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMPoint) + + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMPoint) + + static already_AddRefed + Constructor(const GlobalObject& aGlobal, float aX, float aY, ErrorResult& aError); + + static already_AddRefed + WebKitPoint(const GlobalObject& aGlobal, float aX, float aY, ErrorResult& aError); + + DOMPoint(float aX, float aY); + + ~DOMPoint(); + + // DOMPoint webidl interface + void SetX(float aX) // to-do: add error handling here + { + mX = aX; + } + + void SetY(float aY) + { + mY = aY; + } + + float X() + { + return mX; + } + + float Y() + { + return mY; + } + + nsISupports* GetParentObject() const + { + return nullptr; + } + + static bool PrefEnabled(); + + JSObject* WrapObject(JSContext *cx, JSObject *scope); + +private: + float mX; // to_do: move this to a real internal point struct + float mY; +}; + +} // namespace dom +} // namespace mozilla + +#endif // DOMPoint_h__ diff --git a/layout/style/Makefile.in b/layout/style/Makefile.in --- a/layout/style/Makefile.in +++ b/layout/style/Makefile.in @@ -82,24 +82,26 @@ EXPORTS_mozilla/css = \ NameSpaceRule.h \ Rule.h \ StyleRule.h \ $(NULL) EXPORTS_mozilla/dom = \ CSS.h \ CSSValue.h \ + DOMPoint.h \ $(NULL) CPPSRCS = \ AnimationCommon.cpp \ CSS.cpp \ nsCSSAnonBoxes.cpp \ nsCSSDataBlock.cpp \ Declaration.cpp \ + DOMPoint.cpp \ ErrorReporter.cpp \ nsCSSKeywords.cpp \ ImageLoader.cpp \ Loader.cpp \ nsAnimationManager.cpp \ nsCSSParser.cpp \ nsCSSProps.cpp \ nsCSSPseudoClasses.cpp \