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 "ElementIterator.h" 31#include "Event.h" 32#include "EventNames.h" 33#include "Frame.h" 34#include "FrameLoader.h" 35#include "FrameLoaderClient.h" 36#include "HTMLNames.h" 37#include "Length.h" 38#include "MouseEvent.h" 39#include "RenderFrameSet.h" 40#include "Text.h" 41 42namespace WebCore { 43 44using namespace HTMLNames; 45 46HTMLFrameSetElement::HTMLFrameSetElement(const QualifiedName& tagName, Document& document) 47 : HTMLElement(tagName, document) 48 , m_totalRows(1) 49 , m_totalCols(1) 50 , m_border(6) 51 , m_borderSet(false) 52 , m_borderColorSet(false) 53 , m_frameborder(true) 54 , m_frameborderSet(false) 55 , m_noresize(false) 56{ 57 ASSERT(hasTagName(framesetTag)); 58 setHasCustomStyleResolveCallbacks(); 59} 60 61PassRefPtr<HTMLFrameSetElement> HTMLFrameSetElement::create(const QualifiedName& tagName, Document& document) 62{ 63 return adoptRef(new HTMLFrameSetElement(tagName, document)); 64} 65 66bool HTMLFrameSetElement::isPresentationAttribute(const QualifiedName& name) const 67{ 68 if (name == bordercolorAttr) 69 return true; 70 return HTMLElement::isPresentationAttribute(name); 71} 72 73void HTMLFrameSetElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) 74{ 75 if (name == bordercolorAttr) 76 addHTMLColorToStyle(style, CSSPropertyBorderColor, value); 77 else 78 HTMLElement::collectStyleForPresentationAttribute(name, value, style); 79} 80 81void HTMLFrameSetElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 82{ 83 if (name == rowsAttr) { 84 if (!value.isNull()) { 85 m_rowLengths = newLengthArray(value.string(), m_totalRows); 86 setNeedsStyleRecalc(); 87 } 88 } else if (name == colsAttr) { 89 if (!value.isNull()) { 90 m_colLengths = newLengthArray(value.string(), m_totalCols); 91 setNeedsStyleRecalc(); 92 } 93 } else if (name == frameborderAttr) { 94 if (!value.isNull()) { 95 if (equalIgnoringCase(value, "no") || equalIgnoringCase(value, "0")) { 96 m_frameborder = false; 97 m_frameborderSet = true; 98 } else if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "1")) { 99 m_frameborderSet = true; 100 } 101 } else { 102 m_frameborder = false; 103 m_frameborderSet = false; 104 } 105 } else if (name == noresizeAttr) { 106 m_noresize = true; 107 } else if (name == borderAttr) { 108 if (!value.isNull()) { 109 m_border = value.toInt(); 110 m_borderSet = true; 111 } else 112 m_borderSet = false; 113 } else if (name == bordercolorAttr) 114 m_borderColorSet = !value.isEmpty(); 115 else if (name == onloadAttr) 116 document().setWindowAttributeEventListener(eventNames().loadEvent, name, value); 117 else if (name == onbeforeunloadAttr) 118 document().setWindowAttributeEventListener(eventNames().beforeunloadEvent, name, value); 119 else if (name == onunloadAttr) 120 document().setWindowAttributeEventListener(eventNames().unloadEvent, name, value); 121 else if (name == onblurAttr) 122 document().setWindowAttributeEventListener(eventNames().blurEvent, name, value); 123 else if (name == onfocusAttr) 124 document().setWindowAttributeEventListener(eventNames().focusEvent, name, value); 125 else if (name == onfocusinAttr) 126 document().setWindowAttributeEventListener(eventNames().focusinEvent, name, value); 127 else if (name == onfocusoutAttr) 128 document().setWindowAttributeEventListener(eventNames().focusoutEvent, name, value); 129#if ENABLE(ORIENTATION_EVENTS) 130 else if (name == onorientationchangeAttr) 131 document().setWindowAttributeEventListener(eventNames().orientationchangeEvent, name, value); 132#endif 133 else if (name == onhashchangeAttr) 134 document().setWindowAttributeEventListener(eventNames().hashchangeEvent, name, value); 135 else if (name == onresizeAttr) 136 document().setWindowAttributeEventListener(eventNames().resizeEvent, name, value); 137 else if (name == onscrollAttr) 138 document().setWindowAttributeEventListener(eventNames().scrollEvent, name, value); 139 else if (name == onstorageAttr) 140 document().setWindowAttributeEventListener(eventNames().storageEvent, name, value); 141 else if (name == ononlineAttr) 142 document().setWindowAttributeEventListener(eventNames().onlineEvent, name, value); 143 else if (name == onofflineAttr) 144 document().setWindowAttributeEventListener(eventNames().offlineEvent, name, value); 145 else if (name == onpopstateAttr) 146 document().setWindowAttributeEventListener(eventNames().popstateEvent, name, value); 147 else 148 HTMLElement::parseAttribute(name, value); 149} 150 151bool HTMLFrameSetElement::rendererIsNeeded(const RenderStyle& style) 152{ 153 // For compatibility, frames render even when display: none is set. 154 // However, we delay creating a renderer until stylesheets have loaded. 155 return style.isStyleAvailable(); 156} 157 158RenderPtr<RenderElement> HTMLFrameSetElement::createElementRenderer(PassRef<RenderStyle> style) 159{ 160 if (style.get().hasContent()) 161 return RenderElement::createFor(*this, WTF::move(style)); 162 163 return createRenderer<RenderFrameSet>(*this, WTF::move(style)); 164} 165 166HTMLFrameSetElement* HTMLFrameSetElement::findContaining(Element* descendant) 167{ 168 return ancestorsOfType<HTMLFrameSetElement>(*descendant).first(); 169} 170 171void HTMLFrameSetElement::willAttachRenderers() 172{ 173 // Inherit default settings from parent frameset. 174 // FIXME: This is not dynamic. 175 const HTMLFrameSetElement* containingFrameSet = findContaining(this); 176 if (!containingFrameSet) 177 return; 178 if (!m_frameborderSet) 179 m_frameborder = containingFrameSet->hasFrameBorder(); 180 if (m_frameborder) { 181 if (!m_borderSet) 182 m_border = containingFrameSet->border(); 183 if (!m_borderColorSet) 184 m_borderColorSet = containingFrameSet->hasBorderColor(); 185 } 186 if (!m_noresize) 187 m_noresize = containingFrameSet->noResize(); 188} 189 190void HTMLFrameSetElement::defaultEventHandler(Event* evt) 191{ 192 if (evt->isMouseEvent() && !m_noresize && renderer() && renderer()->isFrameSet()) { 193 if (toRenderFrameSet(renderer())->userResize(toMouseEvent(evt))) { 194 evt->setDefaultHandled(); 195 return; 196 } 197 } 198 HTMLElement::defaultEventHandler(evt); 199} 200 201bool HTMLFrameSetElement::willRecalcStyle(Style::Change) 202{ 203 if (needsStyleRecalc() && renderer()) { 204 renderer()->setNeedsLayout(); 205 clearNeedsStyleRecalc(); 206 } 207 return true; 208} 209 210Node::InsertionNotificationRequest HTMLFrameSetElement::insertedInto(ContainerNode& insertionPoint) 211{ 212 HTMLElement::insertedInto(insertionPoint); 213 if (insertionPoint.inDocument()) { 214 if (Frame* frame = document().frame()) 215 frame->loader().client().dispatchDidBecomeFrameset(document().isFrameSet()); 216 } 217 218 return InsertionDone; 219} 220 221void HTMLFrameSetElement::removedFrom(ContainerNode& insertionPoint) 222{ 223 HTMLElement::removedFrom(insertionPoint); 224 if (insertionPoint.inDocument()) { 225 if (Frame* frame = document().frame()) 226 frame->loader().client().dispatchDidBecomeFrameset(document().isFrameSet()); 227 } 228} 229 230} // namespace WebCore 231