about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/css/cascade.nim7
-rw-r--r--src/css/match.nim4
-rw-r--r--src/css/selectorparser.nim7
-rw-r--r--src/css/values.nim11
4 files changed, 22 insertions, 7 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index 7822bca2..acf2ddf4 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -185,7 +185,8 @@ proc applyDeclarations(styledNode: StyledNode, parent: CSSComputedValues, ua, us
   styledNode.computed = builder.buildComputedValues()
 
 # Either returns a new styled node or nil.
-proc applyDeclarations(pseudo: PseudoElem, styledParent: StyledNode, ua, user: DeclarationList, author: seq[DeclarationList]): StyledNode =
+proc applyDeclarations(pseudo: PseudoElem, styledParent: StyledNode, ua,
+                       user: DeclarationList, author: seq[DeclarationList]): StyledNode =
   var builder = newComputedValueBuilder(styledParent.computed)
 
   builder.addValues(ua[pseudo], ORIGIN_USER_AGENT)
@@ -268,9 +269,7 @@ proc applyRules(document: Document, ua, user: CSSStylesheet, cachedTree: StyledN
         styledParent.children.add(styledChild)
     else:
       # From here on, computed values of this node's children are invalid
-      # (because of inheritance).
-      # That said, we could do this way more efficiently... TODO.
-      # (For example, we could replace the parent's computed values in-place.)
+      # because of property inheritance.
       cachedChild = nil
       if pseudo != PSEUDO_NONE:
         let (ua, user, authordecls) = styledParent.calcRules(ua, user, author)
diff --git a/src/css/match.nim b/src/css/match.nim
index 2d69943b..b17c690d 100644
--- a/src/css/match.nim
+++ b/src/css/match.nim
@@ -100,6 +100,10 @@ func pseudoSelectorMatches[T: Element|StyledNode](elem: T, sel: Selector, felem:
     return selem.selectorsMatch(sel.pseudo.fsels, felem)
   of PSEUDO_LANG:
     return sel.pseudo.s == "en" #TODO languages?
+  of PSEUDO_LINK:
+    return elem.tagType in {TAG_A, TAG_AREA} and elem.attrb("href")
+  of PSEUDO_VISITED:
+    return false
 
 func combinatorSelectorMatches[T: Element|StyledNode](elem: T, sel: Selector, felem: T): bool =
   let selem = elem
diff --git a/src/css/selectorparser.nim b/src/css/selectorparser.nim
index 90214a13..6b719ba6 100644
--- a/src/css/selectorparser.nim
+++ b/src/css/selectorparser.nim
@@ -24,7 +24,8 @@ type
   PseudoClass* = enum
     PSEUDO_FIRST_CHILD, PSEUDO_LAST_CHILD, PSEUDO_ONLY_CHILD, PSEUDO_HOVER,
     PSEUDO_ROOT, PSEUDO_NTH_CHILD, PSEUDO_NTH_LAST_CHILD, PSEUDO_CHECKED,
-    PSEUDO_FOCUS, PSEUDO_IS, PSEUDO_NOT, PSEUDO_WHERE, PSEUDO_LANG
+    PSEUDO_FOCUS, PSEUDO_IS, PSEUDO_NOT, PSEUDO_WHERE, PSEUDO_LANG,
+    PSEUDO_LINK, PSEUDO_VISITED
 
   CombinatorType* = enum
     DESCENDANT_COMBINATOR, CHILD_COMBINATOR, NEXT_SIBLING_COMBINATOR,
@@ -275,6 +276,10 @@ proc parseSelectorToken(state: var SelectorParser, csstoken: CSSToken) =
         add_pseudo_class PSEUDO_CHECKED
       of "focus":
         add_pseudo_class PSEUDO_FOCUS
+      of "link":
+        add_pseudo_class PSEUDO_LINK
+      of "visited":
+        add_pseudo_class PSEUDO_VISITED
     of QUERY_PSELEM:
       case csstoken.value
       of "before":
diff --git a/src/css/values.nim b/src/css/values.nim
index 58e00d74..89a9f7d1 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -330,6 +330,13 @@ func propertyType(s: string): CSSPropertyType =
 func valueType(prop: CSSPropertyType): CSSValueType =
   return ValueTypes[prop]
 
+func `$`*(val: CSSComputedValue): string =
+  result = ($val.t).toLowerAscii().split('_')[1..^1].join('-') & ": "
+  case val.v
+  of VALUE_COLOR:
+    result &= $val.color
+  else: discard
+
 macro `{}`*(vals: CSSComputedValues, s: string): untyped =
   let t = propertyType($s)
   let vs = $valueType(t)
@@ -1232,10 +1239,10 @@ func inheritProperties*(parent: CSSComputedValues): CSSComputedValues =
     else:
       result[prop] = getDefault(prop)
 
-func copyProperties*(parent: CSSComputedValues): CSSComputedValues =
+func copyProperties*(props: CSSComputedValues): CSSComputedValues =
   new(result)
   for prop in CSSPropertyType:
-    result[prop] = parent[prop]
+    result[prop] = props[prop]
 
 func rootProperties*(): CSSComputedValues =
   new(result)
662@gmail.com> 2021-07-30 20:25:38 +0200 CSS selectors and re-organization' href='/ahoang/chawan/commit/readme.md?id=34b023515599bc746c10c597467ecb07f53c49fe'>34b02351 ^
5268aada
5d6af7f5 ^
d8949a39 ^



3de0cccc ^
d8949a39 ^








0392e608 ^
2014e1e0 ^
7319240c ^
ecfdd90f ^
bb2c7cb8 ^
31fbd611 ^
15815d72 ^
d8949a39 ^
ca86dcd3 ^
f77db0bd ^
06fbb9bc ^
f77db0bd ^





06fbb9bc ^
ca86dcd3 ^




618a88e0 ^
d8949a39 ^

618a88e0 ^





ca86dcd3 ^
8fd4662c ^

f646b6ca ^












0392e608 ^

d8949a39 ^
0392e608 ^
8fd4662c ^
06fbb9bc ^
f7cf612a ^

9a3cd69e ^
f7cf612a ^

a13ad5be ^
8fd4662c ^
a13ad5be ^

54623b97 ^
a13ad5be ^


8fd4662c ^








618a88e0 ^




8fd4662c ^
b3b97465 ^
618a88e0 ^



94ea97fd ^



be9ba2f9 ^

c9104264 ^
be9ba2f9 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156