about summary refs log tree commit diff stats
path: root/src/buffer
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-07 19:46:19 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-07 19:58:42 +0200
commit75310d68b875964c757c73ab1df791cda6fba756 (patch)
treed435fcdd9511bbf6f9f02cf380d7d0c45daaf97b /src/buffer
parent578df008d0e2e6ac2d8ee2ad84ccf640f8d07c55 (diff)
downloadchawan-75310d68b875964c757c73ab1df791cda6fba756.tar.gz
Add support for visibility
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/buffer.nim33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index 8775e0e6..acfbad19 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -17,6 +17,7 @@ import css/cssparser
 import css/mediaquery
 import css/sheet
 import css/stylednode
+import css/values
 import config/config
 import data/charset
 import html/dom
@@ -264,26 +265,22 @@ const ClickableElements = {
   TAG_A, TAG_INPUT, TAG_OPTION, TAG_BUTTON, TAG_TEXTAREA, TAG_LABEL
 }
 
+func isClickable(styledNode: StyledNode): bool =
+  if styledNode.t != STYLED_ELEMENT or styledNode.node == nil:
+    return false
+  if styledNode.computed{"visibility"} != VISIBILITY_VISIBLE:
+    return false
+  let element = Element(styledNode.node)
+  if element.tagType == TAG_A:
+    return HTMLAnchorElement(element).href != ""
+  return element.tagType in ClickableElements
+
 func getClickable(styledNode: StyledNode): Element =
-  if styledNode == nil:
-    return nil
   var styledNode = styledNode
-  while styledNode.node == nil:
-    styledNode = styledNode.parent
-    if styledNode == nil:
-      return nil
-  if styledNode.t == STYLED_ELEMENT:
-    let element = Element(styledNode.node)
-    if element.tagType in ClickableElements and (element.tagType != TAG_A or HTMLAnchorElement(element).href != ""):
-      return element
-  var node = styledNode.node
-  while true:
-    result = node.findAncestor(ClickableElements)
-    if result == nil:
-      break
-    if result.tagType != TAG_A or HTMLAnchorElement(result).href != "":
-      break
-    node = result
+  while styledNode != nil:
+    if styledNode.isClickable():
+      return Element(styledNode.node)
+    styledNode = stylednode.parent
 
 func submitForm(form: HTMLFormElement, submitter: Element): Option[Request]