Commit deb0172c authored by tanvir.rizvi's avatar tanvir.rizvi Committed by Commit bot

Introduce ComputeTextBounds template in Range.cpp

Currently textQuads and ComputeTextRects algorithm is
mostly same. The difference of behaviour of these two functions
can be handled efficiently by using templates.

This CL is the Second patch set to achieve the above behaviour.
This CL introduces ComputeTextBounds as template function, which
will  be used by computeTextRects only in this patch.

BUG=691198

Review-Url: https://codereview.chromium.org/2839633002
Cr-Commit-Position: refs/heads/master@{#467707}
parent 6a56addf
...@@ -1440,7 +1440,15 @@ Node* Range::PastLastNode() const { ...@@ -1440,7 +1440,15 @@ Node* Range::PastLastNode() const {
return EndPosition().NodeAsRangePastLastNode(); return EndPosition().NodeAsRangePastLastNode();
} }
static Vector<IntRect> computeTextRects(const EphemeralRange& range) { static void CollectAbsoluteBoundsForRange(unsigned start,
unsigned end,
const LayoutText& layout_text,
Vector<IntRect>& rects) {
layout_text.AbsoluteRectsForRange(rects, start, end);
}
template <typename RectType>
static Vector<RectType> ComputeTextBounds(const EphemeralRange& range) {
const Position& start_position = range.StartPosition(); const Position& start_position = range.StartPosition();
const Position& end_position = range.EndPosition(); const Position& end_position = range.EndPosition();
Node* const start_container = start_position.ComputeContainerNode(); Node* const start_container = start_position.ComputeContainerNode();
...@@ -1448,20 +1456,25 @@ static Vector<IntRect> computeTextRects(const EphemeralRange& range) { ...@@ -1448,20 +1456,25 @@ static Vector<IntRect> computeTextRects(const EphemeralRange& range) {
Node* const end_container = end_position.ComputeContainerNode(); Node* const end_container = end_position.ComputeContainerNode();
DCHECK(end_container); DCHECK(end_container);
Vector<IntRect> rects; Vector<RectType> result;
for (const Node& node : range.Nodes()) { for (const Node& node : range.Nodes()) {
LayoutObject* const layoutObject = node.GetLayoutObject(); LayoutObject* const layoutObject = node.GetLayoutObject();
if (!layoutObject || !layoutObject->IsText()) if (!layoutObject || !layoutObject->IsText())
continue; continue;
LayoutText* layout_text = ToLayoutText(layoutObject); const LayoutText* layout_text = ToLayoutText(layoutObject);
unsigned start_offset = unsigned start_offset =
node == start_container ? start_position.OffsetInContainerNode() : 0; node == start_container ? start_position.OffsetInContainerNode() : 0;
unsigned end_offset = node == end_container unsigned end_offset = node == end_container
? end_position.OffsetInContainerNode() ? end_position.OffsetInContainerNode()
: std::numeric_limits<unsigned>::max(); : std::numeric_limits<unsigned>::max();
layout_text->AbsoluteRectsForRange(rects, start_offset, end_offset); CollectAbsoluteBoundsForRange(start_offset, end_offset, *layout_text,
result);
} }
return rects; return result;
}
static Vector<IntRect> computeTextRects(const EphemeralRange& range) {
return ComputeTextBounds<IntRect>(range);
} }
IntRect Range::BoundingBox() const { IntRect Range::BoundingBox() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment