Exemplo n.º 1
0
        public bool intersects(Node node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (rootNode == node.rootNode)
            {
                var parent = node.parentNode;

                if (parent != null)
                {
                    HtmlElement startElement = startContainer as HtmlElement;
                    HtmlElement endElement   = endContainer as HtmlElement;

                    // Get as element:
                    HtmlElement node1 = node as HtmlElement;

                    if (endElement == null && startElement == null)
                    {
                        // Document - must intersect.
                        return(true);
                    }

                    // End must be after node1 and start must be before node1.

                    // Node 1 must be after start:
                    if (startElement != null && (startElement.compareDocumentPosition(node1) & Node.DOCUMENT_POSITION_FOLLOWING) != Node.DOCUMENT_POSITION_FOLLOWING)
                    {
                        return(false);
                    }

                    // Node 1 must be before end:
                    if (endElement != null && (endElement.compareDocumentPosition(node1) & Node.DOCUMENT_POSITION_PRECEDING) != Node.DOCUMENT_POSITION_PRECEDING)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }