Files
sousa-gecko/dom/html/HTMLDetailsElement.h
Masayuki Nakano ca0029c572 Bug 1625902 - part 4: Make dispatcher of the chrome event of initializing/finalizing UA shadow require a script blocker r=smaug,emilio,layout-reviewers
They may dispatch `UAWidgetSetupOrChange` or `UAWidgetTeardown` chrome
event to notify the UA widget of creation or destruction. That's
required to the layout and making the UA widget start working. This
is important especially when the call is caused by JS. Then, the next
line may require the new UA widget. Therefore, we cannot make them
use `NS_DispatchToCurrentThread` because it may run too late for JS.

On the other hand, they are called during `BindToTree()`,
`UnbindFromTree()` and `nsCSSFrameConstructor` working. In these cases,
running script is blocked. Therefore, their `AddScriptRunner` dispatches
the chrome events asynchronously but before returning to the JS world.

To avoid to mark them as `MOZ_CAN_RUN_SCRIPT` and `BindToTree()`,
`UnbindFromTree()` and `nsCSSFrameConstructor` methods as
`MOZ_CAN_RUN_SCRIPT_BOUNDARY`, they should always dispatch chrome events
asynchronously. Therefore, they will assert that they are called when
script is blocked and this patch adds some callers put
`nsAutoScriptBlocker` or `mozAutoDocUpdate`.

Differential Revision: https://phabricator.services.mozilla.com/D311670
2026-08-25 06:57:24 +00:00

89 lines
3.0 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_HTMLDetailsElement_h
#define mozilla_dom_HTMLDetailsElement_h
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Attributes.h"
#include "nsGenericHTMLElement.h"
namespace mozilla::dom {
class HTMLSummaryElement;
// HTMLDetailsElement implements the <details> tag, which is used as a
// disclosure widget from which the user can obtain additional information or
// controls. Please see the spec for more information.
// https://html.spec.whatwg.org/multipage/forms.html#the-details-element
//
class HTMLDetailsElement final : public nsGenericHTMLElement {
public:
using NodeInfo = mozilla::dom::NodeInfo;
using Element::Command;
explicit HTMLDetailsElement(already_AddRefed<NodeInfo> aNodeInfo);
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLDetailsElement, details)
HTMLSummaryElement* GetFirstSummary() const;
nsresult Clone(NodeInfo* aNodeInfo, nsINode** aResult) const override;
void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue, const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
nsresult BindToTree(BindContext&, nsINode& aParent) override;
bool IsInteractiveHTMLContent() const override { return true; }
// HTMLDetailsElement WebIDL
void SetName(const nsAString& aName, ErrorResult& aRv) {
SetHTMLAttr(nsGkAtoms::name, aName, aRv);
}
void GetName(nsAString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
bool Open() const { return State().HasState(ElementState::OPEN); }
void SetOpen(bool aOpen, ErrorResult& aError) {
SetHTMLBoolAttr(nsGkAtoms::open, aOpen, aError);
}
void ToggleOpen() { SetOpen(!Open(), IgnoreErrors()); }
void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
bool IsValidCommandAction(Command aCommand) const override;
MOZ_CAN_RUN_SCRIPT bool HandleCommandInternal(Element* aSource,
Command aCommand,
ErrorResult& aRv) override;
protected:
virtual ~HTMLDetailsElement();
void SetupShadowTree();
void GetSlotNameFor(const ShadowRoot&, const nsIContent&,
nsAString&) const override;
void OnChildBeforeSlotted(ShadowRoot&, nsIContent&) override;
void OnChildUnslotted(ShadowRoot&, nsIContent&) override;
// https://html.spec.whatwg.org/#ensure-details-exclusivity-by-closing-the-given-element-if-needed
void CloseElementIfNeeded(nsAtom* aName);
// https://html.spec.whatwg.org/#ensure-details-exclusivity-by-closing-other-elements-if-needed
void CloseOtherElementsIfNeeded();
JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
RefPtr<AsyncEventDispatcher> mToggleEventDispatcher;
};
} // namespace mozilla::dom
#endif /* mozilla_dom_HTMLDetailsElement_h */