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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2763013002: Fix incorrect bounding box position for '\n' (Closed)
Patch Set: Refactor to populate one vector. Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/dom/Range/getBoundingClientRect-linebreak-character.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/LayoutText.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutText.cpp b/third_party/WebKit/Source/core/layout/LayoutText.cpp
index 14174575961fc7206f750c4432cc5ba811aef590..a7b0aa7f824730341cd372f57c2e641062207fc1 100644
--- a/third_party/WebKit/Source/core/layout/LayoutText.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutText.cpp
@@ -377,6 +377,8 @@ void LayoutText::absoluteRectsForRange(Vector<IntRect>& rects,
start = std::min(start, static_cast<unsigned>(INT_MAX));
end = std::min(end, static_cast<unsigned>(INT_MAX));
+ bool hasCheckedBoxInRange = false;
+
for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
// Note: box->end() returns the index of the last character, not the index
// past it
@@ -392,8 +394,22 @@ void LayoutText::absoluteRectsForRange(Vector<IntRect>& rects,
r.setX(selectionRect.x().toFloat());
}
}
+ if (!hasCheckedBoxInRange) {
+ hasCheckedBoxInRange = true;
+ rects.clear();
+ }
rects.push_back(localToAbsoluteQuad(r).enclosingBoundingBox());
- } else {
+ } else if ((box->start() <= start && start <= box->end()) ||
+ (box->start() < end && end <= box->end())) {
+ FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHeight);
+ if (!rect.isZero()) {
+ if (!hasCheckedBoxInRange) {
+ hasCheckedBoxInRange = true;
+ rects.clear();
+ }
+ rects.push_back(localToAbsoluteQuad(rect).enclosingBoundingBox());
+ }
+ } else if (!hasCheckedBoxInRange) {
// FIXME: This code is wrong. It's converting local to absolute twice.
// http://webkit.org/b/65722
FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHeight);
@@ -484,6 +500,8 @@ void LayoutText::absoluteQuadsForRange(Vector<FloatQuad>& quads,
start = std::min(std::max(caretMinOffset, start), caretMaxOffset);
end = std::min(std::max(caretMinOffset, end), caretMaxOffset);
+ bool hasCheckedBoxInRange = false;
+
for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
// Note: box->end() returns the index of the last character, not the index
// past it
@@ -499,11 +517,27 @@ void LayoutText::absoluteQuadsForRange(Vector<FloatQuad>& quads,
r.setX(selectionRect.x());
}
}
+ if (!hasCheckedBoxInRange) {
+ hasCheckedBoxInRange = true;
+ quads.clear();
+ }
quads.push_back(localToAbsoluteQuad(FloatRect(r)));
- } else {
+ } else if ((box->start() <= start && start <= box->end()) ||
+ (box->start() < end && end <= box->end())) {
FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHeight);
- if (!rect.isZero())
+ if (!rect.isZero()) {
+ if (!hasCheckedBoxInRange) {
+ hasCheckedBoxInRange = true;
+ quads.clear();
+ }
quads.push_back(localToAbsoluteQuad(rect));
+ }
+ } else if (!hasCheckedBoxInRange) {
+ // consider when the offset of range is area of leading or trailing
+ // whitespace
+ FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHeight);
+ if (!rect.isZero())
+ quads.push_back(localToAbsoluteQuad(rect).enclosingBoundingBox());
}
}
}
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/dom/Range/getBoundingClientRect-linebreak-character.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698