2010-12-03 19:40:23 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
#ifndef MOZILLA_DOMSVGNUMBER_H__
|
|
|
|
#define MOZILLA_DOMSVGNUMBER_H__
|
|
|
|
|
|
|
|
#include "DOMSVGNumberList.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsTArray.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-05-30 11:36:52 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
class nsSVGElement;
|
|
|
|
|
2011-02-08 16:43:34 +03:00
|
|
|
#define MOZ_SVG_LIST_INDEX_BIT_COUNT 27 // supports > 134 million list items
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DOMSVGNumber
|
|
|
|
*
|
|
|
|
* This class creates the DOM objects that wrap internal SVGNumber objects that
|
|
|
|
* are in an SVGNumberList. It is also used to create the objects returned by
|
|
|
|
* SVGSVGElement.createSVGNumber().
|
|
|
|
*
|
|
|
|
* For the DOM wrapper classes for non-list SVGNumber, see nsSVGNumber2.h.
|
|
|
|
*
|
|
|
|
* See the architecture comment in DOMSVGAnimatedNumberList.h.
|
|
|
|
*
|
|
|
|
* See the comment in DOMSVGLength.h (yes, LENGTH), which applies here too.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMSVGNumber final : public nsISupports
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsWrapperCache
|
2010-12-03 19:40:23 +03:00
|
|
|
{
|
2013-12-25 02:09:22 +04:00
|
|
|
friend class AutoChangeNumberNotifier;
|
|
|
|
|
2014-06-24 20:36:45 +04:00
|
|
|
~DOMSVGNumber() {
|
|
|
|
// Our mList's weak ref to us must be nulled out when we die. If GC has
|
|
|
|
// unlinked us using the cycle collector code, then that has already
|
|
|
|
// happened, and mList is null.
|
|
|
|
if (mList) {
|
|
|
|
mList->mItems[mListIndex] = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2014-05-30 11:36:52 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGNumber)
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic ctor for DOMSVGNumber objects that are created for an attribute.
|
|
|
|
*/
|
|
|
|
DOMSVGNumber(DOMSVGNumberList *aList,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aAttrEnum,
|
|
|
|
uint32_t aListIndex,
|
2012-09-23 04:48:27 +04:00
|
|
|
bool aIsAnimValItem);
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctor for creating the objects returned by SVGSVGElement.createSVGNumber(),
|
|
|
|
* which do not initially belong to an attribute.
|
|
|
|
*/
|
2014-05-30 11:36:52 +04:00
|
|
|
explicit DOMSVGNumber(nsISupports* aParent);
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an unowned copy. The caller is responsible for the first AddRef().
|
|
|
|
*/
|
|
|
|
DOMSVGNumber* Clone() {
|
2014-05-30 11:36:52 +04:00
|
|
|
DOMSVGNumber *clone = new DOMSVGNumber(mParent);
|
2010-12-03 19:40:23 +03:00
|
|
|
clone->mValue = ToSVGNumber();
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInList() const {
|
2010-12-03 19:40:23 +03:00
|
|
|
return !!mList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In future, if this class is used for non-list numbers, this will be
|
|
|
|
* different to IsInList().
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasOwner() const {
|
2010-12-03 19:40:23 +03:00
|
|
|
return !!mList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called to notify this DOM object that it is being inserted
|
|
|
|
* into a list, and give it the information it needs as a result.
|
|
|
|
*
|
|
|
|
* This object MUST NOT already belong to a list when this method is called.
|
|
|
|
* That's not to say that script can't move these DOM objects between
|
|
|
|
* lists - it can - it's just that the logic to handle that (and send out
|
|
|
|
* the necessary notifications) is located elsewhere (in DOMSVGNumberList).)
|
|
|
|
*/
|
|
|
|
void InsertingIntoList(DOMSVGNumberList *aList,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aAttrEnum,
|
|
|
|
uint32_t aListIndex,
|
2012-09-23 04:48:27 +04:00
|
|
|
bool aIsAnimValItem);
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t MaxListIndex() {
|
2011-02-08 16:43:34 +03:00
|
|
|
return (1U << MOZ_SVG_LIST_INDEX_BIT_COUNT) - 1;
|
|
|
|
}
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
/// This method is called to notify this object that its list index changed.
|
2012-08-22 19:56:38 +04:00
|
|
|
void UpdateListIndex(uint32_t aListIndex) {
|
2010-12-03 19:40:23 +03:00
|
|
|
mListIndex = aListIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called to notify this DOM object that it is about to be
|
|
|
|
* removed from its current DOM list so that it can first make a copy of its
|
|
|
|
* internal counterpart's value. (If it didn't do this, then it would
|
|
|
|
* "lose" its value on being removed.)
|
|
|
|
*/
|
|
|
|
void RemovingFromList();
|
|
|
|
|
|
|
|
float ToSVGNumber();
|
|
|
|
|
2014-05-30 11:36:52 +04:00
|
|
|
nsISupports* GetParentObject()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-05-30 11:36:52 +04:00
|
|
|
|
|
|
|
static already_AddRefed<DOMSVGNumber>
|
|
|
|
Constructor(const dom::GlobalObject& aGlobal, ErrorResult& aRv);
|
|
|
|
|
|
|
|
static already_AddRefed<DOMSVGNumber>
|
|
|
|
Constructor(const dom::GlobalObject& aGlobal, float aValue, ErrorResult& aRv);
|
|
|
|
|
|
|
|
float Value();
|
|
|
|
|
|
|
|
void SetValue(float aValue, ErrorResult& aRv);
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
nsSVGElement* Element() {
|
|
|
|
return mList->Element();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t AttrEnum() const {
|
2010-12-03 19:40:23 +03:00
|
|
|
return mAttrEnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a reference to the internal SVGNumber list item that this DOM wrapper
|
|
|
|
* object currently wraps.
|
|
|
|
*
|
|
|
|
* To simplify the code we just have this one method for obtaining both
|
|
|
|
* baseVal and animVal internal items. This means that animVal items don't
|
|
|
|
* get const protection, but then our setter methods guard against changing
|
|
|
|
* animVal items.
|
|
|
|
*/
|
|
|
|
float& InternalItem();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IndexIsValid();
|
2010-12-03 19:40:23 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsRefPtr<DOMSVGNumberList> mList;
|
2014-05-30 11:36:52 +04:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
// Bounds for the following are checked in the ctor, so be sure to update
|
|
|
|
// that if you change the capacity of any of the following.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mListIndex:MOZ_SVG_LIST_INDEX_BIT_COUNT;
|
|
|
|
uint32_t mAttrEnum:4; // supports up to 16 attributes
|
|
|
|
uint32_t mIsAnimValItem:1;
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
// The following member is only used when we're not in a list:
|
|
|
|
float mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-02-08 16:43:34 +03:00
|
|
|
#undef MOZ_SVG_LIST_INDEX_BIT_COUNT
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
#endif // MOZILLA_DOMSVGNUMBER_H__
|