2015-05-03 22:32:37 +03: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 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_SVGNUMBERLIST_H__
|
|
|
|
#define MOZILLA_SVGNUMBERLIST_H__
|
|
|
|
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2018-12-21 11:58:14 +03:00
|
|
|
#include "SVGElement.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsTArray.h"
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2018-12-28 16:42:46 +03:00
|
|
|
namespace dom {
|
|
|
|
class DOMSVGNumber;
|
|
|
|
class DOMSVGNumberList;
|
|
|
|
} // namespace dom
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
/**
|
|
|
|
* 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 {
|
2018-12-28 16:42:46 +03:00
|
|
|
friend class dom::DOMSVGNumber;
|
|
|
|
friend class dom::DOMSVGNumberList;
|
2010-12-03 19:40:23 +03:00
|
|
|
friend class SVGAnimatedNumberList;
|
|
|
|
|
|
|
|
public:
|
2019-04-10 07:34:35 +03:00
|
|
|
SVGNumberList() = default;
|
|
|
|
~SVGNumberList() = default;
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
bool IsEmpty() const { return mNumbers.IsEmpty(); }
|
|
|
|
|
|
|
|
uint32_t Length() const { return mNumbers.Length(); }
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
const float& operator[](uint32_t aIndex) const { return mNumbers[aIndex]; }
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool operator==(const SVGNumberList& rhs) const {
|
2010-12-03 19:40:23 +03:00
|
|
|
return mNumbers == rhs.mNumbers;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool SetCapacity(uint32_t size) {
|
2015-05-18 23:50:34 +03:00
|
|
|
return mNumbers.SetCapacity(size, fallible);
|
2010-12-03 19:40:23 +03: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 19:56:38 +04:00
|
|
|
float& operator[](uint32_t aIndex) { return mNumbers[aIndex]; }
|
2010-12-03 19:40:23 +03:00
|
|
|
|
|
|
|
/**
|
2011-10-17 18:59:28 +04:00
|
|
|
* This may fail (return false) on OOM if the internal capacity is being
|
2010-12-03 19:40:23 +03:00
|
|
|
* increased, in which case the list will be left unmodified.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
bool SetLength(uint32_t aNumberOfItems) {
|
2015-05-18 23:50:35 +03:00
|
|
|
return mNumbers.SetLength(aNumberOfItems, fallible);
|
2010-12-03 19:40:23 +03: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 19:56:38 +04:00
|
|
|
bool InsertItem(uint32_t aIndex, const float& aNumber) {
|
2010-12-03 19:40:23 +03:00
|
|
|
if (aIndex >= mNumbers.Length()) {
|
|
|
|
aIndex = mNumbers.Length();
|
|
|
|
}
|
2015-05-28 21:07:43 +03:00
|
|
|
return !!mNumbers.InsertElementAt(aIndex, aNumber, fallible);
|
2010-12-03 19:40:23 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void ReplaceItem(uint32_t aIndex, const float& aNumber) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aIndex < mNumbers.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
2010-12-03 19:40:23 +03:00
|
|
|
mNumbers[aIndex] = aNumber;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void RemoveItem(uint32_t aIndex) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aIndex < mNumbers.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
2010-12-03 19:40:23 +03:00
|
|
|
mNumbers.RemoveElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool AppendItem(float aNumber) {
|
2015-05-28 21:07:44 +03:00
|
|
|
return !!mNumbers.AppendElement(aNumber, fallible);
|
2010-12-03 19:40:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-03-22 04:00:01 +04:00
|
|
|
/* See SVGLengthList for the rationale for using FallibleTArray<float> instead
|
|
|
|
* of FallibleTArray<float, 1>.
|
2010-12-03 19:40:23 +03:00
|
|
|
*/
|
2013-03-22 04:00:01 +04:00
|
|
|
FallibleTArray<float> mNumbers;
|
2010-12-03 19:40:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This SVGNumberList subclass is used by the SMIL code when a number list
|
2019-01-23 16:48:08 +03:00
|
|
|
* is to be stored in a SMILValue instance. Since SMILValue objects may
|
2010-12-03 19:40:23 +03:00
|
|
|
* 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() : mElement(nullptr) {}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
explicit SVGNumberListAndInfo(dom::SVGElement* aElement)
|
2011-05-02 23:19:20 +04:00
|
|
|
: mElement(do_GetWeakReference(static_cast<nsINode*>(aElement))) {}
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
void SetInfo(dom::SVGElement* aElement) {
|
2011-05-02 23:19:20 +04:00
|
|
|
mElement = do_GetWeakReference(static_cast<nsINode*>(aElement));
|
2010-12-03 19:40:23 +03:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
dom::SVGElement* Element() const {
|
2011-05-02 23:19:20 +04:00
|
|
|
nsCOMPtr<nsIContent> e = do_QueryReferent(mElement);
|
2018-12-21 11:58:14 +03:00
|
|
|
return static_cast<dom::SVGElement*>(e.get());
|
2010-12-03 19:40:23 +03: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 19:56:38 +04:00
|
|
|
const float& operator[](uint32_t aIndex) const {
|
2010-12-03 19:40:23 +03:00
|
|
|
return SVGNumberList::operator[](aIndex);
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
float& operator[](uint32_t aIndex) {
|
2010-12-03 19:40:23 +03:00
|
|
|
return SVGNumberList::operator[](aIndex);
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
bool SetLength(uint32_t aNumberOfItems) {
|
2010-12-03 19:40:23 +03:00
|
|
|
return SVGNumberList::SetLength(aNumberOfItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-05-02 23:19:20 +04:00
|
|
|
// We must keep a weak reference to our element because we may belong to a
|
2019-01-23 16:48:08 +03:00
|
|
|
// cached baseVal SMILValue. See the comments starting at:
|
2010-12-03 19:40:23 +03:00
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=515116#c15
|
2011-05-02 23:19:20 +04:00
|
|
|
// See also https://bugzilla.mozilla.org/show_bug.cgi?id=653497
|
|
|
|
nsWeakPtr mElement;
|
2010-12-03 19:40:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGNUMBERLIST_H__
|