| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Debug.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/BrowsingContextContainer.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Layout/FrameBox.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Layout/InitialContainingBlock.h>
 | 
					
						
							| 
									
										
										
										
											2022-07-04 21:09:13 +01:00
										 |  |  | #include <LibWeb/Painting/BorderRadiusCornerClipper.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | #include <LibWeb/Painting/NestedBrowsingContextPaintable.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Painting { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-11 12:51:49 +01:00
										 |  |  | JS::NonnullGCPtr<NestedBrowsingContextPaintable> NestedBrowsingContextPaintable::create(Layout::FrameBox const& layout_box) | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-01-11 12:51:49 +01:00
										 |  |  |     return layout_box.heap().allocate_without_realm<NestedBrowsingContextPaintable>(layout_box); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NestedBrowsingContextPaintable::NestedBrowsingContextPaintable(Layout::FrameBox const& layout_box) | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:57 +01:00
										 |  |  |     : PaintableBox(layout_box) | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Layout::FrameBox const& NestedBrowsingContextPaintable::layout_box() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:57 +01:00
										 |  |  |     return static_cast<Layout::FrameBox const&>(layout_node()); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase phase) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-08-05 12:24:36 +02:00
										 |  |  |     if (!layout_box().is_visible()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:57 +01:00
										 |  |  |     PaintableBox::paint(context, phase); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (phase == PaintPhase::Foreground) { | 
					
						
							| 
									
										
										
										
											2022-10-31 19:46:55 +00:00
										 |  |  |         auto absolute_rect = this->absolute_rect(); | 
					
						
							|  |  |  |         auto clip_rect = context.rounded_device_rect(absolute_rect); | 
					
						
							| 
									
										
										
										
											2022-10-27 16:02:32 +01:00
										 |  |  |         ScopedCornerRadiusClip corner_clip { context, context.painter(), clip_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) }; | 
					
						
							| 
									
										
										
										
											2022-07-04 21:09:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  |         auto* hosted_document = layout_box().dom_node().content_document_without_origin_check(); | 
					
						
							|  |  |  |         if (!hosted_document) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         auto* hosted_layout_tree = hosted_document->layout_node(); | 
					
						
							|  |  |  |         if (!hosted_layout_tree) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         context.painter().save(); | 
					
						
							| 
									
										
										
										
											2022-10-27 14:37:05 +01:00
										 |  |  |         auto old_viewport_rect = context.device_viewport_rect(); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-27 16:02:32 +01:00
										 |  |  |         context.painter().add_clip_rect(clip_rect.to_type<int>()); | 
					
						
							| 
									
										
										
										
											2022-10-31 19:46:55 +00:00
										 |  |  |         context.painter().translate(absolute_rect.x().value(), absolute_rect.y().value()); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-03 12:49:54 +00:00
										 |  |  |         context.set_device_viewport_rect({ {}, context.enclosing_device_size(layout_box().dom_node().nested_browsing_context()->size()) }); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  |         const_cast<Layout::InitialContainingBlock*>(hosted_layout_tree)->paint_all_phases(context); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-27 14:37:05 +01:00
										 |  |  |         context.set_device_viewport_rect(old_viewport_rect); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  |         context.painter().restore(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) { | 
					
						
							|  |  |  |             if (layout_box().dom_node().nested_browsing_context()->is_focused_context()) { | 
					
						
							| 
									
										
										
										
											2022-10-31 19:46:55 +00:00
										 |  |  |                 context.painter().draw_rect(clip_rect.to_type<int>(), Color::Cyan); | 
					
						
							| 
									
										
										
										
											2022-03-10 14:02:25 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |