summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-07-14 23:37:48 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-17 16:24:57 +0430
commit15d8635afc7c1e3c01524cc670d90c3709670b2c (patch)
treedf375a8456861850581d34f1462a187ef081c44a /Userland/Libraries
parent1aeafcc58bc38bd6c90e218b4e75a57893d4f0d8 (diff)
downloadserenity-15d8635afc7c1e3c01524cc670d90c3709670b2c.zip
LibWeb: User getter+setter for HTMLToken tag name and self-closing flag
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h20
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp32
4 files changed, 34 insertions, 22 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
index 67b6b499df..88c7de4ff3 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
@@ -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;
}
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp
index 432df887b9..f5c324f85e 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp
@@ -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);
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h
index 1649a20e7f..12ffa10999 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h
@@ -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)
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp
index 32e3c630c4..fa2489a90b 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp
@@ -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('<'));