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

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
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.h ('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/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..d7d9a9a39b36332045b2685aba450bee3ef65e95 100644
--- a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
@@ -476,4 +476,72 @@ float SVGLayoutSupport::calculateScreenFontSizeScalingFactor(const LayoutObject*
return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2));
}
+LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObject, const FloatPoint& point)
+{
+ // Try to search closest |LayoutSVGText| on sub-tree of |layoutObject|.
fs 2016/01/20 15:29:29 |...| is used for variables, so this should just b
+ // 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<LayoutObject*> candidates;
fs 2016/01/20 15:29:29 Make this: struct SearchCandidate { LayoutObj
+ for (LayoutObject* child = layoutObject->slowLastChild(); child; child = child->previousSibling()) {
+ if (!child->localToParentTransform().isInvertible())
fs 2016/01/20 15:29:29 This will return identity for for example LayoutSV
+ continue;
+
+ FloatRect boundingBox = child->objectBoundingBox();
+ FloatPoint childLocalPoint = child->localToParentTransform().inverse().mapPoint(point);
+ float distance = boundingBox.squaredDistanceTo(childLocalPoint);
+
+ if (distance >= closestDistance)
+ continue;
+
+ if (child->isSVGText()) {
+ candidates.clear();
+ closestLayoutObject = child;
+ closestDistance = distance;
+ continue;
+ }
+
+ if (child->isSVGContainer() && !child->isSVGHiddenContainer())
+ candidates.append(child);
+ }
+
+ // 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.
fs 2016/01/20 15:29:29 In this day and age we have smarty functions that
+ // Because If the distance is close, the higher the priority to search |LayoutSVGText|.
+ Vector<LayoutObject*> sortedCandidates;
+ for (LayoutObject* candidate : candidates) {
+ FloatRect candidateBoundingBox = candidate->objectBoundingBox();
+ FloatPoint candidateLocalPoint = candidate->localToParentTransform().inverse().mapPoint(point);
+ float candidateDistance = candidateBoundingBox.squaredDistanceTo(candidateLocalPoint);
+
+ size_t index;
+ for (index = 0; index < sortedCandidates.size(); index++) {
+ LayoutObject* sortedCandidate = sortedCandidates.at(index);
+ FloatRect sortedCandidateBoundingBox = sortedCandidate->objectBoundingBox();
+ FloatPoint sortedCandidateLocalPoint = sortedCandidate->localToParentTransform().inverse().mapPoint(point);
+ float sortedCandidateDistance = sortedCandidateBoundingBox.squaredDistanceTo(sortedCandidateLocalPoint);
+ if (candidateDistance < sortedCandidateDistance)
+ break;
+ }
+
+ sortedCandidates.insert(index, candidate);
+ }
+ candidates.clear();
+
+ // If not find |LayoutSVGText| on this level of tree, try to search it on sub-tree of |condidate|.
+ // This vector called |sortedCandidates| is the sort in order of distance from the mouse point.
+ // If can not find the |LayoutSVGText| on |sortedCandidates|, after all return nullptr.
+ for (LayoutObject* candidate : sortedCandidates) {
+ FloatPoint candidateLocalPoint = candidate->localToParentTransform().inverse().mapPoint(point);
+ if (LayoutObject* result = findClosestLayoutSVGText(candidate, candidateLocalPoint))
+ return result;
+ }
+
+ return nullptr;
+}
+
}
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698