HTMLIFrameElement.cpp [plain text]
#include "config.h"
#include "HTMLIFrameElement.h"
#include "CSSPropertyNames.h"
#include "Frame.h"
#include "FrameTree.h"
#include "HTMLDocument.h"
#include "HTMLNames.h"
#include "Page.h"
#include "RenderPartObject.h"
namespace WebCore {
using namespace HTMLNames;
HTMLIFrameElement::HTMLIFrameElement(Document* doc)
: HTMLFrameElement(iframeTag, doc)
, needWidgetUpdate(false)
{
m_frameBorder = false;
m_marginWidth = -1;
m_marginHeight = -1;
}
HTMLIFrameElement::~HTMLIFrameElement()
{
}
bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
{
if (attrName == widthAttr || attrName == heightAttr) {
result = eUniversal;
return false;
}
if (attrName == alignAttr) {
result = eReplaced; return false;
}
return HTMLElement::mapToEntry(attrName, result);
}
void HTMLIFrameElement::parseMappedAttribute(MappedAttribute *attr)
{
if (attr->name() == widthAttr)
addCSSLength(attr, CSS_PROP_WIDTH, attr->value());
else if (attr->name() == heightAttr)
addCSSLength(attr, CSS_PROP_HEIGHT, attr->value());
else if (attr->name() == alignAttr)
addHTMLAlignment(attr);
else if (attr->name() == nameAttr) {
String newNameAttr = attr->value();
if (inDocument() && document()->isHTMLDocument()) {
HTMLDocument *doc = static_cast<HTMLDocument *>(document());
doc->removeDocExtraNamedItem(oldNameAttr);
doc->addDocExtraNamedItem(newNameAttr);
}
oldNameAttr = newNameAttr;
} else
HTMLFrameElement::parseMappedAttribute(attr);
}
void HTMLIFrameElement::insertedIntoDocument()
{
if (document()->isHTMLDocument()) {
HTMLDocument *doc = static_cast<HTMLDocument *>(document());
doc->addDocExtraNamedItem(oldNameAttr);
}
HTMLElement::insertedIntoDocument();
m_name = getAttribute(nameAttr);
if (m_name.isNull())
m_name = getAttribute(idAttr);
if (Frame* parentFrame = document()->frame()) {
m_name = parentFrame->tree()->uniqueChildName(m_name);
openURL();
}
}
void HTMLIFrameElement::willRemove()
{
if (Frame* frame = contentFrame()) {
frame->disconnectOwnerElement();
frame->frameDetached();
ASSERT(!contentFrame());
}
HTMLElement::willRemove();
}
void HTMLIFrameElement::removedFromDocument()
{
if (document()->isHTMLDocument()) {
HTMLDocument *doc = static_cast<HTMLDocument *>(document());
doc->removeDocExtraNamedItem(oldNameAttr);
}
HTMLElement::removedFromDocument();
}
bool HTMLIFrameElement::rendererIsNeeded(RenderStyle *style)
{
return isURLAllowed(m_URL) && style->display() != NONE;
}
RenderObject *HTMLIFrameElement::createRenderer(RenderArena *arena, RenderStyle *style)
{
return new (arena) RenderPartObject(this);
}
void HTMLIFrameElement::attach()
{
HTMLElement::attach();
RenderPartObject* renderPart = static_cast<RenderPartObject*>(renderer());
if (renderPart) {
if (!contentFrame())
openURL();
if (contentFrame()) {
renderPart->setWidget(contentFrame()->view());
renderPart->updateWidget();
needWidgetUpdate = false;
}
}
}
void HTMLIFrameElement::detach()
{
HTMLElement::detach();
}
void HTMLIFrameElement::recalcStyle( StyleChange ch )
{
if (needWidgetUpdate) {
if (renderer())
static_cast<RenderPartObject*>(renderer())->updateWidget();
needWidgetUpdate = false;
}
HTMLElement::recalcStyle( ch );
}
void HTMLIFrameElement::openURL()
{
if (!isURLAllowed(m_URL))
return;
if (m_URL.isEmpty())
m_URL = "about:blank";
document()->frame()->requestFrame(this, m_URL, m_name);
if (contentFrame())
contentFrame()->setInViewSourceMode(viewSourceMode());
}
bool HTMLIFrameElement::isURLAttribute(Attribute *attr) const
{
return attr->name() == srcAttr;
}
String HTMLIFrameElement::align() const
{
return getAttribute(alignAttr);
}
void HTMLIFrameElement::setAlign(const String &value)
{
setAttribute(alignAttr, value);
}
String HTMLIFrameElement::height() const
{
return getAttribute(heightAttr);
}
void HTMLIFrameElement::setHeight(const String &value)
{
setAttribute(heightAttr, value);
}
String HTMLIFrameElement::src() const
{
return document()->completeURL(getAttribute(srcAttr));
}
String HTMLIFrameElement::width() const
{
return getAttribute(widthAttr);
}
void HTMLIFrameElement::setWidth(const String &value)
{
setAttribute(widthAttr, value);
}
}