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

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

Issue 2839633002: Introduce ComputeTextBounds template in Range.cpp (Closed)
Patch Set: AddressedReviewComments 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 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Vector<IntRect> computeTextRects(const EphemeralRange& range) { 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 template <typename RectType>
1451 static Vector<RectType> ComputeTextBounds(const EphemeralRange& range) {
1444 const Position& start_position = range.StartPosition(); 1452 const Position& start_position = range.StartPosition();
1445 const Position& end_position = range.EndPosition(); 1453 const Position& end_position = range.EndPosition();
1446 Node* const start_container = start_position.ComputeContainerNode(); 1454 Node* const start_container = start_position.ComputeContainerNode();
1447 DCHECK(start_container); 1455 DCHECK(start_container);
1448 Node* const end_container = end_position.ComputeContainerNode(); 1456 Node* const end_container = end_position.ComputeContainerNode();
1449 DCHECK(end_container); 1457 DCHECK(end_container);
1450 1458
1451 Vector<IntRect> rects; 1459 Vector<RectType> result;
1452 for (const Node& node : range.Nodes()) { 1460 for (const Node& node : range.Nodes()) {
1453 LayoutObject* const layoutObject = node.GetLayoutObject(); 1461 LayoutObject* const layoutObject = node.GetLayoutObject();
1454 if (!layoutObject || !layoutObject->IsText()) 1462 if (!layoutObject || !layoutObject->IsText())
1455 continue; 1463 continue;
1456 LayoutText* layout_text = ToLayoutText(layoutObject); 1464 const LayoutText* layout_text = ToLayoutText(layoutObject);
1457 unsigned start_offset = 1465 unsigned start_offset =
1458 node == start_container ? start_position.OffsetInContainerNode() : 0; 1466 node == start_container ? start_position.OffsetInContainerNode() : 0;
1459 unsigned end_offset = node == end_container 1467 unsigned end_offset = node == end_container
1460 ? end_position.OffsetInContainerNode() 1468 ? end_position.OffsetInContainerNode()
1461 : std::numeric_limits<unsigned>::max(); 1469 : std::numeric_limits<unsigned>::max();
1462 layout_text->AbsoluteRectsForRange(rects, start_offset, end_offset); 1470 CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text,
1471 result);
1463 } 1472 }
1464 return rects; 1473 return result;
1474 }
1475
1476 static Vector<IntRect> computeTextRects(const EphemeralRange& range) {
1477 return ComputeTextBounds<IntRect>(range);
1465 } 1478 }
1466 1479
1467 IntRect Range::BoundingBox() const { 1480 IntRect Range::BoundingBox() const {
1468 IntRect result; 1481 IntRect result;
1469 const Vector<IntRect>& rects = computeTextRects(EphemeralRange(this)); 1482 const Vector<IntRect>& rects = computeTextRects(EphemeralRange(this));
1470 for (const IntRect& rect : rects) 1483 for (const IntRect& rect : rects)
1471 result.Unite(rect); 1484 result.Unite(rect);
1472 return result; 1485 return result;
1473 } 1486 }
1474 1487
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 .data() 1834 .data()
1822 << "start offset: " << range->startOffset() 1835 << "start offset: " << range->startOffset()
1823 << ", end offset: " << range->endOffset(); 1836 << ", end offset: " << range->endOffset();
1824 } else { 1837 } else {
1825 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " 1838 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are "
1826 "invalid."; 1839 "invalid.";
1827 } 1840 }
1828 } 1841 }
1829 1842
1830 #endif 1843 #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