mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 1566324 part 1: Make a static version of IDRefsIterator::GetElem which can be called to get an id reference for any element. r=eeejay
IDRefsIterator::GetElem was previously an instance method which could only be used if you instantiated IDRefsIterator. This is overkill for attributes which can only take a single id reference (rather than an id reference list). Now, there is a static version of IDRefsIterator::GetElem which can be called with an arbitrary source element. Any accessibility code should henceforth be using this instead of calling GetElementById directly, as this deals with shadow DOM, etc. Differential Revision: https://phabricator.services.mozilla.com/D38832 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
194ec7662a
commit
0eb35f6d14
@ -255,15 +255,18 @@ nsIContent* IDRefsIterator::NextElem() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsIContent* IDRefsIterator::GetElem(const nsDependentSubstring& aID) {
|
||||
dom::Element* IDRefsIterator::GetElem(nsIContent* aContent,
|
||||
const nsAString& aID) {
|
||||
// Get elements in DOM tree by ID attribute if this is an explicit content.
|
||||
// In case of bound element check its anonymous subtree.
|
||||
if (!mContent->IsInAnonymousSubtree()) {
|
||||
if (!aContent->IsInAnonymousSubtree()) {
|
||||
dom::DocumentOrShadowRoot* docOrShadowRoot =
|
||||
mContent->GetUncomposedDocOrConnectedShadowRoot();
|
||||
aContent->GetUncomposedDocOrConnectedShadowRoot();
|
||||
if (docOrShadowRoot) {
|
||||
dom::Element* refElm = docOrShadowRoot->GetElementById(aID);
|
||||
if (refElm || !mContent->GetXBLBinding()) return refElm;
|
||||
if (refElm || !aContent->GetXBLBinding()) {
|
||||
return refElm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,9 +274,9 @@ nsIContent* IDRefsIterator::GetElem(const nsDependentSubstring& aID) {
|
||||
// then use "anonid" attribute to get elements in anonymous subtree.
|
||||
|
||||
// Check inside the binding the element is contained in.
|
||||
nsIContent* bindingParent = mContent->GetBindingParent();
|
||||
nsIContent* bindingParent = aContent->GetBindingParent();
|
||||
if (bindingParent) {
|
||||
nsIContent* refElm =
|
||||
dom::Element* refElm =
|
||||
bindingParent->OwnerDoc()->GetAnonymousElementByAttribute(
|
||||
bindingParent, nsGkAtoms::anonid, aID);
|
||||
|
||||
@ -281,14 +284,18 @@ nsIContent* IDRefsIterator::GetElem(const nsDependentSubstring& aID) {
|
||||
}
|
||||
|
||||
// Check inside the binding of the element.
|
||||
if (mContent->GetXBLBinding()) {
|
||||
return mContent->OwnerDoc()->GetAnonymousElementByAttribute(
|
||||
mContent, nsGkAtoms::anonid, aID);
|
||||
if (aContent->GetXBLBinding()) {
|
||||
return aContent->OwnerDoc()->GetAnonymousElementByAttribute(
|
||||
aContent, nsGkAtoms::anonid, aID);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dom::Element* IDRefsIterator::GetElem(const nsDependentSubstring& aID) {
|
||||
return GetElem(mContent, aID);
|
||||
}
|
||||
|
||||
Accessible* IDRefsIterator::Next() {
|
||||
nsIContent* nextEl = nullptr;
|
||||
while ((nextEl = NextElem())) {
|
||||
|
@ -219,7 +219,8 @@ class IDRefsIterator : public AccIterable {
|
||||
/**
|
||||
* Return the element with the given ID.
|
||||
*/
|
||||
nsIContent* GetElem(const nsDependentSubstring& aID);
|
||||
static dom::Element* GetElem(nsIContent* aContent, const nsAString& aID);
|
||||
dom::Element* GetElem(const nsDependentSubstring& aID);
|
||||
|
||||
// AccIterable
|
||||
virtual Accessible* Next() override;
|
||||
|
Loading…
Reference in New Issue
Block a user