mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
LibWeb: User getter+setter for HTMLToken tag name and self-closing flag
This commit is contained in:
parent
1aeafcc58b
commit
15d8635afc
Notes:
sideshowbarker
2024-07-18 08:52:58 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/15d8635afc7 Pull-request: https://github.com/SerenityOS/serenity/pull/8784 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/alimpfard
4 changed files with 34 additions and 22 deletions
|
@ -1570,7 +1570,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
|
|||
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::image) {
|
||||
// Parse error. Change the token's tag name to HTML::TagNames::img and reprocess it. (Don't ask.)
|
||||
log_parse_error();
|
||||
token.m_tag.tag_name = "img";
|
||||
token.set_tag_name("img");
|
||||
process_using_the_rules_for(m_insertion_mode, token);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ String HTMLToken::to_string() const
|
|||
|
||||
if (type() == HTMLToken::Type::StartTag || type() == HTMLToken::Type::EndTag) {
|
||||
builder.append(" { name: '");
|
||||
builder.append(m_tag.tag_name);
|
||||
builder.append(tag_name());
|
||||
builder.append("', { ");
|
||||
for (auto& attribute : m_tag.attributes) {
|
||||
builder.append(attribute.local_name);
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
{
|
||||
HTMLToken token;
|
||||
token.m_type = Type::StartTag;
|
||||
token.m_tag.tag_name = tag_name;
|
||||
token.set_tag_name(tag_name);
|
||||
return token;
|
||||
}
|
||||
|
||||
|
@ -114,18 +114,30 @@ public:
|
|||
m_comment_or_character.data = move(comment);
|
||||
}
|
||||
|
||||
String tag_name() const
|
||||
String const& tag_name() const
|
||||
{
|
||||
VERIFY(is_start_tag() || is_end_tag());
|
||||
return m_tag.tag_name;
|
||||
}
|
||||
|
||||
void set_tag_name(String name)
|
||||
{
|
||||
VERIFY(is_start_tag() || is_end_tag());
|
||||
m_tag.tag_name = move(name);
|
||||
}
|
||||
|
||||
bool is_self_closing() const
|
||||
{
|
||||
VERIFY(is_start_tag() || is_end_tag());
|
||||
return m_tag.self_closing;
|
||||
}
|
||||
|
||||
void set_self_closing(bool self_closing)
|
||||
{
|
||||
VERIFY(is_start_tag() || is_end_tag());
|
||||
m_tag.self_closing = self_closing;
|
||||
}
|
||||
|
||||
bool has_acknowledged_self_closing_flag() const
|
||||
{
|
||||
VERIFY(is_self_closing());
|
||||
|
@ -156,8 +168,8 @@ public:
|
|||
void adjust_tag_name(FlyString const& old_name, FlyString const& new_name)
|
||||
{
|
||||
VERIFY(is_start_tag() || is_end_tag());
|
||||
if (old_name == m_tag.tag_name)
|
||||
m_tag.tag_name = new_name;
|
||||
if (old_name == tag_name())
|
||||
set_tag_name(new_name);
|
||||
}
|
||||
|
||||
void adjust_attribute_name(FlyString const& old_name, FlyString const& new_name)
|
||||
|
|
|
@ -305,19 +305,19 @@ _StartOfFunction:
|
|||
{
|
||||
ON_WHITESPACE
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
m_current_token.m_end_position = nth_last_position(1);
|
||||
SWITCH_TO(BeforeAttributeName);
|
||||
}
|
||||
ON('/')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
m_current_token.m_end_position = nth_last_position(0);
|
||||
SWITCH_TO(SelfClosingStartTag);
|
||||
}
|
||||
ON('>')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
m_current_token.m_end_position = nth_last_position(1);
|
||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||
}
|
||||
|
@ -1031,7 +1031,7 @@ _StartOfFunction:
|
|||
{
|
||||
ON('>')
|
||||
{
|
||||
m_current_token.m_tag.self_closing = true;
|
||||
m_current_token.set_self_closing(true);
|
||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||
}
|
||||
ON_EOF
|
||||
|
@ -1858,7 +1858,7 @@ _StartOfFunction:
|
|||
{
|
||||
ON_WHITESPACE
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (!current_end_tag_token_is_appropriate()) {
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||
|
@ -1870,7 +1870,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('/')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (!current_end_tag_token_is_appropriate()) {
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||
|
@ -1882,7 +1882,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('>')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (!current_end_tag_token_is_appropriate()) {
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||
|
@ -1973,7 +1973,7 @@ _StartOfFunction:
|
|||
{
|
||||
ON_WHITESPACE
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (!current_end_tag_token_is_appropriate()) {
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||
|
@ -1985,7 +1985,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('/')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (!current_end_tag_token_is_appropriate()) {
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||
|
@ -1997,7 +1997,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('>')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (!current_end_tag_token_is_appropriate()) {
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('/'));
|
||||
|
@ -2188,7 +2188,7 @@ _StartOfFunction:
|
|||
{
|
||||
ON_WHITESPACE
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (current_end_tag_token_is_appropriate())
|
||||
SWITCH_TO(BeforeAttributeName);
|
||||
|
||||
|
@ -2203,7 +2203,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('/')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (current_end_tag_token_is_appropriate())
|
||||
SWITCH_TO(SelfClosingStartTag);
|
||||
|
||||
|
@ -2218,7 +2218,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('>')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (current_end_tag_token_is_appropriate())
|
||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||
|
||||
|
@ -2524,7 +2524,7 @@ _StartOfFunction:
|
|||
{
|
||||
ON_WHITESPACE
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (current_end_tag_token_is_appropriate())
|
||||
SWITCH_TO(BeforeAttributeName);
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
|
@ -2537,7 +2537,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('/')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (current_end_tag_token_is_appropriate())
|
||||
SWITCH_TO(SelfClosingStartTag);
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
|
@ -2550,7 +2550,7 @@ _StartOfFunction:
|
|||
}
|
||||
ON('>')
|
||||
{
|
||||
m_current_token.m_tag.tag_name = consume_current_builder();
|
||||
m_current_token.set_tag_name(consume_current_builder());
|
||||
if (current_end_tag_token_is_appropriate())
|
||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||
m_queued_tokens.enqueue(HTMLToken::make_character('<'));
|
||||
|
|
Loading…
Add table
Reference in a new issue