Changeset 60232 in webkit


Ignore:
Timestamp:
May 26, 2010 6:12:40 AM (14 years ago)
Author:
yael.aharon@nokia.com
Message:

Support the labels attribute in labelable form controls
https://bugs.webkit.org/show_bug.cgi?id=38713

Reviewed by Kent Tamura.

WebCore:

Added a new cache type in NodeRareData to store the new cache type.
This cache is created on demand.

Added the "labels" attribute to all form controls that support this attribute.

Tests: fast/forms/labels-add-htmlFor-label.html

fast/forms/labels-add-parent-label.html
fast/forms/labels-change-htmlFor-attribute.html
fast/forms/labels-item-index.html
fast/forms/labels-remove-htmlFor-attribute.html
fast/forms/labels-remove-htmlFor-label.html
fast/forms/labels-remove-parent-label.html
fast/forms/labels-set-htmlFor-attribute.html

  • CMakeLists.txt:
  • GNUmakefile.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/Node.cpp:

(WebCore::Node::notifyLocalNodeListsLabelChanged):
(WebCore::Node::removeCachedLabelsNodeList):
(WebCore::NodeListsNodeData::invalidateCaches):
(WebCore::NodeListsNodeData::invalidateCachesThatDependOnAttributes):
(WebCore::NodeListsNodeData::isEmpty):

  • dom/Node.h:
  • dom/NodeRareData.h:

(WebCore::NodeListsNodeData::NodeListsNodeData):

  • html/HTMLButtonElement.idl:
  • html/HTMLFormControlElement.cpp:

(WebCore::HTMLFormControlElement::isLabelable):
(WebCore::HTMLFormControlElement::labels):

  • html/HTMLFormControlElement.h:
  • html/HTMLInputElement.idl:
  • html/HTMLLabelElement.cpp:

(WebCore::HTMLLabelElement::parseMappedAttribute):

  • html/HTMLLabelElement.h:
  • html/HTMLMeterElement.idl:
  • html/HTMLProgressElement.idl:
  • html/HTMLSelectElement.idl:
  • html/HTMLTextAreaElement.idl:
  • html/LabelsNodeList.cpp: Added.

(WebCore::LabelsNodeList::LabelsNodeList):
(WebCore::LabelsNodeList::~LabelsNodeList):
(WebCore::LabelsNodeList::nodeMatches):

  • html/LabelsNodeList.h: Added.

(WebCore::LabelsNodeList::create):

LayoutTests:

Update result for HTMLSelectElement, since it now includes the new attribute "labels"

  • fast/dom/domListEnumeration-expected.txt:
  • fast/dom/script-tests/domListEnumeration.js:
  • fast/forms/labels-add-htmlFor-label-expected.txt: Added.
  • fast/forms/labels-add-htmlFor-label.html: Added.
  • fast/forms/labels-add-parent-label-expected.txt: Added.
  • fast/forms/labels-add-parent-label.html: Added.
  • fast/forms/labels-change-htmlFor-attribute-expected.txt: Added.
  • fast/forms/labels-change-htmlFor-attribute.html: Added.
  • fast/forms/labels-item-index-expected.txt: Added.
  • fast/forms/labels-item-index.html: Added.
  • fast/forms/labels-remove-htmlFor-attribute-expected.txt: Added.
  • fast/forms/labels-remove-htmlFor-attribute.html: Added.
  • fast/forms/labels-remove-htmlFor-label-expected.txt: Added.
  • fast/forms/labels-remove-htmlFor-label.html: Added.
  • fast/forms/labels-remove-parent-label-expected.txt: Added.
  • fast/forms/labels-remove-parent-label.html: Added.
  • fast/forms/labels-set-htmlFor-attribute-expected.txt: Added.
  • fast/forms/labels-set-htmlFor-attribute.html: Added.
  • fast/forms/script-tests/labels-add-htmlFor-label.js: Added.
  • fast/forms/script-tests/labels-add-parent-label.js: Added.
  • fast/forms/script-tests/labels-change-htmlFor-attribute.js: Added.
  • fast/forms/script-tests/labels-item-index.js: Added.
  • fast/forms/script-tests/labels-remove-htmlFor-attribute.js: Added.
  • fast/forms/script-tests/labels-remove-htmlFor-label.js: Added.
  • fast/forms/script-tests/labels-remove-parent-label.js: Added.
  • fast/forms/script-tests/labels-set-htmlFor-attribute.js: Added.
Location:
trunk
Files:
26 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r60230 r60232  
     12010-05-26  yael aharon  <yael.aharon@nokia.com>
     2
     3        Reviewed by Kent Tamura.
     4
     5        Support the labels attribute in labelable form controls
     6        https://bugs.webkit.org/show_bug.cgi?id=38713
     7
     8        Update result for HTMLSelectElement, since it now includes the new attribute "labels"
     9        * fast/dom/domListEnumeration-expected.txt:
     10        * fast/dom/script-tests/domListEnumeration.js:
     11
     12        * fast/forms/labels-add-htmlFor-label-expected.txt: Added.
     13        * fast/forms/labels-add-htmlFor-label.html: Added.
     14        * fast/forms/labels-add-parent-label-expected.txt: Added.
     15        * fast/forms/labels-add-parent-label.html: Added.
     16        * fast/forms/labels-change-htmlFor-attribute-expected.txt: Added.
     17        * fast/forms/labels-change-htmlFor-attribute.html: Added.
     18        * fast/forms/labels-item-index-expected.txt: Added.
     19        * fast/forms/labels-item-index.html: Added.
     20        * fast/forms/labels-remove-htmlFor-attribute-expected.txt: Added.
     21        * fast/forms/labels-remove-htmlFor-attribute.html: Added.
     22        * fast/forms/labels-remove-htmlFor-label-expected.txt: Added.
     23        * fast/forms/labels-remove-htmlFor-label.html: Added.
     24        * fast/forms/labels-remove-parent-label-expected.txt: Added.
     25        * fast/forms/labels-remove-parent-label.html: Added.
     26        * fast/forms/labels-set-htmlFor-attribute-expected.txt: Added.
     27        * fast/forms/labels-set-htmlFor-attribute.html: Added.
     28        * fast/forms/script-tests/labels-add-htmlFor-label.js: Added.
     29        * fast/forms/script-tests/labels-add-parent-label.js: Added.
     30        * fast/forms/script-tests/labels-change-htmlFor-attribute.js: Added.
     31        * fast/forms/script-tests/labels-item-index.js: Added.
     32        * fast/forms/script-tests/labels-remove-htmlFor-attribute.js: Added.
     33        * fast/forms/script-tests/labels-remove-htmlFor-label.js: Added.
     34        * fast/forms/script-tests/labels-remove-parent-label.js: Added.
     35        * fast/forms/script-tests/labels-set-htmlFor-attribute.js: Added.
     36
    1372010-05-24  Jeremy Orlow  <jorlow@chromium.org>
    238
  • trunk/LayoutTests/fast/dom/domListEnumeration-expected.txt

    r51172 r60232  
    4242
    4343[object HTMLSelectElement]
    44 PASS resultArray.length is 141
     44PASS resultArray.length is 142
    4545PASS resultArray[0].i is '0'
    4646PASS resultArray[0].item is document.getElementsByTagName('option')[0]
  • trunk/LayoutTests/fast/dom/script-tests/domListEnumeration.js

    r51172 r60232  
    142142var htmlSelectElement = document.getElementsByTagName('select')[0];
    143143resultArray = iterateList(htmlSelectElement);
    144 shouldBe("resultArray.length", "141");
     144shouldBe("resultArray.length", "142");
    145145shouldBe("resultArray[0].i", "'0'");
    146146shouldBe("resultArray[0].item", "document.getElementsByTagName('option')[0]");
  • trunk/WebCore/CMakeLists.txt

    r60180 r60232  
    987987    html/HTMLViewSourceDocument.cpp
    988988    html/ImageData.cpp
     989    html/LabelsNodeList.cpp
    989990    html/PreloadScanner.cpp
    990991    html/StepRange.cpp
  • trunk/WebCore/ChangeLog

    r60231 r60232  
     12010-05-26  yael aharon  <yael.aharon@nokia.com>
     2
     3        Reviewed by Kent Tamura.
     4
     5        Support the labels attribute in labelable form controls
     6        https://bugs.webkit.org/show_bug.cgi?id=38713
     7
     8        Added a new cache type in NodeRareData to store the new cache type.
     9        This cache is created on demand.
     10
     11        Added the "labels" attribute to all form controls that support this attribute.
     12
     13        Tests: fast/forms/labels-add-htmlFor-label.html
     14               fast/forms/labels-add-parent-label.html
     15               fast/forms/labels-change-htmlFor-attribute.html
     16               fast/forms/labels-item-index.html
     17               fast/forms/labels-remove-htmlFor-attribute.html
     18               fast/forms/labels-remove-htmlFor-label.html
     19               fast/forms/labels-remove-parent-label.html
     20               fast/forms/labels-set-htmlFor-attribute.html
     21
     22        * CMakeLists.txt:
     23        * GNUmakefile.am:
     24        * WebCore.gypi:
     25        * WebCore.pro:
     26        * WebCore.vcproj/WebCore.vcproj:
     27        * WebCore.xcodeproj/project.pbxproj:
     28        * dom/Node.cpp:
     29        (WebCore::Node::notifyLocalNodeListsLabelChanged):
     30        (WebCore::Node::removeCachedLabelsNodeList):
     31        (WebCore::NodeListsNodeData::invalidateCaches):
     32        (WebCore::NodeListsNodeData::invalidateCachesThatDependOnAttributes):
     33        (WebCore::NodeListsNodeData::isEmpty):
     34        * dom/Node.h:
     35        * dom/NodeRareData.h:
     36        (WebCore::NodeListsNodeData::NodeListsNodeData):
     37        * html/HTMLButtonElement.idl:
     38        * html/HTMLFormControlElement.cpp:
     39        (WebCore::HTMLFormControlElement::isLabelable):
     40        (WebCore::HTMLFormControlElement::labels):
     41        * html/HTMLFormControlElement.h:
     42        * html/HTMLInputElement.idl:
     43        * html/HTMLLabelElement.cpp:
     44        (WebCore::HTMLLabelElement::parseMappedAttribute):
     45        * html/HTMLLabelElement.h:
     46        * html/HTMLMeterElement.idl:
     47        * html/HTMLProgressElement.idl:
     48        * html/HTMLSelectElement.idl:
     49        * html/HTMLTextAreaElement.idl:
     50        * html/LabelsNodeList.cpp: Added.
     51        (WebCore::LabelsNodeList::LabelsNodeList):
     52        (WebCore::LabelsNodeList::~LabelsNodeList):
     53        (WebCore::LabelsNodeList::nodeMatches):
     54        * html/LabelsNodeList.h: Added.
     55        (WebCore::LabelsNodeList::create):
     56
    1572010-05-26  Xan Lopez  <xlopez@igalia.com>
    258
  • trunk/WebCore/GNUmakefile.am

    r60230 r60232  
    12571257        WebCore/html/ImageData.cpp \
    12581258        WebCore/html/ImageData.h \
     1259        WebCore/html/LabelsNodeList.cpp \
     1260        WebCore/html/LabelsNodeList.h \
    12591261        WebCore/html/MediaError.h \
    12601262        WebCore/html/PreloadScanner.cpp \
  • trunk/WebCore/WebCore.gypi

    r60230 r60232  
    16501650            'html/ImageData.cpp',
    16511651            'html/ImageData.h',
     1652            'html/LabelsNodeList.cpp',
     1653            'html/LabelsNodeList.h',
    16521654            'html/MediaError.h',
    16531655            'html/PreloadScanner.cpp',
  • trunk/WebCore/WebCore.pro

    r60230 r60232  
    696696    html/HTMLViewSourceDocument.cpp \
    697697    html/ImageData.cpp \
     698    html/LabelsNodeList.cpp \
    698699    html/PreloadScanner.cpp \
    699700    html/StepRange.cpp \
     
    14261427    html/HTMLViewSourceDocument.h \
    14271428    html/ImageData.h \
     1429    html/LabelsNodeList.h \
    14281430    html/PreloadScanner.h \
    14291431    html/StepRange.h \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r60230 r60232  
    3523435234                        </File>
    3523535235                        <File
     35236                                RelativePath="..\html\LabelsNodeList.cpp"
     35237                                >
     35238                        </File>
     35239                        <File
     35240                                RelativePath="..\html\LabelsNodeList.h"
     35241                                >
     35242                        </File>
     35243                        <File
    3523635244                                RelativePath="..\html\MediaError.h"
    3523735245                                >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r60230 r60232  
    25902590                A454424E119B3687009BE912 /* RenderMeter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A454424C119B3687009BE912 /* RenderMeter.cpp */; };
    25912591                A454424F119B3687009BE912 /* RenderMeter.h in Headers */ = {isa = PBXBuildFile; fileRef = A454424D119B3687009BE912 /* RenderMeter.h */; };
     2592                A456FA2611AD4A830020B420 /* LabelsNodeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A456FA2411AD4A830020B420 /* LabelsNodeList.cpp */; };
     2593                A456FA2711AD4A830020B420 /* LabelsNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = A456FA2511AD4A830020B420 /* LabelsNodeList.h */; };
    25922594                A513B3D7114B1666001C429B /* KeyEventCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */; };
    25932595                A513B3D8114B166A001C429B /* KeyEventCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */; };
     
    81568158                A454424C119B3687009BE912 /* RenderMeter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMeter.cpp; sourceTree = "<group>"; };
    81578159                A454424D119B3687009BE912 /* RenderMeter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMeter.h; sourceTree = "<group>"; };
     8160                A456FA2411AD4A830020B420 /* LabelsNodeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LabelsNodeList.cpp; sourceTree = "<group>"; };
     8161                A456FA2511AD4A830020B420 /* LabelsNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelsNodeList.h; sourceTree = "<group>"; };
    81588162                A59E3C1C11580F510072928E /* KeyEventCodesIPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KeyEventCodesIPhone.h; path = iphone/KeyEventCodesIPhone.h; sourceTree = "<group>"; };
    81598163                A59E3C1D11580F510072928E /* KeyEventIPhone.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = KeyEventIPhone.mm; path = iphone/KeyEventIPhone.mm; sourceTree = "<group>"; };
     
    1360613610                                A77979140D6B9D0C003851B9 /* ImageData.h */,
    1360713611                                A77979150D6B9D0C003851B9 /* ImageData.idl */,
     13612                                A456FA2411AD4A830020B420 /* LabelsNodeList.cpp */,
     13613                                A456FA2511AD4A830020B420 /* LabelsNodeList.h */,
    1360813614                                E446139B0CD6331000FADA75 /* MediaError.h */,
    1360913615                                E446139C0CD6331000FADA75 /* MediaError.idl */,
     
    1933319339                                97DD4D870FDF4D6E00ECF9A4 /* XSSAuditor.h in Headers */,
    1933419340                                CE172E011136E8CE0062A533 /* ZoomMode.h in Headers */,
     19341                                A456FA2711AD4A830020B420 /* LabelsNodeList.h in Headers */,
    1933519342                        );
    1933619343                        runOnlyForDeploymentPostprocessing = 0;
     
    2162221629                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
    2162321630                                97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */,
     21631                                A456FA2611AD4A830020B420 /* LabelsNodeList.cpp in Sources */,
    2162421632                        );
    2162521633                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/dom/Node.cpp

    r60201 r60232  
    5454#include "InspectorTimelineAgent.h"
    5555#include "KeyboardEvent.h"
     56#include "LabelsNodeList.h"
    5657#include "Logging.h"
    5758#include "MouseEvent.h"
     
    897898}
    898899
     900void Node::notifyLocalNodeListsLabelChanged()
     901{
     902    if (!hasRareData())
     903        return;
     904    NodeRareData* data = rareData();
     905    if (!data->nodeLists())
     906        return;
     907
     908    if (data->nodeLists()->m_labelsNodeListCache)
     909        data->nodeLists()->m_labelsNodeListCache->invalidateCache();
     910}
     911
    899912void Node::removeCachedClassNodeList(ClassNodeList* list, const String& className)
    900913{
     
    928941    ASSERT_UNUSED(list, list == data->m_tagNodeListCache.get(name.impl()));
    929942    data->m_tagNodeListCache.remove(name.impl());
     943}
     944
     945void Node::removeCachedLabelsNodeList(DynamicNodeList* list)
     946{
     947    ASSERT(rareData());
     948    ASSERT(rareData()->nodeLists());
     949    ASSERT_UNUSED(list, list->hasOwnCaches());
     950   
     951    NodeListsNodeData* data = rareData()->nodeLists();
     952    data->m_labelsNodeListCache = 0;
    930953}
    931954
     
    22072230{
    22082231    m_childNodeListCaches->reset();
     2232
     2233    if (m_labelsNodeListCache)
     2234        m_labelsNodeListCache->invalidateCache();
    22092235    TagNodeListCache::const_iterator tagCacheEnd = m_tagNodeListCache.end();
    22102236    for (TagNodeListCache::const_iterator it = m_tagNodeListCache.begin(); it != tagCacheEnd; ++it)
     
    22222248    for (NameNodeListCache::iterator it = m_nameNodeListCache.begin(); it != nameCacheEnd; ++it)
    22232249        it->second->invalidateCache();
     2250    if (m_labelsNodeListCache)
     2251        m_labelsNodeListCache->invalidateCache();
    22242252}
    22252253
     
    22492277            return false;
    22502278    }
     2279
     2280    if (m_labelsNodeListCache)
     2281        return false;
    22512282
    22522283    return true;
  • trunk/WebCore/dom/Node.h

    r59072 r60232  
    528528    void notifyNodeListsAttributeChanged();
    529529    void notifyLocalNodeListsAttributeChanged();
     530    void notifyLocalNodeListsLabelChanged();
    530531    void removeCachedClassNodeList(ClassNodeList*, const String&);
    531532    void removeCachedNameNodeList(NameNodeList*, const String&);
    532533    void removeCachedTagNodeList(TagNodeList*, const QualifiedName&);
     534    void removeCachedLabelsNodeList(DynamicNodeList*);
    533535   
    534536    PassRefPtr<NodeList> getElementsByTagName(const String&);
  • trunk/WebCore/dom/NodeRareData.h

    r59058 r60232  
    5252    TagNodeListCache m_tagNodeListCache;
    5353
     54    RefPtr<DynamicNodeList> m_labelsNodeListCache;
     55   
    5456    static PassOwnPtr<NodeListsNodeData> create()
    5557    {
     
    6365private:
    6466    NodeListsNodeData()
    65         : m_childNodeListCaches(DynamicNodeList::Caches::create())
     67        : m_childNodeListCaches(DynamicNodeList::Caches::create()), m_labelsNodeListCache(0)
    6668    {
    6769    }
  • trunk/WebCore/html/HTMLButtonElement.idl

    r52921 r60232  
    3636        void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error);
    3737        void click();
     38        readonly attribute  NodeList              labels;
    3839    };
    3940
  • trunk/WebCore/html/HTMLFormControlElement.cpp

    r59773 r60232  
    3131#include "ChromeClient.h"
    3232#include "Document.h"
     33#include "ElementRareData.h"
    3334#include "Event.h"
    3435#include "EventHandler.h"
     
    4041#include "HTMLParser.h"
    4142#include "HTMLTokenizer.h"
     43#include "LabelsNodeList.h"
    4244#include "Page.h"
    4345#include "RenderBox.h"
     
    407409    // FIXME: Add meterTag and outputTag to the list once we support them.
    408410    return hasTagName(buttonTag) || hasTagName(inputTag) || hasTagName(keygenTag)
     411#if ENABLE(METER_TAG)
     412        || hasTagName(meterTag)
     413#endif
    409414#if ENABLE(PROGRESS_TAG)
    410415        || hasTagName(progressTag)
    411416#endif
    412417        || hasTagName(selectTag) || hasTagName(textareaTag);
     418}
     419
     420PassRefPtr<NodeList> HTMLFormControlElement::labels()
     421{
     422    if (!isLabelable())
     423        return 0;
     424    if (!document())
     425        return 0;
     426   
     427    NodeRareData* data = Node::ensureRareData();
     428    if (!data->nodeLists()) {
     429        data->setNodeLists(NodeListsNodeData::create());
     430        document()->addNodeListCache();
     431    }
     432   
     433    return LabelsNodeList::create(this);
    413434}
    414435   
  • trunk/WebCore/html/HTMLFormControlElement.h

    r59773 r60232  
    124124
    125125    bool isLabelable() const;
     126    PassRefPtr<NodeList> labels();
    126127   
    127128protected:
  • trunk/WebCore/html/HTMLInputElement.idl

    r53893 r60232  
    9696
    9797        readonly attribute FileList files;
     98        readonly attribute  NodeList       labels;
    9899    };
    99100
  • trunk/WebCore/html/HTMLLabelElement.cpp

    r59248 r60232  
    174174}
    175175
     176void HTMLLabelElement::parseMappedAttribute(Attribute* attribute)
     177{
     178    if (attribute->name() == forAttr) {
     179        // htmlFor attribute change affects other nodes than this.
     180        // Clear the caches to ensure that the labels caches are cleared.
     181        if (document())
     182            document()->notifyLocalNodeListsLabelChanged();
     183    } else
     184        HTMLElement::parseMappedAttribute(attribute);
     185}
     186               
    176187} // namespace
  • trunk/WebCore/html/HTMLLabelElement.h

    r59248 r60232  
    5252    String accessKey() const;
    5353    void setAccessKey(const String&);
    54 
     54   
    5555    String htmlFor() const;
    5656    void setHtmlFor(const String&);
     
    5959
    6060 private:
     61    virtual void parseMappedAttribute(Attribute*);
     62
    6163    String m_formElementID;
    6264};
  • trunk/WebCore/html/HTMLMeterElement.idl

    r59541 r60232  
    3535                     setter raises(DOMException);
    3636        readonly attribute HTMLFormElement form;
     37        readonly attribute NodeList labels;
    3738    };
    3839}
  • trunk/WebCore/html/HTMLProgressElement.idl

    r58687 r60232  
    2828        readonly attribute  double                position;
    2929        readonly attribute  HTMLFormElement       form;
     30        readonly attribute  NodeList              labels;
    3031    };
    3132
  • trunk/WebCore/html/HTMLSelectElement.idl

    r52921 r60232  
    6969        Node item(in [IsIndex] unsigned long index);
    7070        Node namedItem(in DOMString name);
     71        readonly attribute NodeList        labels;
    7172    };
    7273
  • trunk/WebCore/html/HTMLTextAreaElement.idl

    r52921 r60232  
    5151                 attribute long selectionEnd;
    5252        void setSelectionRange(in long start, in long end);
     53        readonly attribute  NodeList              labels;
    5354    };
    5455
Note: See TracChangeset for help on using the changeset viewer.