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

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

Issue 2776103002: Make RenderedRectsForMarkers() to ignore disconnected nodes. (Closed)
Patch Set: tt 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
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 e93ee299cd4345348dc02f43e7622d5ca9e52e3d..e8ccb1a98f612f35bfa8e288c0d665831d2efe2f 100644
--- a/third_party/WebKit/Source/core/dom/Range.cpp
+++ b/third_party/WebKit/Source/core/dom/Range.cpp
@@ -1449,34 +1449,39 @@ Node* Range::pastLastNode() const {
}
IntRect Range::boundingBox() const {
- IntRect result;
- Vector<IntRect> rects;
yosin_UTC9 2017/04/07 04:48:10 Just change these two lines: const Vector<IntRect
- 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>
yosin_UTC9 2017/04/07 04:48:10 We don't need to use |template <Strategy>|, |compu
Hwanseung Lee 2017/04/07 17:55:53 Done.
+static Vector<IntRect> computeTextRects(
yosin_UTC9 2017/04/07 04:48:10 It is OK to adding forward declaration before |Ran
Hwanseung Lee 2017/04/07 17:55:53 Done.
+ const EphemeralRangeTemplate<Strategy>& range) {
yosin_UTC9 2017/04/07 04:48:10 nit: const EphemeralRange&
Hwanseung Lee 2017/04/07 17:55:53 Done.
+ const PositionTemplate<Strategy> startPosition = range.startPosition();
yosin_UTC9 2017/04/07 04:48:10 nit const Position&
Hwanseung Lee 2017/04/07 17:55:53 Done.
+ 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;
+}
+
+IntRect Range::computeBoundingBox(const EphemeralRange& range) const {
+ IntRect result;
+ for (const IntRect& rect : computeTextRects(range))
+ result.unite(rect);
+ return result;
}
void Range::textQuads(Vector<FloatQuad>& quads, bool useSelectionHeight) const {

Powered by Google App Engine
This is Rietveld 408576698