From f6bfd44ad6b3d1905c1eb59cc00cf4cb499863c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 17 Aug 2017 10:19:09 +0200 Subject: [PATCH] script: Add a function to check whether a node is before another one in DOM order. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- components/script/dom/node.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index d0dfaddb77d..a337caf4ef9 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -385,6 +385,17 @@ impl Node { } } + /// Returns true if this node is before `other` in the same connected DOM + /// tree. + pub fn is_before(&self, other: &Node) -> bool { + let cmp = other.CompareDocumentPosition(self); + if cmp & NodeConstants::DOCUMENT_POSITION_DISCONNECTED != 0 { + return false; + } + + cmp & NodeConstants::DOCUMENT_POSITION_PRECEDING != 0 + } + /// Return all registered mutation observers for this node. pub fn registered_mutation_observers(&self) -> RefMut> { self.mutation_observers.borrow_mut()