Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1433 } | 1433 } |
| 1434 | 1434 |
| 1435 Node* Range::FirstNode() const { | 1435 Node* Range::FirstNode() const { |
| 1436 return StartPosition().NodeAsRangeFirstNode(); | 1436 return StartPosition().NodeAsRangeFirstNode(); |
| 1437 } | 1437 } |
| 1438 | 1438 |
| 1439 Node* Range::PastLastNode() const { | 1439 Node* Range::PastLastNode() const { |
| 1440 return EndPosition().NodeAsRangePastLastNode(); | 1440 return EndPosition().NodeAsRangePastLastNode(); |
| 1441 } | 1441 } |
| 1442 | 1442 |
| 1443 static void CollectAbsoluteBoundsForRange(unsigned start, | |
| 1444 unsigned end, | |
| 1445 const LayoutText& layout_text, | |
| 1446 Vector<IntRect>& rects) { | |
| 1447 layout_text.AbsoluteRectsForRange(rects, start, end); | |
| 1448 } | |
| 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 | |
| 1457 template <typename RectType> | |
| 1458 static Vector<RectType> ComputeTextBounds(const EphemeralRange& range) { | |
| 1459 const Position& start_position = range.StartPosition(); | |
| 1460 const Position& end_position = range.EndPosition(); | |
| 1461 Node* const start_container = start_position.ComputeContainerNode(); | |
| 1462 DCHECK(start_container); | |
| 1463 Node* const end_container = end_position.ComputeContainerNode(); | |
| 1464 DCHECK(end_container); | |
| 1465 | |
| 1466 Vector<RectType> result; | |
| 1467 for (const Node& node : range.Nodes()) { | |
| 1468 LayoutObject* const layoutObject = node.GetLayoutObject(); | |
|
Xiaocheng
2017/05/11 18:28:20
Good catch! Thanks!
| |
| 1469 if (!layoutObject || !layoutObject->IsText()) | |
| 1470 continue; | |
| 1471 const LayoutText* layout_text = ToLayoutText(layoutObject); | |
| 1472 unsigned start_offset = | |
| 1473 node == start_container ? start_position.OffsetInContainerNode() : 0; | |
| 1474 unsigned end_offset = node == end_container | |
| 1475 ? end_position.OffsetInContainerNode() | |
| 1476 : std::numeric_limits<unsigned>::max(); | |
| 1477 CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text, | |
| 1478 result); | |
| 1479 } | |
| 1480 return result; | |
| 1481 } | |
| 1482 | |
| 1483 static Vector<IntRect> ComputeTextRects(const EphemeralRange& range) { | |
| 1484 return ComputeTextBounds<IntRect>(range); | |
| 1485 } | |
| 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 | |
| 1493 IntRect Range::BoundingBox() const { | 1443 IntRect Range::BoundingBox() const { |
| 1494 IntRect result; | 1444 IntRect result; |
| 1495 const Vector<IntRect>& rects = ComputeTextRects(EphemeralRange(this)); | 1445 const Vector<IntRect>& rects = ComputeTextRects(EphemeralRange(this)); |
| 1496 for (const IntRect& rect : rects) | 1446 for (const IntRect& rect : rects) |
| 1497 result.Unite(rect); | 1447 result.Unite(rect); |
| 1498 return result; | 1448 return result; |
| 1499 } | 1449 } |
| 1500 | 1450 |
| 1451 // TODO(tanvir.rizvi): We will replace Range::TextQuads with | |
| 1452 // ComputeTextQuads(in VisibleUnits) and get rid of Range::TextQuads. | |
| 1501 void Range::TextQuads(Vector<FloatQuad>& quads) const { | 1453 void Range::TextQuads(Vector<FloatQuad>& quads) const { |
| 1502 quads.AppendVector(ComputeTextQuads(EphemeralRange(this))); | 1454 quads.AppendVector(ComputeTextQuads(EphemeralRange(this))); |
| 1503 } | 1455 } |
| 1504 | 1456 |
| 1505 bool AreRangesEqual(const Range* a, const Range* b) { | 1457 bool AreRangesEqual(const Range* a, const Range* b) { |
| 1506 if (a == b) | 1458 if (a == b) |
| 1507 return true; | 1459 return true; |
| 1508 if (!a || !b) | 1460 if (!a || !b) |
| 1509 return false; | 1461 return false; |
| 1510 return a->StartPosition() == b->StartPosition() && | 1462 return a->StartPosition() == b->StartPosition() && |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1828 .data() | 1780 .data() |
| 1829 << "start offset: " << range->startOffset() | 1781 << "start offset: " << range->startOffset() |
| 1830 << ", end offset: " << range->endOffset(); | 1782 << ", end offset: " << range->endOffset(); |
| 1831 } else { | 1783 } else { |
| 1832 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " | 1784 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " |
| 1833 "invalid."; | 1785 "invalid."; |
| 1834 } | 1786 } |
| 1835 } | 1787 } |
| 1836 | 1788 |
| 1837 #endif | 1789 #endif |
| OLD | NEW |