Title: [121478] trunk
Revision
121478
Author
[email protected]
Date
2012-06-28 16:01:06 -0700 (Thu, 28 Jun 2012)

Log Message

Cleanup HTMLFormCollection
https://bugs.webkit.org/show_bug.cgi?id=90111

Reviewed by Andreas Kling.

Source/WebCore: 

Got rid of getNamedItem and enamed getNamedFormItem to firstNamedItem and got rid of duplicateNumber argument since
it's always 0. Also made it a static local function. In addition, removed nextItem() since it's not used anywhere.

WebKit API Test: WebKit1.HTMLFormCollectionNamedItemTest

* html/HTMLFormCollection.cpp:
(WebCore::firstNamedItem):
(WebCore):
(WebCore::HTMLFormCollection::namedItem):
* html/HTMLFormCollection.h:
(HTMLFormCollection):

Tools: 

Add a WebKit API test using copy-paste design pattern per kling's request.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.html: Added.
* TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.mm: Added.
(-[HTMLFormCollectionNamedItemTest webView:didFinishLoadForFrame:]):
(TestWebKitAPI):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121477 => 121478)


--- trunk/Source/WebCore/ChangeLog	2012-06-28 22:57:08 UTC (rev 121477)
+++ trunk/Source/WebCore/ChangeLog	2012-06-28 23:01:06 UTC (rev 121478)
@@ -1,3 +1,22 @@
+2012-06-27  Ryosuke Niwa  <[email protected]>
+
+        Cleanup HTMLFormCollection
+        https://bugs.webkit.org/show_bug.cgi?id=90111
+
+        Reviewed by Andreas Kling.
+
+        Got rid of getNamedItem and enamed getNamedFormItem to firstNamedItem and got rid of duplicateNumber argument since
+        it's always 0. Also made it a static local function. In addition, removed nextItem() since it's not used anywhere.
+
+        WebKit API Test: WebKit1.HTMLFormCollectionNamedItemTest
+
+        * html/HTMLFormCollection.cpp:
+        (WebCore::firstNamedItem):
+        (WebCore):
+        (WebCore::HTMLFormCollection::namedItem):
+        * html/HTMLFormCollection.h:
+        (HTMLFormCollection):
+
 2012-06-28  Alec Flett  <[email protected]>
 
         IndexedDB: Hook up render-side key ASSERTing for get()

Modified: trunk/Source/WebCore/html/HTMLFormCollection.cpp (121477 => 121478)


--- trunk/Source/WebCore/html/HTMLFormCollection.cpp	2012-06-28 22:57:08 UTC (rev 121477)
+++ trunk/Source/WebCore/html/HTMLFormCollection.cpp	2012-06-28 23:01:06 UTC (rev 121478)
@@ -116,51 +116,29 @@
     return 0;
 }
 
-Element* HTMLFormCollection::getNamedItem(const QualifiedName& attrName, const AtomicString& name) const
+static HTMLElement* firstNamedItem(const Vector<FormAssociatedElement*>& elementsArray,
+    const Vector<HTMLImageElement*>* imageElementsArray, const QualifiedName& attrName, const String& name)
 {
-    m_cache.position = 0;
-    return getNamedFormItem(attrName, name, 0);
-}
+    ASSERT(attrName == idAttr || attrName == nameAttr);
 
-Element* HTMLFormCollection::getNamedFormItem(const QualifiedName& attrName, const String& name, int duplicateNumber) const
-{
-    const Vector<FormAssociatedElement*>& elementsArray = formControlElements();
-
-    bool foundInputElements = false;
     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;
-            if (!duplicateNumber)
-                return element;
-            --duplicateNumber;
-        }
+        HTMLElement* element = toHTMLElement(elementsArray[i]);
+        if (elementsArray[i]->isEnumeratable() && element->fastGetAttribute(attrName) == name)
+            return element;
     }
 
-    if (base()->hasTagName(fieldsetTag))
+    if (!imageElementsArray)
         return 0;
 
-    const Vector<HTMLImageElement*>& imageElementsArray = formImageElements();
-    if (!foundInputElements) {
-        for (unsigned i = 0; i < imageElementsArray.size(); ++i) {
-            HTMLImageElement* element = imageElementsArray[i];
-            if (element->getAttribute(attrName) == name) {
-                if (!duplicateNumber)
-                    return element;
-                --duplicateNumber;
-            }
-        }
+    for (unsigned i = 0; i < imageElementsArray->size(); ++i) {
+        HTMLImageElement* element = (*imageElementsArray)[i];
+        if (element->fastGetAttribute(attrName) == name)
+            return element;
     }
 
     return 0;
 }
 
-Node* HTMLFormCollection::nextItem() const
-{
-    return item(m_cache.position + 1);
-}
-
 Node* HTMLFormCollection::namedItem(const AtomicString& name) const
 {
     // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp
@@ -169,11 +147,11 @@
     // object with a matching name attribute, but only on those elements
     // that are allowed a name attribute.
     invalidateCacheIfNeeded();
-    m_cache.current = getNamedItem(idAttr, name);
-    if (m_cache.current)
-        return m_cache.current;
-    m_cache.current = getNamedItem(nameAttr, name);
-    return m_cache.current;
+    const Vector<HTMLImageElement*>* imagesElements = base()->hasTagName(fieldsetTag) ? 0 : &formImageElements();
+    if (HTMLElement* item = firstNamedItem(formControlElements(), imagesElements, idAttr, name))
+        return item;
+
+    return firstNamedItem(formControlElements(), imagesElements, nameAttr, name);
 }
 
 void HTMLFormCollection::updateNameCache() const

Modified: trunk/Source/WebCore/html/HTMLFormCollection.h (121477 => 121478)


--- trunk/Source/WebCore/html/HTMLFormCollection.h	2012-06-28 22:57:08 UTC (rev 121477)
+++ trunk/Source/WebCore/html/HTMLFormCollection.h	2012-06-28 23:01:06 UTC (rev 121478)
@@ -41,8 +41,6 @@
     virtual ~HTMLFormCollection();
 
     virtual Node* item(unsigned index) const;
-    virtual Node* nextItem() const;
-
     virtual Node* namedItem(const AtomicString& name) const;
 
 private:
@@ -51,9 +49,6 @@
     virtual void updateNameCache() const;
     virtual unsigned calcLength() const;
 
-    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;

Modified: trunk/Tools/ChangeLog (121477 => 121478)


--- trunk/Tools/ChangeLog	2012-06-28 22:57:08 UTC (rev 121477)
+++ trunk/Tools/ChangeLog	2012-06-28 23:01:06 UTC (rev 121478)
@@ -1,3 +1,19 @@
+2012-06-28  Ryosuke Niwa  <[email protected]>
+
+        Cleanup HTMLFormCollection
+        https://bugs.webkit.org/show_bug.cgi?id=90111
+
+        Reviewed by Andreas Kling.
+
+        Add a WebKit API test using copy-paste design pattern per kling's request.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.html: Added.
+        * TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.mm: Added.
+        (-[HTMLFormCollectionNamedItemTest webView:didFinishLoadForFrame:]):
+        (TestWebKitAPI):
+        (TestWebKitAPI::TEST):
+
 2012-06-28  Tim Horton  <[email protected]>
 
         [mac] WKTR windows still don't stay off screen sometimes

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (121477 => 121478)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2012-06-28 22:57:08 UTC (rev 121477)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2012-06-28 23:01:06 UTC (rev 121478)
@@ -71,6 +71,8 @@
 		93F1DB5714DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1DB5614DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp */; };
 		93F7E86C14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */; };
 		93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
+		9B26FC6C159D061000CC3765 /* HTMLFormCollectionNamedItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B26FC6B159D061000CC3765 /* HTMLFormCollectionNamedItem.mm */; };
+		9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */; };
 		A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; };
 		B55F11A01516834F00915916 /* AttributedString.mm in Sources */ = {isa = PBXBuildFile; fileRef = B55F119F1516834F00915916 /* AttributedString.mm */; };
 		B55F11B71517D03300915916 /* attributedStringCustomFont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = B55F11B01517A2C400915916 /* attributedStringCustomFont.html */; };
@@ -186,6 +188,7 @@
 				B55F11B71517D03300915916 /* attributedStringCustomFont.html in Copy Resources */,
 				76E182DF154767E600F1FADD /* auto-submitting-form.html in Copy Resources */,
 				5142B2731517C8C800C32B19 /* ContextMenuCanCopyURL.html in Copy Resources */,
+				9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */,
 				E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */,
 				517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html in Copy Resources */,
 				379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
@@ -279,6 +282,8 @@
 		93F1DB5614DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp; sourceTree = "<group>"; };
 		93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames.cpp; sourceTree = "<group>"; };
 		93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp; sourceTree = "<group>"; };
+		9B26FC6B159D061000CC3765 /* HTMLFormCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLFormCollectionNamedItem.mm; sourceTree = "<group>"; };
+		9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLFormCollectionNamedItem.html; sourceTree = "<group>"; };
 		A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckedArithmeticOperations.cpp; path = WTF/CheckedArithmeticOperations.cpp; sourceTree = "<group>"; };
 		B55F119F1516834F00915916 /* AttributedString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedString.mm; sourceTree = "<group>"; };
 		B55F11B01517A2C400915916 /* attributedStringCustomFont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = attributedStringCustomFont.html; sourceTree = "<group>"; };
@@ -658,6 +663,7 @@
 				C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */,
 				3776BC62150946BC0043A66D /* DeviceScaleFactorInDashboardRegions.mm */,
 				939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
+				9B26FC6B159D061000CC3765 /* HTMLFormCollectionNamedItem.mm */,
 				C507E8A614C6545B005D6B3B /* InspectorBar.mm */,
 				E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */,
 				517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */,
@@ -681,6 +687,7 @@
 				379028B814FABE49007E6B43 /* acceptsFirstMouse.html */,
 				5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */,
 				37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */,
+				9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */,
 				E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */,
 				517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */,
 				C07E6CB113FD738A0038B22B /* devicePixelRatio.html */,
@@ -891,6 +898,7 @@
 				F6F49C6915545C8E0007F39D /* DOMWindowExtensionNoCache.cpp in Sources */,
 				51E93017156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp in Sources */,
 				52B8CF9615868CF000281053 /* SetDocumentURI.mm in Sources */,
+				9B26FC6C159D061000CC3765 /* HTMLFormCollectionNamedItem.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Tools/TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.html (0 => 121478)


--- trunk/Tools/TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.html	2012-06-28 23:01:06 UTC (rev 121478)
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<body>
+<form>
+    <input type="text" name="nameForTwoTextFields" value="firstItem">
+    <input type="text" name="nameForTwoTextFields" value="secondItem">
+</form>
+</body>
+</html>

Added: trunk/Tools/TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.mm (0 => 121478)


--- trunk/Tools/TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/HTMLFormCollectionNamedItem.mm	2012-06-28 23:01:06 UTC (rev 121478)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include <wtf/RetainPtr.h>
+
+#import <WebKit/DOM.h>
+#import <WebKit/WebViewPrivate.h>
+
+@interface HTMLFormCollectionNamedItemTest : NSObject {
+}
+@end
+
+static bool didFinishLoad;
+
+@implementation HTMLFormCollectionNamedItemTest
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKit1, HTMLFormCollectionNamedItemTest)
+{
+    RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+    RetainPtr<HTMLFormCollectionNamedItemTest> testController(AdoptNS, [HTMLFormCollectionNamedItemTest new]);
+
+    webView.get().frameLoadDelegate = testController.get();
+    [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle]
+        URLForResource:@"HTMLFormCollectionNamedItem" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    DOMDocument *document = webView.get().mainFrameDocument;
+    DOMHTMLFormElement *form = (DOMHTMLFormElement *)[document querySelector:@"form"];
+    RetainPtr<DOMHTMLCollection> collection = [form elements];
+
+    EXPECT_EQ([collection.get() length], (unsigned)2);
+    EXPECT_WK_STREQ([[collection.get() item:0] value], @"firstItem");
+    EXPECT_WK_STREQ([[collection.get() item:1] value], @"secondItem");
+    EXPECT_WK_STREQ([[collection.get() namedItem:@"nameForTwoTextFields"] value], @"firstItem");
+    EXPECT_WK_STREQ([[collection.get() item:1] value], @"secondItem");
+    EXPECT_WK_STREQ([[collection.get() item:0] value], @"firstItem");
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to