diff options
Diffstat (limited to 'dom/html')
-rw-r--r-- | dom/html/HTMLAllCollection.cpp | 7 | ||||
-rw-r--r-- | dom/html/HTMLDataListElement.cpp | 6 | ||||
-rw-r--r-- | dom/html/HTMLDataListElement.h | 4 | ||||
-rw-r--r-- | dom/html/HTMLFieldSetElement.cpp | 4 | ||||
-rw-r--r-- | dom/html/HTMLFieldSetElement.h | 4 | ||||
-rw-r--r-- | dom/html/HTMLInputElement.cpp | 10 | ||||
-rw-r--r-- | dom/html/HTMLInputElement.h | 2 | ||||
-rw-r--r-- | dom/html/HTMLLabelElement.cpp | 23 | ||||
-rw-r--r-- | dom/html/HTMLSelectElement.cpp | 4 | ||||
-rw-r--r-- | dom/html/HTMLSelectElement.h | 2 | ||||
-rw-r--r-- | dom/html/HTMLTableRowElement.cpp | 4 | ||||
-rw-r--r-- | dom/html/nsGenericHTMLElement.cpp | 40 | ||||
-rw-r--r-- | dom/html/nsGenericHTMLElement.h | 6 | ||||
-rw-r--r-- | dom/html/nsHTMLDocument.cpp | 36 | ||||
-rw-r--r-- | dom/html/nsHTMLDocument.h | 11 | ||||
-rw-r--r-- | dom/html/test/forms/test_button_attributes_reflection.html | 9 |
16 files changed, 121 insertions, 51 deletions
diff --git a/dom/html/HTMLAllCollection.cpp b/dom/html/HTMLAllCollection.cpp index afa160e0c..6305cce31 100644 --- a/dom/html/HTMLAllCollection.cpp +++ b/dom/html/HTMLAllCollection.cpp @@ -8,6 +8,7 @@ #include "mozilla/dom/HTMLAllCollectionBinding.h" #include "mozilla/dom/Nullable.h" +#include "mozilla/dom/Element.h" #include "nsHTMLDocument.h" namespace mozilla { @@ -86,14 +87,14 @@ IsAllNamedElement(nsIContent* aContent) } static bool -DocAllResultMatch(nsIContent* aContent, int32_t aNamespaceID, nsIAtom* aAtom, +DocAllResultMatch(Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData) { - if (aContent->GetID() == aAtom) { + if (aElement->GetID() == aAtom) { return true; } - nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent); + nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aElement); if (!elm) { return false; } diff --git a/dom/html/HTMLDataListElement.cpp b/dom/html/HTMLDataListElement.cpp index d9ad4da09..5aa772645 100644 --- a/dom/html/HTMLDataListElement.cpp +++ b/dom/html/HTMLDataListElement.cpp @@ -35,11 +35,11 @@ NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement) NS_IMPL_ELEMENT_CLONE(HTMLDataListElement) bool -HTMLDataListElement::MatchOptions(nsIContent* aContent, int32_t aNamespaceID, +HTMLDataListElement::MatchOptions(Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData) { - return aContent->NodeInfo()->Equals(nsGkAtoms::option, kNameSpaceID_XHTML) && - !aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled); + return aElement->NodeInfo()->Equals(nsGkAtoms::option, kNameSpaceID_XHTML) && + !aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled); } } // namespace dom diff --git a/dom/html/HTMLDataListElement.h b/dom/html/HTMLDataListElement.h index e0aff818b..ba2a2e0b4 100644 --- a/dom/html/HTMLDataListElement.h +++ b/dom/html/HTMLDataListElement.h @@ -37,8 +37,8 @@ public: virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override; // This function is used to generate the nsContentList (option elements). - static bool MatchOptions(nsIContent* aContent, int32_t aNamespaceID, - nsIAtom* aAtom, void* aData); + static bool MatchOptions(Element* aElement, int32_t aNamespaceID, + nsIAtom* aAtom, void* aData); NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLDataListElement, nsGenericHTMLElement) diff --git a/dom/html/HTMLFieldSetElement.cpp b/dom/html/HTMLFieldSetElement.cpp index 865d3c9cf..d72fd1061 100644 --- a/dom/html/HTMLFieldSetElement.cpp +++ b/dom/html/HTMLFieldSetElement.cpp @@ -120,10 +120,10 @@ HTMLFieldSetElement::GetType(nsAString& aType) /* static */ bool -HTMLFieldSetElement::MatchListedElements(nsIContent* aContent, int32_t aNamespaceID, +HTMLFieldSetElement::MatchListedElements(Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData) { - nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aContent); + nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aElement); return formControl; } diff --git a/dom/html/HTMLFieldSetElement.h b/dom/html/HTMLFieldSetElement.h index d169434ae..96fff4582 100644 --- a/dom/html/HTMLFieldSetElement.h +++ b/dom/html/HTMLFieldSetElement.h @@ -124,8 +124,8 @@ private: void NotifyElementsForFirstLegendChange(bool aNotify); // This function is used to generate the nsContentList (listed form elements). - static bool MatchListedElements(nsIContent* aContent, int32_t aNamespaceID, - nsIAtom* aAtom, void* aData); + static bool MatchListedElements(Element* aElement, int32_t aNamespaceID, + nsIAtom* aAtom, void* aData); // listed form controls elements. RefPtr<nsContentList> mElements; diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 78f74ae0c..d46eccdbc 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -8800,6 +8800,16 @@ HTMLInputElement::GetWebkitEntries(nsTArray<RefPtr<FileSystemEntry>>& aSequence) aSequence.AppendElements(mEntries); } +already_AddRefed<nsINodeList> +HTMLInputElement::GetLabels() +{ + if (!IsLabelable()) { + return nullptr; + } + + return nsGenericHTMLElement::Labels(); +} + } // namespace dom } // namespace mozilla diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index e5d670e08..9ca876aee 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -704,6 +704,8 @@ public: // XPCOM GetCustomVisibility() is OK + already_AddRefed<nsINodeList> GetLabels(); + // XPCOM Select() is OK Nullable<int32_t> GetSelectionStart(ErrorResult& aRv); 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); } diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp index 24ddabb65..53f42317a 100644 --- a/dom/html/HTMLSelectElement.cpp +++ b/dom/html/HTMLSelectElement.cpp @@ -735,12 +735,12 @@ HTMLSelectElement::SetLength(uint32_t aLength, ErrorResult& aRv) /* static */ bool -HTMLSelectElement::MatchSelectedOptions(nsIContent* aContent, +HTMLSelectElement::MatchSelectedOptions(Element* aElement, int32_t /* unused */, nsIAtom* /* unused */, void* /* unused*/) { - HTMLOptionElement* option = HTMLOptionElement::FromContent(aContent); + HTMLOptionElement* option = HTMLOptionElement::FromContent(aElement); return option && option->Selected(); } diff --git a/dom/html/HTMLSelectElement.h b/dom/html/HTMLSelectElement.h index d7e4350b4..8a25385de 100644 --- a/dom/html/HTMLSelectElement.h +++ b/dom/html/HTMLSelectElement.h @@ -247,7 +247,7 @@ public: mOptions->IndexedSetter(aIndex, aOption, aRv); } - static bool MatchSelectedOptions(nsIContent* aContent, int32_t, nsIAtom*, + static bool MatchSelectedOptions(Element* aElement, int32_t, nsIAtom*, void*); nsIHTMLCollection* SelectedOptions(); diff --git a/dom/html/HTMLTableRowElement.cpp b/dom/html/HTMLTableRowElement.cpp index 2dec9c883..ac2463400 100644 --- a/dom/html/HTMLTableRowElement.cpp +++ b/dom/html/HTMLTableRowElement.cpp @@ -120,10 +120,10 @@ HTMLTableRowElement::SectionRowIndex() const } static bool -IsCell(nsIContent *aContent, int32_t aNamespaceID, +IsCell(Element *aElement, int32_t aNamespaceID, nsIAtom* aAtom, void *aData) { - return aContent->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th); + return aElement->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th); } nsIHTMLCollection* diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index d75001a83..2f890325a 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -108,6 +108,7 @@ #include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandleInlines.h" #include "ReferrerPolicy.h" +#include "mozilla/dom/HTMLLabelElement.h" using namespace mozilla; using namespace mozilla::dom; @@ -493,6 +494,14 @@ nsGenericHTMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, } } + // We need to consider a labels element is moved to another subtree + // with different root, it needs to update labels list and its root + // as well. + nsDOMSlots* slots = GetExistingDOMSlots(); + if (slots && slots->mLabelsList) { + slots->mLabelsList->MaybeResetRoot(SubtreeRoot()); + } + return rv; } @@ -513,6 +522,13 @@ nsGenericHTMLElement::UnbindFromTree(bool aDeep, bool aNullParent) } } + // We need to consider a labels element is removed from tree, + // it needs to update labels list and its root as well. + nsDOMSlots* slots = GetExistingDOMSlots(); + if (slots && slots->mLabelsList) { + slots->mLabelsList->MaybeResetRoot(SubtreeRoot()); + } + nsStyledElement::UnbindFromTree(aDeep, aNullParent); } @@ -1701,6 +1717,30 @@ nsGenericHTMLElement::IsLabelable() const return IsAnyOfHTMLElements(nsGkAtoms::progress, nsGkAtoms::meter); } +/* static */ bool +nsGenericHTMLElement::MatchLabelsElement(Element* aElement, int32_t aNamespaceID, + nsIAtom* aAtom, void* aData) +{ + HTMLLabelElement* element = HTMLLabelElement::FromContent(aElement); + return element && element->GetControl() == aData; +} + +already_AddRefed<nsINodeList> +nsGenericHTMLElement::Labels() +{ + MOZ_ASSERT(IsLabelable(), + "Labels() only allow labelable elements to use it."); + nsDOMSlots* slots = DOMSlots(); + + if (!slots->mLabelsList) { + slots->mLabelsList = new nsLabelsNodeList(SubtreeRoot(), MatchLabelsElement, + nullptr, this); + } + + RefPtr<nsLabelsNodeList> labels = slots->mLabelsList; + return labels.forget(); +} + bool nsGenericHTMLElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const { diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 3cca41c3d..0635c27e1 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -834,6 +834,12 @@ public: } virtual bool IsLabelable() const override; + + static bool MatchLabelsElement(Element* aElement, int32_t aNamespaceID, + nsIAtom* aAtom, void* aData); + + already_AddRefed<nsINodeList> Labels(); + virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override; static bool TouchEventsEnabled(JSContext* /* unused */, JSObject* /* unused */); diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 7d66aab04..fea78dc37 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -1100,31 +1100,31 @@ nsHTMLDocument::Applets() } bool -nsHTMLDocument::MatchLinks(nsIContent *aContent, int32_t aNamespaceID, +nsHTMLDocument::MatchLinks(Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData) { - nsIDocument* doc = aContent->GetUncomposedDoc(); + nsIDocument* doc = aElement->GetUncomposedDoc(); if (doc) { - NS_ASSERTION(aContent->IsInUncomposedDoc(), + NS_ASSERTION(aElement->IsInUncomposedDoc(), "This method should never be called on content nodes that " "are not in a document!"); #ifdef DEBUG { nsCOMPtr<nsIHTMLDocument> htmldoc = - do_QueryInterface(aContent->GetUncomposedDoc()); + do_QueryInterface(aElement->GetUncomposedDoc()); NS_ASSERTION(htmldoc, "Huh, how did this happen? This should only be used with " "HTML documents!"); } #endif - mozilla::dom::NodeInfo *ni = aContent->NodeInfo(); + mozilla::dom::NodeInfo *ni = aElement->NodeInfo(); nsIAtom *localName = ni->NameAtom(); if (ni->NamespaceID() == kNameSpaceID_XHTML && (localName == nsGkAtoms::a || localName == nsGkAtoms::area)) { - return aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::href); + return aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::href); } } @@ -1148,24 +1148,24 @@ nsHTMLDocument::Links() } bool -nsHTMLDocument::MatchAnchors(nsIContent *aContent, int32_t aNamespaceID, +nsHTMLDocument::MatchAnchors(Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData) { - NS_ASSERTION(aContent->IsInUncomposedDoc(), + NS_ASSERTION(aElement->IsInUncomposedDoc(), "This method should never be called on content nodes that " "are not in a document!"); #ifdef DEBUG { nsCOMPtr<nsIHTMLDocument> htmldoc = - do_QueryInterface(aContent->GetUncomposedDoc()); + do_QueryInterface(aElement->GetUncomposedDoc()); NS_ASSERTION(htmldoc, "Huh, how did this happen? This should only be used with " "HTML documents!"); } #endif - if (aContent->NodeInfo()->Equals(nsGkAtoms::a, kNameSpaceID_XHTML)) { - return aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::name); + if (aElement->IsHTMLElement(nsGkAtoms::a)) { + return aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::name); } return false; @@ -1952,14 +1952,14 @@ nsHTMLDocument::Writeln(JSContext* cx, const Sequence<nsString>& aText, } bool -nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, int32_t aNamespaceID, +nsHTMLDocument::MatchNameAttribute(Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData) { - NS_PRECONDITION(aContent, "Must have content node to work with!"); + NS_PRECONDITION(aElement, "Must have element to work with!"); nsString* elementName = static_cast<nsString*>(aData); return - aContent->GetNameSpaceID() == kNameSpaceID_XHTML && - aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, + aElement->GetNameSpaceID() == kNameSpaceID_XHTML && + aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, *elementName, eCaseMatters); } @@ -2279,10 +2279,10 @@ nsHTMLDocument::GetForms() return mForms; } -static bool MatchFormControls(nsIContent* aContent, int32_t aNamespaceID, - nsIAtom* aAtom, void* aData) +static bool MatchFormControls(Element* aElement, int32_t aNamespaceID, + nsIAtom* aAtom, void* aData) { - return aContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL); + return aElement->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL); } nsContentList* diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index 2dbbf2b57..426ebddc5 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -261,12 +261,13 @@ protected: nsIContent *MatchId(nsIContent *aContent, const nsAString& aId); - static bool MatchLinks(nsIContent *aContent, int32_t aNamespaceID, + static bool MatchLinks(mozilla::dom::Element* aElement, int32_t aNamespaceID, + nsIAtom* aAtom, void* aData); + static bool MatchAnchors(mozilla::dom::Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom, void* aData); - static bool MatchAnchors(nsIContent *aContent, int32_t aNamespaceID, - nsIAtom* aAtom, void* aData); - static bool MatchNameAttribute(nsIContent* aContent, int32_t aNamespaceID, - nsIAtom* aAtom, void* aData); + static bool MatchNameAttribute(mozilla::dom::Element* aElement, + int32_t aNamespaceID, + nsIAtom* aAtom, void* aData); static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName); static void DocumentWriteTerminationFunc(nsISupports *aRef); diff --git a/dom/html/test/forms/test_button_attributes_reflection.html b/dom/html/test/forms/test_button_attributes_reflection.html index 26858e939..4e702b3ac 100644 --- a/dom/html/test/forms/test_button_attributes_reflection.html +++ b/dom/html/test/forms/test_button_attributes_reflection.html @@ -128,9 +128,12 @@ is(typeof(document.createElement("button").setCustomValidity), "function", "button.setCustomValidity should be a function"); // .labels -todo("labels" in document.createElement("button"), - "button.labels isn't implemented yet"); - +ok("labels" in document.createElement("button"), + "button.labels should be an IDL attribute of the button element"); +is(typeof(document.createElement("button").labels), "object", + "button.labels should be an object"); +ok(document.createElement("button").labels instanceof NodeList, + "button.labels sohuld be an instance of NodeList"); </script> </pre> </body> |