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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org> 2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc. All rights reserved. 5 * Copyright (C) 2009 Google, Inc. All rights reserved.
6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 ASSERT(layoutObject); 469 ASSERT(layoutObject);
470 470
471 // FIXME: trying to compute a device space transform at record time is wrong . All clients 471 // FIXME: trying to compute a device space transform at record time is wrong . All clients
472 // should be updated to avoid relying on this information, and the method sh ould be removed. 472 // should be updated to avoid relying on this information, and the method sh ould be removed.
473 AffineTransform ctm = deprecatedCalculateTransformToLayer(layoutObject) * Su btreeContentTransformScope::currentContentTransformation(); 473 AffineTransform ctm = deprecatedCalculateTransformToLayer(layoutObject) * Su btreeContentTransformScope::currentContentTransformation();
474 ctm.scale(layoutObject->document().frameHost()->deviceScaleFactor()); 474 ctm.scale(layoutObject->document().frameHost()->deviceScaleFactor());
475 475
476 return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2)); 476 return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2));
477 } 477 }
478 478
479 bool SVGLayoutSupport::compareCandidateDistance(const SearchCandidate r1, const SearchCandidate r2)
480 {
481 return r1.distance < r2.distance;
479 } 482 }
483
484 LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObj ect, const FloatPoint& point)
485 {
486 // Try to search closest LayoutSVGText on sub-tree of |layoutObject|.
487 // On this level of tree, try to find the closest LayoutSVGText. If not find this level, try to search
488 // next level which is candidates.
489 LayoutObject* closestLayoutObject = nullptr;
490 float closestDistance = std::numeric_limits<float>::max();
491 Vector<SearchCandidate> candidates;
492 for (LayoutObject* child = layoutObject->slowLastChild(); child; child = chi ld->previousSibling()) {
493 if (child->isSVGHiddenContainer() || !child->localToParentTransform().is Invertible())
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.
494 continue;
495
496 FloatRect boundingBox = child->objectBoundingBox();
497 FloatPoint childLocalPoint = child->localToParentTransform().inverse().m apPoint(point);
498 float distance = boundingBox.squaredDistanceTo(childLocalPoint);
499
500 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.
501 continue;
502
503 if (child->isSVGText()) {
504 candidates.clear();
505 closestLayoutObject = child;
506 closestDistance = distance;
507 continue;
508 }
509
510 if (child->isSVGContainer())
511 candidates.append(SearchCandidate(child, distance));
512 }
513
514 // If find LayoutSVGText this level of tree, return it.
515 if (closestLayoutObject && closestLayoutObject->isSVGText())
516 return closestLayoutObject;
517
518 // Sort using the distance between the mouse point and a candidate.
519 // Because if the distance is close, It is high priority to search LayoutSVG Text.
520 std::stable_sort(candidates.begin(), candidates.end(), compareCandidateDista nce);
521
522 // If not find LayoutSVGText on this level of tree, try to search it on sub- tree of |condidate|.
523 // This vector called |candidates| is the sort in order of distance from the mouse point.
524 // If can not find the LayoutSVGText on |candidates|, after all return nullp tr.
525 for (SearchCandidate searchCandidate : candidates) {
fs 2016/01/21 14:27:16 Use reference.
526 LayoutObject* candidateLayoutObject = searchCandidate.candidateLayoutObj ect;
527 FloatPoint candidateLocalPoint = candidateLayoutObject->localToParentTra nsform().inverse().mapPoint(point);
528 if (LayoutObject* result = findClosestLayoutSVGText(candidateLayoutObjec t, candidateLocalPoint))
529 return result;
530 }
531
532 return nullptr;
533 }
534
535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698