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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
/**
* 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 Stefan Schimanski (1Stein@gmx.de)
*
* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "html/html_objectimpl.h"
#include "khtml_part.h"
#include "dom/dom_string.h"
#include "misc/htmlhashes.h"
#include "khtmlview.h"
#include <qstring.h>
#include <qvariant.h>
#include <qmap.h>
#include <qtimer.h>
#include <kdebug.h>
#include <kimageio.h>
#include "xml/dom_docimpl.h"
#include "css/cssstyleselector.h"
#include "css/csshelper.h"
#include "css/cssproperties.h"
#include "css/cssvalues.h"
#include "rendering/render_applet.h"
#include "rendering/render_frames.h"
#include "rendering/render_image.h"
#include "xml/dom2_eventsimpl.h"
using namespace DOM;
using namespace khtml;
// -------------------------------------------------------------------------
HTMLObjectBaseElementImpl::HTMLObjectBaseElementImpl(DocumentImpl *doc)
: HTMLElementImpl(doc)
{
needWidgetUpdate = false;
m_renderAlternative = false;
}
void HTMLObjectBaseElementImpl::setServiceType(const QString & val) {
serviceType = val.lower();
int pos = serviceType.find( ";" );
if ( pos!=-1 )
serviceType.truncate( pos );
}
void HTMLObjectBaseElementImpl::parseAttribute(AttributeImpl *attr)
{
switch ( attr->id() )
{
case ATTR_TYPE:
case ATTR_CODETYPE:
if (attr->val()) {
DOM::DOMStringImpl *stringImpl = attr->val();
QString val = QConstString( stringImpl->s, stringImpl->l ).string();
setServiceType( val );
needWidgetUpdate = true;
}
break;
case ATTR_WIDTH:
if (!attr->value().isEmpty())
addCSSLength(CSS_PROP_WIDTH, attr->value());
else
removeCSSProperty(CSS_PROP_WIDTH);
break;
case ATTR_HEIGHT:
if (!attr->value().isEmpty())
addCSSLength(CSS_PROP_HEIGHT, attr->value());
else
removeCSSProperty(CSS_PROP_HEIGHT);
break;
case ATTR_NAME:
if (inDocument() && m_name != attr->value()) {
getDocument()->underDocNamedCache().remove(m_name.string(), this);
getDocument()->underDocNamedCache().add (attr->value().string(), this);
}
m_name = attr->value();
//fallthrough
default:
HTMLElementImpl::parseAttribute( attr );
}
}
void HTMLObjectBaseElementImpl::removedFromDocument()
{
getDocument()->underDocNamedCache().remove(m_name.string(), this);
HTMLElementImpl::removedFromDocument();
}
void HTMLObjectBaseElementImpl::insertedIntoDocument()
{
getDocument()->underDocNamedCache().add(m_name.string(), this);
HTMLElementImpl::insertedIntoDocument();
}
void HTMLObjectBaseElementImpl::removeId(const QString& id)
{
getDocument()->underDocNamedCache().remove(id, this);
HTMLElementImpl::removeId(id);
}
void HTMLObjectBaseElementImpl::addId (const QString& id)
{
getDocument()->underDocNamedCache().add(id, this);
HTMLElementImpl::addId(id);
}
void HTMLObjectBaseElementImpl::recalcStyle( StyleChange ch )
{
if (needWidgetUpdate) {
if(m_render && strcmp( m_render->renderName(), "RenderPartObject" ) == 0 )
static_cast<RenderPartObject*>(m_render)->updateWidget();
needWidgetUpdate = false;
}
HTMLElementImpl::recalcStyle( ch );
}
void HTMLObjectBaseElementImpl::renderAlternative()
{
if ( m_renderAlternative ) return;
QTimer::singleShot( 0, this, SLOT( slotRenderAlternative() ) );
}
void HTMLObjectBaseElementImpl::slotRenderAlternative()
{
// the singleshot timer might have fired after we're removed
// from the document, but not yet deleted due to references
if ( !inDocument() || m_renderAlternative ) return;
// ### there can be a m_render if this is called from our attach indirectly
if ( attached() || m_render)
detach();
m_renderAlternative = true;
attach();
}
void HTMLObjectBaseElementImpl::attach() {
assert(!attached());
assert(!m_render);
if (serviceType.isEmpty() && url.startsWith("data:")) {
// Extract the MIME type from the data URL.
int index = url.find(';');
if (index == -1)
index = url.find(',');
if (index != -1) {
int len = index - 5;
if (len > 0)
serviceType = url.mid(5, len);
else
serviceType = "text/plain"; // Data URLs with no MIME type are considered text/plain.
}
}
bool imagelike = serviceType.startsWith("image/") &&
!KImageIO::typeForMime(serviceType).isNull();
if (m_renderAlternative && !imagelike) {
// render alternative content
ElementImpl::attach();
return;
}
if (!parentNode()->renderer()) {
NodeBaseImpl::attach();
return;
}
RenderStyle* _style = getDocument()->styleSelector()->styleForElement(this);
_style->ref();
if (parentNode()->renderer() && parentNode()->renderer()->childAllowed() &&
_style->display() != NONE)
{
needWidgetUpdate = false;
if (imagelike) {
m_render = new (getDocument()->renderArena()) RenderImage(this);
// make sure we don't attach the inner contents
addCSSProperty(CSS_PROP_DISPLAY, CSS_VAL_NONE);
}
else
m_render = new (getDocument()->renderArena())RenderPartObject(this);
m_render->setStyle(_style);
parentNode()->renderer()->addChild(m_render, nextRenderer());
if (imagelike)
m_render->updateFromElement();
}
_style->deref();
NodeBaseImpl::attach();
// ### do this when we are actually finished loading instead
if (m_render) dispatchHTMLEvent(EventImpl::LOAD_EVENT, false, false);
}
// -------------------------------------------------------------------------
HTMLAppletElementImpl::HTMLAppletElementImpl(DocumentImpl *doc)
: HTMLObjectBaseElementImpl(doc)
{
serviceType = "application/x-java-applet";
needWidgetUpdate = true;
}
HTMLAppletElementImpl::~HTMLAppletElementImpl()
{
}
NodeImpl::Id HTMLAppletElementImpl::id() const
{
return ID_APPLET;
}
void HTMLAppletElementImpl::parseAttribute(AttributeImpl *attr)
{
switch( attr->id() )
{
case ATTR_CODEBASE:
case ATTR_ARCHIVE:
case ATTR_CODE:
case ATTR_OBJECT:
case ATTR_ALT:
break;
case ATTR_ALIGN:
addHTMLAlignment( attr->value() );
break;
case ATTR_VSPACE:
addCSSLength(CSS_PROP_MARGIN_TOP, attr->value());
addCSSLength(CSS_PROP_MARGIN_BOTTOM, attr->value());
break;
case ATTR_HSPACE:
addCSSLength(CSS_PROP_MARGIN_LEFT, attr->value());
addCSSLength(CSS_PROP_MARGIN_RIGHT, attr->value());
break;
case ATTR_VALIGN:
addCSSProperty(CSS_PROP_VERTICAL_ALIGN, attr->value().lower() );
break;
default:
HTMLObjectBaseElementImpl::parseAttribute(attr);
}
}
void HTMLAppletElementImpl::attach()
{
KHTMLView* w = getDocument()->view();
#ifndef Q_WS_QWS // FIXME?
DOMString codeBase = getAttribute( ATTR_CODEBASE );
DOMString code = getAttribute( ATTR_CODE );
if ( !codeBase.isEmpty() )
url = codeBase.string();
if ( !code.isEmpty() )
url = code.string();
if (!w || !w->part()->javaEnabled())
#endif
m_renderAlternative = true;
HTMLObjectBaseElementImpl::attach();
}
// -------------------------------------------------------------------------
HTMLEmbedElementImpl::HTMLEmbedElementImpl(DocumentImpl *doc)
: HTMLObjectBaseElementImpl(doc)
{
}
HTMLEmbedElementImpl::~HTMLEmbedElementImpl()
{
}
NodeImpl::Id HTMLEmbedElementImpl::id() const
{
return ID_EMBED;
}
void HTMLEmbedElementImpl::parseAttribute(AttributeImpl *attr)
{
switch ( attr->id() )
{
case ATTR_CODE:
case ATTR_SRC:
url = khtml::parseURL(attr->val()).string();
needWidgetUpdate = true;
break;
case ATTR_BORDER:
addCSSLength(CSS_PROP_BORDER_WIDTH, attr->value());
addCSSProperty( CSS_PROP_BORDER_TOP_STYLE, CSS_VAL_SOLID );
addCSSProperty( CSS_PROP_BORDER_RIGHT_STYLE, CSS_VAL_SOLID );
addCSSProperty( CSS_PROP_BORDER_BOTTOM_STYLE, CSS_VAL_SOLID );
addCSSProperty( CSS_PROP_BORDER_LEFT_STYLE, CSS_VAL_SOLID );
break;
case ATTR_VSPACE:
addCSSLength(CSS_PROP_MARGIN_TOP, attr->value());
addCSSLength(CSS_PROP_MARGIN_BOTTOM, attr->value());
break;
case ATTR_HSPACE:
addCSSLength(CSS_PROP_MARGIN_LEFT, attr->value());
addCSSLength(CSS_PROP_MARGIN_RIGHT, attr->value());
break;
case ATTR_ALIGN:
addHTMLAlignment( attr->value() );
break;
case ATTR_VALIGN:
addCSSProperty(CSS_PROP_VERTICAL_ALIGN, attr->value().lower() );
break;
case ATTR_PLUGINPAGE:
case ATTR_PLUGINSPAGE: {
pluginPage = attr->value().string();
break;
}
case ATTR_HIDDEN:
if (strcasecmp( attr->value(), "yes" ) == 0 || strcasecmp( attr->value() , "true") == 0 )
hidden = true;
else
hidden = false;
break;
default:
HTMLObjectBaseElementImpl::parseAttribute( attr );
}
}
void HTMLEmbedElementImpl::attach()
{
KHTMLView* w = getDocument()->view();
if (!w || !w->part()->pluginsEnabled())
m_renderAlternative = true;
if (parentNode()->id() == ID_OBJECT)
NodeBaseImpl::attach();
else
HTMLObjectBaseElementImpl::attach();
}
// -------------------------------------------------------------------------
HTMLObjectElementImpl::HTMLObjectElementImpl(DocumentImpl *doc)
: HTMLObjectBaseElementImpl(doc)
{
}
HTMLObjectElementImpl::~HTMLObjectElementImpl()
{
}
NodeImpl::Id HTMLObjectElementImpl::id() const
{
return ID_OBJECT;
}
HTMLFormElementImpl *HTMLObjectElementImpl::form() const
{
return 0;
}
void HTMLObjectElementImpl::parseAttribute(AttributeImpl *attr)
{
switch ( attr->id() )
{
case ATTR_DATA:
url = khtml::parseURL( attr->val() ).string();
needWidgetUpdate = true;
break;
case ATTR_CLASSID:
classId = attr->value().string();
needWidgetUpdate = true;
break;
case ATTR_ONLOAD: // ### support load/unload on object elements
setHTMLEventListener(EventImpl::LOAD_EVENT,
getDocument()->createHTMLEventListener(attr->value().string(), "onload", this));
break;
case ATTR_ONUNLOAD:
setHTMLEventListener(EventImpl::UNLOAD_EVENT,
getDocument()->createHTMLEventListener(attr->value().string(), "onunload", this));
break;
case ATTR_VSPACE:
addCSSLength(CSS_PROP_MARGIN_TOP, attr->value());
addCSSLength(CSS_PROP_MARGIN_BOTTOM, attr->value());
break;
case ATTR_HSPACE:
addCSSLength(CSS_PROP_MARGIN_LEFT, attr->value());
addCSSLength(CSS_PROP_MARGIN_RIGHT, attr->value());
break;
case ATTR_ALIGN:
addHTMLAlignment( attr->value() );
break;
case ATTR_VALIGN:
addCSSProperty(CSS_PROP_VERTICAL_ALIGN, attr->value().lower() );
break;
default:
HTMLObjectBaseElementImpl::parseAttribute( attr );
}
}
DocumentImpl* HTMLObjectElementImpl::contentDocument() const
{
if ( !m_render ) return 0;
if ( !m_render->isWidget() ) return 0;
QWidget* widget = static_cast<RenderWidget*>( m_render )->widget();
if( widget && ::qt_cast<KHTMLView*>( widget ) )
return static_cast<KHTMLView*>( widget )->part()->xmlDocImpl();
return 0;
}
void HTMLObjectElementImpl::attach()
{
KHTMLView* w = getDocument()->view();
if (!w || !w->part()->pluginsEnabled())
m_renderAlternative = true;
HTMLObjectBaseElementImpl::attach();
}
// -------------------------------------------------------------------------
NodeImpl::Id HTMLParamElementImpl::id() const
{
return ID_PARAM;
}
void HTMLParamElementImpl::parseAttribute(AttributeImpl *attr)
{
switch( attr->id() )
{
case ATTR_VALUE:
m_value = attr->value().string();
break;
case ATTR_ID:
if (getDocument()->htmlMode() != DocumentImpl::XHtml) break;
// fall through
case ATTR_NAME:
m_name = attr->value().string();
// fall through
default:
HTMLElementImpl::parseAttribute(attr);
}
}
#include "html_objectimpl.moc"
|