• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Stefan Schimanski (1Stein@gmx.de)
5  * Copyright (C) 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
6  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #include "config.h"
25 #include "HTMLAppletElement.h"
26 
27 #include "HTMLDocument.h"
28 #include "HTMLNames.h"
29 #include "MappedAttribute.h"
30 #include "RenderApplet.h"
31 #include "Settings.h"
32 
33 namespace WebCore {
34 
35 using namespace HTMLNames;
36 
HTMLAppletElement(const QualifiedName & tagName,Document * doc)37 HTMLAppletElement::HTMLAppletElement(const QualifiedName& tagName, Document* doc)
38     : HTMLPlugInElement(tagName, doc)
39 {
40     ASSERT(hasTagName(appletTag));
41 }
42 
parseMappedAttribute(MappedAttribute * attr)43 void HTMLAppletElement::parseMappedAttribute(MappedAttribute* attr)
44 {
45     if (attr->name() == altAttr ||
46         attr->name() == archiveAttr ||
47         attr->name() == codeAttr ||
48         attr->name() == codebaseAttr ||
49         attr->name() == mayscriptAttr ||
50         attr->name() == objectAttr) {
51         // Do nothing.
52     } else if (attr->name() == nameAttr) {
53         const AtomicString& newName = attr->value();
54         if (inDocument() && document()->isHTMLDocument()) {
55             HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
56             document->removeNamedItem(m_name);
57             document->addNamedItem(newName);
58         }
59         m_name = newName;
60     } else if (attr->name() == idAttr) {
61         const AtomicString& newId = attr->value();
62         if (inDocument() && document()->isHTMLDocument()) {
63             HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
64             document->removeExtraNamedItem(m_id);
65             document->addExtraNamedItem(newId);
66         }
67         m_id = newId;
68         // also call superclass
69         HTMLPlugInElement::parseMappedAttribute(attr);
70     } else
71         HTMLPlugInElement::parseMappedAttribute(attr);
72 }
73 
insertedIntoDocument()74 void HTMLAppletElement::insertedIntoDocument()
75 {
76     if (document()->isHTMLDocument()) {
77         HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
78         document->addNamedItem(m_name);
79         document->addExtraNamedItem(m_id);
80     }
81 
82     HTMLPlugInElement::insertedIntoDocument();
83 }
84 
removedFromDocument()85 void HTMLAppletElement::removedFromDocument()
86 {
87     if (document()->isHTMLDocument()) {
88         HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
89         document->removeNamedItem(m_name);
90         document->removeExtraNamedItem(m_id);
91     }
92 
93     HTMLPlugInElement::removedFromDocument();
94 }
95 
rendererIsNeeded(RenderStyle * style)96 bool HTMLAppletElement::rendererIsNeeded(RenderStyle* style)
97 {
98     if (getAttribute(codeAttr).isNull())
99         return false;
100 
101     return HTMLPlugInElement::rendererIsNeeded(style);
102 }
103 
createRenderer(RenderArena *,RenderStyle * style)104 RenderObject* HTMLAppletElement::createRenderer(RenderArena*, RenderStyle* style)
105 {
106     Settings* settings = document()->settings();
107 
108     if (settings && settings->isJavaEnabled()) {
109         HashMap<String, String> args;
110 
111         args.set("code", getAttribute(codeAttr));
112 
113         const AtomicString& codeBase = getAttribute(codebaseAttr);
114         if (!codeBase.isNull())
115             args.set("codeBase", codeBase);
116 
117         const AtomicString& name = getAttribute(document()->isHTMLDocument() ? nameAttr : idAttr);
118         if (!name.isNull())
119             args.set("name", name);
120         const AtomicString& archive = getAttribute(archiveAttr);
121         if (!archive.isNull())
122             args.set("archive", archive);
123 
124         args.set("baseURL", document()->baseURL().string());
125 
126         const AtomicString& mayScript = getAttribute(mayscriptAttr);
127         if (!mayScript.isNull())
128             args.set("mayScript", mayScript);
129 
130         // Other arguments (from <PARAM> tags) are added later.
131 
132         return new (document()->renderArena()) RenderApplet(this, args);
133     }
134 
135     return RenderObject::createObject(this, style);
136 }
137 
renderWidgetForJSBindings() const138 RenderWidget* HTMLAppletElement::renderWidgetForJSBindings() const
139 {
140     Settings* settings = document()->settings();
141     if (!settings || !settings->isJavaEnabled())
142         return 0;
143 
144     RenderApplet* applet = toRenderApplet(renderer());
145     if (applet)
146         applet->createWidgetIfNecessary();
147 
148     return applet;
149 }
150 
finishParsingChildren()151 void HTMLAppletElement::finishParsingChildren()
152 {
153     // The parser just reached </applet>, so all the params are available now.
154     HTMLPlugInElement::finishParsingChildren();
155     if (renderer())
156         renderer()->setNeedsLayout(true); // This will cause it to create its widget & the Java applet
157 }
158 
hspace() const159 String HTMLAppletElement::hspace() const
160 {
161     return getAttribute(hspaceAttr);
162 }
163 
setHspace(const String & value)164 void HTMLAppletElement::setHspace(const String &value)
165 {
166     setAttribute(hspaceAttr, value);
167 }
168 
vspace() const169 String HTMLAppletElement::vspace() const
170 {
171     return getAttribute(vspaceAttr);
172 }
173 
setVspace(const String & value)174 void HTMLAppletElement::setVspace(const String &value)
175 {
176     setAttribute(vspaceAttr, value);
177 }
178 
179 }
180