|
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, 2009, 2010 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 "HTMLFrameSetElement.h" |
|
26 |
|
27 #include "Attribute.h" |
|
28 #include "CSSPropertyNames.h" |
|
29 #include "Document.h" |
|
30 #include "Event.h" |
|
31 #include "EventNames.h" |
|
32 #include "HTMLNames.h" |
|
33 #include "Length.h" |
|
34 #include "MouseEvent.h" |
|
35 #include "RenderFrameSet.h" |
|
36 #include "ScriptEventListener.h" |
|
37 #include "Text.h" |
|
38 |
|
39 namespace WebCore { |
|
40 |
|
41 using namespace HTMLNames; |
|
42 |
|
43 HTMLFrameSetElement::HTMLFrameSetElement(const QualifiedName& tagName, Document* document) |
|
44 : HTMLElement(tagName, document) |
|
45 , m_totalRows(1) |
|
46 , m_totalCols(1) |
|
47 , m_border(6) |
|
48 , m_borderSet(false) |
|
49 , m_borderColorSet(false) |
|
50 , frameborder(true) |
|
51 , frameBorderSet(false) |
|
52 , noresize(false) |
|
53 { |
|
54 ASSERT(hasTagName(framesetTag)); |
|
55 } |
|
56 |
|
57 PassRefPtr<HTMLFrameSetElement> HTMLFrameSetElement::create(const QualifiedName& tagName, Document* document) |
|
58 { |
|
59 return adoptRef(new HTMLFrameSetElement(tagName, document)); |
|
60 } |
|
61 |
|
62 bool HTMLFrameSetElement::checkDTD(const Node* newChild) |
|
63 { |
|
64 // FIXME: Old code had adjacent double returns and seemed to want to do something with NOFRAMES (but didn't). |
|
65 // What is the correct behavior? |
|
66 if (newChild->isTextNode()) |
|
67 return static_cast<const Text*>(newChild)->containsOnlyWhitespace(); |
|
68 return newChild->hasTagName(framesetTag) || newChild->hasTagName(frameTag); |
|
69 } |
|
70 |
|
71 bool HTMLFrameSetElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const |
|
72 { |
|
73 if (attrName == bordercolorAttr) { |
|
74 result = eUniversal; |
|
75 return true; |
|
76 } |
|
77 |
|
78 return HTMLElement::mapToEntry(attrName, result); |
|
79 } |
|
80 |
|
81 void HTMLFrameSetElement::parseMappedAttribute(Attribute* attr) |
|
82 { |
|
83 if (attr->name() == rowsAttr) { |
|
84 if (!attr->isNull()) { |
|
85 m_rowLengths.set(newLengthArray(attr->value().string(), m_totalRows)); |
|
86 setNeedsStyleRecalc(); |
|
87 } |
|
88 } else if (attr->name() == colsAttr) { |
|
89 if (!attr->isNull()) { |
|
90 m_colLengths.set(newLengthArray(attr->value().string(), m_totalCols)); |
|
91 setNeedsStyleRecalc(); |
|
92 } |
|
93 } else if (attr->name() == frameborderAttr) { |
|
94 if (!attr->isNull()) { |
|
95 // false or "no" or "0".. |
|
96 if (attr->value().toInt() == 0) { |
|
97 frameborder = false; |
|
98 m_border = 0; |
|
99 } |
|
100 frameBorderSet = true; |
|
101 } else { |
|
102 frameborder = false; |
|
103 frameBorderSet = false; |
|
104 } |
|
105 } else if (attr->name() == noresizeAttr) { |
|
106 noresize = true; |
|
107 } else if (attr->name() == borderAttr) { |
|
108 if (!attr->isNull()) { |
|
109 m_border = attr->value().toInt(); |
|
110 if (!m_border) |
|
111 frameborder = false; |
|
112 m_borderSet = true; |
|
113 } else |
|
114 m_borderSet = false; |
|
115 } else if (attr->name() == bordercolorAttr) { |
|
116 m_borderColorSet = attr->decl(); |
|
117 if (!attr->decl() && !attr->isEmpty()) { |
|
118 addCSSColor(attr, CSSPropertyBorderColor, attr->value()); |
|
119 m_borderColorSet = true; |
|
120 } |
|
121 } else if (attr->name() == onloadAttr) |
|
122 document()->setWindowAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(document()->frame(), attr)); |
|
123 else if (attr->name() == onbeforeunloadAttr) |
|
124 document()->setWindowAttributeEventListener(eventNames().beforeunloadEvent, createAttributeEventListener(document()->frame(), attr)); |
|
125 else if (attr->name() == onunloadAttr) |
|
126 document()->setWindowAttributeEventListener(eventNames().unloadEvent, createAttributeEventListener(document()->frame(), attr)); |
|
127 else if (attr->name() == onblurAttr) |
|
128 document()->setWindowAttributeEventListener(eventNames().blurEvent, createAttributeEventListener(document()->frame(), attr)); |
|
129 else if (attr->name() == onfocusAttr) |
|
130 document()->setWindowAttributeEventListener(eventNames().focusEvent, createAttributeEventListener(document()->frame(), attr)); |
|
131 else if (attr->name() == onfocusinAttr) |
|
132 document()->setWindowAttributeEventListener(eventNames().focusinEvent, createAttributeEventListener(document()->frame(), attr)); |
|
133 else if (attr->name() == onfocusoutAttr) |
|
134 document()->setWindowAttributeEventListener(eventNames().focusoutEvent, createAttributeEventListener(document()->frame(), attr)); |
|
135 #if ENABLE(ORIENTATION_EVENTS) |
|
136 else if (attr->name() == onorientationchangeAttr) |
|
137 document()->setWindowAttributeEventListener(eventNames().orientationchangeEvent, createAttributeEventListener(document()->frame(), attr)); |
|
138 #endif |
|
139 else if (attr->name() == onhashchangeAttr) |
|
140 document()->setWindowAttributeEventListener(eventNames().hashchangeEvent, createAttributeEventListener(document()->frame(), attr)); |
|
141 else if (attr->name() == onresizeAttr) |
|
142 document()->setWindowAttributeEventListener(eventNames().resizeEvent, createAttributeEventListener(document()->frame(), attr)); |
|
143 else if (attr->name() == onscrollAttr) |
|
144 document()->setWindowAttributeEventListener(eventNames().scrollEvent, createAttributeEventListener(document()->frame(), attr)); |
|
145 else if (attr->name() == onstorageAttr) |
|
146 document()->setWindowAttributeEventListener(eventNames().storageEvent, createAttributeEventListener(document()->frame(), attr)); |
|
147 else if (attr->name() == ononlineAttr) |
|
148 document()->setWindowAttributeEventListener(eventNames().onlineEvent, createAttributeEventListener(document()->frame(), attr)); |
|
149 else if (attr->name() == onofflineAttr) |
|
150 document()->setWindowAttributeEventListener(eventNames().offlineEvent, createAttributeEventListener(document()->frame(), attr)); |
|
151 else if (attr->name() == onpopstateAttr) |
|
152 document()->setWindowAttributeEventListener(eventNames().popstateEvent, createAttributeEventListener(document()->frame(), attr)); |
|
153 else |
|
154 HTMLElement::parseMappedAttribute(attr); |
|
155 } |
|
156 |
|
157 bool HTMLFrameSetElement::rendererIsNeeded(RenderStyle *style) |
|
158 { |
|
159 // For compatibility, frames render even when display: none is set. |
|
160 // However, we delay creating a renderer until stylesheets have loaded. |
|
161 return style->isStyleAvailable(); |
|
162 } |
|
163 |
|
164 RenderObject *HTMLFrameSetElement::createRenderer(RenderArena *arena, RenderStyle *style) |
|
165 { |
|
166 if (style->contentData()) |
|
167 return RenderObject::createObject(this, style); |
|
168 |
|
169 return new (arena) RenderFrameSet(this); |
|
170 } |
|
171 |
|
172 void HTMLFrameSetElement::attach() |
|
173 { |
|
174 // Inherit default settings from parent frameset |
|
175 // FIXME: This is not dynamic. |
|
176 for (Node* node = parentNode(); node; node = node->parentNode()) { |
|
177 if (node->hasTagName(framesetTag)) { |
|
178 HTMLFrameSetElement* frameset = static_cast<HTMLFrameSetElement*>(node); |
|
179 if (!frameBorderSet) |
|
180 frameborder = frameset->hasFrameBorder(); |
|
181 if (frameborder) { |
|
182 if (!m_borderSet) |
|
183 m_border = frameset->border(); |
|
184 if (!m_borderColorSet) |
|
185 m_borderColorSet = frameset->hasBorderColor(); |
|
186 } |
|
187 if (!noresize) |
|
188 noresize = frameset->noResize(); |
|
189 break; |
|
190 } |
|
191 } |
|
192 |
|
193 HTMLElement::attach(); |
|
194 } |
|
195 |
|
196 void HTMLFrameSetElement::defaultEventHandler(Event* evt) |
|
197 { |
|
198 if (evt->isMouseEvent() && !noresize && renderer()) { |
|
199 if (toRenderFrameSet(renderer())->userResize(static_cast<MouseEvent*>(evt))) { |
|
200 evt->setDefaultHandled(); |
|
201 return; |
|
202 } |
|
203 } |
|
204 HTMLElement::defaultEventHandler(evt); |
|
205 } |
|
206 |
|
207 void HTMLFrameSetElement::recalcStyle(StyleChange ch) |
|
208 { |
|
209 if (needsStyleRecalc() && renderer()) { |
|
210 renderer()->setNeedsLayout(true); |
|
211 setNeedsStyleRecalc(NoStyleChange); |
|
212 } |
|
213 HTMLElement::recalcStyle(ch); |
|
214 } |
|
215 |
|
216 } // namespace WebCore |