about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-12 01:24:18 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-12 01:24:33 +0200
commit0db193e65412804f30bf40d586d000c7599b8d24 (patch)
treee2e4e55b4708e03af935bae70003c306efc925cc /src
parent37c144fea89bf02a449666128ac2ca8f85f2a985 (diff)
downloadchawan-0db193e65412804f30bf40d586d000c7599b8d24.tar.gz
css: clean up a bit
Diffstat (limited to 'src')
-rw-r--r--src/css/cascade.nim18
-rw-r--r--src/css/cssvalues.nim23
-rw-r--r--src/css/stylednode.nim31
3 files changed, 18 insertions, 54 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index b4cd7b98..bfe36c7b 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -436,7 +436,8 @@ proc applyRulesFrameInvalid(frame: CascadeFrame; ua, user: CSSStylesheet;
       let styledPseudo = pseudo.applyDeclarations(styledParent, declmap)
       if styledPseudo != nil and styledPseudo.computed{"content"}.len > 0:
         for content in styledPseudo.computed{"content"}:
-          styledPseudo.children.add(styledPseudo.newStyledReplacement(content))
+          let child = styledPseudo.newStyledReplacement(content, peNone)
+          styledPseudo.children.add(child)
         styledParent.children.add(styledPseudo)
     of peInputText:
       let s = HTMLInputElement(styledParent.node).inputString()
@@ -461,8 +462,7 @@ proc applyRulesFrameInvalid(frame: CascadeFrame; ua, user: CSSStylesheet;
         s: src,
         bmp: HTMLImageElement(styledParent.node).bitmap
       )
-      let styledText = styledParent.newStyledReplacement(content)
-      styledText.pseudo = pseudo
+      let styledText = styledParent.newStyledReplacement(content, pseudo)
       styledParent.children.add(styledText)
     of peCanvas:
       let content = CSSContent(
@@ -470,24 +470,20 @@ proc applyRulesFrameInvalid(frame: CascadeFrame; ua, user: CSSStylesheet;
         s: "canvas://",
         bmp: HTMLCanvasElement(styledParent.node).bitmap
       )
-      let styledText = styledParent.newStyledReplacement(content)
-      styledText.pseudo = pseudo
+      let styledText = styledParent.newStyledReplacement(content, pseudo)
       styledParent.children.add(styledText)
     of peVideo:
       let content = CSSContent(t: ContentVideo)
-      let styledText = styledParent.newStyledReplacement(content)
-      styledText.pseudo = pseudo
+      let styledText = styledParent.newStyledReplacement(content, pseudo)
       styledParent.children.add(styledText)
     of peAudio:
       let content = CSSContent(t: ContentAudio)
-      let styledText = styledParent.newStyledReplacement(content)
-      styledText.pseudo = pseudo
+      let styledText = styledParent.newStyledReplacement(content, pseudo)
       styledParent.children.add(styledText)
     of peNewline:
       let content = CSSContent(t: ContentNewline)
-      let styledText = styledParent.newStyledReplacement(content)
+      let styledText = styledParent.newStyledReplacement(content, pseudo)
       styledParent.children.add(styledText)
-      styledText.pseudo = pseudo
     of peNone: assert false
   else:
     assert child != nil
diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim
index 1d0f6425..0e863cbc 100644
--- a/src/css/cssvalues.nim
+++ b/src/css/cssvalues.nim
@@ -65,7 +65,6 @@ type
     cptPaddingLeft = "padding-left"
     cptPaddingRight = "padding-right"
     cptPaddingBottom = "padding-bottom"
-    cptWordSpacing = "word-spacing"
     cptVerticalAlign = "vertical-align"
     cptLineHeight = "line-height"
     cptTextAlign = "text-align"
@@ -439,7 +438,6 @@ const ValueTypes = [
   cptPaddingLeft: cvtLength,
   cptPaddingRight: cvtLength,
   cptPaddingBottom: cvtLength,
-  cptWordSpacing: cvtLength,
   cptVerticalAlign: cvtVerticalAlign,
   cptLineHeight: cvtLength,
   cptTextAlign: cvtTextAlign,
@@ -478,7 +476,7 @@ const ValueTypes = [
 
 const InheritedProperties = {
   cptColor, cptFontStyle, cptWhiteSpace, cptFontWeight, cptTextDecoration,
-  cptWordBreak, cptListStyleType, cptWordSpacing, cptLineHeight, cptTextAlign,
+  cptWordBreak, cptListStyleType, cptLineHeight, cptTextAlign,
   cptListStylePosition, cptCaptionSide, cptBorderSpacing, cptBorderCollapse,
   cptQuotes, cptVisibility, cptTextTransform
 }
@@ -1001,18 +999,6 @@ func cssAbsoluteLength(val: CSSComponentValue): Opt[CSSLength] =
     else: discard
   return err()
 
-func cssWordSpacing(cval: CSSComponentValue): Opt[CSSLength] =
-  if cval of CSSToken:
-    let tok = CSSToken(cval)
-    case tok.tokenType
-    of cttDimension:
-      return cssLength(tok.nvalue, tok.unit)
-    of cttIdent:
-      if tok.value.equalsIgnoreCase("normal"):
-        return ok(CSSLengthAuto)
-    else: discard
-  return err()
-
 func cssGlobal(cval: CSSComponentValue): CSSGlobalType =
   return parseIdent[CSSGlobalType](cval).get(cgtNoglobal)
 
@@ -1231,8 +1217,6 @@ proc parseValue(cvals: openArray[CSSComponentValue]; t: CSSPropertyType):
   of cvtColor: return_new color, ?cssColor(cval)
   of cvtLength:
     case t
-    of cptWordSpacing:
-      return_new length, ?cssWordSpacing(cval)
     of cptLineHeight:
       return_new length, ?cssLineHeight(cval)
     of cptMaxWidth, cptMaxHeight, cptMinWidth, cptMinHeight:
@@ -1293,9 +1277,8 @@ func getInitialColor(t: CSSPropertyType): CellColor =
 
 func getInitialLength(t: CSSPropertyType): CSSLength =
   case t
-  of cptWidth, cptHeight, cptWordSpacing, cptLineHeight, cptLeft, cptRight,
-      cptTop, cptBottom, cptMaxWidth, cptMaxHeight, cptMinWidth, cptMinHeight,
-      cptFlexBasis:
+  of cptWidth, cptHeight, cptLineHeight, cptLeft, cptRight, cptTop, cptBottom,
+      cptMaxWidth, cptMaxHeight, cptMinWidth, cptMinHeight, cptFlexBasis:
     return CSSLengthAuto
   else:
     return CSSLength(auto: false, unit: cuPx, num: 0)
diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim
index 1b3a645b..127ce41c 100644
--- a/src/css/stylednode.nim
+++ b/src/css/stylednode.nim
@@ -125,16 +125,6 @@ proc addDependency*(styledNode: StyledNode; dep: Element; t: DependencyType) =
   if dep notin styledNode.depends[t]:
     styledNode.depends[t].add(dep)
 
-func newStyledElement*(parent: StyledNode; element: Element;
-    computed: CSSComputedValues; reg: DependencyInfo): StyledNode =
-  return StyledNode(
-    t: stElement,
-    computed: computed,
-    node: element,
-    parent: parent,
-    depends: reg
-  )
-
 func newStyledElement*(parent: StyledNode; element: Element): StyledNode =
   return StyledNode(t: stElement, node: element, parent: parent)
 
@@ -143,16 +133,6 @@ func newStyledElement*(element: Element): StyledNode =
   return StyledNode(t: stElement, node: element)
 
 func newStyledElement*(parent: StyledNode; pseudo: PseudoElem;
-    computed: CSSComputedValues; reg: DependencyInfo): StyledNode =
-  return StyledNode(
-    t: stElement,
-    computed: computed,
-    pseudo: pseudo,
-    parent: parent,
-    depends: reg
-  )
-
-func newStyledElement*(parent: StyledNode; pseudo: PseudoElem;
     computed: CSSComputedValues): StyledNode =
   return StyledNode(
     t: stElement,
@@ -167,6 +147,11 @@ func newStyledText*(parent: StyledNode; text: Text): StyledNode =
 func newStyledText*(text: string): StyledNode =
   return StyledNode(t: stText, node: CharacterData(data: text))
 
-func newStyledReplacement*(parent: StyledNode; content: CSSContent):
-    StyledNode =
-  return StyledNode(t: stReplacement, parent: parent, content: content)
+func newStyledReplacement*(parent: StyledNode; content: CSSContent;
+    pseudo: PseudoElem): StyledNode =
+  return StyledNode(
+    t: stReplacement,
+    parent: parent,
+    content: content,
+    pseudo: pseudo
+  )