Index: third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_result.h |
diff --git a/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_result.h b/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_result.h |
index 12b0becb896cb0e938da6964c3ee1964c694aa1a..a4a3e541bd79c2409890dbdeb6906c38c12d7a09 100644 |
--- a/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_result.h |
+++ b/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_result.h |
@@ -47,6 +47,20 @@ struct NGOffsetMappingUnit { |
unsigned dom_end = 0; |
unsigned text_content_start = 0; |
unsigned text_content_end = 0; |
+ |
+ unsigned DOMToTextContentOffset(unsigned dom_offset) const { |
+ switch (type) { |
+ case NGOffsetMappingUnitType::kIdentity: |
+ return dom_offset - dom_start + text_content_start; |
+ case NGOffsetMappingUnitType::kCollapsed: |
+ return text_content_start; |
+ case NGOffsetMappingUnitType::kExpanded: |
+ return dom_offset == dom_start ? text_content_start : text_content_end; |
+ } |
+ // Add |return| in this unreachable patch to make Windows compiler happy. |
+ NOTREACHED(); |
+ return 0; |
+ } |
}; |
// An NGOffsetMappingResult stores the units of a LayoutNGBlockFlow in sorted |
@@ -56,6 +70,10 @@ struct NGOffsetMappingUnit { |
struct NGOffsetMappingResult { |
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
+ // Returns the mapping unit whose owner is the node and dom offset range |
+ // contains the given offset. Returns the last one if multiple units qualify. |
+ const NGOffsetMappingUnit* GetMappingUnitForDOMOffset(const Node&, unsigned); |
+ |
Vector<NGOffsetMappingUnit> units; |
HashMap<const LayoutText*, std::pair<unsigned, unsigned>> ranges; |
}; |