about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/css/cascade.nim14
-rw-r--r--src/css/selectorparser.nim3
-rw-r--r--src/css/values.nim2
-rw-r--r--src/html/dom.nim22
-rw-r--r--src/layout/engine.nim4
-rw-r--r--src/server/buffer.nim29
6 files changed, 65 insertions, 9 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index 257d2ef0..f7a3ede3 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -380,6 +380,16 @@ proc applyRulesFrameInvalid(frame: CascadeFrame, ua, user: CSSStylesheet,
       let styledText = styledParent.newStyledReplacement(content)
       styledText.pseudo = pseudo
       styledParent.children.add(styledText)
+    of PSEUDO_VIDEO:
+      let content = CSSContent(t: CONTENT_VIDEO)
+      let styledText = styledParent.newStyledReplacement(content)
+      styledText.pseudo = pseudo
+      styledParent.children.add(styledText)
+    of PSEUDO_AUDIO:
+      let content = CSSContent(t: CONTENT_AUDIO)
+      let styledText = styledParent.newStyledReplacement(content)
+      styledText.pseudo = pseudo
+      styledParent.children.add(styledText)
     of PSEUDO_NEWLINE:
       let content = CSSContent(t: CONTENT_NEWLINE)
       let styledText = styledParent.newStyledReplacement(content)
@@ -477,6 +487,10 @@ proc appendChildren(styledStack: var seq[CascadeFrame], frame: CascadeFrame,
     styledStack.stackAppend(frame, styledChild, PSEUDO_TEXTAREA_TEXT, idx)
   elif elem.tagType == TAG_IMG or elem.tagType == TAG_IMAGE:
     styledStack.stackAppend(frame, styledChild, PSEUDO_IMAGE, idx)
+  elif elem.tagType == TAG_VIDEO:
+    styledStack.stackAppend(frame, styledChild, PSEUDO_VIDEO, idx)
+  elif elem.tagType == TAG_AUDIO:
+    styledStack.stackAppend(frame, styledChild, PSEUDO_AUDIO, idx)
   elif elem.tagType == TAG_BR:
     styledStack.stackAppend(frame, styledChild, PSEUDO_NEWLINE, idx)
   else:
diff --git a/src/css/selectorparser.nim b/src/css/selectorparser.nim
index ca691050..da74c6ed 100644
--- a/src/css/selectorparser.nim
+++ b/src/css/selectorparser.nim
@@ -14,7 +14,8 @@ type
   PseudoElem* = enum
     PSEUDO_NONE, PSEUDO_BEFORE, PSEUDO_AFTER,
     # internal
-    PSEUDO_INPUT_TEXT, PSEUDO_TEXTAREA_TEXT, PSEUDO_IMAGE, PSEUDO_NEWLINE
+    PSEUDO_INPUT_TEXT, PSEUDO_TEXTAREA_TEXT, PSEUDO_IMAGE, PSEUDO_NEWLINE,
+    PSEUDO_VIDEO, PSEUDO_AUDIO
 
   PseudoClass* = enum
     PSEUDO_FIRST_CHILD, PSEUDO_LAST_CHILD, PSEUDO_ONLY_CHILD, PSEUDO_HOVER,
diff --git a/src/css/values.nim b/src/css/values.nim
index 6533c7f1..dd3c96ea 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -173,7 +173,7 @@ type
   CSSContentType* = enum
     CONTENT_STRING, CONTENT_OPEN_QUOTE, CONTENT_CLOSE_QUOTE,
     CONTENT_NO_OPEN_QUOTE, CONTENT_NO_CLOSE_QUOTE, CONTENT_IMAGE,
-    CONTENT_NEWLINE
+    CONTENT_VIDEO, CONTENT_AUDIO, CONTENT_NEWLINE
 
   CSSFloat* = enum
     FLOAT_NONE, FLOAT_LEFT, FLOAT_RIGHT
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 81504d56..2f36d81a 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -370,6 +370,10 @@ type
     bitmap*: Bitmap
     fetchStarted: bool
 
+  HTMLVideoElement* = ref object of HTMLElement
+
+  HTMLAudioElement* = ref object of HTMLElement
+
 jsDestructor(Navigator)
 jsDestructor(PluginArray)
 jsDestructor(MimeTypeArray)
@@ -403,6 +407,8 @@ jsDestructor(HTMLTextAreaElement)
 jsDestructor(HTMLLabelElement)
 jsDestructor(HTMLCanvasElement)
 jsDestructor(HTMLImageElement)
+jsDestructor(HTMLVideoElement)
+jsDestructor(HTMLAudioElement)
 jsDestructor(Node)
 jsDestructor(NodeList)
 jsDestructor(HTMLCollection)
@@ -2426,6 +2432,16 @@ func jsForm(this: HTMLButtonElement): HTMLFormElement {.jsfget: "form".} =
 func jsForm(this: HTMLTextAreaElement): HTMLFormElement {.jsfget: "form".} =
   return this.form
 
+# <video>
+func getSrc*(this: HTMLVideoElement|HTMLAudioElement): string =
+  var src = this.attr(atSrc)
+  if src == "":
+    for el in this.elements(TAG_SOURCE):
+      src = el.attr(atSrc)
+      if src != "":
+        break
+  src
+
 func newText(document: Document, data: string): Text =
   return Text(
     document_internal: document,
@@ -2542,6 +2558,10 @@ proc newHTMLElement*(document: Document, localName: CAtom,
     result = HTMLCanvasElement()
   of TAG_IMG:
     result = HTMLImageElement()
+  of TAG_VIDEO:
+    result = HTMLVideoElement()
+  of TAG_AUDIO:
+    result = HTMLAudioElement()
   of TAG_AREA:
     let area = HTMLAreaElement()
     let localName = document.toAtom(atRel)
@@ -4127,6 +4147,8 @@ proc registerElements(ctx: JSContext, nodeCID: JSClassID) =
   register(HTMLLabelElement, TAG_LABEL)
   register(HTMLCanvasElement, TAG_CANVAS)
   register(HTMLImageElement, TAG_IMG)
+  register(HTMLVideoElement, TAG_VIDEO)
+  register(HTMLAudioElement, TAG_AUDIO)
 
 proc addDOMModule*(ctx: JSContext) =
   let eventTargetCID = ctx.getClass("EventTarget")
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index d2d22ab9..d90fc52c 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -2599,6 +2599,10 @@ proc generateReplacement(ctx: var InnerBlockContext, child, parent: StyledNode)
   of CONTENT_IMAGE:
     #TODO idk
     ctx.generateAnonymousInlineText("[img]", parent)
+  of CONTENT_VIDEO:
+    ctx.generateAnonymousInlineText("[video]", parent)
+  of CONTENT_AUDIO:
+    ctx.generateAnonymousInlineText("[audio]", parent)
   of CONTENT_NEWLINE:
     ctx.iflush()
     #TODO ??
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 9e2b726e..e4af4232 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -354,13 +354,28 @@ proc getClickHover(styledNode: StyledNode): string =
 proc getImageHover(styledNode: StyledNode): string =
   var styledNode = styledNode
   while styledNode != nil:
-    if styledNode.t == STYLED_ELEMENT and styledNode.node of HTMLImageElement:
-      let image = HTMLImageElement(styledNode.node)
-      let src = image.attr(atSrc)
-      if src != "":
-        let url = image.document.parseURL(src)
-        if url.isSome:
-          return $url.get
+    if styledNode.t == STYLED_ELEMENT:
+      if styledNode.node of HTMLImageElement:
+        let image = HTMLImageElement(styledNode.node)
+        let src = image.attr(atSrc)
+        if src != "":
+          let url = image.document.parseURL(src)
+          if url.isSome:
+            return $url.get
+      elif styledNode.node of HTMLVideoElement:
+        let video = HTMLVideoElement(styledNode.node)
+        let src = video.getSrc()
+        if src != "":
+          let url = video.document.parseURL(src)
+          if url.isSome:
+            return $url.get
+      elif styledNode.node of HTMLAudioElement:
+        let audio = HTMLAudioElement(styledNode.node)
+        let src = audio.getSrc()
+        if src != "":
+          let url = audio.document.parseURL(src)
+          if url.isSome:
+            return $url.get
     styledNode = styledNode.parent
   ""