Chromium Code Reviews| 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 "core/html/HTMLDetailsElement.h" | 21 #include "core/html/HTMLDetailsElement.h" |
| 22 | 22 |
| 23 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 23 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 24 #include "core/CSSPropertyNames.h" | 24 #include "core/CSSPropertyNames.h" |
| 25 #include "core/CSSValueKeywords.h" | 25 #include "core/CSSValueKeywords.h" |
| 26 #include "core/HTMLNames.h" | 26 #include "core/HTMLNames.h" |
| 27 #include "core/dom/ElementTraversal.h" | 27 #include "core/dom/ElementTraversal.h" |
| 28 #include "core/dom/TaskRunnerHelper.h" | |
| 28 #include "core/dom/Text.h" | 29 #include "core/dom/Text.h" |
| 29 #include "core/dom/shadow/ShadowRoot.h" | 30 #include "core/dom/shadow/ShadowRoot.h" |
| 30 #include "core/events/Event.h" | 31 #include "core/events/Event.h" |
| 31 #include "core/events/EventSender.h" | |
| 32 #include "core/frame/UseCounter.h" | 32 #include "core/frame/UseCounter.h" |
| 33 #include "core/html/HTMLContentElement.h" | 33 #include "core/html/HTMLContentElement.h" |
| 34 #include "core/html/HTMLDivElement.h" | 34 #include "core/html/HTMLDivElement.h" |
| 35 #include "core/html/HTMLSummaryElement.h" | 35 #include "core/html/HTMLSummaryElement.h" |
| 36 #include "core/html/shadow/DetailsMarkerControl.h" | 36 #include "core/html/shadow/DetailsMarkerControl.h" |
| 37 #include "core/html/shadow/ShadowElementNames.h" | 37 #include "core/html/shadow/ShadowElementNames.h" |
| 38 #include "core/layout/LayoutBlockFlow.h" | 38 #include "core/layout/LayoutBlockFlow.h" |
| 39 #include "platform/text/PlatformLocale.h" | 39 #include "platform/text/PlatformLocale.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 60 } | 60 } |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 DEFINE_INLINE_VIRTUAL_TRACE() { HTMLContentSelectFilter::trace(visitor); } | 64 DEFINE_INLINE_VIRTUAL_TRACE() { HTMLContentSelectFilter::trace(visitor); } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 FirstSummarySelectFilter() {} | 67 FirstSummarySelectFilter() {} |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 static DetailsEventSender& detailsToggleEventSender() { | |
| 71 DEFINE_STATIC_LOCAL(DetailsEventSender, sharedToggleEventSender, | |
| 72 (DetailsEventSender::create(EventTypeNames::toggle))); | |
| 73 return sharedToggleEventSender; | |
| 74 } | |
| 75 | |
| 76 HTMLDetailsElement* HTMLDetailsElement::create(Document& document) { | 70 HTMLDetailsElement* HTMLDetailsElement::create(Document& document) { |
| 77 HTMLDetailsElement* details = new HTMLDetailsElement(document); | 71 HTMLDetailsElement* details = new HTMLDetailsElement(document); |
| 78 details->ensureUserAgentShadowRoot(); | 72 details->ensureUserAgentShadowRoot(); |
| 79 return details; | 73 return details; |
| 80 } | 74 } |
| 81 | 75 |
| 82 HTMLDetailsElement::HTMLDetailsElement(Document& document) | 76 HTMLDetailsElement::HTMLDetailsElement(Document& document) |
| 83 : HTMLElement(detailsTag, document), m_isOpen(false) { | 77 : HTMLElement(detailsTag, document), m_isOpen(false) { |
| 84 UseCounter::count(document, UseCounter::DetailsElement); | 78 UseCounter::count(document, UseCounter::DetailsElement); |
| 85 } | 79 } |
| 86 | 80 |
| 87 HTMLDetailsElement::~HTMLDetailsElement() {} | 81 HTMLDetailsElement::~HTMLDetailsElement() {} |
| 88 | 82 |
| 89 void HTMLDetailsElement::dispatchPendingEvent(DetailsEventSender* eventSender) { | 83 void HTMLDetailsElement::dispatchPendingEvent() { |
| 90 DCHECK_EQ(eventSender, &detailsToggleEventSender()); | |
| 91 dispatchEvent(Event::create(EventTypeNames::toggle)); | 84 dispatchEvent(Event::create(EventTypeNames::toggle)); |
| 92 } | 85 } |
| 93 | 86 |
| 94 LayoutObject* HTMLDetailsElement::createLayoutObject(const ComputedStyle&) { | 87 LayoutObject* HTMLDetailsElement::createLayoutObject(const ComputedStyle&) { |
| 95 return new LayoutBlockFlow(this); | 88 return new LayoutBlockFlow(this); |
| 96 } | 89 } |
| 97 | 90 |
| 98 void HTMLDetailsElement::didAddUserAgentShadowRoot(ShadowRoot& root) { | 91 void HTMLDetailsElement::didAddUserAgentShadowRoot(ShadowRoot& root) { |
| 99 HTMLSummaryElement* defaultSummary = HTMLSummaryElement::create(document()); | 92 HTMLSummaryElement* defaultSummary = HTMLSummaryElement::create(document()); |
| 100 defaultSummary->appendChild(Text::create( | 93 defaultSummary->appendChild(Text::create( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 128 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, | 121 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, |
| 129 const AtomicString& oldValue, | 122 const AtomicString& oldValue, |
| 130 const AtomicString& value) { | 123 const AtomicString& value) { |
| 131 if (name == openAttr) { | 124 if (name == openAttr) { |
| 132 bool oldValue = m_isOpen; | 125 bool oldValue = m_isOpen; |
| 133 m_isOpen = !value.isNull(); | 126 m_isOpen = !value.isNull(); |
| 134 if (m_isOpen == oldValue) | 127 if (m_isOpen == oldValue) |
| 135 return; | 128 return; |
| 136 | 129 |
| 137 // Dispatch toggle event asynchronously. | 130 // Dispatch toggle event asynchronously. |
| 138 detailsToggleEventSender().cancelEvent(this); | 131 m_pendingEvent = |
|
hiroshige
2016/11/07 09:24:55
Here previous event is canceled (because |m_pendin
haraken
2016/11/07 09:51:01
Hmm, we need to keep holding m_pendingEvent in ord
| |
| 139 detailsToggleEventSender().dispatchEventSoon(this); | 132 TaskRunnerHelper::get(TaskType::DOMManipulation, &document()) |
| 133 ->postCancellableTask( | |
| 134 BLINK_FROM_HERE, | |
| 135 WTF::bind(&HTMLDetailsElement::dispatchPendingEvent, | |
| 136 wrapPersistent(this))); | |
| 140 | 137 |
| 141 Element* content = ensureUserAgentShadowRoot().getElementById( | 138 Element* content = ensureUserAgentShadowRoot().getElementById( |
| 142 ShadowElementNames::detailsContent()); | 139 ShadowElementNames::detailsContent()); |
| 143 DCHECK(content); | 140 DCHECK(content); |
| 144 if (m_isOpen) | 141 if (m_isOpen) |
| 145 content->removeInlineStyleProperty(CSSPropertyDisplay); | 142 content->removeInlineStyleProperty(CSSPropertyDisplay); |
| 146 else | 143 else |
| 147 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | 144 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
| 148 | 145 |
| 149 // Invalidate the LayoutDetailsMarker in order to turn the arrow signifying | 146 // Invalidate the LayoutDetailsMarker in order to turn the arrow signifying |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 162 | 159 |
| 163 void HTMLDetailsElement::toggleOpen() { | 160 void HTMLDetailsElement::toggleOpen() { |
| 164 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom); | 161 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom); |
| 165 } | 162 } |
| 166 | 163 |
| 167 bool HTMLDetailsElement::isInteractiveContent() const { | 164 bool HTMLDetailsElement::isInteractiveContent() const { |
| 168 return true; | 165 return true; |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace blink | 168 } // namespace blink |
| OLD | NEW |