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 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { |
Xiaocheng
2017/05/05 17:14:28
Good catch!
| |
1477 return ComputeTextBounds<IntRect>(range); | 1484 return ComputeTextBounds<IntRect>(range); |
1478 } | 1485 } |
1479 | 1486 |
1487 static Vector<FloatQuad> ComputeTextQuads(const EphemeralRange& range) { | |
tkent
2017/05/07 22:55:11
Why do we need this function? Range::TextQuads can
tanvir
2017/05/08 09:10:39
Our plan is like below.
1) Next Patch will move Co
yosin_UTC9
2017/05/08 09:14:18
We'll replace Range::textQuads() with ComputeTextQ
| |
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) const { | 1499 void Range::TextQuads(Vector<FloatQuad>& quads) const { |
1489 Node* start_container = &start_.Container(); | 1500 const Vector<FloatQuad>& result = ComputeTextQuads(EphemeralRange(this)); |
1490 DCHECK(start_container); | 1501 quads.insert(quads.size(), result); |
Xiaocheng
2017/05/05 17:14:28
nit: Please use Vector::appendVector:
https://cs.
tanvir
2017/05/08 09:10:39
Done.
| |
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 } | 1502 } |
1508 | 1503 |
1509 bool AreRangesEqual(const Range* a, const Range* b) { | 1504 bool AreRangesEqual(const Range* a, const Range* b) { |
1510 if (a == b) | 1505 if (a == b) |
1511 return true; | 1506 return true; |
1512 if (!a || !b) | 1507 if (!a || !b) |
1513 return false; | 1508 return false; |
1514 return a->StartPosition() == b->StartPosition() && | 1509 return a->StartPosition() == b->StartPosition() && |
1515 a->EndPosition() == b->EndPosition(); | 1510 a->EndPosition() == b->EndPosition(); |
1516 } | 1511 } |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1832 .data() | 1827 .data() |
1833 << "start offset: " << range->startOffset() | 1828 << "start offset: " << range->startOffset() |
1834 << ", end offset: " << range->endOffset(); | 1829 << ", end offset: " << range->endOffset(); |
1835 } else { | 1830 } else { |
1836 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " | 1831 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " |
1837 "invalid."; | 1832 "invalid."; |
1838 } | 1833 } |
1839 } | 1834 } |
1840 | 1835 |
1841 #endif | 1836 #endif |
OLD | NEW |