Changeset 122584 in webkit


Ignore:
Timestamp:
Jul 13, 2012 8:36:50 AM (12 years ago)
Author:
keishi@webkit.org
Message:

Form of FormAssociatedElement is not updated when id target changes.
https://bugs.webkit.org/show_bug.cgi?id=91042

Reviewed by Kent Tamura.

Source/WebCore:

Test: fast/forms/update-form-attribute-element.html

This patch introduces the IdTargetObserver and IdTargetObserverRegistry class.
They can be used to be notified when the element that an id is pointing to (the id target)
changes.

  • CMakeLists.txt: Added IdTargetObserverRegistry.{h,cpp} and IdTargetObserver.{h,cpp}
  • GNUmakefile.list.am: Ditto.
  • Target.pri: Ditto.
  • WebCore.gypi: Ditto.
  • WebCore.vcproj/WebCore.vcproj: Ditto.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • dom/DOMAllInOne.cpp:
  • dom/IdTargetObserver.cpp: Added. When you want notified of changes to an id target, you should create a new class that inherits this.

(WebCore):
(WebCore::IdTargetObserver::IdTargetObserver):
(WebCore::IdTargetObserver::~IdTargetObserver):

  • dom/IdTargetObserver.h: Added.

(WebCore):
(IdTargetObserver):

  • dom/IdTargetObserverRegistry.cpp: Added.

(WebCore):
(WebCore::IdTargetObserverRegistry::create):
(WebCore::IdTargetObserverRegistry::addObserver): Register an IdTargetObserver to observe an id target.
(WebCore::IdTargetObserverRegistry::removeObserver): Unregisters an IdTargetObserver from observing.
(WebCore::IdTargetObserverRegistry::notifyObserversInternal):

  • dom/IdTargetObserverRegistry.h: Added.

(WebCore):
(IdTargetObserverRegistry):
(WebCore::IdTargetObserverRegistry::IdTargetObserverRegistry):
(WebCore::IdTargetObserverRegistry::notifyObservers): Calls idTargetChanged on all observers for an id. Inlining first part of function for performance.

  • dom/TreeScope.cpp:

(WebCore::TreeScope::TreeScope):
(WebCore::TreeScope::addElementById): Calls IdTargetObserverRegistry::notifyObservers because the id target might have changed.
(WebCore::TreeScope::removeElementById): Ditto.

  • dom/TreeScope.h:

(WebCore):
(WebCore::TreeScope::idTargetObserverRegistry):
(TreeScope):

  • html/FormAssociatedElement.cpp: Observer for id targets defined by the form attribute.

(WebCore::FormAssociatedElement::didMoveToNewDocument):
(WebCore::FormAssociatedElement::insertedInto):
(WebCore::FormAssociatedElement::removedFrom):
(WebCore::FormAssociatedElement::formAttributeChanged):
(WebCore::FormAssociatedElement::resetFormAttributeTargetObserver): Creates and sets up a new FormAttributeTargetObserver.
(WebCore):
(WebCore::FormAssociatedElement::formAttributeTargetChanged):
(WebCore::FormAttributeTargetObserver::create):
(WebCore::FormAttributeTargetObserver::FormAttributeTargetObserver):
(WebCore::FormAttributeTargetObserver::idTargetChanged):

  • html/FormAssociatedElement.h:

(FormAssociatedElement):

  • html/FormController.cpp:
  • html/FormController.h:

(FormController):

  • html/HTMLFormElement.cpp:

(WebCore::HTMLFormElement::removedFrom):
(WebCore::HTMLFormElement::formElementIndexWithFormAttribute): Modified to take a range. It
scans the range and returns the index to insert the element in m_associatedElement.
(WebCore::HTMLFormElement::formElementIndex): Modified to only scan the elements in
m_associatedElement that precede and follow the form element.

  • html/HTMLFormElement.h:

(HTMLFormElement):

LayoutTests:

  • fast/forms/update-form-attribute-element-expected.txt: Added.
  • fast/forms/update-form-attribute-element.html: Added.
Location:
trunk
Files:
6 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r122583 r122584  
     12012-07-13  Keishi Hattori  <keishi@webkit.org>
     2
     3        Form of FormAssociatedElement is not updated when id target changes.
     4        https://bugs.webkit.org/show_bug.cgi?id=91042
     5
     6        Reviewed by Kent Tamura.
     7
     8        * fast/forms/update-form-attribute-element-expected.txt: Added.
     9        * fast/forms/update-form-attribute-element.html: Added.
     10
    1112012-07-13  Vsevolod Vlasov  <vsevik@chromium.org>
    212
  • trunk/Source/WebCore/CMakeLists.txt

    r122582 r122584  
    611611    dom/GenericEventQueue.cpp
    612612    dom/IconURL.cpp
     613    dom/IdTargetObserver.cpp
     614    dom/IdTargetObserverRegistry.cpp
    613615    dom/KeyboardEvent.cpp
    614616    dom/MessageChannel.cpp
  • trunk/Source/WebCore/ChangeLog

    r122582 r122584  
     12012-07-13  Keishi Hattori  <keishi@webkit.org>
     2
     3        Form of FormAssociatedElement is not updated when id target changes.
     4        https://bugs.webkit.org/show_bug.cgi?id=91042
     5
     6        Reviewed by Kent Tamura.
     7
     8        Test: fast/forms/update-form-attribute-element.html
     9
     10        This patch introduces the IdTargetObserver and IdTargetObserverRegistry class.
     11        They can be used to be notified when the element that an id is pointing to (the id target)
     12        changes.
     13
     14        * CMakeLists.txt: Added IdTargetObserverRegistry.{h,cpp} and IdTargetObserver.{h,cpp}
     15        * GNUmakefile.list.am: Ditto.
     16        * Target.pri: Ditto.
     17        * WebCore.gypi: Ditto.
     18        * WebCore.vcproj/WebCore.vcproj: Ditto.
     19        * WebCore.xcodeproj/project.pbxproj: Ditto.
     20        * dom/DOMAllInOne.cpp:
     21        * dom/IdTargetObserver.cpp: Added. When you want notified of changes to an id target, you should create a new class that inherits this.
     22        (WebCore):
     23        (WebCore::IdTargetObserver::IdTargetObserver):
     24        (WebCore::IdTargetObserver::~IdTargetObserver):
     25        * dom/IdTargetObserver.h: Added.
     26        (WebCore):
     27        (IdTargetObserver):
     28        * dom/IdTargetObserverRegistry.cpp: Added.
     29        (WebCore):
     30        (WebCore::IdTargetObserverRegistry::create):
     31        (WebCore::IdTargetObserverRegistry::addObserver): Register an IdTargetObserver to observe an id target.
     32        (WebCore::IdTargetObserverRegistry::removeObserver): Unregisters an IdTargetObserver from observing.
     33        (WebCore::IdTargetObserverRegistry::notifyObserversInternal):
     34        * dom/IdTargetObserverRegistry.h: Added.
     35        (WebCore):
     36        (IdTargetObserverRegistry):
     37        (WebCore::IdTargetObserverRegistry::IdTargetObserverRegistry):
     38        (WebCore::IdTargetObserverRegistry::notifyObservers): Calls idTargetChanged on all observers for an id. Inlining first part of function for performance.
     39        * dom/TreeScope.cpp:
     40        (WebCore::TreeScope::TreeScope):
     41        (WebCore::TreeScope::addElementById): Calls IdTargetObserverRegistry::notifyObservers because the id target might have changed.
     42        (WebCore::TreeScope::removeElementById): Ditto.
     43        * dom/TreeScope.h:
     44        (WebCore):
     45        (WebCore::TreeScope::idTargetObserverRegistry):
     46        (TreeScope):
     47        * html/FormAssociatedElement.cpp: Observer for id targets defined by the form attribute.
     48        (WebCore::FormAssociatedElement::didMoveToNewDocument):
     49        (WebCore::FormAssociatedElement::insertedInto):
     50        (WebCore::FormAssociatedElement::removedFrom):
     51        (WebCore::FormAssociatedElement::formAttributeChanged):
     52        (WebCore::FormAssociatedElement::resetFormAttributeTargetObserver): Creates and sets up a new FormAttributeTargetObserver.
     53        (WebCore):
     54        (WebCore::FormAssociatedElement::formAttributeTargetChanged):
     55        (WebCore::FormAttributeTargetObserver::create):
     56        (WebCore::FormAttributeTargetObserver::FormAttributeTargetObserver):
     57        (WebCore::FormAttributeTargetObserver::idTargetChanged):
     58        * html/FormAssociatedElement.h:
     59        (FormAssociatedElement):
     60        * html/FormController.cpp:
     61        * html/FormController.h:
     62        (FormController):
     63        * html/HTMLFormElement.cpp:
     64        (WebCore::HTMLFormElement::removedFrom):
     65        (WebCore::HTMLFormElement::formElementIndexWithFormAttribute): Modified to take a range. It
     66        scans the range and returns the index to insert the element in m_associatedElement.
     67        (WebCore::HTMLFormElement::formElementIndex): Modified to only scan the elements in
     68        m_associatedElement that precede and follow the form element.
     69        * html/HTMLFormElement.h:
     70        (HTMLFormElement):
     71
    1722012-07-13  Gabor Rapcsanyi  <rgabor@webkit.org>
    273
  • trunk/Source/WebCore/GNUmakefile.list.am

    r122582 r122584  
    19431943        Source/WebCore/dom/IconURL.cpp \
    19441944        Source/WebCore/dom/IconURL.h \
     1945        Source/WebCore/dom/IdTargetObserver.cpp \
     1946        Source/WebCore/dom/IdTargetObserver.h \
     1947        Source/WebCore/dom/IdTargetObserverRegistry.cpp \
     1948        Source/WebCore/dom/IdTargetObserverRegistry.h \
    19451949        Source/WebCore/dom/HashChangeEvent.h \
    19461950        Source/WebCore/dom/KeyboardEvent.cpp \
  • trunk/Source/WebCore/Target.pri

    r122582 r122584  
    574574    dom/GenericEventQueue.cpp \
    575575    dom/IconURL.cpp \
     576    dom/IdTargetObserver.cpp \
     577    dom/IdTargetObserverRegistry.cpp \
    576578    dom/KeyboardEvent.cpp \
    577579    dom/MessageChannel.cpp \
     
    17611763    dom/ExceptionCode.h \
    17621764    dom/FragmentScriptingPermission.h \
     1765    dom/IdTargetObserver.h \
     1766    dom/IdTargetObserverRegistry.h \
    17631767    dom/KeyboardEvent.h \
    17641768    dom/MemoryInstrumentation.h \
  • trunk/Source/WebCore/WebCore.gypi

    r122582 r122584  
    51825182            'dom/IconURL.cpp',
    51835183            'dom/IconURL.h',
     5184            'dom/IdTargetObserver.cpp',
     5185            'dom/IdTargetObserver.h',
     5186            'dom/IdTargetObserverRegistry.cpp',
     5187            'dom/IdTargetObserverRegistry.h',
    51845188            'dom/KeyboardEvent.cpp',
    51855189            'dom/MemoryInstrumentation.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r122582 r122584  
    5120451204                        </File>
    5120551205                        <File
     51206                                RelativePath="..\dom\IdTargetObserver.cpp"
     51207                                >
     51208                                <FileConfiguration
     51209                                        Name="Debug|Win32"
     51210                                        ExcludedFromBuild="true"
     51211                                        >
     51212                                        <Tool
     51213                                                Name="VCCLCompilerTool"
     51214                                        />
     51215                                </FileConfiguration>
     51216                                <FileConfiguration
     51217                                        Name="Release|Win32"
     51218                                        ExcludedFromBuild="true"
     51219                                        >
     51220                                        <Tool
     51221                                                Name="VCCLCompilerTool"
     51222                                        />
     51223                                </FileConfiguration>
     51224                                <FileConfiguration
     51225                                        Name="Debug_Cairo_CFLite|Win32"
     51226                                        ExcludedFromBuild="true"
     51227                                        >
     51228                                        <Tool
     51229                                                Name="VCCLCompilerTool"
     51230                                        />
     51231                                </FileConfiguration>
     51232                                <FileConfiguration
     51233                                        Name="Release_Cairo_CFLite|Win32"
     51234                                        ExcludedFromBuild="true"
     51235                                        >
     51236                                        <Tool
     51237                                                Name="VCCLCompilerTool"
     51238                                        />
     51239                                </FileConfiguration>
     51240                                <FileConfiguration
     51241                                        Name="Debug_All|Win32"
     51242                                        ExcludedFromBuild="true"
     51243                                        >
     51244                                        <Tool
     51245                                                Name="VCCLCompilerTool"
     51246                                        />
     51247                                </FileConfiguration>
     51248                                <FileConfiguration
     51249                                        Name="Production|Win32"
     51250                                        ExcludedFromBuild="true"
     51251                                        >
     51252                                        <Tool
     51253                                                Name="VCCLCompilerTool"
     51254                                        />
     51255                                </FileConfiguration>
     51256                        </File>
     51257                        <File
     51258                                RelativePath="..\dom\IdTargetObserver.h"
     51259                                >
     51260                        </File>
     51261                        <File
     51262                                RelativePath="..\dom\IdTargetObserverRegistry.cpp"
     51263                                >
     51264                                <FileConfiguration
     51265                                        Name="Debug|Win32"
     51266                                        ExcludedFromBuild="true"
     51267                                        >
     51268                                        <Tool
     51269                                                Name="VCCLCompilerTool"
     51270                                        />
     51271                                </FileConfiguration>
     51272                                <FileConfiguration
     51273                                        Name="Release|Win32"
     51274                                        ExcludedFromBuild="true"
     51275                                        >
     51276                                        <Tool
     51277                                                Name="VCCLCompilerTool"
     51278                                        />
     51279                                </FileConfiguration>
     51280                                <FileConfiguration
     51281                                        Name="Debug_Cairo_CFLite|Win32"
     51282                                        ExcludedFromBuild="true"
     51283                                        >
     51284                                        <Tool
     51285                                                Name="VCCLCompilerTool"
     51286                                        />
     51287                                </FileConfiguration>
     51288                                <FileConfiguration
     51289                                        Name="Release_Cairo_CFLite|Win32"
     51290                                        ExcludedFromBuild="true"
     51291                                        >
     51292                                        <Tool
     51293                                                Name="VCCLCompilerTool"
     51294                                        />
     51295                                </FileConfiguration>
     51296                                <FileConfiguration
     51297                                        Name="Debug_All|Win32"
     51298                                        ExcludedFromBuild="true"
     51299                                        >
     51300                                        <Tool
     51301                                                Name="VCCLCompilerTool"
     51302                                        />
     51303                                </FileConfiguration>
     51304                                <FileConfiguration
     51305                                        Name="Production|Win32"
     51306                                        ExcludedFromBuild="true"
     51307                                        >
     51308                                        <Tool
     51309                                                Name="VCCLCompilerTool"
     51310                                        />
     51311                                </FileConfiguration>
     51312                        </File>
     51313                        <File
     51314                                RelativePath="..\dom\IdTargetObserverRegistry.h"
     51315                                >
     51316                        </File>
     51317                        <File
    5120651318                                RelativePath="..\dom\IgnoreDestructiveWriteCountIncrementer.h"
    5120751319                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r122582 r122584  
    57275727                C33EE5C514FB49610002095A /* BaseClickableWithKeyInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = C33EE5C314FB49610002095A /* BaseClickableWithKeyInputType.h */; };
    57285728                C37CDEBD149EF2030042090D /* ColorChooserClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C37CDEBC149EF2030042090D /* ColorChooserClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
     5729                C3CF17A415B0063F00276D39 /* IdTargetObserver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C3CF17A015B0063F00276D39 /* IdTargetObserver.cpp */; };
     5730                C3CF17A515B0063F00276D39 /* IdTargetObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = C3CF17A115B0063F00276D39 /* IdTargetObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
     5731                C3CF17A615B0063F00276D39 /* IdTargetObserverRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C3CF17A215B0063F00276D39 /* IdTargetObserverRegistry.cpp */; };
     5732                C3CF17A715B0063F00276D39 /* IdTargetObserverRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C3CF17A315B0063F00276D39 /* IdTargetObserverRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
    57295733                C50B561612119D23008B46E0 /* GroupSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C50B561412119D23008B46E0 /* GroupSettings.cpp */; };
    57305734                C50B561712119D23008B46E0 /* GroupSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = C50B561512119D23008B46E0 /* GroupSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1295412958                C33EE5C314FB49610002095A /* BaseClickableWithKeyInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseClickableWithKeyInputType.h; sourceTree = "<group>"; };
    1295512959                C37CDEBC149EF2030042090D /* ColorChooserClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorChooserClient.h; sourceTree = "<group>"; };
     12960                C3CF17A015B0063F00276D39 /* IdTargetObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IdTargetObserver.cpp; sourceTree = "<group>"; };
     12961                C3CF17A115B0063F00276D39 /* IdTargetObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdTargetObserver.h; sourceTree = "<group>"; };
     12962                C3CF17A215B0063F00276D39 /* IdTargetObserverRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IdTargetObserverRegistry.cpp; sourceTree = "<group>"; };
     12963                C3CF17A315B0063F00276D39 /* IdTargetObserverRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdTargetObserverRegistry.h; sourceTree = "<group>"; };
    1295612964                C50B561412119D23008B46E0 /* GroupSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GroupSettings.cpp; sourceTree = "<group>"; };
    1295712965                C50B561512119D23008B46E0 /* GroupSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupSettings.h; sourceTree = "<group>"; };
     
    2146921477                                45099C401370A7800058D513 /* IconURL.cpp */,
    2147021478                                45BAC2AF1360BBAB005DA258 /* IconURL.h */,
     21479                                C3CF17A015B0063F00276D39 /* IdTargetObserver.cpp */,
     21480                                C3CF17A115B0063F00276D39 /* IdTargetObserver.h */,
     21481                                C3CF17A215B0063F00276D39 /* IdTargetObserverRegistry.cpp */,
     21482                                C3CF17A315B0063F00276D39 /* IdTargetObserverRegistry.h */,
    2147121483                                8AB4BC76126FDB7100DEB727 /* IgnoreDestructiveWriteCountIncrementer.h */,
    2147221484                                85031B2D0A44EFC700F992E0 /* KeyboardEvent.cpp */,
     
    2522225234                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
    2522325235                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
     25236                                C3CF17A515B0063F00276D39 /* IdTargetObserver.h in Headers */,
     25237                                C3CF17A715B0063F00276D39 /* IdTargetObserverRegistry.h in Headers */,
    2522425238                        );
    2522525239                        runOnlyForDeploymentPostprocessing = 0;
     
    2828128295                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
    2828228296                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
     28297                                C3CF17A415B0063F00276D39 /* IdTargetObserver.cpp in Sources */,
     28298                                C3CF17A615B0063F00276D39 /* IdTargetObserverRegistry.cpp in Sources */,
    2828328299                        );
    2828428300                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/dom/DOMAllInOne.cpp

    r122556 r122584  
    8585#include "ExceptionCodePlaceholder.cpp"
    8686#include "IconURL.cpp"
     87#include "IdTargetObserver.cpp"
     88#include "IdTargetObserverRegistry.cpp"
    8789#include "KeyboardEvent.cpp"
    8890#include "MessageChannel.cpp"
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r122498 r122584  
    4040#include "HTMLMapElement.h"
    4141#include "HTMLNames.h"
     42#include "IdTargetObserverRegistry.h"
    4243#include "InsertionPoint.h"
    4344#include "Page.h"
     
    5556    : m_rootNode(rootNode)
    5657    , m_parentTreeScope(0)
     58    , m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
    5759{
    5860    ASSERT(rootNode);
     
    9395{
    9496    m_elementsById.add(elementId.impl(), element);
     97    m_idTargetObserverRegistry->notifyObservers(elementId);
    9598}
    9699
     
    98101{
    99102    m_elementsById.remove(elementId.impl(), element);
     103    m_idTargetObserverRegistry->notifyObservers(elementId);
    100104}
    101105
  • trunk/Source/WebCore/dom/TreeScope.h

    r122498 r122584  
    3737class Element;
    3838class HTMLMapElement;
     39class IdTargetObserverRegistry;
    3940class Node;
    4041
     
    7980    ContainerNode* rootNode() const { return m_rootNode; }
    8081
     82    IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTargetObserverRegistry.get(); }
     83
    8184protected:
    8285    TreeScope(ContainerNode*);
     
    9194    DocumentOrderedMap m_elementsById;
    9295    DocumentOrderedMap m_imageMapsByName;
     96
     97    OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry;
    9398
    9499    mutable RefPtr<DOMSelection> m_selection;
  • trunk/Source/WebCore/html/FormAssociatedElement.cpp

    r122559 r122584  
    3131#include "HTMLNames.h"
    3232#include "HTMLObjectElement.h"
     33#include "IdTargetObserver.h"
    3334#include "ValidityState.h"
    3435
     
    3637
    3738using namespace HTMLNames;
     39
     40class FormAttributeTargetObserver : IdTargetObserver {
     41public:
     42    static PassOwnPtr<FormAttributeTargetObserver> create(const AtomicString& id, FormAssociatedElement*);
     43    virtual void idTargetChanged() OVERRIDE;
     44
     45private:
     46    FormAttributeTargetObserver(const AtomicString& id, FormAssociatedElement*);
     47
     48    FormAssociatedElement* m_element;
     49};
    3850
    3951FormAssociatedElement::FormAssociatedElement()
     
    5971    HTMLElement* element = toHTMLElement(this);
    6072    if (oldDocument && element->fastHasAttribute(formAttr))
    61         oldDocument->formController()->unregisterFormElementWithFormAttribute(this);
     73        resetFormAttributeTargetObserver();
    6274}
    6375
     
    7082    HTMLElement* element = toHTMLElement(this);
    7183    if (element->fastHasAttribute(formAttr))
    72         element->document()->formController()->registerFormElementWithFormAttribute(this);
     84        resetFormAttributeTargetObserver();
    7385}
    7486
     
    7789    HTMLElement* element = toHTMLElement(this);
    7890    if (insertionPoint->inDocument() && element->fastHasAttribute(formAttr))
    79         element->document()->formController()->unregisterFormElementWithFormAttribute(this);
     91        m_formAttributeTargetObserver = nullptr;
    8092    // If the form and element are both in the same tree, preserve the connection to the form.
    8193    // Otherwise, null out our form and remove ourselves from the form's list of elements.
     
    154166        // The form attribute removed. We need to reset form owner here.
    155167        setForm(element->findFormAncestor());
    156         element->document()->formController()->unregisterFormElementWithFormAttribute(this);
    157     } else
     168        m_formAttributeTargetObserver = nullptr;
     169    } else {
    158170        resetFormOwner();
     171        resetFormAttributeTargetObserver();
     172    }
    159173}
    160174
     
    220234{
    221235    m_customValidationMessage = error;
     236}
     237
     238void FormAssociatedElement::resetFormAttributeTargetObserver()
     239{
     240    m_formAttributeTargetObserver = FormAttributeTargetObserver::create(toHTMLElement(this)->fastGetAttribute(formAttr), this);
     241}
     242
     243void FormAssociatedElement::formAttributeTargetChanged()
     244{
     245    resetFormOwner();
    222246}
    223247
     
    248272}
    249273
     274PassOwnPtr<FormAttributeTargetObserver> FormAttributeTargetObserver::create(const AtomicString& id, FormAssociatedElement* element)
     275{
     276    return adoptPtr(new FormAttributeTargetObserver(id, element));
     277}
     278
     279FormAttributeTargetObserver::FormAttributeTargetObserver(const AtomicString& id, FormAssociatedElement* element)
     280    : IdTargetObserver(toHTMLElement(element)->treeScope()->idTargetObserverRegistry(), id)
     281    , m_element(element)
     282{
     283}
     284
     285void FormAttributeTargetObserver::idTargetChanged()
     286{
     287    m_element->formAttributeTargetChanged();
     288}
     289
    250290} // namespace Webcore
  • trunk/Source/WebCore/html/FormAssociatedElement.h

    r122559 r122584  
    2929namespace WebCore {
    3030
     31class FormAttributeTargetObserver;
    3132class FormDataList;
    3233class HTMLFormElement;
     
    8182    virtual void setCustomValidity(const String&);
    8283
     84    void formAttributeTargetChanged();
     85
    8386protected:
    8487    FormAssociatedElement();
     
    103106    virtual void derefFormAssociatedElement() = 0;
    104107
     108    void resetFormAttributeTargetObserver();
     109
     110    OwnPtr<FormAttributeTargetObserver> m_formAttributeTargetObserver;
    105111    HTMLFormElement* m_form;
    106112    OwnPtr<ValidityState> m_validityState;
  • trunk/Source/WebCore/html/FormController.cpp

    r122559 r122584  
    277277}
    278278
    279 void FormController::registerFormElementWithFormAttribute(FormAssociatedElement* element)
    280 {
    281     ASSERT(toHTMLElement(element)->fastHasAttribute(formAttr));
    282     m_formElementsWithFormAttribute.add(element);
    283 }
    284 
    285 void FormController::unregisterFormElementWithFormAttribute(FormAssociatedElement* element)
    286 {
    287     m_formElementsWithFormAttribute.remove(element);
    288 }
    289 
    290 void FormController::resetFormElementsOwner()
    291 {
    292     typedef FormAssociatedElementListHashSet::iterator Iterator;
    293     Iterator end = m_formElementsWithFormAttribute.end();
    294     for (Iterator it = m_formElementsWithFormAttribute.begin(); it != end; ++it)
    295         (*it)->resetFormOwner();
    296 }
    297 
    298279FormElementKey::FormElementKey(AtomicStringImpl* name, AtomicStringImpl* type, AtomicStringImpl* formKey)
    299280    : m_name(name)
  • trunk/Source/WebCore/html/FormController.h

    r122559 r122584  
    134134    void restoreControlStateIn(HTMLFormElement&);
    135135
    136     void registerFormElementWithFormAttribute(FormAssociatedElement*);
    137     void unregisterFormElementWithFormAttribute(FormAssociatedElement*);
    138     void resetFormElementsOwner();
    139 
    140136private:
    141137    FormController();
     
    146142    typedef ListHashSet<HTMLFormControlElementWithState*, 64> FormElementListHashSet;
    147143    FormElementListHashSet m_formElementsWithState;
    148     typedef ListHashSet<RefPtr<FormAssociatedElement>, 32> FormAssociatedElementListHashSet;
    149     FormAssociatedElementListHashSet m_formElementsWithFormAttribute;
    150144
    151145    typedef HashMap<FormElementKey, Deque<FormControlState>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
  • trunk/Source/WebCore/html/HTMLFormElement.cpp

    r122559 r122584  
    142142}
    143143
    144 void HTMLFormElement::didNotifyDescendantInsertions(ContainerNode* insertionPoint)
    145 {
    146     ASSERT(insertionPoint->inDocument());
    147     HTMLElement::didNotifyDescendantInsertions(insertionPoint);
    148     if (hasID())
    149         document()->formController()->resetFormElementsOwner();
    150 }
    151 
    152144static inline Node* findRoot(Node* n)
    153145{
     
    165157        associatedElements[i]->formRemovedFromTree(root);
    166158    HTMLElement::removedFrom(insertionPoint);
    167     if (insertionPoint->inDocument() && hasID())
    168         document()->formController()->resetFormElementsOwner();
    169159}
    170160
     
    437427}
    438428
    439 unsigned HTMLFormElement::formElementIndexWithFormAttribute(Element* element)
    440 {
    441     // Compares the position of the form element and the inserted element.
    442     // Updates the indeces in order to the relation of the position:
    443     unsigned short position = compareDocumentPosition(element);
    444     if (position & (DOCUMENT_POSITION_CONTAINS | DOCUMENT_POSITION_CONTAINED_BY))
    445         ++m_associatedElementsAfterIndex;
    446     else if (position & DOCUMENT_POSITION_PRECEDING) {
    447         ++m_associatedElementsBeforeIndex;
    448         ++m_associatedElementsAfterIndex;
    449     }
    450 
     429unsigned HTMLFormElement::formElementIndexWithFormAttribute(Element* element, unsigned rangeStart, unsigned rangeEnd)
     430{
    451431    if (m_associatedElements.isEmpty())
    452432        return 0;
    453433
     434    ASSERT(rangeStart <= rangeEnd);
     435
     436    if (rangeStart == rangeEnd)
     437        return rangeStart;
     438
     439    unsigned left = rangeStart;
     440    unsigned right = rangeEnd - 1;
     441    unsigned short position;
     442
    454443    // Does binary search on m_associatedElements in order to find the index
    455444    // to be inserted.
    456     unsigned left = 0, right = m_associatedElements.size() - 1;
    457445    while (left != right) {
    458446        unsigned middle = left + ((right - left) / 2);
     447        ASSERT(middle < m_associatedElementsBeforeIndex || middle >= m_associatedElementsAfterIndex);
    459448        position = element->compareDocumentPosition(toHTMLElement(m_associatedElements[middle]));
    460449        if (position & DOCUMENT_POSITION_FOLLOWING)
     
    463452            left = middle + 1;
    464453    }
    465 
     454   
     455    ASSERT(left < m_associatedElementsBeforeIndex || left >= m_associatedElementsAfterIndex);
    466456    position = element->compareDocumentPosition(toHTMLElement(m_associatedElements[left]));
    467457    if (position & DOCUMENT_POSITION_FOLLOWING)
     
    475465    // Treats separately the case where this element has the form attribute
    476466    // for performance consideration.
    477     if (element->fastHasAttribute(formAttr))
    478         return formElementIndexWithFormAttribute(element);
     467    if (element->fastHasAttribute(formAttr)) {
     468        unsigned short position = compareDocumentPosition(element);
     469        if (position & DOCUMENT_POSITION_PRECEDING) {
     470            ++m_associatedElementsBeforeIndex;
     471            ++m_associatedElementsAfterIndex;
     472            return HTMLFormElement::formElementIndexWithFormAttribute(element, 0, m_associatedElementsBeforeIndex - 1);
     473        }
     474        if (position & DOCUMENT_POSITION_FOLLOWING && !(position & DOCUMENT_POSITION_CONTAINED_BY))
     475            return HTMLFormElement::formElementIndexWithFormAttribute(element, m_associatedElementsAfterIndex, m_associatedElements.size());
     476    }
    479477
    480478    // Check for the special case where this element is the very last thing in
  • trunk/Source/WebCore/html/HTMLFormElement.h

    r122559 r122584  
    120120    virtual bool rendererIsNeeded(const NodeRenderingContext&);
    121121    virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    122     virtual void didNotifyDescendantInsertions(ContainerNode*) OVERRIDE;
    123122    virtual void removedFrom(ContainerNode*) OVERRIDE;
    124123    virtual void finishParsingChildren() OVERRIDE;
     
    137136    void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
    138137
    139     unsigned formElementIndexWithFormAttribute(Element*);
     138    unsigned formElementIndexWithFormAttribute(Element*, unsigned rangeStart, unsigned rangeEnd);
    140139    unsigned formElementIndex(FormAssociatedElement*);
    141140
Note: See TracChangeset for help on using the changeset viewer.