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

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: updated with nit's 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;
1460 for (const Node& node : range.Nodes()) { 1467 for (const Node& node : range.Nodes()) {
1461 LayoutObject* const layoutObject = node.GetLayoutObject(); 1468 LayoutObject* const layoutObject = node.GetLayoutObject();
1462 if (!layoutObject || !layoutObject->IsText()) 1469 if (!layoutObject || !layoutObject->IsText())
1463 continue; 1470 continue;
1464 const LayoutText* layout_text = ToLayoutText(layoutObject); 1471 const LayoutText* layout_text = ToLayoutText(layoutObject);
1465 unsigned start_offset = 1472 unsigned start_offset =
1466 node == start_container ? start_position.OffsetInContainerNode() : 0; 1473 node == start_container ? start_position.OffsetInContainerNode() : 0;
1467 unsigned end_offset = node == end_container 1474 unsigned end_offset = node == end_container
1468 ? end_position.OffsetInContainerNode() 1475 ? end_position.OffsetInContainerNode()
1469 : std::numeric_limits<unsigned>::max(); 1476 : std::numeric_limits<unsigned>::max();
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 // TODO(tanvir.rizvi): We will replace Range::TextQuads with ComputeTextQuads
1488 // and get rid of Range::TextQuads.
1489 static Vector<FloatQuad> ComputeTextQuads(const EphemeralRange& range) {
1490 return ComputeTextBounds<FloatQuad>(range);
1491 }
1492
1480 IntRect Range::BoundingBox() const { 1493 IntRect Range::BoundingBox() const {
1481 IntRect result; 1494 IntRect result;
1482 const Vector<IntRect>& rects = computeTextRects(EphemeralRange(this)); 1495 const Vector<IntRect>& rects = ComputeTextRects(EphemeralRange(this));
1483 for (const IntRect& rect : rects) 1496 for (const IntRect& rect : rects)
1484 result.Unite(rect); 1497 result.Unite(rect);
1485 return result; 1498 return result;
1486 } 1499 }
1487 1500
1488 void Range::TextQuads(Vector<FloatQuad>& quads) const { 1501 void Range::TextQuads(Vector<FloatQuad>& quads) const {
1489 Node* start_container = &start_.Container(); 1502 quads.AppendVector(ComputeTextQuads(EphemeralRange(this)));
1490 DCHECK(start_container);
1491 Node* end_container = &end_.Container();
1492 DCHECK(end_container);
1493
1494 Node* stop_node = PastLastNode();
1495 for (Node* node = FirstNode(); node != stop_node;
1496 node = NodeTraversal::Next(*node)) {
1497 LayoutObject* r = node->GetLayoutObject();
1498 if (!r || !r->IsText())
1499 continue;
1500 LayoutText* layout_text = ToLayoutText(r);
1501 unsigned start_offset = node == start_container ? start_.Offset() : 0;
1502 unsigned end_offset = node == end_container
1503 ? end_.Offset()
1504 : std::numeric_limits<unsigned>::max();
1505 layout_text->AbsoluteQuadsForRange(quads, start_offset, end_offset);
1506 }
1507 } 1503 }
1508 1504
1509 bool AreRangesEqual(const Range* a, const Range* b) { 1505 bool AreRangesEqual(const Range* a, const Range* b) {
1510 if (a == b) 1506 if (a == b)
1511 return true; 1507 return true;
1512 if (!a || !b) 1508 if (!a || !b)
1513 return false; 1509 return false;
1514 return a->StartPosition() == b->StartPosition() && 1510 return a->StartPosition() == b->StartPosition() &&
1515 a->EndPosition() == b->EndPosition(); 1511 a->EndPosition() == b->EndPosition();
1516 } 1512 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 .data() 1828 .data()
1833 << "start offset: " << range->startOffset() 1829 << "start offset: " << range->startOffset()
1834 << ", end offset: " << range->endOffset(); 1830 << ", end offset: " << range->endOffset();
1835 } else { 1831 } else {
1836 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 "
1837 "invalid."; 1833 "invalid.";
1838 } 1834 }
1839 } 1835 }
1840 1836
1841 #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