Move the layout tree from GC allocation to refcounted ownership so removed layout and paint subtrees are destroyed synchronously instead of waiting for the next GC sweep. This dramatically reduces GC memory usage peaks after layout tree churn and makes it easier for memory use to fall back after large document updates. Update layout factories, tree traversal, SVG layout node creation, paintable back-pointers, and pseudo-element layout links to use RefPtr ownership. Make display: contents follow the same shape as Blink and WebKit: the element itself does not create a layout node, and its children are flattened into the nearest layout parent. Wrap direct non-whitespace text in an anonymous inline node when the boxless element contributes inherited style to that text. Use an internal inline wrapper for display: contents pseudo-elements so generated content can still participate in layout, painting, hit testing, and pseudo-element queries. Keep CSSOM reporting the computed display value from the pseudo style, not the internal wrapper. Remove the retained out-of-tree layout node list and its testing hook, since the flattened model does not need a side owner for boxless elements. Add coverage for inherited text style, dynamic insertion order, pseudo-element hit testing, and computed style queries.
87 lines
3 KiB
C++
87 lines
3 KiB
C++
/*
|
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/OwnPtr.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
#include <LibWeb/CSS/Sizing.h>
|
|
#include <LibWeb/Export.h>
|
|
#include <LibWeb/Layout/Node.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
struct LineBoxFragmentCoordinate {
|
|
size_t line_box_index { 0 };
|
|
size_t fragment_index { 0 };
|
|
};
|
|
|
|
struct IntrinsicSizes {
|
|
Optional<CSSPixels> min_content_width;
|
|
Optional<CSSPixels> max_content_width;
|
|
HashMap<CSSPixels, Optional<CSSPixels>> min_content_height;
|
|
HashMap<CSSPixels, Optional<CSSPixels>> max_content_height;
|
|
};
|
|
|
|
class WEB_API Box : public NodeWithStyleAndBoxModelMetrics {
|
|
GC_CELL(Box, NodeWithStyleAndBoxModelMetrics);
|
|
GC_DECLARE_ALLOCATOR(Box);
|
|
|
|
public:
|
|
RefPtr<Painting::PaintableBox const> paintable_box() const;
|
|
RefPtr<Painting::PaintableBox> paintable_box();
|
|
|
|
// https://www.w3.org/TR/css-images-3/#natural-dimensions
|
|
virtual CSS::SizeWithAspectRatio natural_size() const { return {}; }
|
|
|
|
// When computed width/height is auto, auto_content_box_size gives the fallback content-box size for
|
|
// elements whose used size is determined by natural dimensions, attributes, or defaults other than
|
|
// the generic UA fallback (300x150). Any returned aspect ratio comes from natural dimensions (when
|
|
// available) or may be computed from fallback sizing. Don't confuse this with the CSS preferred
|
|
// aspect ratio.
|
|
CSS::SizeWithAspectRatio auto_content_box_size() const;
|
|
virtual bool has_auto_content_box_size() const { return false; }
|
|
|
|
// https://www.w3.org/TR/css-sizing-4/#preferred-aspect-ratio
|
|
Optional<CSSPixelFraction> preferred_aspect_ratio() const;
|
|
bool has_preferred_aspect_ratio() const { return preferred_aspect_ratio().has_value(); }
|
|
|
|
virtual ~Box() override;
|
|
|
|
virtual void did_set_content_size() { }
|
|
|
|
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
|
|
|
void add_contained_abspos_child(Node& child) { m_contained_abspos_children.append(child.make_weak_ptr()); }
|
|
void clear_contained_abspos_children() { m_contained_abspos_children.clear(); }
|
|
Vector<WeakPtr<Node>> const& contained_abspos_children() const { return m_contained_abspos_children; }
|
|
|
|
IntrinsicSizes& cached_intrinsic_sizes() const
|
|
{
|
|
if (!m_cached_intrinsic_sizes)
|
|
m_cached_intrinsic_sizes = make<IntrinsicSizes>();
|
|
return *m_cached_intrinsic_sizes;
|
|
}
|
|
void reset_cached_intrinsic_sizes() const { m_cached_intrinsic_sizes.clear(); }
|
|
|
|
Box(DOM::Document&, DOM::Node*, CSS::ComputedProperties const&);
|
|
Box(DOM::Document&, DOM::Node*, NonnullOwnPtr<CSS::ComputedValues>);
|
|
|
|
protected:
|
|
virtual CSS::SizeWithAspectRatio compute_auto_content_box_size() const { return natural_size(); }
|
|
|
|
private:
|
|
virtual bool is_box() const final { return true; }
|
|
|
|
Vector<WeakPtr<Node>> m_contained_abspos_children;
|
|
|
|
OwnPtr<IntrinsicSizes> mutable m_cached_intrinsic_sizes;
|
|
};
|
|
|
|
template<>
|
|
inline bool Node::fast_is<Box>() const { return is_box(); }
|
|
|
|
}
|