Skip to content

Commit 5d6919b

Browse files
authored
Merge pull request #46 from ferus-web/anchors-impl-001
Implement anchors, again.
2 parents 803efb3 + c7dde18 commit 5d6919b

File tree

11 files changed

+367
-89
lines changed

11 files changed

+367
-89
lines changed

assets/user-agent.css

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,42 @@
99
/* Paragraphs */
1010
p {
1111
font-size: 24px;
12+
color: rgb(0, 0, 0);
1213
}
1314

14-
strong { font-size: 24px; } /* FIXME: add support for multiple class matchers in one selector */
15+
strong {
16+
font-size: 24px;
17+
color: rgb(0, 0, 0);
18+
} /* FIXME: add support for multiple class matchers in one selector */
19+
a {
20+
font-size: 24px;
21+
color: rgb(0, 0, 255); /* Make anchors appear blue. */
22+
}
1523

1624
/* Headings
1725
* They progressively get smaller with each level.
1826
*/
19-
h1 { font-size: 32px; }
20-
h2 { font-size: 30px; }
21-
h3 { font-size: 28px; }
22-
h4 { font-size: 24px; }
23-
h5 { font-size: 22px; }
24-
h6 { font-size: 20px; }
27+
h1 {
28+
font-size: 32px;
29+
color: rgb(0, 0, 0);
30+
}
31+
h2 {
32+
font-size: 30px;
33+
color: rgb(0, 0, 0);
34+
}
35+
h3 {
36+
font-size: 28px;
37+
color: rgb(0, 0, 0);
38+
}
39+
h4 {
40+
font-size: 24px;
41+
color: rgb(0, 0, 0);
42+
}
43+
h5 {
44+
font-size: 22px;
45+
color: rgb(0, 0, 0);
46+
}
47+
h6 {
48+
font-size: 20px;
49+
color: rgb(0, 0, 0);
50+
}

ferus.nimble

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ requires "jsony >= 1.1.5"
2525
requires "chagashi >= 0.5.4"
2626
requires "curly >= 1.1.1"
2727
requires "webby >= 0.2.1"
28-
29-
when defined(ferusUseGlfw):
30-
requires "glfw >= 3.4.0.4"
31-
else:
32-
requires "windy >= 0.0.0"
33-
3428
requires "waterpark >= 0.1.7"
29+
requires "chroma >= 0.2.7"
30+
requires "bumpy >= 1.1.2"
31+
requires "glfw >= 3.4.0.4"

nim.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
# -d:ferusSandboxAttachStrace
1212
# -d:ferusAddMangohudToRendererPrefix
1313
# -d:ferusJustWaitForConnection
14-
-d:ferusUseGlfw
1514
-d:ferusUseCurl
1615
# -d:ferusIpcLogSendsToStdout
1716

1817
# glfw flags
1918
# -d:glfwStaticLib
2019

2120
# ferusgfx-specific flags
22-
-d:ferusgfxDrawDamagedRegions
21+
# -d:ferusgfxDrawDamagedRegions
2322
# -d:ferusgfxDrawTouchInterestNodeBounds
2423

2524
# Enable SIMD support

samples/006.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head><title>Hello anchors!</title></head>
4+
<body>
5+
<a href="https://www.google.com">Visit Google</a>
6+
<a href="https://www.wikipedia.org">Visit Wikipedia</a>
7+
<a href="https://www.github.com">Visit GitHub</a>
8+
</body>
9+
</html>

src/components/layout/processor.nim

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import pkg/[pixie, vmath]
44
import ../../bindings/yoga
55
import ../../components/parsers/html/document
66
import ../../components/parsers/css/[parser, anb, types]
7-
import ../../components/style/[selector_engine, style_matcher]
7+
import ../../components/style/[selector_engine, style_matcher, functions]
88
import ../../components/shared/sugar
99
import ../../components/ipc/[client/prelude, shared]
1010

@@ -16,6 +16,7 @@ type
1616
position*: Vec2
1717
dimensions*: Vec2
1818
fontSize*: float32
19+
color*: ColorRGBA
1920

2021
LayoutNode* = object
2122
parent*: ptr LayoutNode
@@ -91,7 +92,14 @@ proc traverse*(layout: Layout, node: var LayoutNode) =
9192
let fontSize =
9293
toPixels(&layout.stylesheet.getProperty(node.element, Property.FontSize))
9394
# The font-size attribute
95+
96+
let color =
97+
evaluateRGBXFunction(&layout.stylesheet.getProperty(node.element, Property.Color))
98+
99+
failCond *color
100+
# FIXME: Use a more fault-tolerant approach. Currently we just skip the entire node and its children upon this basic failure.
94101
node.processed.fontSize = fontSize
102+
node.processed.color = &color
95103
node.font.size = fontSize
96104

97105
let bounds = node.font.layoutBounds(text)
@@ -104,8 +112,36 @@ proc traverse*(layout: Layout, node: var LayoutNode) =
104112
let text = &node.element.text()
105113
let fontSize =
106114
toPixels(&layout.stylesheet.getProperty(node.element, Property.FontSize))
115+
let color =
116+
evaluateRGBXFunction(&layout.stylesheet.getProperty(node.element, Property.Color))
117+
118+
failCond *color
119+
# FIXME: Use a more fault-tolerant approach. Currently we just skip the entire node and its children upon this basic failure.
120+
node.font.size = fontSize
121+
node.processed.fontSize = fontSize
122+
node.processed.color = &color
123+
let bounds = node.font.layoutBounds(text)
124+
125+
inlineElem
126+
node.processed.dimensions = bounds
127+
of TAG_A:
128+
let text =
129+
if *node.element.text:
130+
&node.element.text()
131+
else:
132+
newString(0)
133+
134+
let fontSize =
135+
toPixels(&layout.stylesheet.getProperty(node.element, Property.FontSize))
136+
let color =
137+
evaluateRGBXFunction(&layout.stylesheet.getProperty(node.element, Property.Color))
138+
139+
failCond *color
140+
# FIXME: Use a more fault-tolerant approach. Currently we just skip the entire node and its children upon this basic failure.
141+
107142
node.font.size = fontSize
108143
node.processed.fontSize = fontSize
144+
node.processed.color = &color
109145
let bounds = node.font.layoutBounds(text)
110146

111147
inlineElem
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import pkg/[jsony]
1+
## This file contains all CSS3 properties supported by Ferus.
2+
##
3+
## Author:
4+
## Trayambak Rai (xtrayambak at disroot dot org)
25

36
type Property* {.pure.} = enum
47
FontSize = "font-size"
8+
Color = "color"

src/components/parsers/css/parser.nim

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ proc parseFunction*(parser: CSSParser, nameTok: Token): Option[CSSValue] {.inlin
5555

5656
parser.state.atStartOf = none(BlockType)
5757

58-
if !parser.state.expectSemicolon():
59-
return
60-
6158
some(function(name, move(args)))
6259

6360
proc parseRule*(parser: CSSParser): Option[Rule] =
@@ -77,6 +74,7 @@ proc parseRule*(parser: CSSParser): Option[Rule] =
7774
return
7875

7976
let value = &ovalue
77+
8078
var parsedValue: CSSValue
8179

8280
case value.kind
@@ -123,6 +121,6 @@ proc consumeRules*(parser: CSSParser): Stylesheet =
123121
of tkIdent:
124122
stylesheet &= parser.onEncounterIdentifier(init)
125123
else:
126-
assert off, $init.kind
124+
discard
127125

128126
stylesheet

0 commit comments

Comments
 (0)