Bug 1494333 - index crons just like artifacts r=Callek
[gecko.git] / dom / html / HTMLDetailsElement.cpp
blobec2235d6c7309f2c5721dd2449e7e58537990e13
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)
13 namespace mozilla {
14 namespace dom {
16 HTMLDetailsElement::~HTMLDetailsElement()
20 NS_IMPL_ELEMENT_CLONE(HTMLDetailsElement)
22 nsIContent*
23 HTMLDetailsElement::GetFirstSummary() const
25 // XXX: Bug 1245032: Might want to cache the first summary element.
26 for (nsIContent* child = nsINode::GetFirstChild();
27 child;
28 child = child->GetNextSibling()) {
29 if (child->IsHTMLElement(nsGkAtoms::summary)) {
30 return child;
33 return nullptr;
36 nsChangeHint
37 HTMLDetailsElement::GetAttributeChangeHint(const nsAtom* aAttribute,
38 int32_t aModType) const
40 nsChangeHint hint =
41 nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
42 if (aAttribute == nsGkAtoms::open) {
43 hint |= nsChangeHint_ReconstructFrame;
45 return hint;
48 nsresult
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
59 // does not bubble.
60 mToggleEventDispatcher =
61 new AsyncEventDispatcher(this,
62 NS_LITERAL_STRING("toggle"),
63 CanBubble::eNo);
64 mToggleEventDispatcher->PostDOMEvent();
68 return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName, aValue,
69 aNotify);
72 void
73 HTMLDetailsElement::AsyncEventRunning(AsyncEventDispatcher* aEvent)
75 if (mToggleEventDispatcher == aEvent) {
76 mToggleEventDispatcher = nullptr;
80 JSObject*
81 HTMLDetailsElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
83 return HTMLDetailsElement_Binding::Wrap(aCx, this, aGivenProto);
86 } // namespace dom
87 } // namespace mozilla