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 304e806bad8f10962cec4d7f5806532a985743eb..4a6c8d5289d02d462b6031da7f62c94da76b2f26 100644 |
--- a/third_party/WebKit/Source/core/dom/Range.cpp |
+++ b/third_party/WebKit/Source/core/dom/Range.cpp |
@@ -1443,34 +1443,39 @@ Node* Range::pastLastNode() const { |
} |
IntRect Range::boundingBox() const { |
- IntRect result; |
- Vector<IntRect> rects; |
- textRects(rects); |
- for (const IntRect& rect : rects) |
- result.unite(rect); |
- return result; |
+ return computeBoundingBox(EphemeralRange(this)); |
} |
-void Range::textRects(Vector<IntRect>& rects, bool useSelectionHeight) const { |
- Node* startContainer = m_start.container(); |
+template <typename Strategy> |
+static Vector<IntRect> computeTextRects( |
+ const EphemeralRangeTemplate<Strategy>& range) { |
+ const PositionTemplate<Strategy> startPosition = range.startPosition(); |
+ const PositionTemplate<Strategy> endPosition = range.endPosition(); |
+ Node* startContainer = startPosition.computeContainerNode(); |
DCHECK(startContainer); |
- Node* endContainer = m_end.container(); |
+ Node* endContainer = endPosition.computeContainerNode(); |
DCHECK(endContainer); |
- |
- Node* stopNode = pastLastNode(); |
- for (Node* node = firstNode(); node != stopNode; |
- node = NodeTraversal::next(*node)) { |
- LayoutObject* r = node->layoutObject(); |
- if (!r || !r->isText()) |
+ Vector<IntRect> rects; |
+ for (Node& node : range.nodes()) { |
+ LayoutObject* layoutObject = node.layoutObject(); |
+ if (!layoutObject || !layoutObject->isText()) |
continue; |
- LayoutText* layoutText = toLayoutText(r); |
- unsigned startOffset = node == startContainer ? m_start.offset() : 0; |
+ LayoutText* layoutText = toLayoutText(layoutObject); |
+ unsigned startOffset = |
+ node == startContainer ? startPosition.offsetInContainerNode() : 0; |
unsigned endOffset = node == endContainer |
- ? m_end.offset() |
+ ? endPosition.offsetInContainerNode() |
: std::numeric_limits<unsigned>::max(); |
- layoutText->absoluteRectsForRange(rects, startOffset, endOffset, |
- useSelectionHeight); |
+ layoutText->absoluteRectsForRange(rects, startOffset, endOffset); |
} |
+ return rects; |
yosin_UTC9
2017/04/04 01:20:39
nit: s/rects/std::move(rects)/
This is subject to
Hwanseung Lee
2017/04/05 15:21:30
Done.
|
+} |
+ |
+IntRect Range::computeBoundingBox(const EphemeralRange& range) const { |
yosin_UTC9
2017/04/04 01:20:39
We don't need to make |computeBoundingBox()| as me
Hwanseung Lee
2017/04/05 15:21:30
Done.
|
+ IntRect result; |
+ for (const IntRect& rect : computeTextRects(range)) |
+ result.unite(rect); |
+ return result; |
} |
void Range::textQuads(Vector<FloatQuad>& quads, bool useSelectionHeight) const { |