Skip to content

Commit

Permalink
Bug 741295 - Treat 'id' and 'class' as global attributes for all elem…
Browse files Browse the repository at this point in the history
…ents; r=bz
  • Loading branch information
Ms2ger committed May 30, 2014
1 parent a5e4e83 commit a39cee4
Show file tree
Hide file tree
Showing 50 changed files with 168 additions and 500 deletions.
2 changes: 1 addition & 1 deletion accessible/src/base/AccIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ RelatedAccIterator::
{
mBindingParent = aDependentContent->GetBindingParent();
nsIAtom* IDAttr = mBindingParent ?
nsGkAtoms::anonid : aDependentContent->GetIDAttributeName();
nsGkAtoms::anonid : nsGkAtoms::id;

nsAutoString id;
if (aDependentContent->GetAttr(kNameSpaceID_None, IDAttr, id))
Expand Down
3 changes: 1 addition & 2 deletions accessible/src/base/nsCoreUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,7 @@ nsCoreUtils::IsErrorPage(nsIDocument *aDocument)
bool
nsCoreUtils::GetID(nsIContent *aContent, nsAString& aID)
{
nsIAtom *idAttribute = aContent->GetIDAttributeName();
return idAttribute ? aContent->GetAttr(kNameSpaceID_None, idAttribute, aID) : false;
return aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, aID);
}

bool
Expand Down
2 changes: 1 addition & 1 deletion accessible/src/generic/Accessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ Accessible::ApplyARIAState(uint64_t* aState) const
if (mRoleMapEntry->role != roles::NOTHING)
*aState &= ~states::READONLY;

if (mContent->HasAttr(kNameSpaceID_None, mContent->GetIDAttributeName())) {
if (mContent->HasID()) {
// If has a role & ID and aria-activedescendant on the container, assume focusable
nsIContent *ancestorContent = mContent;
while ((ancestorContent = ancestorContent->GetParent()) != nullptr) {
Expand Down
46 changes: 34 additions & 12 deletions content/base/public/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,6 @@ class Element : public FragmentOrElement
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
int32_t aModType) const;

/**
* Returns an atom holding the name of the "class" attribute on this
* content node (if applicable). Returns null if there is no
* "class" attribute for this type of content node.
*/
virtual nsIAtom *GetClassAttributeName() const;

inline Directionality GetDirectionality() const {
if (HasFlag(NODE_HAS_DIRECTION_RTL)) {
return eDir_RTL;
Expand Down Expand Up @@ -587,8 +580,20 @@ class Element : public FragmentOrElement
{
SetAttr(kNameSpaceID_None, nsGkAtoms::id, aId, true);
}
void GetClassName(nsAString& aClassName)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aClassName);
}
void GetClassName(DOMString& aClassName)
{
GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aClassName);
}
void SetClassName(const nsAString& aClassName)
{
SetAttr(kNameSpaceID_None, nsGkAtoms::_class, aClassName, true);
}

nsDOMTokenList* GetClassList();
nsDOMTokenList* ClassList();
nsDOMAttributeMap* Attributes()
{
nsDOMSlots* slots = DOMSlots();
Expand Down Expand Up @@ -862,8 +867,6 @@ class Element : public FragmentOrElement
const nsAttrValue* mValue;
};

// Be careful when using this method. This does *NOT* handle
// XUL prototypes. You may want to use GetAttrInfo.
const nsAttrValue* GetParsedAttr(nsIAtom* aAttr) const
{
return mAttrsAndChildren.GetAttr(aAttr);
Expand Down Expand Up @@ -1128,8 +1131,7 @@ class Element : public FragmentOrElement
* Add/remove this element to the documents id cache
*/
void AddToIdTable(nsIAtom* aId);
void RemoveFromIdTable(); // checks HasID() and uses DoGetID()
void RemoveFromIdTable(nsIAtom* aId);
void RemoveFromIdTable();

/**
* Functions to carry out event default actions for links of all types
Expand Down Expand Up @@ -1364,6 +1366,26 @@ NS_IMETHOD GetTagName(nsAString& aTagName) MOZ_FINAL \
Element::GetTagName(aTagName); \
return NS_OK; \
} \
NS_IMETHOD GetId(nsAString& aId) MOZ_FINAL \
{ \
Element::GetId(aId); \
return NS_OK; \
} \
NS_IMETHOD SetId(const nsAString& aId) MOZ_FINAL \
{ \
Element::SetId(aId); \
return NS_OK; \
} \
NS_IMETHOD GetClassName(nsAString& aClassName) MOZ_FINAL \
{ \
Element::GetClassName(aClassName); \
return NS_OK; \
} \
NS_IMETHOD SetClassName(const nsAString& aClassName) MOZ_FINAL \
{ \
Element::SetClassName(aClassName); \
return NS_OK; \
} \
NS_IMETHOD GetClassList(nsISupports** aClassList) MOZ_FINAL \
{ \
Element::GetClassList(aClassList); \
Expand Down
1 change: 0 additions & 1 deletion content/base/public/FragmentOrElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ class FragmentOrElement : public nsIContent
virtual void DestroyContent() MOZ_OVERRIDE;
virtual void SaveSubtreeState() MOZ_OVERRIDE;

virtual const nsAttrValue* DoGetClasses() const MOZ_OVERRIDE;
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) MOZ_OVERRIDE;

nsIHTMLCollection* Children();
Expand Down
17 changes: 4 additions & 13 deletions content/base/public/nsIContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,6 @@ class nsIContent : public nsINode {
GetBindingParent();
}

/**
* Returns an atom holding the name of the attribute of type ID on
* this content node (if applicable). Returns null for non-element
* content nodes.
*/
virtual nsIAtom *GetIDAttributeName() const = 0;

/**
* Set attribute values. All attribute values are assumed to have a
* canonical string representation that can be used for these
Expand Down Expand Up @@ -831,8 +824,7 @@ class nsIContent : public nsINode {

/**
* Get the ID of this content node (the atom corresponding to the
* value of the null-namespace attribute whose name is given by
* GetIDAttributeName(). This may be null if there is no ID.
* value of the id attribute). This may be null if there is no ID.
*/
nsIAtom* GetID() const {
if (HasID()) {
Expand All @@ -843,8 +835,7 @@ class nsIContent : public nsINode {

/**
* Get the class list of this content node (this corresponds to the
* value of the null-namespace attribute whose name is given by
* GetClassAttributeName()). This may be null if there are no
* value of the class attribute). This may be null if there are no
* classes, but that's not guaranteed.
*/
const nsAttrValue* GetClasses() const {
Expand Down Expand Up @@ -957,14 +948,14 @@ class nsIContent : public nsINode {
* Hook for implementing GetID. This is guaranteed to only be
* called if HasID() is true.
*/
virtual nsIAtom* DoGetID() const = 0;
nsIAtom* DoGetID() const;

private:
/**
* Hook for implementing GetClasses. This is guaranteed to only be
* called if the NODE_MAY_HAVE_CLASS flag is set.
*/
virtual const nsAttrValue* DoGetClasses() const = 0;
const nsAttrValue* DoGetClasses() const;

public:
#ifdef DEBUG
Expand Down
17 changes: 0 additions & 17 deletions content/base/public/nsINodeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,6 @@ class nsINodeInfo : public nsISupports
return mInner.mExtraName;
}

/*
* Get and set the ID attribute atom for this node.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
nsIAtom* GetIDAttributeAtom() const
{
return mIDAttributeAtom;
}

void SetIDAttributeAtom(nsIAtom* aID)
{
mIDAttributeAtom = aID;
}

/**
* Get the owning node info manager. Only to be used inside Gecko, you can't
* really do anything with the pointer outside Gecko anyway.
Expand Down Expand Up @@ -330,7 +314,6 @@ class nsINodeInfo : public nsISupports

nsNodeInfoInner mInner;

nsCOMPtr<nsIAtom> mIDAttributeAtom;
nsRefPtr<nsNodeInfoManager> mOwnerManager;

/*
Expand Down
14 changes: 1 addition & 13 deletions content/base/src/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,7 @@ Attr::SetTextContentInternal(const nsAString& aTextContent,
NS_IMETHODIMP
Attr::GetIsId(bool* aReturn)
{
Element* element = GetElement();
if (!element) {
*aReturn = false;
return NS_OK;
}

nsIAtom* idAtom = element->GetIDAttributeName();
if (!idAtom) {
*aReturn = false;
return NS_OK;
}

*aReturn = mNodeInfo->Equals(idAtom, kNameSpaceID_None);
*aReturn = mNodeInfo->Equals(nsGkAtoms::id, kNameSpaceID_None);
return NS_OK;
}

Expand Down
12 changes: 0 additions & 12 deletions content/base/src/DocumentFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ DocumentFragment::IsNodeOfType(uint32_t aFlags) const
return !(aFlags & ~(eCONTENT | eDOCUMENT_FRAGMENT));
}

nsIAtom*
DocumentFragment::DoGetID() const
{
return nullptr;
}

nsIAtom*
DocumentFragment::GetIDAttributeName() const
{
return nullptr;
}

NS_IMETHODIMP
DocumentFragment::QuerySelector(const nsAString& aSelector,
nsIDOMElement **aReturn)
Expand Down
3 changes: 0 additions & 3 deletions content/base/src/DocumentFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ class DocumentFragment : public FragmentOrElement,

virtual nsIDOMNode* AsDOMNode() MOZ_OVERRIDE { return this; }

virtual nsIAtom* DoGetID() const MOZ_OVERRIDE;
virtual nsIAtom *GetIDAttributeName() const MOZ_OVERRIDE;

virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers) MOZ_OVERRIDE
Expand Down
Loading

0 comments on commit a39cee4

Please sign in to comment.