1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Simon Hausmann (hausmann (at) kde.org) 5 * (C) 2001 Dirk Mueller (mueller (at) kde.org) 6 * Copyright (C) 2004, 2006, 2008, 2009 Apple Inc. All rights reserved. 7 * Copyright (C) 2009 Ericsson AB. All rights reserved. 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Library General Public 11 * License as published by the Free Software Foundation; either 12 * version 2 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Library General Public License for more details. 18 * 19 * You should have received a copy of the GNU Library General Public License 20 * along with this library; see the file COPYING.LIB. If not, write to 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 * Boston, MA 02110-1301, USA. 23 */ 24 25 #include "config.h" 26 #include "core/html/HTMLIFrameElement.h" 27 28 #include "core/CSSPropertyNames.h" 29 #include "core/HTMLNames.h" 30 #include "core/html/HTMLDocument.h" 31 #include "core/rendering/RenderIFrame.h" 32 33 namespace WebCore { 34 35 using namespace HTMLNames; 36 37 inline HTMLIFrameElement::HTMLIFrameElement(Document& document) 38 : HTMLFrameElementBase(iframeTag, document) 39 , m_didLoadNonEmptyDocument(false) 40 { 41 ScriptWrappable::init(this); 42 } 43 44 DEFINE_NODE_FACTORY(HTMLIFrameElement) 45 46 bool HTMLIFrameElement::isPresentationAttribute(const QualifiedName& name) const 47 { 48 if (name == widthAttr || name == heightAttr || name == alignAttr || name == frameborderAttr) 49 return true; 50 return HTMLFrameElementBase::isPresentationAttribute(name); 51 } 52 53 void HTMLIFrameElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style) 54 { 55 if (name == widthAttr) 56 addHTMLLengthToStyle(style, CSSPropertyWidth, value); 57 else if (name == heightAttr) 58 addHTMLLengthToStyle(style, CSSPropertyHeight, value); 59 else if (name == alignAttr) 60 applyAlignmentAttributeToStyle(value, style); 61 else if (name == frameborderAttr) { 62 // LocalFrame border doesn't really match the HTML4 spec definition for iframes. It simply adds 63 // a presentational hint that the border should be off if set to zero. 64 if (!value.toInt()) { 65 // Add a rule that nulls out our border width. 66 addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, 0, CSSPrimitiveValue::CSS_PX); 67 } 68 } else 69 HTMLFrameElementBase::collectStyleForPresentationAttribute(name, value, style); 70 } 71 72 void HTMLIFrameElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 73 { 74 if (name == nameAttr) { 75 if (inDocument() && document().isHTMLDocument() && !isInShadowTree()) { 76 HTMLDocument& document = toHTMLDocument(this->document()); 77 document.removeExtraNamedItem(m_name); 78 document.addExtraNamedItem(value); 79 } 80 m_name = value; 81 } else if (name == sandboxAttr) { 82 String invalidTokens; 83 setSandboxFlags(value.isNull() ? SandboxNone : parseSandboxPolicy(value, invalidTokens)); 84 if (!invalidTokens.isNull()) 85 document().addConsoleMessage(OtherMessageSource, ErrorMessageLevel, "Error while parsing the 'sandbox' attribute: " + invalidTokens); 86 } else { 87 HTMLFrameElementBase::parseAttribute(name, value); 88 } 89 } 90 91 bool HTMLIFrameElement::rendererIsNeeded(const RenderStyle& style) 92 { 93 return isURLAllowed() && HTMLElement::rendererIsNeeded(style); 94 } 95 96 RenderObject* HTMLIFrameElement::createRenderer(RenderStyle*) 97 { 98 return new RenderIFrame(this); 99 } 100 101 Node::InsertionNotificationRequest HTMLIFrameElement::insertedInto(ContainerNode* insertionPoint) 102 { 103 InsertionNotificationRequest result = HTMLFrameElementBase::insertedInto(insertionPoint); 104 if (insertionPoint->inDocument() && document().isHTMLDocument() && !insertionPoint->isInShadowTree()) 105 toHTMLDocument(document()).addExtraNamedItem(m_name); 106 return result; 107 } 108 109 void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint) 110 { 111 HTMLFrameElementBase::removedFrom(insertionPoint); 112 if (insertionPoint->inDocument() && document().isHTMLDocument() && !insertionPoint->isInShadowTree()) 113 toHTMLDocument(document()).removeExtraNamedItem(m_name); 114 } 115 116 bool HTMLIFrameElement::isInteractiveContent() const 117 { 118 return true; 119 } 120 121 } 122