Changeset 20148 in webkit
- Timestamp:
- Mar 13, 2007, 7:19:32 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r20147 r20148 1 2007-03-13 Darin Adler <darin@apple.com> 2 3 Reviewed by Adele. 4 5 - test for http://bugs.webkit.org/show_bug.cgi?id=12595 6 <rdar://problem/4722863> REGRESSION: Can't add item to cart at lnt.com 7 (JS type error) (12595) 8 9 * fast/forms/old-names-expected.txt: Added. 10 * fast/forms/old-names.html: Added. 11 12 - check in files that were somehow left out in the last check-in 13 14 * fast/js/resources/js-test-pre.js: Improve the format of the failure message when 15 both the real results and expected results are strings. 16 * fast/dom/wrapper-classes-expected.txt: Changed back to use the new format. 17 1 18 2007-03-13 Sam Weinig <sam@webkit.org> 2 19 … … 84 101 * fast/dom/wrapper-classes-expected.txt: Added. 85 102 * fast/dom/wrapper-classes.html: Added. 86 * fast/js/resources/js-test-pre.js: Improve the format of the failure message when87 both the real results and expected results are strings.88 103 89 104 2007-03-12 Antti Koivisto <antti@apple.com> -
trunk/LayoutTests/fast/dom/wrapper-classes-expected.txt
r20145 r20148 67 67 PASS jsWrapperClass(stylesheet.cssRules) is 'CSSRuleList' 68 68 PASS objCWrapperClass(stylesheet.cssRules) is 'DOMCSSRuleList' 69 FAIL jsWrapperClass(stylesheet.cssRules.item(0)) should be CSSStyleRule (of type string). Was CSSRule (of type string).69 FAIL jsWrapperClass(stylesheet.cssRules.item(0)) should be CSSStyleRule. Was CSSRule. 70 70 PASS objCWrapperClass(stylesheet.cssRules.item(0)) is 'DOMCSSStyleRule' 71 71 PASS jsWrapperClass(stylesheet.cssRules.item(0).style) is 'CSSStyleDeclaration' -
trunk/LayoutTests/fast/js/resources/js-test-pre.js
r19959 r20148 53 53 else if (_av === _bv || (typeof(_av) == "number" && typeof(_bv) == "number" && isNaN(_av) && isNaN(_bv))) 54 54 testPassed(_a + " is " + _b); 55 else {56 testFailed(_a + " should be " + _bv + " (of type " + typeof _bv57 + "). Was " + _av + " (of type " + typeof _av + ").");58 }55 else if (typeof(_av) == "string" && typeof(_bv) == "string") 56 testFailed(_a + " should be " + _bv + ". Was " + _av + "."); 57 else 58 testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ")."); 59 59 } 60 60 -
trunk/WebCore/ChangeLog
r20146 r20148 1 2007-03-13 Darin Adler <darin@apple.com> 2 3 Reviewed by Adele. 4 5 - fix http://bugs.webkit.org/show_bug.cgi?id=12595 6 <rdar://problem/4722863> REGRESSION: Can't add item to cart at lnt.com 7 (JS type error) (12595) 8 9 Test: fast/forms/old-names.html 10 11 * bindings/js/JSHTMLFormElementCustom.cpp: 12 (WebCore::JSHTMLFormElement::canGetItemsForName): If the form collection has 13 nothing for a given name, try the form's oldNamedElement function. 14 (WebCore::JSHTMLFormElement::nameGetter): Ditto. 15 16 * bindings/js/kjs_dom.h: Removed the DOMNamedNodesCollection. Instead we will use 17 a class derived from NodeList. 18 * bindings/js/kjs_dom.cpp: Ditto. 19 20 * bindings/js/kjs_html.cpp: 21 (KJS::VectorNodeList::VectorNodeList): Added. Constructor for a new class derived 22 from NodeList to be used for the named items result from a collection -- uses a 23 vector of node pointers. 24 (KJS::VectorNodeList::length): Added. 25 (KJS::VectorNodeList::item): Added. 26 (KJS::JSHTMLCollection::getNamedItems): Use VectorNodeList and the existing wrapper 27 for NodeList rather than a custom JavaScript class, DOMNamedNodesCollection. 28 29 * dom/ChildNodeList.h: 30 * dom/ChildNodeList.cpp: 31 (WebCore::ChildNodeList::ChildNodeList): Updated to derive from TreeNodeList, 32 since NodeList is now a simpler class. 33 (WebCore::ChildNodeList::elementMatches): Updated for name and parameter change. 34 35 * dom/NameNodeList.h: 36 * dom/NameNodeList.cpp: 37 (WebCore::NameNodeList::NameNodeList): Updated to derive from TreeNodeList, 38 since NodeList is now a simpler class. 39 (WebCore::NameNodeList::rootNodeAttributeChanged): Updated for name and 40 parameter change. 41 42 * dom/Node.h: Change register/unregister functions to take TreeNodeList. 43 * dom/Node.cpp: 44 (WebCore::TagNodeList::TagNodeList): Updated to derive from TreeNodeList, 45 since NodeList is now a simpler abstract class. 46 (WebCore::TagNodeList::elementMatches): Updated for name and parameter change. 47 (WebCore::Node::registerNodeList): Changed type from NodeList to TreeNodeList. 48 (WebCore::Node::unregisterNodeList): Ditto. 49 50 * dom/NodeList.h: Broke NodeList into a simpler base class and a derived class 51 with the machinery for iterating a tree, called TreeNodeList. 52 * dom/NodeList.cpp: 53 (WebCore::NodeList::~NodeList): Added. 54 (WebCore::NodeList::itemWithName): Factored out of the old itemWithName. 55 (WebCore::TreeNodeList::TreeNodeList): Renamed from NodeList. 56 (WebCore::TreeNodeList::~TreeNodeList): Ditto. 57 (WebCore::TreeNodeList::recursiveLength): Ditto. 58 (WebCore::TreeNodeList::itemForwardsFromCurrent): Ditto. 59 (WebCore::TreeNodeList::itemBackwardsFromCurrent): Ditto. 60 (WebCore::TreeNodeList::recursiveItem): Ditto. 61 (WebCore::TreeNodeList::itemWithName): Factored half of this into this function, 62 the other half in NodeList::itemWithName. 63 (WebCore::TreeNodeList::rootNodeAttributeChanged): Added. No longer inline. 64 (WebCore::TreeNodeList::rootNodeChildrenChanged): Renamed from NodeList. 65 66 * html/HTMLFormElement.h: Added formElementNameChanged and oldNamedElement 67 fucntions, and a map called m_oldNames. Also removed m_boundary, which I 68 thought I had already done. 69 * html/HTMLFormElement.cpp: 70 (WebCore::HTMLFormElement::HTMLFormElement): Initialize m_oldNames to 0. 71 Switched the rest of the members to initialization syntax. 72 (WebCore::HTMLFormElement::~HTMLFormElement): Delete m_oldNames. 73 (WebCore::HTMLFormElement::formElementNameChanged): Added. Stores a reference 74 to one element under each of its old names. 75 (WebCore::HTMLFormElement::oldNamedElement): Added. Returns the old element 76 that once had a given name. 77 78 * html/HTMLGenericFormElement.h: 79 * html/HTMLGenericFormElement.cpp: 80 (WebCore::HTMLGenericFormElement::parseMappedAttribute): When the name 81 attribute changes, tell the form about the old name. 82 (WebCore::HTMLGenericFormElement::insertedIntoTree): When telling a form 83 about an element, also store away the old name so that we can use it 84 when the name changes later. 85 86 * html/HTMLInputElement.cpp: 87 (WebCore::HTMLInputElement::parseMappedAttribute): Added a call to the 88 base class in the nameAttr case, so the code in HTMLGenericFormElement 89 above will get called in the input element case. 90 1 91 2007-03-13 Antti Koivisto <antti@apple.com> 2 92 -
trunk/WebCore/bindings/js/JSHTMLFormElementCustom.cpp
r14620 r20148 1 1 /* 2 * Copyright (C) 2006 Apple Computer, Inc.All rights reserved.2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #include "JSHTMLFormElement.h" 28 28 29 #include "HTMLCollection.h" 30 #include "HTMLGenericFormElement.h" 29 31 #include "HTMLFormElement.h" 30 #include "HTMLCollection.h"31 32 32 33 using namespace KJS; … … 36 37 bool JSHTMLFormElement::canGetItemsForName(ExecState* exec, HTMLFormElement* form, const AtomicString& propertyName) 37 38 { 38 // FIXME: ideally there should be a lighter-weight way of doing this39 JSValue* namedItems = JSHTMLCollection(exec, form->elements().get()).getNamedItems(exec, propertyName);40 return ! namedItems->isUndefined();39 if (!JSHTMLCollection(exec, form->elements().get()).getNamedItems(exec, propertyName)->isUndefined()) 40 return true; 41 return !!form->oldNamedElement(propertyName); 41 42 } 42 43 43 44 JSValue* JSHTMLFormElement::nameGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) 44 45 { 45 JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(slot.slotBase()); 46 HTMLFormElement* form = static_cast<HTMLFormElement*>(thisObj->impl()); 47 48 return JSHTMLCollection(exec, form->elements().get()).getNamedItems(exec, propertyName); 46 HTMLFormElement* form = static_cast<HTMLFormElement*>(static_cast<JSHTMLElement*>(slot.slotBase())->impl()); 47 JSValue* items = JSHTMLCollection(exec, form->elements().get()).getNamedItems(exec, propertyName); 48 if (!items->isUndefined()) 49 return items; 50 return toJS(exec, form->oldNamedElement(propertyName)); 49 51 } 50 52 -
trunk/WebCore/bindings/js/kjs_dom.cpp
r20130 r20148 1122 1122 } 1123 1123 1124 // -------------------------------------------------------------------------1125 1126 const ClassInfo DOMNamedNodesCollection::info = { "Collection", 0, 0, 0 };1127 1128 // Such a collection is usually very short-lived, it only exists1129 // for constructs like document.forms.<name>[1],1130 // so it shouldn't be a problem that it's storing all the nodes (with the same name). (David)1131 DOMNamedNodesCollection::DOMNamedNodesCollection(ExecState* exec, const Vector<RefPtr<Node> >& nodes)1132 : m_nodes(nodes)1133 {1134 setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());1135 }1136 1137 JSValue* DOMNamedNodesCollection::lengthGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)1138 {1139 DOMNamedNodesCollection *thisObj = static_cast<DOMNamedNodesCollection*>(slot.slotBase());1140 return jsNumber(thisObj->m_nodes.size());1141 }1142 1143 JSValue* DOMNamedNodesCollection::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)1144 {1145 DOMNamedNodesCollection *thisObj = static_cast<DOMNamedNodesCollection*>(slot.slotBase());1146 return toJS(exec, thisObj->m_nodes[slot.index()].get());1147 }1148 1149 bool DOMNamedNodesCollection::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)1150 {1151 if (propertyName == lengthPropertyName) {1152 slot.setCustom(this, lengthGetter);1153 return true;1154 }1155 1156 // array index ?1157 bool ok;1158 unsigned idx = propertyName.toUInt32(&ok);1159 if (ok && idx < m_nodes.size()) {1160 slot.setCustomIndex(this, idx, indexGetter);1161 return true;1162 }1163 1164 // For IE compatibility, we need to be able to look up elements in a1165 // document.formName.name result by id as well as be index.1166 1167 AtomicString atomicPropertyName = propertyName;1168 for (unsigned i = 0; i < m_nodes.size(); i++) {1169 Node* node = m_nodes[i].get();1170 if (node->hasAttributes() && node->attributes()->id() == atomicPropertyName) {1171 slot.setCustomIndex(this, i, indexGetter);1172 return true;1173 }1174 }1175 1176 return DOMObject::getOwnPropertySlot(exec, propertyName, slot);1177 }1178 1179 1124 } // namespace -
trunk/WebCore/bindings/js/kjs_dom.h
r19617 r20148 143 143 JSObject* getDOMExceptionConstructor(ExecState*); 144 144 145 // Internal class, used for the collection return by e.g. document.forms.myinput146 // when multiple nodes have the same name.147 class DOMNamedNodesCollection : public DOMObject {148 public:149 DOMNamedNodesCollection(ExecState *exec, const Vector<RefPtr<WebCore::Node> >& nodes);150 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);151 virtual const ClassInfo* classInfo() const { return &info; }152 static const ClassInfo info;153 private:154 static JSValue *lengthGetter(ExecState* exec, JSObject *, const Identifier&, const PropertySlot& slot);155 static JSValue *indexGetter(ExecState* exec, JSObject *, const Identifier&, const PropertySlot& slot);156 157 Vector<RefPtr<WebCore::Node> > m_nodes;158 };159 160 145 } // namespace 161 146 -
trunk/WebCore/bindings/js/kjs_html.cpp
r20130 r20148 1 1 // -*- c-basic-offset: 4 -*- 2 2 /* 3 * This file is part of the KDE libraries4 3 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 6 5 * 7 6 * This library is free software; you can redistribute it and/or … … 69 68 70 69 namespace KJS { 70 71 class VectorNodeList : public NodeList { 72 public: 73 VectorNodeList(const Vector<RefPtr<Node> >& nodes) : m_nodes(nodes) { } 74 75 virtual unsigned length() const { return m_nodes.size(); } 76 virtual Node* item(unsigned index) const { return index < m_nodes.size() ? m_nodes[index].get() : 0; } 77 78 private: 79 Vector<RefPtr<Node> > m_nodes; 80 }; 71 81 72 82 class HTMLElementFunction : public InternalFunctionImp { … … 1551 1561 return toJS(exec, namedItems[0].get()); 1552 1562 1553 return new DOMNamedNodesCollection(exec, namedItems);1563 return toJS(exec, new VectorNodeList(namedItems)); 1554 1564 } 1555 1565 -
trunk/WebCore/dom/ChildNodeList.cpp
r13393 r20148 25 25 #include "config.h" 26 26 #include "ChildNodeList.h" 27 #include "Node.h" 27 28 #include "Element.h" 28 29 29 30 using namespace WebCore; … … 31 32 namespace WebCore { 32 33 33 ChildNodeList::ChildNodeList( Node *n)34 : NodeList(n)34 ChildNodeList::ChildNodeList(Node* n) 35 : TreeNodeList(n) 35 36 { 36 37 } … … 42 43 43 44 unsigned len = 0; 44 Node *n; 45 for(n = rootNode->firstChild(); n != 0; n = n->nextSibling()) 45 for (Node* n = rootNode->firstChild(); n; n = n->nextSibling()) 46 46 len++; 47 47 … … 52 52 } 53 53 54 Node *ChildNodeList::item ( unsigned index) const54 Node *ChildNodeList::item(unsigned index) const 55 55 { 56 56 unsigned int pos = 0; 57 Node *n = rootNode->firstChild();57 Node* n = rootNode->firstChild(); 58 58 59 59 if (isItemCacheValid) { … … 81 81 } 82 82 83 bool ChildNodeList:: nodeMatches(Node *testNode) const83 bool ChildNodeList::elementMatches(Element* element) const 84 84 { 85 return testNode->parentNode() == rootNode;85 return element->parentNode() == rootNode; 86 86 } 87 87 -
trunk/WebCore/dom/ChildNodeList.h
r18874 r20148 30 30 namespace WebCore { 31 31 32 class ChildNodeList : public NodeList {32 class ChildNodeList : public TreeNodeList { 33 33 public: 34 34 ChildNodeList(Node*); … … 38 38 39 39 protected: 40 virtual bool nodeMatches(Node* testNode) const;40 virtual bool elementMatches(Element*) const; 41 41 }; 42 42 -
trunk/WebCore/dom/NameNodeList.cpp
r13480 r20148 29 29 #include "HTMLNames.h" 30 30 31 using namespace WebCore;32 33 31 namespace WebCore { 34 32 35 33 using namespace HTMLNames; 36 34 37 NameNodeList::NameNodeList(Node *n, const String &t) 38 : NodeList(n), nodeName(t) 35 NameNodeList::NameNodeList(Node* n, const String &t) 36 : TreeNodeList(n) 37 , nodeName(t) 39 38 { 40 39 } … … 45 44 } 46 45 47 Node *NameNodeList::item 46 Node *NameNodeList::item(unsigned index) const 48 47 { 49 48 return recursiveItem(index); 50 49 } 51 50 52 bool NameNodeList:: nodeMatches(Node *testNode) const51 bool NameNodeList::elementMatches(Element* element) const 53 52 { 54 return static_cast<Element*>(testNode)->getAttribute(nameAttr) == nodeName;53 return element->getAttribute(nameAttr) == nodeName; 55 54 } 56 55 -
trunk/WebCore/dom/NameNodeList.h
r18874 r20148 34 34 * NodeList which lists all Nodes in a Element with a given "name=" tag 35 35 */ 36 class NameNodeList : public NodeList {36 class NameNodeList : public TreeNodeList { 37 37 public: 38 38 NameNodeList(Node* doc, const String& name); … … 45 45 // Other methods (not part of DOM) 46 46 virtual void rootNodeChildrenChanged() { } 47 virtual void rootNodeAttributeChanged() { NodeList::rootNodeChildrenChanged(); }47 virtual void rootNodeAttributeChanged() { TreeNodeList::rootNodeChildrenChanged(); } 48 48 49 49 protected: 50 virtual bool nodeMatches(Node* testNode) const;50 virtual bool elementMatches(Element*) const; 51 51 52 52 String nodeName; -
trunk/WebCore/dom/Node.cpp
r20028 r20148 51 51 * NodeList which lists all Nodes in a document with a given tag name 52 52 */ 53 class TagNodeList : public NodeList 54 { 53 class TagNodeList : public TreeNodeList { 55 54 public: 56 TagNodeList(Node *n, const AtomicString& namespaceURI, const AtomicString& localName); 57 58 // DOM methods overridden from parent classes 55 TagNodeList(Node*, const AtomicString& namespaceURI, const AtomicString& localName); 56 59 57 virtual unsigned length() const; 60 virtual Node *item (unsigned index) const; 61 62 // Other methods (not part of DOM) 58 virtual Node *item(unsigned index) const; 63 59 64 60 protected: 65 virtual bool nodeMatches(Node *testNode) const;61 virtual bool elementMatches(Element*) const; 66 62 67 63 AtomicString m_namespaceURI; … … 70 66 71 67 TagNodeList::TagNodeList(Node *n, const AtomicString& namespaceURI, const AtomicString& localName) 72 : NodeList(n),68 : TreeNodeList(n), 73 69 m_namespaceURI(namespaceURI), 74 70 m_localName(localName) … … 86 82 } 87 83 88 bool TagNodeList::nodeMatches(Node *testNode) const 89 { 90 if (!testNode->isElementNode()) 91 return false; 92 84 bool TagNodeList::elementMatches(Element* testNode) const 85 { 93 86 if (m_namespaceURI != starAtom && m_namespaceURI != testNode->namespaceURI()) 94 87 return false; … … 428 421 } 429 422 430 void Node::registerNodeList( NodeList* list)423 void Node::registerNodeList(TreeNodeList* list) 431 424 { 432 425 if (!m_nodeLists) … … 435 428 } 436 429 437 void Node::unregisterNodeList( NodeList* list)430 void Node::unregisterNodeList(TreeNodeList* list) 438 431 { 439 432 if (!m_nodeLists) -
trunk/WebCore/dom/Node.h
r20028 r20148 55 55 class RenderStyle; 56 56 class TextStream; 57 class TreeNodeList; 57 58 58 59 typedef int ExceptionCode; … … 440 441 #endif 441 442 442 void registerNodeList( NodeList*);443 void unregisterNodeList( NodeList*);443 void registerNodeList(TreeNodeList*); 444 void unregisterNodeList(TreeNodeList*); 444 445 void notifyNodeListsChildrenChanged(); 445 446 void notifyLocalNodeListsChildrenChanged(); … … 457 458 458 459 protected: 459 typedef HashSet< NodeList*> NodeListSet;460 typedef HashSet<TreeNodeList*> NodeListSet; 460 461 NodeListSet* m_nodeLists; 461 462 -
trunk/WebCore/dom/NodeList.cpp
r15057 r20148 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 … … 31 29 namespace WebCore { 32 30 33 NodeList::NodeList(PassRefPtr<Node> _rootNode) 31 NodeList::~NodeList() 32 { 33 } 34 35 Node* NodeList::itemWithName(const AtomicString& name) const 36 { 37 unsigned l = length(); 38 for (unsigned i = 0; i < l; i++) { 39 Node* node = item(i); 40 if (node->isElementNode() && static_cast<Element*>(node)->getIDAttribute() == name) 41 return node; 42 } 43 return 0; 44 } 45 46 TreeNodeList::TreeNodeList(PassRefPtr<Node> _rootNode) 34 47 : rootNode(_rootNode), 35 48 isLengthCacheValid(false), … … 39 52 } 40 53 41 NodeList::~NodeList()54 TreeNodeList::~TreeNodeList() 42 55 { 43 56 rootNode->unregisterNodeList(this); 44 57 } 45 58 46 unsigned NodeList::recursiveLength(Node* start) const59 unsigned TreeNodeList::recursiveLength(Node* start) const 47 60 { 48 61 if (!start) … … 56 69 for (Node* n = start->firstChild(); n; n = n->nextSibling()) 57 70 if (n->isElementNode()) { 58 if (nodeMatches(n)) 59 len++; 71 len += elementMatches(static_cast<Element*>(n)); 60 72 len += recursiveLength(n); 61 73 } … … 69 81 } 70 82 71 Node* NodeList::itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const83 Node* TreeNodeList::itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const 72 84 { 73 85 ASSERT(remainingOffset >= 0); … … 75 87 for (Node *n = start; n; n = n->traverseNextNode(rootNode.get())) { 76 88 if (n->isElementNode()) { 77 if ( nodeMatches(n)) {89 if (elementMatches(static_cast<Element*>(n))) { 78 90 if (!remainingOffset) { 79 91 lastItem = n; … … 90 102 } 91 103 92 Node* NodeList::itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const104 Node* TreeNodeList::itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const 93 105 { 94 106 ASSERT(remainingOffset < 0); 95 107 for (Node *n = start; n; n = n->traversePreviousNode(rootNode.get())) { 96 108 if (n->isElementNode()) { 97 if ( nodeMatches(n)) {109 if (elementMatches(static_cast<Element*>(n))) { 98 110 if (!remainingOffset) { 99 111 lastItem = n; … … 110 122 } 111 123 112 Node* NodeList::recursiveItem(unsigned offset, Node* start) const124 Node* TreeNodeList::recursiveItem(unsigned offset, Node* start) const 113 125 { 114 126 int remainingOffset = offset; … … 131 143 } 132 144 133 Node* NodeList::itemWithName(const AtomicString& elementId) const145 Node* TreeNodeList::itemWithName(const AtomicString& name) const 134 146 { 135 147 if (rootNode->isDocumentNode() || rootNode->inDocument()) { 136 Node* node = rootNode->document()->getElementById(elementId); 137 138 if (!node || !nodeMatches(node)) 148 Element* node = rootNode->document()->getElementById(name); 149 if (!node || !elementMatches(node)) 139 150 return 0; 140 151 … … 146 157 } 147 158 148 unsigned l = length(); 149 for (unsigned i = 0; i < l; i++) { 150 Node* node = item(i); 151 if (node->isElementNode() && static_cast<Element*>(node)->getIDAttribute() == elementId) 152 return node; 153 } 154 155 return 0; 159 return NodeList::itemWithName(name); 156 160 } 157 161 158 void NodeList::rootNodeChildrenChanged() 162 void TreeNodeList::rootNodeAttributeChanged() 163 { 164 } 165 166 void TreeNodeList::rootNodeChildrenChanged() 159 167 { 160 168 isLengthCacheValid = false; -
trunk/WebCore/dom/NodeList.h
r18874 r20148 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 … … 34 32 35 33 class AtomicString; 34 class Element; 36 35 class Node; 37 36 38 37 class NodeList : public Shared<NodeList> { 39 38 public: 40 NodeList(PassRefPtr<Node> rootNode);41 39 virtual ~NodeList(); 42 40 43 // DOM methods & attributes for NodeList44 41 virtual unsigned length() const = 0; 45 42 virtual Node* item(unsigned index) const = 0; 46 Node* itemWithName(const AtomicString&) const; 43 virtual Node* itemWithName(const AtomicString&) const; 44 }; 47 45 48 // Other methods (not part of DOM) 46 // FIXME: Move this to its own source file. 47 class TreeNodeList : public NodeList { 48 public: 49 TreeNodeList(PassRefPtr<Node> rootNode); 50 virtual ~TreeNodeList(); 51 52 virtual Node* itemWithName(const AtomicString&) const; 53 49 54 virtual void rootNodeChildrenChanged(); 50 virtual void rootNodeAttributeChanged() {}55 virtual void rootNodeAttributeChanged(); 51 56 52 57 protected: 53 // helper functions for searching all ElementImpls in a tree58 // helper functions for searching all elements in a tree 54 59 unsigned recursiveLength(Node* start = 0) const; 55 Node* recursiveItem 56 virtual bool nodeMatches(Node* testNode) const = 0;60 Node* recursiveItem(unsigned offset, Node* start = 0) const; 61 virtual bool elementMatches(Element*) const = 0; 57 62 58 63 RefPtr<Node> rootNode; -
trunk/WebCore/html/HTMLFormElement.cpp
r20136 r20148 50 50 HTMLFormElement::HTMLFormElement(Document* doc) 51 51 : HTMLElement(formTag, doc) 52 { 53 collectionInfo = 0; 54 m_post = false; 55 m_multipart = false; 56 m_autocomplete = true; 57 m_insubmit = false; 58 m_doingsubmit = false; 59 m_inreset = false; 60 m_enctype = "application/x-www-form-urlencoded"; 61 m_malformed = false; 62 m_preserveAcrossRemove = false; 52 , m_oldNames(0) 53 , collectionInfo(0) 54 , m_enctype("application/x-www-form-urlencoded") 55 , m_post(false) 56 , m_multipart(false) 57 , m_autocomplete(false) 58 , m_insubmit(false) 59 , m_doingsubmit(false) 60 , m_inreset(false) 61 , m_malformed(false) 62 , m_preserveAcrossRemove(false) 63 { 63 64 } 64 65 65 66 HTMLFormElement::~HTMLFormElement() 66 67 { 68 delete m_oldNames; 67 69 delete collectionInfo; 68 70 … … 273 275 if (current->hasLocalName(inputTag) && 274 276 static_cast<HTMLInputElement*>(current)->inputType() == HTMLInputElement::FILE) { 275 Stringpath = static_cast<HTMLInputElement*>(current)->value();277 const AtomicString& path = static_cast<HTMLInputElement*>(current)->value(); 276 278 277 279 // FIXME: This won't work if the filename includes a " mark, … … 280 282 // in the website's character set. 281 283 hstr += "; filename=\""; 282 int start = path. reverseFind('/') + 1;284 int start = path.domString().reverseFind('/') + 1; 283 285 int length = path.length() - start; 284 286 hstr += encoding.encode(reinterpret_cast<const UChar*>(path.characters() + start), length, true); 285 287 hstr += "\""; 286 288 287 if (! static_cast<HTMLInputElement*>(current)->value().isEmpty()) {289 if (!path.isEmpty()) { 288 290 DeprecatedString mimeType = MimeTypeRegistry::getMIMETypeForPath(path).deprecatedString(); 289 291 if (!mimeType.isEmpty()) { … … 499 501 setHTMLEventListener(resetEvent, attr); 500 502 else if (attr->name() == nameAttr) { 501 StringnewNameAttr = attr->value();503 const AtomicString& newNameAttr = attr->value(); 502 504 if (inDocument() && document()->isHTMLDocument()) { 503 505 HTMLDocument *doc = static_cast<HTMLDocument *>(document()); … … 560 562 if (currentCheckedRadio == e) 561 563 document()->removeRadioButtonGroup(e->name().impl(), this); 564 formElementNameChanged(e, e->name()); 562 565 } 563 566 removeFromVector(formElements, e); … … 565 568 } 566 569 570 void HTMLFormElement::formElementNameChanged(HTMLGenericFormElement* element, const AtomicString& oldName) 571 { 572 if (oldName.isEmpty()) 573 return; 574 if (!m_oldNames) 575 m_oldNames = new OldNameMap; 576 m_oldNames->set(oldName.impl(), element); 577 } 578 579 HTMLGenericFormElement* HTMLFormElement::oldNamedElement(const AtomicString& oldName) const 580 { 581 if (oldName.isEmpty()) 582 return 0; 583 if (!m_oldNames) 584 return 0; 585 return m_oldNames->get(oldName.impl()).get(); 586 } 587 567 588 bool HTMLFormElement::isURLAttribute(Attribute *attr) const 568 589 { -
trunk/WebCore/html/HTMLFormElement.h
r20074 r20148 66 66 void registerFormElement(HTMLGenericFormElement*); 67 67 void removeFormElement(HTMLGenericFormElement*); 68 void formElementNameChanged(HTMLGenericFormElement*, const AtomicString& oldName); 69 68 70 void registerImgElement(HTMLImageElement*); 69 71 void removeImgElement(HTMLImageElement*); … … 100 102 void setTarget(const String&); 101 103 104 HTMLGenericFormElement* oldNamedElement(const AtomicString& oldName) const; 105 102 106 // FIXME: Change this to be private after getting rid of all the clients. 103 107 Vector<HTMLGenericFormElement*> formElements; … … 110 114 friend class HTMLFormCollection; 111 115 116 typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLGenericFormElement> > OldNameMap; 117 118 OldNameMap* m_oldNames; 112 119 HTMLCollection::CollectionInfo* collectionInfo; 113 120 … … 116 123 String m_target; 117 124 String m_enctype; 118 String m_boundary;119 125 String m_acceptcharset; 120 126 bool m_post : 1; -
trunk/WebCore/html/HTMLGenericFormElement.cpp
r18677 r20148 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, 2005, 2006 Apple Computer, Inc.5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 8 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 9 7 * … … 56 54 } 57 55 58 void HTMLGenericFormElement::parseMappedAttribute(MappedAttribute *attr)56 void HTMLGenericFormElement::parseMappedAttribute(MappedAttribute* attr) 59 57 { 60 58 if (attr->name() == nameAttr) { 61 // Do nothing. 59 if (m_form) { 60 m_form->formElementNameChanged(this, m_oldName); 61 m_oldName = name(); 62 } 62 63 } else if (attr->name() == disabledAttr) { 63 64 bool oldDisabled = m_disabled; … … 101 102 // and so we don't need to do anything. 102 103 m_form = getForm(); 103 if (m_form) 104 if (m_form) { 104 105 m_form->registerFormElement(this); 105 else 106 m_oldName = name(); 107 } else 106 108 if (isRadioButton() && !name().isEmpty() && isChecked()) 107 109 document()->radioButtonChecked((HTMLInputElement*)this, m_form); -
trunk/WebCore/html/HTMLGenericFormElement.h
r18874 r20148 107 107 bool m_readOnly; 108 108 mutable bool m_valueMatchesRenderer; 109 109 AtomicString m_oldName; 110 110 }; 111 111 -
trunk/WebCore/html/HTMLInputElement.cpp
r20100 r20148 592 592 document()->radioButtonChecked(this, form()); 593 593 } 594 HTMLGenericFormElement::parseMappedAttribute(attr); 594 595 } else if (attr->name() == autocompleteAttr) { 595 596 m_autocomplete = !equalIgnoringCase(attr->value(), "off");
Note:
See TracChangeset
for help on using the changeset viewer.