LayoutTests:
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Mar 2006 09:38:54 +0000 (09:38 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Mar 2006 09:38:54 +0000 (09:38 +0000)
        Reviewed by Anders.

        Test cases for Element.contains, including testing fix for
        <rdar://problem/4405353> JavaScript flickers popups onmouseover

        * fast/dom/Element/contains-method-expected.txt: Added.
        * fast/dom/Element/contains-method.html: Added.
        * fast/dom/Element/resources/contains-method.js: Added.
        * fast/events/capture-on-target.html:

WebCore:

        Reviewed by Anders.

        - fixed  <rdar://problem/4454976> repro crash in -[NSTextView(NSSharing) setSelectedRanges:affinity:stillSelecting:] when navigating

        Also fixed other issues with contains. The problem that caused the bug was:
        - contains should return true for the element itself, unlike isAncestor

        Other problems I fixed:
        - contains shouldn't be present on non-Element nodes
        - contains should return false when passed a non-Element node
        - contains should return false when passed a non-Node

        * bindings/scripts/CodeGeneratorJS.pm: Handle Element as a parameter.
        * dom/Element.cpp:
        (WebCore::Element::contains): Added new implementation.
        * dom/Element.h: Added prototype for contains.
        * dom/Element.idl: Added IDL declaration for contains.
        * khtml/ecma/kjs_dom.cpp:
        (KJS::DOMNodeProtoFunc::callAsFunction): Added old wrong contains().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13555 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/Element/contains-method-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Element/contains-method.html [new file with mode: 0644]
LayoutTests/fast/dom/Element/resources/contains-method.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/dom/Element.cpp
WebCore/dom/Element.h
WebCore/dom/Element.idl
WebCore/khtml/ecma/kjs_dom.cpp

index 7542682fff176db934175227f89a2535bf570625..44564bb69db544841cbab27c8eaa25e83142e00d 100644 (file)
@@ -1,3 +1,15 @@
+2006-03-29  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Anders.
+        
+        Test cases for Element.contains, including testing fix for
+        <rdar://problem/4405353> JavaScript flickers popups onmouseover
+
+        * fast/dom/Element/contains-method-expected.txt: Added.
+        * fast/dom/Element/contains-method.html: Added.
+        * fast/dom/Element/resources/contains-method.js: Added.
+        * fast/events/capture-on-target.html:
+
 2006-03-28  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Maciej
diff --git a/LayoutTests/fast/dom/Element/contains-method-expected.txt b/LayoutTests/fast/dom/Element/contains-method-expected.txt
new file mode 100644 (file)
index 0000000..3a3e97c
--- /dev/null
@@ -0,0 +1,15 @@
+This test checks behavior of Element.contains.
+
+[test1 [test 2]]
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.contains is undefined.
+PASS test1.contains(test2) is true
+PASS test1.contains(test1TextChild) is false
+PASS test1.contains(123) is false
+PASS test1.contains(null) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/Element/contains-method.html b/LayoutTests/fast/dom/Element/contains-method.html
new file mode 100644 (file)
index 0000000..219cdc5
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css">
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/contains-method.js"></script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/Element/resources/contains-method.js b/LayoutTests/fast/dom/Element/resources/contains-method.js
new file mode 100644 (file)
index 0000000..e4989f5
--- /dev/null
@@ -0,0 +1,15 @@
+description(
+'This test checks behavior of Element.contains. <div id="test1">[test1 <span id="test2">[test 2]</span>]</div>'
+);
+
+var test1 = document.getElementById('test1');
+var test1TextChild = document.getElementById('test1').firstChild;
+var test2 = document.getElementById('test2');
+
+shouldBeUndefined("document.contains");
+shouldBeTrue("test1.contains(test2)");
+shouldBeFalse("test1.contains(test1TextChild)");
+shouldBeFalse("test1.contains(123)");
+shouldBeFalse("test1.contains(null)");
+
+var successfullyParsed = true;
index 4c7dcc7178eb1dd759e8ed24ab8d577a138f4440..9d6d682ed4b4b63492f04d3a433a7efcb72cbf4c 100644 (file)
@@ -1,3 +1,25 @@
+2006-03-29  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Anders.
+        
+        - fixed  <rdar://problem/4454976> repro crash in -[NSTextView(NSSharing) setSelectedRanges:affinity:stillSelecting:] when navigating
+        
+        Also fixed other issues with contains. The problem that caused the bug was:
+        - contains should return true for the element itself, unlike isAncestor
+        
+        Other problems I fixed:
+        - contains shouldn't be present on non-Element nodes
+        - contains should return false when passed a non-Element node
+        - contains should return false when passed a non-Node
+
+        * bindings/scripts/CodeGeneratorJS.pm: Handle Element as a parameter.
+        * dom/Element.cpp:
+        (WebCore::Element::contains): Added new implementation.
+        * dom/Element.h: Added prototype for contains.
+        * dom/Element.idl: Added IDL declaration for contains.
+        * khtml/ecma/kjs_dom.cpp:
+        (KJS::DOMNodeProtoFunc::callAsFunction): Added old wrong contains().
+
 2006-03-28  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Maciej
index 1d7303101865a5fe50fbb9009846dea657b9dbcc..65ca981827e97079bd692152e2b4aad196c850cc 100644 (file)
@@ -710,6 +710,7 @@ sub GetNativeType
   } elsif ($type eq "views::AbstractView") {
     return "AbstractView*";
   } elsif ($type eq "Node" or
+           $type eq "Element" or
            $type eq "Attr" or
            $type eq "DocumentType" or
            $type eq "Range") {
@@ -747,6 +748,8 @@ sub TypeCanFailConversion
       return 0;
   } elsif ($type eq "Node") {
       return 0;
+  } elsif ($type eq "Element") {
+      return 0;
   } elsif ($type eq "Attr") {
       $implIncludes{"ExceptionCode.h"} = 1;
       return 1;
@@ -806,6 +809,9 @@ sub JSValueToNative
   } elsif ($type eq "Range") {
       $implIncludes{"JSRange.h"} = 1;
       return "toRange($value)";
+  } elsif ($type eq "Element") {
+    $implIncludes{"kjs_dom.h"} = 1;
+    return "toElement($value)";
   } else {
     die "Don't know how to convert a JS value of type $type."
   }
index 48775ad947f14fa6239aacc5348e3e8dd600e82c..cc343228959c281992c91861f61b659c65f077e5 100644 (file)
@@ -288,6 +288,13 @@ Node* Element::insertAdjacentElement(const String& where, Node* newChild, int& e
     return 0;
 }
 
+bool Element::contains(const Element* element) const
+{
+    if (!element)
+        return false;
+    return this == element || element->isAncestor(this);
+}
+
 void Element::createAttributeMap() const
 {
     namedAttrMap = new NamedAttrMap(const_cast<Element*>(this));
index 32368c24c2d66dd606b372291f3a385b5def97f6..c53cc93c3d9cf2afe6d40eddd466e981f15a90cf 100644 (file)
@@ -143,6 +143,7 @@ public:
 #endif
 
     Node* insertAdjacentElement(const String& where, Node* newChild, int& exception);
+    bool contains(const Element*) const;
  
 protected:
     virtual void createAttributeMap() const;
index 7e8061ec21bfc5dbec50b54c544255fcb6269aef..e54fa25a01e564471db06918d00f7cd4f7c49b61 100644 (file)
@@ -79,13 +79,14 @@ module core {
         void focus();
         void blur();
 
-        // IE only extension
-        Node insertAdjacentElement(in DOMString position, 
-                                   in Node newAttr)
-            raises(DOMException);
-
         readonly attribute CSSStyleDeclaration style;
 
+        // IE only extensions
+        Node insertAdjacentElement(in DOMString position, 
+                                   in Node newElement)
+            raises(DOMException);
+        
+        boolean contains(in Element element);
     };
 
 }
index 312e92c6a5bc00d2875517dd8a700bf20be0ffe7..b96576436f4df6018179769dcbe4725e5ada22b9 100644 (file)
@@ -87,8 +87,6 @@ namespace KJS {
   isDefaultNamespace    DOMNode::IsDefaultNamespace DontDelete|Function 1
   lookupNamespaceURI    DOMNode::LookupNamespaceURI DontDelete|Function 1
   lookupPrefix  DOMNode::LookupPrefix   DontDelete|Function 1
-# IE extension
-  contains      DOMNode::Contains       DontDelete|Function 1
 # "DOM level 0" (from Gecko DOM reference; also in WinIE)
   item          DOMNode::Item           DontDelete|Function 1
 @end
@@ -320,13 +318,6 @@ JSValue *DOMNodeProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, co
      if (node.replaceChild(toNode(args[0]), toNode(args[1]), exception))
         return args[1];
       return jsNull();
-    case DOMNode::Contains:
-      if (node.isElementNode())
-        if (Node *node0 = toNode(args[0]))
-          return jsBoolean(node.isAncestor(node0));
-      // FIXME: Is there a good reason to return undefined rather than false
-      // when the parameter is not a node? When the object is not an element?
-      return jsUndefined();
     case DOMNode::Item:
       return thisObj->get(exec, args[0]->toInt32(exec));
   }