• 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 Simon Hausmann (hausmann@kde.org)
5  *           (C) 2001 Dirk Mueller (mueller@kde.org)
6  * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
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 "HTMLIFrameElement.h"
26 
27 #include "CSSPropertyNames.h"
28 #include "Frame.h"
29 #include "HTMLDocument.h"
30 #include "HTMLNames.h"
31 #include "MappedAttribute.h"
32 #include "RenderPartObject.h"
33 
34 namespace WebCore {
35 
36 using namespace HTMLNames;
37 
HTMLIFrameElement(const QualifiedName & tagName,Document * document)38 HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
39     : HTMLFrameElementBase(tagName, document)
40 {
41     ASSERT(hasTagName(iframeTag));
42 }
43 
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const44 bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
45 {
46     if (attrName == widthAttr || attrName == heightAttr) {
47         result = eUniversal;
48         return false;
49     }
50 
51     if (attrName == alignAttr) {
52         result = eReplaced; // Share with <img> since the alignment behavior is the same.
53         return false;
54     }
55 
56     if (attrName == frameborderAttr) {
57         result = eReplaced;
58         return false;
59     }
60 
61     return HTMLFrameElementBase::mapToEntry(attrName, result);
62 }
63 
parseMappedAttribute(MappedAttribute * attr)64 void HTMLIFrameElement::parseMappedAttribute(MappedAttribute* attr)
65 {
66     if (attr->name() == widthAttr)
67         addCSSLength(attr, CSSPropertyWidth, attr->value());
68     else if (attr->name() == heightAttr)
69         addCSSLength(attr, CSSPropertyHeight, attr->value());
70     else if (attr->name() == alignAttr)
71         addHTMLAlignment(attr);
72     else if (attr->name() == nameAttr) {
73         const AtomicString& newName = attr->value();
74         if (inDocument() && document()->isHTMLDocument()) {
75             HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
76             document->removeExtraNamedItem(m_name);
77             document->addExtraNamedItem(newName);
78         }
79         m_name = newName;
80     } else if (attr->name() == frameborderAttr) {
81         // Frame border doesn't really match the HTML4 spec definition for iframes.  It simply adds
82         // a presentational hint that the border should be off if set to zero.
83         if (!attr->isNull() && !attr->value().toInt())
84             // Add a rule that nulls out our border width.
85             addCSSLength(attr, CSSPropertyBorderWidth, "0");
86     } else
87         HTMLFrameElementBase::parseMappedAttribute(attr);
88 }
89 
rendererIsNeeded(RenderStyle * style)90 bool HTMLIFrameElement::rendererIsNeeded(RenderStyle* style)
91 {
92     return isURLAllowed(m_URL) && style->display() != NONE;
93 }
94 
createRenderer(RenderArena * arena,RenderStyle *)95 RenderObject* HTMLIFrameElement::createRenderer(RenderArena* arena, RenderStyle*)
96 {
97     return new (arena) RenderPartObject(this);
98 }
99 
insertedIntoDocument()100 void HTMLIFrameElement::insertedIntoDocument()
101 {
102     if (document()->isHTMLDocument())
103         static_cast<HTMLDocument*>(document())->addExtraNamedItem(m_name);
104 
105     HTMLFrameElementBase::insertedIntoDocument();
106 }
107 
removedFromDocument()108 void HTMLIFrameElement::removedFromDocument()
109 {
110     if (document()->isHTMLDocument())
111         static_cast<HTMLDocument*>(document())->removeExtraNamedItem(m_name);
112 
113     HTMLFrameElementBase::removedFromDocument();
114 }
115 
attach()116 void HTMLIFrameElement::attach()
117 {
118     HTMLFrameElementBase::attach();
119 
120     if (RenderPartObject* renderPartObject = toRenderPartObject(renderer()))
121         renderPartObject->updateWidget(false);
122 }
123 
isURLAttribute(Attribute * attr) const124 bool HTMLIFrameElement::isURLAttribute(Attribute* attr) const
125 {
126     return attr->name() == srcAttr;
127 }
128 
align() const129 String HTMLIFrameElement::align() const
130 {
131     return getAttribute(alignAttr);
132 }
133 
setAlign(const String & value)134 void HTMLIFrameElement::setAlign(const String &value)
135 {
136     setAttribute(alignAttr, value);
137 }
138 
height() const139 String HTMLIFrameElement::height() const
140 {
141     return getAttribute(heightAttr);
142 }
143 
setHeight(const String & value)144 void HTMLIFrameElement::setHeight(const String &value)
145 {
146     setAttribute(heightAttr, value);
147 }
148 
width() const149 String HTMLIFrameElement::width() const
150 {
151     return getAttribute(widthAttr);
152 }
153 
setWidth(const String & value)154 void HTMLIFrameElement::setWidth(const String &value)
155 {
156     setAttribute(widthAttr, value);
157 }
158 
159 }
160