mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:15:07 +00:00
LibWeb: Add basic support for dynamic markup insertion
This implements basic support for dynamic markup insertion, adding * Document::open() * Document::write(Vector<String> const&) * Document::writeln(Vector<String> const&) * Document::close() The HTMLParser is modified to make it possible to create a script-created parser which initially only contains a HTMLTokenizer without any data. Aditionally the HTMLParser::run method gains an overload which does not modify the Document and does not run HTMLParser::the_end() so that we can reenter the parser at a later time. Furthermore all FIXMEs that consern the insertion point are implemented wich is defined in the HTMLTokenizer. Additionally the following member-variables of the HTMLParser are now exposed by getter funcions: * m_tokenizer * m_aborted * m_script_nesting_level The HTMLTokenizer is modified so that it contains an insertion point which keeps track of where the next input from the Document::write functions will be inserted. The insertion point is implemented as the charakter offset into m_decoded_input and a boolean describing if the insertion point is defined. Functions to update, check and {re}store the insertion point are also added. The function HTMLTokenizer::insert_eof is added to tell a script-created parser that document::close was called and HTMLParser::the_end() should be called. Lastly an explicit default constructor is added to HTMLTokenizer to create a empty HTMLTokenizer into which data can be inserted.
This commit is contained in:
parent
d29d9462e9
commit
db789813c9
7 changed files with 282 additions and 19 deletions
|
@ -101,6 +101,7 @@ namespace Web::HTML {
|
|||
|
||||
class HTMLTokenizer {
|
||||
public:
|
||||
explicit HTMLTokenizer();
|
||||
explicit HTMLTokenizer(StringView input, String const& encoding);
|
||||
|
||||
enum class State {
|
||||
|
@ -124,6 +125,24 @@ public:
|
|||
|
||||
String source() const { return m_decoded_input; }
|
||||
|
||||
void insert_input_at_insertion_point(String const& input);
|
||||
void insert_eof();
|
||||
bool is_eof_inserted();
|
||||
|
||||
bool is_insertion_point_defined() const { return m_insertion_point.defined; }
|
||||
bool is_insertion_point_reached()
|
||||
{
|
||||
return m_insertion_point.defined && m_insertion_point.position >= m_utf8_view.iterator_offset(m_utf8_iterator);
|
||||
}
|
||||
void undefine_insertion_point() { m_insertion_point.defined = false; }
|
||||
void store_insertion_point() { m_old_insertion_point = m_insertion_point; }
|
||||
void restore_insertion_point() { m_insertion_point = m_old_insertion_point; }
|
||||
void update_insertion_point()
|
||||
{
|
||||
m_insertion_point.defined = true;
|
||||
m_insertion_point.position = m_utf8_view.iterator_offset(m_utf8_iterator);
|
||||
}
|
||||
|
||||
private:
|
||||
void skip(size_t count);
|
||||
Optional<u32> next_code_point();
|
||||
|
@ -163,6 +182,13 @@ private:
|
|||
|
||||
String m_decoded_input;
|
||||
|
||||
struct InsertionPoint {
|
||||
size_t position { 0 };
|
||||
bool defined { false };
|
||||
};
|
||||
InsertionPoint m_insertion_point {};
|
||||
InsertionPoint m_old_insertion_point {};
|
||||
|
||||
Utf8View m_utf8_view;
|
||||
Utf8CodePointIterator m_utf8_iterator;
|
||||
Utf8CodePointIterator m_prev_utf8_iterator;
|
||||
|
@ -172,6 +198,7 @@ private:
|
|||
|
||||
Optional<String> m_last_emitted_start_tag_name;
|
||||
|
||||
bool m_explicit_eof_inserted { false };
|
||||
bool m_has_emitted_eof { false };
|
||||
|
||||
Queue<HTMLToken> m_queued_tokens;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue