• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
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.
8  *
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.
13  *
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.
18  *
19  */
20 
21 #include "config.h"
22 #include "HTMLSummaryElement.h"
23 
24 #include "DetailsMarkerControl.h"
25 #include "HTMLDetailsElement.h"
26 #include "HTMLNames.h"
27 #include "MouseEvent.h"
28 #include "PlatformMouseEvent.h"
29 #include "RenderSummary.h"
30 
31 namespace WebCore {
32 
33 using namespace HTMLNames;
34 
create(const QualifiedName & tagName,Document * document)35 PassRefPtr<HTMLSummaryElement> HTMLSummaryElement::create(const QualifiedName& tagName, Document* document)
36 {
37     RefPtr<HTMLSummaryElement> result = adoptRef(new HTMLSummaryElement(tagName, document));
38     result->createShadowSubtree();
39     return result;
40 }
41 
HTMLSummaryElement(const QualifiedName & tagName,Document * document)42 HTMLSummaryElement::HTMLSummaryElement(const QualifiedName& tagName, Document* document)
43     : HTMLElement(tagName, document)
44 {
45     ASSERT(hasTagName(summaryTag));
46 }
47 
createRenderer(RenderArena * arena,RenderStyle *)48 RenderObject* HTMLSummaryElement::createRenderer(RenderArena* arena, RenderStyle*)
49 {
50     return new (arena) RenderSummary(this);
51 }
52 
createShadowSubtree()53 void HTMLSummaryElement::createShadowSubtree()
54 {
55     ExceptionCode ec = 0;
56     ensureShadowRoot()->appendChild(DetailsMarkerControl::create(document()), ec, true);
57 }
58 
detailsElement() const59 HTMLDetailsElement* HTMLSummaryElement::detailsElement() const
60 {
61     Element* mayDetails = toElement(parentNodeForRenderingAndStyle());
62     if (!mayDetails || !mayDetails->hasTagName(detailsTag))
63         return 0;
64     return static_cast<HTMLDetailsElement*>(mayDetails);
65 }
66 
isMainSummary() const67 bool HTMLSummaryElement::isMainSummary() const
68 {
69     if (HTMLDetailsElement* details = detailsElement())
70         return details->mainSummary() == this;
71     return 0;
72 }
73 
defaultEventHandler(Event * event)74 void HTMLSummaryElement::defaultEventHandler(Event* event)
75 {
76     HTMLElement::defaultEventHandler(event);
77     if (!isMainSummary() || !renderer() || !renderer()->isSummary() || !event->isMouseEvent() || event->type() != eventNames().clickEvent || event->defaultHandled())
78         return;
79 
80     MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
81     if (mouseEvent->button() != LeftButton)
82         return;
83 
84     if (HTMLDetailsElement* details = detailsElement())
85         details->toggleOpen();
86     event->setDefaultHandled();
87 }
88 
89 }
90