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

Unified Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 2877463002: Move ComputeTextRects and ComputeTextQuads to VisibleUnits. (Closed)
Patch Set: updated PS Created 3 years, 7 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/editing/VisibleUnits.cpp
diff --git a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
index a234656ab5f420fdfc89510245cc750322b15ce5..7f1b53a77c5309e024780f703970c2f49e94fcfa 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -4078,4 +4078,52 @@ PositionInFlatTree SkipWhitespace(const PositionInFlatTree& position) {
return SkipWhitespaceAlgorithm(position);
}
+static void CollectAbsoluteBoundsForRange(unsigned start,
+ unsigned end,
+ const LayoutText& layout_text,
+ Vector<IntRect>& rects) {
+ layout_text.AbsoluteRectsForRange(rects, start, end);
+}
+
+static void CollectAbsoluteBoundsForRange(unsigned start,
+ unsigned end,
+ const LayoutText& layout_text,
+ Vector<FloatQuad>& quads) {
+ layout_text.AbsoluteQuadsForRange(quads, start, end);
+}
+
+template <typename RectType>
+static Vector<RectType> ComputeTextBounds(const EphemeralRange& range) {
+ const Position& start_position = range.StartPosition();
+ const Position& end_position = range.EndPosition();
+ Node* const start_container = start_position.ComputeContainerNode();
+ DCHECK(start_container);
+ Node* const end_container = end_position.ComputeContainerNode();
+ DCHECK(end_container);
+
+ Vector<RectType> result;
+ for (const Node& node : range.Nodes()) {
+ LayoutObject* const layout_object = node.GetLayoutObject();
+ if (!layout_object || !layout_object->IsText())
+ continue;
+ const LayoutText* layout_text = ToLayoutText(layout_object);
+ unsigned start_offset =
+ node == start_container ? start_position.OffsetInContainerNode() : 0;
+ unsigned end_offset = node == end_container
+ ? end_position.OffsetInContainerNode()
+ : std::numeric_limits<unsigned>::max();
+ CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text,
+ result);
+ }
+ return result;
+}
+
+Vector<IntRect> ComputeTextRects(const EphemeralRange& range) {
+ return ComputeTextBounds<IntRect>(range);
+}
+
+Vector<FloatQuad> ComputeTextQuads(const EphemeralRange& range) {
+ return ComputeTextBounds<FloatQuad>(range);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698