<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>13464</bug_id>
          
          <creation_ts>2011-07-30 14:16:35 +0000</creation_ts>
          <short_desc>Add Element.contains()?</short_desc>
          <delta_ts>2011-09-07 14:28:52 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Anne">annevk</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>ayg</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>eoconnor</cc>
    
    <cc>erik.arvidsson</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>Ms2ger</cc>
    
    <cc>shadow2531</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>51811</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-07-30 14:16:35 +0000</bug_when>
    <thetext>Presto/WebKit/Trident support this Trident invention. It covers a subset of compareDocumentPosition() with a simpler API.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51863</commentid>
    <comment_count>1</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-07-31 14:18:39 +0000</bug_when>
    <thetext>+1 from me in favor of contains() being defined on Node and working on all Nodes.  Some kind of before()/after() would also be cool, and a way to retrieve the furthest ancestor of a Node so you can check if two Nodes are in the same tree.  compareDocumentPosition() is the kind of incredible evil you get when JS APIs are made up by C++ programmers, and needs to be burned with fire.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51908</commentid>
    <comment_count>2</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2011-08-01 17:11:37 +0000</bug_when>
    <thetext>Based on the use cases listed, it sounds like an API like:

interface Node {
  ...
  Node getCommonAncestor(in Node other);
  ...
};

might be a good solution. It would let you check if two nodes are in the same subtree by doing:

if (node1.getCommonAncestor(node2)) {
  // In same subtree
}

and check for contains() by doing:

if (node1.getCommonAncestor(node2) == node1) {
  // node1 contains node2
}


Of course, performance would be better with separate .contains() and .inSameSubtree() functions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51913</commentid>
    <comment_count>3</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-08-01 18:31:08 +0000</bug_when>
    <thetext>contains() already exists, so it seems better to pave the cowpaths.

getCommonAncestor() as you define it isn&apos;t well-named, because the result might not be an ancestor at all: it might be equal to one or both of the nodes.  The Range interface already has a member called commonAncestorContainer, in fact, and the DOM Range spec uses the term &quot;ancestor container of&quot; to mean &quot;the same as or ancestor of&quot;.

Also, I&apos;m not sure how intuitive it is to ask authors to use getCommonAncestor().  It seems better to have a few simple orthogonal tools than to have one general tool that you can use for several purposes -- the latter is half the problem with compareDocumentPosition() to start with.  Asking authors to do node.getCommonAncestor(node) to get the furthest ancestor of a node or node1.getCommonAncestor(node2) == node 1 check for containment is roundabout.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56044</commentid>
    <comment_count>4</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2011-08-30 16:30:28 +0000</bug_when>
    <thetext>Moving contains to Node seems like a no brainer to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56158</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-09-01 08:36:27 +0000</bug_when>
    <thetext>https://bitbucket.org/ms2ger/dom-core/changeset/9b02836d073d</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56204</commentid>
    <comment_count>6</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-09-01 22:39:36 +0000</bug_when>
    <thetext>For those interested, Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=683852</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56465</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-09-07 13:32:13 +0000</bug_when>
    <thetext>The spec doesn&apos;t match Trident/WebKit/Presto for the case of |node.contains(node)|: per spec this returns false, but Trident/WebKit/Presto return true.  Is this difference purposeful?

The Gecko implementation seems to be following the spec at the moment.

Really wish we wrote tests as we spec stuff.  :(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56471</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-09-07 14:28:52 +0000</bug_when>
    <thetext>https://bitbucket.org/ms2ger/dom-core/changeset/fa4879cb584d

(Still need to write tests :-()</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>