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

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, 10 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 51f3e979d94c282abea135b758f13e1e66e1813a..0ef490f7e6432dad0aebf27ea006d6169130d36a 100644
--- a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
@@ -44,6 +44,17 @@
namespace blink {
+struct SearchCandidate {
+ SearchCandidate() {}
+ SearchCandidate(LayoutObject* layoutObject, float dist)
+ : candidateLayoutObject(layoutObject)
+ , distance(dist)
+ {
+ }
+ LayoutObject* candidateLayoutObject;
+ float distance;
+};
+
static inline LayoutRect adjustedEnclosingIntRect(const FloatRect& rect,
const AffineTransform& rootTransform, float strokeWidthForHairlinePadding)
{
@@ -476,4 +487,72 @@ float SVGLayoutSupport::calculateScreenFontSizeScalingFactor(const LayoutObject*
return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2));
}
+static inline bool compareCandidateDistance(const SearchCandidate& r1, const SearchCandidate& r2)
+{
+ return r1.distance < r2.distance;
+}
+
+static inline float distanceToChildLayoutObject(LayoutObject* child, const FloatPoint& point)
+{
+ const AffineTransform& localToParentTransform = child->localToParentTransform();
+ if (!localToParentTransform.isInvertible())
+ return std::numeric_limits<float>::max();
+ FloatPoint childLocalPoint = localToParentTransform.inverse().mapPoint(point);
+ return child->objectBoundingBox().squaredDistanceTo(childLocalPoint);
+}
+
+static SearchCandidate searchTreeForFindClosestLayoutSVGText(LayoutObject* layoutObject, const FloatPoint& point)
+{
+ LayoutObject* closestLayoutObject = nullptr;
+ float closestDistance = std::numeric_limits<float>::max();
+ Vector<SearchCandidate> candidates;
+ for (LayoutObject* child = layoutObject->slowLastChild(); child; child = child->previousSibling()) {
+ if (child->isSVGText()) {
+ float distance = distanceToChildLayoutObject(child, point);
+ if (distance >= closestDistance)
+ continue;
+ candidates.clear();
+ closestLayoutObject = child;
+ closestDistance = distance;
+ continue;
+ }
+
+ if (child->isSVGContainer() && !layoutObject->isSVGHiddenContainer()) {
+ float distance = distanceToChildLayoutObject(child, point);
+ if (distance > closestDistance)
+ continue;
+ candidates.append(SearchCandidate(child, distance));
+ }
+ }
+
+ if (closestLayoutObject && candidates.isEmpty())
+ return SearchCandidate(closestLayoutObject, closestDistance);
+
+ std::stable_sort(candidates.begin(), candidates.end(), compareCandidateDistance);
+
+ SearchCandidate closestSearchCandidateText = SearchCandidate(nullptr, std::numeric_limits<float>::max());
+ for (SearchCandidate& searchCandidate : candidates) {
hyunjunekim2 2016/02/08 10:41:01 We should find the closest LayoutSVGText on condid
+ if (closestSearchCandidateText.distance < searchCandidate.distance)
hyunjunekim2 2016/02/08 10:41:01 We are not all traversal. If |closestSearchCandida
+ break;
+ LayoutObject* candidateLayoutObject = searchCandidate.candidateLayoutObject;
+ FloatPoint candidateLocalPoint = candidateLayoutObject->localToParentTransform().inverse().mapPoint(point);
+
+ SearchCandidate candidateText = searchTreeForFindClosestLayoutSVGText(candidateLayoutObject, candidateLocalPoint);
+
+ if (candidateText.distance < closestSearchCandidateText.distance)
+ closestSearchCandidateText = candidateText;
+ }
+
+ if (closestDistance <= closestSearchCandidateText.distance)
+ return SearchCandidate(closestLayoutObject, closestDistance);
+
+ return closestSearchCandidateText;
+}
+
+LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObject, const FloatPoint& point)
+{
+ SearchCandidate result = searchTreeForFindClosestLayoutSVGText(layoutObject, point);
+ return result.candidateLayoutObject;
+}
+
} // namespace blink
« 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