about summary refs log tree commit diff stats
path: root/src/buffer
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-03-14 16:08:07 +0100
committerbptato <nincsnevem662@gmail.com>2023-04-10 18:12:06 +0200
commit229e020eba43b1aa2a3ab452461aec133d1f5c1f (patch)
tree46a34cfc05aee4717b965fc23bdc35b898656a40 /src/buffer
parent49f5d9abeb6c0c1de0f44ff45ade07e77d9d0554 (diff)
downloadchawan-229e020eba43b1aa2a3ab452461aec133d1f5c1f.tar.gz
buffer: disable popup confirmation for forms
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/buffer.nim17
-rw-r--r--src/buffer/container.nim3
2 files changed, 15 insertions, 5 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index 04304afb..5aec73df 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -272,6 +272,8 @@ func getClickable(styledNode: StyledNode): Element =
       break
     node = result
 
+func submitForm(form: HTMLFormElement, submitter: Element): Option[Request]
+
 func getClickHover(styledNode: StyledNode): string =
   let clickable = styledNode.getClickable()
   if clickable != nil:
@@ -279,6 +281,13 @@ func getClickHover(styledNode: StyledNode): string =
     of TAG_A:
       return HTMLAnchorElement(clickable).href
     of TAG_INPUT:
+      #TODO this is inefficient and also quite stupid
+      if clickable.tagType in FormAssociatedElements:
+        let fae = FormAssociatedElement(clickable)
+        if fae.form != nil and fae.form.canSubmitImplicitly():
+          let req = fae.form.submitForm(fae)
+          if req.isSome:
+            return $req.get.url
       return "<input>"
     of TAG_OPTION:
       return "<option>"
@@ -779,7 +788,7 @@ proc serializePlainTextFormData(kvs: seq[(string, string)]): string =
     result &= value
     result &= "\r\n"
 
-proc submitForm(form: HTMLFormElement, submitter: Element): Option[Request] =
+func submitForm(form: HTMLFormElement, submitter: Element): Option[Request] =
   let entrylist = form.constructEntryList(submitter)
 
   let action = if submitter.action() == "":
@@ -866,7 +875,7 @@ type ReadSuccessResult* = object
   open*: Option[Request]
   repaint*: bool
 
-proc implicitSubmit(buffer: Buffer, input: HTMLInputElement): Option[Request] =
+func implicitSubmit(input: HTMLInputElement): Option[Request] =
   if input.form != nil and input.form.canSubmitImplicitly():
     return submitForm(input.form, input.form)
 
@@ -881,7 +890,7 @@ proc readSuccess*(buffer: Buffer, s: string): ReadSuccessResult {.proxy.} =
         input.invalid = true
         buffer.do_reshape()
         result.repaint = true
-        result.open = buffer.implicitSubmit(input)
+        result.open = implicitSubmit(input)
       of INPUT_FILE:
         let cdir = parseURL("file://" & getCurrentDir() & DirSep)
         let path = parseURL(s, cdir)
@@ -890,7 +899,7 @@ proc readSuccess*(buffer: Buffer, s: string): ReadSuccessResult {.proxy.} =
           input.invalid = true
           buffer.do_reshape()
           result.repaint = true
-          result.open = buffer.implicitSubmit(input)
+          result.open = implicitSubmit(input)
       else: discard
     of TAG_TEXTAREA:
       let textarea = HTMLTextAreaElement(buffer.document.focus)
diff --git a/src/buffer/container.nim b/src/buffer/container.nim
index 8962908a..7dfd26b9 100644
--- a/src/buffer/container.nim
+++ b/src/buffer/container.nim
@@ -282,7 +282,8 @@ func getHoverText*(container: Container): string =
       return container.hovertext[t]
 
 func isHoverURL*(container: Container, url: URL): bool =
-  return $url == container.hovertext[HOVER_LINK]
+  let hoverurl = parseURL(container.hovertext[HOVER_LINK])
+  return hoverurl.isSome and url.host == hoverurl.get.host
 
 proc triggerEvent(container: Container, event: ContainerEvent) =
   container.events.addLast(event)