Bug 949435, Part 1 - Move nsGenericHTMLElement::GetTokenList to Element. r=bz

This commit is contained in:
Ryo HIKOSAKA 2014-02-18 10:12:54 +09:00
parent 333ed8439c
commit 3661b7af5c
4 changed files with 82 additions and 78 deletions

View File

@ -49,6 +49,7 @@ class nsIScrollableFrame;
class nsAttrValueOrString;
class ContentUnbinder;
class nsContentList;
class nsDOMSettableTokenList;
class nsDOMTokenList;
struct nsRect;
class nsFocusManager;
@ -1164,6 +1165,10 @@ protected:
*/
virtual void GetLinkTarget(nsAString& aTarget);
nsDOMSettableTokenList* GetTokenList(nsIAtom* aAtom);
void GetTokenList(nsIAtom* aAtom, nsIVariant** aResult);
nsresult SetTokenList(nsIAtom* aAtom, nsIVariant* aValue);
private:
/**
* Get this element's client area rect in app units.

View File

@ -41,6 +41,8 @@
#include "nsDOMCSSAttrDeclaration.h"
#include "nsNameSpaceManager.h"
#include "nsContentList.h"
#include "nsVariant.h"
#include "nsDOMSettableTokenList.h"
#include "nsDOMTokenList.h"
#include "nsXBLPrototypeBinding.h"
#include "nsError.h"
@ -2526,6 +2528,81 @@ Element::GetLinkTarget(nsAString& aTarget)
aTarget.Truncate();
}
static void
nsDOMSettableTokenListPropertyDestructor(void *aObject, nsIAtom *aProperty,
void *aPropertyValue, void *aData)
{
nsDOMSettableTokenList* list =
static_cast<nsDOMSettableTokenList*>(aPropertyValue);
NS_RELEASE(list);
}
static nsIAtom** sPropertiesToTraverseAndUnlink[] =
{
&nsGkAtoms::microdataProperties,
&nsGkAtoms::itemtype,
&nsGkAtoms::itemref,
&nsGkAtoms::itemprop,
&nsGkAtoms::sandbox,
&nsGkAtoms::sizes,
nullptr
};
// static
nsIAtom***
nsGenericHTMLElement::PropertiesToTraverseAndUnlink()
{
return sPropertiesToTraverseAndUnlink;
}
nsDOMSettableTokenList*
Element::GetTokenList(nsIAtom* aAtom)
{
#ifdef DEBUG
nsIAtom*** props =
nsGenericHTMLElement::PropertiesToTraverseAndUnlink();
bool found = false;
for (uint32_t i = 0; props[i]; ++i) {
if (*props[i] == aAtom) {
found = true;
break;
}
}
MOZ_ASSERT(found, "Trying to use an unknown tokenlist!");
#endif
nsDOMSettableTokenList* list = nullptr;
if (HasProperties()) {
list = static_cast<nsDOMSettableTokenList*>(GetProperty(aAtom));
}
if (!list) {
list = new nsDOMSettableTokenList(this, aAtom);
NS_ADDREF(list);
SetProperty(aAtom, list, nsDOMSettableTokenListPropertyDestructor);
}
return list;
}
void
Element::GetTokenList(nsIAtom* aAtom, nsIVariant** aResult)
{
nsISupports* itemType = GetTokenList(aAtom);
nsCOMPtr<nsIWritableVariant> out = new nsVariant();
out->SetAsInterface(NS_GET_IID(nsISupports), itemType);
out.forget(aResult);
}
nsresult
Element::SetTokenList(nsIAtom* aAtom, nsIVariant* aValue)
{
nsDOMSettableTokenList* itemType = GetTokenList(aAtom);
nsAutoString string;
aValue->GetAsAString(string);
ErrorResult rv;
itemType->SetValue(string, rv);
return rv.ErrorCode();
}
bool
Element::MozMatchesSelector(const nsAString& aSelector,
ErrorResult& aError)

View File

@ -3138,81 +3138,6 @@ nsGenericHTMLElement::SetItemValueText(const nsAString& text)
SetTextContentInternal(text, rv);
}
static void
nsDOMSettableTokenListPropertyDestructor(void *aObject, nsIAtom *aProperty,
void *aPropertyValue, void *aData)
{
nsDOMSettableTokenList* list =
static_cast<nsDOMSettableTokenList*>(aPropertyValue);
NS_RELEASE(list);
}
static nsIAtom** sPropertiesToTraverseAndUnlink[] =
{
&nsGkAtoms::microdataProperties,
&nsGkAtoms::itemtype,
&nsGkAtoms::itemref,
&nsGkAtoms::itemprop,
&nsGkAtoms::sandbox,
&nsGkAtoms::sizes,
nullptr
};
// static
nsIAtom***
nsGenericHTMLElement::PropertiesToTraverseAndUnlink()
{
return sPropertiesToTraverseAndUnlink;
}
nsDOMSettableTokenList*
nsGenericHTMLElement::GetTokenList(nsIAtom* aAtom)
{
#ifdef DEBUG
nsIAtom*** props =
nsGenericHTMLElement::PropertiesToTraverseAndUnlink();
bool found = false;
for (uint32_t i = 0; props[i]; ++i) {
if (*props[i] == aAtom) {
found = true;
break;
}
}
MOZ_ASSERT(found, "Trying to use an unknown tokenlist!");
#endif
nsDOMSettableTokenList* list = nullptr;
if (HasProperties()) {
list = static_cast<nsDOMSettableTokenList*>(GetProperty(aAtom));
}
if (!list) {
list = new nsDOMSettableTokenList(this, aAtom);
NS_ADDREF(list);
SetProperty(aAtom, list, nsDOMSettableTokenListPropertyDestructor);
}
return list;
}
void
nsGenericHTMLElement::GetTokenList(nsIAtom* aAtom, nsIVariant** aResult)
{
nsISupports* itemType = GetTokenList(aAtom);
nsCOMPtr<nsIWritableVariant> out = new nsVariant();
out->SetAsInterface(NS_GET_IID(nsISupports), itemType);
out.forget(aResult);
}
nsresult
nsGenericHTMLElement::SetTokenList(nsIAtom* aAtom, nsIVariant* aValue)
{
nsDOMSettableTokenList* itemType = GetTokenList(aAtom);
nsAutoString string;
aValue->GetAsAString(string);
ErrorResult rv;
itemType->SetValue(string, rv);
return rv.ErrorCode();
}
static void
HTMLPropertiesCollectionDestructor(void *aObject, nsIAtom *aProperty,
void *aPropertyValue, void *aData)

View File

@ -303,9 +303,6 @@ protected:
// when an element has @itemprop but no @itemscope.
virtual void GetItemValueText(nsAString& text);
virtual void SetItemValueText(const nsAString& text);
nsDOMSettableTokenList* GetTokenList(nsIAtom* aAtom);
void GetTokenList(nsIAtom* aAtom, nsIVariant** aResult);
nsresult SetTokenList(nsIAtom* aAtom, nsIVariant* aValue);
public:
virtual already_AddRefed<mozilla::dom::UndoManager> GetUndoManager();
virtual bool UndoScope() MOZ_OVERRIDE;