mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
LibWeb: Make rendered_text_fragment return a DocumentFragment
This closer matches the spec and is needed in the implementation of the innerText setter.
This commit is contained in:
parent
dd11d48a1d
commit
a1a740bb3e
Notes:
github-actions[bot]
2024-11-10 20:32:26 +00:00
Author: https://github.com/shannonbooth
Commit: a1a740bb3e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2272
2 changed files with 13 additions and 8 deletions
|
@ -145,9 +145,10 @@ WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(StringView content_e
|
||||||
void HTMLElement::set_inner_text(StringView text)
|
void HTMLElement::set_inner_text(StringView text)
|
||||||
{
|
{
|
||||||
// 1. Let fragment be the rendered text fragment for value given element's node document.
|
// 1. Let fragment be the rendered text fragment for value given element's node document.
|
||||||
|
auto fragment = rendered_text_fragment(text);
|
||||||
|
|
||||||
// 2. Replace all with fragment within element.
|
// 2. Replace all with fragment within element.
|
||||||
remove_all_children();
|
replace_all(fragment);
|
||||||
append_rendered_text_fragment(text);
|
|
||||||
|
|
||||||
set_needs_style_update(true);
|
set_needs_style_update(true);
|
||||||
}
|
}
|
||||||
|
@ -160,10 +161,11 @@ WebIDL::ExceptionOr<void> HTMLElement::set_outer_text(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#rendered-text-fragment
|
// https://html.spec.whatwg.org/multipage/dom.html#rendered-text-fragment
|
||||||
void HTMLElement::append_rendered_text_fragment(StringView input)
|
JS::NonnullGCPtr<DOM::DocumentFragment> HTMLElement::rendered_text_fragment(StringView input)
|
||||||
{
|
{
|
||||||
// FIXME: 1. Let fragment be a new DocumentFragment whose node document is document.
|
// 1. Let fragment be a new DocumentFragment whose node document is document.
|
||||||
// Instead of creating a DocumentFragment the nodes are appended directly.
|
// Instead of creating a DocumentFragment the nodes are appended directly.
|
||||||
|
auto fragment = heap().allocate<DOM::DocumentFragment>(realm(), document());
|
||||||
|
|
||||||
// 2. Let position be a position variable for input, initially pointing at the start of input.
|
// 2. Let position be a position variable for input, initially pointing at the start of input.
|
||||||
// 3. Let text be the empty string.
|
// 3. Let text be the empty string.
|
||||||
|
@ -177,7 +179,7 @@ void HTMLElement::append_rendered_text_fragment(StringView input)
|
||||||
|
|
||||||
// 2. If text is not the empty string, then append a new Text node whose data is text and node document is document to fragment.
|
// 2. If text is not the empty string, then append a new Text node whose data is text and node document is document to fragment.
|
||||||
if (!text.is_empty()) {
|
if (!text.is_empty()) {
|
||||||
MUST(append_child(document().create_text_node(MUST(String::from_utf8(text)))));
|
MUST(fragment->append_child(document().create_text_node(MUST(String::from_utf8(text)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. While position is not past the end of input, and the code point at position is either U+000A LF or U+000D CR:
|
// 3. While position is not past the end of input, and the code point at position is either U+000A LF or U+000D CR:
|
||||||
|
@ -193,9 +195,12 @@ void HTMLElement::append_rendered_text_fragment(StringView input)
|
||||||
|
|
||||||
// 3. Append the result of creating an element given document, br, and the HTML namespace to fragment.
|
// 3. Append the result of creating an element given document, br, and the HTML namespace to fragment.
|
||||||
auto br_element = DOM::create_element(document(), HTML::TagNames::br, Namespace::HTML).release_value();
|
auto br_element = DOM::create_element(document(), HTML::TagNames::br, Namespace::HTML).release_value();
|
||||||
MUST(append_child(br_element));
|
MUST(fragment->append_child(br_element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. Return fragment.
|
||||||
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RequiredLineBreakCount {
|
struct RequiredLineBreakCount {
|
||||||
|
|
|
@ -97,7 +97,7 @@ private:
|
||||||
virtual void did_lose_focus() override;
|
virtual void did_lose_focus() override;
|
||||||
|
|
||||||
[[nodiscard]] String get_the_text_steps();
|
[[nodiscard]] String get_the_text_steps();
|
||||||
void append_rendered_text_fragment(StringView input);
|
JS::NonnullGCPtr<DOM::DocumentFragment> rendered_text_fragment(StringView input);
|
||||||
|
|
||||||
JS::GCPtr<DOM::NodeList> m_labels;
|
JS::GCPtr<DOM::NodeList> m_labels;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue