OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies) | 2 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies) |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/html/HTMLDetailsElement.h" | 22 #include "core/html/HTMLDetailsElement.h" |
23 | 23 |
24 #include "CSSPropertyNames.h" | 24 #include "CSSPropertyNames.h" |
25 #include "CSSValueKeywords.h" | 25 #include "CSSValueKeywords.h" |
26 #include "HTMLNames.h" | 26 #include "HTMLNames.h" |
27 #include "bindings/v8/ExceptionStatePlaceholder.h" | 27 #include "bindings/v8/ExceptionStatePlaceholder.h" |
28 #include "core/dom/Text.h" | 28 #include "core/dom/Text.h" |
29 #include "core/dom/shadow/ShadowRoot.h" | 29 #include "core/dom/shadow/ShadowRoot.h" |
| 30 #include "core/events/EventSender.h" |
30 #include "core/html/HTMLContentElement.h" | 31 #include "core/html/HTMLContentElement.h" |
31 #include "core/html/HTMLDivElement.h" | 32 #include "core/html/HTMLDivElement.h" |
32 #include "core/html/HTMLSummaryElement.h" | 33 #include "core/html/HTMLSummaryElement.h" |
33 #include "core/html/shadow/ShadowElementNames.h" | 34 #include "core/html/shadow/ShadowElementNames.h" |
34 #include "core/rendering/RenderBlockFlow.h" | 35 #include "core/rendering/RenderBlockFlow.h" |
35 #include "platform/text/PlatformLocale.h" | 36 #include "platform/text/PlatformLocale.h" |
36 | 37 |
37 namespace WebCore { | 38 namespace WebCore { |
38 | 39 |
39 using namespace HTMLNames; | 40 using namespace HTMLNames; |
40 | 41 |
| 42 static DetailsEventSender& detailsToggleEventSender() |
| 43 { |
| 44 DEFINE_STATIC_LOCAL(DetailsEventSender, sharedToggleEventSender, (EventTypeN
ames::toggle)); |
| 45 return sharedToggleEventSender; |
| 46 } |
| 47 |
41 PassRefPtr<HTMLDetailsElement> HTMLDetailsElement::create(Document& document) | 48 PassRefPtr<HTMLDetailsElement> HTMLDetailsElement::create(Document& document) |
42 { | 49 { |
43 RefPtr<HTMLDetailsElement> details = adoptRef(new HTMLDetailsElement(documen
t)); | 50 RefPtr<HTMLDetailsElement> details = adoptRef(new HTMLDetailsElement(documen
t)); |
44 details->ensureUserAgentShadowRoot(); | 51 details->ensureUserAgentShadowRoot(); |
45 return details.release(); | 52 return details.release(); |
46 } | 53 } |
47 | 54 |
48 HTMLDetailsElement::HTMLDetailsElement(Document& document) | 55 HTMLDetailsElement::HTMLDetailsElement(Document& document) |
49 : HTMLElement(detailsTag, document) | 56 : HTMLElement(detailsTag, document) |
50 , m_isOpen(false) | 57 , m_isOpen(false) |
51 { | 58 { |
52 ScriptWrappable::init(this); | 59 ScriptWrappable::init(this); |
53 } | 60 } |
54 | 61 |
| 62 HTMLDetailsElement::~HTMLDetailsElement() |
| 63 { |
| 64 detailsToggleEventSender().cancelEvent(this); |
| 65 } |
| 66 |
| 67 void HTMLDetailsElement::dispatchPendingEvent(DetailsEventSender* eventSender) |
| 68 { |
| 69 ASSERT_UNUSED(eventSender, eventSender == &detailsToggleEventSender()); |
| 70 dispatchEvent(Event::create(EventTypeNames::toggle)); |
| 71 } |
| 72 |
| 73 |
55 RenderObject* HTMLDetailsElement::createRenderer(RenderStyle*) | 74 RenderObject* HTMLDetailsElement::createRenderer(RenderStyle*) |
56 { | 75 { |
57 return new RenderBlockFlow(this); | 76 return new RenderBlockFlow(this); |
58 } | 77 } |
59 | 78 |
60 void HTMLDetailsElement::didAddUserAgentShadowRoot(ShadowRoot& root) | 79 void HTMLDetailsElement::didAddUserAgentShadowRoot(ShadowRoot& root) |
61 { | 80 { |
62 DEFINE_STATIC_LOCAL(const AtomicString, summarySelector, ("summary:first-of-
type", AtomicString::ConstructFromLiteral)); | 81 DEFINE_STATIC_LOCAL(const AtomicString, summarySelector, ("summary:first-of-
type", AtomicString::ConstructFromLiteral)); |
63 | 82 |
64 RefPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::create(docum
ent()); | 83 RefPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::create(docum
ent()); |
(...skipping 22 matching lines...) Expand all Loading... |
87 return toElement(content->firstChild()); | 106 return toElement(content->firstChild()); |
88 } | 107 } |
89 | 108 |
90 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) | 109 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) |
91 { | 110 { |
92 if (name == openAttr) { | 111 if (name == openAttr) { |
93 bool oldValue = m_isOpen; | 112 bool oldValue = m_isOpen; |
94 m_isOpen = !value.isNull(); | 113 m_isOpen = !value.isNull(); |
95 if (m_isOpen == oldValue) | 114 if (m_isOpen == oldValue) |
96 return; | 115 return; |
| 116 |
| 117 // Dispatch toggle event asynchronously. |
| 118 detailsToggleEventSender().cancelEvent(this); |
| 119 detailsToggleEventSender().dispatchEventSoon(this); |
| 120 |
97 Element* content = ensureUserAgentShadowRoot().getElementById(ShadowElem
entNames::detailsContent()); | 121 Element* content = ensureUserAgentShadowRoot().getElementById(ShadowElem
entNames::detailsContent()); |
98 ASSERT(content); | 122 ASSERT(content); |
99 if (m_isOpen) | 123 if (m_isOpen) |
100 content->removeInlineStyleProperty(CSSPropertyDisplay); | 124 content->removeInlineStyleProperty(CSSPropertyDisplay); |
101 else | 125 else |
102 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | 126 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
103 Element* summary = ensureUserAgentShadowRoot().getElementById(ShadowElem
entNames::detailsSummary()); | 127 Element* summary = ensureUserAgentShadowRoot().getElementById(ShadowElem
entNames::detailsSummary()); |
104 ASSERT(summary); | 128 ASSERT(summary); |
105 // FIXME: DetailsMarkerControl's RenderDetailsMarker has no concept of b
eing updated | 129 // FIXME: DetailsMarkerControl's RenderDetailsMarker has no concept of b
eing updated |
106 // without recreating it causing a repaint. Instead we should change it
so we can tell | 130 // without recreating it causing a repaint. Instead we should change it
so we can tell |
107 // it to toggle the open/closed triangle state and avoid reattaching the
entire summary. | 131 // it to toggle the open/closed triangle state and avoid reattaching the
entire summary. |
108 summary->lazyReattachIfAttached(); | 132 summary->lazyReattachIfAttached(); |
109 return; | 133 return; |
110 } | 134 } |
111 HTMLElement::parseAttribute(name, value); | 135 HTMLElement::parseAttribute(name, value); |
112 } | 136 } |
113 | 137 |
114 void HTMLDetailsElement::toggleOpen() | 138 void HTMLDetailsElement::toggleOpen() |
115 { | 139 { |
116 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom); | 140 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom); |
117 } | 141 } |
118 | 142 |
119 bool HTMLDetailsElement::isInteractiveContent() const | 143 bool HTMLDetailsElement::isInteractiveContent() const |
120 { | 144 { |
121 return true; | 145 return true; |
122 } | 146 } |
123 | 147 |
124 } | 148 } |
OLD | NEW |