OLD | NEW |
| (Empty) |
1 SKY MODULE | |
2 <!-- this is part of sky:core --> | |
3 <script> | |
4 // "internals" is an object only made visible to this module that exports stuff
implemented in C++ | |
5 module.exports.registerProperty = internals.registerProperty; | |
6 internals.registerLayoutManager('none', null); | |
7 module.exports.LayoutManager = internals.LayoutManager; | |
8 module.exports.InlineLayoutManager = internals.InlineLayoutManager; | |
9 internals.registerLayoutManager('inline', internals.InlineLayoutManager); | |
10 module.exports.ParagraphLayoutManager = internals.ParagraphLayoutManager; | |
11 internals.registerLayoutManager('paragraph', internals.ParagraphLayoutManager); | |
12 module.exports.BlockLayoutManager = internals.BlockLayoutManager; | |
13 internals.registerLayoutManager('block', internals.BlockLayoutManager); | |
14 | |
15 let displayTypes = new Map(); | |
16 module.exports.registerLayoutManager = function registerLayoutManager(displayVa
lue, layoutManagerConstructor) { | |
17 // TODO(ianh): apply rules for type-checking displayValue is a String | |
18 // TODO(ianh): apply rules for type-checking layoutManagerConstructor impleme
nts the LayoutManagerConstructor interface (or is null) | |
19 if (displayTypes.has(displayValue)) | |
20 throw new Error(); | |
21 displayTypes.set(displayValue, layoutManagerConstructor); | |
22 }; | |
23 | |
24 module.exports.DisplayStyleGrammar = new StyleGrammar(); // value is null or a
LayoutManagerConstructor | |
25 module.exports.DisplayStyleGrammar.addParser((tokens) => { | |
26 let token = tokens.next(); | |
27 if (token.done) | |
28 throw new Error(); | |
29 if (token.value.kind != 'identifier') | |
30 throw new Error(); | |
31 if (!displayTypes.has(token.value.value)) | |
32 throw new Error(); | |
33 return { | |
34 value: displayTypes.get(token.value.value), | |
35 } | |
36 }); | |
37 | |
38 internals.registerProperty({ | |
39 name: 'display', | |
40 type: module.exports.DisplayStyleGrammar, | |
41 inherits: false, | |
42 initialValue: internals.BlockLayoutManager, | |
43 needsLayout: true, | |
44 }); | |
45 | |
46 module.exports.PositiveLengthStyleGrammar = new StyleGrammar(); // value is a P
arsedValue whose value (once resolved) is a number in 96dpi pixels, >=0 | |
47 module.exports.PositiveLengthStyleGrammar.addParser((tokens) => { | |
48 // just handle "<number>px" | |
49 let token = tokens.next(); | |
50 if (token.done) | |
51 throw new Error(); | |
52 if (token.value.kind != 'dimension') | |
53 throw new Error(); | |
54 if (token.value.unit != 'px') | |
55 throw new Error(); | |
56 if (token.value.value < 0) | |
57 throw new Error(); | |
58 return { | |
59 value: token.value.value; | |
60 }; | |
61 }); | |
62 | |
63 internals.registerProperty({ | |
64 name: 'min-width', | |
65 type: module.exports.PositiveLengthStyleGrammar, | |
66 inherits: false, | |
67 initialValue: 0, | |
68 needsLayout: true, | |
69 }); | |
70 internals.registerProperty({ | |
71 name: 'min-height', | |
72 type: module.exports.PositiveLengthStyleGrammar, | |
73 inherits: false, | |
74 initialValue: 0, | |
75 needsLayout: true, | |
76 }); | |
77 | |
78 module.exports.PositiveLengthOrAutoStyleGrammar = new StyleGrammar(); // value
is a ParsedValue whose value (once resolved) is either a number in 96dpi pixels
(>=0) or null (meaning 'auto') | |
79 module.exports.PositiveLengthOrAutoStyleGrammar.addParser((tokens) => { | |
80 // handle 'auto' | |
81 let token = tokens.next(); | |
82 if (token.done) | |
83 throw new Error(); | |
84 if (token.value.kind != 'identifier') | |
85 throw new Error(); | |
86 if (token.value.value != 'auto') | |
87 throw new Error(); | |
88 return { | |
89 value: null, | |
90 }; | |
91 }); | |
92 module.exports.PositiveLengthOrAutoStyleGrammar.addParser((tokens) => { | |
93 return module.exports.PositiveLengthStyleGrammar.parse(tokens); | |
94 }); | |
95 | |
96 internals.registerProperty({ | |
97 name: 'width', | |
98 type: module.exports.PositiveLengthOrAutoStyleGrammar, | |
99 inherits: false, | |
100 initialValue: null, | |
101 needsLayout: true, | |
102 }); | |
103 internals.registerProperty({ | |
104 name: 'height', | |
105 type: module.exporets.PositiveLengthOrAutoStyleGrammar, | |
106 inherits: false, | |
107 initialValue: null, | |
108 needsLayout: true, | |
109 }); | |
110 | |
111 module.exports.PositiveLengthOrInfinityStyleGrammar = new StyleGrammar(); // va
lue is a ParsedValue whose value (once resolved) is either a number in 96dpi pix
els (>=0) or Infinity | |
112 module.exports.PositiveLengthOrInfinityStyleGrammar.addParser((tokens) => { | |
113 // handle 'infinity' | |
114 let token = tokens.next(); | |
115 if (token.done) | |
116 throw new Error(); | |
117 if (token.value.kind != 'identifier') | |
118 throw new Error(); | |
119 if (token.value.value != 'infinity') | |
120 throw new Error(); | |
121 return { | |
122 value: Infinity, | |
123 }; | |
124 }); | |
125 module.exports.PositiveLengthOrInfinityStyleGrammar.addParser((tokens) => { | |
126 return module.exports.PositiveLengthStyleGrammar.parse(tokens); | |
127 }); | |
128 | |
129 internals.registerProperty({ | |
130 name: 'width', | |
131 type: module.exports.PositiveLengthOrInfinityStyleGrammar, | |
132 inherits: false, | |
133 initialValue: Infinity, | |
134 needsLayout: true, | |
135 }); | |
136 internals.registerProperty({ | |
137 name: 'height', | |
138 type: module.exporets.PositiveLengthOrInfinityStyleGrammar, | |
139 inherits: false, | |
140 initialValue: Infinity, | |
141 needsLayout: true, | |
142 }); | |
143 </script> | |
OLD | NEW |