Commit 14b0d8ec authored by Allan Sandfeld Jensen's avatar Allan Sandfeld Jensen

Implement document.script(), sniffed in webcore-changes

svn path=/branches/KDE/3.5/kdelibs/; revision=552331
parent fad6ab43
/**
* This file is part of the DOM implementation for KDE.
*
* (C) 1999 Lars Knoll (knoll@kde.org)
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -152,6 +152,12 @@ HTMLCollection HTMLDocument::applets() const
return HTMLCollection(impl, HTMLCollectionImpl::DOC_APPLETS);
}
HTMLCollection HTMLDocument::scripts() const
{
if(!impl) return HTMLCollection();
return HTMLCollection(impl, HTMLCollectionImpl::DOC_SCRIPTS);
}
HTMLCollection HTMLDocument::links() const
{
if(!impl) return HTMLCollection();
......
......@@ -177,6 +177,12 @@ public:
*/
HTMLCollection layers() const;
/**
* A collection of all the scripts in the document.
*
*/
HTMLCollection scripts() const;
/**
* A collection of all the anchor ( \c A ) elements in
* a document with a value for the \c name attribute.
......
......@@ -289,22 +289,8 @@ Value KJS::HTMLDocument::tryGet(ExecState *exec, const Identifier &propertyName)
return getHTMLCollection(exec,doc.layers(), true);
case Anchors:
return getHTMLCollection(exec,doc.anchors());
case Scripts: // TODO (IE-specific)
{
// Disable document.scripts unless we try to be IE-compatible
// Especially since it's not implemented, so
// if (document.scripts) shouldn't return true.
if ( exec->interpreter()->compatMode() != Interpreter::IECompat )
return Undefined();
// To be implemented. Meanwhile, return an object with a length property set to 0
// This gets some code going on IE-specific pages.
// The script object isn't really simple to implement though
// (http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/script.asp)
kdDebug(6070) << "WARNING: KJS::HTMLDocument document.scripts called - not implemented" << endl;
Object obj( new ObjectImp() );
obj.put( exec, lengthPropertyName, Number(0) );
return obj;
}
case Scripts:
return getHTMLCollection(exec,doc.scripts());
case All:
// Disable document.all when we try to be Netscape-compatible
if ( exec->interpreter()->compatMode() == Interpreter::NetscapeCompat )
......
......@@ -91,6 +91,10 @@ bool HTMLCollectionImpl::nodeMatches(NodeImpl *current, bool& deep) const
if(e->id() == ID_IMG)
check = true;
break;
case DOC_SCRIPTS:
if(e->id() == ID_SCRIPT)
check = true;
break;
case DOC_FORMS:
if(e->id() == ID_FORM)
check = true;
......@@ -213,7 +217,7 @@ NodeImpl *HTMLCollectionImpl::item ( unsigned long index ) const
return NodeListImpl::item(index);
//For table.rows, we first need to check header, then bodies, then footer.
//we pack any extra headers/footer with bodies. This matches IE, and
//we pack any extra headers/footer with bodies. This matches IE, and
//means doing the usual thing with length is right
const HTMLTableElementImpl* table = static_cast<const HTMLTableElementImpl*>(m_refNode);
......@@ -396,8 +400,8 @@ NodeImpl *HTMLFormCollectionImpl::nextNamedItem( const DOMString &name ) const
}
// -------------------------------------------------------------------------
HTMLMappedNameCollectionImpl::HTMLMappedNameCollectionImpl(NodeImpl* _base, int _type, const DOMString& _name):
HTMLCollectionImpl(_base, NodeListImpl::UNCACHEABLE), name(_name)
HTMLMappedNameCollectionImpl::HTMLMappedNameCollectionImpl(NodeImpl* _base, int _type, const DOMString& _name):
HTMLCollectionImpl(_base, NodeListImpl::UNCACHEABLE), name(_name)
{
type = _type; //We pass uncacheable to collection, but need our own type internally.
}
......@@ -411,7 +415,7 @@ bool HTMLMappedNameCollectionImpl::nodeMatches(NodeImpl *current, bool& deep) co
}
HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current);
return matchesName(e, type, name);
}
......
......@@ -57,6 +57,7 @@ public:
DOC_LAYERS, // all LAYERS
DOC_LINKS, // all A _and_ AREA elements with a value for href
DOC_ANCHORS, // all A elements with a value for name
DOC_SCRIPTS, // all SCRIPT elements
// from HTMLTable, HTMLTableSection, HTMLTableRow
TABLE_ROWS, // all rows in this table
TABLE_TBODIES, // all TBODY elements in this table
......@@ -93,7 +94,7 @@ public:
}
protected:
virtual unsigned long calcLength(NodeImpl *start) const;
// The collection list the following elements
int type:8;
......@@ -130,7 +131,7 @@ private:
};
/*
Special collection for items of given name/id under document. or window.; but using
Special collection for items of given name/id under document. or window.; but using
iteration interface
*/
class HTMLMappedNameCollectionImpl : public HTMLCollectionImpl
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment