Skip to content

Commit f5ea0b0

Browse files
committed
Add method update to document
1 parent cb84450 commit f5ea0b0

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

include/litehtml/document.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ namespace litehtml
105105
void append_children_from_string(element& parent, const char* str);
106106
void dump(dumper& cout);
107107

108+
void update();
109+
108110
static litehtml::document::ptr createFromString(const char* str, litehtml::document_container* objPainter, const char* master_styles = litehtml::master_css, const char* user_styles = "");
109111

110112
private:

src/document.cpp

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,61 @@ litehtml::document::~document()
4545
}
4646
}
4747

48+
void litehtml::document::update()
49+
{
50+
container()->get_media_features(m_media);
51+
52+
//// apply master CSS
53+
m_root->apply_stylesheet(m_master_css);
54+
//
55+
//// parse elements attributes
56+
m_root->parse_attributes();
57+
//
58+
//// parse style sheets linked in document
59+
media_query_list::ptr media;
60+
for (const auto& css : m_css)
61+
{
62+
if (!css.media.empty())
63+
{
64+
media = media_query_list::create_from_string(css.media, shared_from_this());
65+
}
66+
else
67+
{
68+
media = nullptr;
69+
}
70+
m_styles.parse_stylesheet(css.text.c_str(), css.baseurl.c_str(), shared_from_this(), media);
71+
}
72+
//// Sort css selectors using CSS rules.
73+
m_styles.sort_selectors();
74+
//
75+
//// get current media features
76+
if (!m_media_lists.empty())
77+
{
78+
update_media_lists(m_media);
79+
}
80+
//
81+
//// Apply parsed styles.
82+
m_root->apply_stylesheet(m_styles);
83+
//
84+
//// Apply user styles if any
85+
m_root->apply_stylesheet(m_user_css);
86+
//
87+
//// Initialize m_css
88+
m_root->compute_styles();
89+
//
90+
//// Create rendering tree
91+
m_root_render = m_root->create_render_item(nullptr);
92+
//
93+
//// Now the m_tabular_elements is filled with tabular elements.
94+
//// We have to check the tabular elements for missing table elements
95+
//// and create the anonymous boxes in visual table layout
96+
fix_tables_layout();
97+
98+
// Finally initialize elements
99+
// init() return pointer to the render_init element because it can change its type
100+
m_root_render = m_root_render->init();
101+
}
102+
48103
litehtml::document::ptr litehtml::document::createFromString( const char* str, document_container* objPainter, const char* master_styles, const char* user_styles )
49104
{
50105
// parse document into GumboOutput
@@ -77,59 +132,8 @@ litehtml::document::ptr litehtml::document::createFromString( const char* str, d
77132
// Let's process created elements tree
78133
if (doc->m_root)
79134
{
80-
doc->container()->get_media_features(doc->m_media);
81-
82135
doc->m_root->set_pseudo_class(_root_, true);
83-
84-
// apply master CSS
85-
doc->m_root->apply_stylesheet(doc->m_master_css);
86-
87-
// parse elements attributes
88-
doc->m_root->parse_attributes();
89-
90-
// parse style sheets linked in document
91-
media_query_list::ptr media;
92-
for (const auto& css : doc->m_css)
93-
{
94-
if (!css.media.empty())
95-
{
96-
media = media_query_list::create_from_string(css.media, doc);
97-
}
98-
else
99-
{
100-
media = nullptr;
101-
}
102-
doc->m_styles.parse_stylesheet(css.text.c_str(), css.baseurl.c_str(), doc, media);
103-
}
104-
// Sort css selectors using CSS rules.
105-
doc->m_styles.sort_selectors();
106-
107-
// get current media features
108-
if (!doc->m_media_lists.empty())
109-
{
110-
doc->update_media_lists(doc->m_media);
111-
}
112-
113-
// Apply parsed styles.
114-
doc->m_root->apply_stylesheet(doc->m_styles);
115-
116-
// Apply user styles if any
117-
doc->m_root->apply_stylesheet(doc->m_user_css);
118-
119-
// Initialize m_css
120-
doc->m_root->compute_styles();
121-
122-
// Create rendering tree
123-
doc->m_root_render = doc->m_root->create_render_item(nullptr);
124-
125-
// Now the m_tabular_elements is filled with tabular elements.
126-
// We have to check the tabular elements for missing table elements
127-
// and create the anonymous boxes in visual table layout
128-
doc->fix_tables_layout();
129-
130-
// Finally initialize elements
131-
// init() return pointer to the render_init element because it can change its type
132-
doc->m_root_render = doc->m_root_render->init();
136+
doc->update();
133137
}
134138

135139
return doc;

0 commit comments

Comments
 (0)