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