ladybird/Libraries/LibHTML/Layout/LayoutText.h
Andreas Kling 13860e4dd8 LibHTML: Make hit testing work for LayoutText
LayoutText can't simply rely on its LayoutNode::rect() for hit testing.
Instead, we have to iterate over the individual runs and see if we're
hitting any of them.

Also, LayoutNode::hit_test() now always recurses into children, since
we can't trust the rect() to tell the truth (inline rects are wrong.)
2019-09-29 11:32:00 +02:00

40 lines
941 B
C++

#pragma once
#include <LibHTML/DOM/Text.h>
#include <LibHTML/Layout/LayoutNode.h>
class Font;
class LayoutText : public LayoutNode {
public:
LayoutText(const Text&, StyleProperties&&);
virtual ~LayoutText() override;
const Text& node() const { return static_cast<const Text&>(*LayoutNode::node()); }
const String& text() const;
virtual const char* class_name() const override { return "LayoutText"; }
virtual bool is_text() const final { return true; }
virtual void layout() override;
virtual void render(RenderingContext&) override;
struct Run {
Point pos;
String text;
};
const Vector<Run>& runs() const { return m_runs; }
virtual HitTestResult hit_test(const Point&) const override;
private:
template<typename Callback>
void for_each_run(Callback) const;
void load_font();
void compute_runs();
Vector<Run> m_runs;
RefPtr<Font> m_font;
};