Commit 7a6a508d authored by oliver's avatar oliver
Browse files

2007-10-07 Sam Weinig <sam@webkit.org>

        Reviewed by Darin & Nikolas.  Landed by eseidel.

        Patch for http://bugs.webkit.org/show_bug.cgi?id=14455
        Autogenerate the JS bindings for the StyleSheetList

        * DerivedSources.make:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/JSStyleSheetListCustom.cpp: Added.
        (WebCore::JSStyleSheetList::canGetItemsForName):
        (WebCore::JSStyleSheetList::nameGetter):
        * bindings/js/kjs_css.cpp:
        * bindings/js/kjs_css.h:
        * bindings/objc/DOMUtility.mm:
        * bindings/scripts/CodeGeneratorJS.pm:
        * css/StyleSheetList.cpp:
        (WebCore::StyleSheetList::StyleSheetList):
        (WebCore::StyleSheetList::documentDestroyed):
        (WebCore::StyleSheetList::getNamedItem):
        * css/StyleSheetList.h: Add Document member variable and
        getNamedItem function to accommodate the odd javascript
        name getter functionality.
        * css/StyleSheetList.idl:
        * dom/Document.cpp:
        (WebCore::Document::Document):
        (WebCore::Document::~Document):
        * page/DOMWindow.idl: Add StyleSheetListConstructor



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@26509 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8de30256
2007-10-07 Sam Weinig <sam@webkit.org>
Reviewed by Darin and Nikolas. Landed by eseidel.
Update test for http://bugs.webkit.org/show_bug.cgi?id=14455
Autogenerate the JS bindings for the StyleSheetList
* fast/dom/Window/window-properties-expected.txt: Changed for new constructor.
2007-10-06 Nikolas Zimmermann <zimmermann@kde.org>
 
Reviewed by Mark.
......@@ -1078,6 +1078,9 @@ window.SVGUnitTypes.prototype.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX [number]
window.SVGUnitTypes.prototype.SVG_UNIT_TYPE_UNKNOWN [number]
window.SVGUnitTypes.prototype.SVG_UNIT_TYPE_USERSPACEONUSE [number]
window.StyleSheet [printed above as window.CSSStyleSheet]
window.StyleSheetList [object StyleSheetListConstructor]
window.StyleSheetList.prototype [object StyleSheetListPrototype]
window.StyleSheetList.prototype.item [function]
window.SyntaxError [function]
window.Text [object TextConstructor]
window.Text.prototype [printed above as window.CharacterData.prototype]
......
2007-10-07 Sam Weinig <sam@webkit.org>
Reviewed by Darin & Nikolas. Landed by eseidel.
Patch for http://bugs.webkit.org/show_bug.cgi?id=14455
Autogenerate the JS bindings for the StyleSheetList
* DerivedSources.make:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSStyleSheetListCustom.cpp: Added.
(WebCore::JSStyleSheetList::canGetItemsForName):
(WebCore::JSStyleSheetList::nameGetter):
* bindings/js/kjs_css.cpp:
* bindings/js/kjs_css.h:
* bindings/objc/DOMUtility.mm:
* bindings/scripts/CodeGeneratorJS.pm:
* css/StyleSheetList.cpp:
(WebCore::StyleSheetList::StyleSheetList):
(WebCore::StyleSheetList::documentDestroyed):
(WebCore::StyleSheetList::getNamedItem):
* css/StyleSheetList.h: Add Document member variable and
getNamedItem function to accommodate the odd javascript
name getter functionality.
* css/StyleSheetList.idl:
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::~Document):
* page/DOMWindow.idl: Add StyleSheetListConstructor
2007-10-07 Lars Naesbye Christensen <lars@naesbye.dk>
 
Reviewed by Eric Seidel.
......@@ -538,6 +538,7 @@ all : \
JSSVGZoomEvent.h \
JSScreen.h \
JSStyleSheet.h \
JSStyleSheetList.h \
JSText.h \
JSTextEvent.h \
JSTreeWalker.h \
......
......@@ -191,6 +191,7 @@ IDL_BINDINGS += \
css/MediaList.idl \
css/Rect.idl \
css/StyleSheet.idl \
css/StyleSheetList.idl \
dom/Attr.idl \
dom/CharacterData.idl \
dom/CDATASection.idl \
......@@ -332,6 +333,7 @@ SOURCES += \
bindings/js/JSNodeIteratorCustom.cpp \
bindings/js/JSNodeListCustom.cpp \
bindings/js/JSStyleSheetCustom.cpp \
bindings/js/JSStyleSheetListCustom.cpp \
bindings/js/JSTreeWalkerCustom.cpp \
bindings/js/JSXMLHttpRequest.cpp \
bindings/js/JSXSLTProcessor.cpp \
......
......@@ -1236,6 +1236,14 @@
RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSStyleSheet.h"
>
</File>
<File
RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSStyleSheetList.cpp"
>
</File>
<File
RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSStyleSheetList.h"
>
</File>
<File
RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSSVGAElement.cpp"
>
......@@ -7451,6 +7459,10 @@
RelativePath="..\bindings\js\JSStyleSheetCustom.cpp"
>
</File>
<File
RelativePath="..\bindings\js\JSStyleSheetListCustom.cpp"
>
</File>
<File
RelativePath="..\bindings\js\JSSVGElementWrapperFactory.cpp"
>
......
......@@ -1839,6 +1839,9 @@
A84942DA0B64A9CA0069F00F /* ColorDistance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A84942D80B64A9CA0069F00F /* ColorDistance.cpp */; };
A84947AD0B67F4A10069F00F /* SVGTransformDistance.h in Headers */ = {isa = PBXBuildFile; fileRef = A84947AB0B67F4A10069F00F /* SVGTransformDistance.h */; };
A84947AE0B67F4A10069F00F /* SVGTransformDistance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A84947AC0B67F4A10069F00F /* SVGTransformDistance.cpp */; };
A84EBD780CB8C89200079609 /* JSStyleSheetListCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A84EBD770CB8C89200079609 /* JSStyleSheetListCustom.cpp */; };
A84EBD830CB8C97700079609 /* JSStyleSheetList.h in Headers */ = {isa = PBXBuildFile; fileRef = A84EBD810CB8C97700079609 /* JSStyleSheetList.h */; };
A84EBD840CB8C97700079609 /* JSStyleSheetList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A84EBD820CB8C97700079609 /* JSStyleSheetList.cpp */; };
A86629CF09DA2B47009633A5 /* JSUIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A86629C909DA2B47009633A5 /* JSUIEvent.h */; };
A86629D009DA2B48009633A5 /* JSUIEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A86629CA09DA2B47009633A5 /* JSUIEvent.cpp */; };
A86629D109DA2B48009633A5 /* JSMouseEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A86629CB09DA2B47009633A5 /* JSMouseEvent.h */; };
......@@ -5792,6 +5795,9 @@
A84942D80B64A9CA0069F00F /* ColorDistance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorDistance.cpp; sourceTree = "<group>"; };
A84947AB0B67F4A10069F00F /* SVGTransformDistance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTransformDistance.h; sourceTree = "<group>"; };
A84947AC0B67F4A10069F00F /* SVGTransformDistance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTransformDistance.cpp; sourceTree = "<group>"; };
A84EBD770CB8C89200079609 /* JSStyleSheetListCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSStyleSheetListCustom.cpp; sourceTree = "<group>"; };
A84EBD810CB8C97700079609 /* JSStyleSheetList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStyleSheetList.h; sourceTree = "<group>"; };
A84EBD820CB8C97700079609 /* JSStyleSheetList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSStyleSheetList.cpp; sourceTree = "<group>"; };
A85D7A2F0879EBA9006A9172 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = /System/Library/Frameworks/QuartzCore.framework; sourceTree = "<absolute>"; };
A86629C909DA2B47009633A5 /* JSUIEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSUIEvent.h; sourceTree = "<group>"; };
A86629CA09DA2B47009633A5 /* JSUIEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSUIEvent.cpp; sourceTree = "<group>"; };
......@@ -7540,8 +7546,6 @@
14DFB33F0A7DF7630018F769 /* Derived Sources */ = {
isa = PBXGroup;
children = (
B22362260C3AF04A0008CA9B /* JSSVGTextPathElement.cpp */,
B22362270C3AF04A0008CA9B /* JSSVGTextPathElement.h */,
65DF31D809D1C122000BE325 /* JSAttr.cpp */,
65DF31D909D1C123000BE325 /* JSAttr.h */,
BC124EFD0C26447A009E2349 /* JSBarInfo.cpp */,
......@@ -7552,8 +7556,6 @@
65DF323609D1DE65000BE325 /* JSCanvasPattern.h */,
65DF323709D1DE65000BE325 /* JSCanvasRenderingContext2D.cpp */,
65DF323809D1DE65000BE325 /* JSCanvasRenderingContext2D.h */,
B266CD4B0C3AEC6500EB08D2 /* JSSVGException.cpp */,
B266CD4C0C3AEC6500EB08D2 /* JSSVGException.h */,
93F9B79E0BA6032600854064 /* JSCDATASection.cpp */,
93F9B79F0BA6032600854064 /* JSCDATASection.h */,
65DF31DF09D1CC60000BE325 /* JSCharacterData.cpp */,
......@@ -7766,6 +7768,8 @@
BCEC01C10C274DDD009F4EC9 /* JSScreen.h */,
BCE013980C0BEF180043860A /* JSStyleSheet.cpp */,
BCE013990C0BEF180043860A /* JSStyleSheet.h */,
A84EBD820CB8C97700079609 /* JSStyleSheetList.cpp */,
A84EBD810CB8C97700079609 /* JSStyleSheetList.h */,
B20111050AB7740500DB0E68 /* JSSVGAElement.cpp */,
B20111060AB7740500DB0E68 /* JSSVGAElement.h */,
B222F6960AB771950022EFAD /* JSSVGAngle.cpp */,
......@@ -7826,6 +7830,8 @@
B2CB923E0B5BD941009BAA78 /* JSSVGElementInstanceList.h */,
B2FA3C800AB75A6E000E5AC4 /* JSSVGEllipseElement.cpp */,
B2FA3C810AB75A6E000E5AC4 /* JSSVGEllipseElement.h */,
B266CD4B0C3AEC6500EB08D2 /* JSSVGException.cpp */,
B266CD4C0C3AEC6500EB08D2 /* JSSVGException.h */,
B2FA3C820AB75A6E000E5AC4 /* JSSVGFEBlendElement.cpp */,
B2FA3C830AB75A6E000E5AC4 /* JSSVGFEBlendElement.h */,
B2FA3C840AB75A6E000E5AC4 /* JSSVGFEColorMatrixElement.cpp */,
......@@ -7986,6 +7992,8 @@
B2FA3D1B0AB75A6F000E5AC4 /* JSSVGTextContentElement.h */,
B2FA3D1C0AB75A6F000E5AC4 /* JSSVGTextElement.cpp */,
B2FA3D1D0AB75A6F000E5AC4 /* JSSVGTextElement.h */,
B22362260C3AF04A0008CA9B /* JSSVGTextPathElement.cpp */,
B22362270C3AF04A0008CA9B /* JSSVGTextPathElement.h */,
B2FA3D1E0AB75A6F000E5AC4 /* JSSVGTextPositioningElement.cpp */,
B2FA3D1F0AB75A6F000E5AC4 /* JSSVGTextPositioningElement.h */,
B2FA3D200AB75A6F000E5AC4 /* JSSVGTitleElement.cpp */,
......@@ -10600,9 +10608,7 @@
8574D1F10ADE6122004CBA11 /* JSSVGElementWrapperFactory.cpp */,
8574D1F20ADE6122004CBA11 /* JSSVGElementWrapperFactory.h */,
B21127A50B3186770009BE53 /* JSSVGPODTypeWrapper.h */,
B2080A110B3CA3B600120852 /* JSSVGPointListCustom.cpp */,
B2D3FC890C2212CB00CF3618 /* JSSVGTransformListCustom.cpp */,
1A750E330A90F89F000FF215 /* JSTreeWalkerCustom.cpp */,
93B70D4109EB0C7C009D8468 /* JSXMLHttpRequest.cpp */,
93B70D4209EB0C7C009D8468 /* JSXMLHttpRequest.h */,
93B70D4509EB0C7C009D8468 /* JSXSLTProcessor.cpp */,
......@@ -10699,11 +10705,14 @@
1A750DD30A90E729000FF215 /* JSNodeIteratorCustom.cpp */,
BCD9C2610C17AA67005C90A2 /* JSNodeListCustom.cpp */,
BC98A27C0C0C9950004BEBF7 /* JSStyleSheetCustom.cpp */,
A84EBD770CB8C89200079609 /* JSStyleSheetListCustom.cpp */,
B25DFAAE0B2E2929000E6510 /* JSSVGMatrixCustom.cpp */,
B2C96D8C0B3AF2B7005E80EC /* JSSVGPathSegCustom.cpp */,
B297BC6F0B3C14CF0045A590 /* JSSVGPathSegListCustom.cpp */,
B2080A110B3CA3B600120852 /* JSSVGPointListCustom.cpp */,
1A750E330A90F89F000FF215 /* JSTreeWalkerCustom.cpp */,
B2080A110B3CA3B600120852 /* JSSVGPointListCustom.cpp */,
1A750E330A90F89F000FF215 /* JSTreeWalkerCustom.cpp */,
);
name = Custom;
sourceTree = "<group>";
......@@ -13213,6 +13222,7 @@
BC64B4D80CB4298A005F2B62 /* CSSFontFaceSource.h in Headers */,
BC64B4DA0CB4298A005F2B62 /* CSSFontFaceSrcValue.h in Headers */,
BC64B4DC0CB4298A005F2B62 /* CSSFontSelector.h in Headers */,
A84EBD830CB8C97700079609 /* JSStyleSheetList.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -14693,6 +14703,8 @@
BC64B4D70CB4298A005F2B62 /* CSSFontFaceSource.cpp in Sources */,
BC64B4D90CB4298A005F2B62 /* CSSFontFaceSrcValue.cpp in Sources */,
BC64B4DB0CB4298A005F2B62 /* CSSFontSelector.cpp in Sources */,
A84EBD780CB8C89200079609 /* JSStyleSheetListCustom.cpp in Sources */,
A84EBD840CB8C97700079609 /* JSStyleSheetList.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JSStyleSheetList.h"
#include "HTMLStyleElement.h"
#include "JSStyleSheet.h"
#include "StyleSheet.h"
#include "StyleSheetList.h"
namespace WebCore {
bool JSStyleSheetList::canGetItemsForName(KJS::ExecState*, StyleSheetList* styleSheetList, const KJS::Identifier& propertyName)
{
return styleSheetList->getNamedItem(propertyName);
}
KJS::JSValue* JSStyleSheetList::nameGetter(KJS::ExecState* exec, KJS::JSObject*, const KJS::Identifier& propertyName, const KJS::PropertySlot& slot)
{
JSStyleSheetList* thisObj = static_cast<JSStyleSheetList*>(slot.slotBase());
HTMLStyleElement* element = thisObj->impl()->getNamedItem(propertyName);
ASSERT(element);
return toJS(exec, element->sheet());
}
} // namespace WebCore
......@@ -25,16 +25,8 @@
#include "config.h"
#include "kjs_css.h"
#include "CSSRule.h"
#include "CSSRuleList.h"
#include "Document.h"
#include "HTMLNames.h"
#include "HTMLStyleElement.h"
#include "CSSPrimitiveValue.h"
#include "JSCSSPrimitiveValue.h"
#include "JSCSSRule.h"
#include "JSCSSRuleList.h"
#include "JSStyleSheet.h"
#include "StyleSheetList.h"
#include "kjs_dom.h"
#include "kjs_css.lut.h"
......@@ -42,122 +34,6 @@
namespace WebCore {
using namespace KJS;
using namespace HTMLNames;
const ClassInfo JSStyleSheetList::info = { "StyleSheetList", 0, &JSStyleSheetListTable, 0 };
/*
@begin JSStyleSheetListTable 2
length WebCore::JSStyleSheetList::Length DontDelete|ReadOnly
item WebCore::JSStyleSheetList::Item DontDelete|Function 1
@end
*/
KJS_IMPLEMENT_PROTOTYPE_FUNCTION(JSStyleSheetListFunc) // not really a prototype, but doesn't matter
JSStyleSheetList::JSStyleSheetList(ExecState* exec, StyleSheetList* styleSheetList, Document* doc)
: m_impl(styleSheetList)
, m_doc(doc)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
JSStyleSheetList::~JSStyleSheetList()
{
ScriptInterpreter::forgetDOMObject(m_impl.get());
}
JSValue* JSStyleSheetList::getValueProperty(ExecState* exec, int token) const
{
switch (token) {
case Length:
return jsNumber(m_impl->length());
default:
ASSERT_NOT_REACHED();
return jsUndefined();
}
}
JSValue* JSStyleSheetList::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
{
JSStyleSheetList* thisObj = static_cast<JSStyleSheetList*>(slot.slotBase());
return toJS(exec, thisObj->m_impl->item(slot.index()));
}
JSValue* JSStyleSheetList::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
{
JSStyleSheetList* thisObj = static_cast<JSStyleSheetList*>(slot.slotBase());
Element* element = thisObj->m_doc->getElementById(propertyName);
return toJS(exec, static_cast<HTMLStyleElement*>(element)->sheet());
}
bool JSStyleSheetList::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
const HashEntry* entry = Lookup::findEntry(&JSStyleSheetListTable, propertyName);
if (entry) {
switch(entry->value) {
case Length:
slot.setStaticEntry(this, entry, staticValueGetter<JSStyleSheetList>);
return true;
case Item:
slot.setStaticEntry(this, entry, staticFunctionGetter<JSStyleSheetListFunc>);
return true;
}
}
StyleSheetList* styleSheetList = m_impl.get();
// Retrieve stylesheet by index
bool ok;
unsigned u = propertyName.toUInt32(&ok);
if (ok && u < styleSheetList->length()) {
slot.setCustomIndex(this, u, indexGetter);
return true;
}
// IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag
// (this is consistent with all the other collections)
// ### Bad implementation because returns a single element (are IDs always unique?)
// and doesn't look for name attribute (see implementation above).
// But unicity of stylesheet ids is good practice anyway ;)
Element* element = m_doc->getElementById(propertyName);
if (element && element->hasTagName(styleTag)) {
slot.setCustom(this, nameGetter);
return true;
}
return DOMObject::getOwnPropertySlot(exec, propertyName, slot);
}
JSValue* toJS(ExecState* exec, StyleSheetList* styleSheetList, Document* doc)
{
// Can't use the cacheDOMObject macro because of the doc argument
if (!styleSheetList)
return jsNull();
ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
DOMObject* ret = interp->getDOMObject(styleSheetList);
if (ret)
return ret;
ret = new JSStyleSheetList(exec, styleSheetList, doc);
interp->putDOMObject(styleSheetList, ret);
return ret;
}
JSValue* JSStyleSheetListFunc::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&JSStyleSheetList::info))
return throwError(exec, TypeError);
StyleSheetList* styleSheetList = static_cast<JSStyleSheetList*>(thisObj)->impl();
if (id == JSStyleSheetList::Item)
return toJS(exec, styleSheetList->item(args[0]->toInt32(exec)));
return jsUndefined();
}
// -------------------------------------------------------------------------
const ClassInfo JSRGBColor::info = { "RGBColor", 0, &JSRGBColorTable, 0 };
......
......@@ -24,42 +24,10 @@
#define kjs_css_h
#include "Color.h"
#include "JSStyleSheet.h"
#include "kjs_binding.h"
namespace WebCore {
class Counter;
class CSSStyleSheet;
class StyleSheet;
class StyleSheetList;
class JSStyleSheetList : public KJS::DOMObject {
public:
JSStyleSheetList(KJS::ExecState*, StyleSheetList*, Document*);
virtual ~JSStyleSheetList();
virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
// no put - all read-only
virtual const KJS::ClassInfo* classInfo() const { return &info; }
static const KJS::ClassInfo info;
enum { Item, Length };
StyleSheetList* impl() const { return m_impl.get(); }
private:
static KJS::JSValue* indexGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
static KJS::JSValue* nameGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
RefPtr<StyleSheetList> m_impl;
RefPtr<Document> m_doc;
};
// The document is only used for get-stylesheet-by-name (make optional if necessary)
KJS::JSValue* toJS(KJS::ExecState*, StyleSheetList*, Document*);
class JSRGBColor : public KJS::DOMObject {
public:
JSRGBColor(KJS::ExecState*, unsigned color);
......
......@@ -45,6 +45,7 @@
#import "JSRange.h"
#import "JSRect.h"
#import "JSStyleSheet.h"
#import "JSStyleSheetList.h"
#import "JSTreeWalker.h"
#import "JSXPathExpression.h"
#import "JSXPathResult.h"
......
......@@ -1486,12 +1486,6 @@ sub NativeToJSValue
}
}
if ($type eq "StyleSheetList") {
$implIncludes{"StyleSheetList.h"} = 1;
$implIncludes{"kjs_css.h"} = 1;
return "toJS(exec, WTF::getPtr($value), imp)";
}
if ($codeGenerator->IsSVGAnimatedType($type)) {
$value =~ s/\(\)//;
$value .= "Animated()";
......
......@@ -2,7 +2,7 @@
* This file is part of the DOM implementation for KDE.
*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004, 2006 Apple Computer, Inc.
* Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -19,19 +19,36 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "StyleSheetList.h"
#include "CSSStyleSheet.h"
#include "Document.h"
#include "HTMLNames.h"
#include "HTMLStyleElement.h"
#include "PlatformString.h"
namespace WebCore {
using namespace HTMLNames;
StyleSheetList::StyleSheetList(Document* doc)
: m_doc(doc)
{
}
StyleSheetList::~StyleSheetList()
{
for (DeprecatedPtrListIterator<StyleSheet> it (styleSheets); it.current(); ++it)
it.current()->deref();
}
void StyleSheetList::documentDestroyed()
{
m_doc = 0;
}
void StyleSheetList::add(StyleSheet* s)
{
if (!styleSheets.containsRef(s)) {
......@@ -56,4 +73,21 @@ StyleSheet* StyleSheetList::item(unsigned index)
return index < length() ? styleSheets.at(index) : 0;
}
HTMLStyleElement* StyleSheetList::getNamedItem(const String& name) const
{
if (!m_doc)
return 0;
// IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag
// (this is consistent with all the other collections)
// ### Bad implementation because returns a single element (are IDs always unique?)
// and doesn't look for name attribute.
// But unicity of stylesheet ids is good practice anyway ;)
Element* element = m_doc->getElementById(name);
if (element && element->hasTagName(styleTag))
return static_cast<HTMLStyleElement*>(element);
return 0;
}
} // namespace WebCore
/*
* This file is part of the DOM implementation for KDE.
*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004, 2006 Apple Computer, Inc.
* Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -28,22 +26,32 @@
namespace WebCore {
class Document;
class HTMLStyleElement;
class StyleSheet;
class String;
class StyleSheetList : public Shared<StyleSheetList>
{
class StyleSheetList : public Shared<StyleSheetList> {
public:
StyleSheetList(Document*);
~StyleSheetList();
void documentDestroyed();
unsigned length() const;
StyleSheet* item(unsigned index);
void add(StyleSheet*);
void remove(StyleSheet*);
HTMLStyleElement* getNamedItem(const String&) const;
DeprecatedPtrList<StyleSheet> styleSheets;
private:
Document* m_doc;
};
} // namespace
} // namespace WebCore
#endif
#endif // StyleSheetList_h
/*
* Copyright (C) 2006 Apple Computer, Inc.
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
*
* This library is free software; you can redistribute it and/or
......@@ -21,7 +21,7 @@
module stylesheets {
// Introduced in DOM Level 2:
interface StyleSheetList {
interface [GenerateConstructor, HasIndexGetter, HasNameGetter] StyleSheetList {
readonly attribute unsigned long length;
StyleSheet item(in unsigned long index);
};
......
......@@ -250,7 +250,7 @@ Document::Document(DOMImplementation* impl, Frame* frame, bool isXHTML)
: ContainerNode(0)
, m_implementation(impl)
, m_domtree_version(0)
, m_styleSheets(new StyleSheetList)
, m_styleSheets(new StyleSheetList(this))
, m_title("")
, m_titleSetExplicitly(false)
, m_imageLoadEventTimer(this, &Document::imageLoadEventTimerFired)
......@@ -433,6 +433,9 @@ Document::~Document()
unsigned count = sizeof(m_nameCollectionInfo) / sizeof(m_nameCollectionInfo[0]);
for (unsigned i = 0; i < count; i++)
deleteAllValues(m_nameCollectionInfo[i]);
if (m_styleSheets)