html_baseimpl.cpp 24.8 KB
Newer Older
George Staikos's avatar
George Staikos committed
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
/**
 * 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-2003 Dirk Mueller (mueller@kde.org)
 *
 * 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_baseimpl.h"
#include "html/html_documentimpl.h"

#include "khtmlview.h"
#include "khtml_part.h"
31
#include "khtmlpart_p.h"
George Staikos's avatar
George Staikos committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

#include "rendering/render_frames.h"
#include "rendering/render_body.h"
#include "css/cssstyleselector.h"
#include "css/css_stylesheetimpl.h"
#include "css/cssproperties.h"
#include "css/cssvalues.h"
#include "misc/loader.h"
#include "dom/dom_string.h"
#include "dom/dom_doc.h"
#include "xml/dom2_eventsimpl.h"

#include <kurl.h>
#include <kdebug.h>

using namespace DOM;
using namespace khtml;

Germain Garand's avatar
Germain Garand committed
50
HTMLBodyElementImpl::HTMLBodyElementImpl(DocumentImpl *doc)
George Staikos's avatar
George Staikos committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    : HTMLElementImpl(doc),
    m_bgSet( false ), m_fgSet( false )
{
    m_styleSheet = 0;
}

HTMLBodyElementImpl::~HTMLBodyElementImpl()
{
    if(m_styleSheet) m_styleSheet->deref();
}

NodeImpl::Id HTMLBodyElementImpl::id() const
{
    return ID_BODY;
}

void HTMLBodyElementImpl::parseAttribute(AttributeImpl *attr)
{
    switch(attr->id())
    {

    case ATTR_BACKGROUND:
    {
74
        QString url = attr->value().trimSpaces().string();
George Staikos's avatar
George Staikos committed
75
        if (!url.isEmpty()) {
76
            url = document()->completeURL( url );
George Staikos's avatar
George Staikos committed
77 78 79 80 81 82 83 84 85 86
            addCSSProperty(CSS_PROP_BACKGROUND_IMAGE, DOMString("url('"+url+"')") );
            m_bgSet = true;
        }
        else {
             removeCSSProperty(CSS_PROP_BACKGROUND_IMAGE);
             m_bgSet = false;
         }
        break;
    }
    case ATTR_MARGINWIDTH: {
87
	KHTMLView* w = document()->view();
George Staikos's avatar
George Staikos committed
88 89 90 91 92 93 94 95 96
	if (w)
	    w->setMarginWidth( -1 ); // unset this, so it doesn't override the setting here
        addCSSLength(CSS_PROP_MARGIN_RIGHT, attr->value() );
    }
        /* nobreak; */
    case ATTR_LEFTMARGIN:
        addCSSLength(CSS_PROP_MARGIN_LEFT, attr->value() );
        break;
    case ATTR_MARGINHEIGHT: {
97
	KHTMLView* w = document()->view();
George Staikos's avatar
George Staikos committed
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
	if (w)
	    w->setMarginHeight( -1 ); // unset this, so it doesn't override the setting here
        addCSSLength(CSS_PROP_MARGIN_BOTTOM, attr->value());
    }
        /* nobreak */
    case ATTR_TOPMARGIN:
        addCSSLength(CSS_PROP_MARGIN_TOP, attr->value());
        break;
    case ATTR_BGCOLOR:
        addHTMLColor(CSS_PROP_BACKGROUND_COLOR, attr->value());
        m_bgSet = !attr->value().isNull();
        break;
    case ATTR_TEXT:
        addHTMLColor(CSS_PROP_COLOR, attr->value());
        m_fgSet = !attr->value().isNull();
        break;
    case ATTR_BGPROPERTIES:
        if ( strcasecmp( attr->value(), "fixed" ) == 0)
            addCSSProperty(CSS_PROP_BACKGROUND_ATTACHMENT, CSS_VAL_FIXED);
        break;
    case ATTR_VLINK:
    case ATTR_ALINK:
    case ATTR_LINK:
    {
        if(!m_styleSheet) {
123
            m_styleSheet = new CSSStyleSheetImpl(this,DOMString(),true /*implicit*/);
George Staikos's avatar
George Staikos committed
124 125 126 127 128 129 130 131 132 133
            m_styleSheet->ref();
        }
        QString aStr;
	if ( attr->id() == ATTR_LINK )
	    aStr = "a:link";
	else if ( attr->id() == ATTR_VLINK )
	    aStr = "a:visited";
	else if ( attr->id() == ATTR_ALINK )
	    aStr = "a:active";
	aStr += " { color: " + attr->value().string() + "; }";
134
        m_styleSheet->parseString(aStr, false);
George Staikos's avatar
George Staikos committed
135
        if (attached())
136
            document()->updateStyleSelector();
George Staikos's avatar
George Staikos committed
137 138 139
        break;
    }
    case ATTR_ONLOAD:
140 141
        document()->setHTMLWindowEventListener(EventImpl::LOAD_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onload", NULL));
George Staikos's avatar
George Staikos committed
142 143
        break;
    case ATTR_ONUNLOAD:
144 145
        document()->setHTMLWindowEventListener(EventImpl::UNLOAD_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onunload", NULL));
George Staikos's avatar
George Staikos committed
146 147
        break;
    case ATTR_ONBLUR:
148 149
        document()->setHTMLWindowEventListener(EventImpl::BLUR_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onblur", NULL));
George Staikos's avatar
George Staikos committed
150 151
        break;
    case ATTR_ONFOCUS:
152 153
        document()->setHTMLWindowEventListener(EventImpl::FOCUS_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onfocus", NULL));
George Staikos's avatar
George Staikos committed
154 155
        break;
    case ATTR_ONRESIZE:
156 157
        document()->setHTMLWindowEventListener(EventImpl::RESIZE_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onresize", NULL));
George Staikos's avatar
George Staikos committed
158
        break;
Maks Orlovich's avatar
Maks Orlovich committed
159
    case ATTR_ONKEYUP:
160 161
        document()->setHTMLWindowEventListener(EventImpl::KEYUP_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onkeyup", NULL));
Maks Orlovich's avatar
Maks Orlovich committed
162 163
        break;
    case ATTR_ONKEYDOWN:
164 165
        document()->setHTMLWindowEventListener(EventImpl::KEYDOWN_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onkeydown", NULL));
Maks Orlovich's avatar
Maks Orlovich committed
166 167
        break;
    case ATTR_ONKEYPRESS:
168 169
        document()->setHTMLWindowEventListener(EventImpl::KEYPRESS_EVENT,
	    document()->createHTMLEventListener(attr->value().string(), "onkeypress", NULL));
Maks Orlovich's avatar
Maks Orlovich committed
170
        break;
171
    case ATTR_ONSCROLL:
172 173
        document()->setHTMLWindowEventListener(EventImpl::SCROLL_EVENT,
            document()->createHTMLEventListener(attr->value().string(), "onscroll", NULL));
174
        break;
Maks Orlovich's avatar
Maks Orlovich committed
175 176 177 178
    case ATTR_ONMESSAGE:
        document()->setHTMLWindowEventListener(EventImpl::MESSAGE_EVENT,
            document()->createHTMLEventListener(attr->value().string(), "onmessage", NULL));
        break;        
179 180 181 182
    case ATTR_ONHASHCHANGE:
        document()->setHTMLWindowEventListener(EventImpl::HASHCHANGE_EVENT,
            document()->createHTMLEventListener(attr->value().string(), "onhashchange", NULL));
        break;
George Staikos's avatar
George Staikos committed
183 184 185 186 187 188 189 190 191 192 193
    case ATTR_NOSAVE:
	break;
    default:
        HTMLElementImpl::parseAttribute(attr);
    }
}

void HTMLBodyElementImpl::insertedIntoDocument()
{
    HTMLElementImpl::insertedIntoDocument();

194
    KHTMLView* w = document()->view();
George Staikos's avatar
George Staikos committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    if(w && w->marginWidth() != -1) {
        QString s;
        s.sprintf( "%d", w->marginWidth() );
        addCSSLength(CSS_PROP_MARGIN_LEFT, s);
        addCSSLength(CSS_PROP_MARGIN_RIGHT, s);
    }
    if(w && w->marginHeight() != -1) {
        QString s;
        s.sprintf( "%d", w->marginHeight() );
        addCSSLength(CSS_PROP_MARGIN_TOP, s);
        addCSSLength(CSS_PROP_MARGIN_BOTTOM, s);
    }

    if ( m_bgSet && !m_fgSet )
        addCSSProperty(CSS_PROP_COLOR, CSS_VAL_BLACK);

    if (m_styleSheet)
212
        document()->updateStyleSelector();
George Staikos's avatar
George Staikos committed
213 214 215 216 217 218 219
}

void HTMLBodyElementImpl::removedFromDocument()
{
    HTMLElementImpl::removedFromDocument();

    if (m_styleSheet)
220
        document()->updateStyleSelector();
George Staikos's avatar
George Staikos committed
221 222 223 224 225 226 227
}

void HTMLBodyElementImpl::attach()
{
    assert(!m_render);
    assert(parentNode());

228
    RenderStyle* style = document()->styleSelector()->styleForElement(this);
George Staikos's avatar
George Staikos committed
229
    style->ref();
230 231
    if (parentNode()->renderer() && parentNode()->renderer()->childAllowed()
                                 && style->display() != NONE) {
George Staikos's avatar
George Staikos committed
232 233
        if (style->display() == BLOCK)
            // only use the quirky class for block display
234
            m_render = new (document()->renderArena()) RenderBody(this);
George Staikos's avatar
George Staikos committed
235 236 237 238 239 240 241 242 243 244 245 246
        else
            m_render = RenderObject::createObject(this, style);
        m_render->setStyle(style);
        parentNode()->renderer()->addChild(m_render, nextRenderer());
    }
    style->deref();

    NodeBaseImpl::attach();
}

// -------------------------------------------------------------------------

Germain Garand's avatar
Germain Garand committed
247
HTMLFrameElementImpl::HTMLFrameElementImpl(DocumentImpl *doc)
248
    : HTMLPartContainerElementImpl(doc)
George Staikos's avatar
George Staikos committed
249 250 251 252 253
{
    frameBorder = true;
    frameBorderSet = false;
    marginWidth = -1;
    marginHeight = -1;
254
    scrolling = Qt::ScrollBarAsNeeded;
George Staikos's avatar
George Staikos committed
255
    noresize = false;
256
    url = QLatin1String("about:blank");;
George Staikos's avatar
George Staikos committed
257 258 259 260 261 262 263 264 265 266 267
}

HTMLFrameElementImpl::~HTMLFrameElementImpl()
{
}

NodeImpl::Id HTMLFrameElementImpl::id() const
{
    return ID_FRAME;
}

268 269
void HTMLFrameElementImpl::ensureUniqueName()
{
270 271 272
    // If we already have a name, don't do anything.
    if (!name.isEmpty())
        return;
273

274 275 276 277 278 279 280
    // Use the specified name first..
    name = getAttribute(ATTR_NAME);
    if (name.isNull())
        name = getAttribute(ATTR_ID);

    // Generate synthetic name if there isn't a natural one or
    // if the natural one conflicts
281
    KHTMLPart* parentPart = document()->part();
282 283 284 285 286
    
    // If there is no part, we will not load anything, so no 
    // worry about names being unique or not.
    if (!parentPart)
        return;
287 288 289

    KHTMLPart* otherFrame = parentPart->findFrame( name.string() );
    if (name.isEmpty() || (otherFrame && otherFrame != contentPart()))
290
        name = DOMString(parentPart->requestFrameName());
291 292 293

    // Make sure we're registered properly.
    parentPart->d->renameFrameForContainer(this, name.string());
294 295
}

Germain Garand's avatar
Germain Garand committed
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
void HTMLFrameElementImpl::defaultEventHandler(EventImpl *e)
{
     // ### duplicated in HTMLObjectBaseElementImpl
     if ( e->target() == this && m_render && m_render->isWidget() 
                                    && static_cast<RenderWidget*>(m_render)->isRedirectedWidget() 
                                    && qobject_cast<KHTMLView*>(static_cast<RenderWidget*>(m_render)->widget())) {
        switch(e->id())  {
        case EventImpl::MOUSEDOWN_EVENT:
        case EventImpl::MOUSEUP_EVENT:
        case EventImpl::MOUSEMOVE_EVENT:
        case EventImpl::MOUSEOUT_EVENT:
        case EventImpl::MOUSEOVER_EVENT:
        case EventImpl::KHTML_MOUSEWHEEL_EVENT:
        case EventImpl::KEYDOWN_EVENT:
        case EventImpl::KEYUP_EVENT:
        case EventImpl::KEYPRESS_EVENT:
        case EventImpl::DOMFOCUSIN_EVENT:
        case EventImpl::DOMFOCUSOUT_EVENT:
            if (static_cast<RenderWidget*>(m_render)->handleEvent(*e))
                e->setDefaultHandled();
        default:
            break;
        }
    }
    HTMLPartContainerElementImpl::defaultEventHandler(e);
}

George Staikos's avatar
George Staikos committed
323 324 325 326 327
void HTMLFrameElementImpl::parseAttribute(AttributeImpl *attr)
{
    switch(attr->id())
    {
    case ATTR_SRC:
328
        setLocation(attr->value().trimSpaces().string());
George Staikos's avatar
George Staikos committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
        break;
    case ATTR_FRAMEBORDER:
    {
        frameBorder = attr->value().toInt();
        frameBorderSet = ( attr->val() != 0 );
        // FIXME: when attached, has no effect
    }
    break;
    case ATTR_MARGINWIDTH:
        marginWidth = attr->val()->toInt();
        // FIXME: when attached, has no effect
        break;
    case ATTR_MARGINHEIGHT:
        marginHeight = attr->val()->toInt();
        // FIXME: when attached, has no effect
        break;
    case ATTR_NORESIZE:
        noresize = true;
        // FIXME: when attached, has no effect
        break;
    case ATTR_SCROLLING:
        if( strcasecmp( attr->value(), "auto" ) == 0 )
351
            scrolling = Qt::ScrollBarAsNeeded;
George Staikos's avatar
George Staikos committed
352
        else if( strcasecmp( attr->value(), "yes" ) == 0 )
353
            scrolling = Qt::ScrollBarAlwaysOn;
George Staikos's avatar
George Staikos committed
354
        else if( strcasecmp( attr->value(), "no" ) == 0 )
355
            scrolling = Qt::ScrollBarAlwaysOff;
George Staikos's avatar
George Staikos committed
356 357 358 359
        // when attached, has no effect
        break;
    case ATTR_ONLOAD:
        setHTMLEventListener(EventImpl::LOAD_EVENT,
360
            document()->createHTMLEventListener(attr->value().string(), "onload", this));
George Staikos's avatar
George Staikos committed
361 362 363
        break;
    case ATTR_ONUNLOAD:
        setHTMLEventListener(EventImpl::UNLOAD_EVENT,
364
            document()->createHTMLEventListener(attr->value().string(), "onunload", this));
George Staikos's avatar
George Staikos committed
365 366 367 368 369 370 371 372 373 374 375
        break;
    default:
        HTMLElementImpl::parseAttribute(attr);
    }
}

void HTMLFrameElementImpl::attach()
{
    assert(!attached());
    assert(parentNode());

376
    computeContentIfNeeded();
George Staikos's avatar
George Staikos committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391

    // inherit default settings from parent frameset
    HTMLElementImpl* node = static_cast<HTMLElementImpl*>(parentNode());
    while(node)
    {
        if(node->id() == ID_FRAMESET)
        {
            HTMLFrameSetElementImpl* frameset = static_cast<HTMLFrameSetElementImpl*>(node);
            if(!frameBorderSet)  frameBorder = frameset->frameBorder();
            if(!noresize)  noresize = frameset->noResize();
            break;
        }
        node = static_cast<HTMLElementImpl*>(node->parentNode());
    }

392
    if (parentNode()->renderer() && parentNode()->renderer()->childAllowed()
393
                                 && document()->isURLAllowed(url))  {
394
        RenderStyle* _style = document()->styleSelector()->styleForElement(this);
George Staikos's avatar
George Staikos committed
395 396
        _style->ref();
        if ( _style->display() != NONE ) {
397
            m_render = new (document()->renderArena()) RenderFrame(this);
George Staikos's avatar
George Staikos committed
398 399 400 401 402 403
            m_render->setStyle(_style);
            parentNode()->renderer()->addChild(m_render, nextRenderer());
        }
        _style->deref();
    }

404 405 406
    // If we already have a widget, set it.
    if (m_render && childWidget())
        static_cast<RenderFrame*>(m_render)->setWidget(childWidget());
George Staikos's avatar
George Staikos committed
407

408 409
    NodeBaseImpl::attach();
}
George Staikos's avatar
George Staikos committed
410

411 412 413 414
void HTMLFrameElementImpl::setWidgetNotify(QWidget* widget)
{
    if (m_render)
        static_cast<RenderFrame*>(m_render)->setWidget(widget);
George Staikos's avatar
George Staikos committed
415 416
}

417
void HTMLFrameElementImpl::computeContent()
George Staikos's avatar
George Staikos committed
418
{
419
    KHTMLPart* parentPart = document()->part();
George Staikos's avatar
George Staikos committed
420

421 422
    if (!parentPart)
        return;
George Staikos's avatar
George Staikos committed
423

424
    // Bail out on any disallowed URLs
425
    if( !document()->isURLAllowed(url) )
George Staikos's avatar
George Staikos committed
426 427
        return;

428 429 430 431 432
    // If we have a part already, make sure it's in the right spot...
    // (can happen if someone asks to change location while we're in process 
    // of loading the original one)
    if ( contentPart() ) {
        setLocation(url);
George Staikos's avatar
George Staikos committed
433 434 435
        return;
    }

436 437 438 439
    ensureUniqueName();    

    // Go ahead and load a part... We don't need to clear the widget here,
    // since the -frames- have their lifetime managed, using the name uniqueness.
440
    parentPart->loadFrameElement( this, url, name.string() );
441 442
}

443
void HTMLFrameElementImpl::setLocation( const QString& str )
444 445 446
{
    url = str;

447
    if( !document()->isURLAllowed(url) )
George Staikos's avatar
George Staikos committed
448 449
        return;

450 451 452
    // if we already have a child part, ask it to go there..
    KHTMLPart* childPart = contentPart();
    if ( childPart )
453
        childPart->openUrl( KUrl( document()->completeURL( url ) ) );
454 455
    else
        setNeedComputeContent(); // otherwise, request it.. 
George Staikos's avatar
George Staikos committed
456 457
}

458
bool HTMLFrameElementImpl::isFocusableImpl(FocusType ft) const
George Staikos's avatar
George Staikos committed
459
{
460 461 462
    if (m_render!=0)
        return true;
    return HTMLPartContainerElementImpl::isFocusableImpl(ft);
George Staikos's avatar
George Staikos committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
}

void HTMLFrameElementImpl::setFocus(bool received)
{
    HTMLElementImpl::setFocus(received);
    khtml::RenderFrame *renderFrame = static_cast<khtml::RenderFrame *>(m_render);
    if (!renderFrame || !renderFrame->widget())
	return;
    if (received)
	renderFrame->widget()->setFocus();
    else
	renderFrame->widget()->clearFocus();
}

DocumentImpl* HTMLFrameElementImpl::contentDocument() const
{
479
    if (!childWidget()) return 0;
George Staikos's avatar
George Staikos committed
480

481 482
    if (::qobject_cast<KHTMLView*>( childWidget() ) )
        return static_cast<KHTMLView*>( childWidget() )->part()->xmlDocImpl();
George Staikos's avatar
George Staikos committed
483

484 485 486 487 488 489 490 491 492
    return 0;
}

KHTMLPart*   HTMLFrameElementImpl::contentPart() const
{
    if (!childWidget()) return 0;

    if (::qobject_cast<KHTMLView*>( childWidget() ) )
        return static_cast<KHTMLView*>( childWidget() )->part();
George Staikos's avatar
George Staikos committed
493 494 495 496

    return 0;
}

497 498
// -------------------------------------------------------------------------

George Staikos's avatar
George Staikos committed
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
DOMString HTMLBodyElementImpl::aLink() const
{
    return getAttribute(ATTR_ALINK);
}

void HTMLBodyElementImpl::setALink( const DOMString &value )
{
    setAttribute(ATTR_ALINK, value);
}

DOMString HTMLBodyElementImpl::bgColor() const
{
    return getAttribute(ATTR_BGCOLOR);
}

void HTMLBodyElementImpl::setBgColor( const DOMString &value )
{
    setAttribute(ATTR_BGCOLOR, value);
}

DOMString HTMLBodyElementImpl::link() const
{
    return getAttribute(ATTR_LINK);
}

void HTMLBodyElementImpl::setLink( const DOMString &value )
{
    setAttribute(ATTR_LINK, value);
}

DOMString HTMLBodyElementImpl::text() const
{
    return getAttribute(ATTR_TEXT);
}

void HTMLBodyElementImpl::setText( const DOMString &value )
{
    setAttribute(ATTR_TEXT, value);
}

DOMString HTMLBodyElementImpl::vLink() const
{
    return getAttribute(ATTR_VLINK);
}

void HTMLBodyElementImpl::setVLink( const DOMString &value )
{
    setAttribute(ATTR_VLINK, value);
}

// -------------------------------------------------------------------------

Germain Garand's avatar
Germain Garand committed
551
HTMLFrameSetElementImpl::HTMLFrameSetElementImpl(DocumentImpl *doc)
George Staikos's avatar
George Staikos committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
    : HTMLElementImpl(doc)
{
    // default value for rows and cols...
    m_totalRows = 1;
    m_totalCols = 1;

    m_rows = m_cols = 0;

    frameborder = true;
    frameBorderSet = false;
    m_border = 4;
    noresize = false;

    m_resizing = false;
}

HTMLFrameSetElementImpl::~HTMLFrameSetElementImpl()
{
    delete [] m_rows;
    delete [] m_cols;
}

NodeImpl::Id HTMLFrameSetElementImpl::id() const
{
    return ID_FRAMESET;
}

void HTMLFrameSetElementImpl::parseAttribute(AttributeImpl *attr)
{
    switch(attr->id())
    {
    case ATTR_ROWS:
        if (!attr->val()) break;
        delete [] m_rows;
        m_rows = attr->val()->toLengthArray(m_totalRows);
        setChanged();
    break;
    case ATTR_COLS:
        if (!attr->val()) break;
        delete [] m_cols;
        m_cols = attr->val()->toLengthArray(m_totalCols);
        setChanged();
    break;
    case ATTR_FRAMEBORDER:
        // false or "no" or "0"..
        if ( attr->value().toInt() == 0 ) {
            frameborder = false;
            m_border = 0;
        }
        frameBorderSet = true;
        break;
    case ATTR_NORESIZE:
        noresize = true;
        break;
    case ATTR_BORDER:
        m_border = attr->val()->toInt();
        if(!m_border)
            frameborder = false;
        break;
    case ATTR_ONLOAD:
Maks Orlovich's avatar
Maks Orlovich committed
612 613
        document()->setHTMLWindowEventListener(EventImpl::LOAD_EVENT,
            document()->createHTMLEventListener(attr->value().string(), "onload", NULL));
George Staikos's avatar
George Staikos committed
614 615
        break;
    case ATTR_ONUNLOAD:
Maks Orlovich's avatar
Maks Orlovich committed
616 617
        document()->setHTMLWindowEventListener(EventImpl::UNLOAD_EVENT,
            document()->createHTMLEventListener(attr->value().string(), "onunload", NULL));
George Staikos's avatar
George Staikos committed
618
        break;
Maks Orlovich's avatar
Maks Orlovich committed
619 620 621 622
    case ATTR_ONMESSAGE:
        document()->setHTMLWindowEventListener(EventImpl::MESSAGE_EVENT,
            document()->createHTMLEventListener(attr->value().string(), "onmessage", NULL));
        break;
George Staikos's avatar
George Staikos committed
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    default:
        HTMLElementImpl::parseAttribute(attr);
    }
}

void HTMLFrameSetElementImpl::attach()
{
    assert(!attached() );
    assert(parentNode());

    // inherit default settings from parent frameset
    HTMLElementImpl* node = static_cast<HTMLElementImpl*>(parentNode());
    while(node)
    {
        if(node->id() == ID_FRAMESET)
        {
            HTMLFrameSetElementImpl* frameset = static_cast<HTMLFrameSetElementImpl*>(node);
            if(!frameBorderSet)  frameborder = frameset->frameBorder();
            if(!noresize)  noresize = frameset->noResize();
            break;
        }
        node = static_cast<HTMLElementImpl*>(node->parentNode());
    }

647 648
    RenderStyle* _style = document()->styleSelector()->styleForElement(this);
    _style->ref();
George Staikos's avatar
George Staikos committed
649
    // ignore display: none
650
    if ( parentNode()->renderer() && parentNode()->renderer()->childAllowed() ) {
651
        m_render = new (document()->renderArena()) RenderFrameSet(this);
652 653
        m_render->setStyle(_style);
        parentNode()->renderer()->addChild(m_render, nextRenderer());
George Staikos's avatar
George Staikos committed
654
    }
655
    _style->deref();
George Staikos's avatar
George Staikos committed
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672

    NodeBaseImpl::attach();
}

void HTMLFrameSetElementImpl::defaultEventHandler(EventImpl *evt)
{
    if (evt->isMouseEvent() && !noresize && m_render)
        static_cast<khtml::RenderFrameSet *>(m_render)->userResize(static_cast<MouseEventImpl*>(evt));

    evt->setDefaultHandled();
    HTMLElementImpl::defaultEventHandler(evt);
}

void HTMLFrameSetElementImpl::detach()
{
    if(attached())
        // ### send the event when we actually get removed from the doc instead of here
673
        document()->dispatchHTMLEvent(EventImpl::UNLOAD_EVENT,false,false);
George Staikos's avatar
George Staikos committed
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705

    HTMLElementImpl::detach();
}

void HTMLFrameSetElementImpl::recalcStyle( StyleChange ch )
{
    if (changed() && m_render) {
        m_render->setNeedsLayout(true);
//         m_render->layout();
        setChanged(false);
    }
    HTMLElementImpl::recalcStyle( ch );
}


// -------------------------------------------------------------------------

NodeImpl::Id HTMLHeadElementImpl::id() const
{
    return ID_HEAD;
}

// -------------------------------------------------------------------------

NodeImpl::Id HTMLHtmlElementImpl::id() const
{
    return ID_HTML;
}


// -------------------------------------------------------------------------

Germain Garand's avatar
Germain Garand committed
706
HTMLIFrameElementImpl::HTMLIFrameElementImpl(DocumentImpl *doc) : HTMLFrameElementImpl(doc)
George Staikos's avatar
George Staikos committed
707 708 709 710
{
    frameBorder = false;
    marginWidth = 0;
    marginHeight = 0;
711
    m_frame = true;
George Staikos's avatar
George Staikos committed
712 713
}

714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
void HTMLIFrameElementImpl::insertedIntoDocument()
{
    HTMLFrameElementImpl::insertedIntoDocument();
    
    assert(!contentPart());
    setNeedComputeContent();
    computeContentIfNeeded(); // also clears
}

void HTMLIFrameElementImpl::removedFromDocument()
{
    HTMLFrameElementImpl::removedFromDocument();
    clearChildWidget();
}

George Staikos's avatar
George Staikos committed
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
HTMLIFrameElementImpl::~HTMLIFrameElementImpl()
{
}

NodeImpl::Id HTMLIFrameElementImpl::id() const
{
    return ID_IFRAME;
}

void HTMLIFrameElementImpl::parseAttribute(AttributeImpl *attr )
{
    switch (  attr->id() )
    {
    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;
754 755 756
    case ATTR_ALIGN:
        addHTMLAlignment( attr->value() );
        break;
George Staikos's avatar
George Staikos committed
757
    case ATTR_SRC:
758
        url = attr->value().trimSpaces().string();
759
        setNeedComputeContent();
760 761 762 763 764 765 766 767
        // ### synchronously start the process?
        break;
    case ATTR_NAME:
        ensureUniqueName();
        break;
    case ATTR_ID:
        HTMLFrameElementImpl::parseAttribute( attr ); // want default ID handling
        ensureUniqueName();
George Staikos's avatar
George Staikos committed
768
        break;
769 770 771 772
    case ATTR_FRAMEBORDER:
    {
        m_frame = (!attr->val() || attr->value().toInt() > 0);
        if (attached()) updateFrame();
773
        break;
774
    }
George Staikos's avatar
George Staikos committed
775 776 777 778 779
    default:
        HTMLFrameElementImpl::parseAttribute( attr );
    }
}

780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
void HTMLIFrameElementImpl::updateFrame()
{
    if (m_frame) {
        addCSSProperty(CSS_PROP_BORDER_TOP_STYLE, CSS_VAL_OUTSET);
        addCSSProperty(CSS_PROP_BORDER_BOTTOM_STYLE, CSS_VAL_OUTSET);
        addCSSProperty(CSS_PROP_BORDER_LEFT_STYLE, CSS_VAL_OUTSET);
        addCSSProperty(CSS_PROP_BORDER_RIGHT_STYLE, CSS_VAL_OUTSET);
        addCSSLength(CSS_PROP_BORDER_WIDTH, "2");
    } else {
        addCSSProperty(CSS_PROP_BORDER_TOP_STYLE, CSS_VAL_NONE);
        addCSSProperty(CSS_PROP_BORDER_BOTTOM_STYLE, CSS_VAL_NONE);
        addCSSProperty(CSS_PROP_BORDER_LEFT_STYLE, CSS_VAL_NONE);
        addCSSProperty(CSS_PROP_BORDER_RIGHT_STYLE, CSS_VAL_NONE);
        removeCSSProperty(CSS_PROP_BORDER_WIDTH);
    }

}

George Staikos's avatar
George Staikos committed
798 799 800 801 802 803
void HTMLIFrameElementImpl::attach()
{
    assert(!attached());
    assert(!m_render);
    assert(parentNode());

804
    updateFrame();
George Staikos's avatar
George Staikos committed
805

806
    RenderStyle* style = document()->styleSelector()->styleForElement(this);
George Staikos's avatar
George Staikos committed
807
    style->ref();
808
    if (document()->isURLAllowed(url) && parentNode()->renderer()
809
        && parentNode()->renderer()->childAllowed() && style->display() != NONE) {
810
        m_render = new (document()->renderArena()) RenderPartObject(this);
George Staikos's avatar
George Staikos committed
811 812 813 814 815 816 817
        m_render->setStyle(style);
        parentNode()->renderer()->addChild(m_render, nextRenderer());
    }
    style->deref();

    NodeBaseImpl::attach();

818 819
    if (m_render && childWidget())
        static_cast<RenderPartObject*>(m_render)->setWidget(childWidget());
George Staikos's avatar
George Staikos committed
820 821
}

822
void HTMLIFrameElementImpl::computeContent()
George Staikos's avatar
George Staikos committed
823
{
824
    KHTMLPart* parentPart = document()->part();
825 826 827 828

    if (!parentPart)
        return;

829
    if (!document()->isURLAllowed(url))
830 831
        return;

832 833 834 835 836 837
    if (!inDocument()) {
        clearChildWidget();
        return;
    }

    // get our name in order..
838
    ensureUniqueName();
839 840

    // make sure "" is handled as about: blank
841
    QString effectiveURL = url;
842
    if (effectiveURL.isEmpty())
843
        effectiveURL = QLatin1String("about:blank");
844 845 846 847

    kDebug(6031) << "-> requesting:" << name.string() << effectiveURL << contentPart();
    
    parentPart->loadFrameElement(this, effectiveURL, name.string(), QStringList(), true);
George Staikos's avatar
George Staikos committed
848 849
}

850 851 852 853 854
void HTMLIFrameElementImpl::setWidgetNotify(QWidget* widget)
{
    if (m_render)
        static_cast<RenderPartObject*>(m_render)->setWidget(widget);
}
855 856

// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;