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.
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.
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.
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.
25 #include "core/html/HTMLFrameSetElement.h"
27 #include "bindings/core/v8/ScriptEventListener.h"
28 #include "core/CSSPropertyNames.h"
29 #include "core/HTMLNames.h"
30 #include "core/dom/Document.h"
31 #include "core/events/Event.h"
32 #include "core/events/MouseEvent.h"
33 #include "core/frame/LocalFrame.h"
34 #include "core/html/HTMLCollection.h"
35 #include "core/html/HTMLFrameElement.h"
36 #include "core/layout/LayoutFrameSet.h"
37 #include "core/loader/FrameLoaderClient.h"
41 using namespace HTMLNames
;
43 inline HTMLFrameSetElement::HTMLFrameSetElement(Document
& document
)
44 : HTMLElement(framesetTag
, document
)
47 , m_borderColorSet(false)
49 , m_frameborderSet(false)
52 setHasCustomStyleCallbacks();
55 DEFINE_NODE_FACTORY(HTMLFrameSetElement
)
57 bool HTMLFrameSetElement::isPresentationAttribute(const QualifiedName
& name
) const
59 if (name
== bordercolorAttr
)
61 return HTMLElement::isPresentationAttribute(name
);
64 void HTMLFrameSetElement::collectStyleForPresentationAttribute(const QualifiedName
& name
, const AtomicString
& value
, MutableStylePropertySet
* style
)
66 if (name
== bordercolorAttr
)
67 addHTMLColorToStyle(style
, CSSPropertyBorderColor
, value
);
69 HTMLElement::collectStyleForPresentationAttribute(name
, value
, style
);
72 void HTMLFrameSetElement::parseAttribute(const QualifiedName
& name
, const AtomicString
& value
)
74 if (name
== rowsAttr
) {
75 if (!value
.isNull()) {
76 m_rowLengths
= parseListOfDimensions(value
.string());
77 setNeedsStyleRecalc(SubtreeStyleChange
, StyleChangeReasonForTracing::fromAttribute(name
));
79 } else if (name
== colsAttr
) {
80 if (!value
.isNull()) {
81 m_colLengths
= parseListOfDimensions(value
.string());
82 setNeedsStyleRecalc(SubtreeStyleChange
, StyleChangeReasonForTracing::fromAttribute(name
));
84 } else if (name
== frameborderAttr
) {
85 if (!value
.isNull()) {
86 if (equalIgnoringCase(value
, "no") || equalIgnoringCase(value
, "0")) {
87 m_frameborder
= false;
88 m_frameborderSet
= true;
89 } else if (equalIgnoringCase(value
, "yes") || equalIgnoringCase(value
, "1")) {
90 m_frameborderSet
= true;
93 m_frameborder
= false;
94 m_frameborderSet
= false;
96 } else if (name
== noresizeAttr
) {
98 } else if (name
== borderAttr
) {
99 if (!value
.isNull()) {
100 m_border
= value
.toInt();
105 } else if (name
== bordercolorAttr
) {
106 m_borderColorSet
= !value
.isEmpty();
107 } else if (name
== onloadAttr
) {
108 document().setWindowAttributeEventListener(EventTypeNames::load
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
109 } else if (name
== onbeforeunloadAttr
) {
110 document().setWindowAttributeEventListener(EventTypeNames::beforeunload
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
111 } else if (name
== onunloadAttr
) {
112 document().setWindowAttributeEventListener(EventTypeNames::unload
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
113 } else if (name
== onpagehideAttr
) {
114 document().setWindowAttributeEventListener(EventTypeNames::pagehide
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
115 } else if (name
== onpageshowAttr
) {
116 document().setWindowAttributeEventListener(EventTypeNames::pageshow
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
117 } else if (name
== onblurAttr
) {
118 document().setWindowAttributeEventListener(EventTypeNames::blur
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
119 } else if (name
== onerrorAttr
) {
120 document().setWindowAttributeEventListener(EventTypeNames::error
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
121 } else if (name
== onfocusAttr
) {
122 document().setWindowAttributeEventListener(EventTypeNames::focus
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
123 } else if (name
== onfocusinAttr
) {
124 document().setWindowAttributeEventListener(EventTypeNames::focusin
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
125 } else if (name
== onfocusoutAttr
) {
126 document().setWindowAttributeEventListener(EventTypeNames::focusout
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
127 } else if (RuntimeEnabledFeatures::orientationEventEnabled() && name
== onorientationchangeAttr
) {
128 document().setWindowAttributeEventListener(EventTypeNames::orientationchange
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
129 } else if (name
== onhashchangeAttr
) {
130 document().setWindowAttributeEventListener(EventTypeNames::hashchange
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
131 } else if (name
== onmessageAttr
) {
132 document().setWindowAttributeEventListener(EventTypeNames::message
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
133 } else if (name
== onresizeAttr
) {
134 document().setWindowAttributeEventListener(EventTypeNames::resize
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
135 } else if (name
== onscrollAttr
) {
136 document().setWindowAttributeEventListener(EventTypeNames::scroll
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
137 } else if (name
== onstorageAttr
) {
138 document().setWindowAttributeEventListener(EventTypeNames::storage
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
139 } else if (name
== ononlineAttr
) {
140 document().setWindowAttributeEventListener(EventTypeNames::online
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
141 } else if (name
== onofflineAttr
) {
142 document().setWindowAttributeEventListener(EventTypeNames::offline
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
143 } else if (name
== onpopstateAttr
) {
144 document().setWindowAttributeEventListener(EventTypeNames::popstate
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
145 } else if (name
== onlanguagechangeAttr
) {
146 document().setWindowAttributeEventListener(EventTypeNames::languagechange
, createAttributeEventListener(document().frame(), name
, value
, eventParameterName()));
148 HTMLElement::parseAttribute(name
, value
);
152 bool HTMLFrameSetElement::layoutObjectIsNeeded(const ComputedStyle
& style
)
154 // For compatibility, frames layoutObject even when display: none is set.
155 // However, we delay creating a layoutObject until stylesheets have loaded.
156 return style
.isStyleAvailable();
159 LayoutObject
* HTMLFrameSetElement::createLayoutObject(const ComputedStyle
& style
)
161 if (style
.hasContent())
162 return LayoutObject::createObject(this, style
);
163 return new LayoutFrameSet(this);
166 void HTMLFrameSetElement::attach(const AttachContext
& context
)
168 // Inherit default settings from parent frameset
169 // FIXME: This is not dynamic.
170 if (HTMLFrameSetElement
* frameset
= Traversal
<HTMLFrameSetElement
>::firstAncestor(*this)) {
171 if (!m_frameborderSet
)
172 m_frameborder
= frameset
->hasFrameBorder();
175 m_border
= frameset
->border();
176 if (!m_borderColorSet
)
177 m_borderColorSet
= frameset
->hasBorderColor();
180 m_noresize
= frameset
->noResize();
183 HTMLElement::attach(context
);
186 void HTMLFrameSetElement::defaultEventHandler(Event
* evt
)
188 if (evt
->isMouseEvent() && !m_noresize
&& layoutObject() && layoutObject()->isFrameSet()) {
189 if (toLayoutFrameSet(layoutObject())->userResize(toMouseEvent(evt
))) {
190 evt
->setDefaultHandled();
194 HTMLElement::defaultEventHandler(evt
);
197 Node::InsertionNotificationRequest
HTMLFrameSetElement::insertedInto(ContainerNode
* insertionPoint
)
199 if (insertionPoint
->inDocument() && document().frame()) {
200 // A document using <frameset> likely won't literally have a body, but as far as the client is concerned, the frameset is effectively the body.
201 document().frame()->loader().client()->dispatchWillInsertBody();
203 return HTMLElement::insertedInto(insertionPoint
);
206 void HTMLFrameSetElement::willRecalcStyle(StyleRecalcChange
)
208 if (needsStyleRecalc() && layoutObject()) {
209 layoutObject()->setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::StyleChange
);
210 clearNeedsStyleRecalc();
214 LocalDOMWindow
* HTMLFrameSetElement::anonymousNamedGetter(const AtomicString
& name
)
216 Element
* frameElement
= children()->namedItem(name
);
217 if (!isHTMLFrameElement(frameElement
))
219 Document
* document
= toHTMLFrameElement(frameElement
)->contentDocument();
220 if (!document
|| !document
->frame())
222 return document
->domWindow();