Commit Graph
305 Commits
Author SHA1 Message Date
Keith Cirkel 03f4244d59 Bug 2018902 - Part 2: Add CustomElementRegistry option to ShadowRoot init r=dom-core-reviewers,webidl,smaug,edgar
Differential Revision: https://phabricator.services.mozilla.com/D287096
2026-06-11 07:12:47 +00:00
Masayuki Nakano 821c05533a Bug 2045219 - Improve the debug print of nsINode r=smaug,dom-core-reviewers
Currently, `operator<<(std::ostram&, const nsINode&)` prints the path
of the node with some attribute information of each node. However, there
are some issues:

1. It's unclear if the reached root is a `DocumentFragment` or
`ShadowRoot` due to the same node name, `#document-fragment`.
2. Do not print the host's path.
3. Cannot print only in a specific node such as a `contenteditable`.
4. It's hard to consider which `Text` if a node has multiple `Text`
nodes.
5. No information about the assigned `<slot>`.
6. No information about `EditContext`.

This patch appends these information to each node. Additionally, adding
`format_as()` for avoiding to use `mozilla::ToString` for `fmt::format`
and `MOZ_LOG_FMT`.

Finally, to test the new data, this makes `Selection` and `SelectionAPI`
log use `MOZ_LOG_FMT`.

Differential Revision: https://phabricator.services.mozilla.com/D304964
2026-06-08 01:00:49 +00:00
Daniel Holbert b9c26953f1 Bug 2044510: Pass already_AddRefed types by-value instead of by rvalue reference, in dom/base/. r=dom-core-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D304358
2026-06-05 21:06:35 +00:00
Emilio Cobos Álvarez bb1efcc2e5 Bug 2044618 - Remove some include dependencies. r=firefox-style-system-reviewers,layout-reviewers,dshin
Stop including StyleSheet.h from most headers.

Differential Revision: https://phabricator.services.mozilla.com/D304408
2026-06-05 01:15:06 +00:00
Serban Stanca 94f4c69168 Revert "Bug 2018902 - Part 2: Add CustomElementRegistry option to ShadowRoot init r=dom-core,webidl,smaug,edgar" for causing build bustages in nsGenericHTMLElement.h.
This reverts commit 5d94012a7d.
2026-05-21 11:00:30 +00:00
Keith Cirkel 5d94012a7d Bug 2018902 - Part 2: Add CustomElementRegistry option to ShadowRoot init r=dom-core,webidl,smaug,edgar
Differential Revision: https://phabricator.services.mozilla.com/D287096
2026-05-21 10:24:12 +00:00
Emilio Cobos Álvarez e4ecfea530 Bug 2038976 - Make CSSOM work on raw declaration blocks, rather than DeclarationBlock. r=firefox-style-system-reviewers,layout-reviewers,dshin
This will make being more granular with cloning easier, and we don't
need it after the previous patch.

This leaves DeclarationBlock only for the style attribute for now, we
need it for the AttrStyles stuff. But I plan to move that to
MiscContainer instead or so.

Differential Revision: https://phabricator.services.mozilla.com/D300052
2026-05-13 22:29:25 +00:00
Edgar Chen 12e1a55722 Bug 2038439 - Clean up stylesheets when destroying Document/ShadowRoot; r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D299725
2026-05-12 22:58:26 +00:00
Keith Cirkel f502ae4b7a Bug 2012698 - Part 1 - Refactor Element, abstracting Details Shadow tree branches to virtual methods r=dom-core,jjaschke,emilio
Currently Element has the SHADOW_ROOT_IS_DETAILS_SHADOW_TREE flag, which
determines if the element is a Details element and allows branching for specific
shadow root operations, such as getting the slot names, and handlers for slot
changed and unslotted.

This change refactors this to be more generic: switching this branching for
virtual methods instead, while dropping the flag. It also then co-locates the
Details specific shadow root operations into HTMLDetailsElement.cpp.

This will allow us to introduce more element specific Shadow Root behaviours,
such as those for the `<select>` element.

Differential Revision: https://phabricator.services.mozilla.com/D295337
2026-04-29 20:20:27 +00:00
Emilio Cobos Álvarez dbb9581748 Bug 2026109 - Improve cloning internal shadow trees for printing. r=smaug
Clone built-in stylesheets that aren't node associated: this fixes
select.css not applying which is what fixes the bug as reported.

Clone pseudo-element type (this fixes the dropmarker not showing up in
appearance: auto mode.

Differential Revision: https://phabricator.services.mozilla.com/D289935
2026-03-26 08:53:41 +00:00
Alexandru Marc ae9a1488ed Revert "Bug 2026109 - Improve cloning internal shadow trees for printing. r=smaug" for causing wpt failures @ select-combobox-print.html
This reverts commit 5a7f14c9c4.
2026-03-26 05:16:14 +00:00
Emilio Cobos Álvarez 5a7f14c9c4 Bug 2026109 - Improve cloning internal shadow trees for printing. r=smaug
Clone built-in stylesheets that aren't node associated: this fixes
select.css not applying which is what fixes the bug as reported.

Clone pseudo-element type (this fixes the dropmarker not showing up in
appearance: auto mode.

Differential Revision: https://phabricator.services.mozilla.com/D289935
2026-03-26 01:36:19 +00:00
Emilio Cobos Álvarez 5a68a62e93 Bug 2024654 - Simplify ShadowRoot::InvalidateStyleAndLayoutOnSubtree. r=dom-core,smaug
Differential Revision: https://phabricator.services.mozilla.com/D288958
2026-03-24 13:32:10 +00:00
Emilio Cobos Álvarez 11be491237 Bug 2024942 - Reduce more includes of ServoStyleConsts. r=sergesanspaille
Use nsTArray + span for SendAsyncMessage since it allows for incomplete
types (std::vector on libc++ doesn't).

Differential Revision: https://phabricator.services.mozilla.com/D288906
2026-03-21 07:07:21 +00:00
Sylvestre Ledru 9eb1a31a98 Bug 2023419 - Remove Emacs/Vim modelines from dom/ r=emilio,media-playback-reviewers,webidl,padenot
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287843
2026-03-16 21:02:32 +00:00
Norisz Fay a86d829321 Revert "Bug 2012637 - part 9: Add a Firefox Source Docs documentation page for TreeKind and notable issues r=smaug,dom-core" as requested by dev
This reverts commit 88008cd8ca.

Revert "Bug 2012637 - part 8: Make `nsContentUtils::ComparePoints` handle `TreeKind::Flat` and `TreeKind::FlatForSelection` correctly r=smaug,dom-core"

This reverts commit 73e6f6587b.

Revert "Bug 2012637 - part 7: Make `RangeUtils::CompareNodeToRangeBoundaries()` use `nsContentUtils::ComparePoints` with valid point in the tree r=smaug"

This reverts commit 6985d5e80f.

Revert "Bug 2012637 - part 6: Make `nsRange::CutContents()` convert the range boundaries to the ones in the DOM before comparing r=smaug"

This reverts commit 73b585af3d.

Revert "Bug 2012637 - part 5: Delete the default template parameter of `nsContentUtils::ComparePoints` and relatives r=smaug,dom-core"

This reverts commit 1a7f24e5b5.

Revert "Bug 2012637 - part 4: Make `nsContentUtils` use `nsIContent` for taking a child node as a parameter r=smaug"

This reverts commit a6ea8d6824.

Revert "Bug 2012637 - part 3: Add template `nsINode` API which can switch to call API from `TreeKind` r=smaug,dom-core,webidl"

This reverts commit a4211e9df0.

Revert "Bug 2012637 - part 2: Add `TreeKind::FlatForSelection` and change the template parameter of `ChildIteratorBase` to `TreeKind` r=smaug,dom-core"

This reverts commit 0241749ee7.

Revert "Bug 2012637 - part 1: Make `ChildIterBase` template class to re-implement `FlattenedChildIterator` for DOM, Flat and FlatForSelection TreeKind r=smaug,dom-core,layout-reviewers,emilio"

This reverts commit 9e71cb77fb.
2026-03-13 02:52:45 +00:00
Masayuki Nakano 9e71cb77fb Bug 2012637 - part 1: Make ChildIterBase template class to re-implement FlattenedChildIterator for DOM, Flat and FlatForSelection TreeKind r=smaug,dom-core,layout-reviewers,emilio
`FlattenedChildIterator` is a non-template class and work only for the
flattened tree (i.e., in the `TreeKind::Flat` mode).

To centralize the implementation to access children from a parent node
in the various kinds of tree except `ShadowIncludingDOM`, this patch
makes it a template class and support the simple DOM (for
`TreeKind::DOM`), the flattened tree (for`TreeKind::Flat`) and also the
flattened tree for selection whose `TreeKind` will be added by the next
patch.

The reason why this patch does not support
`TreeKind::ShadowIncludingDOM` is, it is not clear that which children
should be handled when the parent is a shadow host, i.e., whether the
children of the host or the `ShadowRoot`. Therefore, the caller should
use `ShadowRoot` if the users want to list up the the children from a
host. Then, the code is really clear about what it does.

Differential Revision: https://phabricator.services.mozilla.com/D281303
2026-03-12 03:01:45 +00:00
Keith Cirkel cddd51de64 Bug 2018900 - Implement customElementRegistry on Element DocumentOrShadowRoot r=dom-core,webidl,smaug
Differential Revision: https://phabricator.services.mozilla.com/D285678
2026-03-09 19:18:22 +00:00
Keith Cirkel 0137398cf8 Bug 2018908 - Add comments to various CustomElementRegistry functions r=dom-core,edgar
Differential Revision: https://phabricator.services.mozilla.com/D284626
2026-02-26 14:15:34 +00:00
Cristina Horotan fbd0964b46 Revert "Bug 1937566, Bug 2018899, Bug 2018907, Bug 2018908 - Make CustomElementRegistry constructable r=dom-core,webidl,emilio,edgar" for causing wpt failures on Document-createElement.html
This reverts commit dc1af4136a.

Revert "Bug 2018899 - Add dom.scoped-custom-element-registries.enabled pref r=dom-core,edgar"

This reverts commit fd5355f74e.

Revert "Bug 2018907 - Extract LifecycleCallbackArgs from CustomElementRegistry r=dom-core,edgar"

This reverts commit 41c64730eb.

Revert "Bug 2018908 - Add comments to various CustomElementRegistry functions r=dom-core,edgar"

This reverts commit 3e75494429.
2026-02-25 18:21:24 +00:00
Keith Cirkel 3e75494429 Bug 2018908 - Add comments to various CustomElementRegistry functions r=dom-core,edgar
Differential Revision: https://phabricator.services.mozilla.com/D284626
2026-02-25 14:51:58 +00:00
Emilio Cobos Álvarez e0b647d871 Bug 2017005 - Always keep track of subtree root. r=dom-core,smaug
This stops penalizing shadow DOM contents by forcing extended slots into
everything inside a shadow tree, but grows nodes by a pointer.

It has an additional benefit of making forgetting a null-check in
GetPrimaryFrame() not cause a type confusion, and is a speedometer 3
progression, specially on the webcomponents-heavy bits, but even more
now that we use Shadow DOM a bit more internally.

Differential Revision: https://phabricator.services.mozilla.com/D283477
2026-02-24 12:07:03 +00:00
Emilio Cobos Álvarez 968fc5a645 Bug 2015924 - Centralize lazyload checks, and observe only while in document. r=smaug
Now that stuff is a bit more complex and that we're adding media lazy
loading, factor the observer management down to Element.

Make UnbindContext more parallel to BindContext while at it. This
allows the new calls to work regardless of whether they get called
before or after the base class's Bind/UnbindFromTree, which is nice.

Differential Revision: https://phabricator.services.mozilla.com/D282723
2026-02-11 15:14:46 +00:00
Keith Cirkel 6fb924e837 Bug 2010888 - Move ShadowRoot boolean members into Node flags r=dom-core,smaug
Differential Revision: https://phabricator.services.mozilla.com/D279346
2026-01-18 00:01:40 +00:00
Alice Boxhall a4ba7f0009 Bug 1981349 - Add referenceTarget support for label/for, label wrapped and output/for. r=credential-management-reviewers,webidl,dimi,Jamie,smaug
This makes significant changes to RelatedAccIterator, nsLabelsNodeList and nsContentList:

- RelatedAccIterator is now able to walk up shadow roots where appropriate.
- HTMLLabelsIterator now eagerly constructs a TreeOrderedArray of related elements, walking up shadow roots while the shadow root's reference target is either mAcc's content or a host of one of its ancestor shadow roots.
- nsLabelsNodeList now has an array of roots as well as mRootNode in the superclass nsContentList. This list is reset under certain conditions, adding each shadow root found by walking up from the labeled element until one is found which doesn't have either the labeled element or the host of one of its ancestor shadow roots as a reference target. The last element in this list is set as mRootNode in the superclass, and is either the containing document, or the subtree root of either the labeled element or the host element whose containing shadow root doesn't have it as a reference target. Each root has a mutation observer added to ensure that the list is marked dirty when necessary, and also that roots are removed from `mRoots` when they are destroyed.
- In order to enable nsLabelsNodeList to be a mutation observer for each root, nsContentList now inherits from nsStubMultiMutationObserver instead of nsStubMutationObserver.

This change also moves the ReferenceTargetChangeObserver-related methods from DocumentOrShadowRoot on to Element, and the related data structures on to nsExtendedDOMSlots.

It also introduces a distinction between GetControlForBindings, which returns an element in the same scope as the label element it's called on, and GetLabeledElementInternal, which returns the element which actually has the label element as its label.

Differential Revision: https://phabricator.services.mozilla.com/D261368
2026-01-15 13:40:05 +00:00
Alice Boxhall d5493de262 Bug 1981346 - Add referenceTarget support for the form attribute. r=credential-management-reviewers,webidl,dimi,Jamie,smaug
This change adds attr-associated element observers, which observe changes in the element associated with a single-element attribute.
For example, if an element has an attribute |attr| with a value |value|, and an AttrTargetObserver has been added for |attr| on that element, the observer would fire if an element with an ID matching |value| was added to the element's document or shadow root.

Attr-associated element observers are tracked in mAttrElementObserverMap in an element's nsExtendedDOMSlots.

An attr-associated element can change in multiple ways:
- The attribute value changes;
- An element matching the content attribute value is added or removed from the element's document or shadow root;
- The explicitly-set attr element is added or removed from the element's document or shadow root;
- The resolved reference target for the explicitly set attr-element or the element whose ID matches the string value of the attribute changes.

The resolved reference target can likewise change in multiple ways:
- The referenceTarget property of the element's shadow root is added, changed or removed;
- An element whose ID matches the element's shadow root's referenceTarget value is added or removed from the shadow root;
- The resolved reference target of the element whose ID matches the shadow root's referenceTarget value changes.

These changes are tracked via reference target change observers, which observe changes to an element's resolved reference target.
Reference target change observers are added on the host element's document or shadow root, and fired when one of the above circumstances occurs.

Differential Revision: https://phabricator.services.mozilla.com/D261367
2026-01-14 18:03:46 +00:00
Alice Boxhall 760830f75d Bug 1989323 - Make referenceTarget IDL attributes on ShadowRoot, HTMLTemplateElement and ShadowRootInit nullable. r=dom-core,webidl,saschanaz,smaug
This was resolved in https://github.com/WICG/webcomponents/issues/1093.

Differential Revision: https://phabricator.services.mozilla.com/D265456
2026-01-14 18:03:26 +00:00
Sandor Molnar 8faede9a1f Revert "Bug 1981349 - Add referenceTarget support for label/for, label wrapped and output/for. r=credential-management-reviewers,webidl,dimi,Jamie,smaug" for causing accessibility crashes (bug 2008970)
This reverts commit d46abe6d76.

Revert "Bug 1981346 - Add referenceTarget support for the form attribute. r=credential-management-reviewers,webidl,dimi,Jamie,smaug"

This reverts commit df11a4666d.

Revert "Bug 1981345 - Implement referenceTarget support for multiple element attributes. r=dom-core,Jamie,smaug"

This reverts commit 89cc779f5e.

Revert "Bug 1984685 - Refactor: consistently return Maybe<nsTArray<RefPtr<Element>>> when getting attr-associated elements, and key AttrRelProviders on nsAtom rather than nsString. r=dom-core,morgan,Jamie,smaug"

This reverts commit 33130e712d.

Revert "Bug 1981344 - Implement referenceTarget support for single-element attributes. r=dom-core,credential-management-reviewers,webidl,layout-reviewers,emilio,keithamus,smaug,mtigley"

This reverts commit d6440c4cae.

Revert "Bug 1983766 - Split single element attribute getters into bindings/internals versions. r=dom-core,credential-management-reviewers,webidl,layout-reviewers,smaug,keithamus,jwatt,mtigley"

This reverts commit 83b70e0645.

Revert "Bug 1989323 - Make `referenceTarget` IDL attributes on ShadowRoot, HTMLTemplateElement and ShadowRootInit nullable. r=dom-core,webidl,saschanaz,smaug"

This reverts commit 3a0b29121e.
2026-01-07 16:08:51 +00:00
Alice Boxhall d46abe6d76 Bug 1981349 - Add referenceTarget support for label/for, label wrapped and output/for. r=credential-management-reviewers,webidl,dimi,Jamie,smaug
This makes significant changes to RelatedAccIterator, nsLabelsNodeList and nsContentList:

- RelatedAccIterator now eagerly constructs a TreeOrderedArray of related elements, walking up shadow roots from mDependentContent while the shadow root's reference target is either mDependentContent or a host of one of its ancestor shadow roots.
- nsLabelsNodeList now has an array of roots as well as mRootNode in the superclass nsContentList. This list is reset under certain conditions, adding each shadow root found by walking up from the labeled element until one is found which doesn't have either the labeled element or the host of one of its ancestor shadow roots as a reference target. The last element in this list is set as mRootNode in the superclass, and is either the containing document, or the subtree root of either the labeled element or the host element whose containing shadow root doesn't have it as a reference target. Each root has a mutation observer added to ensure that the list is marked dirty when necessary, and also that roots are removed from `mRoots` when they are destroyed.
- In order to enable nsLabelsNodeList to be a mutation observer for each root, nsContentList now inherits from nsStubMultiMutationObserver instead of nsStubMutationObserver.

This change also moves the ReferenceTargetChangeObserver-related methods from DocumentOrShadowRoot on to Element, and the related data structures on to nsExtendedDOMSlots.

It also introduces a distinction between GetControlForBindings, which returns an element in the same scope as the label element it's called on, and GetLabeledElementInternal, which returns the element which actually has the label element as its label.

Differential Revision: https://phabricator.services.mozilla.com/D261368
2026-01-06 16:16:29 +00:00
Alice Boxhall df11a4666d Bug 1981346 - Add referenceTarget support for the form attribute. r=credential-management-reviewers,webidl,dimi,Jamie,smaug
This change adds attr-associated element observers, which observe changes in the element associated with a single-element attribute.
For example, if an element has an attribute |attr| with a value |value|, and an AttrTargetObserver has been added for |attr| on that element, the observer would fire if an element with an ID matching |value| was added to the element's document or shadow root.

Attr-associated element observers are tracked in mAttrElementObserverMap in an element's nsExtendedDOMSlots.

An attr-associated element can change in multiple ways:
- The attribute value changes;
- An element matching the content attribute value is added or removed from the element's document or shadow root;
- The explicitly-set attr element is added or removed from the element's document or shadow root;
- The resolved reference target for the explicitly set attr-element or the element whose ID matches the string value of the attribute changes.

The resolved reference target can likewise change in multiple ways:
- The referenceTarget property of the element's shadow root is added, changed or removed;
- An element whose ID matches the element's shadow root's referenceTarget value is added or removed from the shadow root;
- The resolved reference target of the element whose ID matches the shadow root's referenceTarget value changes.

These changes are tracked via reference target change observers, which observe changes to an element's resolved reference target.
Reference target change observers are added on the host element's document or shadow root, and fired when one of the above circumstances occurs.

Differential Revision: https://phabricator.services.mozilla.com/D261367
2026-01-06 16:16:26 +00:00
Alice Boxhall 3a0b29121e Bug 1989323 - Make referenceTarget IDL attributes on ShadowRoot, HTMLTemplateElement and ShadowRootInit nullable. r=dom-core,webidl,saschanaz,smaug
This was resolved in https://github.com/WICG/webcomponents/issues/1093.

Differential Revision: https://phabricator.services.mozilla.com/D265456
2026-01-06 16:16:10 +00:00
iulian moraru e162366a25 Revert "Bug 1981349, Bug 1981346, Bug 1981345, Bug 1984685, Bug 1981344, Bug 1983766, Bug 1989323 - Add referenceTarget support for label/for, label wrapped and output/for. r=credential-management-reviewers,webidl,dimi,Jamie,smaug" for causing android build bustages.
This reverts commit 1b5cf4cdf8.

Revert "Bug 1981346 - Add referenceTarget support for the form attribute. r=credential-management-reviewers,webidl,dimi,Jamie,smaug"

This reverts commit 2394d9205a.

Revert "Bug 1981345 - Implement referenceTarget support for multiple element attributes. r=dom-core,Jamie,smaug"

This reverts commit 571a17ff82.

Revert "Bug 1984685 - Refactor: consistently return Maybe<nsTArray<RefPtr<Element>>> when getting attr-associated elements, and key AttrRelProviders on nsAtom rather than nsString. r=dom-core,morgan,Jamie,smaug"

This reverts commit 3b389fdd62.

Revert "Bug 1981344 - Implement referenceTarget support for single-element attributes. r=dom-core,credential-management-reviewers,webidl,layout-reviewers,emilio,keithamus,smaug,mtigley"

This reverts commit 5cc2a12756.

Revert "Bug 1983766 - Split single element attribute getters into bindings/internals versions. r=dom-core,credential-management-reviewers,webidl,layout-reviewers,smaug,keithamus,jwatt,mtigley"

This reverts commit 68e2d26aa9.

Revert "Bug 1989323 - Make `referenceTarget` IDL attributes on ShadowRoot, HTMLTemplateElement and ShadowRootInit nullable. r=dom-core,webidl,saschanaz,smaug"

This reverts commit 1234b31599.
2025-12-24 15:16:52 +00:00
Alice Boxhall 1b5cf4cdf8 Bug 1981349 - Add referenceTarget support for label/for, label wrapped and output/for. r=credential-management-reviewers,webidl,dimi,Jamie,smaug
This makes significant changes to RelatedAccIterator, nsLabelsNodeList and nsContentList:

- RelatedAccIterator now eagerly constructs a TreeOrderedArray of related elements, walking up shadow roots from mDependentContent while the shadow root's reference target is either mDependentContent or a host of one of its ancestor shadow roots.
- nsLabelsNodeList now has an array of roots as well as mRootNode in the superclass nsContentList. This list is reset under certain conditions, adding each shadow root found by walking up from the labeled element until one is found which doesn't have either the labeled element or the host of one of its ancestor shadow roots as a reference target. The last element in this list is set as mRootNode in the superclass, and is either the containing document, or the subtree root of either the labeled element or the host element whose containing shadow root doesn't have it as a reference target. Each root has a mutation observer added to ensure that the list is marked dirty when necessary, and also that roots are removed from `mRoots` when they are destroyed.
- In order to enable nsLabelsNodeList to be a mutation observer for each root, nsContentList now inherits from nsStubMultiMutationObserver instead of nsStubMutationObserver.

This change also moves the ReferenceTargetChangeObserver-related methods from DocumentOrShadowRoot on to Element, and the related data structures on to nsExtendedDOMSlots.

It also introduces a distinction between GetControlForBindings, which returns an element in the same scope as the label element it's called on, and GetLabeledElementInternal, which returns the element which actually has the label element as its label.

Differential Revision: https://phabricator.services.mozilla.com/D261368
2025-12-24 13:41:57 +00:00
Alice Boxhall 2394d9205a Bug 1981346 - Add referenceTarget support for the form attribute. r=credential-management-reviewers,webidl,dimi,Jamie,smaug
This change adds attr-associated element observers, which observe changes in the element associated with a single-element attribute.
For example, if an element has an attribute |attr| with a value |value|, and an AttrTargetObserver has been added for |attr| on that element, the observer would fire if an element with an ID matching |value| was added to the element's document or shadow root.

Attr-associated element observers are tracked in mAttrElementObserverMap in an element's nsExtendedDOMSlots.

An attr-associated element can change in multiple ways:
- The attribute value changes;
- An element matching the content attribute value is added or removed from the element's document or shadow root;
- The explicitly-set attr element is added or removed from the element's document or shadow root;
- The resolved reference target for the explicitly set attr-element or the element whose ID matches the string value of the attribute changes.

The resolved reference target can likewise change in multiple ways:
- The referenceTarget property of the element's shadow root is added, changed or removed;
- An element whose ID matches the element's shadow root's referenceTarget value is added or removed from the shadow root;
- The resolved reference target of the element whose ID matches the shadow root's referenceTarget value changes.

These changes are tracked via reference target change observers, which observe changes to an element's resolved reference target.
Reference target change observers are added on the host element's document or shadow root, and fired when one of the above circumstances occurs.

Differential Revision: https://phabricator.services.mozilla.com/D261367
2025-12-24 13:41:54 +00:00
Alice Boxhall 1234b31599 Bug 1989323 - Make referenceTarget IDL attributes on ShadowRoot, HTMLTemplateElement and ShadowRootInit nullable. r=dom-core,webidl,saschanaz,smaug
This was resolved in https://github.com/WICG/webcomponents/issues/1093.

Differential Revision: https://phabricator.services.mozilla.com/D265456
2025-12-24 13:41:38 +00:00
Emilio Cobos Álvarez 2a3733e687 Bug 2006613 - Optimize front-removal of various tree-ordered-arrays. r=smaug
The previous approach wasn't quite sound, because it makes the frame
constructor receive the WillBeRemoved after the flat tree has already
changed.

Instead, what do you think about something like this? This creates a
very simple wrapper over an array, but special-cases removals from the
front, and uses it for TreeOrderedArray and also AssignedNodes...

It could be polished (in particular there are a few places where an
Span::IndexOf operator could be beneficial and so).

Differential Revision: https://phabricator.services.mozilla.com/D277301
2025-12-22 21:03:58 +00:00
Norisz Fay ac500ea570 Revert "Bug 2006613 - Optimize front-removal of various tree-ordered-arrays. r=smaug" for causing multiple failures and bustages
This reverts commit 4d02f992d0.
2025-12-22 19:45:18 +00:00
Emilio Cobos Álvarez 4d02f992d0 Bug 2006613 - Optimize front-removal of various tree-ordered-arrays. r=smaug
The previous approach wasn't quite sound, because it makes the frame
constructor receive the WillBeRemoved after the flat tree has already
changed.

Instead, what do you think about something like this? This creates a
very simple wrapper over an array, but special-cases removals from the
front, and uses it for TreeOrderedArray and also AssignedNodes...

It could be polished (in particular there are a few places where an
Span::IndexOf operator could be beneficial and so).

Differential Revision: https://phabricator.services.mozilla.com/D277301
2025-12-22 18:35:29 +00:00
Emilio Cobos Álvarez a1993f4ba4 Bug 2007270 - Partially back out the regressing patch.
Differential Revision: https://phabricator.services.mozilla.com/D277296
2025-12-21 17:09:22 +00:00
Emilio Cobos Álvarez 09b0c2e504 Bug 2006613 - Plumb batch removal state through unbind, and use it to optimize Shadow DOM removal. r=smaug
This shows up in bug 2000414, where the front-end clears all the
menuitems of a <menupopup> at once, and they are all slotted, and
clearing the assigned node list from the front is more expensive than
necessary. See the profile in: https://share.firefox.dev/493zcYj

Of course, it'd be better to remove back to front, but that would be
observable, and it seems we can improve our batch removal machinery to
deal with this case quite easily, since if all the host kids are going
away, we know we will end up with no assigned nodes at all.

Differential Revision: https://phabricator.services.mozilla.com/D276828
2025-12-18 09:45:12 +00:00
Cristina Horotan 3959e0d60e Revert "Bug 2006613 - Pass batch removal state through to unbind / unlink. r=smaug,dom-core" for causing crashtest failures on nsINode.h
This reverts commit 42f606b166.

Revert "Bug 2006613 - Plumb batch removal state through unbind, and use it to optimize Shadow DOM removal. r=smaug"

This reverts commit 264c0f0437.
2025-12-18 02:05:58 +00:00
Emilio Cobos Álvarez 264c0f0437 Bug 2006613 - Plumb batch removal state through unbind, and use it to optimize Shadow DOM removal. r=smaug
This shows up in bug 2000414, where the front-end clears all the
menuitems of a <menupopup> at once, and they are all slotted, and
clearing the assigned node list from the front is more expensive than
necessary. See the profile in: https://share.firefox.dev/493zcYj

Of course, it'd be better to remove back to front, but that would be
observable, and it seems we can improve our batch removal machinery to
deal with this case quite easily, since if all the host kids are going
away, we know we will end up with no assigned nodes at all.

Differential Revision: https://phabricator.services.mozilla.com/D276828
2025-12-17 22:12:56 +00:00
Emilio Cobos ÁlvarezandNicolas Chevobbe 65f4a6b2c8 Bug 1986702 - Fix CSSOM tracking in shadow DOM. r=devtools-reviewers,nchevobbe
Bug 1933473 missed the shadow root style rule map, this is the
equivalent fix.

The test in D268698 covers this (now it shows the bug but it should be
adapted to expect the right behavior).

Co-authored-by: Nicolas Chevobbe <[email protected]>

Differential Revision: https://phabricator.services.mozilla.com/D268744
2025-10-16 07:40:58 +00:00
Alice Boxhall e5cf85c1e4 Bug 1981341 - Add referenceTarget and shadowRootReferenceTarget attributes. r=webidl,emilio,hsivonen
Allows setting referenceTarget when creating shadow roots declaratively or programatically, and also getting the referenceTarget value for a shadow root.

Differential Revision: https://phabricator.services.mozilla.com/D260140
2025-09-08 13:39:34 +00:00
Emilio Cobos Álvarez 791917d8af Bug 1976665 - Sort headers in dom/. r=dom-core,media-playback-reviewers,webrtc-reviewers,dom-storage-reviewers,padenot,janv,smaug,jesup,jib
Most changes are automated. Relevant bit is dom/.clang-format. I had to
manually disable clang-format in a few places where importing external
files and so on that aren't self-contained, and fix a couple includes /
forward declarations.

Differential Revision: https://phabricator.services.mozilla.com/D256800
2025-08-05 11:47:34 +00:00
Olli Pettay 0b460dc40d Bug 1923880, ParentNode.moveBefore(), r=edgar,emilio
iframe tests neeeded tweak because the changes for about:blank haven't landed quite yet.
Render blocking and such aren't supported, so the .ini files are still there.
Selection test seemed to be very chromium specific.

Differential Revision: https://phabricator.services.mozilla.com/D255463
2025-07-21 16:33:44 +00:00
iulian moraru d9d5a440a7 Revert "Bug 1923880, ParentNode.moveBefore(), r=edgar,emilio" for causing non-unified build bustages on nsGenericHTMLFrameElement.cpp.
This reverts commit feac8d52fc.
2025-07-21 10:49:53 +00:00
Olli Pettay feac8d52fc Bug 1923880, ParentNode.moveBefore(), r=edgar,emilio
iframe tests neeeded tweak because the changes for about:blank haven't landed quite yet.
Render blocking and such aren't supported, so the .ini files are still there.
Selection test seemed to be very chromium specific.

Differential Revision: https://phabricator.services.mozilla.com/D255463
2025-07-21 09:37:38 +00:00
David Shin d892acf987 Bug 1930618: LinkStyle subclasses clone its stylesheet while cloning for static document. r=layout-reviewers,emilio
... This preserves the link between the node and its stylesheet, enabling
implicit scope to continue working for the static document (e.g. For printing).

Differential Revision: https://phabricator.services.mozilla.com/D229531
2025-07-07 18:52:10 +00:00
Emilio Cobos Álvarez 0fb5512190 Bug 1922586 - More explicitly opt in into bindings for UniquePtr. r=sergesanspaille
std::unique_ptr's subtleties are hard for bindgen to cope with.

Bug 1973598 was going to make this workaround even uglier by having to figure
out the specific path for std::unique_ptr in the standard library.

Rather than assuming that all usage bindgen sees is simple, explicitly opt in
the few pointers that we need via a new BindgenUniquePtr, and make opaque the
rest.

Differential Revision: https://phabricator.services.mozilla.com/D255568
2025-07-01 08:30:38 +00:00