2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/DOM/Element.h>
|
2020-11-22 11:53:01 -03:00
|
|
|
#include <LibWeb/Layout/BlockBox.h>
|
2020-12-05 19:41:07 -03:00
|
|
|
#include <LibWeb/Layout/InlineFormattingContext.h>
|
2020-11-22 11:53:01 -03:00
|
|
|
#include <LibWeb/Layout/ReplacedBox.h>
|
2019-10-05 17:07:45 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
namespace Web::Layout {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
ReplacedBox::ReplacedBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
|
|
|
|
|
: Box(document, &element, move(style))
|
2019-10-05 17:07:45 -03:00
|
|
|
{
|
|
|
|
|
// FIXME: Allow non-inline replaced elements.
|
|
|
|
|
set_inline(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
ReplacedBox::~ReplacedBox()
|
2019-10-05 17:07:45 -03:00
|
|
|
{
|
|
|
|
|
}
|
2019-10-05 18:20:35 -03:00
|
|
|
|
2020-12-15 14:40:08 -03:00
|
|
|
void ReplacedBox::split_into_lines(InlineFormattingContext& context, LayoutMode layout_mode)
|
2020-06-05 14:13:27 -03:00
|
|
|
{
|
2020-12-06 15:48:02 -03:00
|
|
|
auto& containing_block = context.containing_block();
|
2020-12-05 16:10:39 -03:00
|
|
|
|
2020-11-22 09:38:18 -03:00
|
|
|
prepare_for_replaced_layout();
|
2020-12-15 14:40:08 -03:00
|
|
|
context.dimension_box_on_line(*this, layout_mode);
|
2019-10-05 18:20:35 -03:00
|
|
|
|
2020-12-05 16:10:39 -03:00
|
|
|
auto* line_box = &containing_block.ensure_last_line_box();
|
2020-12-15 14:40:08 -03:00
|
|
|
if (line_box->width() > 0 && line_box->width() + width() > context.available_width_at_line(containing_block.line_boxes().size() - 1))
|
2020-12-05 16:10:39 -03:00
|
|
|
line_box = &containing_block.add_line_box();
|
2020-12-15 14:40:08 -03:00
|
|
|
line_box->add_fragment(*this, 0, 0, width(), height());
|
2019-10-05 18:20:35 -03:00
|
|
|
}
|
2020-03-07 06:27:02 -03:00
|
|
|
|
|
|
|
|
}
|