Form of FormAssociatedElement is not updated when id target changes.
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2012 15:36:50 +0000 (15:36 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2012 15:36:50 +0000 (15:36 +0000)
commitb3baef62a291213ffc75a295a96edcd28ca8731c
treeeac33cdda524eae53be7ee0d656938e3a25e8626
parentede987885e1395ac80e95faeddb868e569264bb4
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122584 268f45cc-cd09-0410-ab3c-d52691b4dbfc
23 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/update-form-attribute-element-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/update-form-attribute-element.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/DOMAllInOne.cpp
Source/WebCore/dom/IdTargetObserver.cpp [new file with mode: 0644]
Source/WebCore/dom/IdTargetObserver.h [new file with mode: 0644]
Source/WebCore/dom/IdTargetObserverRegistry.cpp [new file with mode: 0644]
Source/WebCore/dom/IdTargetObserverRegistry.h [new file with mode: 0644]
Source/WebCore/dom/TreeScope.cpp
Source/WebCore/dom/TreeScope.h
Source/WebCore/html/FormAssociatedElement.cpp
Source/WebCore/html/FormAssociatedElement.h
Source/WebCore/html/FormController.cpp
Source/WebCore/html/FormController.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h