Commit 8dbf1e70 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[LayoutNG] Change offset mapping annotation type to general LayoutObject

This patch is a preparation for supporting IMG and other atomic inlines
in offset mapping, for which we need to use general annotation type in
offset mapping builder instead of LayoutText.

Bug: 776272
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: I0c9a24dc4ff97f1c839cb36f25dbef38e30cd4a8
Reviewed-on: https://chromium-review.googlesource.com/728925Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510272}
parent 69eba886
...@@ -21,19 +21,21 @@ NGOffsetMappingUnitType GetUnitLengthMappingType(unsigned value) { ...@@ -21,19 +21,21 @@ NGOffsetMappingUnitType GetUnitLengthMappingType(unsigned value) {
return NGOffsetMappingUnitType::kExpanded; return NGOffsetMappingUnitType::kExpanded;
} }
// Returns the associated node of a possibly null LayoutText. // Returns the associated node of a possibly null LayoutObject.
const Node* GetAssociatedNode(const LayoutText* layout_text) { const Node* GetAssociatedNode(const LayoutObject* layout_object) {
if (!layout_text) if (!layout_object)
return nullptr; return nullptr;
if (layout_text->IsTextFragment()) if (!layout_object->IsText() ||
return ToLayoutTextFragment(layout_text)->AssociatedTextNode(); !ToLayoutText(layout_object)->IsTextFragment())
return layout_text->GetNode(); return layout_object->GetNode();
const LayoutTextFragment* fragment = ToLayoutTextFragment(layout_object);
return fragment->AssociatedTextNode();
} }
// Finds the offset mapping unit starting from index |start|. // Finds the offset mapping unit starting from index |start|.
std::pair<NGOffsetMappingUnitType, unsigned> GetMappingUnitTypeAndEnd( std::pair<NGOffsetMappingUnitType, unsigned> GetMappingUnitTypeAndEnd(
const Vector<unsigned>& mapping, const Vector<unsigned>& mapping,
const Vector<const LayoutText*>& annotation, const Vector<const LayoutObject*>& annotation,
unsigned start) { unsigned start) {
DCHECK_LT(start + 1, mapping.size()); DCHECK_LT(start + 1, mapping.size());
NGOffsetMappingUnitType type = NGOffsetMappingUnitType type =
...@@ -54,6 +56,14 @@ std::pair<NGOffsetMappingUnitType, unsigned> GetMappingUnitTypeAndEnd( ...@@ -54,6 +56,14 @@ std::pair<NGOffsetMappingUnitType, unsigned> GetMappingUnitTypeAndEnd(
return std::make_pair(type, end); return std::make_pair(type, end);
} }
// If |layout_object| is the remaining text of a text node, returns the start
// offset; In all other cases, returns 0.
unsigned GetRemainingTextOffset(const LayoutObject* layout_object) {
if (!layout_object || !layout_object->IsText())
return 0;
return ToLayoutText(layout_object)->TextStartOffset();
}
} // namespace } // namespace
NGOffsetMappingBuilder::NGOffsetMappingBuilder() { NGOffsetMappingBuilder::NGOffsetMappingBuilder() {
...@@ -93,13 +103,13 @@ void NGOffsetMappingBuilder::CollapseTrailingSpace(unsigned skip_length) { ...@@ -93,13 +103,13 @@ void NGOffsetMappingBuilder::CollapseTrailingSpace(unsigned skip_length) {
} }
} }
void NGOffsetMappingBuilder::Annotate(const LayoutText* layout_object) { void NGOffsetMappingBuilder::Annotate(const LayoutObject* layout_object) {
std::fill(annotation_.begin(), annotation_.end(), layout_object); std::fill(annotation_.begin(), annotation_.end(), layout_object);
} }
void NGOffsetMappingBuilder::AnnotateRange(unsigned start, void NGOffsetMappingBuilder::AnnotateRange(unsigned start,
unsigned end, unsigned end,
const LayoutText* layout_object) { const LayoutObject* layout_object) {
DCHECK_LE(start, end); DCHECK_LE(start, end);
DCHECK_LE(end, annotation_.size()); DCHECK_LE(end, annotation_.size());
std::fill(annotation_.begin() + start, annotation_.begin() + end, std::fill(annotation_.begin() + start, annotation_.begin() + end,
...@@ -107,7 +117,7 @@ void NGOffsetMappingBuilder::AnnotateRange(unsigned start, ...@@ -107,7 +117,7 @@ void NGOffsetMappingBuilder::AnnotateRange(unsigned start,
} }
void NGOffsetMappingBuilder::AnnotateSuffix(unsigned length, void NGOffsetMappingBuilder::AnnotateSuffix(unsigned length,
const LayoutText* layout_object) { const LayoutObject* layout_object) {
DCHECK_LE(length, annotation_.size()); DCHECK_LE(length, annotation_.size());
AnnotateRange(annotation_.size() - length, annotation_.size(), layout_object); AnnotateRange(annotation_.size() - length, annotation_.size(), layout_object);
} }
...@@ -152,8 +162,10 @@ NGOffsetMappingResult NGOffsetMappingBuilder::Build() const { ...@@ -152,8 +162,10 @@ NGOffsetMappingResult NGOffsetMappingBuilder::Build() const {
current_node = GetAssociatedNode(annotation_[start]); current_node = GetAssociatedNode(annotation_[start]);
inline_start = start; inline_start = start;
unit_range_start = units.size(); unit_range_start = units.size();
remaining_text_offset = // We get a non-zero |remaining_text_offset| only when |current_node| is a
annotation_[start] ? annotation_[start]->TextStartOffset() : 0; // text node that has blockified ::first-letter style, and we are at the
// remaining text of |current_node|.
remaining_text_offset = GetRemainingTextOffset(annotation_[start]);
} }
if (!current_node) { if (!current_node) {
...@@ -186,7 +198,7 @@ Vector<unsigned> NGOffsetMappingBuilder::DumpOffsetMappingForTesting() const { ...@@ -186,7 +198,7 @@ Vector<unsigned> NGOffsetMappingBuilder::DumpOffsetMappingForTesting() const {
return mapping_; return mapping_;
} }
Vector<const LayoutText*> NGOffsetMappingBuilder::DumpAnnotationForTesting() Vector<const LayoutObject*> NGOffsetMappingBuilder::DumpAnnotationForTesting()
const { const {
return annotation_; return annotation_;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace blink { namespace blink {
class LayoutText; class LayoutObject;
class NGOffsetMappingResult; class NGOffsetMappingResult;
// This is the helper class for constructing the DOM-to-TextContent offset // This is the helper class for constructing the DOM-to-TextContent offset
...@@ -28,13 +28,13 @@ class CORE_EXPORT NGOffsetMappingBuilder { ...@@ -28,13 +28,13 @@ class CORE_EXPORT NGOffsetMappingBuilder {
// Associate the offset mapping with a simple annotation with the given node // Associate the offset mapping with a simple annotation with the given node
// as its value. // as its value.
void Annotate(const LayoutText*); void Annotate(const LayoutObject*);
// Annotate the offset range with the given node. // Annotate the offset range with the given node.
void AnnotateRange(unsigned start, unsigned end, const LayoutText*); void AnnotateRange(unsigned start, unsigned end, const LayoutObject*);
// Annotatie the offset range ending at domain end of the specified length. // Annotatie the offset range ending at domain end of the specified length.
void AnnotateSuffix(unsigned length, const LayoutText*); void AnnotateSuffix(unsigned length, const LayoutObject*);
// Append an identity offset mapping of the specified length with null // Append an identity offset mapping of the specified length with null
// annotation to the builder. // annotation to the builder.
...@@ -74,7 +74,7 @@ class CORE_EXPORT NGOffsetMappingBuilder { ...@@ -74,7 +74,7 @@ class CORE_EXPORT NGOffsetMappingBuilder {
// Exposed for testing only. // Exposed for testing only.
Vector<unsigned> DumpOffsetMappingForTesting() const; Vector<unsigned> DumpOffsetMappingForTesting() const;
Vector<const LayoutText*> DumpAnnotationForTesting() const; Vector<const LayoutObject*> DumpAnnotationForTesting() const;
private: private:
// A mock implementation of the offset mapping builder that stores the mapping // A mock implementation of the offset mapping builder that stores the mapping
...@@ -84,7 +84,7 @@ class CORE_EXPORT NGOffsetMappingBuilder { ...@@ -84,7 +84,7 @@ class CORE_EXPORT NGOffsetMappingBuilder {
// A mock implementation that stores the annotation value of all offsets in // A mock implementation that stores the annotation value of all offsets in
// the plain way. It will be replaced by a real implementation for efficiency. // the plain way. It will be replaced by a real implementation for efficiency.
Vector<const LayoutText*> annotation_; Vector<const LayoutObject*> annotation_;
// The destination string of the offset mapping. // The destination string of the offset mapping.
String destination_string_; String destination_string_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment