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-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_DOMSVGLENGTH_H__
|
|
|
|
#define MOZILLA_DOMSVGLENGTH_H__
|
|
|
|
|
|
|
|
#include "DOMSVGLengthList.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIDOMSVGLength.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "SVGLength.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-04-12 01:26:29 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
class nsSVGElement;
|
|
|
|
|
|
|
|
// We make DOMSVGLength a pseudo-interface to allow us to QI to it in order to
|
|
|
|
// check that the objects that scripts pass to DOMSVGLengthList methods are our
|
|
|
|
// *native* length objects.
|
|
|
|
//
|
|
|
|
// {A8468350-7F7B-4976-9A7E-3765A1DADF9A}
|
|
|
|
#define MOZILLA_DOMSVGLENGTH_IID \
|
|
|
|
{ 0xA8468350, 0x7F7B, 0x4976, { 0x9A, 0x7E, 0x37, 0x65, 0xA1, 0xDA, 0xDF, 0x9A } }
|
|
|
|
|
2011-02-08 16:43:34 +03:00
|
|
|
#define MOZ_SVG_LIST_INDEX_BIT_COUNT 22 // supports > 4 million list items
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
class ErrorResult;
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
/**
|
|
|
|
* Class DOMSVGLength
|
|
|
|
*
|
|
|
|
* This class creates the DOM objects that wrap internal SVGLength objects that
|
|
|
|
* are in an SVGLengthList. It is also used to create the objects returned by
|
|
|
|
* SVGSVGElement.createSVGLength().
|
|
|
|
*
|
|
|
|
* For the DOM wrapper classes for non-list SVGLength, see nsSVGLength2.h.
|
|
|
|
*
|
|
|
|
* See the architecture comment in DOMSVGAnimatedLengthList.h.
|
|
|
|
*
|
|
|
|
* This class is strongly intertwined with DOMSVGAnimatedLengthList and
|
|
|
|
* DOMSVGLengthList. We are a friend of DOMSVGLengthList, and are responsible
|
|
|
|
* for nulling out our DOMSVGLengthList's pointer to us when we die, making it
|
|
|
|
* a real weak pointer.
|
|
|
|
*
|
|
|
|
* When objects of this type are in a DOMSVGLengthList they belong to an
|
|
|
|
* attribute. While they belong to an attribute, the objects' values come from
|
|
|
|
* their corresponding internal SVGLength objects in the internal SVGLengthList
|
|
|
|
* objects for the attribute. Getting and setting values of a DOMSVGLength
|
|
|
|
* requires reading and writing to its internal SVGLength. However, if the
|
|
|
|
* DOMSVGLength is detached from its DOMSVGLengthList then it first makes a
|
|
|
|
* copy of its internal SVGLength's value and unit so that it doesn't appear to
|
|
|
|
* "lose" its value from script's perspective on being removed from the list.
|
|
|
|
* This means that these DOM tearoffs have space to store these values, even
|
|
|
|
* though they're not used in the common case.
|
|
|
|
*
|
2014-08-06 03:15:00 +04:00
|
|
|
* Objects of this type are also used to reflect the baseVal and animVal of
|
|
|
|
* a single, non-list SVGLength attribute. Getting and settings values of the
|
|
|
|
* DOMSVGLength in this case requires reading and writing to the corresponding
|
|
|
|
* nsSVGLength2 object.
|
|
|
|
*
|
2010-07-17 01:42:12 +04:00
|
|
|
* This class also stores its current list index, attribute enum, and whether
|
|
|
|
* it belongs to a baseVal or animVal list. This is so that objects of this
|
|
|
|
* type can find their corresponding internal SVGLength.
|
|
|
|
*
|
|
|
|
* To use these classes for <length> attributes as well as <list-of-length>
|
|
|
|
* attributes, we would need to take a bit from mListIndex and use that to
|
|
|
|
* indicate whether the object belongs to a list or non-list attribute, then
|
|
|
|
* if-else as appropriate. The bug for doing that work is:
|
|
|
|
* https://bugzilla.mozilla.org/show_bug.cgi?id=571734
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMSVGLength final : public nsIDOMSVGLength,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsWrapperCache
|
2010-07-17 01:42:12 +04:00
|
|
|
{
|
2013-12-25 02:09:22 +04:00
|
|
|
friend class AutoChangeLengthNotifier;
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
/**
|
|
|
|
* Ctor for creating the object returned by nsSVGLength2::ToDOMBaseVal/ToDOMAnimVal
|
|
|
|
*/
|
|
|
|
DOMSVGLength(nsSVGLength2* aVal, nsSVGElement* aSVGElement, bool aAnimVal);
|
|
|
|
|
2014-06-24 20:36:45 +04:00
|
|
|
~DOMSVGLength();
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOMSVGLENGTH_IID)
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2014-04-12 01:26:29 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGLength)
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_DECL_NSIDOMSVGLENGTH
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic ctor for DOMSVGLength objects that are created for an attribute.
|
|
|
|
*/
|
|
|
|
DOMSVGLength(DOMSVGLengthList *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-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctor for creating the objects returned by SVGSVGElement.createSVGLength(),
|
|
|
|
* which do not initially belong to an attribute.
|
|
|
|
*/
|
|
|
|
DOMSVGLength();
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
static already_AddRefed<DOMSVGLength> GetTearOff(nsSVGLength2* aVal,
|
|
|
|
nsSVGElement* aSVGElement,
|
|
|
|
bool aAnimVal);
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
/**
|
2014-08-06 03:15:00 +04:00
|
|
|
* Create an unowned copy of a length that is owned or is reflecting a single
|
|
|
|
* attribute. The caller is responsible for the first AddRef().
|
2010-07-17 01:42:12 +04:00
|
|
|
*/
|
2014-08-06 03:15:00 +04:00
|
|
|
DOMSVGLength* Copy();
|
2010-07-17 01:42:12 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInList() const {
|
2010-07-17 01:42:12 +04:00
|
|
|
return !!mList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In future, if this class is used for non-list lengths, this will be
|
|
|
|
* different to IsInList().
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasOwner() const {
|
2010-07-17 01:42:12 +04:00
|
|
|
return !!mList;
|
|
|
|
}
|
|
|
|
|
2014-08-06 03:15:00 +04:00
|
|
|
/**
|
|
|
|
* Returns whether this length object is reflecting a single SVG element
|
|
|
|
* attribute. This includes the baseVal or animVal of SVGRectElement.x, for
|
|
|
|
* example, but not an item in an SVGLengthList, such as those in the
|
|
|
|
* baseVal or animVal of SVGTextElement.x.
|
|
|
|
*/
|
|
|
|
bool IsReflectingAttribute() const {
|
|
|
|
return mVal;
|
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
/**
|
|
|
|
* 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 DOMSVGLengthList).)
|
|
|
|
*/
|
|
|
|
void InsertingIntoList(DOMSVGLengthList *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-07-17 01:42:12 +04: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-07-17 01:42:12 +04: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-07-17 01:42:12 +04: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 values. (If it didn't do this, then it would
|
2010-12-03 19:40:23 +03:00
|
|
|
* "lose" its value on being removed.)
|
2010-07-17 01:42:12 +04:00
|
|
|
*/
|
|
|
|
void RemovingFromList();
|
|
|
|
|
|
|
|
SVGLength ToSVGLength();
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
// WebIDL
|
|
|
|
uint16_t UnitType();
|
|
|
|
float GetValue(ErrorResult& aRv);
|
|
|
|
void SetValue(float aValue, ErrorResult& aRv);
|
|
|
|
float ValueInSpecifiedUnits();
|
|
|
|
void SetValueInSpecifiedUnits(float aValue, ErrorResult& aRv);
|
|
|
|
// The XPCOM GetValueAsString is good
|
|
|
|
void SetValueAsString(const nsAString& aValue, ErrorResult& aRv);
|
|
|
|
void NewValueSpecifiedUnits(uint16_t aUnit, float aValue,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
void ConvertToSpecifiedUnits(uint16_t aUnit, ErrorResult& aRv);
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const {
|
|
|
|
auto svgElement = mList ? Element() : mSVGElement.get();
|
|
|
|
return static_cast<nsIDOMSVGElement*> (svgElement);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-04-12 01:26:29 +04:00
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
private:
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
nsSVGElement* Element() const {
|
2010-07-17 01:42:12 +04:00
|
|
|
return mList->Element();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t AttrEnum() const {
|
2010-07-17 01:42:12 +04:00
|
|
|
return mAttrEnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the axis that this length lies along. This method must only be called
|
|
|
|
* when this object is associated with an element (HasOwner() returns true).
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t Axis() const {
|
2010-07-17 01:42:12 +04:00
|
|
|
return mList->Axis();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a reference to the internal SVGLength list item that this DOM wrapper
|
|
|
|
* object currently wraps.
|
|
|
|
*
|
2010-12-03 19:40:23 +03:00
|
|
|
* To simplify the code we just have this one method for obtaining both
|
2010-07-17 01:42:12 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
SVGLength& InternalItem();
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IndexIsValid();
|
2010-12-03 19:40:23 +03:00
|
|
|
#endif
|
|
|
|
|
2016-07-21 20:49:38 +03:00
|
|
|
/**
|
|
|
|
* Clears soon-to-be-invalid weak references in external objects that were
|
|
|
|
* set up during the creation of this object. This should be called during
|
|
|
|
* destruction and during cycle collection.
|
|
|
|
*/
|
|
|
|
void CleanupWeakRefs();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGLengthList> mList;
|
2010-07-17 01:42:12 +04: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-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
// The following members are only used when we're not in a list:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mUnit:5; // can handle 31 units (the 10 SVG 1.1 units + rem, vw, vh, wm, calc + future additions)
|
2010-07-17 01:42:12 +04:00
|
|
|
float mValue;
|
2014-04-12 01:26:29 +04:00
|
|
|
|
|
|
|
// The following members are only used when we have an nsSVGLength2
|
|
|
|
nsSVGLength2* mVal; // kept alive because it belongs to mSVGElement
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSVGElement> mSVGElement;
|
2010-07-17 01:42:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(DOMSVGLength, MOZILLA_DOMSVGLENGTH_IID)
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-02-08 16:43:34 +03:00
|
|
|
#undef MOZ_SVG_LIST_INDEX_BIT_COUNT
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
#endif // MOZILLA_DOMSVGLENGTH_H__
|