chromium/third_party/blink/renderer/core/layout/inline/ruby_utils.h

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

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_INLINE_RUBY_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_INLINE_RUBY_UTILS_H_

#include <optional>

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/fonts/font_height.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"

namespace blink {

class ComputedStyle;
class InlineItem;
class LineInfo;
class LogicalLineContainer;
class LogicalLineItems;
class PhysicalBoxFragment;
class ShapeResultView;
struct InlineItemResult;
struct LogicalRubyColumn;
struct PhysicalRect;

struct RubyItemIndexes {};

// Get item indexes for a ruby column starting at `start_item_index`.
// `start_item_index` must point to kOpenRubyColumn item.
RubyItemIndexes ParseRubyInInlineItems(const HeapVector<InlineItem>& items,
                                       wtf_size_t start_item_index);

// Adjust the specified |rect| of a text fragment for 'em' height.
// This is called on computing scrollable overflow with kEmHeight.
PhysicalRect AdjustTextRectForEmHeight(const PhysicalRect& rect,
                                       const ComputedStyle& style,
                                       const ShapeResultView* shape_view,
                                       WritingMode writing_mode);

PhysicalRect ComputeRubyEmHeightBox(const PhysicalBoxFragment& box_fragment);

struct AnnotationOverhang {};

// Returns overhang values of the specified InlineItemResult representing
// LayoutRubyColumn.
//
// This is used by LineBreaker.
AnnotationOverhang GetOverhang(const InlineItemResult& item);

// Returns overhang values of the specified base/annotation lines.
// These lines should have correct LineStyle.
//
// This is used by LineBreaker.
AnnotationOverhang GetOverhang(
    LayoutUnit ruby_size,
    const LineInfo& base_line,
    const HeapVector<LineInfo, 1> annotation_line_list);

// Returns true if |start_overhang| is applied to a previous item, and
// clamp |start_overhang| to the width of the previous item.
//
// This is used by LineBreaker.
bool CanApplyStartOverhang(const LineInfo& line_info,
                           wtf_size_t ruby_index,
                           const ComputedStyle& ruby_style,
                           LayoutUnit& start_overhang);

// This should be called before a text `InlineItem` is added in
// LineBreaker::HandleText().
//
// This function may update a InlineItemResult representing RubyColumn
// in |line_info|
LayoutUnit CommitPendingEndOverhang(const InlineItem& text_item,
                                    LineInfo* line_info);

// Justify InlineItemResutls of the specified `line_info`.
// Returns a pair of the left and the right insets.  They should be applied
// to LogicalLineItems generated from `line_info` after bidi reorder.
[[nodiscard]] std::pair<LayoutUnit, LayoutUnit> ApplyRubyAlign(
    LayoutUnit available_line_size,
    bool on_start_edge,
    bool on_end_edge,
    LineInfo& line_info);

// Stores ComputeAnnotationOverflow() results.
//
// |overflow_over| and |space_over| are exclusive. Only one of them can be
// non-zero. |overflow_under| and |space_under| are exclusive too.
// All fields never be negative.
struct AnnotationMetrics {};

// Compute over/under annotation overflow/space for the specified line.
AnnotationMetrics ComputeAnnotationOverflow(
    const LogicalLineItems& logical_line,
    const FontHeight& line_box_metrics,
    const ComputedStyle& line_style,
    std::optional<FontHeight> annotation_metrics);

// Update inline positions of LogicalLineItems for all LogicalRubyColumns
// linked from `column_list`.
void UpdateRubyColumnInlinePositions(
    const LogicalLineItems& line_items,
    LayoutUnit inline_size,
    HeapVector<Member<LogicalRubyColumn>>& column_list);

// This class calculates block positions of annotation lines on the base line.
class CORE_EXPORT RubyBlockPositionCalculator {};

}  // namespace blink

WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS()

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_INLINE_RUBY_UTILS_H_