diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 732582b0cb..b09c1d48da 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -372,7 +372,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho for (size_t i = 0; i < indent; ++i) builder.append(" "sv); auto& layout_text = static_cast(fragment.layout_node()); - auto fragment_text = layout_text.text_for_rendering().substring(fragment.start(), fragment.length()); + auto fragment_text = MUST(layout_text.text_for_rendering().substring_from_byte_offset(fragment.start(), fragment.length())); builder.appendff(" \"{}\"\n", fragment_text); } } diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index e5b5d0cebe..ca1a916541 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -306,7 +306,7 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) next_width = iterator.next_non_whitespace_sequence_width(); } else { // In whitespace-preserving contexts (white-space: pre*), we have to check manually. - auto view = text_node.text_for_rendering().substring_view(item.offset_in_node, item.length_in_node); + auto view = text_node.text_for_rendering().bytes_as_string_view().substring_view(item.offset_in_node, item.length_in_node); is_whitespace = view.is_whitespace(); if (is_whitespace) next_width = iterator.next_non_whitespace_sequence_width(); diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index be7f5a5e68..7d84974d3a 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -148,7 +148,7 @@ CSSPixels InlineLevelIterator::next_non_whitespace_sequence_width() if (next_item.is_collapsible_whitespace) break; auto& next_text_node = verify_cast(*(next_item.node)); - auto next_view = next_text_node.text_for_rendering().substring_view(next_item.offset_in_node, next_item.length_in_node); + auto next_view = next_text_node.text_for_rendering().bytes_as_string_view().substring_view(next_item.offset_in_node, next_item.length_in_node); if (next_view.is_whitespace()) break; } diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp index ce185ec52a..9b8ff28c89 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -31,7 +31,7 @@ StringView LineBoxFragment::text() const { if (!is(layout_node())) return {}; - return verify_cast(layout_node()).text_for_rendering().substring_view(m_start, m_length); + return verify_cast(layout_node()).text_for_rendering().bytes_as_string_view().substring_view(m_start, m_length); } CSSPixelRect const LineBoxFragment::absolute_rect() const diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index f189c659dd..daae7ae6d8 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -33,7 +33,7 @@ static bool is_all_whitespace(StringView string) } // https://w3c.github.io/mathml-core/#new-text-transform-values -static DeprecatedString apply_math_auto_text_transform(DeprecatedString const& string) +static String apply_math_auto_text_transform(String const& string) { // https://w3c.github.io/mathml-core/#italic-mappings @@ -268,27 +268,27 @@ static DeprecatedString apply_math_auto_text_transform(DeprecatedString const& s } }; - StringBuilder builder(string.length()); + StringBuilder builder(string.bytes().size()); - for (auto code_point : Utf8View(string)) + for (auto code_point : string.code_points()) builder.append_code_point(map_code_point_to_italic(code_point)); - return builder.to_deprecated_string(); + return MUST(builder.to_string()); } -static ErrorOr apply_text_transform(DeprecatedString const& string, CSS::TextTransform text_transform) +static ErrorOr apply_text_transform(String const& string, CSS::TextTransform text_transform) { switch (text_transform) { case CSS::TextTransform::Uppercase: - return Unicode::to_unicode_uppercase_full(string); + return string.to_uppercase(); case CSS::TextTransform::Lowercase: - return Unicode::to_unicode_lowercase_full(string); + return string.to_lowercase(); case CSS::TextTransform::None: return string; case CSS::TextTransform::MathAuto: return apply_math_auto_text_transform(string); case CSS::TextTransform::Capitalize: { - return TRY(Unicode::to_unicode_titlecase_full(string, {}, Unicode::TrailingCodePointTransformation::PreserveExisting)).to_deprecated_string(); + return string.to_titlecase({}, TrailingCodePointTransformation::PreserveExisting); } case CSS::TextTransform::FullSizeKana: case CSS::TextTransform::FullWidth: @@ -304,7 +304,7 @@ void TextNode::invalidate_text_for_rendering() m_text_for_rendering = {}; } -DeprecatedString const& TextNode::text_for_rendering() const +String const& TextNode::text_for_rendering() const { if (!m_text_for_rendering.has_value()) const_cast(this)->compute_text_for_rendering(); @@ -330,10 +330,12 @@ void TextNode::compute_text_for_rendering() if (dom_node().is_editable() && !dom_node().is_uninteresting_whitespace_node()) collapse = false; - auto data = apply_text_transform(dom_node().data().to_deprecated_string(), computed_values().text_transform()).release_value_but_fixme_should_propagate_errors(); + auto data = apply_text_transform(dom_node().data(), computed_values().text_transform()).release_value_but_fixme_should_propagate_errors(); + + auto data_view = data.bytes_as_string_view(); if (dom_node().is_password_input()) { - m_text_for_rendering = DeprecatedString::repeated('*', data.length()); + m_text_for_rendering = MUST(String::repeated('*', data_view.length())); return; } @@ -343,9 +345,9 @@ void TextNode::compute_text_for_rendering() } // NOTE: A couple fast returns to avoid unnecessarily allocating a StringBuilder. - if (data.length() == 1) { - if (is_ascii_space(data[0])) { - static DeprecatedString s_single_space_string = " "; + if (data_view.length() == 1) { + if (is_ascii_space(data_view[0])) { + static String s_single_space_string = " "_string; m_text_for_rendering = s_single_space_string; } else { m_text_for_rendering = data; @@ -354,7 +356,7 @@ void TextNode::compute_text_for_rendering() } bool contains_space = false; - for (auto& c : data) { + for (auto c : data_view) { if (is_ascii_space(c)) { contains_space = true; break; @@ -365,26 +367,26 @@ void TextNode::compute_text_for_rendering() return; } - StringBuilder builder(data.length()); + StringBuilder builder(data_view.length()); size_t index = 0; - auto skip_over_whitespace = [&index, &data] { - while (index < data.length() && is_ascii_space(data[index])) + auto skip_over_whitespace = [&index, &data_view] { + while (index < data_view.length() && is_ascii_space(data_view[index])) ++index; }; - while (index < data.length()) { - if (is_ascii_space(data[index])) { + while (index < data_view.length()) { + if (is_ascii_space(data_view[index])) { builder.append(' '); ++index; skip_over_whitespace(); } else { - builder.append(data[index]); + builder.append(data_view[index]); ++index; } } - m_text_for_rendering = builder.to_deprecated_string(); + m_text_for_rendering = MUST(builder.to_string()); } TextNode::ChunkIterator::ChunkIterator(StringView text, bool wrap_lines, bool respect_linebreaks) diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.h b/Userland/Libraries/LibWeb/Layout/TextNode.h index 30699e7ae5..0daeb1272e 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.h +++ b/Userland/Libraries/LibWeb/Layout/TextNode.h @@ -23,7 +23,7 @@ public: const DOM::Text& dom_node() const { return static_cast(*Node::dom_node()); } - DeprecatedString const& text_for_rendering() const; + String const& text_for_rendering() const; struct Chunk { Utf8View view; @@ -55,7 +55,7 @@ public: private: virtual bool is_text_node() const final { return true; } - Optional m_text_for_rendering; + Optional m_text_for_rendering; }; template<> diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index c13a8f1d1f..a0ac8d68ef 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -234,13 +234,13 @@ ErrorOr TreeBuilder::create_pseudo_element_if_needed(DOM::Element& element static bool is_ignorable_whitespace(Layout::Node const& node) { - if (node.is_text_node() && static_cast(node).text_for_rendering().is_whitespace()) + if (node.is_text_node() && static_cast(node).text_for_rendering().bytes_as_string_view().is_whitespace()) return true; if (node.is_anonymous() && node.is_block_container() && static_cast(node).children_are_inline()) { bool contains_only_white_space = true; node.for_each_in_inclusive_subtree_of_type([&contains_only_white_space](auto& text_node) { - if (!text_node.text_for_rendering().is_whitespace()) { + if (!text_node.text_for_rendering().bytes_as_string_view().is_whitespace()) { contains_only_white_space = false; return IterationDecision::Break; } diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 11b7418b70..88cdbca3e4 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -615,7 +615,7 @@ bool EventHandler::handle_doubleclick(CSSPixelPoint position, CSSPixelPoint scre // Start from one before the index position to prevent selecting only spaces between words, caused by the addition below. // This also helps us dealing with cases where index is equal to the string length. for (int i = result->index_in_node - 1; i >= 0; --i) { - if (is_ascii_space(text_for_rendering[i])) { + if (is_ascii_space(text_for_rendering.bytes_as_string_view()[i])) { // Don't include the space in the selection return i + 1; } @@ -624,11 +624,11 @@ bool EventHandler::handle_doubleclick(CSSPixelPoint position, CSSPixelPoint scre }(); int first_word_break_after = [&] { - for (size_t i = result->index_in_node; i < text_for_rendering.length(); ++i) { - if (is_ascii_space(text_for_rendering[i])) + for (size_t i = result->index_in_node; i < text_for_rendering.bytes().size(); ++i) { + if (is_ascii_space(text_for_rendering.bytes_as_string_view()[i])) return i; } - return text_for_rendering.length(); + return text_for_rendering.bytes().size(); }(); auto& realm = node->document().realm(); diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index a67663cf42..5699ca0597 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -645,7 +645,7 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t auto text = text_node.text_for_rendering(); DevicePixelPoint baseline_start { fragment_absolute_device_rect.x(), fragment_absolute_device_rect.y() + context.rounded_device_pixels(fragment.baseline()) }; - Utf8View view { text.substring_view(fragment.start(), fragment.length()) }; + Utf8View view { text.code_points().substring_view(fragment.start(), fragment.length()) }; auto& scaled_font = fragment.layout_node().scaled_font(context);