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
|
|
|
*/
|
|
|
|
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/DOM/Element.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/BlockBox.h>
|
2020-12-05 23:41:07 +01:00
|
|
|
#include <LibWeb/Layout/InlineFormattingContext.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/ReplacedBox.h>
|
2019-10-05 22:07:45 +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
|
|
|
ReplacedBox::ReplacedBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
|
|
|
|
: Box(document, &element, move(style))
|
2019-10-05 22:07:45 +02:00
|
|
|
{
|
|
|
|
// FIXME: Allow non-inline replaced elements.
|
|
|
|
set_inline(true);
|
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
ReplacedBox::~ReplacedBox()
|
2019-10-05 22:07:45 +02:00
|
|
|
{
|
|
|
|
}
|
2019-10-05 23:20:35 +02:00
|
|
|
|
2020-12-15 18:40:08 +01:00
|
|
|
void ReplacedBox::split_into_lines(InlineFormattingContext& context, LayoutMode layout_mode)
|
2020-06-05 19:13:27 +02:00
|
|
|
{
|
2020-12-06 19:48:02 +01:00
|
|
|
auto& containing_block = context.containing_block();
|
2020-12-05 20:10:39 +01:00
|
|
|
|
2020-11-22 13:38:18 +01:00
|
|
|
prepare_for_replaced_layout();
|
2020-12-15 18:40:08 +01:00
|
|
|
context.dimension_box_on_line(*this, layout_mode);
|
2019-10-05 23:20:35 +02:00
|
|
|
|
2020-12-05 20:10:39 +01:00
|
|
|
auto* line_box = &containing_block.ensure_last_line_box();
|
2020-12-15 18:40:08 +01:00
|
|
|
if (line_box->width() > 0 && line_box->width() + width() > context.available_width_at_line(containing_block.line_boxes().size() - 1))
|
2020-12-05 20:10:39 +01:00
|
|
|
line_box = &containing_block.add_line_box();
|
2020-12-15 18:40:08 +01:00
|
|
|
line_box->add_fragment(*this, 0, 0, width(), height());
|
2019-10-05 23:20:35 +02:00
|
|
|
}
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|