summaryrefslogtreecommitdiffstats
path: root/dom/html/HTMLLabelElement.cpp
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2017-08-18 06:04:15 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-03-12 09:59:19 +0100
commit6be9e507077bfdd2b8c82c203cf70f010ecce086 (patch)
tree5f0a9188256213506d1f2477d9ee1040b133c762 /dom/html/HTMLLabelElement.cpp
parent93f8e06bb8d8656e868679d584c7c8771ff8e42f (diff)
downloadUXP-6be9e507077bfdd2b8c82c203cf70f010ecce086.tar
UXP-6be9e507077bfdd2b8c82c203cf70f010ecce086.tar.gz
UXP-6be9e507077bfdd2b8c82c203cf70f010ecce086.tar.lz
UXP-6be9e507077bfdd2b8c82c203cf70f010ecce086.tar.xz
UXP-6be9e507077bfdd2b8c82c203cf70f010ecce086.zip
HTML - implement the labels attribute
Diffstat (limited to 'dom/html/HTMLLabelElement.cpp')
-rw-r--r--dom/html/HTMLLabelElement.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/dom/html/HTMLLabelElement.cpp b/dom/html/HTMLLabelElement.cpp
index c1d22b0a6..d1c037336 100644
--- a/dom/html/HTMLLabelElement.cpp
+++ b/dom/html/HTMLLabelElement.cpp
@@ -14,6 +14,7 @@
#include "nsFocusManager.h"
#include "nsIDOMMouseEvent.h"
#include "nsQueryObject.h"
+#include "mozilla/dom/ShadowRoot.h"
// construction, destruction
@@ -268,17 +269,23 @@ HTMLLabelElement::GetLabeledElement() const
return GetFirstLabelableDescendant();
}
- // We have a @for. The id has to be linked to an element in the same document
+ // We have a @for. The id has to be linked to an element in the same tree
// and this element should be a labelable form control.
- //XXXsmaug It is unclear how this should work in case the element is in
- // Shadow DOM.
- // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=26365.
- nsIDocument* doc = GetUncomposedDoc();
- if (!doc) {
- return nullptr;
+ nsINode* root = SubtreeRoot();
+ ShadowRoot* shadow = ShadowRoot::FromNode(root);
+ Element* element = nullptr;
+
+ if (shadow) {
+ element = shadow->GetElementById(elementId);
+ } else {
+ nsIDocument* doc = GetUncomposedDoc();
+ if (doc) {
+ element = doc->GetElementById(elementId);
+ } else {
+ element = nsContentUtils::MatchElementId(root->AsContent(), elementId);
+ }
}
- Element* element = doc->GetElementById(elementId);
if (element && element->IsLabelable()) {
return static_cast<nsGenericHTMLElement*>(element);
}