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

Unified Diff: third_party/WebKit/Source/core/dom/Range.cpp

Issue 2839633002: Introduce ComputeTextBounds template in Range.cpp (Closed)
Patch Set: AddressedReviewComments Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Range.cpp
diff --git a/third_party/WebKit/Source/core/dom/Range.cpp b/third_party/WebKit/Source/core/dom/Range.cpp
index 76e18fa4a989b4c8e263194cc052a329fa79348e..938e7c2acac291ee8ab4a70f35508cae5947b084 100644
--- a/third_party/WebKit/Source/core/dom/Range.cpp
+++ b/third_party/WebKit/Source/core/dom/Range.cpp
@@ -1440,7 +1440,15 @@ Node* Range::PastLastNode() const {
return EndPosition().NodeAsRangePastLastNode();
}
-static Vector<IntRect> computeTextRects(const EphemeralRange& range) {
+static void CollectAbsoluteBoundsForRange(unsigned start,
+ unsigned end,
+ const LayoutText& layout_text,
+ Vector<IntRect>& rects) {
+ layout_text.AbsoluteRectsForRange(rects, 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();
@@ -1448,20 +1456,25 @@ static Vector<IntRect> computeTextRects(const EphemeralRange& range) {
Node* const end_container = end_position.ComputeContainerNode();
DCHECK(end_container);
- Vector<IntRect> rects;
+ Vector<RectType> result;
for (const Node& node : range.Nodes()) {
LayoutObject* const layoutObject = node.GetLayoutObject();
if (!layoutObject || !layoutObject->IsText())
continue;
- LayoutText* layout_text = ToLayoutText(layoutObject);
+ const LayoutText* layout_text = ToLayoutText(layoutObject);
unsigned start_offset =
node == start_container ? start_position.OffsetInContainerNode() : 0;
unsigned end_offset = node == end_container
? end_position.OffsetInContainerNode()
: std::numeric_limits<unsigned>::max();
- layout_text->AbsoluteRectsForRange(rects, start_offset, end_offset);
+ CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text,
+ result);
}
- return rects;
+ return result;
+}
+
+static Vector<IntRect> computeTextRects(const EphemeralRange& range) {
+ return ComputeTextBounds<IntRect>(range);
}
IntRect Range::BoundingBox() const {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698