| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 static DetailsEventSender& detailsToggleEventSender() | 46 static DetailsEventSender& detailsToggleEventSender() |
| 47 { | 47 { |
| 48 DEFINE_STATIC_LOCAL(DetailsEventSender, sharedToggleEventSender, (EventTypeN
ames::toggle)); | 48 DEFINE_STATIC_LOCAL(DetailsEventSender, sharedToggleEventSender, (EventTypeN
ames::toggle)); |
| 49 return sharedToggleEventSender; | 49 return sharedToggleEventSender; |
| 50 } | 50 } |
| 51 | 51 |
| 52 PassRefPtrWillBeRawPtr<HTMLDetailsElement> HTMLDetailsElement::create(Document&
document) | 52 PassRefPtrWillBeRawPtr<HTMLDetailsElement> HTMLDetailsElement::create(Document&
document) |
| 53 { | 53 { |
| 54 RefPtrWillBeRawPtr<HTMLDetailsElement> details = adoptRefWillBeNoop(new HTML
DetailsElement(document)); | 54 RefPtrWillBeRawPtr<HTMLDetailsElement> details = adoptRefWillBeNoop(new HTML
DetailsElement(document)); |
| 55 details->ensureUserAgentShadowRoot(); | 55 details->ensureClosedShadowRoot(); |
| 56 return details.release(); | 56 return details.release(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 HTMLDetailsElement::HTMLDetailsElement(Document& document) | 59 HTMLDetailsElement::HTMLDetailsElement(Document& document) |
| 60 : HTMLElement(detailsTag, document) | 60 : HTMLElement(detailsTag, document) |
| 61 , m_isOpen(false) | 61 , m_isOpen(false) |
| 62 { | 62 { |
| 63 UseCounter::count(document, UseCounter::DetailsElement); | 63 UseCounter::count(document, UseCounter::DetailsElement); |
| 64 } | 64 } |
| 65 | 65 |
| 66 HTMLDetailsElement::~HTMLDetailsElement() | 66 HTMLDetailsElement::~HTMLDetailsElement() |
| 67 { | 67 { |
| 68 detailsToggleEventSender().cancelEvent(this); | 68 detailsToggleEventSender().cancelEvent(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void HTMLDetailsElement::dispatchPendingEvent(DetailsEventSender* eventSender) | 71 void HTMLDetailsElement::dispatchPendingEvent(DetailsEventSender* eventSender) |
| 72 { | 72 { |
| 73 ASSERT_UNUSED(eventSender, eventSender == &detailsToggleEventSender()); | 73 ASSERT_UNUSED(eventSender, eventSender == &detailsToggleEventSender()); |
| 74 dispatchEvent(Event::create(EventTypeNames::toggle)); | 74 dispatchEvent(Event::create(EventTypeNames::toggle)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 LayoutObject* HTMLDetailsElement::createRenderer(const LayoutStyle&) | 78 LayoutObject* HTMLDetailsElement::createRenderer(const LayoutStyle&) |
| 79 { | 79 { |
| 80 return new RenderBlockFlow(this); | 80 return new RenderBlockFlow(this); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void HTMLDetailsElement::didAddUserAgentShadowRoot(ShadowRoot& root) | 83 void HTMLDetailsElement::didAddClosedShadowRoot(ShadowRoot& root) |
| 84 { | 84 { |
| 85 DEFINE_STATIC_LOCAL(const AtomicString, summarySelector, ("summary:first-of-
type", AtomicString::ConstructFromLiteral)); | 85 DEFINE_STATIC_LOCAL(const AtomicString, summarySelector, ("summary:first-of-
type", AtomicString::ConstructFromLiteral)); |
| 86 | 86 |
| 87 RefPtrWillBeRawPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::
create(document()); | 87 RefPtrWillBeRawPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::
create(document()); |
| 88 defaultSummary->appendChild(Text::create(document(), locale().queryString(bl
ink::WebLocalizedString::DetailsLabel))); | 88 defaultSummary->appendChild(Text::create(document(), locale().queryString(bl
ink::WebLocalizedString::DetailsLabel))); |
| 89 | 89 |
| 90 RefPtrWillBeRawPtr<HTMLContentElement> summary = HTMLContentElement::create(
document()); | 90 RefPtrWillBeRawPtr<HTMLContentElement> summary = HTMLContentElement::create(
document()); |
| 91 summary->setIdAttribute(ShadowElementNames::detailsSummary()); | 91 summary->setIdAttribute(ShadowElementNames::detailsSummary()); |
| 92 summary->setAttribute(selectAttr, summarySelector); | 92 summary->setAttribute(selectAttr, summarySelector); |
| 93 summary->appendChild(defaultSummary); | 93 summary->appendChild(defaultSummary); |
| 94 root.appendChild(summary.release()); | 94 root.appendChild(summary.release()); |
| 95 | 95 |
| 96 RefPtrWillBeRawPtr<HTMLDivElement> content = HTMLDivElement::create(document
()); | 96 RefPtrWillBeRawPtr<HTMLDivElement> content = HTMLDivElement::create(document
()); |
| 97 content->setIdAttribute(ShadowElementNames::detailsContent()); | 97 content->setIdAttribute(ShadowElementNames::detailsContent()); |
| 98 content->appendChild(HTMLContentElement::create(document())); | 98 content->appendChild(HTMLContentElement::create(document())); |
| 99 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | 99 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
| 100 root.appendChild(content.release()); | 100 root.appendChild(content.release()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 Element* HTMLDetailsElement::findMainSummary() const | 103 Element* HTMLDetailsElement::findMainSummary() const |
| 104 { | 104 { |
| 105 if (HTMLSummaryElement* summary = Traversal<HTMLSummaryElement>::firstChild(
*this)) | 105 if (HTMLSummaryElement* summary = Traversal<HTMLSummaryElement>::firstChild(
*this)) |
| 106 return summary; | 106 return summary; |
| 107 | 107 |
| 108 HTMLContentElement* content = toHTMLContentElement(userAgentShadowRoot()->fi
rstChild()); | 108 HTMLContentElement* content = toHTMLContentElement(closedShadowRoot()->first
Child()); |
| 109 ASSERT(content->firstChild() && isHTMLSummaryElement(*content->firstChild())
); | 109 ASSERT(content->firstChild() && isHTMLSummaryElement(*content->firstChild())
); |
| 110 return toElement(content->firstChild()); | 110 return toElement(content->firstChild()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) | 113 void HTMLDetailsElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) |
| 114 { | 114 { |
| 115 if (name == openAttr) { | 115 if (name == openAttr) { |
| 116 bool oldValue = m_isOpen; | 116 bool oldValue = m_isOpen; |
| 117 m_isOpen = !value.isNull(); | 117 m_isOpen = !value.isNull(); |
| 118 if (m_isOpen == oldValue) | 118 if (m_isOpen == oldValue) |
| 119 return; | 119 return; |
| 120 | 120 |
| 121 // Dispatch toggle event asynchronously. | 121 // Dispatch toggle event asynchronously. |
| 122 detailsToggleEventSender().cancelEvent(this); | 122 detailsToggleEventSender().cancelEvent(this); |
| 123 detailsToggleEventSender().dispatchEventSoon(this); | 123 detailsToggleEventSender().dispatchEventSoon(this); |
| 124 | 124 |
| 125 Element* content = ensureUserAgentShadowRoot().getElementById(ShadowElem
entNames::detailsContent()); | 125 Element* content = ensureClosedShadowRoot().getElementById(ShadowElement
Names::detailsContent()); |
| 126 ASSERT(content); | 126 ASSERT(content); |
| 127 if (m_isOpen) | 127 if (m_isOpen) |
| 128 content->removeInlineStyleProperty(CSSPropertyDisplay); | 128 content->removeInlineStyleProperty(CSSPropertyDisplay); |
| 129 else | 129 else |
| 130 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | 130 content->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
| 131 | 131 |
| 132 // Invalidate the LayoutDetailsMarker in order to turn the arrow signify
ing if the | 132 // Invalidate the LayoutDetailsMarker in order to turn the arrow signify
ing if the |
| 133 // details element is open or closed. | 133 // details element is open or closed. |
| 134 Element* summary = findMainSummary(); | 134 Element* summary = findMainSummary(); |
| 135 ASSERT(summary); | 135 ASSERT(summary); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 147 { | 147 { |
| 148 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom); | 148 setAttribute(openAttr, m_isOpen ? nullAtom : emptyAtom); |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool HTMLDetailsElement::isInteractiveContent() const | 151 bool HTMLDetailsElement::isInteractiveContent() const |
| 152 { | 152 { |
| 153 return true; | 153 return true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 } | 156 } |
| OLD | NEW |