Title: [117754] trunk/Source/WebCore
- Revision
- 117754
- Author
- [email protected]
- Date
- 2012-05-21 03:29:37 -0700 (Mon, 21 May 2012)
Log Message
[Forms] Refactor HTMLFormCollection
https://bugs.webkit.org/show_bug.cgi?id=86602
Patch by Rakesh KN <[email protected]> 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.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (117753 => 117754)
--- trunk/Source/WebCore/ChangeLog 2012-05-21 09:49:53 UTC (rev 117753)
+++ trunk/Source/WebCore/ChangeLog 2012-05-21 10:29:37 UTC (rev 117754)
@@ -1,3 +1,41 @@
+2012-05-21 Rakesh KN <[email protected]>
+
+ [Forms] Refactor HTMLFormCollection
+ https://bugs.webkit.org/show_bug.cgi?id=86602
+
+ 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.
+
2012-05-21 Yury Semikhatsky <[email protected]>
Web Inspector: expand only neighbors of the highlighted node when revealing it in heap snapshot
Modified: trunk/Source/WebCore/html/HTMLFormCollection.cpp (117753 => 117754)
--- trunk/Source/WebCore/html/HTMLFormCollection.cpp 2012-05-21 09:49:53 UTC (rev 117753)
+++ trunk/Source/WebCore/html/HTMLFormCollection.cpp 2012-05-21 10:29:37 UTC (rev 117754)
@@ -35,26 +35,47 @@
// Since the collections are to be "live", we have to do the
// calculation every time if anything has changed.
-HTMLFormCollection::HTMLFormCollection(HTMLFormElement* form)
- : HTMLCollection(form, FormControls)
+HTMLFormCollection::HTMLFormCollection(HTMLElement* base)
+ : HTMLCollection(base, FormControls)
, currentPos(0)
{
}
-PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLFormElement* form)
+PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLElement* base)
{
- return adoptPtr(new HTMLFormCollection(form));
+ return adoptPtr(new HTMLFormCollection(base));
}
HTMLFormCollection::~HTMLFormCollection()
{
}
-unsigned HTMLFormCollection::calcLength() const
+const Vector<FormAssociatedElement*>& HTMLFormCollection::formControlElements() const
{
+ ASSERT(base());
+ ASSERT(base()->hasTagName(formTag));
+ return static_cast<HTMLFormElement*>(base())->associatedElements();
+}
+
+const Vector<HTMLImageElement*>& HTMLFormCollection::formImageElements() const
+{
+ ASSERT(base());
+ ASSERT(base()->hasTagName(formTag));
+ return static_cast<HTMLFormElement*>(base())->imageElements();
+}
+
+unsigned HTMLFormCollection::numberOfFormControlElements() const
+{
+ ASSERT(base());
+ ASSERT(base()->hasTagName(formTag));
return static_cast<HTMLFormElement*>(base())->length();
}
+unsigned HTMLFormCollection::calcLength() const
+{
+ return numberOfFormControlElements();
+}
+
Node* HTMLFormCollection::item(unsigned index) const
{
invalidateCacheIfNeeded();
@@ -71,7 +92,7 @@
m_cache.elementsArrayPosition = 0;
}
- Vector<FormAssociatedElement*>& elementsArray = static_cast<HTMLFormElement*>(base())->m_associatedElements;
+ const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
unsigned currentIndex = m_cache.position;
for (unsigned i = m_cache.elementsArrayPosition; i < elementsArray.size(); i++) {
@@ -99,14 +120,11 @@
Element* HTMLFormCollection::getNamedFormItem(const QualifiedName& attrName, const String& name, int duplicateNumber) const
{
- HTMLFormElement* form = static_cast<HTMLFormElement*>(base());
+ const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
- if (!form)
- return 0;
-
bool foundInputElements = false;
- for (unsigned i = 0; i < form->m_associatedElements.size(); ++i) {
- FormAssociatedElement* associatedElement = form->m_associatedElements[i];
+ for (unsigned i = 0; i < elementsArray.size(); ++i) {
+ FormAssociatedElement* associatedElement = elementsArray[i];
HTMLElement* element = toHTMLElement(associatedElement);
if (associatedElement->isEnumeratable() && element->getAttribute(attrName) == name) {
foundInputElements = true;
@@ -116,9 +134,10 @@
}
}
+ const Vector<HTMLImageElement*>& imageElementsArray = formImageElements();
if (!foundInputElements) {
- for (unsigned i = 0; i < form->m_imageElements.size(); ++i) {
- HTMLImageElement* element = form->m_imageElements[i];
+ for (unsigned i = 0; i < imageElementsArray.size(); ++i) {
+ HTMLImageElement* element = imageElementsArray[i];
if (element->getAttribute(attrName) == name) {
if (!duplicateNumber)
return element;
@@ -157,10 +176,10 @@
HashSet<AtomicStringImpl*> foundInputElements;
- HTMLFormElement* f = static_cast<HTMLFormElement*>(base());
+ const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
- for (unsigned i = 0; i < f->m_associatedElements.size(); ++i) {
- FormAssociatedElement* associatedElement = f->m_associatedElements[i];
+ for (unsigned i = 0; i < elementsArray.size(); ++i) {
+ FormAssociatedElement* associatedElement = elementsArray[i];
if (associatedElement->isEnumeratable()) {
HTMLElement* element = toHTMLElement(associatedElement);
const AtomicString& idAttrVal = element->getIdAttribute();
@@ -176,8 +195,9 @@
}
}
- for (unsigned i = 0; i < f->m_imageElements.size(); ++i) {
- HTMLImageElement* element = f->m_imageElements[i];
+ const Vector<HTMLImageElement*>& imageElementsArray = formImageElements();
+ for (unsigned i = 0; i < imageElementsArray.size(); ++i) {
+ HTMLImageElement* element = imageElementsArray[i];
const AtomicString& idAttrVal = element->getIdAttribute();
const AtomicString& nameAttrVal = element->getNameAttribute();
if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl()))
Modified: trunk/Source/WebCore/html/HTMLFormCollection.h (117753 => 117754)
--- trunk/Source/WebCore/html/HTMLFormCollection.h 2012-05-21 09:49:53 UTC (rev 117753)
+++ trunk/Source/WebCore/html/HTMLFormCollection.h 2012-05-21 10:29:37 UTC (rev 117754)
@@ -27,15 +27,16 @@
namespace WebCore {
-class HTMLFormElement;
+class FormAssociatedElement;
+class HTMLElement;
+class HTMLImageElement;
class QualifiedName;
-
// This class is just a big hack to find form elements even in malformed HTML elements.
// The famous <table><tr><form><td> problem.
class HTMLFormCollection : public HTMLCollection {
public:
- static PassOwnPtr<HTMLFormCollection> create(HTMLFormElement*);
+ static PassOwnPtr<HTMLFormCollection> create(HTMLElement*);
virtual ~HTMLFormCollection();
@@ -45,7 +46,7 @@
virtual Node* namedItem(const AtomicString& name) const;
private:
- HTMLFormCollection(HTMLFormElement*);
+ HTMLFormCollection(HTMLElement*);
virtual void updateNameCache() const;
virtual unsigned calcLength() const;
@@ -53,6 +54,10 @@
Element* getNamedItem(const QualifiedName& attrName, const AtomicString& name) const;
Element* getNamedFormItem(const QualifiedName& attrName, const String& name, int duplicateNumber) const;
+ const Vector<FormAssociatedElement*>& formControlElements() const;
+ const Vector<HTMLImageElement*>& formImageElements() const;
+ unsigned numberOfFormControlElements() const;
+
mutable int currentPos;
};
Modified: trunk/Source/WebCore/html/HTMLFormElement.h (117753 => 117754)
--- trunk/Source/WebCore/html/HTMLFormElement.h 2012-05-21 09:49:53 UTC (rev 117753)
+++ trunk/Source/WebCore/html/HTMLFormElement.h 2012-05-21 10:29:37 UTC (rev 117754)
@@ -110,7 +110,8 @@
CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
const Vector<FormAssociatedElement*>& associatedElements() const { return m_associatedElements; }
-
+ const Vector<HTMLImageElement*>& imageElements() const { return m_imageElements; }
+
void getTextFieldValues(StringPairVector& fieldNamesAndValues) const;
private:
@@ -145,8 +146,6 @@
// are any invalid controls in this form.
bool checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<FormAssociatedElement> >&);
- friend class HTMLFormCollection;
-
typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap;
FormSubmission::Attributes m_attributes;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes