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

Side by Side Diff: third_party/WebKit/Source/core/dom/Range.cpp

Issue 2854043002: Make Range::TextQuads() to use ComputeTextBounds() template function. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
5 * (C) 2001 Peter Kelly (pmk@post.com) 5 * (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
7 * rights reserved. 7 * rights reserved.
8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 8 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 return EndPosition().NodeAsRangePastLastNode(); 1440 return EndPosition().NodeAsRangePastLastNode();
1441 } 1441 }
1442 1442
1443 static void CollectAbsoluteBoundsForRange(unsigned start, 1443 static void CollectAbsoluteBoundsForRange(unsigned start,
1444 unsigned end, 1444 unsigned end,
1445 const LayoutText& layout_text, 1445 const LayoutText& layout_text,
1446 Vector<IntRect>& rects) { 1446 Vector<IntRect>& rects) {
1447 layout_text.AbsoluteRectsForRange(rects, start, end); 1447 layout_text.AbsoluteRectsForRange(rects, start, end);
1448 } 1448 }
1449 1449
1450 static void CollectAbsoluteBoundsForRange(unsigned start,
1451 unsigned end,
1452 const LayoutText& layout_text,
1453 Vector<FloatQuad>& quads) {
1454 layout_text.AbsoluteQuadsForRange(quads, start, end);
1455 }
1456
1450 template <typename RectType> 1457 template <typename RectType>
1451 static Vector<RectType> ComputeTextBounds(const EphemeralRange& range) { 1458 static Vector<RectType> ComputeTextBounds(const EphemeralRange& range) {
1452 const Position& start_position = range.StartPosition(); 1459 const Position& start_position = range.StartPosition();
1453 const Position& end_position = range.EndPosition(); 1460 const Position& end_position = range.EndPosition();
1454 Node* const start_container = start_position.ComputeContainerNode(); 1461 Node* const start_container = start_position.ComputeContainerNode();
1455 DCHECK(start_container); 1462 DCHECK(start_container);
1456 Node* const end_container = end_position.ComputeContainerNode(); 1463 Node* const end_container = end_position.ComputeContainerNode();
1457 DCHECK(end_container); 1464 DCHECK(end_container);
1458 1465
1459 Vector<RectType> result; 1466 Vector<RectType> result;
(...skipping 10 matching lines...) Expand all
1470 CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text, 1477 CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text,
1471 result); 1478 result);
1472 } 1479 }
1473 return result; 1480 return result;
1474 } 1481 }
1475 1482
1476 static Vector<IntRect> computeTextRects(const EphemeralRange& range) { 1483 static Vector<IntRect> computeTextRects(const EphemeralRange& range) {
1477 return ComputeTextBounds<IntRect>(range); 1484 return ComputeTextBounds<IntRect>(range);
1478 } 1485 }
1479 1486
1487 static Vector<FloatQuad> computeTextQuads(const EphemeralRange& range) {
1488 return ComputeTextBounds<FloatQuad>(range);
1489 }
1490
1480 IntRect Range::BoundingBox() const { 1491 IntRect Range::BoundingBox() const {
1481 IntRect result; 1492 IntRect result;
1482 const Vector<IntRect>& rects = computeTextRects(EphemeralRange(this)); 1493 const Vector<IntRect>& rects = computeTextRects(EphemeralRange(this));
1483 for (const IntRect& rect : rects) 1494 for (const IntRect& rect : rects)
1484 result.Unite(rect); 1495 result.Unite(rect);
1485 return result; 1496 return result;
1486 } 1497 }
1487 1498
1488 void Range::TextQuads(Vector<FloatQuad>& quads, 1499 void Range::TextQuads(Vector<FloatQuad>& quads,
1489 bool use_selection_height) const { 1500 bool use_selection_height) const {
1490 Node* start_container = &start_.Container(); 1501 const Vector<FloatQuad>& result = computeTextQuads(EphemeralRange(this));
1491 DCHECK(start_container); 1502 quads.insert(quads.size(), result);
1492 Node* end_container = &end_.Container();
1493 DCHECK(end_container);
1494
1495 Node* stop_node = PastLastNode();
1496 for (Node* node = FirstNode(); node != stop_node;
1497 node = NodeTraversal::Next(*node)) {
1498 LayoutObject* r = node->GetLayoutObject();
1499 if (!r || !r->IsText())
1500 continue;
1501 LayoutText* layout_text = ToLayoutText(r);
1502 unsigned start_offset = node == start_container ? start_.Offset() : 0;
1503 unsigned end_offset = node == end_container
1504 ? end_.Offset()
1505 : std::numeric_limits<unsigned>::max();
1506 layout_text->AbsoluteQuadsForRange(quads, start_offset, end_offset,
1507 use_selection_height);
Xiaocheng 2017/05/02 21:15:03 Could you first remove |use_selection_height| from
1508 }
1509 } 1503 }
1510 1504
1511 bool AreRangesEqual(const Range* a, const Range* b) { 1505 bool AreRangesEqual(const Range* a, const Range* b) {
1512 if (a == b) 1506 if (a == b)
1513 return true; 1507 return true;
1514 if (!a || !b) 1508 if (!a || !b)
1515 return false; 1509 return false;
1516 return a->StartPosition() == b->StartPosition() && 1510 return a->StartPosition() == b->StartPosition() &&
1517 a->EndPosition() == b->EndPosition(); 1511 a->EndPosition() == b->EndPosition();
1518 } 1512 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 .data() 1828 .data()
1835 << "start offset: " << range->startOffset() 1829 << "start offset: " << range->startOffset()
1836 << ", end offset: " << range->endOffset(); 1830 << ", end offset: " << range->endOffset();
1837 } else { 1831 } else {
1838 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " 1832 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are "
1839 "invalid."; 1833 "invalid.";
1840 } 1834 }
1841 } 1835 }
1842 1836
1843 #endif 1837 #endif
OLDNEW
« 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