| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-11 14:01:33 +01:00
										 |  |  | class TextNode final : 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 10:56:29 +13:00
										 |  |  |     String const& text_for_rendering() const; | 
					
						
							| 
									
										
										
										
											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: | 
					
						
							| 
									
										
										
										
											2023-07-11 12:28:47 +02:00
										 |  |  |         ChunkIterator(StringView text, bool wrap_lines, bool respect_linebreaks); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2021-04-27 13:05:50 +02:00
										 |  |  |         Utf8View m_utf8_view; | 
					
						
							|  |  |  |         Utf8View::Iterator m_iterator; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 11:03:00 +02:00
										 |  |  |     void invalidate_text_for_rendering(); | 
					
						
							| 
									
										
										
										
											2023-07-03 10:29:30 +02:00
										 |  |  |     void compute_text_for_rendering(); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 10:56:29 +13:00
										 |  |  |     Optional<String> 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
										 |  |  | } |