From 09c30c22cf750230c5a572639153786b07efea73 Mon Sep 17 00:00:00 2001 From: Jeremy Maitin-Shepard Date: Mon, 29 Dec 2008 19:06:28 -0500 Subject: [PATCH] browser-next-form-field: skip non-visible elements --- modules/content-buffer-input.js | 47 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/modules/content-buffer-input.js b/modules/content-buffer-input.js index b7fbc56..a6df5d9 100644 --- a/modules/content-buffer-input.js +++ b/modules/content-buffer-input.js @@ -241,30 +241,37 @@ function browser_focus_next_form_field(buffer, count, xpath_expr) { null /* existing results */); var length = res.snapshotLength; if (length > 0) { - var index = null; - if (focused_elem != null) { - for (var i = 0; i < length; ++i) { - if (res.snapshotItem(i) == focused_elem) { - index = i; - break; - } - } + let valid_nodes = []; + for (let i = 0; i < length; ++i) { + let elem = res.snapshotItem(i); + if (elem.clientWidth == 0 && + elem.clientHeight == 0) + continue; + let style = win.getComputedStyle(elem, ""); + if (style.display == "none" || style.visibility == "hidden") + continue; + valid_nodes.push(elem); } - if (index == null) { - if (count > 0) - index = count - 1; + + if (valid_nodes.length > 0) { + var index = -1; + if (focused_elem != null) + index = valid_nodes.indexOf(focused_elem); + if (index == -1) { + if (count > 0) + index = count - 1; + else + index = -count; + } else - index = -count; - } - else - index = index + count; - index = index % length; - if (index < 0) - index += length; + index = index + count; + index = index % valid_nodes.length; + if (index < 0) + index += valid_nodes.length; - return res.snapshotItem(index); + return valid_nodes[index]; + } } - // Recurse on sub-frames for (var i = 0; i < win.frames.length; ++i) { var elem = helper(win.frames[i], skip_win); -- 2.11.4.GIT