HTMLIFrameElement.cpp 5.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * This file is part of the DOM implementation for KDE.
 *
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 *           (C) 2000 Simon Hausmann (hausmann@kde.org)
 *           (C) 2001 Dirk Mueller (mueller@kde.org)
 * Copyright (C) 2004, 2006 Apple Computer, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#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; // Share with <img> since the alignment behavior is the same.
        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();
andersca's avatar
andersca committed
96
97
98
99
100
101
102
103
104
105
106
107
108
    
    // Load the frame
    m_name = getAttribute(nameAttr);
    if (m_name.isNull())
        m_name = getAttribute(idAttr);
    
    Frame* parentFrame = document()->frame();
    if (parentFrame) {
        parentFrame->page()->incrementFrameCount();
        m_name = parentFrame->tree()->uniqueChildName(m_name);
        
        openURL();
    }    
109
110
}

111
void HTMLIFrameElement::willRemove()
112
{
andersca's avatar
andersca committed
113
114
115
116
117
118
    if (Frame* frame = contentFrame()) {
        frame->disconnectOwnerElement();
        frame->page()->decrementFrameCount();
        frame->frameDetached();
        ASSERT(!contentFrame());
    }
119
120
121
122
123
124
125
126
127
128
129

    HTMLElement::willRemove();
}

void HTMLIFrameElement::removedFromDocument()
{
    if (document()->isHTMLDocument()) {
        HTMLDocument *doc = static_cast<HTMLDocument *>(document());
        doc->removeDocExtraNamedItem(oldNameAttr);
    }

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    HTMLElement::removedFromDocument();
}

bool HTMLIFrameElement::rendererIsNeeded(RenderStyle *style)
{
    // Don't ignore display: none the way frame does.
    return isURLAllowed(m_URL) && style->display() != NONE;
}

RenderObject *HTMLIFrameElement::createRenderer(RenderArena *arena, RenderStyle *style)
{
    return new (arena) RenderPartObject(this);
}

void HTMLIFrameElement::attach()
{
    HTMLElement::attach();

andersca's avatar
andersca committed
148
149
150
151
152
153
154
155
    RenderPartObject* renderPart = static_cast<RenderPartObject*>(renderer());

    if (renderPart) {        
        if (!contentFrame())
            openURL();
        
        renderPart->setWidget(contentFrame()->view());
        renderPart->updateWidget();
156
157
158
159
        needWidgetUpdate = false;
    }
}

andersca's avatar
andersca committed
160
161
162
163
164
165
void HTMLIFrameElement::detach()
{
    HTMLElement::detach();
}


166
167
168
169
170
171
172
173
174
175
176
177
void HTMLIFrameElement::recalcStyle( StyleChange ch )
{
    if (needWidgetUpdate) {
        if (renderer())
            static_cast<RenderPartObject*>(renderer())->updateWidget();
        needWidgetUpdate = false;
    }
    HTMLElement::recalcStyle( ch );
}

void HTMLIFrameElement::openURL()
{
andersca's avatar
andersca committed
178
179
180
181
182
183
184
185
    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());
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
}

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);
}

}