1 /*
2 * This file is part of LibCSS.
3 * Licensed under the MIT License,
4 * http://www.opensource.org/licenses/mit-license.php
5 * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
6 */
7
8 #ifndef css_bytecode_bytecode_h_
9 #define css_bytecode_bytecode_h_
10
11 #include <inttypes.h>
12 #include <stdio.h>
13
14 #include <libcss/types.h>
15 #include <libcss/properties.h>
16
17 typedef uint32_t css_code_t;
18
19 typedef enum css_properties_e opcode_t;
20
21 enum flag {
22 FLAG_IMPORTANT = (1<<0),
23 FLAG_INHERIT = (1<<1)
24 };
25
26 typedef enum unit {
27 UNIT_PX = 0,
28 UNIT_EX = 1,
29 UNIT_EM = 2,
30 UNIT_IN = 3,
31 UNIT_CM = 4,
32 UNIT_MM = 5,
33 UNIT_PT = 6,
34 UNIT_PC = 7,
35 UNIT_CAP = 8,
36 UNIT_CH = 9,
37 UNIT_IC = 10,
38 UNIT_REM = 11,
39 UNIT_LH = 12,
40 UNIT_RLH = 13,
41 UNIT_VH = 14,
42 UNIT_VW = 15,
43 UNIT_VI = 16,
44 UNIT_VB = 17,
45 UNIT_VMIN = 18,
46 UNIT_VMAX = 19,
47 UNIT_Q = 20,
48
49 UNIT_PCT = (1 << 8),
50
51 UNIT_ANGLE = (1 << 9),
52 UNIT_DEG = (1 << 9) + 0,
53 UNIT_GRAD = (1 << 9) + 1,
54 UNIT_RAD = (1 << 9) + 2,
55 UNIT_TURN = (1 << 9) + 3,
56
57 UNIT_TIME = (1 << 10),
58 UNIT_MS = (1 << 10) + 0,
59 UNIT_S = (1 << 10) + 1,
60
61 UNIT_FREQ = (1 << 11),
62 UNIT_HZ = (1 << 11) + 0,
63 UNIT_KHZ = (1 << 11) + 1,
64
65 UNIT_RESOLUTION = (1 << 12),
66 UNIT_DPI = (1 << 12) + 0,
67 UNIT_DPCM = (1 << 12) + 1,
68 UNIT_DPPX = (1 << 12) + 2,
69 } unit;
70
71 typedef uint32_t colour;
72
73 typedef enum shape {
74 SHAPE_RECT = 0
75 } shape;
76
buildOPV(opcode_t opcode,uint8_t flags,uint16_t value)77 static inline css_code_t buildOPV(opcode_t opcode, uint8_t flags, uint16_t value)
78 {
79 return (opcode & 0x3ff) | (flags << 10) | ((value & 0x3fff) << 18);
80 }
81
getOpcode(css_code_t OPV)82 static inline opcode_t getOpcode(css_code_t OPV)
83 {
84 return (OPV & 0x3ff);
85 }
86
getFlags(css_code_t OPV)87 static inline uint8_t getFlags(css_code_t OPV)
88 {
89 return ((OPV >> 10) & 0xff);
90 }
91
getValue(css_code_t OPV)92 static inline uint16_t getValue(css_code_t OPV)
93 {
94 return (OPV >> 18);
95 }
96
isImportant(css_code_t OPV)97 static inline bool isImportant(css_code_t OPV)
98 {
99 return getFlags(OPV) & 0x1;
100 }
101
isInherit(css_code_t OPV)102 static inline bool isInherit(css_code_t OPV)
103 {
104 return getFlags(OPV) & 0x2;
105 }
106
107 #endif
108
109
110
111