Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "mozilla/dom/HTMLDetailsElement.h"
7 :
8 : #include "mozilla/dom/HTMLDetailsElementBinding.h"
9 :
10 0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Details)
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 0 : HTMLDetailsElement::~HTMLDetailsElement()
16 : {
17 0 : }
18 :
19 0 : NS_IMPL_ELEMENT_CLONE(HTMLDetailsElement)
20 :
21 : nsIContent*
22 0 : HTMLDetailsElement::GetFirstSummary() const
23 : {
24 : // XXX: Bug 1245032: Might want to cache the first summary element.
25 0 : for (nsIContent* child = nsINode::GetFirstChild();
26 0 : child;
27 0 : child = child->GetNextSibling()) {
28 0 : if (child->IsHTMLElement(nsGkAtoms::summary)) {
29 0 : return child;
30 : }
31 : }
32 0 : return nullptr;
33 : }
34 :
35 : nsChangeHint
36 0 : HTMLDetailsElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
37 : int32_t aModType) const
38 : {
39 : nsChangeHint hint =
40 0 : nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
41 0 : if (aAttribute == nsGkAtoms::open) {
42 0 : hint |= nsChangeHint_ReconstructFrame;
43 : }
44 0 : return hint;
45 : }
46 :
47 : nsresult
48 0 : HTMLDetailsElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
49 : const nsAttrValueOrString* aValue, bool aNotify)
50 : {
51 0 : if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::open) {
52 0 : bool setOpen = aValue != nullptr;
53 0 : if (Open() != setOpen) {
54 0 : if (mToggleEventDispatcher) {
55 0 : mToggleEventDispatcher->Cancel();
56 : }
57 : // According to the html spec, a 'toggle' event is a simple event which
58 : // does not bubble.
59 : mToggleEventDispatcher =
60 0 : new AsyncEventDispatcher(this, NS_LITERAL_STRING("toggle"), false);
61 0 : mToggleEventDispatcher->PostDOMEvent();
62 : }
63 : }
64 :
65 0 : return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName, aValue,
66 0 : aNotify);
67 : }
68 :
69 : void
70 0 : HTMLDetailsElement::AsyncEventRunning(AsyncEventDispatcher* aEvent)
71 : {
72 0 : if (mToggleEventDispatcher == aEvent) {
73 0 : mToggleEventDispatcher = nullptr;
74 : }
75 0 : }
76 :
77 : JSObject*
78 0 : HTMLDetailsElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
79 : {
80 0 : return HTMLDetailsElementBinding::Wrap(aCx, this, aGivenProto);
81 : }
82 :
83 : } // namespace dom
84 : } // namespace mozilla
|