forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Create list-item markers during layout tree construction
Previously, these were added during layout. This didn't fit into the new world where layout doesn't mutate the tree incrementally, so this patch adds logic to Layout::TreeBuilder for adding a marker to each list-item box after its children have been constructed.
- Loading branch information
1 parent
c9700e1
commit 92266d2
Showing
8 changed files
with
65 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2020-2022, Andreas Kling <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
@@ -58,6 +58,8 @@ class BlockFormattingContext : public FormattingContext { | |
|
||
void apply_transformations_to_children(Box const&); | ||
|
||
void layout_list_item_marker(ListItemBox const&); | ||
|
||
enum class FloatSide { | ||
Left, | ||
Right, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2018-2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2018-2022, Andreas Kling <[email protected]> | ||
* Copyright (c) 2021, Tobias Christiansen <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
|
@@ -19,30 +19,9 @@ ListItemBox::~ListItemBox() | |
{ | ||
} | ||
|
||
void ListItemBox::layout_marker() | ||
void ListItemBox::set_marker(RefPtr<ListItemMarkerBox> marker) | ||
{ | ||
if (m_marker) { | ||
remove_child(*m_marker); | ||
m_marker = nullptr; | ||
} | ||
|
||
if (computed_values().list_style_type() == CSS::ListStyleType::None) | ||
return; | ||
|
||
if (!m_marker) { | ||
auto* marker_style = dom_node().specified_css_values(); | ||
VERIFY(marker_style); | ||
int child_index = parent()->index_of_child<ListItemBox>(*this).value(); | ||
m_marker = adopt_ref(*new ListItemMarkerBox(document(), computed_values().list_style_type(), child_index + 1, *marker_style)); | ||
if (first_child()) | ||
m_marker->set_inline(first_child()->is_inline()); | ||
append_child(*m_marker); | ||
} | ||
|
||
m_marker->set_offset(-(m_marker->content_width() + 4), 0); | ||
|
||
if (m_marker->content_height() > content_height()) | ||
set_content_height(m_marker->content_height()); | ||
m_marker = move(marker); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2018-2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2018-2022, Andreas Kling <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
@@ -11,18 +11,17 @@ | |
|
||
namespace Web::Layout { | ||
|
||
class ListItemMarkerBox; | ||
|
||
class ListItemBox final : public BlockContainer { | ||
public: | ||
ListItemBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); | ||
virtual ~ListItemBox() override; | ||
|
||
void layout_marker(); | ||
|
||
DOM::Element& dom_node() { return static_cast<DOM::Element&>(*BlockContainer::dom_node()); } | ||
DOM::Element const& dom_node() const { return static_cast<DOM::Element const&>(*BlockContainer::dom_node()); } | ||
|
||
ListItemMarkerBox const* marker() const { return m_marker; } | ||
void set_marker(RefPtr<ListItemMarkerBox>); | ||
|
||
private: | ||
RefPtr<ListItemMarkerBox> m_marker; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2018-2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2018-2022, Andreas Kling <[email protected]> | ||
* Copyright (c) 2021, Tobias Christiansen <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
|
@@ -48,22 +48,6 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType | |
default: | ||
VERIFY_NOT_REACHED(); | ||
} | ||
|
||
int image_width = 0; | ||
int image_height = 0; | ||
if (auto const* list_style_image = list_style_image_bitmap()) { | ||
image_width = list_style_image->rect().width(); | ||
image_height = list_style_image->rect().height(); | ||
} | ||
|
||
if (m_text.is_null()) { | ||
set_content_width(image_width + 4); | ||
} else { | ||
auto text_width = font().width(m_text); | ||
set_content_width(image_width + text_width); | ||
} | ||
|
||
set_content_height(max(image_height, line_height())); | ||
} | ||
|
||
ListItemMarkerBox::~ListItemMarkerBox() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2018-2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2018-2022, Andreas Kling <[email protected]> | ||
* Copyright (c) 2021, Tobias Christiansen <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
|
@@ -18,9 +18,11 @@ class ListItemMarkerBox final : public Box { | |
|
||
virtual void paint(PaintContext&, PaintPhase) override; | ||
|
||
Gfx::Bitmap const* list_style_image_bitmap() const; | ||
String const& text() const { return m_text; } | ||
|
||
private: | ||
virtual bool can_have_children() const override { return false; } | ||
Gfx::Bitmap const* list_style_image_bitmap() const; | ||
|
||
CSS::ListStyleType m_list_style_type { CSS::ListStyleType::None }; | ||
size_t m_index; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2018-2021, Andreas Kling <[email protected]> | ||
* Copyright (c) 2018-2022, Andreas Kling <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
@@ -12,6 +12,8 @@ | |
#include <LibWeb/DOM/ShadowRoot.h> | ||
#include <LibWeb/Dump.h> | ||
#include <LibWeb/Layout/InitialContainingBlock.h> | ||
#include <LibWeb/Layout/ListItemBox.h> | ||
#include <LibWeb/Layout/ListItemMarkerBox.h> | ||
#include <LibWeb/Layout/Node.h> | ||
#include <LibWeb/Layout/TableBox.h> | ||
#include <LibWeb/Layout/TableCellBox.h> | ||
|
@@ -147,6 +149,16 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& | |
}); | ||
pop_parent(); | ||
} | ||
|
||
if (is<ListItemBox>(*layout_node)) { | ||
int child_index = layout_node->parent()->index_of_child<ListItemBox>(*layout_node).value(); | ||
auto marker_style = static_cast<DOM::Element const&>(dom_node).specified_css_values(); | ||
auto list_item_marker = adopt_ref(*new ListItemMarkerBox(document, layout_node->computed_values().list_style_type(), child_index + 1, *marker_style)); | ||
if (layout_node->first_child()) | ||
list_item_marker->set_inline(layout_node->first_child()->is_inline()); | ||
static_cast<ListItemBox&>(*layout_node).set_marker(list_item_marker); | ||
layout_node->append_child(move(list_item_marker)); | ||
} | ||
} | ||
|
||
RefPtr<Node> TreeBuilder::build(DOM::Node& dom_node) | ||
|