2 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
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
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "HTMLSummaryElement.h"
26 #include "DetailsMarkerControl.h"
27 #include "HTMLDetailsElement.h"
28 #include "HTMLNames.h"
29 #include "MouseEvent.h"
30 #include "PlatformMouseEvent.h"
31 #include "RenderSummary.h"
32 #include "ShadowContentElement.h"
34 #include "ShadowRoot.h"
38 using namespace HTMLNames;
40 class SummaryContentElement : public ShadowContentElement {
42 static PassRefPtr<SummaryContentElement> create(Document*);
45 SummaryContentElement(Document* document)
46 : ShadowContentElement(HTMLNames::divTag, document)
51 PassRefPtr<SummaryContentElement> SummaryContentElement::create(Document* document)
53 return adoptRef(new SummaryContentElement(document));
56 PassRefPtr<HTMLSummaryElement> HTMLSummaryElement::create(const QualifiedName& tagName, Document* document)
58 RefPtr<HTMLSummaryElement> result = adoptRef(new HTMLSummaryElement(tagName, document));
59 result->createShadowSubtree();
63 HTMLSummaryElement::HTMLSummaryElement(const QualifiedName& tagName, Document* document)
64 : HTMLElement(tagName, document)
66 ASSERT(hasTagName(summaryTag));
69 RenderObject* HTMLSummaryElement::createRenderer(RenderArena* arena, RenderStyle*)
71 return new (arena) RenderSummary(this);
74 void HTMLSummaryElement::createShadowSubtree()
77 ensureShadowRoot()->appendChild(DetailsMarkerControl::create(document()), ec, true);
78 ensureShadowRoot()->appendChild(SummaryContentElement::create(document()), ec, true);
81 HTMLDetailsElement* HTMLSummaryElement::detailsElement() const
83 Node* mayDetails = const_cast<HTMLSummaryElement*>(this)->parentNodeForRenderingAndStyle();
84 if (!mayDetails || !mayDetails->hasTagName(detailsTag))
86 return static_cast<HTMLDetailsElement*>(mayDetails);
89 bool HTMLSummaryElement::isMainSummary() const
91 if (HTMLDetailsElement* details = detailsElement())
92 return details->mainSummary() == this;
96 void HTMLSummaryElement::defaultEventHandler(Event* event)
98 HTMLElement::defaultEventHandler(event);
99 if (!isMainSummary() || !renderer() || !renderer()->isSummary() || !event->isMouseEvent() || event->type() != eventNames().clickEvent || event->defaultHandled())
102 MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
103 if (mouseEvent->button() != LeftButton)
106 if (HTMLDetailsElement* details = detailsElement())
107 details->toggleOpen();
108 event->setDefaultHandled();