Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1317)

Side by Side Diff: Source/core/html/HTMLDetailsElement.cpp

Issue 249573002: HTMLDetailsElement should fire a 'toggle' event (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 29 matching lines...) Expand all
40 40
41 PassRefPtr<HTMLDetailsElement> HTMLDetailsElement::create(Document& document) 41 PassRefPtr<HTMLDetailsElement> HTMLDetailsElement::create(Document& document)
42 { 42 {
43 RefPtr<HTMLDetailsElement> details = adoptRef(new HTMLDetailsElement(documen t)); 43 RefPtr<HTMLDetailsElement> details = adoptRef(new HTMLDetailsElement(documen t));
44 details->ensureUserAgentShadowRoot(); 44 details->ensureUserAgentShadowRoot();
45 return details.release(); 45 return details.release();
46 } 46 }
47 47
48 HTMLDetailsElement::HTMLDetailsElement(Document& document) 48 HTMLDetailsElement::HTMLDetailsElement(Document& document)
49 : HTMLElement(detailsTag, document) 49 : HTMLElement(detailsTag, document)
50 , m_toggleEventTimer(this, &HTMLDetailsElement::toggleEventTimerFired)
50 , m_isOpen(false) 51 , m_isOpen(false)
51 { 52 {
52 ScriptWrappable::init(this); 53 ScriptWrappable::init(this);
53 } 54 }
54 55
56 void HTMLDetailsElement::toggleEventTimerFired(Timer<HTMLDetailsElement> *)
57 {
58 dispatchEvent(Event::create(EventTypeNames::toggle));
59 }
60
61 void HTMLDetailsElement::dispatchToggleEventAsync()
62 {
63 if (m_toggleEventTimer.isActive())
64 m_toggleEventTimer.stop();
65 m_toggleEventTimer.startOneShot(0, FROM_HERE);
66 }
67
55 RenderObject* HTMLDetailsElement::createRenderer(RenderStyle*) 68 RenderObject* HTMLDetailsElement::createRenderer(RenderStyle*)
56 { 69 {
57 return new RenderBlockFlow(this); 70 return new RenderBlockFlow(this);
58 } 71 }
59 72
60 void HTMLDetailsElement::didAddUserAgentShadowRoot(ShadowRoot& root) 73 void HTMLDetailsElement::didAddUserAgentShadowRoot(ShadowRoot& root)
61 { 74 {
62 DEFINE_STATIC_LOCAL(const AtomicString, summarySelector, ("summary:first-of- type", AtomicString::ConstructFromLiteral)); 75 DEFINE_STATIC_LOCAL(const AtomicString, summarySelector, ("summary:first-of- type", AtomicString::ConstructFromLiteral));
63 76
64 RefPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::create(docum ent()); 77 RefPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::create(docum ent());
(...skipping 22 matching lines...) Expand all
87 return toElement(content->firstChild()); 100 return toElement(content->firstChild());
88 } 101 }
89 102
90 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, const AtomicS tring& value) 103 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, const AtomicS tring& value)
91 { 104 {
92 if (name == openAttr) { 105 if (name == openAttr) {
93 bool oldValue = m_isOpen; 106 bool oldValue = m_isOpen;
94 m_isOpen = !value.isNull(); 107 m_isOpen = !value.isNull();
95 if (m_isOpen == oldValue) 108 if (m_isOpen == oldValue)
96 return; 109 return;
110
111 // Dispatch toggle event asynchronously.
112 dispatchToggleEventAsync();
113
97 Element* content = ensureUserAgentShadowRoot().getElementById(ShadowElem entNames::detailsContent()); 114 Element* content = ensureUserAgentShadowRoot().getElementById(ShadowElem entNames::detailsContent());
98 ASSERT(content); 115 ASSERT(content);
99 if (m_isOpen) 116 if (m_isOpen)
100 content->removeInlineStyleProperty(CSSPropertyDisplay); 117 content->removeInlineStyleProperty(CSSPropertyDisplay);
101 else 118 else
102 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); 119 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
103 Element* summary = ensureUserAgentShadowRoot().getElementById(ShadowElem entNames::detailsSummary()); 120 Element* summary = ensureUserAgentShadowRoot().getElementById(ShadowElem entNames::detailsSummary());
104 ASSERT(summary); 121 ASSERT(summary);
105 // FIXME: DetailsMarkerControl's RenderDetailsMarker has no concept of b eing updated 122 // 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 123 // 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. 124 // it to toggle the open/closed triangle state and avoid reattaching the entire summary.
108 summary->lazyReattachIfAttached(); 125 summary->lazyReattachIfAttached();
109 return; 126 return;
110 } 127 }
111 HTMLElement::parseAttribute(name, value); 128 HTMLElement::parseAttribute(name, value);
112 } 129 }
113 130
114 void HTMLDetailsElement::toggleOpen() 131 void HTMLDetailsElement::toggleOpen()
115 { 132 {
116 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom); 133 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom);
117 } 134 }
118 135
119 bool HTMLDetailsElement::isInteractiveContent() const 136 bool HTMLDetailsElement::isInteractiveContent() const
120 { 137 {
121 return true; 138 return true;
122 } 139 }
123 140
124 } 141 }
OLDNEW
« LayoutTests/fast/html/details-open-toggle-event.html ('K') | « Source/core/html/HTMLDetailsElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698