void HTMLDocumentImpl::close()
{
    bool doload = !parsing() && m_tokenizer;

    DocumentImpl::close();

    HTMLElementImpl* b = body();
    if (b && doload) {
        // According to dom the load event must not bubble
        // but other browsers execute in a frameset document
        // the first(IE)/last(Moz/Konq) registered onload on a <frame> and the
        // first(IE)/last(Moz/Konq) registered onload on a <frameset>.

        // The body has the listener for <frame onload>
        b->dispatchWindowEvent(EventImpl::LOAD_EVENT, false, false);

        b = body(); // the onload code could have changed it (e.g. document.open/write/close)

        // The document has the listener for <frameset onload>
        if (b && b->id() == ID_FRAMESET)
            getDocument()->dispatchWindowEvent(EventImpl::LOAD_EVENT, false, false);

        // don't update rendering if we're going to redirect anyway
        if ( view() && ( view()->part()->d->m_redirectURL.isNull() ||
                         view()->part()->d->m_delayRedirect > 1 ) )
        updateRendering();
    }
}
void HTMLTableCellElementImpl::attach(KHTMLView *_view)
{
    HTMLElementImpl* p = static_cast<HTMLElementImpl*>(_parent);
    while(p && p->id() != ID_TABLE)
        p = static_cast<HTMLElementImpl*>(p->parentNode());

    if(p) {
        HTMLTableElementImpl* table = static_cast<HTMLTableElementImpl*>(p);

        if(table->m_noBorder && getAttribute(ATTR_BORDER).isNull())
            addCSSProperty(CSS_PROP_BORDER_WIDTH, "0px");
        if(!table->getAttribute(ATTR_BORDERCOLOR).isNull())
            addCSSProperty(CSS_PROP_BORDER_STYLE, "solid");
    }

    setStyle(document->styleSelector()->styleForElement(this));
    khtml::RenderObject *r = _parent->renderer();
    if(r)
    {
	m_render = khtml::RenderObject::createObject(this);
	if(m_render && m_render->style()->display() == TABLE_CELL)
	{
	    RenderTableCell *cell = static_cast<RenderTableCell *>(m_render);
	    cell->setRowSpan(rSpan);
	    cell->setColSpan(cSpan);
            cell->setNoWrap(nWrap);
	}
	if(m_render) r->addChild(m_render, _next ? _next->renderer() : 0);
    }

    NodeBaseImpl::attach(_view);
}
void HTMLFrameSetElementImpl::attach()
{
    assert(!m_render);
    assert(parentNode());
    assert(parentNode()->renderer());

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

    // ignore display: none
    m_render = new RenderFrameSet(this);
    m_render->setStyle(getDocument()->styleSelector()->styleForElement(this));
    parentNode()->renderer()->addChild(m_render, nextRenderer());

    NodeBaseImpl::attach();
}
void HTMLTableCellElementImpl::attach()
{
    HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parentNode());
    while(p && p->id() != ID_TABLE)
        p = static_cast<HTMLElementImpl*>(p->parentNode());

    if(p) {
        HTMLTableElementImpl* table = static_cast<HTMLTableElementImpl*>(p);
        if (table->m_noBorder) {
            addCSSProperty(CSS_PROP_BORDER_WIDTH, "0");
        }
        else {
            addCSSProperty(CSS_PROP_BORDER_WIDTH, "1px");
            int v = (table->m_solid || m_solid) ? CSS_VAL_SOLID : CSS_VAL_INSET;
            addCSSProperty(CSS_PROP_BORDER_TOP_STYLE, v);
            addCSSProperty(CSS_PROP_BORDER_BOTTOM_STYLE, v);
            addCSSProperty(CSS_PROP_BORDER_LEFT_STYLE, v);
            addCSSProperty(CSS_PROP_BORDER_RIGHT_STYLE, v);

            if (!m_solid)
                addCSSProperty(CSS_PROP_BORDER_COLOR, "inherit");
        }
    }

    HTMLTablePartElementImpl::attach();
}
void HTMLTableCellElementImpl::attach()
{
    HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parentNode());
    while(p && p->id() != ID_TABLE)
        p = static_cast<HTMLElementImpl*>(p->parentNode());

    HTMLTablePartElementImpl::attach();
}
unsigned long HTMLFormCollectionImpl::calcLength(NodeImpl*) const
{
    if(base->nodeType() == Node::ELEMENT_NODE)
    {
        HTMLElementImpl* e = static_cast<HTMLElementImpl*>(base);
        if(e->id() == ID_FORM)
            return static_cast<HTMLFormElementImpl*>(e)->formElements.count();
    }

    return 0;
}
Exemple #7
0
void HTMLFrameElementImpl::attach()
{
    assert(!attached());
    assert(parentNode());

    name = getAttribute(ATTR_NAME);
    if(name.isNull())
        name = getAttribute(ATTR_ID);

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

    if(parentNode()->renderer() && getDocument()->isURLAllowed(url.string()))
    {
        RenderStyle *_style = getDocument()->styleSelector()->styleForElement(this);
        _style->ref();
        if(_style->display() != NONE)
        {
            m_render = new(getDocument()->renderArena()) RenderFrame(this);
            m_render->setStyle(_style);
            parentNode()->renderer()->addChild(m_render, nextRenderer());
        }
        _style->deref();
    }

    NodeBaseImpl::attach();

    if(!m_render)
        return;

    KHTMLView *w = getDocument()->view();
    if(w)
    {
        // we need a unique name for every frame in the frameset. Hope that's unique enough.
        if(name.isEmpty() || w->part()->frameExists(name.string()))
            name = DOMString(w->part()->requestFrameName());

        // load the frame contents
        w->part()->requestFrame(static_cast< RenderFrame * >(m_render), url.string(), name.string());
    }
}
NodeImpl* HTMLFormCollectionImpl::getItem(NodeImpl *, int index, int&) const
{
    if(base->nodeType() == Node::ELEMENT_NODE)
    {
        HTMLElementImpl* e = static_cast<HTMLElementImpl*>(base);
        if(e->id() == ID_FORM)
            return static_cast<HTMLFormElementImpl*>(e)->formElements.at(index);

    }

    return 0;
}
// used by table cells to share style decls created by the enclosing table.
CSSMutableStyleDeclarationImpl* HTMLTableCellElementImpl::additionalAttributeStyleDecl()
{
    HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parentNode());
    while(p && p->id() != ID_TABLE)
        p = static_cast<HTMLElementImpl*>(p->parentNode());

    if (p) {
        HTMLTableElementImpl* table = static_cast<HTMLTableElementImpl*>(p);
        return table->getSharedCellDecl();
    }

    return 0;
}
void HTMLFrameElementImpl::attach()
{
    assert(!attached());
    assert(parentNode());
    assert(parentNode()->renderer());

    // we should first look up via id, then via name.
    // this shortterm hack fixes the ugly case. ### rewrite needed for next release
    name = getAttribute(ATTR_NAME);
    if (name.isNull())
        name = getAttribute(ATTR_ID);

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

    // ignore display: none for this element!
    KHTMLView* w = getDocument()->view();

    if (isURLAllowed(url.string()))  {
        m_render = new RenderFrame(this);
        m_render->setStyle(getDocument()->styleSelector()->styleForElement(this));
        parentNode()->renderer()->addChild(m_render, nextRenderer());
    }

    NodeBaseImpl::attach();

    if (!m_render)
        return;

    // we need a unique name for every frame in the frameset. Hope that's unique enough.
    if(name.isEmpty() || w->part()->frameExists( name.string() ) )
      name = DOMString(w->part()->requestFrameName());

    // load the frame contents
    w->part()->requestFrame( static_cast<RenderFrame*>(m_render), url.string(), name.string() );
}
NodeImpl* HTMLFormCollectionImpl::getNamedItem(NodeImpl*, int attr_id, const DOMString& name) const
{
    if(base->nodeType() == Node::ELEMENT_NODE)
    {
        HTMLElementImpl* e = static_cast<HTMLElementImpl*>(base);
        if(e->id() == ID_FORM)
        {
            HTMLGenericFormElementImpl* element;
            HTMLFormElementImpl* f = static_cast<HTMLFormElementImpl*>(e);

            for(element = f->formElements.first(); element; element = f->formElements.next())
                if(element->getAttribute(attr_id) == name)
                    return element;
        }
    }

    return 0;
}
unsigned long HTMLCollectionImpl::calcLength(NodeImpl *current) const
{
    unsigned long len = 0;
    while(current)
    {
	if(current->nodeType() == Node::ELEMENT_NODE)
	{
	    bool deep = true;
	    HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current);
	    switch(type)
	    {
	    case DOC_IMAGES:
		if(e->id() == ID_IMG)
		    len++;
		break;
	    case DOC_FORMS:
		if(e->id() == ID_FORM)
		    len++;
		break;
	    case TABLE_TBODIES:
		if(e->id() == ID_TBODY)
		    len++;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case TR_CELLS:
		if(e->id() == ID_TD)
		    len++;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case TABLE_ROWS:
	    case TSECTION_ROWS:
		if(e->id() == ID_TR || e->id() == ID_TH)
		    len++;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case SELECT_OPTIONS:
		if(e->id() == ID_OPTION)
		    len++;
		break;
	    case MAP_AREAS:
		if(e->id() == ID_AREA)
		    len++;
		break;
	    case DOC_APPLETS:   // all OBJECT and APPLET elements
		if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
		    len++;
		break;
	    case DOC_LINKS:     // all A _and_ AREA elements with a value for href
		if(e->id() == ID_A || e->id() == ID_AREA)
		    if(e->getAttribute(ATTR_HREF) != 0)
			len++;
		break;
	    case DOC_ANCHORS:      // all A elements with a value for name and all elements with an id attribute
		if ( e->hasID() )
		    len++;
		else if(e->id() == ID_A) {
		    if(e->getAttribute(ATTR_NAME) != 0)
			len++;
		}  
		break;
	    case DOC_ALL:      // "all" elements
		len++;
		break;
	    default:
		kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl;
	    }
	    if(deep && current->firstChild())
		len += calcLength(current->firstChild());
	}
	current = current->nextSibling();
    }
    return len;
}
NodeImpl *HTMLCollectionImpl::getNamedItem( NodeImpl *current, int attr_id,
					    const DOMString &name ) const
{
    if(name.isEmpty())
	return 0;

    while(current)
    {
	if(current->nodeType() == Node::ELEMENT_NODE)
	{
	    bool deep = true;
	    bool check = false;
	    HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current);
	    switch(type)
	    {
	    case DOC_IMAGES:
		if(e->id() == ID_IMG)
		    check = true;
		break;
	    case DOC_FORMS:
		if(e->id() == ID_FORM)
		    check = true;
		break;
	    case TABLE_TBODIES:
		if(e->id() == ID_TBODY)
		    check = true;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case TR_CELLS:
		if(e->id() == ID_TD)
		    check = true;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case TABLE_ROWS:
	    case TSECTION_ROWS:
		if(e->id() == ID_TR || e->id() == ID_TH)
		    check = true;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case SELECT_OPTIONS:
		if(e->id() == ID_OPTION)
		    check = true;
		break;
	    case MAP_AREAS:
		if(e->id() == ID_AREA)
		    check = true;
		break;
	    case DOC_APPLETS:   // all OBJECT and APPLET elements
		if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
		    check = true;
		break;
	    case DOC_LINKS:     // all A _and_ AREA elements with a value for href
		if(e->id() == ID_A || e->id() == ID_AREA)
		    if(e->getAttribute(ATTR_HREF) != 0)
			check = true;
		break;
	    case DOC_ANCHORS:      // all A elements with a value for name
		if( e->hasID() )
		    check = true;
		else if(e->id() == ID_A)
		    if(e->getAttribute(ATTR_NAME) != 0)
			check = true;
		break;
	    case DOC_ALL:
		check = true;
		break;
	    default:
		kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl;
		break;
	    }
	    if(check && e->getAttribute(attr_id) == name)
	    {
		//kdDebug( 6030 ) << "found node: " << e << " " << current << " " << e->id() << endl;
		return current;
	    }
	    NodeImpl *retval = 0;
	    if(deep && current->firstChild())
		retval = getNamedItem(current->firstChild(), attr_id, name);
	    if(retval)
	    {
		//kdDebug( 6030 ) << "got a return value " << retval << endl;
		return retval;
	    }
	}
	current = current->nextSibling();
    }
    return 0;
}
NodeImpl *HTMLCollectionImpl::getItem(NodeImpl *current, int index, int &len) const
{
    while(current)
    {
	if(current->nodeType() == Node::ELEMENT_NODE)
	{
	    bool deep = true;
	    HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current);
	    switch(type)
	    {
	    case DOC_IMAGES:
		if(e->id() == ID_IMG)
		    len++;
		break;
	    case DOC_FORMS:
		if(e->id() == ID_FORM)
		    len++;
		break;
	    case TABLE_TBODIES:
		if(e->id() == ID_TBODY)
		    len++;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case TR_CELLS:
		if(e->id() == ID_TD)
		    len++;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case TABLE_ROWS:
	    case TSECTION_ROWS:
		if(e->id() == ID_TR || e->id() == ID_TH)
		    len++;
		else if(e->id() == ID_TABLE)
		    deep = false;
		break;
	    case SELECT_OPTIONS:
		if(e->id() == ID_OPTION)
		    len++;
		break;
	    case MAP_AREAS:
		if(e->id() == ID_AREA)
		    len++;
		break;
	    case DOC_APPLETS:   // all OBJECT and APPLET elements
		if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
		    len++;
		break;
	    case DOC_LINKS:     // all A _and_ AREA elements with a value for href
		if(e->id() == ID_A || e->id() == ID_AREA)
		    if(e->getAttribute(ATTR_HREF) != 0)
			len++;
		break;
	    case DOC_ANCHORS:      // all A elements with a value for name or an id attribute
		if( e->hasID() )
		    len++;
		else if(e->id() == ID_A)
		    if(e->getAttribute(ATTR_NAME) != 0)
			len++;
		break;
	    case DOC_ALL:
		len++;
		break;
	    default:
		kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl;
	    }
	    if(len == (index + 1)) return current;
	    NodeImpl *retval=0;
	    if(deep && current->firstChild())
		retval = getItem(current->firstChild(), index, len);
	    if(retval) return retval;
	}
	current = current->nextSibling();
    }
    return 0;
}