2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-06-15 22:49:44 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-27 13:05:50 +02:00
|
|
|
#include <AK/Utf8View.h>
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/DOM/Text.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/Node.h>
|
2019-06-15 22:49:44 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
namespace Web::Layout {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2019-10-03 15:20:13 +02:00
|
|
|
class LineBoxFragment;
|
2019-09-25 12:36:44 +03:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
class TextNode : public Node {
|
2022-10-17 14:41:50 +02:00
|
|
|
JS_CELL(TextNode, Node);
|
|
|
|
|
2019-06-15 22:49:44 +02:00
|
|
|
public:
|
2020-11-22 15:53:01 +01:00
|
|
|
TextNode(DOM::Document&, DOM::Text&);
|
|
|
|
virtual ~TextNode() override;
|
2019-06-15 22:49:44 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
const DOM::Text& dom_node() const { return static_cast<const DOM::Text&>(*Node::dom_node()); }
|
2019-06-15 22:49:44 +02:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& text_for_rendering() const { return m_text_for_rendering; }
|
2019-06-15 23:17:08 +02:00
|
|
|
|
2021-04-27 13:05:50 +02:00
|
|
|
struct Chunk {
|
|
|
|
Utf8View view;
|
|
|
|
size_t start { 0 };
|
|
|
|
size_t length { 0 };
|
|
|
|
bool has_breaking_newline { false };
|
|
|
|
bool is_all_whitespace { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
class ChunkIterator {
|
|
|
|
public:
|
2022-10-14 12:38:02 +02:00
|
|
|
ChunkIterator(StringView text, bool wrap_lines, bool respect_linebreaks, bool is_generated_empty_string);
|
2021-04-27 13:05:50 +02:00
|
|
|
Optional<Chunk> next();
|
|
|
|
|
|
|
|
private:
|
2022-07-09 15:17:47 +02:00
|
|
|
Optional<Chunk> try_commit_chunk(Utf8View::Iterator const& start, Utf8View::Iterator const& end, bool has_breaking_newline) const;
|
2021-04-27 13:05:50 +02:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
bool const m_wrap_lines;
|
|
|
|
bool const m_respect_linebreaks;
|
2022-10-14 12:38:02 +02:00
|
|
|
bool m_should_emit_one_empty_chunk { false };
|
2021-04-27 13:05:50 +02:00
|
|
|
Utf8View m_utf8_view;
|
|
|
|
Utf8View::Iterator m_iterator;
|
|
|
|
};
|
|
|
|
|
2022-03-27 21:14:10 +02:00
|
|
|
void compute_text_for_rendering(bool collapse);
|
2021-04-29 08:51:31 +02:00
|
|
|
|
2023-01-11 12:51:49 +01:00
|
|
|
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
2022-03-10 16:46:44 +01:00
|
|
|
|
2019-06-15 22:49:44 +02:00
|
|
|
private:
|
2021-01-17 09:34:01 +01:00
|
|
|
virtual bool is_text_node() const final { return true; }
|
2019-12-18 12:44:16 +01:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_text_for_rendering;
|
2019-06-15 22:49:44 +02:00
|
|
|
};
|
2019-10-15 14:19:52 +02:00
|
|
|
|
2021-01-17 09:34:01 +01:00
|
|
|
template<>
|
|
|
|
inline bool Node::fast_is<TextNode>() const { return is_text_node(); }
|
|
|
|
|
2019-10-15 14:19:52 +02:00
|
|
|
}
|