1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/HTMLDetailsElement.h"
9 #include "mozilla/dom/HTMLDetailsElementBinding.h"
11 NS_IMPL_NS_NEW_HTML_ELEMENT(Details
)
16 HTMLDetailsElement::~HTMLDetailsElement()
20 NS_IMPL_ELEMENT_CLONE(HTMLDetailsElement
)
23 HTMLDetailsElement::GetFirstSummary() const
25 // XXX: Bug 1245032: Might want to cache the first summary element.
26 for (nsIContent
* child
= nsINode::GetFirstChild();
28 child
= child
->GetNextSibling()) {
29 if (child
->IsHTMLElement(nsGkAtoms::summary
)) {
37 HTMLDetailsElement::GetAttributeChangeHint(const nsAtom
* aAttribute
,
38 int32_t aModType
) const
41 nsGenericHTMLElement::GetAttributeChangeHint(aAttribute
, aModType
);
42 if (aAttribute
== nsGkAtoms::open
) {
43 hint
|= nsChangeHint_ReconstructFrame
;
49 HTMLDetailsElement::BeforeSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
50 const nsAttrValueOrString
* aValue
, bool aNotify
)
52 if (aNameSpaceID
== kNameSpaceID_None
&& aName
== nsGkAtoms::open
) {
53 bool setOpen
= aValue
!= nullptr;
54 if (Open() != setOpen
) {
55 if (mToggleEventDispatcher
) {
56 mToggleEventDispatcher
->Cancel();
58 // According to the html spec, a 'toggle' event is a simple event which
60 mToggleEventDispatcher
=
61 new AsyncEventDispatcher(this,
62 NS_LITERAL_STRING("toggle"),
64 mToggleEventDispatcher
->PostDOMEvent();
68 return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID
, aName
, aValue
,
73 HTMLDetailsElement::AsyncEventRunning(AsyncEventDispatcher
* aEvent
)
75 if (mToggleEventDispatcher
== aEvent
) {
76 mToggleEventDispatcher
= nullptr;
81 HTMLDetailsElement::WrapNode(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
)
83 return HTMLDetailsElement_Binding::Wrap(aCx
, this, aGivenProto
);
87 } // namespace mozilla