1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +00:00

LibWeb: Rename LayoutNode classes and move them into Layout namespace

Bring the names of various boxes closer to spec language. This should
hopefully make things easier to understand and hack on. :^)

Some notable changes:

- LayoutNode -> Layout::Node
- LayoutBox -> Layout::Box
- LayoutBlock -> Layout::BlockBox
- LayoutReplaced -> Layout::ReplacedBox
- LayoutDocument -> Layout::InitialContainingBlockBox
- LayoutText -> Layout::TextNode
- LayoutInline -> Layout::InlineNode

Note that this is not strictly a "box tree" as we also hang inline/text
nodes in the same tree, and they don't generate boxes. (Instead, they
contribute line box fragments to their containing block!)
This commit is contained in:
Andreas Kling 2020-11-22 15:53:01 +01:00
parent f358f2255f
commit 5aeab9878e
114 changed files with 863 additions and 880 deletions

View file

@ -33,14 +33,14 @@
#include <LibWeb/HTML/HTMLIFrameElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/LayoutDocument.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/UIEvents/MouseEvent.h>
namespace Web {
static Gfx::IntPoint compute_mouse_event_offset(const Gfx::IntPoint& position, const LayoutNode& layout_node)
static Gfx::IntPoint compute_mouse_event_offset(const Gfx::IntPoint& position, const Layout::Node& layout_node)
{
auto top_left_of_layout_node = layout_node.box_type_agnostic_position();
return {
@ -58,14 +58,14 @@ EventHandler::~EventHandler()
{
}
const LayoutDocument* EventHandler::layout_root() const
const Layout::InitialContainingBlockBox* EventHandler::layout_root() const
{
if (!m_frame.document())
return nullptr;
return m_frame.document()->layout_node();
}
LayoutDocument* EventHandler::layout_root()
Layout::InitialContainingBlockBox* EventHandler::layout_root()
{
if (!m_frame.document())
return nullptr;
@ -84,15 +84,15 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
bool handled_event = false;
auto result = layout_root()->hit_test(position, HitTestType::Exact);
auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact);
if (result.layout_node && result.layout_node->wants_mouse_events()) {
result.layout_node->handle_mouseup({}, position, button, modifiers);
// Things may have changed as a consequence of LayoutNode::handle_mouseup(). Hit test again.
// Things may have changed as a consequence of Layout::Node::handle_mouseup(). Hit test again.
if (!layout_root())
return true;
result = layout_root()->hit_test(position, HitTestType::Exact);
result = layout_root()->hit_test(position, Layout::HitTestType::Exact);
}
if (result.layout_node && result.layout_node->dom_node()) {
@ -126,7 +126,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
NonnullRefPtr document = *m_frame.document();
auto result = layout_root()->hit_test(position, HitTestType::Exact);
auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact);
if (!result.layout_node)
return false;
@ -193,7 +193,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
}
} else {
if (button == GUI::MouseButton::Left) {
auto result = layout_root()->hit_test(position, HitTestType::TextCursor);
auto result = layout_root()->hit_test(position, Layout::HitTestType::TextCursor);
if (result.layout_node && result.layout_node->dom_node()) {
m_frame.set_cursor_position(DOM::Position(*node, result.index_in_node));
layout_root()->set_selection({ { result.layout_node, result.index_in_node }, {} });
@ -223,7 +223,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
bool hovered_node_changed = false;
bool is_hovering_link = false;
bool is_hovering_text = false;
auto result = layout_root()->hit_test(position, HitTestType::Exact);
auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact);
const HTML::HTMLAnchorElement* hovered_link_element = nullptr;
if (result.layout_node) {
@ -258,7 +258,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
return true;
}
if (m_in_mouse_selection) {
auto hit = layout_root()->hit_test(position, HitTestType::TextCursor);
auto hit = layout_root()->hit_test(position, Layout::HitTestType::TextCursor);
if (hit.layout_node && hit.layout_node->dom_node()) {
layout_root()->set_selection_end({ hit.layout_node, hit.index_in_node });
}
@ -368,7 +368,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
return false;
}
void EventHandler::set_mouse_event_tracking_layout_node(LayoutNode* layout_node)
void EventHandler::set_mouse_event_tracking_layout_node(Layout::Node* layout_node)
{
if (layout_node)
m_mouse_event_tracking_layout_node = layout_node->make_weak_ptr();

View file

@ -48,14 +48,14 @@ public:
bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
void set_mouse_event_tracking_layout_node(LayoutNode*);
void set_mouse_event_tracking_layout_node(Layout::Node*);
private:
bool focus_next_element();
bool focus_previous_element();
LayoutDocument* layout_root();
const LayoutDocument* layout_root() const;
Layout::InitialContainingBlockBox* layout_root();
const Layout::InitialContainingBlockBox* layout_root() const;
void dump_selection(const char* event_name) const;
@ -63,7 +63,7 @@ private:
bool m_in_mouse_selection { false };
WeakPtr<LayoutNode> m_mouse_event_tracking_layout_node;
WeakPtr<Layout::Node> m_mouse_event_tracking_layout_node;
};
}

View file

@ -27,10 +27,10 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/LayoutBreak.h>
#include <LibWeb/Layout/LayoutDocument.h>
#include <LibWeb/Layout/LayoutText.h>
#include <LibWeb/Layout/LayoutWidget.h>
#include <LibWeb/Layout/BreakNode.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/WidgetBox.h>
#include <LibWeb/Page/Frame.h>
namespace Web {
@ -137,7 +137,7 @@ void Frame::did_scroll(Badge<InProcessWebView>)
return;
if (!m_document->layout_node())
return;
m_document->layout_node()->for_each_in_subtree_of_type<LayoutWidget>([&](auto& layout_widget) {
m_document->layout_node()->for_each_in_subtree_of_type<Layout::WidgetBox>([&](auto& layout_widget) {
layout_widget.update_widget();
return IterationDecision::Continue;
});
@ -165,8 +165,8 @@ void Frame::scroll_to_anchor(const String& fragment)
auto& layout_node = *element->layout_node();
Gfx::FloatRect float_rect { layout_node.box_type_agnostic_position(), { (float)viewport_rect().width(), (float)viewport_rect().height() } };
if (is<LayoutBox>(layout_node)) {
auto& layout_box = downcast<LayoutBox>(layout_node);
if (is<Layout::Box>(layout_node)) {
auto& layout_box = downcast<Layout::Box>(layout_node);
auto padding_box = layout_box.box_model().padding_box(layout_box);
float_rect.move_by(-padding_box.left, -padding_box.top);
}
@ -227,24 +227,24 @@ String Frame::selected_text() const
auto selection = layout_root->selection().normalized();
if (selection.start().layout_node == selection.end().layout_node) {
if (!is<LayoutText>(*selection.start().layout_node))
if (!is<Layout::TextNode>(*selection.start().layout_node))
return "";
return downcast<LayoutText>(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node);
return downcast<Layout::TextNode>(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node);
}
// Start node
auto layout_node = selection.start().layout_node;
if (is<LayoutText>(*layout_node)) {
auto& text = downcast<LayoutText>(*layout_node).text_for_rendering();
if (is<Layout::TextNode>(*layout_node)) {
auto& text = downcast<Layout::TextNode>(*layout_node).text_for_rendering();
builder.append(text.substring(selection.start().index_in_node, text.length() - selection.start().index_in_node));
}
// Middle nodes
layout_node = layout_node->next_in_pre_order();
while (layout_node && layout_node != selection.end().layout_node) {
if (is<LayoutText>(*layout_node))
builder.append(downcast<LayoutText>(*layout_node).text_for_rendering());
else if (is<LayoutBreak>(*layout_node) || is<LayoutBlock>(*layout_node))
if (is<Layout::TextNode>(*layout_node))
builder.append(downcast<Layout::TextNode>(*layout_node).text_for_rendering());
else if (is<Layout::BreakNode>(*layout_node) || is<Layout::BlockBox>(*layout_node))
builder.append('\n');
layout_node = layout_node->next_in_pre_order();
@ -252,8 +252,8 @@ String Frame::selected_text() const
// End node
ASSERT(layout_node == selection.end().layout_node);
if (is<LayoutText>(*layout_node)) {
auto& text = downcast<LayoutText>(*layout_node).text_for_rendering();
if (is<Layout::TextNode>(*layout_node)) {
auto& text = downcast<Layout::TextNode>(*layout_node).text_for_rendering();
builder.append(text.substring(0, selection.end().index_in_node));
}