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

Unified Diff: third_party/WebKit/Source/core/editing/EphemeralRange.cpp

Issue 1409073004: Return EphemeralRange from Editor::findRangeOfString. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use assertion for nodes common ancestor Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698