mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:08:11 +00:00

The "paintable" state in Layout::Box was actually not safe to access until after layout had been performed. As a first step towards making this harder to mess up accidentally, this patch moves painting information from Layout::Box to a new class: Painting::Box. Every layout can have a corresponding paint box, and it holds the final used metrics determined by layout. The paint box is created and populated by FormattingState::commit(). I've also added DOM::Node::paint_box() as a convenient way to access the paint box (if available) of a given DOM node. Going forward, I believe this will allow us to better separate data that belongs to layout vs painting, and also open up opportunities for naturally invalidating caches in the paint box (since it's reconstituted by every layout.)
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/OwnPtr.h>
|
|
#include <LibGfx/Rect.h>
|
|
#include <LibWeb/Layout/Node.h>
|
|
#include <LibWeb/Painting/BorderPainting.h>
|
|
#include <LibWeb/Painting/StackingContext.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
struct LineBoxFragmentCoordinate {
|
|
size_t line_box_index { 0 };
|
|
size_t fragment_index { 0 };
|
|
};
|
|
|
|
class Box : public NodeWithStyleAndBoxModelMetrics {
|
|
public:
|
|
OwnPtr<Painting::Box> m_paint_box;
|
|
|
|
bool is_out_of_flow(FormattingContext const&) const;
|
|
|
|
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
|
|
virtual void set_needs_display() override;
|
|
|
|
bool is_body() const;
|
|
|
|
StackingContext* stacking_context() { return m_stacking_context; }
|
|
const StackingContext* stacking_context() const { return m_stacking_context; }
|
|
void set_stacking_context(NonnullOwnPtr<StackingContext> context) { m_stacking_context = move(context); }
|
|
StackingContext* enclosing_stacking_context();
|
|
|
|
virtual void paint(PaintContext&, PaintPhase) override;
|
|
virtual void paint_border(PaintContext& context);
|
|
virtual void paint_box_shadow(PaintContext& context);
|
|
virtual void paint_background(PaintContext& context);
|
|
|
|
Painting::BorderRadiusData normalized_border_radius_data();
|
|
|
|
virtual Optional<float> intrinsic_width() const { return {}; }
|
|
virtual Optional<float> intrinsic_height() const { return {}; }
|
|
virtual Optional<float> intrinsic_aspect_ratio() const { return {}; }
|
|
|
|
bool has_intrinsic_width() const { return intrinsic_width().has_value(); }
|
|
bool has_intrinsic_height() const { return intrinsic_height().has_value(); }
|
|
bool has_intrinsic_aspect_ratio() const { return intrinsic_aspect_ratio().has_value(); }
|
|
|
|
virtual void before_children_paint(PaintContext&, PaintPhase) override;
|
|
virtual void after_children_paint(PaintContext&, PaintPhase) override;
|
|
|
|
virtual ~Box() override;
|
|
|
|
virtual void did_set_rect() { }
|
|
|
|
protected:
|
|
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
|
|
Box(DOM::Document&, DOM::Node*, CSS::ComputedValues);
|
|
|
|
private:
|
|
virtual bool is_box() const final { return true; }
|
|
|
|
OwnPtr<StackingContext> m_stacking_context;
|
|
};
|
|
|
|
template<>
|
|
inline bool Node::fast_is<Box>() const { return is_box(); }
|
|
|
|
}
|