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 // TODO(hs1217.lee):: we should move this implement to VisibleUnits and then | |
1444 // this function will remove. | |
1445 static Vector<IntRect> computeTextRects(const EphemeralRange&); | |
1446 | |
1447 IntRect Range::BoundingBox() const { | |
1448 IntRect result; | |
1449 const Vector<IntRect>& rects = computeTextRects(EphemeralRange(this)); | |
1450 for (const IntRect& rect : rects) | |
1451 result.Unite(rect); | |
1452 return result; | |
1453 } | |
1454 | |
1455 static Vector<IntRect> computeTextRects(const EphemeralRange& range) { | 1443 static Vector<IntRect> computeTextRects(const EphemeralRange& range) { |
1456 const Position& start_position = range.StartPosition(); | 1444 const Position& start_position = range.StartPosition(); |
1457 const Position& end_position = range.EndPosition(); | 1445 const Position& end_position = range.EndPosition(); |
1458 Node* const start_container = start_position.ComputeContainerNode(); | 1446 Node* const start_container = start_position.ComputeContainerNode(); |
1459 DCHECK(start_container); | 1447 DCHECK(start_container); |
1460 Node* const end_container = end_position.ComputeContainerNode(); | 1448 Node* const end_container = end_position.ComputeContainerNode(); |
1461 DCHECK(end_container); | 1449 DCHECK(end_container); |
1462 | 1450 |
1463 Vector<IntRect> rects; | 1451 Vector<IntRect> rects; |
1464 for (const Node& node : range.Nodes()) { | 1452 for (const Node& node : range.Nodes()) { |
1465 LayoutObject* const layoutObject = node.GetLayoutObject(); | 1453 LayoutObject* const layoutObject = node.GetLayoutObject(); |
1466 if (!layoutObject || !layoutObject->IsText()) | 1454 if (!layoutObject || !layoutObject->IsText()) |
1467 continue; | 1455 continue; |
1468 LayoutText* layout_text = ToLayoutText(layoutObject); | 1456 LayoutText* layout_text = ToLayoutText(layoutObject); |
1469 unsigned start_offset = | 1457 unsigned start_offset = |
1470 node == start_container ? start_position.OffsetInContainerNode() : 0; | 1458 node == start_container ? start_position.OffsetInContainerNode() : 0; |
1471 unsigned end_offset = node == end_container | 1459 unsigned end_offset = node == end_container |
1472 ? end_position.OffsetInContainerNode() | 1460 ? end_position.OffsetInContainerNode() |
1473 : std::numeric_limits<unsigned>::max(); | 1461 : std::numeric_limits<unsigned>::max(); |
1474 layout_text->AbsoluteRectsForRange(rects, start_offset, end_offset); | 1462 layout_text->AbsoluteRectsForRange(rects, start_offset, end_offset); |
1475 } | 1463 } |
1476 return rects; | 1464 return rects; |
1477 } | 1465 } |
1478 | 1466 |
| 1467 IntRect Range::BoundingBox() const { |
| 1468 IntRect result; |
| 1469 const Vector<IntRect>& rects = computeTextRects(EphemeralRange(this)); |
| 1470 for (const IntRect& rect : rects) |
| 1471 result.Unite(rect); |
| 1472 return result; |
| 1473 } |
| 1474 |
1479 void Range::TextQuads(Vector<FloatQuad>& quads, | 1475 void Range::TextQuads(Vector<FloatQuad>& quads, |
1480 bool use_selection_height) const { | 1476 bool use_selection_height) const { |
1481 Node* start_container = &start_.Container(); | 1477 Node* start_container = &start_.Container(); |
1482 DCHECK(start_container); | 1478 DCHECK(start_container); |
1483 Node* end_container = &end_.Container(); | 1479 Node* end_container = &end_.Container(); |
1484 DCHECK(end_container); | 1480 DCHECK(end_container); |
1485 | 1481 |
1486 Node* stop_node = PastLastNode(); | 1482 Node* stop_node = PastLastNode(); |
1487 for (Node* node = FirstNode(); node != stop_node; | 1483 for (Node* node = FirstNode(); node != stop_node; |
1488 node = NodeTraversal::Next(*node)) { | 1484 node = NodeTraversal::Next(*node)) { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1823 .Data() | 1819 .Data() |
1824 << "start offset: " << range->startOffset() | 1820 << "start offset: " << range->startOffset() |
1825 << ", end offset: " << range->endOffset(); | 1821 << ", end offset: " << range->endOffset(); |
1826 } else { | 1822 } else { |
1827 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " | 1823 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " |
1828 "invalid."; | 1824 "invalid."; |
1829 } | 1825 } |
1830 } | 1826 } |
1831 | 1827 |
1832 #endif | 1828 #endif |
OLD | NEW |