chromium/third_party/blink/renderer/core/layout/inline/inline_node.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#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) {}

// Returns sum of |ShapeResult::Width()| in |data.items|. Note: All items
// should be text item other type of items are not allowed.
float CalculateWidthForTextCombine(const InlineItemsData& data) {}

// Estimate the number of InlineItem to minimize the vector expansions.
unsigned EstimateInlineItemsCount(const LayoutBlockFlow& block) {}

// Estimate the number of units and ranges in OffsetMapping to minimize vector
// and hash map expansions.
unsigned EstimateOffsetMappingItemsCount(const LayoutBlockFlow& block) {}

// Wrapper over ShapeText that re-uses existing shape results for items that
// haven't changed.
class ReusingTextShaper final {};

const Font& ScaledFont(const LayoutText& layout_text) {}

// The function is templated to indicate the purpose of collected inlines:
// - With EmptyOffsetMappingBuilder: updating layout;
// - With OffsetMappingBuilder: building offset mapping on clean layout.
//
// This allows code sharing between the two purposes with slightly different
// behaviors. For example, we clear a LayoutObject's need layout flags when
// updating layout, but don't do that when building offset mapping.
//
// There are also performance considerations, since template saves the overhead
// for condition checking and branching.
template <typename ItemsBuilder>
void CollectInlinesInternal(ItemsBuilder* builder,
                            const InlineNodeData* previous_data) {}

// Returns whether this text should break shaping. Even within a box, text runs
// that have different shaping properties need to break shaping.
inline bool ShouldBreakShapingBeforeText(const InlineItem& item,
                                         const InlineItem& start_item,
                                         const ComputedStyle& start_style,
                                         const Font& start_font,
                                         TextDirection start_direction) {}

// Returns whether the start of this box should break shaping.
inline bool ShouldBreakShapingBeforeBox(const InlineItem& item) {}

// Returns whether the end of this box should break shaping.
inline bool ShouldBreakShapingAfterBox(const InlineItem& item) {}

inline bool NeedsShaping(const InlineItem& item) {}

// Determine if reshape is needed for ::first-line style.
bool FirstLineNeedsReshape(const ComputedStyle& first_line_style,
                           const ComputedStyle& base_style) {}

// Make a string to the specified length, either by truncating if longer, or
// appending space characters if shorter.
void TruncateOrPadText(String* text, unsigned length) {}

bool SetParagraphTo(const String& text,
                    const ComputedStyle& block_style,
                    BidiParagraph& bidi) {}

}  // namespace

InlineNode::InlineNode(LayoutBlockFlow* block)
    :{}

bool InlineNode::IsPrepareLayoutFinished() const {}

void InlineNode::PrepareLayoutIfNeeded() const {}

void InlineNode::PrepareLayout(InlineNodeData* previous_data) const {}

// Building |InlineNodeData| for |LayoutText::SetTextWithOffset()| with
// reusing data.
class InlineNodeDataEditor final {};

// static
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) {}

// Depth-first-scan of all LayoutInline and LayoutText nodes that make up this
// InlineNode object. Collects LayoutText items, merging them up into the
// parent LayoutInline where possible, and joining all text content in a single
// string to allow bidi resolution and shaping of the entire block.
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 {}

// Segment InlineItem by script, Emoji, and orientation using RunSegmenter.
void InlineNode::SegmentScriptRuns(InlineNodeData* data,
                                   InlineNodeData* previous_data) const {}

void InlineNode::SegmentFontOrientation(InlineNodeData* data) const {}

// Segment bidi runs by resolving bidi embedding levels.
// http://unicode.org/reports/tr9/#Resolving_Embedding_Levels
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 {}

// Create HeapVector<InlineItem> with :first-line rules applied if needed.
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) {}

}  // namespace

// The stick images quirk changes the line breaking behavior around images. This
// function returns a text content that has non-breaking spaces for images, so
// that no changes are needed in the line breaking logic.
// https://quirks.spec.whatwg.org/#the-table-cell-width-calculation-quirk
// static
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 {}

}  // namespace blink