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

Unified Diff: third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.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/LayoutSVGRoot.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/LayoutSVGRoot.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp
index fbe5909f7a0917a37e843ac9a56c9a385ae59861..88950ebfdd429ea49d5ba6c08200b0fe63cf9b57 100644
--- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp
@@ -28,6 +28,7 @@
#include "core/layout/LayoutAnalyzer.h"
#include "core/layout/LayoutPart.h"
#include "core/layout/LayoutView.h"
+#include "core/layout/svg/LayoutSVGText.h"
#include "core/layout/svg/SVGLayoutSupport.h"
#include "core/layout/svg/SVGResourcesCache.h"
#include "core/paint/PaintLayer.h"
@@ -281,6 +282,56 @@ void LayoutSVGRoot::willBeRemovedFromTree()
LayoutReplaced::willBeRemovedFromTree();
}
+PositionWithAffinity LayoutSVGRoot::positionForPoint(const LayoutPoint& point)
+{
+ LayoutObject* closestDescendant = nullptr;
+ float closestDistance = std::numeric_limits<float>::max();
+ FloatPoint absolutePoint(point);
+
+ for (LayoutObject* descendant = firstChild(); descendant; descendant = descendant->nextInPreOrder(this)) {
+ if (descendant->isSVGText()) {
+ FloatRect boundaries = toLayoutSVGText(descendant)->objectBoundingBox();
+ FloatPoint closestPoint;
+ closestPoint.setX(std::max(std::min(absolutePoint.x(), boundaries.maxX()), boundaries.x()));
+ closestPoint.setY(std::max(std::min(absolutePoint.y(), boundaries.maxY()), boundaries.y()));
+ float distance = (absolutePoint - closestPoint).diagonalLengthSquared();
+
+ if (distance < closestDistance) {
+ closestDistance = distance;
+ closestDescendant = descendant;
hyunjunekim2 2016/01/11 09:13:17 1. Find closest LayoutSVGText from mouse which is
+ }
+ }
+ }
+
+ if (!closestDescendant)
+ return createPositionWithAffinity(0);
hyunjunekim2 2016/01/11 09:13:16 2. If no has LayoutSVGText, return 0.
+
+ AffineTransform transform;
+ transform.makeIdentity();
+ if (toLayoutSVGText(closestDescendant)->location().x())
+ transform.setE(toLayoutSVGText(closestDescendant)->location().x());
+ if (toLayoutSVGText(closestDescendant)->location().y())
+ transform.setF(toLayoutSVGText(closestDescendant)->location().y());
+
+ LayoutObject* layoutObject = closestDescendant;
+ while (layoutObject) {
+ layoutObject = layoutObject->parent();
+ if (layoutObject->isSVGRoot())
+ break;
+ transform = layoutObject->localToParentTransform() * transform;
+ }
+
+ transform = m_localToBorderBoxTransform * transform;
hyunjunekim2 2016/01/11 09:13:16 3. Make a Matrix M. M is (Root's child Matrix) * (
+ absolutePoint = transform.inverse().mapPoint(absolutePoint);
hyunjunekim2 2016/01/11 09:13:16 5. LayoutSVGText's local coordinate = M^-1 * point
+
+ if (absolutePoint.x() < 0)
+ absolutePoint.setX(0);
+ if (absolutePoint.y() < 0)
+ absolutePoint.setY(0);
+
+ return closestDescendant->positionForPoint(LayoutPoint(absolutePoint.x(), absolutePoint.y()));
hyunjunekim2 2016/01/11 09:13:16 6. After calculate position For Point on LayoutSVG
+}
+
// LayoutBox methods will expect coordinates w/o any transforms in coordinates
// relative to our borderBox origin. This method gives us exactly that.
void LayoutSVGRoot::buildLocalToBorderBoxTransform()
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698