height: 50px;
border: 1px dotted black;
padding: 25px;
- overflow: visible;
+ overflow: scroll;
scrollbar-width: 15px;
scrollbar-color: orangeRed lightGray;
}
return tmp;
}
-static int __css_parse_value(abc_obj_t* css, abc_obj_t* attr)
+static int __css_parse_value(abc_obj_t* css, abc_attr_t* attr)
{
scf_string_t* value = scf_string_alloc();
if (!value)
break;
};
- scf_list_t* l;
- abc_obj_t* attr;
+ scf_list_t* l;
+ abc_attr_t* attr;
int i;
int j;
scf_string_free(key);
key = NULL;
- attr->line = css->text_line;
- attr->pos = css->text_pos;
-
return __css_parse_value(css, attr);
}
abc_char_t* c;
abc_char_t* c2;
abc_io_t* io = NULL;
- abc_obj_t* href;
+ abc_attr_t* href;
char* path;
int n;
return ret;
}
-static void __css_background(abc_obj_t* obj, abc_obj_t* attr)
+static void __css_background(abc_obj_t* obj, abc_attr_t* attr)
{
char* p0 = NULL;
char* p1 = attr->value->data;
}
}
-static void __css_set_attr(abc_obj_t* obj, abc_obj_t* attr)
+static void __css_set_attr(abc_obj_t* obj, abc_attr_t* attr)
{
switch (attr->type)
{
static void __css_merge(abc_obj_t* dst, abc_obj_t* src)
{
- abc_obj_t* s;
- abc_obj_t* d;
+ abc_attr_t* s;
+ abc_attr_t* d;
int i;
for (i = 0; i < sizeof(src->attrs) / sizeof(src->attrs[0]); i++) {
return 0;
}
-static abc_obj_t* __css_filter_pse(abc_obj_t* current, abc_obj_t* pse)
+static abc_obj_t* __css_filter_pse(abc_obj_t* current, abc_attr_t* pse)
{
scf_list_t* l;
abc_obj_t* parent = current->parent;
{
scf_list_t* l;
abc_obj_t* tmp;
- abc_obj_t* pse;
+ abc_attr_t* pse;
pse_link_t* pseLink;
assert(next >= 0 && next < vec->size);
{
scf_list_t* l;
abc_obj_t* tmp;
- abc_obj_t* attr;
- abc_obj_t* pse;
+ abc_attr_t* attr;
+ abc_attr_t* pse;
pse_link_t* pseLink;
assert(next >= 0 && next < vec->size);
if (!html || !obj)
return -EINVAL;
- if (!html->css)
- return 0;
-
scf_list_t* l;
+ abc_attr_t* attr;
abc_obj_t* css;
- abc_obj_t* attr;
- for (l = scf_list_head(&html->css->childs); l != scf_list_sentinel(&html->css->childs); l = scf_list_next(l)) {
- css = scf_list_data(l, abc_obj_t, list);
+ if (html->css) {
+ for (l = scf_list_head(&html->css->childs); l != scf_list_sentinel(&html->css->childs); l = scf_list_next(l)) {
+ css = scf_list_data(l, abc_obj_t, list);
- switch (css->type)
- {
- case ABC_CSS_ID:
- case ABC_CSS_CLASS:
- case ABC_CSS_PSE_CLASS:
- case ABC_CSS_PSE_ELEMENT:
- case ABC_CSS_COMBINATOR:
- __css_use_complex(css, obj);
- break;
+ switch (css->type)
+ {
+ case ABC_CSS_ID:
+ case ABC_CSS_CLASS:
+ case ABC_CSS_PSE_CLASS:
+ case ABC_CSS_PSE_ELEMENT:
+ case ABC_CSS_COMBINATOR:
+ __css_use_complex(css, obj);
+ break;
- default:
- if (css->type == obj->type)
- abc_obj_set_css(obj, css);
- break;
- };
+ default:
+ if (css->type == obj->type)
+ abc_obj_set_css(obj, css);
+ break;
+ };
+ }
}
// for inline css below
- css = abc_obj_get_attr(obj, ABC_HTML_ATTR_STYLE);
+ attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_STYLE);
- if (css && css->value && css->value->len > 0)
+ if (attr && attr->value && attr->value->len > 0)
{
html_label_t* label = __html_find_label2(obj->type);
abc_io_t* io = abc_io_array[ABC_PROTO_STR];
+ css = abc_obj_alloc(obj->file, obj->line, obj->pos, ABC_HTML_STYLE);
+ if (!css)
+ return -ENOMEM;
+
css->io.proto = io->proto;
css->io.priv = NULL;
css->io.open = io->open;
css->text_line = 1;
css->text_pos = 0;
- int ret = io->open(&css->io, css->value->data);
- if (ret < 0)
+ int ret = io->open(&css->io, attr->value->data);
+ if (ret < 0) {
+ abc_obj_free(css);
return ret;
+ }
ret = __css_parse_attr(css, css, label->attrs, label->n_attrs);
io->close(&css->io);
- if (ret < 0 && EOF != ret)
+ if (ret < 0 && EOF != ret) {
+ abc_obj_free(css);
return ret;
+ }
int i;
for (i = 0; i < sizeof(css->attrs) / sizeof(css->attrs[0]); i++) {
continue;
__css_set_attr(obj, attr);
-
- abc_obj_free(attr);
- css->attrs[i] = NULL;
}
+
+ abc_obj_free(css);
}
return 0;
void abc_obj_set_css(abc_obj_t* obj, abc_obj_t* css)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
int i;
for (i = 0; i < sizeof(css->attrs) / sizeof(css->attrs[0]); i++) {
double g = 0.0;
double b = 0.0;
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_MARGIN);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_MARGIN);
if (attr)
margin = atoi(attr->value->data);
int abc_css_width(abc_obj_t* obj, int width, int margin)
{
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_WIDTH);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_WIDTH);
if (attr && attr->value && attr->value->len > 0) {
int abc_css_height(abc_obj_t* obj, int height, int margin)
{
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HEIGHT);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HEIGHT);
if (attr && attr->value && attr->value->len > 0) {
return ABC_OVERFLOW_VISIBLE;
}
+int abc_css_scrollbar_width(const uint8_t* str)
+{
+ if (!__html_strcmp(str, "thin") || !__html_strcmp(str, "auto"))
+ return 15;
+
+ else if (!__html_strcmp(str, "none"))
+ return 0;
+
+ return atoi(str);
+}
+
void abc_overflow_show(int* x, int* y, int* w, int* h, int mask_x, int mask_y, int mask_w, int mask_h)
{
#define CSS_OVERFLOW_SHOW(px, pw, x2, x3) \
if (type < ABC_HTML_ATTR_ID || type >= ABC_HTML_CSS_NB)
return -EINVAL;
- abc_obj_t* attr = abc_obj_alloc(NULL, 0, 0, type);
+ abc_attr_t* attr = calloc(1, sizeof(abc_attr_t));
if (!attr)
return -ENOMEM;
- attr->keys = names;
-
attr->value = scf_string_cstr(value);
if (!attr->value) {
- abc_obj_free(attr);
+ free(attr);
return -ENOMEM;
}
+ attr->type = type;
+ attr->keys = names;
attr->flags = flags;
int i = type - ABC_HTML_ATTR_ID;
if (obj->attrs[i])
- abc_obj_free(obj->attrs[i]);
+ abc_attr_free(obj->attrs[i]);
obj->attrs[i] = attr;
return 0;
static int __html_load_attrs(abc_obj_t* obj, html_attr_t* attrs, int n_attrs)
{
- scf_list_t* l;
- abc_obj_t* attr;
-
+ scf_list_t* l;
+ abc_attr_t* attr;
int ret;
int i;
scf_string_t* url;
scf_string_t* content;
abc_html_t* html;
- abc_obj_t* action;
+ abc_attr_t* action;
abc_io_t* io;
int n;
return __html_parse_end(html, obj);
}
-static int __html_parse_value(abc_html_t* html, abc_obj_t* attr)
+static int __html_parse_value(abc_html_t* html, abc_attr_t* attr)
{
scf_string_t* value = scf_string_alloc();
if (!value)
free(c);
c = NULL;
- abc_obj_t* attr;
+ abc_attr_t* attr;
int i;
int j;
scf_string_free(key);
key = NULL;
- assert(!attr->file);
-
- attr->file = scf_string_clone(html->file);
- if (!attr->file)
- return -ENOMEM;
-
- attr->line = html->n_lines;
- attr->pos = html->pos;
-
return __html_parse_value(html, attr);
}
static int __html_parse_obj(abc_html_t* html, abc_char_t* c)
{
- html_label_t* label;
- abc_obj_t* obj;
- abc_obj_t* type;
-
- scf_string_t* key = scf_string_cstr_len(c->utf8, c->len);
+ html_label_t* label;
+ abc_obj_t* obj;
+ abc_attr_t* type;
+ scf_string_t* key = scf_string_cstr_len(c->utf8, c->len);
html->pos += c->len;
free(c);
int abc_css_position(const uint8_t* str);
int abc_css_overflow(const uint8_t* str);
+int abc_css_scrollbar_width(const uint8_t* str);
+int abc_css_scrollbar_color(double thumb[3], double track[3], const uint8_t* str);
+
void abc_overflow_show(int* x, int* y, int* w, int* h, int mask_x, int mask_y, int mask_w, int mask_h);
#endif
if (obj->av_filter)
abc_filter_close(obj->av_filter, 0);
#endif
+ int i;
+ for (i = 0; i < sizeof(obj->attrs) / sizeof(obj->attrs[0]); i++) {
+ if (obj->attrs[i])
+ abc_attr_free(obj->attrs[i]);
+ }
scf_list_clear(&obj->childs, abc_obj_t, list, abc_obj_free);
scf_list_clear(&obj->css_pse_rules, abc_obj_t, list, abc_obj_free);
}
}
+void abc_attr_free(abc_attr_t* attr)
+{
+ if (attr) {
+ if (attr->value)
+ scf_string_free(attr->value);
+
+ free(attr);
+ }
+}
+
void abc_dfs_update_xy(abc_obj_t* root, int dx, int dy)
{
scf_list_t* l;
return NULL;
}
+int abc_attr_cmp_keys(abc_attr_t* attr, const char* name, size_t len)
+{
+ int i;
+ for (i = 0; attr->keys[i]; i++) {
+
+ if (!__html_strncmp(attr->keys[i], name, len))
+ return 0;
+ }
+ return -1;
+}
+
int abc_obj_cmp_keys(abc_obj_t* obj, const char* name, size_t len)
{
int i;
int abc_obj_copy_attrs(abc_obj_t* dst, abc_obj_t* src)
{
- abc_obj_t* attr;
- abc_obj_t* copy;
+ abc_attr_t* attr;
+ abc_attr_t* copy;
int i;
for (i = 0; i < sizeof(src->attrs) / sizeof(src->attrs[0]); i++) {
if (!attr)
continue;
- copy = abc_obj_alloc(attr->file, attr->line, attr->pos, attr->type);
+ copy = calloc(1, sizeof(abc_attr_t));
if (!copy)
return -ENOMEM;
copy->value = scf_string_clone(attr->value);
if (!copy->value) {
- abc_obj_free(copy);
+ abc_attr_free(copy);
return -ENOMEM;
}
+ copy->type = attr->type;
copy->keys = attr->keys;
copy->flags = attr->flags;
if (dst->attrs[i])
- abc_obj_free(dst->attrs[i]);
+ abc_attr_free(dst->attrs[i]);
dst->attrs[i] = copy;
}
int abc_obj_set_attr(abc_obj_t* obj, int key, const char* value, size_t len)
{
scf_string_t* s;
- abc_obj_t* attr;
+ abc_attr_t* attr;
if (key < ABC_HTML_ATTR_ID || key >= ABC_HTML_CSS_NB)
return -EINVAL;
return 0;
}
-abc_obj_t* abc_obj_get_attr2(abc_obj_t* obj, const char* key, int len)
+abc_attr_t* abc_obj_get_attr2(abc_obj_t* obj, const char* key, int len)
{
- abc_obj_t* attr;
int i;
-
for (i = 0; i < sizeof(obj->attrs) / sizeof(obj->attrs[0]); i++) {
- attr = obj->attrs[i];
+ abc_attr_t* attr = obj->attrs[i];
- if (attr && !abc_obj_cmp_keys(attr, key, len))
+ if (attr && !abc_attr_cmp_keys(attr, key, len))
return attr;
}
return NULL;
}
-abc_obj_t* abc_obj_find_attr(abc_obj_t* obj, int key)
+abc_attr_t* abc_obj_find_attr(abc_obj_t* obj, int key)
{
- abc_obj_t* attr;
-
while (obj) {
- attr = abc_obj_get_attr(obj, key);
+ abc_attr_t* attr = abc_obj_get_attr(obj, key);
if (attr && attr->value && attr->value->len > 0)
return attr;
else if (obj->keys)
printf("%s ", obj->keys[0]);
- pse_link_t* pseLink;
- abc_obj_t* attr;
+ pse_link_t* pseLink;
+ abc_attr_t* attr;
int i;
printf("{\n");
printf("}\n");
}
+void abc_attr_print(abc_attr_t* attr)
+{
+ if (attr && attr->value && attr->value->len > 0)
+ {
+ if (!(ABC_HTML_FLAG_SHOW & attr->flags))
+ return;
+
+ printf(" %s=\"%s\"", attr->keys[0], attr->value->data);
+ }
+}
+
void abc_obj_print(abc_obj_t* obj)
{
- scf_list_t* l;
- abc_obj_t* attr;
- abc_obj_t* child;
+ scf_list_t* l;
+ abc_attr_t* attr;
+ abc_obj_t* child;
if (!obj)
return;
if (!(ABC_HTML_FLAG_SHOW & obj->flags))
return;
- if (obj->value) {
- if (obj->value->len > 0)
- printf(" %s=\"%s\"", obj->keys[0], obj->value->data);
- } else if (obj->keys)
+ if (obj->keys)
printf("<%s", obj->keys[0]);
int i;
continue;
if (ABC_HTML_FLAG_SHOW & attr->flags)
- abc_obj_print(attr);
+ abc_attr_print(attr);
}
- if (!obj->value) {
- if (obj->flags & ABC_HTML_FLAG_SINGLE)
- printf(" />\n");
- else if (obj->keys)
- printf(">\n");
- }
+ if (obj->flags & ABC_HTML_FLAG_SINGLE)
+ printf(" />\n");
+ else if (obj->keys)
+ printf(">\n");
if (obj->text)
printf("%s\n", obj->text->data);
}
}
-static int __abc_obj_to_string(abc_obj_t* obj, scf_string_t* s)
+static int __abc_attr_to_string(abc_attr_t* attr, scf_string_t* s)
{
- scf_list_t* l;
- abc_obj_t* attr;
- abc_obj_t* child;
-
- int ret;
-
- if (!obj)
+ if (!attr || !attr->value)
return 0;
- if (!(ABC_HTML_FLAG_SHOW & obj->flags))
+ if (!(ABC_HTML_FLAG_SHOW & attr->flags))
return 0;
- if (obj->value) {
- ret = scf_string_cat_cstr(s, " ");
- if (ret < 0)
- return ret;
+ int ret = scf_string_cat_cstr(s, " ");
+ if (ret < 0)
+ return ret;
- ret = scf_string_cat_cstr(s, obj->keys[0]);
- if (ret < 0)
- return ret;
+ ret = scf_string_cat_cstr(s, attr->keys[0]);
+ if (ret < 0)
+ return ret;
- ret = scf_string_cat_cstr(s, "=\"");
- if (ret < 0)
- return ret;
+ ret = scf_string_cat_cstr(s, "=\"");
+ if (ret < 0)
+ return ret;
- ret = scf_string_cat(s, obj->value);
- if (ret < 0)
- return ret;
+ ret = scf_string_cat(s, attr->value);
+ if (ret < 0)
+ return ret;
- ret = scf_string_cat_cstr(s, "\"");
- if (ret < 0)
- return ret;
+ return scf_string_cat_cstr(s, "\"");
+}
- } else if (obj->keys) {
+static int __abc_obj_to_string(abc_obj_t* obj, scf_string_t* s)
+{
+ scf_list_t* l;
+ abc_attr_t* attr;
+ abc_obj_t* child;
+ int ret;
+
+ if (!obj)
+ return 0;
+
+ if (!(ABC_HTML_FLAG_SHOW & obj->flags))
+ return 0;
+
+ if (obj->keys) {
ret = scf_string_cat_cstr(s, "<");
if (ret < 0)
return ret;
continue;
if (ABC_HTML_FLAG_SHOW & attr->flags) {
- ret = __abc_obj_to_string(attr, s);
+ ret = __abc_attr_to_string(attr, s);
if (ret < 0)
return ret;
}
}
- if (!obj->value) {
- if (obj->flags & ABC_HTML_FLAG_SINGLE) {
+ if (obj->flags & ABC_HTML_FLAG_SINGLE) {
- ret = scf_string_cat_cstr(s, " />\n");
- if (ret < 0)
- return ret;
+ ret = scf_string_cat_cstr(s, " />\n");
+ if (ret < 0)
+ return ret;
- } else if (obj->keys) {
- ret = scf_string_cat_cstr(s, ">\n");
- if (ret < 0)
- return ret;
- }
+ } else if (obj->keys) {
+ ret = scf_string_cat_cstr(s, ">\n");
+ if (ret < 0)
+ return ret;
}
if (obj->text) {
scf_string_t* abc_ol_list_style(abc_obj_t* obj, int num)
{
- abc_obj_t* attr = abc_obj_find_attr(obj, ABC_CSS_LIST_STYLE_TYPE);
+ abc_attr_t* attr = abc_obj_find_attr(obj, ABC_CSS_LIST_STYLE_TYPE);
if (attr) {
const char* p = attr->value->data;
return __li_style_number(num, 10, '0');
}
+
+static int __obj_scroll_xy(int* position, int move, int thumb, int track, int content_out)
+{
+ int range = track - thumb;
+ int min = thumb / 2;
+ int max = track - min;
+
+ if (*position < min)
+ *position = min;
+ if (*position > max)
+ *position = max;
+
+ if (move < min - *position)
+ move = min - *position;
+ if (move > max - *position)
+ move = max - *position;
+
+ assert(move >= -range && move <= range);
+
+ *position += move;
+
+ int diff = -(*position - min) * content_out / range;
+ return diff;
+}
+
+int abc_obj_scroll_y(abc_obj_t* obj, int thumb, int track, int move)
+{
+ int content_out = obj->content_h - obj->h;
+
+ return __obj_scroll_xy(&obj->scroll_y, move, thumb, track, content_out);
+}
+
+int abc_obj_scroll_x(abc_obj_t* obj, int thumb, int track, int move)
+{
+ int content_out = obj->content_w - obj->w;
+
+ return __obj_scroll_xy(&obj->scroll_x, move, thumb, track, content_out);
+}
#include"abc_io.h"
typedef struct abc_obj_s abc_obj_t;
+typedef struct abc_attr_s abc_attr_t;
typedef struct abc_text_s abc_text_t;
typedef struct pse_link_s pse_link_t;
#define ABC_HTML_FLAG_SINGLE 2
#define ABC_HTML_FLAG_SHOW 4
+struct abc_attr_s
+{
+ int type;
+ uint32_t flags;
+
+ char** keys;
+ scf_string_t* value;
+
+ abc_obj_t* parent;
+};
+
struct abc_obj_s
{
int type;
int n_childs;
int index;
- abc_obj_t* attrs[ABC_HTML_CSS_NB - ABC_HTML_ATTR_ID];
+ abc_attr_t* attrs[ABC_HTML_CSS_NB - ABC_HTML_ATTR_ID];
void* gtk_builder;
abc_filter_t* av_filter;
abc_obj_t* abc_obj_alloc(scf_string_t* file, int line, int pos, int type);
void abc_obj_free (abc_obj_t* obj);
+void abc_attr_free(abc_attr_t* attr);
+
abc_obj_t* abc_obj_find (abc_obj_t* root, int x, int y);
void abc_obj_print(abc_obj_t* obj);
void abc_obj_set_css (abc_obj_t* obj, abc_obj_t* css);
int abc_obj_set_attr (abc_obj_t* obj, int key, const char* value, size_t len);
-abc_obj_t* abc_obj_get_attr2(abc_obj_t* obj, const char* key, int len);
-abc_obj_t* abc_obj_find_attr(abc_obj_t* obj, int key);
+abc_attr_t* abc_obj_get_attr2(abc_obj_t* obj, const char* key, int len);
+abc_attr_t* abc_obj_find_attr(abc_obj_t* obj, int key);
abc_obj_t* abc_obj_find_type(abc_obj_t* root, int type);
-void abc_dfs_update_xy(abc_obj_t* root, int dx, int dy);
+void abc_dfs_update_xy(abc_obj_t* root, int dx, int dy);
+int abc_obj_scroll_y (abc_obj_t* obj, int thumb, int track, int move);
+int abc_obj_scroll_x (abc_obj_t* obj, int thumb, int track, int move);
scf_string_t* abc_obj_to_string(abc_obj_t* obj);
scf_string_t* abc_ol_list_style(abc_obj_t* obj, int num);
-static inline abc_obj_t* abc_obj_get_attr(abc_obj_t* obj, int key)
+static inline abc_attr_t* abc_obj_get_attr(abc_obj_t* obj, int key)
{
if (key < ABC_HTML_ATTR_ID || key >= ABC_HTML_CSS_NB)
return NULL;
static int __render_draw_bg_image(abc_render_t* render, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_BG_IMAGE);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_BG_IMAGE);
if (!attr)
return 0;
if (!attr->value || attr->value->len <= 0)
static int __render_draw_border(abc_render_t* render, abc_obj_t* obj, int width, int height)
{
+ abc_obj_t* parent = obj->parent;
+
if (0 == program)
__init_program(&program, vert_shader, frag_shader);
double fgColor[3] = {0.0, 0.0, 0.0};
double bgColor[4] = {0.0, 0.0, 0.0, 0.0};
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_BG_COLOR);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_BG_COLOR);
if (attr && attr->value->len > 0) {
- bgColor[4] = 1.0;
+ bgColor[3] = 1.0;
abc_css_color(bgColor, bgColor + 1, bgColor + 2, attr->value->data, attr->value->len);
}
obj->view_w = w;
obj->view_h = h;
- abc_obj_t* parent = obj->parent;
+ attr = abc_obj_find_attr(obj, ABC_CSS_OVERFLOW);
+ if (attr)
+ obj->overflow_type = abc_css_overflow(attr->value->data);
- if (parent && (x < parent->view_x
- || y < parent->view_y
- || x + w > parent->view_x + parent->view_w
- || y + h > parent->view_y + parent->view_h)) {
+ int scroll_flag = 0;
+ switch (obj->overflow_type)
+ {
+ case ABC_OVERFLOW_SCROLL:
+ case ABC_OVERFLOW_AUTO:
+ scroll_flag = 1;
- attr = abc_obj_find_attr(obj, ABC_CSS_OVERFLOW);
- if (attr)
- obj->overflow_type = abc_css_overflow(attr->value->data);
+ case ABC_OVERFLOW_HIDDEN:
+ if (parent && (x < parent->view_x
+ || y < parent->view_y
+ || x + w > parent->view_x + parent->view_w
+ || y + h > parent->view_y + parent->view_h)) {
- switch (obj->overflow_type)
- {
- case ABC_OVERFLOW_HIDDEN:
abc_overflow_show(&obj->view_x, &obj->view_y, &obj->view_w, &obj->view_h,
parent->view_x,
parent->view_y, parent->view_w, parent->view_h);
-
- scf_logw("x: %d, y: %d, w: %d, h: %d, obj: x: %d, y: %d, w: %d, h: %d, parent: x: %d, y: %d, w: %d, h: %d\n",
- x, y, w, h,
- obj->view_x, obj->view_y, obj->view_w, obj->view_h,
- parent->view_x, parent->view_y, parent->view_w, parent->view_h);
- break;
- case ABC_OVERFLOW_SCROLL:
- break;
- default:
- break;
- };
- }
+ }
+ break;
+ default:
+ break;
+ };
float mvp[16];
__compute_mvp(mvp, 0, 0, 0);
GLfloat x_border = border / (float)w;
GLfloat y_border = border / (float)h;
- if (ABC_OVERFLOW_HIDDEN == obj->overflow_type) {
- for (int i = 0; i < sizeof(texture_update) / sizeof(texture_update[0]) / 2; i++)
- scf_logi("%lg, %lg\n", texture_update[2 * i], texture_update[2 * i + 1]);
-
- printf(" x_border: %lg, y_border: %lg\n\n", x_border, y_border);
- }
-
GLfloat aspect = w / (float)h;
GLfloat w_scroll = 0.0;
GLfloat scroll_y = 0.0;
double thumbColor[4] = {bgColor[0], bgColor[1], bgColor[2], bgColor[3]};
double trackColor[4] = {bgColor[0], bgColor[1], bgColor[2], bgColor[3]};
- if (obj->content_h > obj->h)
+ if (obj->content_h > obj->h && scroll_flag)
{
- float percent = h / (float)obj->content_h;
- int len = h * percent;
- int range = h - len;
- int min = len / 2;
- int max = h - min;
-
- if (obj->scroll_y < min)
- obj->scroll_y = min;
- if (obj->scroll_y > max)
- obj->scroll_y = max;
-
- w_scroll = 25.0;
-
- attr = abc_obj_get_attr(obj, ABC_CSS_SCROLLBAR_WIDTH);
- if (attr && attr->value->len > 0)
- w_scroll = atof(attr->value->data);
-
attr = abc_obj_get_attr(obj, ABC_CSS_SCROLLBAR_COLOR);
if (attr && attr->value->len > 0) {
thumbColor[3] = 1.0;
thumbColor[3] = 1.0;
}
- scf_logi("obj mouse_down_x: %d, mouse_down_y: %d, mouse_move_x: %d, mouse_move_y: %d, x: %d, y: %d, x+w: %d, y+h: %d\n",
- obj->mouse_down_x,
- obj->mouse_down_x, obj->mouse_move_x, obj->mouse_move_y,
- x, y, x + w, y + h);
+ w_scroll = 15.0;
+
+ attr = abc_obj_get_attr(obj, ABC_CSS_SCROLLBAR_WIDTH);
+ if (attr && attr->value->len > 0)
+ w_scroll = abc_css_scrollbar_width(attr->value->data);
- int dy = 0;
+ if (w_scroll > h / 2)
+ w_scroll = h / 2;
+
+ float percent = h / (float)obj->content_h;
+
+ scroll_h = h * percent;
+ if (scroll_h < w_scroll)
+ scroll_h = w_scroll;
+
+ int move = 0;
if (obj->mouse_move_x > x + w - w_scroll
&& obj->mouse_move_x < x + w
&& obj->mouse_move_y > y
&& obj->mouse_down_y > y
&& obj->mouse_down_y < y + h) {
- dy = obj->mouse_move_y - obj->mouse_down_y;
- if (dy < min - obj->scroll_y)
- dy = min - obj->scroll_y;
- if (dy > max - obj->scroll_y)
- dy = max - obj->scroll_y;
-
- assert(dy >= -range && dy <= range);
-
- obj->scroll_y += dy;
+ move = obj->mouse_move_y - obj->mouse_down_y;
}
}
- dy = -(obj->scroll_y - min) * (obj->content_h - obj->h) / range;
+ int dy = abc_obj_scroll_y(obj, scroll_h, h, move);
abc_dfs_update_xy(obj, 0, dy);
- scroll_h = percent;
- scroll_y = obj->scroll_y / (float)h;
-
+ scroll_h /= (float)h;
+ scroll_y = obj->scroll_y / (float)h;
w_scroll /= (float)w;
- if (w_scroll > scroll_h / aspect)
- w_scroll = scroll_h / aspect;
scf_logi("aspect: %lg, w_scroll: %lg, scroll_y: %lg, scroll_h: %lg\n\n", aspect, w_scroll, scroll_y, scroll_h);
}
int __init_text(cairo_t* cr, abc_obj_t* obj, int num_flag)
{
- abc_obj_t* attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT);
+ abc_attr_t* attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT);
if (attr) {
int bold = CAIRO_FONT_WEIGHT_NORMAL;
int italic = CAIRO_FONT_SLANT_NORMAL;
- abc_obj_t* style = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT_STYLE);
+ abc_attr_t* style = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT_STYLE);
if (style) {
if (!__html_strcmp(style->value->data, "bold"))
bold = CAIRO_FONT_WEIGHT_BOLD;
if (0 == texture_rgba)
__init_texture(&texture_rgba, GL_RGBA, w, h, NULL);
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_surface_t* surface;
cairo_t* cr;
switch (obj->overflow_type)
{
case ABC_OVERFLOW_HIDDEN:
+ case ABC_OVERFLOW_SCROLL:
+ case ABC_OVERFLOW_AUTO:
abc_overflow_show(&view_x, &view_y, &view_w, &view_h,
obj->view_x,
obj->view_y, obj->view_w, obj->view_h);
do { \
abc_obj_t* tmp = parent; \
while (tmp && ABC_HTML != tmp->type) { \
- abc_obj_t* attr = abc_obj_get_attr(tmp, ABC_CSS_POSITION); \
+ abc_attr_t* attr = abc_obj_get_attr(tmp, ABC_CSS_POSITION); \
\
if (attr && attr->value->len > 0 \
&& __html_strcmp(attr->value->data, "static")) \
int abc_layout_css(abc_obj_t* obj)
{
- abc_obj_t* parent = obj->parent;
- abc_obj_t* attr;
+ abc_obj_t* parent = obj->parent;
+ abc_attr_t* attr;
if (!parent || parent->w <= 0)
return 0;
int abc_layout_div(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
int abc_layout_form(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
int abc_layout_h1(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
- abc_obj_t* style;
+ abc_attr_t* attr;
+ abc_attr_t* style;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
int abc_layout_input(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
int abc_layout_label(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
scf_list_t* l2;
abc_obj_t* tr;
abc_obj_t* td;
- abc_obj_t* attr;
+ abc_attr_t* attr;
int collapse = 0;
int abc_layout_td(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
abc_obj_t* table;
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
int __layout_text(cairo_t* cr, abc_obj_t* obj, int x, int width, cairo_text_extents_t* extents)
{
- abc_obj_t* attr;
- abc_obj_t* style;
+ abc_attr_t* attr;
+ abc_attr_t* style;
attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT);
if (attr) {
int abc_layout_text(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
abc_obj_t* parent = obj->parent;
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
abc_avio_t* avin = NULL;
abc_avio_t* vout = NULL;
abc_avio_t* aout = NULL;
- abc_obj_t* attr;
+ abc_attr_t* attr;
abc_obj_t* src;
int ret = abc_filter_open(&obj->av_filter);
int abc_layout_video(abc_layout_t* layout, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
int w = 0;
int h = 0;
static int _render_draw_a_href(abc_render_t* render, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HREF);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HREF);
if (!attr || !attr->value || attr->value->len <= 0) {
scf_loge("hyper link '%s' not found a URL\n", obj->text->data);
static int _render_draw_audio(abc_render_t* render, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_SRC);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_SRC);
if (!attr) {
scf_loge("src audio of '%s' not found\n", obj->keys[0]);
return -EINVAL;
{
__render_border.draw(&__render_border, obj, width, height);
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_BG_IMAGE);
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_BG_IMAGE);
if (attr && attr->value && attr->value->len > 0)
{
__render_bg_image.draw(&__render_bg_image, obj, width, height);
if (0 == texture_rgba)
__init_texture(&texture_rgba, GL_RGBA, obj->w, obj->h, NULL);
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
static int _render_draw_img(abc_render_t* render, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
abc_img_t* img = NULL;
attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_SRC);
if (0 == texture_rgba)
__init_texture(&texture_rgba, GL_RGBA, obj->w, obj->h, NULL);
- abc_obj_t* type;
- abc_obj_t* attr;
+ abc_attr_t* type;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
if (0 == texture_rgba)
__init_texture(&texture_rgba, GL_RGBA, obj->w, obj->h, NULL);
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_text_extents_t extents;
cairo_surface_t* surface;
cairo_t* cr;
static int _render_draw_li(abc_render_t* render, abc_obj_t* obj, int width, int height)
{
- abc_obj_t* attr;
+ abc_attr_t* attr;
cairo_surface_t* surface;
cairo_t* cr;
if (!obj->text)
return 0;
- abc_obj_t* attr;
+ abc_attr_t* attr;
int margin = 0;
int border = 1;
cairo_fill(cr);
cairo_stroke(cr);
- abc_obj_t* attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT);
+ abc_attr_t* attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT);
if (attr)
cairo_select_font_face(cr, attr->value->data, italic, bold);
__init_texture(&texture_rgba, GL_RGBA, obj->w, obj->h, NULL);
abc_text_t* t;
- abc_obj_t* attr;
+ abc_attr_t* attr;
double bcolor[3] = {0.0};
double fcolor[3] = {0.0};
return 0;
scf_list_t* l;
+ abc_attr_t* attr;
abc_obj_t* prev = ctx->current->current;
abc_obj_t* obj = abc_obj_find(ctx->current->root, x, y);
- abc_obj_t* attr;
abc_obj_t* css;
int ret = 0;
static int __do_button_release_a(abc_ctx_t* ctx, abc_obj_t* obj, int x, int y)
{
- abc_html_t* html = NULL;
- abc_obj_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HREF);
+ abc_html_t* html = NULL;
+ abc_attr_t* attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_HREF);
int ret = abc_html_open(&html, attr->value->data);
if (ret < 0)
static int __do_button_release(abc_ctx_t* ctx, int x, int y)
{
- abc_html_t* html;
- abc_obj_t* obj = abc_obj_find(ctx->current->root, x, y);
- abc_obj_t* css;
- abc_obj_t* attr;
+ abc_html_t* html;
+ abc_attr_t* attr;
+ abc_obj_t* obj = abc_obj_find(ctx->current->root, x, y);
+ abc_obj_t* css;
if (!obj)
return __do_button_move(ctx, x, y);
static void __utf8_delete(abc_ctx_t* ctx)
{
- abc_obj_t* obj;
- abc_obj_t* attr;
+ abc_attr_t* attr;
+ abc_obj_t* obj;
if (!ctx->current || !ctx->current->current)
return;
if (c < 0x80)
break;
-
if ((c >> 6) != 0x2)
break;
}
static void im_commit(GtkIMContext* self, gchar* str, gpointer user_data)
{
- abc_ctx_t* ctx = user_data;
- abc_obj_t* obj;
- abc_obj_t* attr;
+ abc_ctx_t* ctx = user_data;
+ abc_obj_t* obj;
+ abc_attr_t* attr;
scf_logw("str: %s\n", str);