ladybird/Userland/Libraries/LibWeb/Painting/ViewportPaintable.h
Aliaksandr Kalenik 6a549f6270 LibWeb: Replace InlinePaintable with PaintableWithLines created per line
InlinePaintable was an ad-hoc paintable type required to support the
fragmentation of inline nodes across multiple lines. It existed because
there was no way to associate multiple paintables with a single layout
node. This resulted in a lot of duplicated code between PaintableBox and
InlinePaintable. For example, most of the CSS properties like
background, border, shadows, etc. and hit-testing are almost identical
for both of them. However, the code had to be duplicated to account for
the fact that InlinePaintable creates a box for each line. And we had
quite many places that operate on paintables with a code like:
```
if (box.is_paintable_box()) {
  // do something
} else (box.is_inline_paintable()) {
  // do exactly the same as for paintable box but using InlinePaintable
}
```

This change replaces the usage of `InlinePaintable` with
`PaintableWithLines` created for each line, which is now possible
because we support having multiple paintables per layout node. By doing
that, we remove lots of duplicated code and bring our implementation
closer to the spec.
2024-10-16 20:25:42 +02:00

55 lines
1.6 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/ScrollState.h>
namespace Web::Painting {
class ViewportPaintable final : public PaintableWithLines {
JS_CELL(ViewportPaintable, PaintableWithLines);
JS_DECLARE_ALLOCATOR(ViewportPaintable);
public:
static JS::NonnullGCPtr<ViewportPaintable> create(Layout::Viewport const&);
virtual ~ViewportPaintable() override;
void paint_all_phases(PaintContext&);
void build_stacking_context_tree_if_needed();
void assign_scroll_frames();
void refresh_scroll_state();
HashMap<JS::GCPtr<PaintableBox const>, RefPtr<ClipFrame>> clip_state;
void assign_clip_frames();
void resolve_paint_only_properties();
JS::GCPtr<Selection::Selection> selection() const;
void recompute_selection_states(DOM::Range&);
void update_selection();
bool handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) override;
void set_needs_to_refresh_scroll_state(bool value) { m_needs_to_refresh_scroll_state = value; }
ScrollState const& scroll_state() const { return m_scroll_state; }
private:
void build_stacking_context_tree();
explicit ViewportPaintable(Layout::Viewport const&);
virtual void visit_edges(Visitor&) override;
ScrollState m_scroll_state;
bool m_needs_to_refresh_scroll_state { true };
};
}