We now apply first letter styles by splitting text with a first-letter style applied into 2 `TextSliceNode` objects. The `DOM::Text` layout node always points at the non first-letter slice and the first-letter slice is reachable via `TextSliceNode::first_letter_slice()`. First letter splitting works by `TreeBuilder` walking a block container's inline descendants to find the first typographic letter unit per the pattern given in css-pseudo level 4, which is then wrapped in an anonymous inline box styled with the `::first-letter` computed properties. Consumers that map between DOM offsets and layout geometry are updated to visit all slices of a `DOM::Text` through `TextOffsetMapping`.
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Utf16String.h>
|
|
#include <LibWeb/Layout/BlockContainer.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
class Viewport final : public BlockContainer {
|
|
GC_CELL(Viewport, BlockContainer);
|
|
GC_DECLARE_ALLOCATOR(Viewport);
|
|
|
|
public:
|
|
explicit Viewport(DOM::Document&, GC::Ref<CSS::ComputedProperties>);
|
|
virtual ~Viewport() override;
|
|
|
|
struct TextPosition {
|
|
GC::Ref<DOM::Text> dom_node;
|
|
size_t start_offset { 0 };
|
|
size_t dom_offset_within_node { 0 };
|
|
};
|
|
struct TextBlock {
|
|
Utf16String text;
|
|
Vector<TextPosition> positions;
|
|
};
|
|
Vector<TextBlock> const& text_blocks();
|
|
void invalidate_text_blocks_cache() { m_text_blocks.clear(); }
|
|
|
|
DOM::Document const& dom_node() const;
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
private:
|
|
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
|
|
|
void update_text_blocks();
|
|
|
|
virtual bool is_viewport() const override { return true; }
|
|
|
|
Optional<Vector<TextBlock>> m_text_blocks;
|
|
};
|
|
|
|
template<>
|
|
inline bool Node::fast_is<Viewport>() const { return is_viewport(); }
|
|
|
|
}
|