Skip to content

Commit

Permalink
Back out 26f0d590a021, d92e88a18263, 5a2d12a34466 (bug 846995) for no…
Browse files Browse the repository at this point in the history
…t building

CLOSED TREE
  • Loading branch information
philor committed Mar 20, 2013
1 parent 128bde1 commit 21cd63d
Show file tree
Hide file tree
Showing 25 changed files with 694 additions and 692 deletions.
141 changes: 141 additions & 0 deletions content/svg/content/src/DOMSVGAnimatedTransformList.cpp
@@ -0,0 +1,141 @@
/* -*- 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 "DOMSVGAnimatedTransformList.h"
#include "DOMSVGTransformList.h"
#include "SVGAnimatedTransformList.h"
#include "nsSVGAttrTearoffTable.h"
#include "mozilla/dom/SVGAnimatedTransformListBinding.h"
#include "nsContentUtils.h"

namespace mozilla {

static
nsSVGAttrTearoffTable<SVGAnimatedTransformList,DOMSVGAnimatedTransformList>
sSVGAnimatedTransformListTearoffTable;

NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAnimatedTransformList, mElement)

NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGAnimatedTransformList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGAnimatedTransformList)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGAnimatedTransformList)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

JSObject*
DOMSVGAnimatedTransformList::WrapObject(JSContext* aCx, JSObject* aScope)
{
return mozilla::dom::SVGAnimatedTransformListBinding::Wrap(aCx, aScope, this);
}

//----------------------------------------------------------------------
already_AddRefed<DOMSVGTransformList>
DOMSVGAnimatedTransformList::BaseVal()
{
if (!mBaseVal) {
mBaseVal = new DOMSVGTransformList(this, InternalAList().GetBaseValue());
}
nsRefPtr<DOMSVGTransformList> baseVal = mBaseVal;
return baseVal.forget();
}

already_AddRefed<DOMSVGTransformList>
DOMSVGAnimatedTransformList::AnimVal()
{
if (!mAnimVal) {
mAnimVal = new DOMSVGTransformList(this, InternalAList().GetAnimValue());
}
nsRefPtr<DOMSVGTransformList> animVal = mAnimVal;
return animVal.forget();
}

/* static */ already_AddRefed<DOMSVGAnimatedTransformList>
DOMSVGAnimatedTransformList::GetDOMWrapper(SVGAnimatedTransformList *aList,
nsSVGElement *aElement)
{
nsRefPtr<DOMSVGAnimatedTransformList> wrapper =
sSVGAnimatedTransformListTearoffTable.GetTearoff(aList);
if (!wrapper) {
wrapper = new DOMSVGAnimatedTransformList(aElement);
sSVGAnimatedTransformListTearoffTable.AddTearoff(aList, wrapper);
}
return wrapper.forget();
}

/* static */ DOMSVGAnimatedTransformList*
DOMSVGAnimatedTransformList::GetDOMWrapperIfExists(
SVGAnimatedTransformList *aList)
{
return sSVGAnimatedTransformListTearoffTable.GetTearoff(aList);
}

DOMSVGAnimatedTransformList::~DOMSVGAnimatedTransformList()
{
// Script no longer has any references to us, to our base/animVal objects, or
// to any of their list items.
sSVGAnimatedTransformListTearoffTable.RemoveTearoff(&InternalAList());
}

void
DOMSVGAnimatedTransformList::InternalBaseValListWillChangeLengthTo(
uint32_t aNewLength)
{
// When the number of items in our internal counterpart's baseVal changes,
// we MUST keep our baseVal in sync. If we don't, script will either see a
// list that is too short and be unable to access indexes that should be
// valid, or else, MUCH WORSE, script will see a list that is too long and be
// able to access "items" at indexes that are out of bounds (read/write to
// bad memory)!!

nsRefPtr<DOMSVGAnimatedTransformList> kungFuDeathGrip;
if (mBaseVal) {
if (aNewLength < mBaseVal->LengthNoFlush()) {
// InternalListLengthWillChange might clear last reference to |this|.
// Retain a temporary reference to keep from dying before returning.
kungFuDeathGrip = this;
}
mBaseVal->InternalListLengthWillChange(aNewLength);
}

// If our attribute is not animating, then our animVal mirrors our baseVal
// and we must sync its length too. (If our attribute is animating, then the
// SMIL engine takes care of calling InternalAnimValListWillChangeLengthTo()
// if necessary.)

if (!IsAnimating()) {
InternalAnimValListWillChangeLengthTo(aNewLength);
}
}

void
DOMSVGAnimatedTransformList::InternalAnimValListWillChangeLengthTo(
uint32_t aNewLength)
{
if (mAnimVal) {
mAnimVal->InternalListLengthWillChange(aNewLength);
}
}

bool
DOMSVGAnimatedTransformList::IsAnimating() const
{
return InternalAList().IsAnimating();
}

SVGAnimatedTransformList&
DOMSVGAnimatedTransformList::InternalAList()
{
return *mElement->GetAnimatedTransformList();
}

const SVGAnimatedTransformList&
DOMSVGAnimatedTransformList::InternalAList() const
{
return *mElement->GetAnimatedTransformList();
}

} // namespace mozilla
130 changes: 130 additions & 0 deletions content/svg/content/src/DOMSVGAnimatedTransformList.h
@@ -0,0 +1,130 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
* 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/. */

#ifndef MOZILLA_DOMSVGANIMATEDTRANSFORMLIST_H__
#define MOZILLA_DOMSVGANIMATEDTRANSFORMLIST_H__

#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsSVGElement.h"
#include "nsWrapperCache.h"
#include "mozilla/Attributes.h"

namespace mozilla {

class DOMSVGTransformList;
class SVGAnimatedTransformList;

/**
* Class DOMSVGAnimatedTransformList
*
* This class is used to create the DOM tearoff objects that wrap internal
* SVGAnimatedTransformList objects.
*
* See the architecture comment in DOMSVGAnimatedLengthList.h (that's
* LENGTH list). The comment for that class largly applies to this one too
* and will go a long way to helping you understand the architecture here.
*
* This class is strongly intertwined with DOMSVGTransformList and
* DOMSVGTransform.
* Our DOMSVGTransformList base and anim vals are friends and take care of
* nulling out our pointers to them when they die (making our pointers to them
* true weak refs).
*/
class DOMSVGAnimatedTransformList MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
friend class DOMSVGTransformList;

public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGAnimatedTransformList)

/**
* Factory method to create and return a DOMSVGAnimatedTransformList wrapper
* for a given internal SVGAnimatedTransformList object. The factory takes
* care of caching the object that it returns so that the same object can be
* returned for the given SVGAnimatedTransformList each time it is requested.
* The cached object is only removed from the cache when it is destroyed due
* to there being no more references to it or to any of its descendant
* objects. If that happens, any subsequent call requesting the DOM wrapper
* for the SVGAnimatedTransformList will naturally result in a new
* DOMSVGAnimatedTransformList being returned.
*/
static already_AddRefed<DOMSVGAnimatedTransformList>
GetDOMWrapper(SVGAnimatedTransformList *aList, nsSVGElement *aElement);

/**
* This method returns the DOMSVGAnimatedTransformList wrapper for an internal
* SVGAnimatedTransformList object if it currently has a wrapper. If it does
* not, then nullptr is returned.
*/
static DOMSVGAnimatedTransformList*
GetDOMWrapperIfExists(SVGAnimatedTransformList *aList);

/**
* Called by internal code to notify us when we need to sync the length of
* our baseVal DOM list with its internal list. This is called just prior to
* the length of the internal baseVal list being changed so that any DOM list
* items that need to be removed from the DOM list can first get their values
* from their internal counterpart.
*
* The only time this method could fail is on OOM when trying to increase the
* length of the DOM list. If that happens then this method simply clears the
* list and returns. Callers just proceed as normal, and we simply accept
* that the DOM list will be empty (until successfully set to a new value).
*/
void InternalBaseValListWillChangeLengthTo(uint32_t aNewLength);
void InternalAnimValListWillChangeLengthTo(uint32_t aNewLength);

/**
* Returns true if our attribute is animating (in which case our animVal is
* not simply a mirror of our baseVal).
*/
bool IsAnimating() const;

// WebIDL
nsSVGElement* GetParentObject() const { return mElement; }
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
// These aren't weak refs because mBaseVal and mAnimVal are weak
already_AddRefed<DOMSVGTransformList> BaseVal();
already_AddRefed<DOMSVGTransformList> AnimVal();

private:

/**
* Only our static GetDOMWrapper() factory method may create objects of our
* type.
*/
explicit DOMSVGAnimatedTransformList(nsSVGElement *aElement)
: mBaseVal(nullptr)
, mAnimVal(nullptr)
, mElement(aElement)
{
SetIsDOMBinding();
}

~DOMSVGAnimatedTransformList();

/// Get a reference to this DOM wrapper object's internal counterpart.
SVGAnimatedTransformList& InternalAList();
const SVGAnimatedTransformList& InternalAList() const;

// Weak refs to our DOMSVGTransformList baseVal/animVal objects. These objects
// are friends and take care of clearing these pointers when they die, making
// these true weak references.
DOMSVGTransformList *mBaseVal;
DOMSVGTransformList *mAnimVal;

// Strong ref to our element to keep it alive. We hold this not only for
// ourself, but also for our base/animVal and all of their items.
nsRefPtr<nsSVGElement> mElement;
};

} // namespace mozilla

#endif // MOZILLA_DOMSVGANIMATEDTRANSFORMLIST_H__
6 changes: 3 additions & 3 deletions content/svg/content/src/DOMSVGTransform.cpp
Expand Up @@ -6,10 +6,10 @@

#include "DOMSVGTransform.h"
#include "mozilla/dom/SVGMatrix.h"
#include "SVGAnimatedTransformList.h"
#include "nsError.h"
#include "nsContentUtils.h"
#include "nsAttrValueInlines.h"
#include "nsSVGAnimatedTransformList.h"
#include "nsSVGAttrTearoffTable.h"
#include "mozilla/dom/SVGTransformBinding.h"

Expand Down Expand Up @@ -292,7 +292,7 @@ DOMSVGTransform::RemovingFromList()
SVGTransform&
DOMSVGTransform::InternalItem()
{
nsSVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
SVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
return mIsAnimValItem && alist->mAnimVal ?
(*alist->mAnimVal)[mListIndex] :
alist->mBaseVal[mListIndex];
Expand All @@ -308,7 +308,7 @@ DOMSVGTransform::InternalItem() const
bool
DOMSVGTransform::IndexIsValid()
{
nsSVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
SVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
return (mIsAnimValItem &&
mListIndex < alist->GetAnimValue().Length()) ||
(!mIsAnimValItem &&
Expand Down
6 changes: 3 additions & 3 deletions content/svg/content/src/DOMSVGTransformList.cpp
Expand Up @@ -6,7 +6,7 @@
#include "DOMSVGTransformList.h"
#include "DOMSVGTransform.h"
#include "mozilla/dom/SVGMatrix.h"
#include "nsSVGAnimatedTransformList.h"
#include "SVGAnimatedTransformList.h"
#include "nsSVGElement.h"
#include "nsContentUtils.h"
#include "mozilla/dom/SVGTransformListBinding.h"
Expand Down Expand Up @@ -34,7 +34,7 @@ void UpdateListIndicesFromIndex(
namespace mozilla {

// We could use NS_IMPL_CYCLE_COLLECTION_1, except that in Unlink() we need to
// clear our SVGAnimatedTransformList's weak ref to us to be safe. (The other
// clear our DOMSVGAnimatedTransformList's weak ref to us to be safe. (The other
// option would be to not unlink and rely on the breaking of the other edges in
// the cycle, as NS_SVG_VAL_IMPL_CYCLE_COLLECTION does.)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGTransformList)
Expand Down Expand Up @@ -114,7 +114,7 @@ DOMSVGTransformList::InternalListLengthWillChange(uint32_t aNewLength)
SVGTransformList&
DOMSVGTransformList::InternalList() const
{
nsSVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
SVGAnimatedTransformList *alist = Element()->GetAnimatedTransformList();
return IsAnimValList() && alist->mAnimVal ?
*alist->mAnimVal :
alist->mBaseVal;
Expand Down
8 changes: 4 additions & 4 deletions content/svg/content/src/DOMSVGTransformList.h
Expand Up @@ -7,7 +7,7 @@
#ifndef MOZILLA_DOMSVGTRANSFORMLIST_H__
#define MOZILLA_DOMSVGTRANSFORMLIST_H__

#include "mozilla/dom/SVGAnimatedTransformList.h"
#include "DOMSVGAnimatedTransformList.h"
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDebug.h"
Expand All @@ -33,7 +33,7 @@ class DOMSVGTransform;
* This class is used to create the DOM tearoff objects that wrap internal
* SVGTransformList objects.
*
* See the architecture comment in SVGAnimatedTransformList.h.
* See the architecture comment in DOMSVGAnimatedTransformList.h.
*/
class DOMSVGTransformList MOZ_FINAL : public nsISupports,
public nsWrapperCache
Expand All @@ -44,7 +44,7 @@ class DOMSVGTransformList MOZ_FINAL : public nsISupports,
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGTransformList)

DOMSVGTransformList(dom::SVGAnimatedTransformList *aAList,
DOMSVGTransformList(DOMSVGAnimatedTransformList *aAList,
const SVGTransformList &aInternalList)
: mAList(aAList)
{
Expand Down Expand Up @@ -162,7 +162,7 @@ class DOMSVGTransformList MOZ_FINAL : public nsISupports,
// of clearing our pointer to them when they die.
nsTArray<DOMSVGTransform*> mItems;

nsRefPtr<dom::SVGAnimatedTransformList> mAList;
nsRefPtr<DOMSVGAnimatedTransformList> mAList;
};

} // namespace mozilla
Expand Down
4 changes: 1 addition & 3 deletions content/svg/content/src/Makefile.in
Expand Up @@ -19,6 +19,7 @@ endif # !_MSC_VER
CPPSRCS = \
DOMSVGAnimatedLengthList.cpp \
DOMSVGAnimatedNumberList.cpp \
DOMSVGAnimatedTransformList.cpp \
DOMSVGLength.cpp \
DOMSVGLengthList.cpp \
DOMSVGNumber.cpp \
Expand All @@ -33,7 +34,6 @@ CPPSRCS = \
nsDOMSVGZoomEvent.cpp \
nsISVGPoint.cpp \
nsSVGAngle.cpp \
nsSVGAnimatedTransformList.cpp \
nsSVGBoolean.cpp \
nsSVGClass.cpp \
nsSVGDataParser.cpp \
Expand Down Expand Up @@ -156,7 +156,6 @@ include $(topsrcdir)/config/config.mk
FORCE_STATIC_LIB = 1

EXPORTS = \
nsSVGAnimatedTransformList.h \
nsSVGClass.h \
nsSVGElement.h \
nsSVGFeatures.h \
Expand All @@ -174,7 +173,6 @@ EXPORTS_mozilla/dom = \
SVGAnimatedAngle.h \
SVGAnimatedBoolean.h \
SVGAnimatedLength.h \
SVGAnimatedTransformList.h \
SVGAnimateElement.h \
SVGAnimateTransformElement.h \
SVGAnimateMotionElement.h \
Expand Down

0 comments on commit 21cd63d

Please sign in to comment.