node.h 5.22 KB
Newer Older
XueShuming's avatar
XueShuming committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/////////////////////////////////////////////////////////////////////////////// //
//                          IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/**
 \verbatim

XueShuming's avatar
XueShuming committed
15
16
17
    This file is part of HiDOMLayout. hiDOMLayout is a library to
    maintain a DOM tree, lay out and stylize the DOM nodes by
    using CSS (Cascaded Style Sheets).
XueShuming's avatar
XueShuming committed
18

XueShuming's avatar
XueShuming committed
19
    Copyright (C) 2021 Beijing FMSoft Technologies Co., Ltd.
XueShuming's avatar
XueShuming committed
20
21

    This program is free software: you can redistribute it and/or modify
XueShuming's avatar
XueShuming committed
22
    it under the terms of the GNU Lesser General License as published by
XueShuming's avatar
XueShuming committed
23
24
25
26
27
28
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XueShuming's avatar
XueShuming committed
29
    GNU Lesser General License for more details.
XueShuming's avatar
XueShuming committed
30

XueShuming's avatar
XueShuming committed
31
    You should have received a copy of the GNU Lesser General License
XueShuming's avatar
XueShuming committed
32
33
34
35
36
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Or,

    As this program is a library, any link to this program must follow
XueShuming's avatar
XueShuming committed
37
38
    GNU Lesser General License version 3 (LGPLv3). If you cannot accept
    LGPLv3, you need to be licensed from FMSoft.
XueShuming's avatar
XueShuming committed
39
40
41
42
43
44
45
46
47
48

    If you have got a commercial license of this program, please use it
    under the terms and conditions of the commercial license.

    For more information about the commercial license, please refer to
    <http://www.minigui.com/blog/minigui-licensing-policy/>.

 \endverbatim
 */

XueShuming's avatar
XueShuming committed
49

50
51
#ifndef _HL_NODE_H
#define _HL_NODE_H
XueShuming's avatar
XueShuming committed
52

XueShuming's avatar
XueShuming committed
53
#include "hidomlayout.h"
XueShuming's avatar
XueShuming committed
54
#include <libcss/libcss.h>
55
#include <glib.h>
XueShuming's avatar
XueShuming committed
56

57
58
#define HL_INNER_CSS_SELECT_ATTACH "hl_inner_css_select_attach"
#define HL_INNER_LAYOUT_ATTACH "hl_inner_layout_attach"
XueShuming's avatar
XueShuming committed
59

XueShuming's avatar
XueShuming committed
60
61
62
63
#ifdef __cplusplus
extern "C" {
#endif

XueShuming's avatar
XueShuming committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
typedef enum {
    DOM_ELEMENT_NODE        = 1,
    DOM_ATTRIBUTE_NODE      = 2,
    DOM_TEXT_NODE           = 3,
    DOM_CDATA_SECTION_NODE      = 4,
    DOM_ENTITY_REFERENCE_NODE   = 5,
    DOM_ENTITY_NODE         = 6,
    DOM_PROCESSING_INSTRUCTION_NODE = 7,
    DOM_COMMENT_NODE        = 8,
    DOM_DOCUMENT_NODE       = 9,
    DOM_DOCUMENT_TYPE_NODE      = 10,
    DOM_DOCUMENT_FRAGMENT_NODE  = 11,
    DOM_NOTATION_NODE       = 12,

    /* And a count of the number of node types */
    DOM_NODE_TYPE_COUNT
80
} HLDomElementNodeType;
XueShuming's avatar
XueShuming committed
81

XueShuming's avatar
XueShuming committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
typedef enum {
    LAYOUT_BLOCK,
    LAYOUT_INLINE_CONTAINER,
    LAYOUT_INLINE,
    LAYOUT_TABLE,
    LAYOUT_TABLE_ROW,
    LAYOUT_TABLE_CELL,
    LAYOUT_TABLE_ROW_GROUP,
    LAYOUT_FLOAT_LEFT,
    LAYOUT_FLOAT_RIGHT,
    LAYOUT_INLINE_BLOCK,
    LAYOUT_BR,
    LAYOUT_TEXT,
    LAYOUT_INLINE_END,
96
97
    LAYOUT_GRID,
    LAYOUT_INLINE_GRID,
XueShuming's avatar
XueShuming committed
98
99
100
    LAYOUT_NONE
} LayoutType;

XueShuming's avatar
XueShuming committed
101
102
103
104
105
typedef struct HLAttachData_ {
    void* data;
    HlDestroyCallback callback;
} HLAttachData;

XueShuming's avatar
XueShuming committed
106
107
108
109
110
111
typedef struct HLDomElementNode_ {
    struct HLDomElementNode_* parent;  /**< Parent node */
    struct HLDomElementNode_* first_child; /**< First child node */
    struct HLDomElementNode_* last_child;  /**< Last child node */
    struct HLDomElementNode_* previous;    /**< Previous sibling */
    struct HLDomElementNode_* next;        /**< Next sibling */
112
    uint32_t n_children;        // child count;
XueShuming's avatar
XueShuming committed
113

XueShuming's avatar
XueShuming committed
114
    char* tag;
XueShuming's avatar
add api    
XueShuming committed
115

XueShuming's avatar
XueShuming committed
116
    GHashTable* common_attrs;  // common attrs key(uint64_t) -> value(string)
117

XueShuming's avatar
XueShuming committed
118
    GHashTable* general_attrs;     // user attrs key(string) -> value(string)
XueShuming's avatar
XueShuming committed
119
120
121
    GHashTable* user_data;     // user data key(string) -> value(HLAttachData)

    GHashTable* inner_attrs;    // inner attrs key(string) -> value(string)
122
    GHashTable* inner_data;     // inner data key(string) -> value(HLAttachData)
123

124
    HLAttachData* attach_data; // attach data
XueShuming's avatar
XueShuming committed
125

126
127
128
129

    // class name
    GList* class_list;

XueShuming's avatar
XueShuming committed
130
131
132
    //inner layout
    LayoutType layout_type;

XueShuming's avatar
XueShuming committed
133
    // begin for hicss inner
XueShuming's avatar
XueShuming committed
134
135
    lwc_string* inner_tag;
    lwc_string* inner_id;
136
    lwc_string** inner_classes;
XueShuming's avatar
XueShuming committed
137
    int inner_classes_count;
XueShuming's avatar
XueShuming committed
138

139
    HLDomElementNodeType inner_dom_type;;
XueShuming's avatar
XueShuming committed
140
141
142
    // end for hicss inner
    
    // begin for layout output
XueShuming's avatar
XueShuming committed
143
    HLUsedBoxValues box_values;
XueShuming's avatar
XueShuming committed
144
    HLUsedBackgroundValues background_values;
XueShuming's avatar
XueShuming committed
145
    HLUsedTextValues text_values;
XueShuming's avatar
XueShuming committed
146
    HLUsedSvgValues* svg_values;
XueShuming's avatar
XueShuming committed
147
148
149
150
151
152
153
154
155
156

    double min_w;
    double max_w;

    double min_h;
    double max_h;

    // top, right, bottom, left
    double margin[4];
    double padding[4];
157
    double border[4];
XueShuming's avatar
XueShuming committed
158
159
160
    int borderType[4];

    // end for layout output
XueShuming's avatar
XueShuming committed
161
162
163
164

    // for css select result
    css_select_results* select_styles;
    css_computed_style* computed_style;
XueShuming's avatar
XueShuming committed
165

XueShuming's avatar
XueShuming committed
166
167
} HLDomElementNode;

XueShuming's avatar
XueShuming committed
168
bool _hl_node_is_root(HLDomElementNode *n);
XueShuming's avatar
XueShuming committed
169
170
int _hl_element_node_set_inner_attr(HLDomElementNode* node, const char* attr_name, const char* attr_value);
const char* _hl_element_node_get_inner_attr(HLDomElementNode* node, const char* attr_name);
171
172
int _hl_element_node_set_inner_data(HLDomElementNode* node, const char* key, void* data, HlDestroyCallback destroy_callback);
void* _hl_element_node_get_inner_data(HLDomElementNode* node, const char* key);
XueShuming's avatar
XueShuming committed
173
void _hl_destroy_svg_values(HLUsedSvgValues* svg);
XueShuming's avatar
XueShuming committed
174

XueShuming's avatar
XueShuming committed
175
176
177
178
#ifdef __cplusplus
}
#endif

179
#endif // _HL_NODE_H