aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer/buffer.nim24
-rw-r--r--src/html/dom.nim25
-rw-r--r--src/html/tags.nim7
3 files changed, 41 insertions, 15 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index c89e2edd..2bc67d7c 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -239,7 +239,7 @@ func getLink(node: StyledNode): HTMLAnchorElement =
#TODO ::before links?
const ClickableElements = {
- TAG_A, TAG_INPUT, TAG_OPTION
+ TAG_A, TAG_INPUT, TAG_OPTION, TAG_BUTTON
}
func getClickable(styledNode: StyledNode): Element =
@@ -501,16 +501,6 @@ proc loadResources(buffer: Buffer, document: Document) =
proc c_setvbuf(f: File, buf: pointer, mode: cint, size: csize_t): cint {.
importc: "setvbuf", header: "<stdio.h>", tags: [].}
-func getFd(buffer: Buffer): int =
- if buffer.streamclosed: return -1
- let source = buffer.source
- case source.t
- of CLONE, LOAD_REQUEST:
- let istream = SocketStream(buffer.istream)
- return cast[FileHandle](istream.source.getFd())
- of LOAD_PIPE:
- return buffer.source.fd
-
type ConnectResult* = tuple[code: int, needsAuth: bool, redirect: Option[URL], contentType: string]
proc setupSource(buffer: Buffer): ConnectResult =
@@ -683,6 +673,8 @@ proc constructEntryList(form: HTMLFormElement, submitter: Element = nil, encodin
else:
if field.tagType == TAG_INPUT:
entrylist.add((name, HTMLInputElement(field).value))
+ elif field.tagType == TAG_BUTTON:
+ entrylist.add((name, HTMLButtonElement(field).value))
else:
assert false
if field.tagType == TAG_TEXTAREA or
@@ -875,6 +867,16 @@ proc click*(buffer: Buffer, cursorx, cursory: int): ClickResult {.proxy.} =
else:
# focus on select
buffer.set_focus select
+ of TAG_BUTTON:
+ let button = HTMLButtonElement(clickable)
+ if button.form != nil:
+ case button.ctype
+ of BUTTON_SUBMIT: result.open = submitForm(button.form, button)
+ of BUTTON_RESET:
+ button.form.reset()
+ result.repaint = true
+ buffer.do_reshape()
+ of BUTTON_BUTTON: discard
of TAG_INPUT:
buffer.restore_focus
let input = HTMLInputElement(clickable)
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 51a4058b..be66dc51 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -168,6 +168,10 @@ type
HTMLAreaElement* = ref object of HTMLElement
+ HTMLButtonElement* = ref object of FormAssociatedElement
+ ctype*: ButtonType
+ value*: string
+
proc tostr(ftype: enum): string =
return ($ftype).split('_')[1..^1].join("-").tolower()
@@ -649,6 +653,8 @@ func newHTMLElement*(document: Document, tagType: TagType, namespace = Namespace
HTMLScriptElement(result).forceAsync = true
of TAG_BASE:
result = new(HTMLBaseElement)
+ of TAG_BUTTON:
+ result = new(HTMLButtonElement)
else:
result = new(HTMLElement)
@@ -892,7 +898,11 @@ proc setForm*(element: FormAssociatedElement, form: HTMLFormElement) =
let select = HTMLSelectElement(element)
select.form = form
form.controls.add(select)
- of TAG_BUTTON, TAG_FIELDSET, TAG_OBJECT, TAG_OUTPUT, TAG_TEXTAREA, TAG_IMG:
+ of TAG_BUTTON:
+ let button = HTMLButtonElement(element)
+ button.form = form
+ form.controls.add(button)
+ of TAG_FIELDSET, TAG_OBJECT, TAG_OUTPUT, TAG_TEXTAREA, TAG_IMG:
discard #TODO
else: assert false
@@ -926,7 +936,7 @@ proc insertionSteps(insertedNode: Node) =
select.resetElement()
else: discard
if tagType in FormAssociatedElements:
- if tagType notin {TAG_SELECT, TAG_INPUT}:
+ if tagType notin SupportedFormAssociatedElements:
return #TODO TODO TODO implement others too
let element = FormAssociatedElement(element)
if element.parserInserted:
@@ -1012,9 +1022,19 @@ proc appendAttribute*(element: Element, k, v: string) =
select.size = parseInt(v)
elif "multiple" in select.attributes:
select.size = 4
+ of TAG_BUTTON:
+ let button = HTMLButtonElement(element)
+ if k == "type":
+ case v
+ of "submit": button.ctype = BUTTON_SUBMIT
+ of "reset": button.ctype = BUTTON_RESET
+ of "button": button.ctype = BUTTON_BUTTON
+ elif k == "value":
+ button.value = v
else: discard
element.attributes[k] = v
+# Forward definition hack (these are set in selectors.nim)
var doqsa*: proc (node: Node, q: string): seq[Element]
var doqs*: proc (node: Node, q: string): Element
@@ -1052,3 +1072,4 @@ proc addDOMModule*(ctx: JSContext) =
ctx.registerType(HTMLTemplateElement, parent = htmlElementCID)
ctx.registerType(HTMLUnknownElement, parent = htmlElementCID)
ctx.registerType(HTMLScriptElement, parent = htmlElementCID)
+ ctx.registerType(HTMLButtonElement, parent = htmlElementCID)
diff --git a/src/html/tags.nim b/src/html/tags.nim
index 5e0a2935..fbec9164 100644
--- a/src/html/tags.nim
+++ b/src/html/tags.nim
@@ -24,6 +24,9 @@ type
INPUT_RESET, INPUT_SEARCH, INPUT_SUBMIT, INPUT_TEL, INPUT_TEXT, INPUT_TIME,
INPUT_URL, INPUT_WEEK
+ ButtonType* = enum
+ BUTTON_SUBMIT, BUTTON_RESET, BUTTON_BUTTON
+
TagType* = enum
TAG_UNKNOWN, TAG_APPLET, TAG_BIG, TAG_HTML, TAG_BASE, TAG_BASEFONT,
TAG_BGSOUND, TAG_HEAD, TAG_LINK, TAG_LISTING, TAG_META, TAG_STYLE,
@@ -115,11 +118,11 @@ const FormAssociatedElements* = {
#TODO support all the other ones
const SupportedFormAssociatedElements* = {
- TAG_SELECT, TAG_INPUT
+ TAG_SELECT, TAG_INPUT, TAG_BUTTON
}
const ListedElements* = {
- TAG_BUTTON, TAG_FIELDSET, TAG_INPUT, TAG_OBJECT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA
+ TAG_FIELDSET, TAG_INPUT, TAG_OBJECT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA
}
const SubmittableElements* = {