diff --git a/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.cc b/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.cc index 20be8c24770d2..d69d32f83faf2 100644 --- a/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.cc +++ b/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.cc @@ -101,6 +101,13 @@ class SpacingApplier { DCHECK(shape_result); shape_result->ApplyTextAutoSpacing(offsets_with_spacing_); item->SetUnsafeToReuseShapeResult(); + if (callback_for_testing_) [[unlikely]] { + callback_for_testing_->DidApply(offsets_with_spacing_); + } + } + + void SetCallbackForTesting(InlineTextAutoSpace::Callback* callback) { + callback_for_testing_ = callback; } private: @@ -108,6 +115,7 @@ class SpacingApplier { // Stores the spacing (1/8 ic) and auto-space points's previous positions, for // the previous item. Vector<OffsetWithSpacing, 16> offsets_with_spacing_; + InlineTextAutoSpace::Callback* callback_for_testing_ = nullptr; }; } // namespace @@ -151,8 +159,7 @@ void InlineTextAutoSpace::Initialize(const InlineItemsData& data) { } } -void InlineTextAutoSpace::Apply(InlineItemsData& data, - Vector<wtf_size_t>* offsets_out) { +void InlineTextAutoSpace::Apply(InlineItemsData& data) { const String& text = data.text_content; DCHECK(!text.Is8Bit()); DCHECK_EQ(text.length(), ranges_.back().end); @@ -166,6 +173,7 @@ void InlineTextAutoSpace::Apply(InlineItemsData& data, // whether to add spacing into the bound of two items. TextDirection last_direction = TextDirection::kLtr; SpacingApplier applier; + applier.SetCallbackForTesting(callback_for_testing_); for (const Member<InlineItem>& item_ptr : data.items) { const InlineItem& item = *item_ptr; if (item.Type() != InlineItem::kText) { @@ -275,11 +283,7 @@ void InlineTextAutoSpace::Apply(InlineItemsData& data, } } while (offset < item.EndOffset()); - if (!offsets_out) { - applier.SetSpacing(offsets, &item, *style); - } else { - offsets_out->AppendVector(offsets); - } + applier.SetSpacing(offsets, &item, *style); offsets.Shrink(0); } // Apply the pending spacing for the last item if needed. diff --git a/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.h b/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.h index a585d01c04082..89a11ec97850b 100644 --- a/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.h +++ b/third_party/blink/renderer/core/layout/inline/inline_text_auto_space.h @@ -23,6 +23,12 @@ class CORE_EXPORT InlineTextAutoSpace : public TextAutoSpace { STACK_ALLOCATED(); public: + // A class for testing to inspect what `InlineTextAutoSpace` did. + class CORE_EXPORT Callback { + public: + virtual void DidApply(base::span<const OffsetWithSpacing>) = 0; + }; + explicit InlineTextAutoSpace(const InlineItemsData& data); // True if this may apply auto-spacing. If this is false, it's safe to skip @@ -33,21 +39,22 @@ class CORE_EXPORT InlineTextAutoSpace : public TextAutoSpace { // https://drafts.csswg.org/css-text-4/#propdef-text-autospace // // The `data` must be the same instance as the one given to the constructor. - // - // If `offsets_out` is not null, the offsets of auto-space points are added to - // it without applying auto-spacing. This is for tseting-purpose. - void Apply(InlineItemsData& data, Vector<wtf_size_t>* offsets_out = nullptr); - void ApplyIfNeeded(InlineItemsData& data, - Vector<wtf_size_t>* offsets_out = nullptr) { + void Apply(InlineItemsData& data); + void ApplyIfNeeded(InlineItemsData& data) { if (MayApply()) [[unlikely]] { - Apply(data, offsets_out); + Apply(data); } } + void SetCallbackForTesting(Callback* callback) { + callback_for_testing_ = callback; + } + private: void Initialize(const InlineItemsData& data); InlineItemSegments::RunSegmenterRanges ranges_; + Callback* callback_for_testing_ = nullptr; }; inline InlineTextAutoSpace::InlineTextAutoSpace(const InlineItemsData& data) { diff --git a/third_party/blink/renderer/core/layout/inline/inline_text_auto_space_test.cc b/third_party/blink/renderer/core/layout/inline/inline_text_auto_space_test.cc index 76c1415065b62..438873961bde7 100644 --- a/third_party/blink/renderer/core/layout/inline/inline_text_auto_space_test.cc +++ b/third_party/blink/renderer/core/layout/inline/inline_text_auto_space_test.cc @@ -21,6 +21,16 @@ using testing::ElementsAreArray; class InlineTextAutoSpaceTest : public RenderingTest, ScopedCSSTextAutoSpaceForTest { public: + struct AutoSpaceCallback : public InlineTextAutoSpace::Callback { + void DidApply(base::span<const OffsetWithSpacing> applied_offsets) final { + for (const OffsetWithSpacing& offset : applied_offsets) { + offsets.push_back(offset.offset); + } + } + + Vector<wtf_size_t> offsets; + }; + explicit InlineTextAutoSpaceTest() : ScopedCSSTextAutoSpaceForTest(true) {} LayoutBlockFlow* PreparePageLayoutBlock(String html, @@ -44,10 +54,11 @@ class InlineTextAutoSpaceTest : public RenderingTest, const LayoutBlockFlow* container = PreparePageLayoutBlock(html, container_css); InlineNodeData* node_data = container->GetInlineNodeData(); - Vector<wtf_size_t> offsets; InlineTextAutoSpace auto_space(*node_data); - auto_space.ApplyIfNeeded(*node_data, &offsets); - return offsets; + AutoSpaceCallback callback; + auto_space.SetCallbackForTesting(&callback); + auto_space.ApplyIfNeeded(*node_data); + return callback.offsets; } }; diff --git a/third_party/blink/renderer/platform/fonts/shaping/shape_result.h b/third_party/blink/renderer/platform/fonts/shaping/shape_result.h index d1472d36a093f..8e1528294716a 100644 --- a/third_party/blink/renderer/platform/fonts/shaping/shape_result.h +++ b/third_party/blink/renderer/platform/fonts/shaping/shape_result.h @@ -101,7 +101,7 @@ struct ShapeResultCharacterData { }; // A space should be appended after `offset` with the width of `spacing`. -struct OffsetWithSpacing { +struct PLATFORM_EXPORT OffsetWithSpacing { wtf_size_t offset; float spacing; };