summaryrefslogtreecommitdiff
path: root/css_media_queries.mdwn
blob: cbd91f7e717886d716aa4808a6794b2d774ff5e4 (plain)
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
[[!meta title="Css media queries"]]
[[!meta author="Kyllikki"]]
[[!meta date="2015-04-03T13:09:32Z"]]


[[!toc]]

irc discussion
==============

**jmb** if this is in libcss, then you probably only need to alter
parseMediaList (and friends)

**kyllikki** oh thats a thought, this should probably be an interface in
libcss rather than open coded in the browser

**jmb** seems reasonable, given libcss needs it too

**kyllikki** I worked my way to where it was currently done and it
extracts the entry from the link and does string messing on it

**jmb** yeah; that's hideous, and should die

**kyllikki** ok so how ought we to do it?

**jmb** first, we need to change how libcss represents media. currently,
it's a bitfield. which clearly doesn't work for media queries. so, that
needs to be an object, instead. which probably isn't much work to
change. then, in libcss' parser, parseMediaList will need to change to
understand the new media query grammar

**kyllikki** ok, i think i know what you mean. thats just altering the
internal libcss representation?

**jmb** mostly. And then, finally, we need to expose an api to allow a
client to parse an arbitrary string as if it were a media query list.
that should return the new media object. that's needed, because of

` `<link type="stylesheet" media="<query>`">`

**kyllikki** right, which is all we currently support right?

**jmb** libcss supports @media rules.

<style markdown="1">
may also have a media attribute. though I don't recall if NetSurf
supports that.

**kyllikki**
<https://html.spec.whatwg.org/multipage/semantics.html#the-style-element>
it does indeed carry it and netsurf does not support it

**kyllikki** so how does libcss make decisions about applying the rules?
it obviously has no knowledge of any of the state

**jmb** see the selection api. when you add a stylesheet to a selection
context, the client provides the media it applies to (e.g.
css\_select\_ctx\_append\_sheet)

**kyllikki** so we have netsurf call the new libcss api to get the media
object and pass that instead?

**jmb** seems reasonable

**kyllikki** but how does libcss make an actual decision whether to
apply the styling or not?

**jmb** there needs to be a way to construct one computationally, too
(rather than from string), as the client must also pass a media
descriptor into css\_select\_style. which I think answers your question
:)

**kyllikki** not sure how they are comparable though. I guess thats
implementation detail

**jmb** likely. today's implementation uses & .the basic concept is:
style information has associated metadata that says what kinds of media
it applies to

**kyllikki** I guess we have to figure that providing a media object
that represents the browsers current media state is enough to make media
selection comparisons

*'jmb* and then, when selecting a style, you know what media you are
selecting for, and can then include/exclude specific style information
based on that. and the metadata either applies to the whole of a
stylesheet (be that <link> or

<style markdown="1">
), or it applies to part of a stylesheet (through the use of @media
within the CSS). libcss already has all the plumbing for that logic; it
just doesn't have a rich enough mechanism for expressing media
information. or the parse implementation for media queries ;)

**kyllikki** so

-   first up is moving the existing media api to be an object
-   then ensuring the browser creates such objects where needed and
    passes them
-   only then should the parse api in libcss be expanded, given it
    already has one for @media and we want it to be universal

**jmb** ya

**kyllikki** so we are already just fucking doing it wrong

**jmb** well, media queries weren't mature enough when libcss was first
designed for them to be considered and all the stuff in NS mostly
predates libcss, anyway -- certainly that media attribute parsing on
link elements has been around forever

**kyllikki** yeah but we always add sheets fetched from the dom as
screen!

**jmb** "oops" :)