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
+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
--- /dev/null
+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
+
--- /dev/null
+<!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>
--- /dev/null
+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;
+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
} 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") {
return 0;
} elsif ($type eq "Node") {
return 0;
+ } elsif ($type eq "Element") {
+ return 0;
} elsif ($type eq "Attr") {
$implIncludes{"ExceptionCode.h"} = 1;
return 1;
} 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."
}
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));
#endif
Node* insertAdjacentElement(const String& where, Node* newChild, int& exception);
+ bool contains(const Element*) const;
protected:
virtual void createAttributeMap() const;
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);
};
}
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
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));
}