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/. */
|
2009-08-27 08:30:51 +04:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGATTRTEAROFFTABLE_H_
|
|
|
|
#define DOM_SVG_SVGATTRTEAROFFTABLE_H_
|
2009-08-27 08:30:51 +04:00
|
|
|
|
|
|
|
#include "nsDataHashtable.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsHashKeys.h"
|
2009-08-27 08:30:51 +04:00
|
|
|
|
2019-01-24 00:48:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2009-08-27 08:30:51 +04:00
|
|
|
/**
|
2019-04-09 23:04:33 +03:00
|
|
|
* Global hashmap to associate internal SVG data types (e.g. SVGAnimatedLength)
|
|
|
|
* with DOM tear-off objects (e.g. DOMSVGLength). This allows us to always
|
|
|
|
* return the same object for subsequent requests for DOM objects.
|
2009-08-27 08:30:51 +04:00
|
|
|
*
|
|
|
|
* We don't keep an owning reference to the tear-off objects so they are
|
|
|
|
* responsible for removing themselves from this table when they die.
|
|
|
|
*/
|
|
|
|
template <class SimpleType, class TearoffType>
|
2019-01-24 00:48:00 +03:00
|
|
|
class SVGAttrTearoffTable {
|
2009-08-27 08:30:51 +04:00
|
|
|
public:
|
2013-09-02 12:41:57 +04:00
|
|
|
#ifdef DEBUG
|
2019-01-24 00:48:00 +03:00
|
|
|
~SVGAttrTearoffTable() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mTable, "Tear-off objects remain in hashtable at shutdown.");
|
2009-08-27 08:30:51 +04:00
|
|
|
}
|
2013-09-02 12:41:57 +04:00
|
|
|
#endif
|
2009-08-27 08:30:51 +04:00
|
|
|
|
|
|
|
TearoffType* GetTearoff(SimpleType* aSimple);
|
|
|
|
|
|
|
|
void AddTearoff(SimpleType* aSimple, TearoffType* aTearoff);
|
|
|
|
|
|
|
|
void RemoveTearoff(SimpleType* aSimple);
|
|
|
|
|
|
|
|
private:
|
2020-08-29 17:24:37 +03:00
|
|
|
using SimpleTypePtrKey = nsPtrHashKey<SimpleType>;
|
|
|
|
using TearoffTable = nsDataHashtable<SimpleTypePtrKey, TearoffType*>;
|
2009-08-27 08:30:51 +04:00
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
TearoffTable* mTable;
|
2009-08-27 08:30:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class SimpleType, class TearoffType>
|
2019-01-24 00:48:00 +03:00
|
|
|
TearoffType* SVGAttrTearoffTable<SimpleType, TearoffType>::GetTearoff(
|
2009-08-27 08:30:51 +04:00
|
|
|
SimpleType* aSimple) {
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!mTable) return nullptr;
|
2009-08-27 08:30:51 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
TearoffType* tearoff = nullptr;
|
2010-07-11 16:30:35 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found =
|
2010-07-11 16:30:35 +04:00
|
|
|
#endif
|
2013-09-02 12:41:57 +04:00
|
|
|
mTable->Get(aSimple, &tearoff);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!found || tearoff,
|
|
|
|
"null pointer stored in attribute tear-off map");
|
2009-08-27 08:30:51 +04:00
|
|
|
|
|
|
|
return tearoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class SimpleType, class TearoffType>
|
2019-01-24 00:48:00 +03:00
|
|
|
void SVGAttrTearoffTable<SimpleType, TearoffType>::AddTearoff(
|
2009-08-27 08:30:51 +04:00
|
|
|
SimpleType* aSimple, TearoffType* aTearoff) {
|
2013-09-02 12:41:57 +04:00
|
|
|
if (!mTable) {
|
|
|
|
mTable = new TearoffTable;
|
2009-08-27 08:30:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We shouldn't be adding a tear-off if there already is one. If that happens,
|
|
|
|
// something is wrong.
|
2013-09-02 12:41:57 +04:00
|
|
|
if (mTable->Get(aSimple, nullptr)) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(false, "There is already a tear-off for this object.");
|
2009-08-27 08:30:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
mTable->Put(aSimple, aTearoff);
|
2009-08-27 08:30:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class SimpleType, class TearoffType>
|
2019-01-24 00:48:00 +03:00
|
|
|
void SVGAttrTearoffTable<SimpleType, TearoffType>::RemoveTearoff(
|
2009-08-27 08:30:51 +04:00
|
|
|
SimpleType* aSimple) {
|
2013-09-02 12:41:57 +04:00
|
|
|
if (!mTable) {
|
2009-08-27 08:30:51 +04:00
|
|
|
// Perhaps something happened in between creating the SimpleType object and
|
|
|
|
// registering it
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
mTable->Remove(aSimple);
|
|
|
|
if (mTable->Count() == 0) {
|
|
|
|
delete mTable;
|
|
|
|
mTable = nullptr;
|
|
|
|
}
|
2009-08-27 08:30:51 +04:00
|
|
|
}
|
|
|
|
|
2019-01-24 00:48:00 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGATTRTEAROFFTABLE_H_
|