From 9f8d776c70cb7eb15f6e5e2b4f1ca17bd55f5997 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 25 Sep 2019 12:30:13 +0300 Subject: [PATCH] LibHTML: Implement LayoutInline::layout() This currently uses a gross hack where it subtracts 11px from the previous sibling bottom to calculate its top. This should be fixed by switching to a proper two-phase line layouting model, were we first distribute inline elements into lines and figure out their horizontal positions and heights; then compute the needed line heights and position inline elements there vertically. --- Libraries/LibHTML/Layout/LayoutInline.cpp | 26 +++++++++++++++++++++++ Libraries/LibHTML/Layout/LayoutInline.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/Libraries/LibHTML/Layout/LayoutInline.cpp b/Libraries/LibHTML/Layout/LayoutInline.cpp index 69f7474c14..d8c1652dab 100644 --- a/Libraries/LibHTML/Layout/LayoutInline.cpp +++ b/Libraries/LibHTML/Layout/LayoutInline.cpp @@ -9,3 +9,29 @@ LayoutInline::LayoutInline(const Node& node, StyleProperties&& style_properties) LayoutInline::~LayoutInline() { } + +void LayoutInline::layout() +{ + Point origin; + + if (previous_sibling() != nullptr) { + auto& previous_sibling_rect = previous_sibling()->rect(); + auto& previous_sibling_style = previous_sibling()->style(); + origin = previous_sibling_rect.location(); + // FIXME: Implement proper inline positioning when + // there are nodes with different heights. And don't + // hardcode font size like we do here. + origin.move_by(previous_sibling_rect.width(), previous_sibling_rect.height()); + origin.move_by(previous_sibling_style.full_margin().right, -11); + } else { + origin = parent()->rect().location(); + } + + rect().set_location(origin); + + for_each_child([&](auto& child) { + child.layout(); + rect().set_right(child.rect().right() + child.style().full_margin().right); + rect().set_bottom(child.rect().bottom() + child.style().full_margin().bottom); + }); +} diff --git a/Libraries/LibHTML/Layout/LayoutInline.h b/Libraries/LibHTML/Layout/LayoutInline.h index 2760581098..424fe654de 100644 --- a/Libraries/LibHTML/Layout/LayoutInline.h +++ b/Libraries/LibHTML/Layout/LayoutInline.h @@ -12,5 +12,7 @@ public: virtual const char* class_name() const override { return "LayoutInline"; } virtual bool is_inline() const override { return true; } + virtual void layout() override; + private: };