Bug 816778 Part 8: Convert SVGAnimatedBoolean to WebIDL r=bz

This commit is contained in:
David Zbarsky 2012-12-22 23:54:22 -05:00
parent 073c7334d5
commit fc2efedcc6
7 changed files with 134 additions and 46 deletions

View File

@ -92,6 +92,7 @@ CPPSRCS = \
nsSVGUseElement.cpp \
nsSVGViewBox.cpp \
nsSVGViewElement.cpp \
SVGAnimatedBoolean.cpp \
SVGAnimatedLengthList.cpp \
SVGAnimatedNumberList.cpp \
SVGAnimatedPathSegList.cpp \
@ -144,6 +145,12 @@ EXPORTS = \
SVGAttrValueWrapper.h \
$(NULL)
EXPORTS_NAMESPACES = mozilla/dom
EXPORTS_mozilla/dom = \
SVGAnimatedBoolean.h \
$(NULL)
include $(topsrcdir)/config/rules.mk
INCLUDES += \

View File

@ -0,0 +1,46 @@
/* -*- 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/. */
#include "SVGAnimatedBoolean.h"
#include "nsSVGBoolean.h"
#include "mozilla/dom/SVGAnimatedBooleanBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_CYCLE_COLLECTING_ADDREF(SVGAnimatedBoolean)
NS_IMPL_CYCLE_COLLECTING_RELEASE(SVGAnimatedBoolean)
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGAnimatedBoolean)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(SVGAnimatedBoolean)
// No unlinking mElement, we'd need to null out the value pointer (the object it
// points to is held by the element) and null-check it everywhere.
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(SVGAnimatedBoolean)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSVGElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(SVGAnimatedBoolean)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAnimatedBoolean)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedBoolean)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedBoolean)
NS_INTERFACE_MAP_END
DOMCI_DATA(SVGAnimatedBoolean, SVGAnimatedBoolean)
JSObject*
SVGAnimatedBoolean::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
return SVGAnimatedBooleanBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}

View File

@ -0,0 +1,55 @@
/* -*- 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/. */
#pragma once
#include "nsIDOMSVGAnimatedBoolean.h"
#include "nsWrapperCache.h"
#include "nsSVGElement.h"
#include "mozilla/Attributes.h"
#include "nsSVGBoolean.h"
namespace mozilla {
namespace dom {
class SVGAnimatedBoolean MOZ_FINAL : public nsIDOMSVGAnimatedBoolean,
public nsWrapperCache
{
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SVGAnimatedBoolean)
SVGAnimatedBoolean(nsSVGBoolean* aVal, nsSVGElement *aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement)
{
SetIsDOMBinding();
}
~SVGAnimatedBoolean();
NS_IMETHOD GetBaseVal(bool* aResult)
{ *aResult = BaseVal(); return NS_OK; }
NS_IMETHOD SetBaseVal(bool aValue)
{ mVal->SetBaseValue(aValue, mSVGElement); return NS_OK; }
// Script may have modified animation parameters or timeline -- DOM getters
// need to flush any resample requests to reflect these modifications.
NS_IMETHOD GetAnimVal(bool* aResult)
{
*aResult = AnimVal();
return NS_OK;
}
// WebIDL
nsSVGElement* GetParentObject() const { return mSVGElement; }
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap);
bool BaseVal() const { return mVal->GetBaseValue(); }
bool AnimVal() const { mSVGElement->FlushAnimations(); return mVal->GetAnimValue(); }
protected:
nsSVGBoolean* mVal; // kept alive because it belongs to content
nsRefPtr<nsSVGElement> mSVGElement;
};
} //namespace dom
} //namespace mozilla

View File

@ -8,25 +8,14 @@
#include "nsSVGBoolean.h"
#include "nsSMILValue.h"
#include "SMILBoolType.h"
#include "SVGAnimatedBoolean.h"
using namespace mozilla;
NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGBoolean::DOMAnimatedBoolean, mSVGElement)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGBoolean::DOMAnimatedBoolean)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGBoolean::DOMAnimatedBoolean)
DOMCI_DATA(SVGAnimatedBoolean, nsSVGBoolean::DOMAnimatedBoolean)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGBoolean::DOMAnimatedBoolean)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedBoolean)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedBoolean)
NS_INTERFACE_MAP_END
using namespace mozilla::dom;
/* Implementation */
static nsSVGAttrTearoffTable<nsSVGBoolean, nsSVGBoolean::DOMAnimatedBoolean>
static nsSVGAttrTearoffTable<nsSVGBoolean, SVGAnimatedBoolean>
sSVGAnimatedBooleanTearoffTable;
static nsresult
@ -121,10 +110,10 @@ nsresult
nsSVGBoolean::ToDOMAnimatedBoolean(nsIDOMSVGAnimatedBoolean **aResult,
nsSVGElement *aSVGElement)
{
nsRefPtr<DOMAnimatedBoolean> domAnimatedBoolean =
nsRefPtr<SVGAnimatedBoolean> domAnimatedBoolean =
sSVGAnimatedBooleanTearoffTable.GetTearoff(this);
if (!domAnimatedBoolean) {
domAnimatedBoolean = new DOMAnimatedBoolean(this, aSVGElement);
domAnimatedBoolean = new SVGAnimatedBoolean(this, aSVGElement);
sSVGAnimatedBooleanTearoffTable.AddTearoff(this, domAnimatedBoolean);
}
@ -132,7 +121,7 @@ nsSVGBoolean::ToDOMAnimatedBoolean(nsIDOMSVGAnimatedBoolean **aResult,
return NS_OK;
}
nsSVGBoolean::DOMAnimatedBoolean::~DOMAnimatedBoolean()
SVGAnimatedBoolean::~SVGAnimatedBoolean()
{
sSVGAnimatedBooleanTearoffTable.RemoveTearoff(mVal);
}

View File

@ -52,45 +52,18 @@ private:
uint8_t mAttrEnum; // element specified tracking for attribute
public:
struct DOMAnimatedBoolean MOZ_FINAL : public nsIDOMSVGAnimatedBoolean
{
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedBoolean)
DOMAnimatedBoolean(nsSVGBoolean* aVal, nsSVGElement *aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement) {}
virtual ~DOMAnimatedBoolean();
nsSVGBoolean* mVal; // kept alive because it belongs to content
nsRefPtr<nsSVGElement> mSVGElement;
NS_IMETHOD GetBaseVal(bool* aResult)
{ *aResult = mVal->GetBaseValue(); return NS_OK; }
NS_IMETHOD SetBaseVal(bool aValue)
{ mVal->SetBaseValue(aValue, mSVGElement); return NS_OK; }
// Script may have modified animation parameters or timeline -- DOM getters
// need to flush any resample requests to reflect these modifications.
NS_IMETHOD GetAnimVal(bool* aResult)
{
mSVGElement->FlushAnimations();
*aResult = mVal->GetAnimValue();
return NS_OK;
}
};
struct SMILBool : public nsISMILAttr
{
public:
SMILBool(nsSVGBoolean* aVal, nsSVGElement* aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement) {}
// These will stay alive because a nsISMILAttr only lives as long
// as the Compositing step, and DOM elements don't get a chance to
// die during that.
nsSVGBoolean* mVal;
nsSVGElement* mSVGElement;
// nsISMILAttr methods
virtual nsresult ValueFromString(const nsAString& aStr,
const nsISMILAnimationElement* aSrcElement,

View File

@ -0,0 +1,17 @@
/* -*- 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://www.w3.org/TR/SVG2/
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface SVGAnimatedBoolean {
attribute boolean baseVal;
readonly attribute boolean animVal;
};

View File

@ -68,6 +68,7 @@ webidl_files = \
PerformanceTiming.webidl \
RGBColor.webidl \
Screen.webidl \
SVGAnimatedBoolean.webidl \
SVGAnimatedNumberList.webidl \
SVGAnimatedPreserveAspectRatio.webidl \
SVGAnimatedTransformList.webidl \