| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 20:33:02 +01:00
										 |  |  | #include <LibGUI/Painter.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/HTMLBodyElement.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-07 10:06:22 +02:00
										 |  |  | #include <LibWeb/Frame/Frame.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/Layout/LayoutBlock.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Layout/LayoutBox.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | namespace Web { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 21:35:44 +02:00
										 |  |  | void LayoutBox::paint_border(PaintContext& context, Edge edge, const Gfx::FloatRect& rect, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id) | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-24 13:51:14 +02:00
										 |  |  |     auto border_width = specified_style().property(width_property_id); | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  |     if (!border_width.has_value()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 13:51:14 +02:00
										 |  |  |     auto border_style = specified_style().property(style_property_id); | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  |     float width = border_width.value()->to_length().to_px(*this); | 
					
						
							| 
									
										
										
										
											2020-05-11 00:03:18 +01:00
										 |  |  |     if (width <= 0) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  |     int int_width = max((int)width, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  |     Color color; | 
					
						
							| 
									
										
										
										
											2020-06-24 13:51:14 +02:00
										 |  |  |     auto border_color = specified_style().property(color_property_id); | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  |     if (border_color.has_value()) { | 
					
						
							|  |  |  |         color = border_color.value()->to_color(document()); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         // FIXME: This is basically CSS "currentColor" which should be handled elsewhere
 | 
					
						
							|  |  |  |         //        in a much more reusable way.
 | 
					
						
							| 
									
										
										
										
											2020-06-24 13:51:14 +02:00
										 |  |  |         auto current_color = specified_style().property(CSS::PropertyID::Color); | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  |         if (current_color.has_value()) | 
					
						
							|  |  |  |             color = current_color.value()->to_color(document()); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             color = Color::Black; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 14:33:05 +01:00
										 |  |  |     auto first_point_for_edge = [](Edge edge, const Gfx::FloatRect& rect) { | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  |         switch (edge) { | 
					
						
							|  |  |  |         case Edge::Top: | 
					
						
							|  |  |  |             return rect.top_left(); | 
					
						
							|  |  |  |         case Edge::Right: | 
					
						
							|  |  |  |             return rect.top_right(); | 
					
						
							|  |  |  |         case Edge::Bottom: | 
					
						
							|  |  |  |             return rect.bottom_left(); | 
					
						
							|  |  |  |         case Edge::Left: | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             return rect.top_left(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 14:33:05 +01:00
										 |  |  |     auto second_point_for_edge = [](Edge edge, const Gfx::FloatRect& rect) { | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  |         switch (edge) { | 
					
						
							|  |  |  |         case Edge::Top: | 
					
						
							|  |  |  |             return rect.top_right(); | 
					
						
							|  |  |  |         case Edge::Right: | 
					
						
							|  |  |  |             return rect.bottom_right(); | 
					
						
							|  |  |  |         case Edge::Bottom: | 
					
						
							|  |  |  |             return rect.bottom_right(); | 
					
						
							|  |  |  |         case Edge::Left: | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             return rect.bottom_left(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto p1 = first_point_for_edge(edge, rect); | 
					
						
							|  |  |  |     auto p2 = second_point_for_edge(edge, rect); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (border_style.has_value() && border_style.value()->to_string() == "inset") { | 
					
						
							|  |  |  |         auto top_left_color = Color::from_rgb(0x5a5a5a); | 
					
						
							|  |  |  |         auto bottom_right_color = Color::from_rgb(0x888888); | 
					
						
							|  |  |  |         color = (edge == Edge::Left || edge == Edge::Top) ? top_left_color : bottom_right_color; | 
					
						
							|  |  |  |     } else if (border_style.has_value() && border_style.value()->to_string() == "outset") { | 
					
						
							|  |  |  |         auto top_left_color = Color::from_rgb(0x888888); | 
					
						
							|  |  |  |         auto bottom_right_color = Color::from_rgb(0x5a5a5a); | 
					
						
							|  |  |  |         color = (edge == Edge::Left || edge == Edge::Top) ? top_left_color : bottom_right_color; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 11:58:33 +01:00
										 |  |  |     auto line_style = Gfx::Painter::LineStyle::Solid; | 
					
						
							|  |  |  |     if (border_style.has_value()) { | 
					
						
							|  |  |  |         if (border_style.value()->to_string() == "dotted") | 
					
						
							|  |  |  |             line_style = Gfx::Painter::LineStyle::Dotted; | 
					
						
							| 
									
										
										
										
											2020-05-10 18:08:02 +01:00
										 |  |  |         if (border_style.value()->to_string() == "dashed") | 
					
						
							|  |  |  |             line_style = Gfx::Painter::LineStyle::Dashed; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (line_style != Gfx::Painter::LineStyle::Solid) { | 
					
						
							|  |  |  |         switch (edge) { | 
					
						
							|  |  |  |         case Edge::Top: | 
					
						
							|  |  |  |             p1.move_by(int_width / 2, int_width / 2); | 
					
						
							|  |  |  |             p2.move_by(-int_width / 2, int_width / 2); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case Edge::Right: | 
					
						
							|  |  |  |             p1.move_by(-int_width / 2, int_width / 2); | 
					
						
							|  |  |  |             p2.move_by(-int_width / 2, -int_width / 2); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case Edge::Bottom: | 
					
						
							|  |  |  |             p1.move_by(int_width / 2, -int_width / 2); | 
					
						
							|  |  |  |             p2.move_by(-int_width / 2, -int_width / 2); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case Edge::Left: | 
					
						
							|  |  |  |             p1.move_by(int_width / 2, int_width / 2); | 
					
						
							|  |  |  |             p2.move_by(int_width / 2, -int_width / 2); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, int_width, line_style); | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2020-05-10 11:58:33 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-27 20:53:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  |     auto draw_line = [&](auto& p1, auto& p2) { | 
					
						
							| 
									
										
										
										
											2020-05-10 11:58:33 +01:00
										 |  |  |         context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, 1, line_style); | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto width_for = [&](CSS::PropertyID property_id) -> float { | 
					
						
							| 
									
										
										
										
											2020-06-24 13:51:14 +02:00
										 |  |  |         auto width = specified_style().property(property_id); | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  |         if (!width.has_value()) | 
					
						
							|  |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  |         return width.value()->to_length().to_px(*this); | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     float p1_step = 0; | 
					
						
							|  |  |  |     float p2_step = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (edge) { | 
					
						
							|  |  |  |     case Edge::Top: | 
					
						
							|  |  |  |         p1_step = width_for(CSS::PropertyID::BorderLeftWidth) / (float)int_width; | 
					
						
							|  |  |  |         p2_step = width_for(CSS::PropertyID::BorderRightWidth) / (float)int_width; | 
					
						
							|  |  |  |         for (int i = 0; i < int_width; ++i) { | 
					
						
							|  |  |  |             draw_line(p1, p2); | 
					
						
							|  |  |  |             p1.move_by(p1_step, 1); | 
					
						
							|  |  |  |             p2.move_by(-p2_step, 1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case Edge::Right: | 
					
						
							|  |  |  |         p1_step = width_for(CSS::PropertyID::BorderTopWidth) / (float)int_width; | 
					
						
							|  |  |  |         p2_step = width_for(CSS::PropertyID::BorderBottomWidth) / (float)int_width; | 
					
						
							|  |  |  |         for (int i = int_width - 1; i >= 0; --i) { | 
					
						
							|  |  |  |             draw_line(p1, p2); | 
					
						
							|  |  |  |             p1.move_by(-1, p1_step); | 
					
						
							|  |  |  |             p2.move_by(-1, -p2_step); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case Edge::Bottom: | 
					
						
							|  |  |  |         p1_step = width_for(CSS::PropertyID::BorderLeftWidth) / (float)int_width; | 
					
						
							|  |  |  |         p2_step = width_for(CSS::PropertyID::BorderRightWidth) / (float)int_width; | 
					
						
							|  |  |  |         for (int i = int_width - 1; i >= 0; --i) { | 
					
						
							|  |  |  |             draw_line(p1, p2); | 
					
						
							|  |  |  |             p1.move_by(p1_step, -1); | 
					
						
							|  |  |  |             p2.move_by(-p2_step, -1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case Edge::Left: | 
					
						
							|  |  |  |         p1_step = width_for(CSS::PropertyID::BorderTopWidth) / (float)int_width; | 
					
						
							|  |  |  |         p2_step = width_for(CSS::PropertyID::BorderBottomWidth) / (float)int_width; | 
					
						
							|  |  |  |         for (int i = 0; i < int_width; ++i) { | 
					
						
							|  |  |  |             draw_line(p1, p2); | 
					
						
							|  |  |  |             p1.move_by(1, p1_step); | 
					
						
							|  |  |  |             p2.move_by(1, -p2_step); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-11-25 13:17:14 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 21:35:44 +02:00
										 |  |  | void LayoutBox::paint(PaintContext& context, PaintPhase phase) | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-10-15 19:12:12 +02:00
										 |  |  |     if (!is_visible()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-12 14:19:03 +02:00
										 |  |  |     Gfx::PainterStateSaver saver(context.painter()); | 
					
						
							|  |  |  |     if (is_fixed_position()) | 
					
						
							|  |  |  |         context.painter().translate(context.scroll_offset()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 14:33:05 +01:00
										 |  |  |     Gfx::FloatRect padded_rect; | 
					
						
							| 
									
										
										
										
											2020-06-24 11:22:34 +02:00
										 |  |  |     padded_rect.set_x(absolute_x() - box_model().padding.left.to_px(*this)); | 
					
						
							|  |  |  |     padded_rect.set_width(width() + box_model().padding.left.to_px(*this) + box_model().padding.right.to_px(*this)); | 
					
						
							|  |  |  |     padded_rect.set_y(absolute_y() - box_model().padding.top.to_px(*this)); | 
					
						
							|  |  |  |     padded_rect.set_height(height() + box_model().padding.top.to_px(*this) + box_model().padding.bottom.to_px(*this)); | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 18:57:35 +02:00
										 |  |  |     if (phase == PaintPhase::Background && !is_body()) { | 
					
						
							|  |  |  |         // FIXME: We should paint the body here too, but that currently happens at the view layer.
 | 
					
						
							| 
									
										
										
										
											2020-06-24 13:51:14 +02:00
										 |  |  |         auto bgcolor = specified_style().property(CSS::PropertyID::BackgroundColor); | 
					
						
							| 
									
										
										
										
											2019-10-19 11:49:46 +02:00
										 |  |  |         if (bgcolor.has_value() && bgcolor.value()->is_color()) { | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  |             context.painter().fill_rect(enclosing_int_rect(padded_rect), bgcolor.value()->to_color(document())); | 
					
						
							| 
									
										
										
										
											2019-10-19 11:49:46 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 13:51:14 +02:00
										 |  |  |         auto bgimage = specified_style().property(CSS::PropertyID::BackgroundImage); | 
					
						
							| 
									
										
										
										
											2019-10-19 11:49:46 +02:00
										 |  |  |         if (bgimage.has_value() && bgimage.value()->is_image()) { | 
					
						
							|  |  |  |             auto& image_value = static_cast<const ImageStyleValue&>(*bgimage.value()); | 
					
						
							|  |  |  |             if (image_value.bitmap()) { | 
					
						
							| 
									
										
										
										
											2019-11-25 14:12:04 +01:00
										 |  |  |                 context.painter().draw_tiled_bitmap(enclosing_int_rect(padded_rect), *image_value.bitmap()); | 
					
						
							| 
									
										
										
										
											2019-10-19 11:49:46 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 18:57:35 +02:00
										 |  |  |     if (phase == PaintPhase::Border) { | 
					
						
							|  |  |  |         Gfx::FloatRect bordered_rect; | 
					
						
							| 
									
										
										
										
											2020-06-24 11:22:34 +02:00
										 |  |  |         bordered_rect.set_x(padded_rect.x() - box_model().border.left.to_px(*this)); | 
					
						
							|  |  |  |         bordered_rect.set_width(padded_rect.width() + box_model().border.left.to_px(*this) + box_model().border.right.to_px(*this)); | 
					
						
							|  |  |  |         bordered_rect.set_y(padded_rect.y() - box_model().border.top.to_px(*this)); | 
					
						
							|  |  |  |         bordered_rect.set_height(padded_rect.height() + box_model().border.top.to_px(*this) + box_model().border.bottom.to_px(*this)); | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 18:57:35 +02:00
										 |  |  |         paint_border(context, Edge::Left, bordered_rect, CSS::PropertyID::BorderLeftStyle, CSS::PropertyID::BorderLeftColor, CSS::PropertyID::BorderLeftWidth); | 
					
						
							|  |  |  |         paint_border(context, Edge::Right, bordered_rect, CSS::PropertyID::BorderRightStyle, CSS::PropertyID::BorderRightColor, CSS::PropertyID::BorderRightWidth); | 
					
						
							|  |  |  |         paint_border(context, Edge::Top, bordered_rect, CSS::PropertyID::BorderTopStyle, CSS::PropertyID::BorderTopColor, CSS::PropertyID::BorderTopWidth); | 
					
						
							|  |  |  |         paint_border(context, Edge::Bottom, bordered_rect, CSS::PropertyID::BorderBottomStyle, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomWidth); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-15 19:12:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 21:35:44 +02:00
										 |  |  |     LayoutNodeWithStyleAndBoxModelMetrics::paint(context, phase); | 
					
						
							| 
									
										
										
										
											2020-05-10 23:04:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 18:57:35 +02:00
										 |  |  |     if (phase == PaintPhase::Overlay && node() && document().inspected_node() == node()) | 
					
						
							| 
									
										
										
										
											2020-06-10 10:42:29 +02:00
										 |  |  |         context.painter().draw_rect(enclosing_int_rect(absolute_rect()), Color::Magenta); | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  | HitTestResult LayoutBox::hit_test(const Gfx::IntPoint& position) const | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     // FIXME: It would be nice if we could confidently skip over hit testing
 | 
					
						
							|  |  |  |     //        parts of the layout tree, but currently we can't just check
 | 
					
						
							|  |  |  |     //        m_rect.contains() since inline text rects can't be trusted..
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:42:29 +02:00
										 |  |  |     HitTestResult result { absolute_rect().contains(position.x(), position.y()) ? this : nullptr }; | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  |     for_each_child([&](auto& child) { | 
					
						
							|  |  |  |         auto child_result = child.hit_test(position); | 
					
						
							|  |  |  |         if (child_result.layout_node) | 
					
						
							|  |  |  |             result = child_result; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LayoutBox::set_needs_display() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!is_inline()) { | 
					
						
							| 
									
										
										
										
											2020-06-14 16:45:45 +02:00
										 |  |  |         frame().set_needs_display(enclosing_int_rect(absolute_rect())); | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 20:45:52 +02:00
										 |  |  |     LayoutNode::set_needs_display(); | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-10-19 11:49:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool LayoutBox::is_body() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return node() && node() == document().body(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:42:29 +02:00
										 |  |  | void LayoutBox::set_offset(const Gfx::FloatPoint& offset) | 
					
						
							| 
									
										
										
										
											2020-06-05 19:13:27 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-10 10:42:29 +02:00
										 |  |  |     if (m_offset == offset) | 
					
						
							| 
									
										
										
										
											2020-06-05 19:13:27 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2020-06-10 10:42:29 +02:00
										 |  |  |     m_offset = offset; | 
					
						
							| 
									
										
										
										
											2020-06-05 19:13:27 +02:00
										 |  |  |     did_set_rect(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:42:29 +02:00
										 |  |  | void LayoutBox::set_size(const Gfx::FloatSize& size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_size == size) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     m_size = size; | 
					
						
							|  |  |  |     did_set_rect(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Gfx::FloatPoint LayoutBox::effective_offset() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_containing_line_box_fragment) | 
					
						
							|  |  |  |         return m_containing_line_box_fragment->offset(); | 
					
						
							|  |  |  |     return m_offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Gfx::FloatRect LayoutBox::absolute_rect() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Gfx::FloatRect rect { effective_offset(), size() }; | 
					
						
							|  |  |  |     for (auto* block = containing_block(); block; block = block->containing_block()) { | 
					
						
							|  |  |  |         rect.move_by(block->effective_offset()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return rect; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LayoutBox::set_containing_line_box_fragment(LineBoxFragment& fragment) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_containing_line_box_fragment = fragment.make_weak_ptr(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 17:29:35 +02:00
										 |  |  | StackingContext* LayoutBox::enclosing_stacking_context() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { | 
					
						
							|  |  |  |         if (!ancestor->is_box()) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         auto& ancestor_box = to<LayoutBox>(*ancestor); | 
					
						
							|  |  |  |         if (!ancestor_box.establishes_stacking_context()) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         ASSERT(ancestor_box.stacking_context()); | 
					
						
							|  |  |  |         return ancestor_box.stacking_context(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // We should always reach the LayoutDocument stacking context.
 | 
					
						
							|  |  |  |     ASSERT_NOT_REACHED(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool LayoutBox::establishes_stacking_context() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!has_style()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     if (node() == document().root()) | 
					
						
							|  |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2020-06-24 14:34:40 +02:00
										 |  |  |     auto position = style().position(); | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  |     auto z_index = style().z_index(); | 
					
						
							| 
									
										
										
										
											2020-06-15 17:29:35 +02:00
										 |  |  |     if (position == CSS::Position::Absolute || position == CSS::Position::Relative) { | 
					
						
							|  |  |  |         if (z_index.has_value()) | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (position == CSS::Position::Fixed || position == CSS::Position::Sticky) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | } |