#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/layout/inline/inline_node.h"
#include <memory>
#include <numeric>
#include "base/containers/adapters.h"
#include "base/debug/dump_without_crashing.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/trace_event/trace_event.h"
#include "third_party/blink/renderer/core/dom/text_diff_range.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/layout/block_break_token.h"
#include "third_party/blink/renderer/core/layout/constraint_space.h"
#include "third_party/blink/renderer/core/layout/constraint_space_builder.h"
#include "third_party/blink/renderer/core/layout/inline/initial_letter_utils.h"
#include "third_party/blink/renderer/core/layout/inline/inline_break_token.h"
#include "third_party/blink/renderer/core/layout/inline/inline_item.h"
#include "third_party/blink/renderer/core/layout/inline/inline_item_result_ruby_column.h"
#include "third_party/blink/renderer/core/layout/inline/inline_items_builder.h"
#include "third_party/blink/renderer/core/layout/inline/inline_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/inline/inline_text_auto_space.h"
#include "third_party/blink/renderer/core/layout/inline/line_breaker.h"
#include "third_party/blink/renderer/core/layout/inline/line_info.h"
#include "third_party/blink/renderer/core/layout/inline/offset_mapping.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/layout_counter.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_object_inlines.h"
#include "third_party/blink/renderer/core/layout/layout_result.h"
#include "third_party/blink/renderer/core/layout/layout_text.h"
#include "third_party/blink/renderer/core/layout/layout_text_combine.h"
#include "third_party/blink/renderer/core/layout/legacy_layout_tree_walking.h"
#include "third_party/blink/renderer/core/layout/length_utils.h"
#include "third_party/blink/renderer/core/layout/list/layout_inline_list_item.h"
#include "third_party/blink/renderer/core/layout/list/layout_list_item.h"
#include "third_party/blink/renderer/core/layout/list/list_marker.h"
#include "third_party/blink/renderer/core/layout/positioned_float.h"
#include "third_party/blink/renderer/core/layout/space_utils.h"
#include "third_party/blink/renderer/core/layout/svg/layout_svg_inline_text.h"
#include "third_party/blink/renderer/core/layout/svg/svg_inline_node_data.h"
#include "third_party/blink/renderer/core/layout/svg/svg_text_layout_attributes_builder.h"
#include "third_party/blink/renderer/core/layout/unpositioned_float.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/computed_style_base_constants.h"
#include "third_party/blink/renderer/platform/fonts/font_performance.h"
#include "third_party/blink/renderer/platform/fonts/shaping/harfbuzz_shaper.h"
#include "third_party/blink/renderer/platform/fonts/shaping/ng_shape_cache.h"
#include "third_party/blink/renderer/platform/fonts/shaping/run_segmenter.h"
#include "third_party/blink/renderer/platform/fonts/shaping/shape_result_spacing.h"
#include "third_party/blink/renderer/platform/fonts/shaping/shape_result_view.h"
#include "third_party/blink/renderer/platform/heap/collection_support/clear_collection_scope.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/text/bidi_paragraph.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/string_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/text_offset_map.h"
namespace blink {
namespace {
template <typename Span1, typename Span2>
unsigned MismatchInternal(const Span1& span1, const Span2& span2) { … }
unsigned Mismatch(const String& old_text, const String& new_text) { … }
template <typename Span1, typename Span2>
unsigned MismatchFromEnd(const Span1& span1, const Span2& span2) { … }
unsigned MismatchFromEnd(StringView old_text, StringView new_text) { … }
float CalculateWidthForTextCombine(const InlineItemsData& data) { … }
unsigned EstimateInlineItemsCount(const LayoutBlockFlow& block) { … }
unsigned EstimateOffsetMappingItemsCount(const LayoutBlockFlow& block) { … }
class ReusingTextShaper final { … };
const Font& ScaledFont(const LayoutText& layout_text) { … }
template <typename ItemsBuilder>
void CollectInlinesInternal(ItemsBuilder* builder,
const InlineNodeData* previous_data) { … }
inline bool ShouldBreakShapingBeforeText(const InlineItem& item,
const InlineItem& start_item,
const ComputedStyle& start_style,
const Font& start_font,
TextDirection start_direction) { … }
inline bool ShouldBreakShapingBeforeBox(const InlineItem& item) { … }
inline bool ShouldBreakShapingAfterBox(const InlineItem& item) { … }
inline bool NeedsShaping(const InlineItem& item) { … }
bool FirstLineNeedsReshape(const ComputedStyle& first_line_style,
const ComputedStyle& base_style) { … }
void TruncateOrPadText(String* text, unsigned length) { … }
bool SetParagraphTo(const String& text,
const ComputedStyle& block_style,
BidiParagraph& bidi) { … }
}
InlineNode::InlineNode(LayoutBlockFlow* block)
: … { … }
bool InlineNode::IsPrepareLayoutFinished() const { … }
void InlineNode::PrepareLayoutIfNeeded() const { … }
void InlineNode::PrepareLayout(InlineNodeData* previous_data) const { … }
class InlineNodeDataEditor final { … };
bool InlineNode::SetTextWithOffset(LayoutText* layout_text,
String new_text,
const TextDiffRange& diff) { … }
const InlineNodeData& InlineNode::EnsureData() const { … }
const OffsetMapping* InlineNode::ComputeOffsetMappingIfNeeded() const { … }
void InlineNode::ComputeOffsetMapping(LayoutBlockFlow* layout_block_flow,
InlineNodeData* data) { … }
const OffsetMapping* InlineNode::GetOffsetMapping(
LayoutBlockFlow* layout_block_flow) { … }
void InlineNode::CollectInlines(InlineNodeData* data,
InlineNodeData* previous_data) const { … }
const SvgTextChunkOffsets* InlineNode::FindSvgTextChunks(
LayoutBlockFlow& block,
InlineNodeData& data) const { … }
void InlineNode::SegmentText(InlineNodeData* data,
InlineNodeData* previous_data) const { … }
void InlineNode::SegmentScriptRuns(InlineNodeData* data,
InlineNodeData* previous_data) const { … }
void InlineNode::SegmentFontOrientation(InlineNodeData* data) const { … }
void InlineNode::SegmentBidiRuns(InlineNodeData* data) const { … }
bool InlineNode::IsNGShapeCacheAllowed(
const String& text_content,
const Font* override_font,
const HeapVector<InlineItem>& items,
ShapeResultSpacing<String>& spacing) const { … }
void InlineNode::ShapeText(InlineItemsData* data,
const String* previous_text,
const HeapVector<InlineItem>* previous_items,
const Font* override_font) const { … }
void InlineNode::ShapeTextForFirstLineIfNeeded(InlineNodeData* data) const { … }
void InlineNode::ShapeTextIncludingFirstLine(
InlineNodeData* data,
const String* previous_text,
const HeapVector<InlineItem>* previous_items) const { … }
void InlineNode::AssociateItemsWithInlines(InlineNodeData* data) const { … }
const LayoutResult* InlineNode::Layout(
const ConstraintSpace& constraint_space,
const BreakToken* break_token,
const ColumnSpannerPath* column_spanner_path,
InlineChildLayoutContext* context) const { … }
namespace {
template <typename CharType>
String CreateTextContentForStickyImagesQuirk(
const CharType* text,
unsigned length,
base::span<const InlineItem> items) { … }
}
String InlineNode::TextContentForStickyImagesQuirk(
const InlineItemsData& items_data) { … }
static LayoutUnit ComputeContentSize(InlineNode node,
WritingMode container_writing_mode,
const ConstraintSpace& space,
const MinMaxSizesFloatInput& float_input,
LineBreakerMode mode,
LineBreaker::MaxSizeCache* max_size_cache,
std::optional<LayoutUnit>* max_size_out,
bool* depends_on_block_constraints_out) { … }
MinMaxSizesResult InlineNode::ComputeMinMaxSizes(
WritingMode container_writing_mode,
const ConstraintSpace& space,
const MinMaxSizesFloatInput& float_input) const { … }
bool InlineNode::UseFirstLineStyle() const { … }
void InlineNode::CheckConsistency() const { … }
const Vector<std::pair<unsigned, SvgCharacterData>>&
InlineNode::SvgCharacterDataList() const { … }
const HeapVector<SvgTextContentRange>& InlineNode::SvgTextLengthRangeList()
const { … }
const HeapVector<SvgTextContentRange>& InlineNode::SvgTextPathRangeList()
const { … }
void InlineNode::AdjustFontForTextCombineUprightAll() const { … }
bool InlineNode::NeedsShapingForTesting(const InlineItem& item) { … }
String InlineNode::ToString() const { … }
}