Skip to content

Blocks rendering #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set(SOURCE_LITEHTML
src/render_table.cpp
src/render_flex.cpp
src/render_image.cpp
src/formatting_context.cpp
)

set(HEADER_LITEHTML
Expand Down Expand Up @@ -124,6 +125,7 @@ set(HEADER_LITEHTML
include/litehtml/render_item.h
include/litehtml/master_css.h
include/litehtml/string_id.h
include/litehtml/formatting_context.h
)

set(TEST_LITEHTML
Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace litehtml
private:
uint_ptr add_font(const char* name, int size, const char* weight, const char* style, const char* decoration, font_metrics* fm);

void create_node(void* gnode, elements_vector& elements, bool parseTextNode);
void create_node(void* gnode, elements_list& elements, bool parseTextNode);
bool update_media_lists(const media_features& features);
void fix_tables_layout();
void fix_table_children(const std::shared_ptr<render_item>& el_ptr, style_display disp, const char* disp_str);
Expand Down
1 change: 0 additions & 1 deletion include/litehtml/el_before_after.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace litehtml
el_before_after_base(const std::shared_ptr<document>& doc, bool before);

void add_style(const style& style) override;
void apply_stylesheet(const litehtml::css& stylesheet) override;
private:
void add_text(const string& txt);
void add_function(const string& fnc, const string& params);
Expand Down
2 changes: 1 addition & 1 deletion include/litehtml/el_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace litehtml
{
class el_style : public element
{
elements_vector m_children;
elements_list m_children;
public:
explicit el_style(const std::shared_ptr<document>& doc);

Expand Down
23 changes: 13 additions & 10 deletions include/litehtml/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ namespace litehtml
protected:
std::weak_ptr<element> m_parent;
std::weak_ptr<document> m_doc;
elements_vector m_children;
elements_list m_children;
css_properties m_css;
std::list<std::weak_ptr<render_item>> m_renders;
used_selector::vector m_used_styles;

virtual void select_all(const css_selector& selector, elements_vector& res);
virtual void select_all(const css_selector& selector, elements_list& res);
element::ptr _add_before_after(int type, const style& style);
public:
explicit element(const std::shared_ptr<document>& doc);
Expand All @@ -43,23 +43,25 @@ namespace litehtml
css_properties& css_w();

bool in_normal_flow() const;
bool is_inline_box() const;
bool is_inline() const; // returns true if element is inline
bool is_inline_box() const; // returns true if element is inline box (inline-table, inline-box, inline-flex)
bool is_block_box() const;
position get_placement() const;
bool is_positioned() const;
bool is_float() const;
bool is_block_formatting_context() const;

bool have_parent() const;
bool is_root() const;
element::ptr parent() const;
void parent(const element::ptr& par);
// returns true for elements inside a table (but outside cells) that don't participate in table rendering
bool is_table_skip() const;

std::shared_ptr<document> get_document() const;
const std::list<std::shared_ptr<element>>& children() const;

virtual elements_vector select_all(const string& selector);
virtual elements_vector select_all(const css_selector& selector);
virtual elements_list select_all(const string& selector);
virtual elements_list select_all(const css_selector& selector);

virtual element::ptr select_one(const string& selector);
virtual element::ptr select_one(const css_selector& selector);
Expand All @@ -73,8 +75,6 @@ namespace litehtml
virtual const char* get_tagName() const;
virtual void set_tagName(const char* tag);
virtual void set_data(const char* data);
virtual size_t get_children_count() const;
virtual element::ptr get_child(int idx) const;

virtual void set_attr(const char* name, const char* val);
virtual const char* get_attr(const char* name, const char* def = nullptr) const;
Expand Down Expand Up @@ -119,8 +119,6 @@ namespace litehtml
virtual element::ptr find_adjacent_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual element::ptr find_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual void get_content_size(size& sz, int max_width);
virtual bool is_floats_holder() const;
virtual void update_floats(int dy, const ptr &parent);
virtual bool is_nth_child(const element::ptr& el, int num, int off, bool of_type) const;
virtual bool is_nth_last_child(const element::ptr& el, int num, int off, bool of_type) const;
virtual bool is_only_child(const element::ptr& el, bool of_type) const;
Expand Down Expand Up @@ -211,6 +209,11 @@ namespace litehtml
}
return false;
}

inline const std::list<std::shared_ptr<element>>& element::children() const
{
return m_children;
}
}

#endif // LH_ELEMENT_H
54 changes: 54 additions & 0 deletions include/litehtml/formatting_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef LITEHTML_FLOATS_HOLDER_H
#define LITEHTML_FLOATS_HOLDER_H

#include <list>
#include "types.h"

namespace litehtml
{
class formatting_context
{
private:
std::list<floated_box> m_floats_left;
std::list<floated_box> m_floats_right;
int_int_cache m_cache_line_left;
int_int_cache m_cache_line_right;
int m_current_top;
int m_current_left;

public:
formatting_context() : m_current_top(0), m_current_left(0) {}

void push_position(int x, int y)
{
m_current_left += x;
m_current_top += y;
}
void pop_position(int x, int y)
{
m_current_left -= x;
m_current_top -= y;
}

void add_float(const std::shared_ptr<render_item> &el, int min_width, int context);
void clear_floats(int context);
int find_next_line_top( int top, int width, int def_right );
int get_floats_height(element_float el_float = float_none) const;
int get_left_floats_height() const;
int get_right_floats_height() const;
int get_line_left( int y );
void get_line_left_right( int y, int def_right, int& ln_left, int& ln_right )
{
ln_left = get_line_left(y);
ln_right = get_line_right(y, def_right);
}
int get_line_right( int y, int def_right );
int get_cleared_top(const std::shared_ptr<render_item> &el, int line_top) const;
void update_floats(int dy, const std::shared_ptr<render_item> &parent);
void apply_relative_shift(const containing_block_context &containing_block_size);
int find_min_left(int y, int context_idx);
int find_min_right(int y, int right, int context_idx);
};
}

#endif //LITEHTML_FLOATS_HOLDER_H
13 changes: 5 additions & 8 deletions include/litehtml/html_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace litehtml
string_map m_attrs;
std::vector<string_id> m_pseudo_classes;

void select_all(const css_selector& selector, elements_vector& res) override;
void select_all(const css_selector& selector, elements_list& res) override;

public:
explicit html_tag(const std::shared_ptr<document>& doc);
Expand All @@ -46,8 +46,6 @@ namespace litehtml
const char* get_tagName() const override;
void set_tagName(const char* tag) override;
void set_data(const char* data) override;
size_t get_children_count() const override;
element::ptr get_child(int idx) const override;

void set_attr(const char* name, const char* val) override;
const char* get_attr(const char* name, const char* def = nullptr) const override;
Expand Down Expand Up @@ -84,16 +82,16 @@ namespace litehtml
size_vector get_size_vector_property (string_id name, bool inherited, const size_vector& default_value, uint_ptr css_properties_member_offset) const override;
string get_custom_property(string_id name, const string& default_value) const override;

elements_vector& children();
elements_list& children();

int select(const string& selector) override;
int select(const css_selector& selector, bool apply_pseudo = true) override;
int select(const css_element_selector& selector, bool apply_pseudo = true) override;
int select_pseudoclass(const css_attribute_selector& sel);
int select_attribute(const css_attribute_selector& sel);

elements_vector select_all(const string& selector) override;
elements_vector select_all(const css_selector& selector) override;
elements_list select_all(const string& selector) override;
elements_list select_all(const css_selector& selector) override;

element::ptr select_one(const string& selector) override;
element::ptr select_one(const css_selector& selector) override;
Expand All @@ -105,7 +103,6 @@ namespace litehtml
void parse_attributes() override;

void get_content_size(size& sz, int max_width) override;
bool is_floats_holder() const override;
void add_style(const style& style) override;

bool is_nth_child(const element::ptr& el, int num, int off, bool of_type) const override;
Expand All @@ -128,7 +125,7 @@ namespace litehtml
/* Inline Functions */
/************************************************************************/

inline elements_vector& litehtml::html_tag::children()
inline elements_list& litehtml::html_tag::children()
{
return m_children;
}
Expand Down
13 changes: 13 additions & 0 deletions include/litehtml/master_css.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ table[border|=0] td, table[border|=0] th {
border-style:none;
}

table[align=left] {
float: left;
}

table[align=right] {
float: right;
}

table[align=center] {
margin-left: auto;
margin-right: auto;
}

caption {
display: table-caption;
}
Expand Down
Loading