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
|
|
|
|
*/
|
|
|
|
|
|
2021-02-10 08:25:35 +01:00
|
|
|
|
#include <LibGfx/Painter.h>
|
2020-03-07 10:32:51 +01:00
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
|
#include <LibWeb/HTML/HTMLBodyElement.h>
|
2021-05-13 09:39:30 -04:00
|
|
|
|
#include <LibWeb/HTML/HTMLHtmlElement.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
|
#include <LibWeb/Layout/BlockBox.h>
|
|
|
|
|
#include <LibWeb/Layout/Box.h>
|
2021-05-30 12:36:53 +02:00
|
|
|
|
#include <LibWeb/Page/BrowsingContext.h>
|
2020-12-04 18:02:21 +01:00
|
|
|
|
#include <LibWeb/Painting/BorderPainting.h>
|
2019-10-15 16:48:38 +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
|
|
|
|
void Box::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());
|
|
|
|
|
|
2021-02-22 18:52:58 +01:00
|
|
|
|
auto padded_rect = this->padded_rect();
|
2019-10-15 16:48:38 +02:00
|
|
|
|
|
2021-05-13 09:39:30 -04:00
|
|
|
|
if (phase == PaintPhase::Background) {
|
|
|
|
|
|
2021-05-15 20:54:01 +02:00
|
|
|
|
paint_background(context);
|
2019-10-15 16:48:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 18:57:35 +02:00
|
|
|
|
if (phase == PaintPhase::Border) {
|
2021-04-20 13:39:36 +02:00
|
|
|
|
paint_border(context);
|
2020-06-18 18:57:35 +02:00
|
|
|
|
}
|
2019-10-15 19:12:12 +02:00
|
|
|
|
|
2020-11-22 14:46:36 +01:00
|
|
|
|
if (phase == PaintPhase::Overlay && dom_node() && document().inspected_node() == dom_node()) {
|
2020-06-25 15:15:01 +02:00
|
|
|
|
auto content_rect = absolute_rect();
|
|
|
|
|
|
2020-12-12 21:02:06 +01:00
|
|
|
|
auto margin_box = box_model().margin_box();
|
2020-06-25 15:15:01 +02:00
|
|
|
|
Gfx::FloatRect margin_rect;
|
|
|
|
|
margin_rect.set_x(absolute_x() - margin_box.left);
|
|
|
|
|
margin_rect.set_width(width() + margin_box.left + margin_box.right);
|
|
|
|
|
margin_rect.set_y(absolute_y() - margin_box.top);
|
|
|
|
|
margin_rect.set_height(height() + margin_box.top + margin_box.bottom);
|
|
|
|
|
|
|
|
|
|
context.painter().draw_rect(enclosing_int_rect(margin_rect), Color::Yellow);
|
|
|
|
|
context.painter().draw_rect(enclosing_int_rect(padded_rect), Color::Cyan);
|
|
|
|
|
context.painter().draw_rect(enclosing_int_rect(content_rect), Color::Magenta);
|
|
|
|
|
}
|
2020-08-14 19:40:37 +02:00
|
|
|
|
|
2021-06-24 19:53:42 +02:00
|
|
|
|
if (phase == PaintPhase::FocusOutline && dom_node() && dom_node()->is_element() && verify_cast<DOM::Element>(*dom_node()).is_focused()) {
|
2020-08-14 19:40:37 +02:00
|
|
|
|
context.painter().draw_rect(enclosing_int_rect(absolute_rect()), context.palette().focus_outline());
|
|
|
|
|
}
|
2019-10-15 16:48:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 13:39:36 +02:00
|
|
|
|
void Box::paint_border(PaintContext& context)
|
|
|
|
|
{
|
|
|
|
|
auto bordered_rect = this->bordered_rect();
|
2021-05-15 00:45:33 +02:00
|
|
|
|
auto border_rect = enclosing_int_rect(bordered_rect);
|
|
|
|
|
|
2021-05-16 00:15:37 +02:00
|
|
|
|
auto border_radius_data = normalized_border_radius_data();
|
|
|
|
|
auto top_left_radius = border_radius_data.top_left;
|
|
|
|
|
auto top_right_radius = border_radius_data.top_right;
|
|
|
|
|
auto bottom_right_radius = border_radius_data.bottom_right;
|
|
|
|
|
auto bottom_left_radius = border_radius_data.bottom_left;
|
2021-05-15 00:45:33 +02:00
|
|
|
|
|
2021-05-16 00:15:37 +02:00
|
|
|
|
// FIXME: Support elliptical border radii.
|
2021-05-15 00:45:33 +02:00
|
|
|
|
|
|
|
|
|
Gfx::FloatRect top_border_rect = {
|
|
|
|
|
border_rect.x() + top_left_radius,
|
|
|
|
|
border_rect.y(),
|
|
|
|
|
border_rect.width() - top_left_radius - top_right_radius,
|
|
|
|
|
border_rect.height()
|
|
|
|
|
};
|
|
|
|
|
Gfx::FloatRect right_border_rect = {
|
|
|
|
|
border_rect.x(),
|
|
|
|
|
border_rect.y() + top_right_radius,
|
|
|
|
|
border_rect.width(),
|
|
|
|
|
border_rect.height() - top_right_radius - bottom_right_radius
|
|
|
|
|
};
|
|
|
|
|
Gfx::FloatRect bottom_border_rect = {
|
|
|
|
|
border_rect.x() + bottom_left_radius,
|
|
|
|
|
border_rect.y(),
|
|
|
|
|
border_rect.width() - bottom_left_radius - bottom_right_radius,
|
|
|
|
|
border_rect.height()
|
|
|
|
|
};
|
|
|
|
|
Gfx::FloatRect left_border_rect = {
|
|
|
|
|
border_rect.x(),
|
|
|
|
|
border_rect.y() + top_left_radius,
|
|
|
|
|
border_rect.width(),
|
|
|
|
|
border_rect.height() - top_left_radius - bottom_left_radius
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Painting::paint_border(context, Painting::BorderEdge::Top, top_border_rect, computed_values());
|
|
|
|
|
Painting::paint_border(context, Painting::BorderEdge::Right, right_border_rect, computed_values());
|
|
|
|
|
Painting::paint_border(context, Painting::BorderEdge::Bottom, bottom_border_rect, computed_values());
|
|
|
|
|
Painting::paint_border(context, Painting::BorderEdge::Left, left_border_rect, computed_values());
|
|
|
|
|
|
|
|
|
|
// Draws a quarter cirle clockwise
|
|
|
|
|
auto draw_quarter_circle = [&](Gfx::IntPoint& from, Gfx::IntPoint& to, Gfx::Color color, int thickness) {
|
|
|
|
|
Gfx::IntPoint center = { 0, 0 };
|
|
|
|
|
Gfx::IntPoint offset = { 0, 0 };
|
|
|
|
|
Gfx::IntPoint circle_position = { 0, 0 };
|
|
|
|
|
|
|
|
|
|
auto radius = abs(from.x() - to.x());
|
|
|
|
|
|
|
|
|
|
if (from.x() < to.x() && from.y() > to.y()) {
|
|
|
|
|
// top-left
|
|
|
|
|
center.set_x(radius);
|
|
|
|
|
center.set_y(radius);
|
|
|
|
|
offset.set_y(1);
|
|
|
|
|
} else if (from.x() < to.x() && from.y() < to.y()) {
|
|
|
|
|
// top-right
|
|
|
|
|
circle_position.set_x(from.x());
|
|
|
|
|
center.set_y(radius);
|
|
|
|
|
offset.set_x(-1);
|
|
|
|
|
offset.set_y(1);
|
|
|
|
|
} else if (from.x() > to.x() && from.y() < to.y()) {
|
|
|
|
|
// bottom-right
|
|
|
|
|
circle_position.set_x(to.x());
|
|
|
|
|
circle_position.set_y(from.y());
|
|
|
|
|
offset.set_x(-1);
|
|
|
|
|
} else if (from.x() > to.x() && from.y() > to.y()) {
|
|
|
|
|
// bottom-left
|
|
|
|
|
circle_position.set_y(to.y());
|
|
|
|
|
center.set_x(radius);
|
|
|
|
|
} else {
|
|
|
|
|
// How did you get here?
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Gfx::IntRect circle_rect = {
|
|
|
|
|
border_rect.x() + circle_position.x(),
|
|
|
|
|
border_rect.y() + circle_position.y(),
|
|
|
|
|
radius,
|
|
|
|
|
radius
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
context.painter().draw_circle_arc_intersecting(
|
|
|
|
|
circle_rect,
|
|
|
|
|
center + offset,
|
|
|
|
|
radius,
|
|
|
|
|
color,
|
|
|
|
|
thickness);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// FIXME: Which color to use?
|
|
|
|
|
if (top_left_radius) {
|
|
|
|
|
Gfx::IntPoint arc_start = { 0, (int)top_left_radius };
|
|
|
|
|
Gfx::IntPoint arc_end = { (int)top_left_radius, 0 };
|
|
|
|
|
draw_quarter_circle(arc_start, arc_end, computed_values().border_top().color, computed_values().border_top().width);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (top_right_radius) {
|
|
|
|
|
Gfx::IntPoint arc_start = { (int)top_left_radius + (int)top_border_rect.width(), 0 };
|
|
|
|
|
Gfx::IntPoint arc_end = { (int)bordered_rect.width(), (int)top_right_radius };
|
|
|
|
|
draw_quarter_circle(arc_start, arc_end, computed_values().border_top().color, computed_values().border_top().width);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bottom_right_radius) {
|
|
|
|
|
Gfx::IntPoint arc_start = { (int)bordered_rect.width(), (int)top_right_radius + (int)right_border_rect.height() };
|
|
|
|
|
Gfx::IntPoint arc_end = { (int)bottom_border_rect.width() + (int)bottom_left_radius, (int)bordered_rect.height() };
|
|
|
|
|
draw_quarter_circle(arc_start, arc_end, computed_values().border_bottom().color, computed_values().border_bottom().width);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bottom_left_radius) {
|
|
|
|
|
Gfx::IntPoint arc_start = { (int)bottom_left_radius, (int)bordered_rect.height() };
|
|
|
|
|
Gfx::IntPoint arc_end = { 0, (int)bordered_rect.height() - (int)bottom_left_radius };
|
|
|
|
|
draw_quarter_circle(arc_start, arc_end, computed_values().border_bottom().color, computed_values().border_bottom().width);
|
|
|
|
|
}
|
2021-04-20 13:39:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-15 20:54:01 +02:00
|
|
|
|
void Box::paint_background(PaintContext& context)
|
|
|
|
|
{
|
|
|
|
|
auto padded_rect = this->padded_rect();
|
|
|
|
|
// If the body's background properties were propagated to the root element, do no re-paint the body's background.
|
|
|
|
|
if (is_body() && document().html_element()->should_use_body_background_properties())
|
|
|
|
|
return;
|
|
|
|
|
|
2021-05-16 20:03:04 +02:00
|
|
|
|
Gfx::IntRect background_rect;
|
2021-05-15 20:54:01 +02:00
|
|
|
|
Color background_color = computed_values().background_color();
|
|
|
|
|
const Gfx::Bitmap* background_image = this->background_image() ? this->background_image()->bitmap() : nullptr;
|
|
|
|
|
CSS::Repeat background_repeat_x = computed_values().background_repeat_x();
|
|
|
|
|
CSS::Repeat background_repeat_y = computed_values().background_repeat_y();
|
|
|
|
|
|
|
|
|
|
if (is_root_element()) {
|
|
|
|
|
// CSS 2.1 Appendix E.2: If the element is a root element, paint the background over the entire canvas.
|
|
|
|
|
background_rect = context.viewport_rect();
|
|
|
|
|
|
|
|
|
|
// Section 2.11.2: If the computed value of background-image on the root element is none and its background-color is transparent,
|
|
|
|
|
// user agents must instead propagate the computed values of the background properties from that element’s first HTML BODY child element.
|
|
|
|
|
if (document().html_element()->should_use_body_background_properties()) {
|
|
|
|
|
background_color = document().background_color(context.palette());
|
|
|
|
|
background_image = document().background_image();
|
|
|
|
|
background_repeat_x = document().background_repeat_x();
|
|
|
|
|
background_repeat_y = document().background_repeat_y();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
background_rect = enclosing_int_rect(padded_rect);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 20:03:04 +02:00
|
|
|
|
// HACK: If the Box has a border, use the bordered_rect to paint the background.
|
|
|
|
|
// This way if we have a border-radius there will be no gap between the filling and actual border.
|
|
|
|
|
if (computed_values().border_top().width || computed_values().border_right().width || computed_values().border_bottom().width || computed_values().border_left().width)
|
|
|
|
|
background_rect = enclosing_int_rect(bordered_rect());
|
|
|
|
|
|
2021-05-15 23:34:45 +02:00
|
|
|
|
// FIXME: some values should be relative to the height() if specified, but which? For now, all relative values are relative to the width.
|
2021-05-16 00:15:37 +02:00
|
|
|
|
auto border_radius_data = normalized_border_radius_data();
|
|
|
|
|
auto top_left_radius = border_radius_data.top_left;
|
|
|
|
|
auto top_right_radius = border_radius_data.top_right;
|
|
|
|
|
auto bottom_right_radius = border_radius_data.bottom_right;
|
|
|
|
|
auto bottom_left_radius = border_radius_data.bottom_left;
|
2021-05-15 23:34:45 +02:00
|
|
|
|
|
|
|
|
|
context.painter().fill_rect_with_rounded_corners(background_rect, move(background_color), top_left_radius, top_right_radius, bottom_right_radius, bottom_left_radius);
|
|
|
|
|
|
2021-05-15 20:54:01 +02:00
|
|
|
|
if (background_image)
|
|
|
|
|
paint_background_image(context, *background_image, background_repeat_x, background_repeat_y, move(background_rect));
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 18:04:38 -04:00
|
|
|
|
void Box::paint_background_image(
|
|
|
|
|
PaintContext& context,
|
|
|
|
|
const Gfx::Bitmap& background_image,
|
2021-04-05 12:05:35 -04:00
|
|
|
|
CSS::Repeat background_repeat_x,
|
|
|
|
|
CSS::Repeat background_repeat_y,
|
2021-04-04 18:04:38 -04:00
|
|
|
|
Gfx::IntRect background_rect)
|
|
|
|
|
{
|
2021-04-05 12:05:35 -04:00
|
|
|
|
switch (background_repeat_x) {
|
|
|
|
|
case CSS::Repeat::Round:
|
|
|
|
|
case CSS::Repeat::Space:
|
|
|
|
|
// FIXME: Support 'round' and 'space'. Fall through to 'repeat' since that most closely resembles these.
|
2021-04-04 18:04:38 -04:00
|
|
|
|
case CSS::Repeat::Repeat:
|
|
|
|
|
// The background rect is already sized to align with 'repeat'.
|
|
|
|
|
break;
|
2021-04-05 12:05:35 -04:00
|
|
|
|
case CSS::Repeat::NoRepeat:
|
2021-04-04 18:04:38 -04:00
|
|
|
|
background_rect.set_width(background_image.width());
|
|
|
|
|
break;
|
2021-04-05 12:05:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (background_repeat_y) {
|
|
|
|
|
case CSS::Repeat::Round:
|
|
|
|
|
case CSS::Repeat::Space:
|
|
|
|
|
// FIXME: Support 'round' and 'space'. Fall through to 'repeat' since that most closely resembles these.
|
|
|
|
|
case CSS::Repeat::Repeat:
|
|
|
|
|
// The background rect is already sized to align with 'repeat'.
|
|
|
|
|
break;
|
2021-04-04 18:04:38 -04:00
|
|
|
|
case CSS::Repeat::NoRepeat:
|
|
|
|
|
background_rect.set_height(background_image.height());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.painter().blit_tiled(background_rect, background_image, background_image.rect());
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 00:15:37 +02:00
|
|
|
|
Box::BorderRadiusData Box::normalized_border_radius_data()
|
|
|
|
|
{
|
|
|
|
|
// FIXME: some values should be relative to the height() if specified, but which? For now, all relative values are relative to the width.
|
|
|
|
|
auto bottom_left_radius = computed_values().border_bottom_left_radius().resolved_or_zero(*this, width()).to_px(*this);
|
|
|
|
|
auto bottom_right_radius = computed_values().border_bottom_right_radius().resolved_or_zero(*this, width()).to_px(*this);
|
|
|
|
|
auto top_left_radius = computed_values().border_top_left_radius().resolved_or_zero(*this, width()).to_px(*this);
|
|
|
|
|
auto top_right_radius = computed_values().border_top_right_radius().resolved_or_zero(*this, width()).to_px(*this);
|
|
|
|
|
|
|
|
|
|
// Scale overlapping curves according to https://www.w3.org/TR/css-backgrounds-3/#corner-overlap
|
|
|
|
|
auto f = 1.0f;
|
|
|
|
|
f = min(f, bordered_rect().width() / (float)(top_left_radius + top_right_radius));
|
|
|
|
|
f = min(f, bordered_rect().height() / (float)(top_right_radius + bottom_right_radius));
|
|
|
|
|
f = min(f, bordered_rect().width() / (float)(bottom_left_radius + bottom_right_radius));
|
|
|
|
|
f = min(f, bordered_rect().height() / (float)(top_left_radius + bottom_left_radius));
|
|
|
|
|
|
|
|
|
|
top_left_radius = (int)(top_left_radius * f);
|
|
|
|
|
top_right_radius = (int)(top_right_radius * f);
|
|
|
|
|
bottom_right_radius = (int)(bottom_right_radius * f);
|
|
|
|
|
bottom_left_radius = (int)(bottom_left_radius * f);
|
|
|
|
|
|
|
|
|
|
return { (int)top_left_radius, (int)top_right_radius, (int)bottom_right_radius, (int)bottom_left_radius };
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
HitTestResult Box::hit_test(const Gfx::IntPoint& position, HitTestType type) 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 };
|
2020-12-06 19:59:28 +01:00
|
|
|
|
for_each_child_in_paint_order([&](auto& child) {
|
2020-08-05 16:55:56 +02:00
|
|
|
|
auto child_result = child.hit_test(position, type);
|
2019-10-15 16:48:38 +02:00
|
|
|
|
if (child_result.layout_node)
|
|
|
|
|
result = child_result;
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
void Box::set_needs_display()
|
2019-10-15 16:48:38 +02:00
|
|
|
|
{
|
|
|
|
|
if (!is_inline()) {
|
2021-05-30 12:36:53 +02:00
|
|
|
|
browsing_context().set_needs_display(enclosing_int_rect(absolute_rect()));
|
2019-10-15 16:48:38 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
Node::set_needs_display();
|
2019-10-15 16:48:38 +02:00
|
|
|
|
}
|
2019-10-19 11:49:46 +02:00
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
bool Box::is_body() const
|
2019-10-19 11:49:46 +02:00
|
|
|
|
{
|
2020-11-22 14:46:36 +01:00
|
|
|
|
return dom_node() && dom_node() == document().body();
|
2019-10-19 11:49:46 +02:00
|
|
|
|
}
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
void Box::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-11-22 15:53:01 +01:00
|
|
|
|
void Box::set_size(const Gfx::FloatSize& size)
|
2020-06-10 10:42:29 +02:00
|
|
|
|
{
|
|
|
|
|
if (m_size == size)
|
|
|
|
|
return;
|
|
|
|
|
m_size = size;
|
|
|
|
|
did_set_rect();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
Gfx::FloatPoint Box::effective_offset() const
|
2020-06-10 10:42:29 +02:00
|
|
|
|
{
|
|
|
|
|
if (m_containing_line_box_fragment)
|
|
|
|
|
return m_containing_line_box_fragment->offset();
|
|
|
|
|
return m_offset;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
const Gfx::FloatRect Box::absolute_rect() const
|
2020-06-10 10:42:29 +02:00
|
|
|
|
{
|
|
|
|
|
Gfx::FloatRect rect { effective_offset(), size() };
|
|
|
|
|
for (auto* block = containing_block(); block; block = block->containing_block()) {
|
2021-04-12 11:47:09 -07:00
|
|
|
|
rect.translate_by(block->effective_offset());
|
2020-06-10 10:42:29 +02:00
|
|
|
|
}
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
void Box::set_containing_line_box_fragment(LineBoxFragment& fragment)
|
2020-06-10 10:42:29 +02:00
|
|
|
|
{
|
|
|
|
|
m_containing_line_box_fragment = fragment.make_weak_ptr();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
StackingContext* Box::enclosing_stacking_context()
|
2020-06-15 17:29:35 +02:00
|
|
|
|
{
|
|
|
|
|
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
2021-01-01 18:55:47 +01:00
|
|
|
|
if (!is<Box>(ancestor))
|
2020-06-15 17:29:35 +02:00
|
|
|
|
continue;
|
2021-06-24 19:53:42 +02:00
|
|
|
|
auto& ancestor_box = verify_cast<Box>(*ancestor);
|
2020-06-15 17:29:35 +02:00
|
|
|
|
if (!ancestor_box.establishes_stacking_context())
|
|
|
|
|
continue;
|
2021-02-23 20:42:32 +01:00
|
|
|
|
VERIFY(ancestor_box.stacking_context());
|
2020-06-15 17:29:35 +02:00
|
|
|
|
return ancestor_box.stacking_context();
|
|
|
|
|
}
|
2020-11-22 15:53:01 +01:00
|
|
|
|
// We should always reach the Layout::InitialContainingBlockBox stacking context.
|
2021-02-23 20:42:32 +01:00
|
|
|
|
VERIFY_NOT_REACHED();
|
2020-06-15 17:29:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
LineBox& Box::ensure_last_line_box()
|
2020-11-22 13:38:18 +01:00
|
|
|
|
{
|
|
|
|
|
if (m_line_boxes.is_empty())
|
|
|
|
|
return add_line_box();
|
|
|
|
|
return m_line_boxes.last();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
LineBox& Box::add_line_box()
|
2020-11-22 13:38:18 +01:00
|
|
|
|
{
|
|
|
|
|
m_line_boxes.append(LineBox());
|
|
|
|
|
return m_line_boxes.last();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
|
float Box::width_of_logical_containing_block() const
|
2020-11-22 13:38:18 +01:00
|
|
|
|
{
|
|
|
|
|
auto* containing_block = this->containing_block();
|
2021-02-23 20:42:32 +01:00
|
|
|
|
VERIFY(containing_block);
|
2020-11-22 13:38:18 +01:00
|
|
|
|
return containing_block->width();
|
|
|
|
|
}
|
2020-03-07 10:27:02 +01:00
|
|
|
|
}
|