Changeset 117754 in webkit


Ignore:
Timestamp:
May 21, 2012 3:29:37 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[Forms] Refactor HTMLFormCollection
https://bugs.webkit.org/show_bug.cgi?id=86602

Patch by Rakesh KN <rakesh.kn@motorola.com> on 2012-05-21
Reviewed by Kent Tamura.

Modify HTMLFormCollection to be independent of HTMLFormElement which is needed
for implementing HTMLFieldSetElement's element attribute.

Covered by existing tests.

  • html/HTMLFormCollection.cpp:

(WebCore::HTMLFormCollection::HTMLFormCollection):
Modified to take more generic HTMLElement* instead of HTMLFormElement* so that
HTMLFormCollection for HTMLFieldSetElement can also be created.
(WebCore::HTMLFormCollection::create): Ditto.
(WebCore::HTMLFormCollection::formControlElements):
Helper function for getting the array of FormAssociatedElements for this form.
(WebCore::HTMLFormCollection::formImageElements):
Helper function for getting the array of image elements for this form.
(WebCore::HTMLFormCollection::numberOfFormControlElements):
Helper function for getting the number of elements in this form.
(WebCore::HTMLFormCollection::calcLength):
Modified to use new helper functions defined for getting the FormAssociatedElements
and image elements array instead of static_cast to HTMLFormElement.
(WebCore::HTMLFormCollection::item): Ditto.
(WebCore::HTMLFormCollection::getNamedFormItem): Ditto.
(WebCore::HTMLFormCollection::updateNameCache): Ditto.

  • html/HTMLFormCollection.h:

(WebCore):
(HTMLFormCollection):

  • html/HTMLFormElement.h:

(WebCore::HTMLFormElement::imageElements):
New accessor for image elements array of form element.
Also HTMLFormCollection is not needed to be friend of HTMLFormElement as collection
does not access the form element memebers directly now.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117753 r117754  
     12012-05-21  Rakesh KN  <rakesh.kn@motorola.com>
     2
     3        [Forms] Refactor HTMLFormCollection
     4        https://bugs.webkit.org/show_bug.cgi?id=86602
     5
     6        Reviewed by Kent Tamura.
     7
     8        Modify HTMLFormCollection to be independent of HTMLFormElement which is needed
     9        for implementing HTMLFieldSetElement's element attribute.
     10
     11        Covered by existing tests.
     12
     13        * html/HTMLFormCollection.cpp:
     14        (WebCore::HTMLFormCollection::HTMLFormCollection):
     15        Modified to take more generic HTMLElement* instead of HTMLFormElement* so that
     16        HTMLFormCollection for HTMLFieldSetElement can also be created.
     17        (WebCore::HTMLFormCollection::create): Ditto.
     18        (WebCore::HTMLFormCollection::formControlElements):
     19        Helper function for getting the array of FormAssociatedElements for this form.
     20        (WebCore::HTMLFormCollection::formImageElements):
     21        Helper function for getting the array of image elements for this form.
     22        (WebCore::HTMLFormCollection::numberOfFormControlElements):
     23        Helper function for getting the number of elements in this form.
     24        (WebCore::HTMLFormCollection::calcLength):
     25        Modified to use new helper functions defined for getting the FormAssociatedElements
     26        and image elements array instead of static_cast to HTMLFormElement.
     27        (WebCore::HTMLFormCollection::item): Ditto.
     28        (WebCore::HTMLFormCollection::getNamedFormItem): Ditto.
     29        (WebCore::HTMLFormCollection::updateNameCache): Ditto.
     30        * html/HTMLFormCollection.h:
     31        (WebCore):
     32        (HTMLFormCollection):
     33        * html/HTMLFormElement.h:
     34        (WebCore::HTMLFormElement::imageElements):
     35        New accessor for image elements array of form element.
     36        Also HTMLFormCollection is not needed to be friend of HTMLFormElement as collection
     37        does not access the form element memebers directly now.
     38
    1392012-05-21  Yury Semikhatsky  <yurys@chromium.org>
    240
  • trunk/Source/WebCore/html/HTMLFormCollection.cpp

    r116487 r117754  
    3636// calculation every time if anything has changed.
    3737
    38 HTMLFormCollection::HTMLFormCollection(HTMLFormElement* form)
    39     : HTMLCollection(form, FormControls)
     38HTMLFormCollection::HTMLFormCollection(HTMLElement* base)
     39    : HTMLCollection(base, FormControls)
    4040    , currentPos(0)
    4141{
    4242}
    4343
    44 PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLFormElement* form)
    45 {
    46     return adoptPtr(new HTMLFormCollection(form));
     44PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLElement* base)
     45{
     46    return adoptPtr(new HTMLFormCollection(base));
    4747}
    4848
     
    5151}
    5252
     53const Vector<FormAssociatedElement*>& HTMLFormCollection::formControlElements() const
     54{
     55    ASSERT(base());
     56    ASSERT(base()->hasTagName(formTag));
     57    return static_cast<HTMLFormElement*>(base())->associatedElements();
     58}
     59
     60const Vector<HTMLImageElement*>& HTMLFormCollection::formImageElements() const
     61{
     62    ASSERT(base());
     63    ASSERT(base()->hasTagName(formTag));
     64    return static_cast<HTMLFormElement*>(base())->imageElements();
     65}
     66
     67unsigned HTMLFormCollection::numberOfFormControlElements() const
     68{
     69    ASSERT(base());
     70    ASSERT(base()->hasTagName(formTag));
     71    return static_cast<HTMLFormElement*>(base())->length();
     72}
     73
    5374unsigned HTMLFormCollection::calcLength() const
    5475{
    55     return static_cast<HTMLFormElement*>(base())->length();
     76    return numberOfFormControlElements();
    5677}
    5778
     
    7293    }
    7394
    74     Vector<FormAssociatedElement*>& elementsArray = static_cast<HTMLFormElement*>(base())->m_associatedElements;
     95    const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
    7596    unsigned currentIndex = m_cache.position;
    7697   
     
    100121Element* HTMLFormCollection::getNamedFormItem(const QualifiedName& attrName, const String& name, int duplicateNumber) const
    101122{
    102     HTMLFormElement* form = static_cast<HTMLFormElement*>(base());
    103 
    104     if (!form)
    105         return 0;
     123    const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
    106124
    107125    bool foundInputElements = false;
    108     for (unsigned i = 0; i < form->m_associatedElements.size(); ++i) {
    109         FormAssociatedElement* associatedElement = form->m_associatedElements[i];
     126    for (unsigned i = 0; i < elementsArray.size(); ++i) {
     127        FormAssociatedElement* associatedElement = elementsArray[i];
    110128        HTMLElement* element = toHTMLElement(associatedElement);
    111129        if (associatedElement->isEnumeratable() && element->getAttribute(attrName) == name) {
     
    117135    }
    118136
     137    const Vector<HTMLImageElement*>& imageElementsArray = formImageElements();
    119138    if (!foundInputElements) {
    120         for (unsigned i = 0; i < form->m_imageElements.size(); ++i) {
    121             HTMLImageElement* element = form->m_imageElements[i];
     139        for (unsigned i = 0; i < imageElementsArray.size(); ++i) {
     140            HTMLImageElement* element = imageElementsArray[i];
    122141            if (element->getAttribute(attrName) == name) {
    123142                if (!duplicateNumber)
     
    158177    HashSet<AtomicStringImpl*> foundInputElements;
    159178
    160     HTMLFormElement* f = static_cast<HTMLFormElement*>(base());
    161 
    162     for (unsigned i = 0; i < f->m_associatedElements.size(); ++i) {
    163         FormAssociatedElement* associatedElement = f->m_associatedElements[i];
     179    const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
     180
     181    for (unsigned i = 0; i < elementsArray.size(); ++i) {
     182        FormAssociatedElement* associatedElement = elementsArray[i];
    164183        if (associatedElement->isEnumeratable()) {
    165184            HTMLElement* element = toHTMLElement(associatedElement);
     
    177196    }
    178197
    179     for (unsigned i = 0; i < f->m_imageElements.size(); ++i) {
    180         HTMLImageElement* element = f->m_imageElements[i];
     198    const Vector<HTMLImageElement*>& imageElementsArray = formImageElements();
     199    for (unsigned i = 0; i < imageElementsArray.size(); ++i) {
     200        HTMLImageElement* element = imageElementsArray[i];
    181201        const AtomicString& idAttrVal = element->getIdAttribute();
    182202        const AtomicString& nameAttrVal = element->getNameAttribute();
  • trunk/Source/WebCore/html/HTMLFormCollection.h

    r104383 r117754  
    2828namespace WebCore {
    2929
    30 class HTMLFormElement;
     30class FormAssociatedElement;
     31class HTMLElement;
     32class HTMLImageElement;
    3133class QualifiedName;
    32 
    3334// This class is just a big hack to find form elements even in malformed HTML elements.
    3435// The famous <table><tr><form><td> problem.
     
    3637class HTMLFormCollection : public HTMLCollection {
    3738public:
    38     static PassOwnPtr<HTMLFormCollection> create(HTMLFormElement*);
     39    static PassOwnPtr<HTMLFormCollection> create(HTMLElement*);
    3940
    4041    virtual ~HTMLFormCollection();
     
    4647
    4748private:
    48     HTMLFormCollection(HTMLFormElement*);
     49    HTMLFormCollection(HTMLElement*);
    4950
    5051    virtual void updateNameCache() const;
     
    5455    Element* getNamedFormItem(const QualifiedName& attrName, const String& name, int duplicateNumber) const;
    5556
     57    const Vector<FormAssociatedElement*>& formControlElements() const;
     58    const Vector<HTMLImageElement*>& formImageElements() const;
     59    unsigned numberOfFormControlElements() const;
     60
    5661    mutable int currentPos;
    5762};
  • trunk/Source/WebCore/html/HTMLFormElement.h

    r117195 r117754  
    111111
    112112    const Vector<FormAssociatedElement*>& associatedElements() const { return m_associatedElements; }
    113    
     113    const Vector<HTMLImageElement*>& imageElements() const { return m_imageElements; }
     114
    114115    void getTextFieldValues(StringPairVector& fieldNamesAndValues) const;
    115116
     
    146147    bool checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<FormAssociatedElement> >&);
    147148
    148     friend class HTMLFormCollection;
    149 
    150149    typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap;
    151150
Note: See TracChangeset for help on using the changeset viewer.