2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 16:40:23 +00:00
|
|
|
|
|
|
|
#ifndef MOZILLA_SVGNUMBERLIST_H__
|
|
|
|
#define MOZILLA_SVGNUMBERLIST_H__
|
|
|
|
|
2012-01-26 09:57:21 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2010-12-03 16:40:23 +00:00
|
|
|
#include "nsSVGElement.h"
|
2012-01-26 09:57:21 +00:00
|
|
|
#include "nsTArray.h"
|
2010-12-03 16:40:23 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ATTENTION! WARNING! WATCH OUT!!
|
|
|
|
*
|
|
|
|
* Consumers that modify objects of this type absolutely MUST keep the DOM
|
|
|
|
* wrappers for those lists (if any) in sync!! That's why this class is so
|
|
|
|
* locked down.
|
|
|
|
*
|
|
|
|
* The DOM wrapper class for this class is DOMSVGNumberList.
|
|
|
|
*/
|
|
|
|
class SVGNumberList
|
|
|
|
{
|
|
|
|
friend class SVGAnimatedNumberList;
|
|
|
|
friend class DOMSVGNumberList;
|
|
|
|
friend class DOMSVGNumber;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
SVGNumberList(){}
|
|
|
|
~SVGNumberList(){}
|
|
|
|
|
|
|
|
// Only methods that don't make/permit modification to this list are public.
|
|
|
|
// Only our friend classes can access methods that may change us.
|
|
|
|
|
|
|
|
/// This may return an incomplete string on OOM, but that's acceptable.
|
|
|
|
void GetValueAsString(nsAString& aValue) const;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsEmpty() const {
|
2010-12-03 16:40:23 +00:00
|
|
|
return mNumbers.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t Length() const {
|
2010-12-03 16:40:23 +00:00
|
|
|
return mNumbers.Length();
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
const float& operator[](uint32_t aIndex) const {
|
2010-12-03 16:40:23 +00:00
|
|
|
return mNumbers[aIndex];
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool operator==(const SVGNumberList& rhs) const {
|
2010-12-03 16:40:23 +00:00
|
|
|
return mNumbers == rhs.mNumbers;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool SetCapacity(uint32_t size) {
|
2015-05-18 20:50:34 +00:00
|
|
|
return mNumbers.SetCapacity(size, fallible);
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compact() {
|
|
|
|
mNumbers.Compact();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Access to methods that can modify objects of this type is deliberately
|
|
|
|
// limited. This is to reduce the chances of someone modifying objects of
|
|
|
|
// this type without taking the necessary steps to keep DOM wrappers in sync.
|
|
|
|
// If you need wider access to these methods, consider adding a method to
|
|
|
|
// SVGAnimatedNumberList and having that class act as an intermediary so it
|
|
|
|
// can take care of keeping DOM wrappers in sync.
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This may fail on OOM if the internal capacity needs to be increased, in
|
|
|
|
* which case the list will be left unmodified.
|
|
|
|
*/
|
|
|
|
nsresult CopyFrom(const SVGNumberList& rhs);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
float& operator[](uint32_t aIndex) {
|
2010-12-03 16:40:23 +00:00
|
|
|
return mNumbers[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-17 14:59:28 +00:00
|
|
|
* This may fail (return false) on OOM if the internal capacity is being
|
2010-12-03 16:40:23 +00:00
|
|
|
* increased, in which case the list will be left unmodified.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
bool SetLength(uint32_t aNumberOfItems) {
|
2015-05-18 20:50:35 +00:00
|
|
|
return mNumbers.SetLength(aNumberOfItems, fallible);
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Marking the following private only serves to show which methods are only
|
|
|
|
// used by our friend classes (as opposed to our subclasses) - it doesn't
|
|
|
|
// really provide additional safety.
|
|
|
|
|
|
|
|
nsresult SetValueFromString(const nsAString& aValue);
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
mNumbers.Clear();
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool InsertItem(uint32_t aIndex, const float &aNumber) {
|
2010-12-03 16:40:23 +00:00
|
|
|
if (aIndex >= mNumbers.Length()) {
|
|
|
|
aIndex = mNumbers.Length();
|
|
|
|
}
|
2015-05-28 18:07:43 +00:00
|
|
|
return !!mNumbers.InsertElementAt(aIndex, aNumber, fallible);
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void ReplaceItem(uint32_t aIndex, const float &aNumber) {
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aIndex < mNumbers.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
2010-12-03 16:40:23 +00:00
|
|
|
mNumbers[aIndex] = aNumber;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void RemoveItem(uint32_t aIndex) {
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aIndex < mNumbers.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
2010-12-03 16:40:23 +00:00
|
|
|
mNumbers.RemoveElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool AppendItem(float aNumber) {
|
2015-05-28 18:07:44 +00:00
|
|
|
return !!mNumbers.AppendElement(aNumber, fallible);
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2013-03-22 00:00:01 +00:00
|
|
|
/* See SVGLengthList for the rationale for using FallibleTArray<float> instead
|
|
|
|
* of FallibleTArray<float, 1>.
|
2010-12-03 16:40:23 +00:00
|
|
|
*/
|
2013-03-22 00:00:01 +00:00
|
|
|
FallibleTArray<float> mNumbers;
|
2010-12-03 16:40:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This SVGNumberList subclass is used by the SMIL code when a number list
|
|
|
|
* is to be stored in an nsISMILValue instance. Since nsISMILValue objects may
|
|
|
|
* be cached, it is necessary for us to hold a strong reference to our element
|
|
|
|
* so that it doesn't disappear out from under us if, say, the element is
|
|
|
|
* removed from the DOM tree.
|
|
|
|
*/
|
|
|
|
class SVGNumberListAndInfo : public SVGNumberList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
SVGNumberListAndInfo()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mElement(nullptr)
|
2010-12-03 16:40:23 +00:00
|
|
|
{}
|
|
|
|
|
2014-09-01 01:08:04 +00:00
|
|
|
explicit SVGNumberListAndInfo(nsSVGElement *aElement)
|
2011-05-02 19:19:20 +00:00
|
|
|
: mElement(do_GetWeakReference(static_cast<nsINode*>(aElement)))
|
2010-12-03 16:40:23 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void SetInfo(nsSVGElement *aElement) {
|
2011-05-02 19:19:20 +00:00
|
|
|
mElement = do_GetWeakReference(static_cast<nsINode*>(aElement));
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement* Element() const {
|
2011-05-02 19:19:20 +00:00
|
|
|
nsCOMPtr<nsIContent> e = do_QueryReferent(mElement);
|
|
|
|
return static_cast<nsSVGElement*>(e.get());
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult CopyFrom(const SVGNumberListAndInfo& rhs) {
|
|
|
|
mElement = rhs.mElement;
|
|
|
|
return SVGNumberList::CopyFrom(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instances of this special subclass do not have DOM wrappers that we need
|
|
|
|
// to worry about keeping in sync, so it's safe to expose any hidden base
|
|
|
|
// class methods required by the SMIL code, as we do below.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exposed so that SVGNumberList baseVals can be copied to
|
|
|
|
* SVGNumberListAndInfo objects. Note that callers should also call
|
|
|
|
* SetInfo() when using this method!
|
|
|
|
*/
|
|
|
|
nsresult CopyFrom(const SVGNumberList& rhs) {
|
|
|
|
return SVGNumberList::CopyFrom(rhs);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
const float& operator[](uint32_t aIndex) const {
|
2010-12-03 16:40:23 +00:00
|
|
|
return SVGNumberList::operator[](aIndex);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
float& operator[](uint32_t aIndex) {
|
2010-12-03 16:40:23 +00:00
|
|
|
return SVGNumberList::operator[](aIndex);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
bool SetLength(uint32_t aNumberOfItems) {
|
2010-12-03 16:40:23 +00:00
|
|
|
return SVGNumberList::SetLength(aNumberOfItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-05-02 19:19:20 +00:00
|
|
|
// We must keep a weak reference to our element because we may belong to a
|
2010-12-03 16:40:23 +00:00
|
|
|
// cached baseVal nsSMILValue. See the comments starting at:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=515116#c15
|
2011-05-02 19:19:20 +00:00
|
|
|
// See also https://bugzilla.mozilla.org/show_bug.cgi?id=653497
|
|
|
|
nsWeakPtr mElement;
|
2010-12-03 16:40:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGNUMBERLIST_H__
|