Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc

Issue 2968803002: EXPERIMENT TextIterator built on Layout NG offset mapping
Patch Set: Mon Jul 17 15:55:29 PDT 2017 Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc b/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc
index 46c551c224066683e16223b7fb2e9dc0cd94b9dd..7b6c4746b428b655bb101a10ca4ed6425d152f6b 100644
--- a/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc
+++ b/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc
@@ -4,6 +4,9 @@
#include "core/layout/ng/inline/ng_offset_mapping_builder.h"
+#include <algorithm>
+#include "core/editing/VisibleUnits.h"
+#include "core/layout/LayoutText.h"
#include "core/layout/ng/inline/ng_offset_mapping_result.h"
#include "platform/wtf/text/StringBuilder.h"
@@ -45,6 +48,34 @@ std::pair<NGOffsetMappingUnitType, unsigned> GetMappingUnitTypeAndEnd(
} // namespace
+const NGOffsetMappingUnit* NGOffsetMappingResult::GetMappingUnitForDOMOffset(
+ const Node& node,
+ unsigned offset) {
+ const LayoutObject* layout_object = AssociatedLayoutObjectOf(node, offset);
+ if (!layout_object || !layout_object->IsText() ||
+ !ranges.Contains(ToLayoutText(layout_object)))
+ return nullptr;
+
+ unsigned range_start;
+ unsigned range_end;
+ std::tie(range_start, range_end) = ranges.at(ToLayoutText(layout_object));
+
+ if (range_start == range_end || units[range_start].dom_start > offset)
+ return nullptr;
+
+ // Find the last unit where unit.dom_start <= offset
+ unsigned unit_index =
+ std::upper_bound(units.begin() + range_start, units.begin() + range_end,
+ offset,
+ [](unsigned offset, const NGOffsetMappingUnit& unit) {
+ return offset < unit.dom_start;
+ }) -
+ units.begin() - 1;
+ if (units[unit_index].dom_end < offset)
+ return nullptr;
+ return &units[unit_index];
+}
+
NGOffsetMappingBuilder::NGOffsetMappingBuilder() {
mapping_.push_back(0);
}

Powered by Google App Engine
This is Rietveld 408576698