ladybird/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp
Aliaksandr Kalenik de32b77ceb LibWeb: Use separate structure to represent fragments in paintable tree
This is a part of refactoring towards making the paintable tree
independent of the layout tree. Now, instead of transferring text
fragments from the layout tree to the paintable tree during the layout
commit phase, we allocate separate PaintableFragments that contain only
the information necessary for painting. Doing this also allows us to
get rid LineBoxes, as they are used only during layout.
2024-01-13 10:53:38 +01:00

49 lines
1.2 KiB
C++

/*
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Utf8View.h>
#include <LibWeb/DOM/Range.h>
#include <LibWeb/Layout/LayoutState.h>
#include <LibWeb/Layout/Viewport.h>
#include <ctype.h>
namespace Web::Layout {
bool LineBoxFragment::ends_in_whitespace() const
{
auto text = this->text();
if (text.is_empty())
return false;
return isspace(text[text.length() - 1]);
}
bool LineBoxFragment::is_justifiable_whitespace() const
{
return text() == " ";
}
StringView LineBoxFragment::text() const
{
if (!is<TextNode>(layout_node()))
return {};
return verify_cast<TextNode>(layout_node()).text_for_rendering().bytes_as_string_view().substring_view(m_start, m_length);
}
CSSPixelRect const LineBoxFragment::absolute_rect() const
{
CSSPixelRect rect { {}, size() };
rect.set_location(m_layout_node->containing_block()->paintable_box()->absolute_position());
rect.translate_by(offset());
return rect;
}
bool LineBoxFragment::is_atomic_inline() const
{
return layout_node().is_replaced_box() || (layout_node().display().is_inline_outside() && !layout_node().display().is_flow_inside());
}
}