From 226fe4b57d9d832b9673c47778ed3b8cf8536327 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 19 Aug 2021 12:20:43 +0100 Subject: [PATCH] LibWeb: Paint inspection outline for InlineNodes :^) This iterates the fragments of the containing block, and paints their outlines if they are descendants of the InlineNode. If multiple fragments are adjacent, eg: ```html Well hello friends! ``` ...then we get a double-thick outline between "Well", " hello " and "friends!", but we can come back to this after we implement non-rectangular outlines for the `outline` CSS property. --- Userland/Libraries/LibWeb/Layout/InlineNode.cpp | 17 +++++++++++++++++ Userland/Libraries/LibWeb/Layout/InlineNode.h | 1 + 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibWeb/Layout/InlineNode.cpp b/Userland/Libraries/LibWeb/Layout/InlineNode.cpp index 592186fc80..0ef7b62d85 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineNode.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -48,4 +49,20 @@ void InlineNode::paint_fragment(PaintContext& context, const LineBoxFragment& fr } } +void InlineNode::paint(PaintContext& context, PaintPhase phase) +{ + auto& painter = context.painter(); + + if (phase == PaintPhase::Foreground && document().inspected_node() == dom_node()) { + // FIXME: This paints a double-thick border between adjacent fragments, where ideally there + // would be none. Once we implement non-rectangular outlines for the `outline` CSS + // property, we can use that here instead. + containing_block()->for_each_fragment([&](auto& fragment) { + if (is_inclusive_ancestor_of(fragment.layout_node())) + painter.draw_rect(enclosing_int_rect(fragment.absolute_rect()), Color::Magenta); + return IterationDecision::Continue; + }); + } +} + } diff --git a/Userland/Libraries/LibWeb/Layout/InlineNode.h b/Userland/Libraries/LibWeb/Layout/InlineNode.h index 258c52d768..5f6d4d4597 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineNode.h +++ b/Userland/Libraries/LibWeb/Layout/InlineNode.h @@ -15,6 +15,7 @@ public: InlineNode(DOM::Document&, DOM::Element&, NonnullRefPtr); virtual ~InlineNode() override; + virtual void paint(PaintContext&, PaintPhase) override; virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override; virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override;