From ef863e5748c088f80ec9a0ffcaa06201c42e6c98 Mon Sep 17 00:00:00 2001
From: mrmr1993
Date: Thu, 18 Dec 2014 13:23:25 +0000
Subject: Make some minor changes/tweaks to rect handling in dom_utils
---
lib/dom_utils.coffee | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
(limited to 'lib')
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index ebbed006..df1db3b9 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -68,8 +68,7 @@ DomUtils =
else
clientRect = @cropRectToVisible clientRect
- if (!clientRect || clientRect.width < 3 || clientRect.height < 3)
- continue
+ continue unless clientRect
# eliminate invisible elements (see test_harnesses/visibility_test.html)
computedStyle = window.getComputedStyle(element, null)
@@ -81,33 +80,42 @@ DomUtils =
null
+ #
+ # Bounds the rect by the current viewport dimensions. If the rect is offscreen or has a height or width < 3
+ # then null is returned instead of a rect.
+ #
cropRectToVisible: (rect) ->
- if (rect.top < 0)
- rect.height += rect.top
- rect.top = 0
-
- if (rect.left < 0)
- rect.width += rect.left
- rect.left = 0
-
- if (rect.top >= window.innerHeight - 4 || rect.left >= window.innerWidth - 4)
+ boundedRect = Rect.create(
+ Math.max(rect.left, 0),
+ Math.max(rect.top, 0),
+ Math.min(rect.right, window.innerWidth),
+ Math.min(rect.bottom, window.innerHeight)
+ )
+ if boundedRect.width < 3 or boundedRect.height < 3
null
else
- rect
+ boundedRect
+ #
+ # Get the client rects for the elements in a