| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | #include <LibWeb/Layout/Box.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/Layout/LineBox.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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | class BlockBox : public Box { | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     BlockBox(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>); | 
					
						
							| 
									
										
										
										
											2021-01-06 14:10:53 +01:00
										 |  |  |     BlockBox(DOM::Document&, DOM::Node*, CSS::ComputedValues); | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     virtual ~BlockBox() override; | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 21:35:44 +02:00
										 |  |  |     virtual void paint(PaintContext&, PaintPhase) override; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:00:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 16:55:56 +02:00
										 |  |  |     virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override; | 
					
						
							| 
									
										
										
										
											2019-10-03 15:20:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     BlockBox* previous_sibling() { return downcast<BlockBox>(Node::previous_sibling()); } | 
					
						
							|  |  |  |     const BlockBox* previous_sibling() const { return downcast<BlockBox>(Node::previous_sibling()); } | 
					
						
							|  |  |  |     BlockBox* next_sibling() { return downcast<BlockBox>(Node::next_sibling()); } | 
					
						
							|  |  |  |     const BlockBox* next_sibling() const { return downcast<BlockBox>(Node::next_sibling()); } | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-20 09:14:12 +02:00
										 |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     void for_each_fragment(Callback); | 
					
						
							|  |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     void for_each_fragment(Callback) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-05 20:10:39 +01:00
										 |  |  |     virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override; | 
					
						
							| 
									
										
										
										
											2021-01-17 09:34:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-22 23:44:51 +01:00
										 |  |  |     bool is_scrollable() const; | 
					
						
							| 
									
										
										
										
											2021-02-22 19:48:24 +01:00
										 |  |  |     const Gfx::FloatPoint& scroll_offset() const { return m_scroll_offset; } | 
					
						
							|  |  |  |     void set_scroll_offset(const Gfx::FloatPoint&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-17 09:34:01 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     virtual bool is_block_box() const final { return true; } | 
					
						
							| 
									
										
										
										
											2021-02-22 19:48:24 +01:00
										 |  |  |     virtual bool wants_mouse_events() const override { return true; } | 
					
						
							| 
									
										
										
										
											2021-03-02 08:36:58 +11:00
										 |  |  |     virtual bool handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta) override; | 
					
						
							| 
									
										
										
										
											2021-02-22 19:19:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool should_clip_overflow() const; | 
					
						
							| 
									
										
										
										
											2021-02-22 19:48:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Gfx::FloatPoint m_scroll_offset; | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-10-09 21:25:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-17 09:34:01 +01:00
										 |  |  | template<> | 
					
						
							|  |  |  | inline bool Node::fast_is<BlockBox>() const { return is_block_box(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 21:25:29 +02:00
										 |  |  | template<typename Callback> | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | void BlockBox::for_each_fragment(Callback callback) | 
					
						
							| 
									
										
										
										
											2019-10-20 09:14:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     for (auto& line_box : line_boxes()) { | 
					
						
							|  |  |  |         for (auto& fragment : line_box.fragments()) { | 
					
						
							|  |  |  |             if (callback(fragment) == IterationDecision::Break) | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename Callback> | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | void BlockBox::for_each_fragment(Callback callback) const | 
					
						
							| 
									
										
										
										
											2019-10-09 21:25:29 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-10-20 09:14:12 +02:00
										 |  |  |     for (auto& line_box : line_boxes()) { | 
					
						
							| 
									
										
										
										
											2019-10-09 21:25:29 +02:00
										 |  |  |         for (auto& fragment : line_box.fragments()) { | 
					
						
							|  |  |  |             if (callback(fragment) == IterationDecision::Break) | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-10-15 14:19:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |