public bool on_mouse_over(int x, int y, int z, int client_x, int client_y, int client_z, IList <position> redraw_boxes) //:h3ml { if (_root == null) { return(false); } var over_el = _root.get_element_by_point(x, y, z, client_x, client_y, client_z); //:h3ml var state_was_changed = false; if (over_el != _over_element) { if (_over_element != null) { if (_over_element.on_mouse_leave()) { state_was_changed = true; } } _over_element = over_el; } string cursor = null; if (_over_element != null) { if (_over_element.on_mouse_over()) { state_was_changed = true; } cursor = _over_element.get_cursor(); } _container.set_cursor(cursor ?? "auto"); return(state_was_changed ? _root.find_styles_changes(redraw_boxes, 0, 0, 0) : false); //:h3ml }
public floated_box(floated_box val) { pos = val.pos; float_side = val.float_side; clear_floats = val.clear_floats; el = val.el; }
public element next(bool ret_parent = true) { next_idx(); while (_idx < _el.get_children_count) { var el = _el.get_child(_idx); if (el.get_children_count != 0 && _go_inside != null && _go_inside.select(el)) { stack_item si; si.idx = _idx; si.el = _el; _stack.Push(si); _el = el; _idx = -1; if (ret_parent) { return(el); } next_idx(); } else { if (_select == null || (_select != null && _select.select(_el.get_child(_idx)))) { return(_el.get_child(_idx)); } else { next_idx(); } } } return(null); }
public override int depth => _depth; //:h3ml public override void add_element(element el) { el._skip = false; el._box = null; var add = true; if ((_items.Count == 0 && el.is_white_space()) || el.is_break()) { el._skip = true; } else if (el.is_white_space()) { if (have_last_space()) { add = false; el._skip = true; } } if (add) { el._box = this; _items.Add(el); if (!el._skip) { var el_shift_left = el.get_inline_shift_left(); var el_shift_right = el.get_inline_shift_right(); el._pos.x = _box_left + _width + el_shift_left + el.content_margins_left; el._pos.y = _box_top + el.content_margins_top; el._pos.z = _box_front + el.content_margins_front; //:h3ml _width += el.width + el_shift_left + el_shift_right; //_depth += el.depth + el_shift_front + el_shift_back; //:h3ml } } }
public elements_iterator(element el, iterator_selector go_inside, iterator_selector select) { _el = el; _idx = -1; _go_inside = go_inside; _select = select; }
void fix_table_children(element el_ptr, style_display disp, string disp_str) { // IList<element> tmp; // var first_iter = el_ptr._children.begin(); // var cur_iter = el_ptr._children.begin(); // auto flush_elements = [&]() // { // element::ptr annon_tag = std::make_shared<html_tag>(shared_from_this()); // style st; // st.add_property(_t("display"), disp_str, 0, false); // annon_tag.add_style(st); // annon_tag.parent(el_ptr); // annon_tag.parse_styles(); // std::for_each(tmp.begin(), tmp.end(), // [&annon_tag](element::ptr & el) // { // annon_tag.appendChild(el); // } //); // first_iter = el_ptr.m_children.insert(first_iter, annon_tag); // cur_iter = first_iter + 1; // while (cur_iter != el_ptr.m_children.end() && (*cur_iter).parent() != el_ptr) // { // cur_iter = el_ptr.m_children.erase(cur_iter); // } // first_iter = cur_iter; // tmp.clear(); // }; // while (cur_iter != el_ptr.m_children.end()) // { // if ((*cur_iter).get_display() != disp) // { // if (!(*cur_iter).is_white_space() || ((*cur_iter).is_white_space() && !tmp.empty())) // { // if (tmp.empty()) // { // first_iter = cur_iter; // } // tmp.push_back((*cur_iter)); // } // cur_iter++; // } // else if (!tmp.empty()) // { // flush_elements(); // } // else // { // cur_iter++; // } // } // if (!tmp.empty()) // { // flush_elements(); // } }
public void Dispose() { _over_element = null; if (_container != null) { foreach (var f in _fonts) { _container.delete_font(f.Value.font); } } }
public table_row() { min_height = 0; top = 0; bottom = 0; border_bottom = 0; border_top = 0; height = 0; el_row = null; css_height.predef = 0; }
public table_row(table_row val) { min_height = val.min_height; top = val.top; bottom = val.bottom; border_bottom = val.border_bottom; border_top = val.border_top; height = val.height; css_height = val.css_height; el_row = val.el_row; }
public table_cell() { min_width = 0; min_height = 0; max_width = 0; max_height = 0; width = 0; height = 0; colspan = 1; rowspan = 1; el = null; }
void next_idx() { _idx++; while (_idx >= _el.get_children_count && _stack.Count != 0) { var si = _stack.Last(); _stack.Pop(); _idx = si.idx; _el = si.el; _idx++; continue; } }
public table_cell(table_cell val) { el = val.el; colspan = val.colspan; rowspan = val.rowspan; width = val.width; height = val.height; min_width = val.min_width; min_height = val.min_height; max_width = val.max_width; max_height = val.max_height; borders = val.borders; }
public table_row(int h, element row) { min_height = 0; height = h; el_row = row; border_bottom = 0; border_top = 0; top = 0; bottom = 0; if (row != null) { css_height = row.get_css_height(); } }
public void add_cell(element el) { var cell = new table_cell { el = el, colspan = int.TryParse(el.get_attr("colspan", "1"), out var v) ? v : 0, rowspan = int.TryParse(el.get_attr("rowspan", "1"), out v) ? v : 0, borders = el.get_borders, }; while (is_rowspanned(_cells.Count - 1, _cells.Back().Count)) { _cells.Back().Add(new table_cell()); } _cells.Back().Add(cell); for (var i = 1; i < cell.colspan; i++) { _cells.Back().Add(new table_cell()); } }
public override bool can_hold(element el, white_space ws) { if (!el.is_inline_box) { return(false); } if (el.is_break()) { return(false); } if (ws == white_space.nowrap || ws == white_space.pre) { return(true); } if (_box_left + _width + el.width + el.get_inline_shift_left() + el.get_inline_shift_right() > _box_right) { return(false); } return(true); }
public override bool appendChild(element el) { _children.Add(el); return(true); }
public void begin_row(element row) { _cells.Add(new List <table_cell>()); _rows.Add(new table_row(0, row)); }
public bool select(element el) => el.get_display == style_display.table_cell;
public override bool appendChild(element el) { el.get_text(ref _text); return(true); }
//stack_item() { } stack_item(stack_item val) { idx = val.idx; el = val.el; }
void fix_table_parent(element el_ptr, style_display disp, string disp_str) { // element::ptr parent = el_ptr.parent(); // if (parent.get_display() != disp) // { // IList<element>::iterator this_element = std::find_if(parent.m_children.begin(), parent.m_children.end(), // [&](element::ptr & el) // { // if (el == el_ptr) // { // return true; // } // return false; // } //); // if (this_element != parent.m_children.end()) // { // style_display el_disp = el_ptr.get_display(); // IList<element>::iterator first = this_element; // IList<element>::iterator last = this_element; // IList<element>::iterator cur = this_element; // // find first element with same display // while (true) // { // if (cur == parent.m_children.begin()) break; // cur--; // if ((*cur).is_white_space() || (*cur).get_display() == el_disp) // { // first = cur; // } // else // { // break; // } // } // // find last element with same display // cur = this_element; // while (true) // { // cur++; // if (cur == parent.m_children.end()) break; // if ((*cur).is_white_space() || (*cur).get_display() == el_disp) // { // last = cur; // } // else // { // break; // } // } // // extract elements with the same display and wrap them with anonymous object // element::ptr annon_tag = std::make_shared<html_tag>(shared_from_this()); // style st; // st.add_property(_t("display"), disp_str, 0, false); // annon_tag.add_style(st); // annon_tag.parent(parent); // annon_tag.parse_styles(); // std::for_each(first, last + 1, // [&annon_tag](element::ptr & el) // { // annon_tag.appendChild(el); // } // ); // first = parent.m_children.erase(first, last + 1); // parent.m_children.insert(first, annon_tag); // } // } }
void create_node(Node node, List <element> elements) { switch (node) { case Element elementNode when node.Type == GumboNodeType.GUMBO_NODE_ELEMENT: { var attrs = new Dictionary <string, string>(); foreach (var attr in elementNode.Attributes) { attrs[attr.Name] = attr.Value; } element ret = null; var tag = elementNode.OriginalTagName; if (tag != null) { ret = create_element(tag, attrs); } else if (elementNode.OriginalTag != null) { ret = create_element(elementNode.OriginalTag, attrs); } if (ret != null) { var children = new List <element>(); foreach (var child in elementNode.Children) { children.Clear(); create_node(child, children); foreach (var i in children) { ret.appendChild(i); } } elements.Add(ret); } } break; case Text textNode when node.Type == GumboNodeType.GUMBO_NODE_TEXT: { var str = string.Empty; var str_in = textNode.Value; char c; for (var i = 0; i < str_in.Length; i++) { c = str_in[i]; if (c <= ' ' && (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f')) { if (str.Length != 0) { elements.Add(new el_text(str, this)); str = string.Empty; } str += c; elements.Add(new el_space(str, this)); str = string.Empty; } // CJK character range else if (c >= 0x4E00 && c <= 0x9FCC) { if (str.Length != 0) { elements.Add(new el_text(str, this)); str = string.Empty; } str += c; elements.Add(new el_text(str, this)); str = string.Empty; } else { str += c; } } if (str.Length != 0) { elements.Add(new el_text(str, this)); } } break; case Text textNode when node.Type == GumboNodeType.GUMBO_NODE_CDATA: { var ret = new el_cdata(this); ret.set_data(textNode.Value); elements.Add(ret); } break; case Text textNode when node.Type == GumboNodeType.GUMBO_NODE_COMMENT: { var ret = new el_comment(this); ret.set_data(textNode.Value); elements.Add(ret); } break; case Text textNode when node.Type == GumboNodeType.GUMBO_NODE_WHITESPACE: { var str = textNode.Value; for (var i = 0; i < str.Length; i++) { elements.Add(new el_space(str.Substring(i, 1), this)); } } break; default: break; } }
public bool select(element el) => el.get_display == style_display.inline || el.get_display == style_display.inline_text;
public void add_tabular(element el) => _tabular_elements.Add(el);
public override bool can_hold(element el, white_space ws) => _element != null || el.is_inline_box ? false : true;
public bool select(element el) => el.get_display == style_display.table_row_group || el.get_display == style_display.table_header_group || el.get_display == style_display.table_footer_group;
public void on_anchor_click(string url, element el) { }
public void link(document doc, element el) { }
public element create_element(string tag_name, Dictionary <string, string> attributes) { element newTag = null; var this_doc = this; if (_container != null) { newTag = _container.create_element(tag_name, attributes, this_doc); } if (newTag == null) { if (tag_name == "br") { newTag = new el_break(this_doc); } else if (tag_name == "p") { newTag = new el_para(this_doc); } else if (tag_name == "img") { newTag = new el_image(this_doc); } else if (tag_name == "table") { newTag = new el_table(this_doc); } else if (tag_name == "td" || tag_name == "th") { newTag = new el_td(this_doc); } else if (tag_name == "link") { newTag = new el_link(this_doc); } else if (tag_name == "title") { newTag = new el_title(this_doc); } else if (tag_name == "a") { newTag = new el_anchor(this_doc); } else if (tag_name == "tr") { newTag = new el_tr(this_doc); } else if (tag_name == "style") { newTag = new el_style(this_doc); } else if (tag_name == "base") { newTag = new el_base(this_doc); } else if (tag_name == "body") { newTag = new el_body(this_doc); } else if (tag_name == "div") { newTag = new el_div(this_doc); } else if (tag_name == "script") { newTag = new el_script(this_doc); } else if (tag_name == "font") { newTag = new el_font(this_doc); } else { newTag = new html_tag(this_doc); } } if (newTag != null) { newTag.set_tagName(tag_name); foreach (var iter in attributes) { newTag.set_attr(iter.Key, iter.Value); } } return(newTag); }
public override int depth => _element.depth; //:h3ml public override void add_element(element el) { _element = el; el._box = this; }