2015-05-03 12:32:37 -07: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: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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;
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace dom
|
2013-04-02 12:17:41 -07:00
|
|
|
|
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) {
|
2015-05-18 13:50:34 -07:00
|
|
|
return mItems.SetCapacity(size, fallible);
|
2011-09-25 14:04:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2015-05-18 13:50:35 -07:00
|
|
|
return mItems.SetLength(aNumberOfItems, fallible);
|
2011-09-25 14:04:31 -07: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() {
|
|
|
|
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();
|
|
|
|
}
|
2015-05-28 11:07:43 -07:00
|
|
|
return !!mItems.InsertElementAt(aIndex, aTransform, fallible);
|
2011-09-25 14:04:31 -07:00
|
|
|
}
|
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
void ReplaceItem(uint32_t aIndex, const nsSVGTransform& aTransform) {
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(aIndex < mItems.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
2011-09-25 14:04:31 -07:00
|
|
|
mItems[aIndex] = aTransform;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void RemoveItem(uint32_t aIndex) {
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(aIndex < mItems.Length(),
|
|
|
|
"DOM wrapper caller should have raised INDEX_SIZE_ERR");
|
2011-09-25 14:04:31 -07:00
|
|
|
mItems.RemoveElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:17:41 -07:00
|
|
|
bool AppendItem(const nsSVGTransform& aTransform) {
|
2015-05-28 11:07:44 -07:00
|
|
|
return !!mItems.AppendElement(aTransform, fallible);
|
2011-09-25 14:04:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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__
|