Changeset 28981 in webkit
- Timestamp:
- Dec 25, 2007 4:46:46 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 30 deleted
- 18 edited
- 2 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r28968 r28981 1 2007-12-25 David Smith <catfish.man@gmail.com> and Sam Weinig <sam@webkit.org> 2 3 Reviewed by Oliver. 4 5 - http://bugs.webkit.org/show_bug.cgi?id=16587 6 Implement the most useful part of the W3C Selectors API. 7 8 * fast/dom/SelectorAPI: Copied from LayoutTests/fast/dom/getElementsByClassName. 9 * fast/dom/SelectorAPI/dumpNodeList-expected.txt: 10 * fast/dom/SelectorAPI/dumpNodeList.html: Modified to test querySelector and querySelectorAll instead of getElementsByClassName 11 * fast/dom/Window/window-properties-expected.txt: Added querySelector and querySelectorAll 12 1 13 2007-12-23 Darin Adler <darin@apple.com> 2 14 -
trunk/LayoutTests/fast/dom/SelectorAPI/dumpNodeList-expected.txt
r28722 r28981 6 6 line 5 7 7 8 [object HTMLDivElement], [object HTMLDivElement], [object HTMLDivElement], length: 38 [object HTMLDivElement], length: 1 9 9 [object HTMLDivElement], [object HTMLDivElement], [object HTMLDivElement], [object HTMLParagraphElement], length: 4 10 [object HTMLDivElement], [object HTMLDivElement], length: 211 [object HTMLDivElement], [object HTMLDivElement], length:212 length: 0 13 length: 0 14 length: 0 15 length: 0 10 [object HTMLDivElement], [object HTMLDivElement], [object HTMLDivElement], [object HTMLDivElement], [object HTMLParagraphElement], length: 5 11 Error: SYNTAX_ERR: DOM Exception 12 12 Error: SYNTAX_ERR: DOM Exception 12 13 Error: SYNTAX_ERR: DOM Exception 12 14 Error: SYNTAX_ERR: DOM Exception 12 15 Error: SYNTAX_ERR: DOM Exception 12 16 16 length: 0 17 17 [object HTMLDivElement], length: 1 18 18 [object HTMLDivElement], [object HTMLParagraphElement], length: 2 19 [object HTMLDivElement], length: 1 20 [object HTMLDivElement], length: 1 21 length: 0 22 length: 0 23 length: 0 24 length: 0 25 length: 0 19 [object HTMLDivElement], [object HTMLParagraphElement], length: 2 20 Error: SYNTAX_ERR: DOM Exception 12 21 Error: SYNTAX_ERR: DOM Exception 12 22 Error: SYNTAX_ERR: DOM Exception 12 23 Error: SYNTAX_ERR: DOM Exception 12 24 Error: SYNTAX_ERR: DOM Exception 12 25 [object HTMLDivElement] 26 [object HTMLDivElement] 27 [object HTMLDivElement] 28 Error: SYNTAX_ERR: DOM Exception 12 29 Error: SYNTAX_ERR: DOM Exception 12 30 Error: SYNTAX_ERR: DOM Exception 12 31 Error: SYNTAX_ERR: DOM Exception 12 32 Error: SYNTAX_ERR: DOM Exception 12 33 TypeError: Null value 34 [object HTMLDivElement] 35 [object HTMLDivElement] 36 [object HTMLDivElement] 37 Error: SYNTAX_ERR: DOM Exception 12 38 Error: SYNTAX_ERR: DOM Exception 12 39 Error: SYNTAX_ERR: DOM Exception 12 40 Error: SYNTAX_ERR: DOM Exception 12 41 Error: SYNTAX_ERR: DOM Exception 12 26 42 -
trunk/LayoutTests/fast/dom/SelectorAPI/dumpNodeList.html
r28722 r28981 2 2 <body> 3 3 <div class="one">Line 1<div class="two">Line 2</div><p>Line <i>3</i></p></div> 4 <div id="test" class="one two"><div class="one two">line 4</div><p class="two">line 5</p></div>4 <div id="test" class="one two"><div id="test2" class="one two">line 4</div><p class="two">line 5</p></div> 5 5 <p><ol id="console"></ol></p> 6 6 <script type="text/javascript"> … … 13 13 item.appendChild(document.createTextNode(message)); 14 14 document.getElementById("console").appendChild(item); 15 } 16 17 Element.prototype.dump = function() 18 { 19 return this; 15 20 } 16 21 … … 27 32 try { 28 33 var elm = document.getElementById("test"); 34 35 try { log(document.querySelectorAll("#test").dump()); } catch (e) { log(e) } 36 try { log(document.querySelectorAll(".two").dump()); } catch (e) { log(e) } 37 try { log(document.querySelectorAll(".one, .two").dump()); } catch (e) { log(e) } 38 try { log(document.querySelectorAll("@font-face").dump()); } catch (e) { log(e) } 39 try { log(document.querySelectorAll("").dump()); } catch (e) { log(e) } 40 try { log(document.querySelectorAll().dump()); } catch (e) { log(e) } 41 try { log(document.querySelectorAll(null).dump()); } catch (e) { log(e) } 42 try { log(document.querySelectorAll(undefined).dump()); } catch (e) { log(e) } 29 43 30 log(document.getElementsByClassName("one").dump());31 log(document.getElementsByClassName("two").dump());32 log(document.getElementsByClassName("one two").dump());33 log(document.getElementsByClassName("one\t\t\n \ftwo").dump());34 log(document.getElementsByClassName("").dump());35 log(document.getElementsByClassName("onetwo").dump());36 log(document.getElementsByClassName().dump());37 log(document.getElementsByClassName(null).dump());38 log(document.getElementsByClassName(undefined).dump());44 try { log(elm.querySelectorAll("#test").dump()); } catch (e) { log(e) } 45 try { log(elm.querySelectorAll("#test2").dump()); } catch (e) { log(e) } 46 try { log(elm.querySelectorAll(".two").dump()); } catch (e) { log(e) } 47 try { log(elm.querySelectorAll(".one, .two").dump()); } catch (e) { log(e) } 48 try { log(elm.querySelectorAll("@font-face").dump()); } catch (e) { log(e) } 49 try { log(elm.querySelectorAll("").dump()); } catch (e) { log(e) } 50 try { log(elm.querySelectorAll().dump()); } catch (e) { log(e) } 51 try { log(elm.querySelectorAll(null).dump()); } catch (e) { log(e) } 52 try { log(elm.querySelectorAll(undefined).dump()); } catch (e) { log(e) } 39 53 40 log(elm.getElementsByClassName("one").dump()); 41 log(elm.getElementsByClassName("two").dump()); 42 log(elm.getElementsByClassName("one two").dump()); 43 log(elm.getElementsByClassName("one\t\t\n \ftwo").dump()); 44 log(elm.getElementsByClassName("").dump()); 45 log(elm.getElementsByClassName("onetwo").dump()); 46 log(elm.getElementsByClassName().dump()); 47 log(elm.getElementsByClassName(null).dump()); 48 log(elm.getElementsByClassName(undefined).dump()); 54 try { log(document.querySelector("#test").dump()); } catch (e) { log(e) } 55 try { log(document.querySelector(".two").dump()); } catch (e) { log(e) } 56 try { log(document.querySelector(".one, .two").dump()); } catch (e) { log(e) } 57 try { log(document.querySelector("@font-face").dump()); } catch (e) { log(e) } 58 try { log(document.querySelector("").dump()); } catch (e) { log(e) } 59 try { log(document.querySelector().dump()); } catch (e) { log(e) } 60 try { log(document.querySelector(null).dump()); } catch (e) { log(e) } 61 try { log(document.querySelector(undefined).dump()); } catch (e) { log(e) } 62 63 try { log(elm.querySelector("#test").dump()); } catch (e) { log(e) } 64 try { log(elm.querySelector("#test2").dump()); } catch (e) { log(e) } 65 try { log(elm.querySelector(".two").dump()); } catch (e) { log(e) } 66 try { log(elm.querySelector(".one, .two").dump()); } catch (e) { log(e) } 67 try { log(elm.querySelector("@font-face").dump()); } catch (e) { log(e) } 68 try { log(elm.querySelector("").dump()); } catch (e) { log(e) } 69 try { log(elm.querySelector().dump()); } catch (e) { log(e) } 70 try { log(elm.querySelector(null).dump()); } catch (e) { log(e) } 71 try { log(elm.querySelector(undefined).dump()); } catch (e) { log(e) } 49 72 } catch (ex) { 50 73 log("Exception: " + ex.description); -
trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt
r28722 r28981 339 339 window.Document.prototype.queryCommandSupported [function] 340 340 window.Document.prototype.queryCommandValue [function] 341 window.Document.prototype.querySelector [function] 342 window.Document.prototype.querySelectorAll [function] 341 343 window.Document.prototype.removeChild [function] 342 344 window.Document.prototype.removeEventListener [function] … … 442 444 window.Element.prototype.lookupPrefix [function] 443 445 window.Element.prototype.normalize [function] 446 window.Element.prototype.querySelector [function] 447 window.Element.prototype.querySelectorAll [function] 444 448 window.Element.prototype.removeAttribute [function] 445 449 window.Element.prototype.removeAttributeNS [function] -
trunk/WebCore/ChangeLog
r28979 r28981 1 2007-12-25 David Smith <catfish.man@gmail.com> and Sam Weinig <sam@webkit.org> 2 3 Reviewed by Oliver. 4 5 - http://bugs.webkit.org/show_bug.cgi?id=16587 6 Implement the most useful part of the W3C Selectors API. 7 8 * WebCore.xcodeproj/project.pbxproj: 9 * css/CSSStyleSelector.h: Make Node a friend of CSSStyleSelector so it can use checkSelector() 10 * dom/ChildNodeList.cpp: 11 (WebCore::ChildNodeList::ChildNodeList): Change to being a DynamicNodeList 12 * dom/ChildNodeList.h: 13 * dom/ClassNodeList.cpp: 14 (WebCore::ClassNodeList::ClassNodeList): Change to being a DynamicNodeList 15 * dom/ClassNodeList.h: 16 * dom/Document.idl: Add the new functions 17 * dom/DynamicNodeList.cpp: Copied from WebCore/dom/NodeList.cpp. 18 (WebCore::DynamicNodeList::DynamicNodeList): Rename NodeList to DynamicNodeList, to differentiate it from the new StaticNodeList 19 (WebCore::DynamicNodeList::~DynamicNodeList): 20 (WebCore::DynamicNodeList::recursiveLength): 21 (WebCore::DynamicNodeList::itemForwardsFromCurrent): 22 (WebCore::DynamicNodeList::itemBackwardsFromCurrent): 23 (WebCore::DynamicNodeList::recursiveItem): 24 (WebCore::DynamicNodeList::itemWithName): 25 (WebCore::DynamicNodeList::rootNodeChildrenChanged): 26 (WebCore::DynamicNodeList::Caches::Caches): 27 (WebCore::DynamicNodeList::Caches::reset): 28 * dom/DynamicNodeList.h: Copied from WebCore/dom/NodeList.h. 29 (WebCore::DynamicNodeList::rootNodeAttributeChanged): 30 * dom/Element.idl: Add the new functions 31 * dom/NameNodeList.cpp: Change to being a DynamicNodeList 32 (WebCore::NameNodeList::NameNodeList): 33 * dom/NameNodeList.h: 34 (WebCore::NameNodeList::rootNodeAttributeChanged): 35 * dom/Node.cpp: 36 (WebCore::TagNodeList::TagNodeList): Change to being a DynamicNodeList 37 (WebCore::Node::registerDynamicNodeList): 38 (WebCore::Node::unregisterDynamicNodeList): 39 (WebCore::Node::getElementsByName): 40 (WebCore::Node::getElementsByClassName): 41 (WebCore::Node::querySelector): new 42 (WebCore::Node::querySelectorAll): new 43 * dom/Node.h: 44 * dom/NodeList.cpp: Removed. 45 * dom/NodeList.h: This is now an abstract superclass of DynamicNodeList and StaticNodeList 46 (WebCore::NodeList::NodeList): 47 (WebCore::NodeList::~NodeList): 48 * dom/SelectorNodeList.cpp: Added. 49 (WebCore::SelectorNodeList::SelectorNodeList): New StaticNodeList subclass that filters elements by CSS selector 50 * dom/SelectorNodeList.h: Added. 51 * dom/StaticNodeList.cpp: Added. 52 (WebCore::StaticNodeList::length): 53 (WebCore::StaticNodeList::item): 54 (WebCore::StaticNodeList::itemWithName): 55 * dom/StaticNodeList.h: Added. 56 (WebCore::StaticNodeList::StaticNodeList): 57 (WebCore::StaticNodeList::~StaticNodeList): 58 1 59 2007-12-25 Mark Rowe <mrowe@apple.com> 2 60 -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r28798 r28981 1979 1979 A818721F0977D3C0005826D9 /* ContainerNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A81872140977D3C0005826D9 /* ContainerNode.cpp */; }; 1980 1980 A81872200977D3C0005826D9 /* ChildNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = A81872150977D3C0005826D9 /* ChildNodeList.h */; }; 1981 A81872210977D3C0005826D9 /* NodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A81872160977D3C0005826D9 /* NodeList.cpp */; };1982 1981 A81872230977D3C0005826D9 /* NamedNodeMap.h in Headers */ = {isa = PBXBuildFile; fileRef = A81872180977D3C0005826D9 /* NamedNodeMap.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1983 1982 A81872240977D3C0005826D9 /* NameNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A81872190977D3C0005826D9 /* NameNodeList.cpp */; }; … … 3615 3614 BC772C5E0C4EB3440083285F /* MIMETypeRegistryMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */; }; 3616 3615 BC7F44A80B9E324E00A9D081 /* ImageObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7F44A70B9E324E00A9D081 /* ImageObserver.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3616 BC7FA6200D1F0CBD00DB22A9 /* DynamicNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC7FA61E0D1F0CBD00DB22A9 /* DynamicNodeList.cpp */; }; 3617 BC7FA6210D1F0CBD00DB22A9 /* DynamicNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7FA61F0D1F0CBD00DB22A9 /* DynamicNodeList.h */; }; 3618 BC7FA62D0D1F0EFF00DB22A9 /* StaticNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7FA62B0D1F0EFF00DB22A9 /* StaticNodeList.h */; }; 3619 BC7FA62E0D1F0EFF00DB22A9 /* StaticNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */; }; 3620 BC7FA6810D1F167900DB22A9 /* SelectorNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = BC7FA67F0D1F167900DB22A9 /* SelectorNodeList.h */; }; 3621 BC7FA6820D1F167900DB22A9 /* SelectorNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC7FA6800D1F167900DB22A9 /* SelectorNodeList.cpp */; }; 3617 3622 BC80C9870CD294EE00A0B7B3 /* CSSTimingFunctionValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC80C9850CD294EE00A0B7B3 /* CSSTimingFunctionValue.cpp */; }; 3618 3623 BC80C9880CD294EE00A0B7B3 /* CSSTimingFunctionValue.h in Headers */ = {isa = PBXBuildFile; fileRef = BC80C9860CD294EE00A0B7B3 /* CSSTimingFunctionValue.h */; }; … … 6109 6114 A81872140977D3C0005826D9 /* ContainerNode.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContainerNode.cpp; sourceTree = "<group>"; }; 6110 6115 A81872150977D3C0005826D9 /* ChildNodeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ChildNodeList.h; sourceTree = "<group>"; }; 6111 A81872160977D3C0005826D9 /* NodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = NodeList.cpp; sourceTree = "<group>"; };6112 6116 A81872180977D3C0005826D9 /* NamedNodeMap.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NamedNodeMap.h; sourceTree = "<group>"; }; 6113 6117 A81872190977D3C0005826D9 /* NameNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = NameNodeList.cpp; sourceTree = "<group>"; }; … … 7626 7630 BC7B2AF90450824100A8000F /* PlatformScrollBarMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformScrollBarMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; }; 7627 7631 BC7F44A70B9E324E00A9D081 /* ImageObserver.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ImageObserver.h; sourceTree = "<group>"; }; 7632 BC7FA61E0D1F0CBD00DB22A9 /* DynamicNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DynamicNodeList.cpp; sourceTree = "<group>"; }; 7633 BC7FA61F0D1F0CBD00DB22A9 /* DynamicNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicNodeList.h; sourceTree = "<group>"; }; 7634 BC7FA62B0D1F0EFF00DB22A9 /* StaticNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticNodeList.h; sourceTree = "<group>"; }; 7635 BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticNodeList.cpp; sourceTree = "<group>"; }; 7636 BC7FA67F0D1F167900DB22A9 /* SelectorNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorNodeList.h; sourceTree = "<group>"; }; 7637 BC7FA6800D1F167900DB22A9 /* SelectorNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorNodeList.cpp; sourceTree = "<group>"; }; 7628 7638 BC80C9850CD294EE00A0B7B3 /* CSSTimingFunctionValue.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CSSTimingFunctionValue.cpp; sourceTree = "<group>"; }; 7629 7639 BC80C9860CD294EE00A0B7B3 /* CSSTimingFunctionValue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSTimingFunctionValue.h; sourceTree = "<group>"; }; … … 12167 12177 A8185F3309765765005826D9 /* DOMImplementation.h */, 12168 12178 93EEC1E909C2877700C515D1 /* DOMImplementation.idl */, 12179 BC7FA61E0D1F0CBD00DB22A9 /* DynamicNodeList.cpp */, 12180 BC7FA61F0D1F0CBD00DB22A9 /* DynamicNodeList.h */, 12169 12181 6550B699099DF0270090D781 /* EditingText.cpp */, 12170 12182 6550B69A099DF0270090D781 /* EditingText.h */, … … 12225 12237 854FE72B0A2297BE0058D7AD /* NodeIterator.h */, 12226 12238 1A750D870A90E394000FF215 /* NodeIterator.idl */, 12227 A81872160977D3C0005826D9 /* NodeList.cpp */,12228 12239 A81872100977D3C0005826D9 /* NodeList.h */, 12229 12240 85ACA9FA0A9B631000671E90 /* NodeList.idl */, … … 12253 12264 85031B350A44EFC700F992E0 /* RegisteredEventListener.cpp */, 12254 12265 85031B360A44EFC700F992E0 /* RegisteredEventListener.h */, 12266 BC7FA6800D1F167900DB22A9 /* SelectorNodeList.cpp */, 12267 BC7FA67F0D1F167900DB22A9 /* SelectorNodeList.h */, 12268 BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */, 12269 BC7FA62B0D1F0EFF00DB22A9 /* StaticNodeList.h */, 12255 12270 A8C4A7EC09D563270003AC8D /* StyledElement.cpp */, 12256 12271 A8C4A7EB09D563270003AC8D /* StyledElement.h */, … … 14119 14134 BCA379150D163E5500B793D6 /* JSLocation.h in Headers */, 14120 14135 BCA3793F0D1647E000B793D6 /* JSLocation.lut.h in Headers */, 14136 BC7FA6210D1F0CBD00DB22A9 /* DynamicNodeList.h in Headers */, 14137 BC7FA62D0D1F0EFF00DB22A9 /* StaticNodeList.h in Headers */, 14138 BC7FA6810D1F167900DB22A9 /* SelectorNodeList.h in Headers */, 14121 14139 ); 14122 14140 runOnlyForDeploymentPostprocessing = 0; … … 15378 15396 854FE7320A2297BE0058D7AD /* NodeFilterCondition.cpp in Sources */, 15379 15397 854FE7340A2297BE0058D7AD /* NodeIterator.cpp in Sources */, 15380 A81872210977D3C0005826D9 /* NodeList.cpp in Sources */,15381 15398 A8EA7EBF0A1945D000A8EF5F /* Notation.cpp in Sources */, 15382 15399 1A0D57360A5C77FE007EDD4C /* OverflowEvent.cpp in Sources */, … … 15833 15850 93309E1D099E64920056E581 /* visible_units.cpp in Sources */, 15834 15851 BCA379140D163E5500B793D6 /* JSLocation.cpp in Sources */, 15852 BC7FA6200D1F0CBD00DB22A9 /* DynamicNodeList.cpp in Sources */, 15853 BC7FA62E0D1F0EFF00DB22A9 /* StaticNodeList.cpp in Sources */, 15854 BC7FA6820D1F167900DB22A9 /* SelectorNodeList.cpp in Sources */, 15835 15855 ); 15836 15856 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/css/CSSStyleSelector.h
r28882 r28981 130 130 CSSFontSelector* fontSelector() { return m_fontSelector.get(); } 131 131 132 protected:133 134 132 /* checks if a compound selector (which can consist of multiple simple selectors) 135 133 matches the given Element */ 136 bool checkSelector(CSSSelector* selector); 134 bool checkSelector(CSSSelector*); 135 136 protected: 137 137 enum SelectorMatch { SelectorMatches=0, SelectorFailsLocally, SelectorFailsCompletely}; 138 138 SelectorMatch checkSelector(CSSSelector* selector, Element *e, bool isAncestor, bool isSubSelector); … … 243 243 244 244 friend class CSSRuleSet; 245 friend class Node; 245 246 }; 246 247 -
trunk/WebCore/dom/ChildNodeList.cpp
r28868 r28981 31 31 namespace WebCore { 32 32 33 ChildNodeList::ChildNodeList(Node* n, NodeList::Caches* info)34 : NodeList(n, info, false)33 ChildNodeList::ChildNodeList(Node* n, DynamicNodeList::Caches* info) 34 : DynamicNodeList(n, info, false) 35 35 { 36 36 } -
trunk/WebCore/dom/ChildNodeList.h
r25754 r28981 1 1 /* 2 * This file is part of the DOM implementation for KDE.3 *4 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 5 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 7 * Copyright (C) 2004 Apple Computer, Inc.5 * Copyright (C) 2004, 2007 Apple Inc. All rights reserved. 8 6 * 9 7 * This library is free software; you can redistribute it and/or … … 23 21 * 24 22 */ 23 25 24 #ifndef ChildNodeList_h 26 25 #define ChildNodeList_h 27 26 28 #include " NodeList.h"27 #include "DynamicNodeList.h" 29 28 30 29 namespace WebCore { 31 30 32 class ChildNodeList : public NodeList {31 class ChildNodeList : public DynamicNodeList { 33 32 public: 34 ChildNodeList(Node*, NodeList::Caches*);33 ChildNodeList(Node*, DynamicNodeList::Caches*); 35 34 36 35 virtual unsigned length() const; -
trunk/WebCore/dom/ClassNodeList.cpp
r28868 r28981 37 37 namespace WebCore { 38 38 39 ClassNodeList::ClassNodeList(PassRefPtr<Node> rootNode, const String& classNames, NodeList::Caches* caches)40 : NodeList(rootNode, caches, true)39 ClassNodeList::ClassNodeList(PassRefPtr<Node> rootNode, const String& classNames, DynamicNodeList::Caches* caches) 40 : DynamicNodeList(rootNode, caches, true) 41 41 { 42 42 m_classNames.parseClassAttribute(classNames, m_rootNode->document()->inCompatMode()); -
trunk/WebCore/dom/ClassNodeList.h
r28868 r28981 32 32 33 33 #include "ClassNames.h" 34 #include " NodeList.h"34 #include "DynamicNodeList.h" 35 35 36 36 namespace WebCore { … … 38 38 class String; 39 39 40 class ClassNodeList : public NodeList {40 class ClassNodeList : public DynamicNodeList { 41 41 public: 42 ClassNodeList(PassRefPtr<Node> rootNode, const String& classNames, NodeList::Caches*);42 ClassNodeList(PassRefPtr<Node> rootNode, const String& classNames, DynamicNodeList::Caches*); 43 43 44 44 virtual unsigned length() const; -
trunk/WebCore/dom/Document.idl
r28722 r28981 223 223 // HTML 5 224 224 NodeList getElementsByClassName(in DOMString tagname); 225 226 // DocumentSelector - Selector API 227 Element querySelector(in [ConvertUndefinedOrNullToNullString] DOMString selectors) 228 raises(DOMException); 229 NodeList querySelectorAll(in [ConvertUndefinedOrNullToNullString] DOMString selectors) 230 raises(DOMException); 225 231 }; 226 232 -
trunk/WebCore/dom/DynamicNodeList.cpp
r28972 r28981 1 1 /** 2 * This file is part of the DOM implementation for KDE.3 *4 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 5 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 7 * Copyright (C) 2004, 2006 Apple Computer, Inc.5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 8 6 * 9 7 * This library is free software; you can redistribute it and/or … … 24 22 25 23 #include "config.h" 26 #include " NodeList.h"24 #include "DynamicNodeList.h" 27 25 28 26 #include "Document.h" … … 31 29 namespace WebCore { 32 30 33 NodeList::NodeList(PassRefPtr<Node> rootNode, bool needsNotifications)31 DynamicNodeList::DynamicNodeList(PassRefPtr<Node> rootNode, bool needsNotifications) 34 32 : m_rootNode(rootNode) 35 33 , m_caches(new Caches) … … 37 35 , m_needsNotifications(needsNotifications) 38 36 { 39 m_rootNode->register NodeList(this);37 m_rootNode->registerDynamicNodeList(this); 40 38 } 41 39 42 NodeList::NodeList(PassRefPtr<Node> rootNode,NodeList::Caches* info, bool needsNotifications)40 DynamicNodeList::DynamicNodeList(PassRefPtr<Node> rootNode, DynamicNodeList::Caches* info, bool needsNotifications) 43 41 : m_rootNode(rootNode) 44 42 , m_caches(info) … … 46 44 , m_needsNotifications(needsNotifications) 47 45 { 48 m_rootNode->register NodeList(this);46 m_rootNode->registerDynamicNodeList(this); 49 47 } 50 48 51 NodeList::~NodeList()49 DynamicNodeList::~DynamicNodeList() 52 50 { 53 m_rootNode->unregister NodeList(this);51 m_rootNode->unregisterDynamicNodeList(this); 54 52 if (m_ownsCaches) 55 53 delete m_caches; 56 54 } 57 55 58 unsigned NodeList::recursiveLength(Node* start) const56 unsigned DynamicNodeList::recursiveLength(Node* start) const 59 57 { 60 58 if (!start) … … 81 79 } 82 80 83 Node* NodeList::itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const81 Node* DynamicNodeList::itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const 84 82 { 85 83 ASSERT(remainingOffset >= 0); … … 102 100 } 103 101 104 Node* NodeList::itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const102 Node* DynamicNodeList::itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const 105 103 { 106 104 ASSERT(remainingOffset < 0); … … 122 120 } 123 121 124 Node* NodeList::recursiveItem(unsigned offset, Node* start) const122 Node* DynamicNodeList::recursiveItem(unsigned offset, Node* start) const 125 123 { 126 124 int remainingOffset = offset; … … 143 141 } 144 142 145 Node* NodeList::itemWithName(const AtomicString& elementId) const143 Node* DynamicNodeList::itemWithName(const AtomicString& elementId) const 146 144 { 147 145 if (m_rootNode->isDocumentNode() || m_rootNode->inDocument()) { … … 168 166 } 169 167 170 void NodeList::rootNodeChildrenChanged()168 void DynamicNodeList::rootNodeChildrenChanged() 171 169 { 172 170 m_caches->reset(); … … 174 172 175 173 176 NodeList::Caches::Caches()174 DynamicNodeList::Caches::Caches() 177 175 : lastItem(0) 178 176 , isLengthCacheValid(false) … … 181 179 } 182 180 183 void NodeList::Caches::reset()181 void DynamicNodeList::Caches::reset() 184 182 { 185 183 lastItem = 0; -
trunk/WebCore/dom/DynamicNodeList.h
r28972 r28981 1 1 /* 2 * This file is part of the DOM implementation for KDE.3 *4 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 5 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 7 * Copyright (C) 2004, 2006 Apple Computer, Inc.5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 8 6 * 9 7 * This library is free software; you can redistribute it and/or … … 24 22 */ 25 23 26 #ifndef NodeList_h27 #define NodeList_h24 #ifndef DynamicNodeList_h 25 #define DynamicNodeList_h 28 26 27 #include "NodeList.h" 29 28 #include <wtf/RefCounted.h> 30 29 #include <wtf/Forward.h> … … 36 35 class Node; 37 36 38 class NodeList : public RefCounted<NodeList>{37 class DynamicNodeList : public NodeList { 39 38 public: 40 41 39 struct Caches { 42 40 Caches(); 43 41 void reset(); 44 42 45 43 unsigned cachedLength; 46 44 Node* lastItem; … … 50 48 }; 51 49 52 NodeList(PassRefPtr<Node> rootNode, bool needsNotifications);53 NodeList(PassRefPtr<Node> rootNode, Caches*, bool needsNotifications);54 virtual ~ NodeList();50 DynamicNodeList(PassRefPtr<Node> rootNode, bool needsNotifications); 51 DynamicNodeList(PassRefPtr<Node> rootNode, Caches*, bool needsNotifications); 52 virtual ~DynamicNodeList(); 55 53 56 54 bool needsNotifications() const { return m_needsNotifications; } … … 63 61 // Other methods (not part of DOM) 64 62 virtual void rootNodeChildrenChanged(); 65 virtual void rootNodeAttributeChanged() { }63 virtual void rootNodeAttributeChanged() { } 66 64 67 65 protected: … … 76 74 bool m_needsNotifications; 77 75 78 76 private: 79 77 Node* itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const; 80 78 Node* itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const; 81 79 }; 82 80 83 } // namespace81 } // namespace WebCore 84 82 85 #endif 83 #endif // DynamicNodeList_h -
trunk/WebCore/dom/Element.idl
r28722 r28981 106 106 NodeList getElementsByClassName(in DOMString name); 107 107 108 // ElementSelector - Selector API 109 Element querySelector(in [ConvertUndefinedOrNullToNullString] DOMString selectors) 110 raises(DOMException); 111 NodeList querySelectorAll(in [ConvertUndefinedOrNullToNullString] DOMString selectors) 112 raises(DOMException); 113 108 114 #if defined(LANGUAGE_OBJECTIVE_C) 109 115 // Objective-C extensions -
trunk/WebCore/dom/NameNodeList.cpp
r28868 r28981 31 31 using namespace HTMLNames; 32 32 33 NameNodeList::NameNodeList(Node* root, const String& name, NodeList::Caches* caches)34 : NodeList(root, caches, true)33 NameNodeList::NameNodeList(Node* root, const String& name, DynamicNodeList::Caches* caches) 34 : DynamicNodeList(root, caches, true) 35 35 , m_nodeName(name) 36 36 { -
trunk/WebCore/dom/NameNodeList.h
r28868 r28981 21 21 * 22 22 */ 23 23 24 #ifndef NameNodeList_h 24 25 #define NameNodeList_h 25 26 26 #include " NodeList.h"27 #include "DynamicNodeList.h" 27 28 #include "PlatformString.h" 28 29 … … 32 33 * NodeList which lists all Nodes in a Element with a given "name=" tag 33 34 */ 34 class NameNodeList : public NodeList {35 class NameNodeList : public DynamicNodeList { 35 36 public: 36 NameNodeList(Node* root, const String& name, NodeList::Caches*);37 NameNodeList(Node* root, const String& name, DynamicNodeList::Caches*); 37 38 38 39 // DOM methods overridden from parent classes … … 43 44 // Other methods (not part of DOM) 44 45 45 virtual void rootNodeAttributeChanged() { NodeList::rootNodeChildrenChanged(); }46 virtual void rootNodeAttributeChanged() { DynamicNodeList::rootNodeChildrenChanged(); } 46 47 47 48 protected: -
trunk/WebCore/dom/Node.cpp
r28875 r28981 25 25 #include "Node.h" 26 26 27 #include "CSSRule.h" 28 #include "CSSRuleList.h" 29 #include "CSSStyleRule.h" 30 #include "CSSStyleSelector.h" 31 #include "CSSStyleSheet.h" 32 #include "CSSParser.h" 33 #include "CSSSelector.h" 27 34 #include "CString.h" 28 35 #include "ChildNodeList.h" … … 30 37 #include "DOMImplementation.h" 31 38 #include "Document.h" 39 #include "DynamicNodeList.h" 32 40 #include "Element.h" 33 41 #include "ExceptionCode.h" … … 40 48 #include "NamedAttrMap.h" 41 49 #include "RenderObject.h" 50 #include "SelectorNodeList.h" 42 51 #include "Text.h" 43 52 #include "TextStream.h" … … 50 59 using namespace HTMLNames; 51 60 52 typedef HashSet< NodeList*> NodeListSet;61 typedef HashSet<DynamicNodeList*> NodeListSet; 53 62 struct NodeListsNodeData { 54 63 NodeListSet m_listsToNotify; 55 NodeList::Caches m_childNodeListCaches;56 HashMap<String, NodeList::Caches> m_classNodeListCaches;57 HashMap<String, NodeList::Caches> m_nameNodeListCaches;64 DynamicNodeList::Caches m_childNodeListCaches; 65 HashMap<String, DynamicNodeList::Caches> m_classNodeListCaches; 66 HashMap<String, DynamicNodeList::Caches> m_nameNodeListCaches; 58 67 }; 59 68 60 69 // NodeList that limits to a particular tag. 61 class TagNodeList : public NodeList {70 class TagNodeList : public DynamicNodeList { 62 71 public: 63 72 TagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName); … … 74 83 75 84 inline TagNodeList::TagNodeList(PassRefPtr<Node> rootNode, const AtomicString& namespaceURI, const AtomicString& localName) 76 : NodeList(rootNode, true)85 : DynamicNodeList(rootNode, true) 77 86 , m_namespaceURI(namespaceURI) 78 87 , m_localName(localName) … … 442 451 } 443 452 444 void Node::register NodeList(NodeList* list)453 void Node::registerDynamicNodeList(DynamicNodeList* list) 445 454 { 446 455 if (!m_nodeLists) … … 455 464 } 456 465 457 void Node::unregister NodeList(NodeList* list)466 void Node::unregisterDynamicNodeList(DynamicNodeList* list) 458 467 { 459 468 ASSERT(m_nodeLists); … … 1216 1225 m_nodeLists.set(new NodeListsNodeData); 1217 1226 1218 return new NameNodeList(this, elementName, &m_nodeLists->m_nameNodeListCaches.add(elementName, NodeList::Caches()).first->second);1227 return new NameNodeList(this, elementName, &m_nodeLists->m_nameNodeListCaches.add(elementName, DynamicNodeList::Caches()).first->second); 1219 1228 } 1220 1229 … … 1224 1233 m_nodeLists.set(new NodeListsNodeData); 1225 1234 1226 return new ClassNodeList(this, classNames, &m_nodeLists->m_classNodeListCaches.add(classNames, NodeList::Caches()).first->second); 1235 return new ClassNodeList(this, classNames, &m_nodeLists->m_classNodeListCaches.add(classNames, DynamicNodeList::Caches()).first->second); 1236 } 1237 1238 PassRefPtr<Element> Node::querySelector(const String& selectors, ExceptionCode& ec) 1239 { 1240 if (selectors.isNull() || selectors.isEmpty()) { 1241 ec = SYNTAX_ERR; 1242 return 0; 1243 } 1244 CSSStyleSheet tempStyleSheet(document()); 1245 CSSParser p(true); 1246 RefPtr<CSSRule> rule = p.parseRule(&tempStyleSheet, selectors + "{}"); 1247 if (!rule || !rule->isStyleRule()) { 1248 ec = SYNTAX_ERR; 1249 return 0; 1250 } 1251 1252 CSSStyleSelector* styleSelector = document()->styleSelector(); 1253 CSSSelector* querySelector = static_cast<CSSStyleRule*>(rule.get())->selector(); 1254 1255 // FIXME: We can speed this up by implementing caching similar to the one use by getElementById 1256 for (Node *n = traverseNextNode(); n; n = n->traverseNextNode()) { 1257 if (n->isElementNode()) { 1258 Element* element = static_cast<Element*>(n); 1259 styleSelector->initElementAndPseudoState(element); 1260 for (CSSSelector* selector = querySelector; selector; selector = selector->next()) { 1261 if (styleSelector->checkSelector(selector)) 1262 return element; 1263 } 1264 } 1265 } 1266 1267 return 0; 1268 } 1269 1270 PassRefPtr<NodeList> Node::querySelectorAll(const String& selectors, ExceptionCode& ec) 1271 { 1272 if (selectors.isNull() || selectors.isEmpty()) { 1273 ec = SYNTAX_ERR; 1274 return 0; 1275 } 1276 CSSStyleSheet tempStyleSheet(document()); 1277 CSSParser p(true); 1278 RefPtr<CSSRule> rule = p.parseRule(&tempStyleSheet, selectors + "{}"); 1279 if (!rule || !rule->isStyleRule()) { 1280 ec = SYNTAX_ERR; 1281 return 0; 1282 } 1283 1284 SelectorNodeList* resultList = new SelectorNodeList(this, static_cast<CSSStyleRule*>(rule.get())->selector()); 1285 1286 return resultList; 1227 1287 } 1228 1288 -
trunk/WebCore/dom/Node.h
r28868 r28981 39 39 class ContainerNode; 40 40 class Document; 41 class DynamicNodeList; 41 42 class Element; 42 43 class Event; … … 443 444 #endif 444 445 445 void register NodeList(NodeList*);446 void unregister NodeList(NodeList*);446 void registerDynamicNodeList(DynamicNodeList*); 447 void unregisterDynamicNodeList(DynamicNodeList*); 447 448 void notifyNodeListsChildrenChanged(); 448 449 void notifyLocalNodeListsChildrenChanged(); … … 452 453 PassRefPtr<NodeList> getElementsByTagName(const String&); 453 454 PassRefPtr<NodeList> getElementsByTagNameNS(const String& namespaceURI, const String& localName); 454 455 455 PassRefPtr<NodeList> getElementsByName(const String& elementName); 456 456 PassRefPtr<NodeList> getElementsByClassName(const String& classNames); 457 458 PassRefPtr<Element> querySelector(const String& selectors, ExceptionCode&); 459 PassRefPtr<NodeList> querySelectorAll(const String& selectors, ExceptionCode&); 457 460 458 461 private: // members -
trunk/WebCore/dom/NodeList.h
r28868 r28981 29 29 #include <wtf/RefCounted.h> 30 30 #include <wtf/Forward.h> 31 #include <wtf/RefPtr.h>32 31 33 32 namespace WebCore { 34 33 35 class AtomicString;36 class Node;34 class AtomicString; 35 class Node; 37 36 38 class NodeList : public RefCounted<NodeList> { 39 public: 37 class NodeList : public RefCounted<NodeList> { 38 public: 39 NodeList() { } 40 virtual ~NodeList() { } 40 41 41 struct Caches { 42 Caches(); 43 void reset(); 44 45 unsigned cachedLength; 46 Node* lastItem; 47 unsigned lastItemOffset; 48 bool isLengthCacheValid : 1; 49 bool isItemCacheValid : 1; 42 // DOM methods & attributes for NodeList 43 virtual unsigned length() const = 0; 44 virtual Node* item(unsigned index) const = 0; 45 virtual Node* itemWithName(const AtomicString&) const = 0; 50 46 }; 51 47 52 NodeList(PassRefPtr<Node> rootNode, bool needsNotifications); 53 NodeList(PassRefPtr<Node> rootNode, Caches*, bool needsNotifications); 54 virtual ~NodeList(); 48 } // namespace WebCore 55 49 56 bool needsNotifications() const { return m_needsNotifications; } 57 58 // DOM methods & attributes for NodeList 59 virtual unsigned length() const = 0; 60 virtual Node* item(unsigned index) const = 0; 61 Node* itemWithName(const AtomicString&) const; 62 63 // Other methods (not part of DOM) 64 virtual void rootNodeChildrenChanged(); 65 virtual void rootNodeAttributeChanged() {} 66 67 protected: 68 // helper functions for searching all ElementImpls in a tree 69 unsigned recursiveLength(Node* start = 0) const; 70 Node* recursiveItem (unsigned offset, Node* start = 0) const; 71 virtual bool nodeMatches(Node* testNode) const = 0; 72 73 RefPtr<Node> m_rootNode; 74 mutable Caches* m_caches; 75 bool m_ownsCaches; 76 bool m_needsNotifications; 77 78 private: 79 Node* itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const; 80 Node* itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const; 81 }; 82 83 } //namespace 84 85 #endif 50 #endif NodeList_h
Note: See TracChangeset
for help on using the changeset viewer.