| 
									
										
										
										
											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 { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 18:36:33 +01:00
										 |  |  |     const String& text_for_rendering() const { return m_text_for_rendering; } | 
					
						
							| 
									
										
										
										
											2019-06-15 23:17:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-03 19:30:48 +01:00
										 |  |  |     virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:00:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-05 20:10:39 +01:00
										 |  |  |     virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override; | 
					
						
							| 
									
										
										
										
											2019-09-29 11:32:00 +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: | 
					
						
							|  |  |  |         ChunkIterator(StringView const& text, LayoutMode, bool wrap_lines, bool wrap_breaks); | 
					
						
							|  |  |  |         Optional<Chunk> next(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         Optional<Chunk> try_commit_chunk(Utf8View::Iterator const&, bool has_breaking_newline, bool must_commit = false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const LayoutMode m_layout_mode; | 
					
						
							|  |  |  |         const bool m_wrap_lines; | 
					
						
							|  |  |  |         const bool m_wrap_breaks; | 
					
						
							|  |  |  |         bool m_last_was_space { false }; | 
					
						
							|  |  |  |         bool m_last_was_newline { false }; | 
					
						
							|  |  |  |         Utf8View m_utf8_view; | 
					
						
							|  |  |  |         Utf8View::Iterator m_start_of_chunk; | 
					
						
							|  |  |  |         Utf8View::Iterator m_iterator; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 08:51:31 +02:00
										 |  |  |     void compute_text_for_rendering(bool collapse, bool previous_is_empty_or_ends_in_whitespace); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; } | 
					
						
							| 
									
										
										
										
											2021-04-03 21:48:05 -04:00
										 |  |  |     virtual bool wants_mouse_events() const override; | 
					
						
							|  |  |  |     virtual void handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; | 
					
						
							|  |  |  |     virtual void handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; | 
					
						
							|  |  |  |     virtual void handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; | 
					
						
							| 
									
										
										
										
											2020-12-05 20:10:39 +01:00
										 |  |  |     void split_into_lines_by_rules(InlineFormattingContext&, LayoutMode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks); | 
					
						
							| 
									
										
										
										
											2020-08-02 11:52:35 +02:00
										 |  |  |     void paint_cursor_if_needed(PaintContext&, const LineBoxFragment&) const; | 
					
						
							| 
									
										
										
										
											2021-07-28 16:44:26 +02:00
										 |  |  |     void paint_text_decoration(Gfx::Painter&, LineBoxFragment const&) const; | 
					
						
							| 
									
										
										
										
											2019-12-18 12:44:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 16:29:23 +02:00
										 |  |  |     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
										 |  |  | } |