2011-09-25 14:04:31 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
2012-05-21 04:12:37 -07: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/. */
|
2011-09-25 14:04:31 -07:00
|
|
|
|
|
|
|
#ifndef MOZILLA_SVGTRANSFORMLIST_H__
|
|
|
|
#define MOZILLA_SVGTRANSFORMLIST_H__
|
|
|
|
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "nsDebug.h"
|
2011-09-25 14:04:31 -07:00
|
|
|
#include "nsTArray.h"
|
2013-04-02 12:17:41 -07:00
|
|
|
#include "nsSVGTransform.h"
|
2011-09-25 14:04:31 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
namespace dom {
|
|
|
|
class SVGTransform;
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:04:31 -07: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 DOMSVGTransformList.
|
|
|
|
*/
|
|
|
|
class SVGTransformList
|
|
|
|
{
|
2013-04-14 15:56:34 -07:00
|
|
|
friend class nsSVGAnimatedTransformList;
|
2011-09-25 14:04:31 -07:00
|
|
|
friend class DOMSVGTransformList;
|
2013-04-02 12:17:41 -07:00
|
|
|
friend class dom::SVGTransform;
|
2011-09-25 14:04:31 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
SVGTransformList() {}
|
|
|
|
~SVGTransformList() {}
|
|
|
|
|
|
|
|
// 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-28 23:19:26 -07:00
|
|
|
bool IsEmpty() const {
|
2011-09-25 14:04:31 -07:00
|
|
|
return mItems.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t Length() const {
|
2011-09-25 14:04:31 -07:00
|
|
|
return mItems.Length();
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
const nsSVGTransform& operator[](uint32_t aIndex) const {
|
2011-09-25 14:04:31 -07:00
|
|
|
return mItems[aIndex];
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool operator==(const SVGTransformList& rhs) const {
|
2011-09-25 14:04:31 -07:00
|
|
|
return mItems == rhs.mItems;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool SetCapacity(uint32_t size) {
|
2011-09-25 14:04:31 -07:00
|
|
|
return mItems.SetCapacity(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compact() {
|
|
|
|
mItems.Compact();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix GetConsolidationMatrix() const;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// SVGAnimatedTransformList and having that class act as an intermediary so it
|
|
|
|
// can take care of keeping DOM wrappers in sync.
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These may fail on OOM if the internal capacity needs to be increased, in
|
|
|
|
* which case the list will be left unmodified.
|
|
|
|
*/
|
|
|
|
nsresult CopyFrom(const SVGTransformList& rhs);
|
2013-04-02 12:17:41 -07:00
|
|
|
nsresult CopyFrom(const nsTArray<nsSVGTransform>& aTransformArray);
|
2011-09-25 14:04:31 -07:00
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
nsSVGTransform& operator[](uint32_t aIndex) {
|
2011-09-25 14:04:31 -07:00
|
|
|
return mItems[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* This may fail (return false) on OOM if the internal capacity is being
|
2011-09-25 14:04:31 -07:00
|
|
|
* increased, in which case the list will be left unmodified.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
bool SetLength(uint32_t aNumberOfItems) {
|
2011-09-25 14:04:31 -07:00
|
|
|
return mItems.SetLength(aNumberOfItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
mItems.Clear();
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
bool InsertItem(uint32_t aIndex, const nsSVGTransform& aTransform) {
|
2011-09-25 14:04:31 -07:00
|
|
|
if (aIndex >= mItems.Length()) {
|
|
|
|
aIndex = mItems.Length();
|
|
|
|
}
|
|
|
|
return !!mItems.InsertElementAt(aIndex, aTransform);
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
void ReplaceItem(uint32_t aIndex, const nsSVGTransform& aTransform) {
|
2011-09-25 14:04:31 -07:00
|
|
|
NS_ABORT_IF_FALSE(aIndex < mItems.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
|
|
|
mItems[aIndex] = aTransform;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void RemoveItem(uint32_t aIndex) {
|
2011-09-25 14:04:31 -07:00
|
|
|
NS_ABORT_IF_FALSE(aIndex < mItems.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
|
|
|
mItems.RemoveElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
bool AppendItem(const nsSVGTransform& aTransform) {
|
2011-09-25 14:04:31 -07:00
|
|
|
return !!mItems.AppendElement(aTransform);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/*
|
2013-04-02 12:17:41 -07:00
|
|
|
* See SVGLengthList for the rationale for using FallibleTArray<nsSVGTransform>
|
|
|
|
* instead of FallibleTArray<nsSVGTransform, 1>.
|
2011-09-25 14:04:31 -07:00
|
|
|
*/
|
2013-04-02 12:17:41 -07:00
|
|
|
FallibleTArray<nsSVGTransform> mItems;
|
2011-09-25 14:04:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_SVGTRANSFORMLIST_H__
|