Changeset 20148 in webkit


Ignore:
Timestamp:
Mar 13, 2007, 7:19:32 AM (18 years ago)
Author:
darin
Message:

LayoutTests:

Reviewed by Adele.

  • fast/forms/old-names-expected.txt: Added.
  • fast/forms/old-names.html: Added.
  • check in files that were somehow left out in the last check-in
  • fast/js/resources/js-test-pre.js: Improve the format of the failure message when both the real results and expected results are strings.
  • fast/dom/wrapper-classes-expected.txt: Changed back to use the new format.

WebCore:

Reviewed by Adele.

Test: fast/forms/old-names.html

  • bindings/js/JSHTMLFormElementCustom.cpp: (WebCore::JSHTMLFormElement::canGetItemsForName): If the form collection has nothing for a given name, try the form's oldNamedElement function. (WebCore::JSHTMLFormElement::nameGetter): Ditto.
  • bindings/js/kjs_dom.h: Removed the DOMNamedNodesCollection. Instead we will use a class derived from NodeList.
  • bindings/js/kjs_dom.cpp: Ditto.
  • bindings/js/kjs_html.cpp: (KJS::VectorNodeList::VectorNodeList): Added. Constructor for a new class derived from NodeList to be used for the named items result from a collection -- uses a vector of node pointers. (KJS::VectorNodeList::length): Added. (KJS::VectorNodeList::item): Added. (KJS::JSHTMLCollection::getNamedItems): Use VectorNodeList and the existing wrapper for NodeList rather than a custom JavaScript class, DOMNamedNodesCollection.
  • dom/ChildNodeList.h:
  • dom/ChildNodeList.cpp: (WebCore::ChildNodeList::ChildNodeList): Updated to derive from TreeNodeList, since NodeList is now a simpler class. (WebCore::ChildNodeList::elementMatches): Updated for name and parameter change.
  • dom/NameNodeList.h:
  • dom/NameNodeList.cpp: (WebCore::NameNodeList::NameNodeList): Updated to derive from TreeNodeList, since NodeList is now a simpler class. (WebCore::NameNodeList::rootNodeAttributeChanged): Updated for name and parameter change.
  • dom/Node.h: Change register/unregister functions to take TreeNodeList.
  • dom/Node.cpp: (WebCore::TagNodeList::TagNodeList): Updated to derive from TreeNodeList, since NodeList is now a simpler abstract class. (WebCore::TagNodeList::elementMatches): Updated for name and parameter change. (WebCore::Node::registerNodeList): Changed type from NodeList to TreeNodeList. (WebCore::Node::unregisterNodeList): Ditto.
  • dom/NodeList.h: Broke NodeList into a simpler base class and a derived class with the machinery for iterating a tree, called TreeNodeList.
  • dom/NodeList.cpp: (WebCore::NodeList::~NodeList): Added. (WebCore::NodeList::itemWithName): Factored out of the old itemWithName. (WebCore::TreeNodeList::TreeNodeList): Renamed from NodeList. (WebCore::TreeNodeList::~TreeNodeList): Ditto. (WebCore::TreeNodeList::recursiveLength): Ditto. (WebCore::TreeNodeList::itemForwardsFromCurrent): Ditto. (WebCore::TreeNodeList::itemBackwardsFromCurrent): Ditto. (WebCore::TreeNodeList::recursiveItem): Ditto. (WebCore::TreeNodeList::itemWithName): Factored half of this into this function, the other half in NodeList::itemWithName. (WebCore::TreeNodeList::rootNodeAttributeChanged): Added. No longer inline. (WebCore::TreeNodeList::rootNodeChildrenChanged): Renamed from NodeList.
  • html/HTMLFormElement.h: Added formElementNameChanged and oldNamedElement fucntions, and a map called m_oldNames. Also removed m_boundary, which I thought I had already done.
  • html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::HTMLFormElement): Initialize m_oldNames to 0. Switched the rest of the members to initialization syntax. (WebCore::HTMLFormElement::~HTMLFormElement): Delete m_oldNames. (WebCore::HTMLFormElement::formElementNameChanged): Added. Stores a reference to one element under each of its old names. (WebCore::HTMLFormElement::oldNamedElement): Added. Returns the old element that once had a given name.
  • html/HTMLGenericFormElement.h:
  • html/HTMLGenericFormElement.cpp: (WebCore::HTMLGenericFormElement::parseMappedAttribute): When the name attribute changes, tell the form about the old name. (WebCore::HTMLGenericFormElement::insertedIntoTree): When telling a form about an element, also store away the old name so that we can use it when the name changes later.
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::parseMappedAttribute): Added a call to the base class in the nameAttr case, so the code in HTMLGenericFormElement above will get called in the input element case.
Location:
trunk
Files:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r20147 r20148  
     12007-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
    1182007-03-13  Sam Weinig  <sam@webkit.org>
    219
     
    84101        * fast/dom/wrapper-classes-expected.txt: Added.
    85102        * fast/dom/wrapper-classes.html: Added.
    86         * fast/js/resources/js-test-pre.js: Improve the format of the failure message when
    87         both the real results and expected results are strings.
    88103
    891042007-03-12  Antti Koivisto  <antti@apple.com>
  • trunk/LayoutTests/fast/dom/wrapper-classes-expected.txt

    r20145 r20148  
    6767PASS jsWrapperClass(stylesheet.cssRules) is 'CSSRuleList'
    6868PASS objCWrapperClass(stylesheet.cssRules) is 'DOMCSSRuleList'
    69 FAIL jsWrapperClass(stylesheet.cssRules.item(0)) should be CSSStyleRule (of type string). Was CSSRule (of type string).
     69FAIL jsWrapperClass(stylesheet.cssRules.item(0)) should be CSSStyleRule. Was CSSRule.
    7070PASS objCWrapperClass(stylesheet.cssRules.item(0)) is 'DOMCSSStyleRule'
    7171PASS jsWrapperClass(stylesheet.cssRules.item(0).style) is 'CSSStyleDeclaration'
  • trunk/LayoutTests/fast/js/resources/js-test-pre.js

    r19959 r20148  
    5353  else if (_av === _bv || (typeof(_av) == "number" && typeof(_bv) == "number" && isNaN(_av) && isNaN(_bv)))
    5454    testPassed(_a + " is " + _b);
    55   else {
    56     testFailed(_a + " should be " + _bv + " (of type " + typeof _bv
    57                + "). 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 + ").");
    5959}
    6060
  • trunk/WebCore/ChangeLog

    r20146 r20148  
     12007-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
    1912007-03-13  Antti Koivisto  <antti@apple.com>
    292
  • trunk/WebCore/bindings/js/JSHTMLFormElementCustom.cpp

    r14620 r20148  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#include "JSHTMLFormElement.h"
    2828
     29#include "HTMLCollection.h"
     30#include "HTMLGenericFormElement.h"
    2931#include "HTMLFormElement.h"
    30 #include "HTMLCollection.h"
    3132
    3233using namespace KJS;
     
    3637bool JSHTMLFormElement::canGetItemsForName(ExecState* exec, HTMLFormElement* form, const AtomicString& propertyName)
    3738{
    38     // FIXME: ideally there should be a lighter-weight way of doing this
    39     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);
    4142}
    4243
    4344JSValue* JSHTMLFormElement::nameGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
    4445{
    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));
    4951}
    5052
  • trunk/WebCore/bindings/js/kjs_dom.cpp

    r20130 r20148  
    11221122}
    11231123
    1124 // -------------------------------------------------------------------------
    1125 
    1126 const ClassInfo DOMNamedNodesCollection::info = { "Collection", 0, 0, 0 };
    1127 
    1128 // Such a collection is usually very short-lived, it only exists
    1129 // 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 a
    1165   // 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 
    11791124} // namespace
  • trunk/WebCore/bindings/js/kjs_dom.h

    r19617 r20148  
    143143  JSObject* getDOMExceptionConstructor(ExecState*);
    144144
    145   // Internal class, used for the collection return by e.g. document.forms.myinput
    146   // 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 
    160145} // namespace
    161146
  • trunk/WebCore/bindings/js/kjs_html.cpp

    r20130 r20148  
    11// -*- c-basic-offset: 4 -*-
    22/*
    3  *  This file is part of the KDE libraries
    43 *  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.
    65 *
    76 *  This library is free software; you can redistribute it and/or
     
    6968
    7069namespace KJS {
     70
     71class VectorNodeList : public NodeList {
     72public:
     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
     78private:
     79    Vector<RefPtr<Node> > m_nodes;
     80};
    7181
    7282class HTMLElementFunction : public InternalFunctionImp {
     
    15511561        return toJS(exec, namedItems[0].get());
    15521562
    1553     return new DOMNamedNodesCollection(exec, namedItems);
     1563    return toJS(exec, new VectorNodeList(namedItems));
    15541564}
    15551565
  • trunk/WebCore/dom/ChildNodeList.cpp

    r13393 r20148  
    2525#include "config.h"
    2626#include "ChildNodeList.h"
    27 #include "Node.h"
     27
     28#include "Element.h"
    2829
    2930using namespace WebCore;
     
    3132namespace WebCore {
    3233
    33 ChildNodeList::ChildNodeList( Node *n )
    34     : NodeList(n)
     34ChildNodeList::ChildNodeList(Node* n)
     35    : TreeNodeList(n)
    3536{
    3637}
     
    4243
    4344    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())
    4646        len++;
    4747
     
    5252}
    5353
    54 Node *ChildNodeList::item ( unsigned index ) const
     54Node *ChildNodeList::item(unsigned index) const
    5555{
    5656    unsigned int pos = 0;
    57     Node *n = rootNode->firstChild();
     57    Node* n = rootNode->firstChild();
    5858
    5959    if (isItemCacheValid) {
     
    8181}
    8282
    83 bool ChildNodeList::nodeMatches(Node *testNode) const
     83bool ChildNodeList::elementMatches(Element* element) const
    8484{
    85     return testNode->parentNode() == rootNode;
     85    return element->parentNode() == rootNode;
    8686}
    8787
  • trunk/WebCore/dom/ChildNodeList.h

    r18874 r20148  
    3030namespace WebCore {
    3131
    32 class ChildNodeList : public NodeList {
     32class ChildNodeList : public TreeNodeList {
    3333public:
    3434    ChildNodeList(Node*);
     
    3838
    3939protected:
    40     virtual bool nodeMatches(Node* testNode) const;
     40    virtual bool elementMatches(Element*) const;
    4141};
    4242
  • trunk/WebCore/dom/NameNodeList.cpp

    r13480 r20148  
    2929#include "HTMLNames.h"
    3030
    31 using namespace WebCore;
    32 
    3331namespace WebCore {
    3432
    3533using namespace HTMLNames;
    3634
    37 NameNodeList::NameNodeList(Node *n, const String &t)
    38   : NodeList(n), nodeName(t)
     35NameNodeList::NameNodeList(Node* n, const String &t)
     36    : TreeNodeList(n)
     37    , nodeName(t)
    3938{
    4039}
     
    4544}
    4645
    47 Node *NameNodeList::item (unsigned index) const
     46Node *NameNodeList::item(unsigned index) const
    4847{
    4948    return recursiveItem(index);
    5049}
    5150
    52 bool NameNodeList::nodeMatches(Node *testNode) const
     51bool NameNodeList::elementMatches(Element* element) const
    5352{
    54     return static_cast<Element*>(testNode)->getAttribute(nameAttr) == nodeName;
     53    return element->getAttribute(nameAttr) == nodeName;
    5554}
    5655
  • trunk/WebCore/dom/NameNodeList.h

    r18874 r20148  
    3434 * NodeList which lists all Nodes in a Element with a given "name=" tag
    3535 */
    36 class NameNodeList : public NodeList {
     36class NameNodeList : public TreeNodeList {
    3737public:
    3838    NameNodeList(Node* doc, const String& name);
     
    4545    // Other methods (not part of DOM)
    4646    virtual void rootNodeChildrenChanged() { }
    47     virtual void rootNodeAttributeChanged() { NodeList::rootNodeChildrenChanged(); }
     47    virtual void rootNodeAttributeChanged() { TreeNodeList::rootNodeChildrenChanged(); }
    4848
    4949protected:
    50     virtual bool nodeMatches(Node* testNode) const;
     50    virtual bool elementMatches(Element*) const;
    5151
    5252    String nodeName;
  • trunk/WebCore/dom/Node.cpp

    r20028 r20148  
    5151 * NodeList which lists all Nodes in a document with a given tag name
    5252 */
    53 class TagNodeList : public NodeList
    54 {
     53class TagNodeList : public TreeNodeList {
    5554public:
    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
    5957    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;
    6359
    6460protected:
    65     virtual bool nodeMatches(Node *testNode) const;
     61    virtual bool elementMatches(Element*) const;
    6662
    6763    AtomicString m_namespaceURI;
     
    7066
    7167TagNodeList::TagNodeList(Node *n, const AtomicString& namespaceURI, const AtomicString& localName)
    72     : NodeList(n),
     68    : TreeNodeList(n),
    7369      m_namespaceURI(namespaceURI),
    7470      m_localName(localName)
     
    8682}
    8783
    88 bool TagNodeList::nodeMatches(Node *testNode) const
    89 {
    90     if (!testNode->isElementNode())
    91         return false;
    92 
     84bool TagNodeList::elementMatches(Element* testNode) const
     85{
    9386    if (m_namespaceURI != starAtom && m_namespaceURI != testNode->namespaceURI())
    9487        return false;
     
    428421}
    429422
    430 void Node::registerNodeList(NodeList* list)
     423void Node::registerNodeList(TreeNodeList* list)
    431424{
    432425    if (!m_nodeLists)
     
    435428}
    436429
    437 void Node::unregisterNodeList(NodeList* list)
     430void Node::unregisterNodeList(TreeNodeList* list)
    438431{
    439432    if (!m_nodeLists)
  • trunk/WebCore/dom/Node.h

    r20028 r20148  
    5555class RenderStyle;
    5656class TextStream;
     57class TreeNodeList;
    5758
    5859typedef int ExceptionCode;
     
    440441#endif
    441442
    442     void registerNodeList(NodeList*);
    443     void unregisterNodeList(NodeList*);
     443    void registerNodeList(TreeNodeList*);
     444    void unregisterNodeList(TreeNodeList*);
    444445    void notifyNodeListsChildrenChanged();
    445446    void notifyLocalNodeListsChildrenChanged();
     
    457458
    458459protected:
    459     typedef HashSet<NodeList*> NodeListSet;
     460    typedef HashSet<TreeNodeList*> NodeListSet;
    460461    NodeListSet* m_nodeLists;
    461462
  • trunk/WebCore/dom/NodeList.cpp

    r15057 r20148  
    11/**
    2  * This file is part of the DOM implementation for KDE.
    3  *
    42 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    53 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    64 *           (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.
    86 *
    97 * This library is free software; you can redistribute it and/or
     
    3129namespace WebCore {
    3230
    33 NodeList::NodeList(PassRefPtr<Node> _rootNode)
     31NodeList::~NodeList()
     32{
     33}
     34
     35Node* 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
     46TreeNodeList::TreeNodeList(PassRefPtr<Node> _rootNode)
    3447    : rootNode(_rootNode),
    3548      isLengthCacheValid(false),
     
    3952}   
    4053
    41 NodeList::~NodeList()
     54TreeNodeList::~TreeNodeList()
    4255{
    4356    rootNode->unregisterNodeList(this);
    4457}
    4558
    46 unsigned NodeList::recursiveLength(Node* start) const
     59unsigned TreeNodeList::recursiveLength(Node* start) const
    4760{
    4861    if (!start)
     
    5669    for (Node* n = start->firstChild(); n; n = n->nextSibling())
    5770        if (n->isElementNode()) {
    58             if (nodeMatches(n))
    59                 len++;
     71            len += elementMatches(static_cast<Element*>(n));
    6072            len += recursiveLength(n);
    6173        }
     
    6981}
    7082
    71 Node* NodeList::itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const
     83Node* TreeNodeList::itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const
    7284{
    7385    ASSERT(remainingOffset >= 0);
     
    7587    for (Node *n = start; n; n = n->traverseNextNode(rootNode.get())) {
    7688        if (n->isElementNode()) {
    77             if (nodeMatches(n)) {
     89            if (elementMatches(static_cast<Element*>(n))) {
    7890                if (!remainingOffset) {
    7991                    lastItem = n;
     
    90102}
    91103
    92 Node* NodeList::itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const
     104Node* TreeNodeList::itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOffset) const
    93105{
    94106    ASSERT(remainingOffset < 0);
    95107    for (Node *n = start; n; n = n->traversePreviousNode(rootNode.get())) {
    96108        if (n->isElementNode()) {
    97             if (nodeMatches(n)) {
     109            if (elementMatches(static_cast<Element*>(n))) {
    98110                if (!remainingOffset) {
    99111                    lastItem = n;
     
    110122}
    111123
    112 Node* NodeList::recursiveItem(unsigned offset, Node* start) const
     124Node* TreeNodeList::recursiveItem(unsigned offset, Node* start) const
    113125{
    114126    int remainingOffset = offset;
     
    131143}
    132144
    133 Node* NodeList::itemWithName(const AtomicString& elementId) const
     145Node* TreeNodeList::itemWithName(const AtomicString& name) const
    134146{
    135147    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))
    139150            return 0;
    140151
     
    146157    }
    147158
    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);
    156160}
    157161
    158 void NodeList::rootNodeChildrenChanged()
     162void TreeNodeList::rootNodeAttributeChanged()
     163{
     164}
     165
     166void TreeNodeList::rootNodeChildrenChanged()
    159167{
    160168    isLengthCacheValid = false;
  • trunk/WebCore/dom/NodeList.h

    r18874 r20148  
    11/*
    2  * This file is part of the DOM implementation for KDE.
    3  *
    42 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    53 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    64 *           (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.
    86 *
    97 * This library is free software; you can redistribute it and/or
     
    3432
    3533class AtomicString;
     34class Element;
    3635class Node;
    3736
    3837class NodeList : public Shared<NodeList> {
    3938public:
    40     NodeList(PassRefPtr<Node> rootNode);
    4139    virtual ~NodeList();
    4240
    43     // DOM methods & attributes for NodeList
    4441    virtual unsigned length() const = 0;
    4542    virtual Node* item(unsigned index) const = 0;
    46     Node* itemWithName(const AtomicString&) const;
     43    virtual Node* itemWithName(const AtomicString&) const;
     44};
    4745
    48     // Other methods (not part of DOM)
     46// FIXME: Move this to its own source file.
     47class TreeNodeList : public NodeList {
     48public:
     49    TreeNodeList(PassRefPtr<Node> rootNode);
     50    virtual ~TreeNodeList();
     51
     52    virtual Node* itemWithName(const AtomicString&) const;
     53
    4954    virtual void rootNodeChildrenChanged();
    50     virtual void rootNodeAttributeChanged() {}
     55    virtual void rootNodeAttributeChanged();
    5156
    5257protected:
    53     // helper functions for searching all ElementImpls in a tree
     58    // helper functions for searching all elements in a tree
    5459    unsigned recursiveLength(Node* start = 0) const;
    55     Node* recursiveItem (unsigned offset, Node* start = 0) const;
    56     virtual bool nodeMatches(Node* testNode) const = 0;
     60    Node* recursiveItem(unsigned offset, Node* start = 0) const;
     61    virtual bool elementMatches(Element*) const = 0;
    5762
    5863    RefPtr<Node> rootNode;
  • trunk/WebCore/html/HTMLFormElement.cpp

    r20136 r20148  
    5050HTMLFormElement::HTMLFormElement(Document* doc)
    5151    : 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{
    6364}
    6465
    6566HTMLFormElement::~HTMLFormElement()
    6667{
     68    delete m_oldNames;
    6769    delete collectionInfo;
    6870   
     
    273275                    if (current->hasLocalName(inputTag) &&
    274276                        static_cast<HTMLInputElement*>(current)->inputType() == HTMLInputElement::FILE) {
    275                         String path = static_cast<HTMLInputElement*>(current)->value();
     277                        const AtomicString& path = static_cast<HTMLInputElement*>(current)->value();
    276278
    277279                        // FIXME: This won't work if the filename includes a " mark,
     
    280282                        // in the website's character set.
    281283                        hstr += "; filename=\"";
    282                         int start = path.reverseFind('/') + 1;
     284                        int start = path.domString().reverseFind('/') + 1;
    283285                        int length = path.length() - start;
    284286                        hstr += encoding.encode(reinterpret_cast<const UChar*>(path.characters() + start), length, true);
    285287                        hstr += "\"";
    286288
    287                         if (!static_cast<HTMLInputElement*>(current)->value().isEmpty()) {
     289                        if (!path.isEmpty()) {
    288290                            DeprecatedString mimeType = MimeTypeRegistry::getMIMETypeForPath(path).deprecatedString();
    289291                            if (!mimeType.isEmpty()) {
     
    499501        setHTMLEventListener(resetEvent, attr);
    500502    else if (attr->name() == nameAttr) {
    501         String newNameAttr = attr->value();
     503        const AtomicString& newNameAttr = attr->value();
    502504        if (inDocument() && document()->isHTMLDocument()) {
    503505            HTMLDocument *doc = static_cast<HTMLDocument *>(document());
     
    560562        if (currentCheckedRadio == e)
    561563            document()->removeRadioButtonGroup(e->name().impl(), this);
     564        formElementNameChanged(e, e->name());
    562565    }
    563566    removeFromVector(formElements, e);
     
    565568}
    566569
     570void 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
     579HTMLGenericFormElement* 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
    567588bool HTMLFormElement::isURLAttribute(Attribute *attr) const
    568589{
  • trunk/WebCore/html/HTMLFormElement.h

    r20074 r20148  
    6666    void registerFormElement(HTMLGenericFormElement*);
    6767    void removeFormElement(HTMLGenericFormElement*);
     68    void formElementNameChanged(HTMLGenericFormElement*, const AtomicString& oldName);
     69
    6870    void registerImgElement(HTMLImageElement*);
    6971    void removeImgElement(HTMLImageElement*);
     
    100102    void setTarget(const String&);
    101103
     104    HTMLGenericFormElement* oldNamedElement(const AtomicString& oldName) const;
     105
    102106    // FIXME: Change this to be private after getting rid of all the clients.
    103107    Vector<HTMLGenericFormElement*> formElements;
     
    110114    friend class HTMLFormCollection;
    111115
     116    typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLGenericFormElement> > OldNameMap;
     117
     118    OldNameMap* m_oldNames;
    112119    HTMLCollection::CollectionInfo* collectionInfo;
    113120
     
    116123    String m_target;
    117124    String m_enctype;
    118     String m_boundary;
    119125    String m_acceptcharset;
    120126    bool m_post : 1;
  • trunk/WebCore/html/HTMLGenericFormElement.cpp

    r18677 r20148  
    11/*
    2  * This file is part of the DOM implementation for KDE.
    3  *
    42 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    53 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    64 *           (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.
    86 *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
    97 *
     
    5654}
    5755
    58 void HTMLGenericFormElement::parseMappedAttribute(MappedAttribute *attr)
     56void HTMLGenericFormElement::parseMappedAttribute(MappedAttribute* attr)
    5957{
    6058    if (attr->name() == nameAttr) {
    61         // Do nothing.
     59        if (m_form) {
     60            m_form->formElementNameChanged(this, m_oldName);
     61            m_oldName = name();
     62        }
    6263    } else if (attr->name() == disabledAttr) {
    6364        bool oldDisabled = m_disabled;
     
    101102        // and so we don't need to do anything.
    102103        m_form = getForm();
    103         if (m_form)
     104        if (m_form) {
    104105            m_form->registerFormElement(this);
    105         else
     106            m_oldName = name();
     107        } else
    106108            if (isRadioButton() && !name().isEmpty() && isChecked())
    107109                document()->radioButtonChecked((HTMLInputElement*)this, m_form);
  • trunk/WebCore/html/HTMLGenericFormElement.h

    r18874 r20148  
    107107    bool m_readOnly;
    108108    mutable bool m_valueMatchesRenderer;
    109 
     109    AtomicString m_oldName;
    110110};
    111111
  • trunk/WebCore/html/HTMLInputElement.cpp

    r20100 r20148  
    592592                document()->radioButtonChecked(this, form());
    593593        }
     594        HTMLGenericFormElement::parseMappedAttribute(attr);
    594595    } else if (attr->name() == autocompleteAttr) {
    595596        m_autocomplete = !equalIgnoringCase(attr->value(), "off");
Note: See TracChangeset for help on using the changeset viewer.