Home | History | Annotate | Download | only in html
      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 "CSSPropertyNames.h"
     29 #include "HTMLNames.h"
     30 #include "core/dom/NodeRenderingContext.h"
     31 #include "core/html/HTMLDocument.h"
     32 #include "core/rendering/RenderIFrame.h"
     33 
     34 namespace WebCore {
     35 
     36 using namespace HTMLNames;
     37 
     38 inline HTMLIFrameElement::HTMLIFrameElement(const QualifiedName& tagName, Document* document)
     39     : HTMLFrameElementBase(tagName, document)
     40     , m_didLoadNonEmptyDocument(false)
     41 {
     42     ASSERT(hasTagName(iframeTag));
     43     ScriptWrappable::init(this);
     44     setHasCustomStyleCallbacks();
     45 }
     46 
     47 PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(const QualifiedName& tagName, Document* document)
     48 {
     49     return adoptRef(new HTMLIFrameElement(tagName, document));
     50 }
     51 
     52 bool HTMLIFrameElement::isPresentationAttribute(const QualifiedName& name) const
     53 {
     54     if (name == widthAttr || name == heightAttr || name == alignAttr || name == frameborderAttr || name == seamlessAttr)
     55         return true;
     56     return HTMLFrameElementBase::isPresentationAttribute(name);
     57 }
     58 
     59 void HTMLIFrameElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
     60 {
     61     if (name == widthAttr)
     62         addHTMLLengthToStyle(style, CSSPropertyWidth, value);
     63     else if (name == heightAttr)
     64         addHTMLLengthToStyle(style, CSSPropertyHeight, value);
     65     else if (name == alignAttr)
     66         applyAlignmentAttributeToStyle(value, style);
     67     else if (name == frameborderAttr) {
     68         // Frame border doesn't really match the HTML4 spec definition for iframes. It simply adds
     69         // a presentational hint that the border should be off if set to zero.
     70         if (!value.toInt()) {
     71             // Add a rule that nulls out our border width.
     72             addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, 0, CSSPrimitiveValue::CSS_PX);
     73         }
     74     } else
     75         HTMLFrameElementBase::collectStyleForPresentationAttribute(name, value, style);
     76 }
     77 
     78 void HTMLIFrameElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
     79 {
     80     if (name == nameAttr) {
     81         if (inDocument() && document()->isHTMLDocument() && !isInShadowTree()) {
     82             HTMLDocument* document = toHTMLDocument(this->document());
     83             document->removeExtraNamedItem(m_name);
     84             document->addExtraNamedItem(value);
     85         }
     86         m_name = value;
     87     } else if (name == sandboxAttr) {
     88         String invalidTokens;
     89         setSandboxFlags(value.isNull() ? SandboxNone : SecurityContext::parseSandboxPolicy(value, invalidTokens));
     90         if (!invalidTokens.isNull())
     91             document()->addConsoleMessage(OtherMessageSource, ErrorMessageLevel, "Error while parsing the 'sandbox' attribute: " + invalidTokens);
     92     } else if (name == seamlessAttr) {
     93         // If we're adding or removing the seamless attribute, we need to force the content document to recalculate its StyleResolver.
     94         if (contentDocument())
     95             contentDocument()->styleResolverChanged(DeferRecalcStyle);
     96     } else
     97         HTMLFrameElementBase::parseAttribute(name, value);
     98 }
     99 
    100 bool HTMLIFrameElement::rendererIsNeeded(const NodeRenderingContext& context)
    101 {
    102     return isURLAllowed() && context.style()->display() != NONE;
    103 }
    104 
    105 RenderObject* HTMLIFrameElement::createRenderer(RenderStyle*)
    106 {
    107     return new RenderIFrame(this);
    108 }
    109 
    110 Node::InsertionNotificationRequest HTMLIFrameElement::insertedInto(ContainerNode* insertionPoint)
    111 {
    112     InsertionNotificationRequest result = HTMLFrameElementBase::insertedInto(insertionPoint);
    113     if (insertionPoint->inDocument() && document()->isHTMLDocument() && !insertionPoint->isInShadowTree())
    114         toHTMLDocument(document())->addExtraNamedItem(m_name);
    115     return result;
    116 }
    117 
    118 void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint)
    119 {
    120     HTMLFrameElementBase::removedFrom(insertionPoint);
    121     if (insertionPoint->inDocument() && document()->isHTMLDocument() && !insertionPoint->isInShadowTree())
    122         toHTMLDocument(document())->removeExtraNamedItem(m_name);
    123 }
    124 
    125 bool HTMLIFrameElement::shouldDisplaySeamlessly() const
    126 {
    127     return contentDocument() && contentDocument()->shouldDisplaySeamlesslyWithParent();
    128 }
    129 
    130 void HTMLIFrameElement::didRecalcStyle(StyleChange styleChange)
    131 {
    132     if (!shouldDisplaySeamlessly())
    133         return;
    134     Document* childDocument = contentDocument();
    135     if (shouldRecalcStyle(styleChange, childDocument))
    136         contentDocument()->recalcStyle(styleChange);
    137 }
    138 
    139 }
    140