blob: 042bb64691035d41b1e910b4440e0596734365f3 [file] [log] [blame]
darin@apple.com1f643c72010-05-30 21:22:42 +00001/*
eseidel409f4302006-05-12 22:56:41 +00002 * 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)
darin@apple.com1f643c72010-05-30 21:22:42 +00006 * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved.
eseidel409f4302006-05-12 22:56:41 +00007 *
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
ddkilzerc8eccec2007-09-26 02:29:57 +000020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
eseidel409f4302006-05-12 22:56:41 +000022 */
weinig681a5172006-06-19 22:58:36 +000023
eseidel409f4302006-05-12 22:56:41 +000024#include "config.h"
25#include "HTMLFrameSetElement.h"
26
weinig@apple.comc3608932010-05-19 17:48:06 +000027#include "Attribute.h"
hyatt0fa2fbc2007-03-18 09:21:21 +000028#include "CSSPropertyNames.h"
eseidel409f4302006-05-12 22:56:41 +000029#include "Document.h"
weinig681a5172006-06-19 22:58:36 +000030#include "Event.h"
eseidel409f4302006-05-12 22:56:41 +000031#include "EventNames.h"
ap@apple.com43af8a82010-10-29 17:23:55 +000032#include "Frame.h"
abarth@webkit.org401a3792013-03-03 10:12:59 +000033#include "FrameLoader.h"
ap@apple.com43af8a82010-10-29 17:23:55 +000034#include "FrameLoaderClient.h"
eseidel409f4302006-05-12 22:56:41 +000035#include "HTMLNames.h"
36#include "Length.h"
weinig681a5172006-06-19 22:58:36 +000037#include "MouseEvent.h"
eseidel409f4302006-05-12 22:56:41 +000038#include "RenderFrameSet.h"
weinig@apple.comc3608932010-05-19 17:48:06 +000039#include "ScriptEventListener.h"
hyatt4f25e172007-05-24 05:23:43 +000040#include "Text.h"
eseidel409f4302006-05-12 22:56:41 +000041
42namespace WebCore {
43
eseidel409f4302006-05-12 22:56:41 +000044using namespace HTMLNames;
45
darin@apple.com1f643c72010-05-30 21:22:42 +000046HTMLFrameSetElement::HTMLFrameSetElement(const QualifiedName& tagName, Document* document)
47 : HTMLElement(tagName, document)
eseidel409f4302006-05-12 22:56:41 +000048 , m_totalRows(1)
49 , m_totalCols(1)
hyatt0fa2fbc2007-03-18 09:21:21 +000050 , m_border(6)
51 , m_borderSet(false)
52 , m_borderColorSet(false)
dbates@webkit.org05c12fa2011-03-23 17:58:29 +000053 , m_frameborder(true)
54 , m_frameborderSet(false)
55 , m_noresize(false)
eseidel409f4302006-05-12 22:56:41 +000056{
jchaffraix@webkit.org74dae402008-12-01 23:07:04 +000057 ASSERT(hasTagName(framesetTag));
antti@apple.com0f2ac5b2013-08-18 20:01:20 +000058 setHasCustomStyleResolveCallbacks();
eseidel409f4302006-05-12 22:56:41 +000059}
60
darin@apple.com1f643c72010-05-30 21:22:42 +000061PassRefPtr<HTMLFrameSetElement> HTMLFrameSetElement::create(const QualifiedName& tagName, Document* document)
eseidel409f4302006-05-12 22:56:41 +000062{
darin@apple.comf190b3d2010-06-16 23:07:32 +000063 return adoptRef(new HTMLFrameSetElement(tagName, document));
eseidel409f4302006-05-12 22:56:41 +000064}
65
kling@webkit.org44bc0dd2012-02-28 22:21:02 +000066bool HTMLFrameSetElement::isPresentationAttribute(const QualifiedName& name) const
kling@webkit.org11f25562012-02-13 10:36:55 +000067{
kling@webkit.org44bc0dd2012-02-28 22:21:02 +000068 if (name == bordercolorAttr)
kling@webkit.org11f25562012-02-13 10:36:55 +000069 return true;
kling@webkit.org44bc0dd2012-02-28 22:21:02 +000070 return HTMLElement::isPresentationAttribute(name);
kling@webkit.org11f25562012-02-13 10:36:55 +000071}
72
akling@apple.comb75eeea2013-02-23 17:57:50 +000073void HTMLFrameSetElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
kling@webkit.org8b0e8432012-02-11 19:29:49 +000074{
akling@apple.comb75eeea2013-02-23 17:57:50 +000075 if (name == bordercolorAttr)
76 addHTMLColorToStyle(style, CSSPropertyBorderColor, value);
kling@webkit.org8b0e8432012-02-11 19:29:49 +000077 else
akling@apple.comb75eeea2013-02-23 17:57:50 +000078 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
kling@webkit.org8b0e8432012-02-11 19:29:49 +000079}
80
akling@apple.com43e9d042012-11-18 16:55:06 +000081void HTMLFrameSetElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
eseidel409f4302006-05-12 22:56:41 +000082{
akling@apple.com43e9d042012-11-18 16:55:06 +000083 if (name == rowsAttr) {
84 if (!value.isNull()) {
85 m_rowLengths = newLengthArray(value.string(), m_totalRows);
hyatt@apple.comf6d72f32009-04-10 00:05:02 +000086 setNeedsStyleRecalc();
eseidel409f4302006-05-12 22:56:41 +000087 }
akling@apple.com43e9d042012-11-18 16:55:06 +000088 } else if (name == colsAttr) {
89 if (!value.isNull()) {
90 m_colLengths = newLengthArray(value.string(), m_totalCols);
hyatt@apple.comf6d72f32009-04-10 00:05:02 +000091 setNeedsStyleRecalc();
eseidel409f4302006-05-12 22:56:41 +000092 }
akling@apple.com43e9d042012-11-18 16:55:06 +000093 } else if (name == frameborderAttr) {
94 if (!value.isNull()) {
commit-queue@webkit.org4ec3bba2012-06-29 00:55:47 +000095 if (equalIgnoringCase(value, "no") || equalIgnoringCase(value, "0")) {
dbates@webkit.org05c12fa2011-03-23 17:58:29 +000096 m_frameborder = false;
commit-queue@webkit.org4ec3bba2012-06-29 00:55:47 +000097 m_frameborderSet = true;
98 } else if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "1")) {
99 m_frameborderSet = true;
hyatt0fa2fbc2007-03-18 09:21:21 +0000100 }
hyatt0fa2fbc2007-03-18 09:21:21 +0000101 } else {
dbates@webkit.org05c12fa2011-03-23 17:58:29 +0000102 m_frameborder = false;
103 m_frameborderSet = false;
eseidel409f4302006-05-12 22:56:41 +0000104 }
akling@apple.com43e9d042012-11-18 16:55:06 +0000105 } else if (name == noresizeAttr) {
dbates@webkit.org05c12fa2011-03-23 17:58:29 +0000106 m_noresize = true;
akling@apple.com43e9d042012-11-18 16:55:06 +0000107 } else if (name == borderAttr) {
108 if (!value.isNull()) {
109 m_border = value.toInt();
hyatt0fa2fbc2007-03-18 09:21:21 +0000110 m_borderSet = true;
111 } else
112 m_borderSet = false;
akling@apple.com43e9d042012-11-18 16:55:06 +0000113 } else if (name == bordercolorAttr)
114 m_borderColorSet = !value.isEmpty();
115 else if (name == onloadAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000116 document().setWindowAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000117 else if (name == onbeforeunloadAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000118 document().setWindowAttributeEventListener(eventNames().beforeunloadEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000119 else if (name == onunloadAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000120 document().setWindowAttributeEventListener(eventNames().unloadEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000121 else if (name == onblurAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000122 document().setWindowAttributeEventListener(eventNames().blurEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000123 else if (name == onfocusAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000124 document().setWindowAttributeEventListener(eventNames().focusEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000125 else if (name == onfocusinAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000126 document().setWindowAttributeEventListener(eventNames().focusinEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000127 else if (name == onfocusoutAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000128 document().setWindowAttributeEventListener(eventNames().focusoutEvent, createAttributeEventListener(document().frame(), name, value));
bolsinga@apple.comdcfc7892009-09-21 23:10:30 +0000129#if ENABLE(ORIENTATION_EVENTS)
akling@apple.com43e9d042012-11-18 16:55:06 +0000130 else if (name == onorientationchangeAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000131 document().setWindowAttributeEventListener(eventNames().orientationchangeEvent, createAttributeEventListener(document().frame(), name, value));
bolsinga@apple.comdcfc7892009-09-21 23:10:30 +0000132#endif
akling@apple.com43e9d042012-11-18 16:55:06 +0000133 else if (name == onhashchangeAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000134 document().setWindowAttributeEventListener(eventNames().hashchangeEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000135 else if (name == onresizeAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000136 document().setWindowAttributeEventListener(eventNames().resizeEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000137 else if (name == onscrollAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000138 document().setWindowAttributeEventListener(eventNames().scrollEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000139 else if (name == onstorageAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000140 document().setWindowAttributeEventListener(eventNames().storageEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000141 else if (name == ononlineAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000142 document().setWindowAttributeEventListener(eventNames().onlineEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000143 else if (name == onofflineAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000144 document().setWindowAttributeEventListener(eventNames().offlineEvent, createAttributeEventListener(document().frame(), name, value));
akling@apple.com43e9d042012-11-18 16:55:06 +0000145 else if (name == onpopstateAttr)
akling@apple.com622b1a42013-08-30 14:30:12 +0000146 document().setWindowAttributeEventListener(eventNames().popstateEvent, createAttributeEventListener(document().frame(), name, value));
weinig@apple.com19e78c52009-06-23 03:05:03 +0000147 else
akling@apple.com43e9d042012-11-18 16:55:06 +0000148 HTMLElement::parseAttribute(name, value);
eseidel409f4302006-05-12 22:56:41 +0000149}
150
antti@apple.comb74dfb62013-08-20 21:22:53 +0000151bool HTMLFrameSetElement::rendererIsNeeded(const RenderStyle& style)
eseidel409f4302006-05-12 22:56:41 +0000152{
ggaren31614e22006-10-13 20:22:08 +0000153 // For compatibility, frames render even when display: none is set.
154 // However, we delay creating a renderer until stylesheets have loaded.
antti@apple.comb74dfb62013-08-20 21:22:53 +0000155 return style.isStyleAvailable();
eseidel409f4302006-05-12 22:56:41 +0000156}
157
158RenderObject *HTMLFrameSetElement::createRenderer(RenderArena *arena, RenderStyle *style)
159{
simon.fraser@apple.com2759ea42011-06-07 22:14:39 +0000160 if (style->hasContent())
bdakineb2c2042006-07-10 11:39:35 +0000161 return RenderObject::createObject(this, style);
162
eseidel409f4302006-05-12 22:56:41 +0000163 return new (arena) RenderFrameSet(this);
164}
165
antti@apple.com927b66d2013-08-20 15:25:04 +0000166HTMLFrameSetElement* HTMLFrameSetElement::findContaining(Node* node)
167{
168 for (Element* parent = node->parentElement(); parent; parent = parent->parentElement()) {
169 if (isHTMLFrameSetElement(parent))
170 return toHTMLFrameSetElement(parent);
171 }
172 return 0;
173}
174
antti@apple.com0f2ac5b2013-08-18 20:01:20 +0000175void HTMLFrameSetElement::willAttachRenderers()
eseidel409f4302006-05-12 22:56:41 +0000176{
antti@apple.com927b66d2013-08-20 15:25:04 +0000177 // Inherit default settings from parent frameset.
hyatt0fa2fbc2007-03-18 09:21:21 +0000178 // FIXME: This is not dynamic.
antti@apple.com927b66d2013-08-20 15:25:04 +0000179 const HTMLFrameSetElement* containingFrameSet = findContaining(this);
180 if (!containingFrameSet)
181 return;
182 if (!m_frameborderSet)
183 m_frameborder = containingFrameSet->hasFrameBorder();
184 if (m_frameborder) {
185 if (!m_borderSet)
186 m_border = containingFrameSet->border();
187 if (!m_borderColorSet)
188 m_borderColorSet = containingFrameSet->hasBorderColor();
eseidel409f4302006-05-12 22:56:41 +0000189 }
antti@apple.com927b66d2013-08-20 15:25:04 +0000190 if (!m_noresize)
191 m_noresize = containingFrameSet->noResize();
eseidel409f4302006-05-12 22:56:41 +0000192}
193
194void HTMLFrameSetElement::defaultEventHandler(Event* evt)
195{
dbates@webkit.org05c12fa2011-03-23 17:58:29 +0000196 if (evt->isMouseEvent() && !m_noresize && renderer() && renderer()->isFrameSet()) {
darin@apple.comb6cb2562009-08-05 21:25:09 +0000197 if (toRenderFrameSet(renderer())->userResize(static_cast<MouseEvent*>(evt))) {
darin8c216132006-12-20 01:49:03 +0000198 evt->setDefaultHandled();
199 return;
200 }
darin@apple.comf8fc1012008-01-15 01:03:11 +0000201 }
eseidel409f4302006-05-12 22:56:41 +0000202 HTMLElement::defaultEventHandler(evt);
203}
204
antti@apple.come6cf4112013-08-07 12:02:04 +0000205bool HTMLFrameSetElement::willRecalcStyle(Style::Change)
eseidel409f4302006-05-12 22:56:41 +0000206{
hyatt@apple.comf6d72f32009-04-10 00:05:02 +0000207 if (needsStyleRecalc() && renderer()) {
eseidel409f4302006-05-12 22:56:41 +0000208 renderer()->setNeedsLayout(true);
simon.fraser@apple.com2ae4ee92010-07-30 23:02:18 +0000209 clearNeedsStyleRecalc();
eseidel409f4302006-05-12 22:56:41 +0000210 }
antti@apple.comf513f272011-09-02 11:19:35 +0000211 return true;
eseidel409f4302006-05-12 22:56:41 +0000212}
213
darin@apple.com183547b2012-05-23 16:56:33 +0000214Node::InsertionNotificationRequest HTMLFrameSetElement::insertedInto(ContainerNode* insertionPoint)
ap@apple.com43af8a82010-10-29 17:23:55 +0000215{
commit-queue@webkit.org9ea00802012-04-17 06:40:55 +0000216 HTMLElement::insertedInto(insertionPoint);
217 if (insertionPoint->inDocument()) {
akling@apple.com622b1a42013-08-30 14:30:12 +0000218 if (Frame* frame = document().frame())
219 frame->loader().client().dispatchDidBecomeFrameset(document().isFrameSet());
commit-queue@webkit.org9ea00802012-04-17 06:40:55 +0000220 }
221
222 return InsertionDone;
ap@apple.com43af8a82010-10-29 17:23:55 +0000223}
224
darin@apple.com183547b2012-05-23 16:56:33 +0000225void HTMLFrameSetElement::removedFrom(ContainerNode* insertionPoint)
ap@apple.com43af8a82010-10-29 17:23:55 +0000226{
commit-queue@webkit.org9ea00802012-04-17 06:40:55 +0000227 HTMLElement::removedFrom(insertionPoint);
228 if (insertionPoint->inDocument()) {
akling@apple.com622b1a42013-08-30 14:30:12 +0000229 if (Frame* frame = document().frame())
230 frame->loader().client().dispatchDidBecomeFrameset(document().isFrameSet());
commit-queue@webkit.org9ea00802012-04-17 06:40:55 +0000231 }
ap@apple.com43af8a82010-10-29 17:23:55 +0000232}
233
weinig@apple.com19e78c52009-06-23 03:05:03 +0000234} // namespace WebCore