Commit efbe0b50 authored by yosin@chromium.org's avatar yosin@chromium.org

Make LayoutText::absoluteQuadsForRange to consider leading/trailing whitespaces

This patch makes |LayoutText::absoluteQuadsForRange| to consider leading and
trailing whitespaces by adjusting specified offsets by rendered portion of
characters.

Before this patch, |LayoutText::absoluteQuadsForRange| returns empty rectangle
for character offsets not in |InlineTextBox| objects.

BUG=389054
TEST=LayoutTests/fast/dom/Range/getClientRects-leading-trailing-whitespaces.html

Review URL: https://codereview.chromium.org/361683002

git-svn-id: svn://svn.chromium.org/blink/trunk@200828 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 74c5761f
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<div id="target"> abc </div>
<div id="log"></div>
<script>
var target = document.getElementById('target').firstChild;
function clientRectLeftOfNodeOffsetAt(offset) {
var range = document.createRange();
range.setStart(target, offset);
var rects = range.getClientRects();
return rects.length ? rects[0].left : 'no rects';
}
test(function() {
assert_equals(clientRectLeftOfNodeOffsetAt(0), clientRectLeftOfNodeOffsetAt(3), '0');
assert_equals(clientRectLeftOfNodeOffsetAt(1), clientRectLeftOfNodeOffsetAt(3), '1');
assert_equals(clientRectLeftOfNodeOffsetAt(2), clientRectLeftOfNodeOffsetAt(3), '2');
}, 'leading whitespaces');
test(function() {
assert_greater_than(clientRectLeftOfNodeOffsetAt(6), clientRectLeftOfNodeOffsetAt(5), '6');
assert_equals(clientRectLeftOfNodeOffsetAt(7), clientRectLeftOfNodeOffsetAt(6), '7');
assert_equals(clientRectLeftOfNodeOffsetAt(8), clientRectLeftOfNodeOffsetAt(6), '8');
}, 'trailing whitespaces');
</script>
...@@ -441,6 +441,14 @@ void LayoutText::absoluteQuadsForRange(Vector<FloatQuad>& quads, unsigned start, ...@@ -441,6 +441,14 @@ void LayoutText::absoluteQuadsForRange(Vector<FloatQuad>& quads, unsigned start,
start = std::min(start, static_cast<unsigned>(INT_MAX)); start = std::min(start, static_cast<unsigned>(INT_MAX));
end = std::min(end, static_cast<unsigned>(INT_MAX)); end = std::min(end, static_cast<unsigned>(INT_MAX));
const unsigned caretMinOffset = static_cast<unsigned>(this->caretMinOffset());
const unsigned caretMaxOffset = static_cast<unsigned>(this->caretMaxOffset());
// Narrows |start| and |end| into |caretMinOffset| and |careMaxOffset|
// to ignore unrendered leading and trailing whitespaces.
start = std::min(std::max(caretMinOffset, start), caretMaxOffset);
end = std::min(std::max(caretMinOffset, end), caretMaxOffset);
for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
// Note: box->end() returns the index of the last character, not the index past it // Note: box->end() returns the index of the last character, not the index past it
if (start <= box->start() && box->end() < end) { if (start <= box->start() && box->end() < end) {
......
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