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

Unified Diff: third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp

Issue 1541083002: Fix invalid selection produced when dragging mouse outside the SVG text element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/layout/svg/SVGLayoutSupport.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
index 32073042bd914cd8999f8fd2c593feade0f70a23..4c109b2ae26434a6930074a0d4b0096e57909ea1 100644
--- a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
@@ -476,4 +476,60 @@ float SVGLayoutSupport::calculateScreenFontSizeScalingFactor(const LayoutObject*
return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2));
}
+bool SVGLayoutSupport::compareCandidateDistance(const SearchCandidate r1, const SearchCandidate r2)
+{
+ return r1.distance < r2.distance;
+}
+
+LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObject, const FloatPoint& point)
+{
+ // Try to search closest LayoutSVGText on sub-tree of |layoutObject|.
+ // On this level of tree, try to find the closest LayoutSVGText. If not find this level, try to search
+ // next level which is candidates.
+ LayoutObject* closestLayoutObject = nullptr;
+ float closestDistance = std::numeric_limits<float>::max();
+ Vector<SearchCandidate> candidates;
+ for (LayoutObject* child = layoutObject->slowLastChild(); child; child = child->previousSibling()) {
+ if (child->isSVGHiddenContainer() || !child->localToParentTransform().isInvertible())
fs 2016/01/21 14:27:15 Marginally better than before. I think it'd better
hyunjunekim2 2016/01/21 15:14:05 I separated it.
+ continue;
+
+ FloatRect boundingBox = child->objectBoundingBox();
+ FloatPoint childLocalPoint = child->localToParentTransform().inverse().mapPoint(point);
+ float distance = boundingBox.squaredDistanceTo(childLocalPoint);
+
+ if (distance >= closestDistance)
fs 2016/01/21 14:27:16 If distance == closestDistance and !child->isSVGTe
hyunjunekim2 2016/01/21 15:14:05 I contained it in that case.
+ continue;
+
+ if (child->isSVGText()) {
+ candidates.clear();
+ closestLayoutObject = child;
+ closestDistance = distance;
+ continue;
+ }
+
+ if (child->isSVGContainer())
+ candidates.append(SearchCandidate(child, distance));
+ }
+
+ // If find LayoutSVGText this level of tree, return it.
+ if (closestLayoutObject && closestLayoutObject->isSVGText())
+ return closestLayoutObject;
+
+ // Sort using the distance between the mouse point and a candidate.
+ // Because if the distance is close, It is high priority to search LayoutSVGText.
+ std::stable_sort(candidates.begin(), candidates.end(), compareCandidateDistance);
+
+ // If not find LayoutSVGText on this level of tree, try to search it on sub-tree of |condidate|.
+ // This vector called |candidates| is the sort in order of distance from the mouse point.
+ // If can not find the LayoutSVGText on |candidates|, after all return nullptr.
+ for (SearchCandidate searchCandidate : candidates) {
fs 2016/01/21 14:27:16 Use reference.
+ LayoutObject* candidateLayoutObject = searchCandidate.candidateLayoutObject;
+ FloatPoint candidateLocalPoint = candidateLayoutObject->localToParentTransform().inverse().mapPoint(point);
+ if (LayoutObject* result = findClosestLayoutSVGText(candidateLayoutObject, candidateLocalPoint))
+ return result;
+ }
+
+ return nullptr;
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698