Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/EphemeralRange.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/EphemeralRange.cpp b/third_party/WebKit/Source/core/editing/EphemeralRange.cpp |
| index a578146ae9e2cb48ea7aad6e06331b761e872981..f9e4050966e94c0b8f43fab4fa3951e8edb6a755 100644 |
| --- a/third_party/WebKit/Source/core/editing/EphemeralRange.cpp |
| +++ b/third_party/WebKit/Source/core/editing/EphemeralRange.cpp |
| @@ -9,6 +9,7 @@ |
| #include "core/dom/Element.h" |
| #include "core/dom/Range.h" |
| #include "core/dom/Text.h" |
| +#include "core/layout/LayoutText.h" |
| namespace blink { |
| @@ -123,6 +124,44 @@ EphemeralRangeTemplate<Strategy> EphemeralRangeTemplate<Strategy>::rangeOfConten |
| return EphemeralRangeTemplate<Strategy>(PositionTemplate<Strategy>::firstPositionInNode(&const_cast<Node&>(node)), PositionTemplate<Strategy>::lastPositionInNode(&const_cast<Node&>(node))); |
| } |
| +static IntRect uniteRects(const Vector<IntRect>& rects) |
| +{ |
| + IntRect result; |
| + for (const auto& rect : rects) |
| + result.unite(rect); |
| + return result; |
| +} |
| + |
| +template <typename Strategy> |
| +IntRect EphemeralRangeTemplate<Strategy>::textBoundingBox() const |
|
yosin_UTC9
2015/11/02 03:44:17
Rather than copying code from Range::textRects(),
Andrey Kraynov
2015/11/02 14:06:57
I tried to do it.
Pros: it can be used to shorten
|
| +{ |
| + if (isCollapsed()) |
| + return IntRect(); |
| + |
| + Node* const startContainer = m_startPosition.computeContainerNode(); |
| + ASSERT(startContainer); |
| + Node* const endContainer = m_endPosition.computeContainerNode(); |
| + ASSERT(endContainer); |
| + |
| + IntRect result; |
| + Vector<IntRect> rects; |
| + Node* stopNode = m_endPosition.nodeAsRangePastLastNode(); |
| + for (Node* node = m_startPosition.nodeAsRangeFirstNode(); node != stopNode; node = Strategy::next(*node)) { |
| + LayoutObject* const layoutObject = node->layoutObject(); |
| + if (!layoutObject || !layoutObject->isText()) |
| + continue; |
| + |
| + const int startOffset = node == startContainer ? m_startPosition.computeOffsetInContainerNode() : 0; |
| + const int endOffset = node == endContainer ? m_endPosition.computeOffsetInContainerNode() : std::numeric_limits<int>::max(); |
| + toLayoutText(layoutObject)->absoluteRectsForRange(rects, startOffset, endOffset); |
| + |
| + result.unite(uniteRects(rects)); |
| + rects.clear(); |
| + } |
| + |
| + return result; |
| +} |
| + |
| #if ENABLE(ASSERT) |
| template <typename Strategy> |
| bool EphemeralRangeTemplate<Strategy>::isValid() const |