OLD | NEW |
---|---|
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 Loading... | |
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 LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObj ect, const FloatPoint& point) | |
480 { | |
481 // 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
| |
482 // On this level of tree, try to find the closest |LayoutSVGText|. If not fi nd this level, try to search | |
483 // next level which is candidates. | |
484 LayoutObject* closestLayoutObject = nullptr; | |
485 float closestDistance = std::numeric_limits<float>::max(); | |
486 Vector<LayoutObject*> candidates; | |
fs
2016/01/20 15:29:29
Make this:
struct SearchCandidate {
LayoutObj
| |
487 for (LayoutObject* child = layoutObject->slowLastChild(); child; child = chi ld->previousSibling()) { | |
488 if (!child->localToParentTransform().isInvertible()) | |
fs
2016/01/20 15:29:29
This will return identity for for example LayoutSV
| |
489 continue; | |
490 | |
491 FloatRect boundingBox = child->objectBoundingBox(); | |
492 FloatPoint childLocalPoint = child->localToParentTransform().inverse().m apPoint(point); | |
493 float distance = boundingBox.squaredDistanceTo(childLocalPoint); | |
494 | |
495 if (distance >= closestDistance) | |
496 continue; | |
497 | |
498 if (child->isSVGText()) { | |
499 candidates.clear(); | |
500 closestLayoutObject = child; | |
501 closestDistance = distance; | |
502 continue; | |
503 } | |
504 | |
505 if (child->isSVGContainer() && !child->isSVGHiddenContainer()) | |
506 candidates.append(child); | |
507 } | |
508 | |
509 // If find |LayoutSVGText| this level of tree, return it. | |
510 if (closestLayoutObject && closestLayoutObject->isSVGText()) | |
511 return closestLayoutObject; | |
512 | |
513 // 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
| |
514 // Because If the distance is close, the higher the priority to search |Layo utSVGText|. | |
515 Vector<LayoutObject*> sortedCandidates; | |
516 for (LayoutObject* candidate : candidates) { | |
517 FloatRect candidateBoundingBox = candidate->objectBoundingBox(); | |
518 FloatPoint candidateLocalPoint = candidate->localToParentTransform().inv erse().mapPoint(point); | |
519 float candidateDistance = candidateBoundingBox.squaredDistanceTo(candida teLocalPoint); | |
520 | |
521 size_t index; | |
522 for (index = 0; index < sortedCandidates.size(); index++) { | |
523 LayoutObject* sortedCandidate = sortedCandidates.at(index); | |
524 FloatRect sortedCandidateBoundingBox = sortedCandidate->objectBoundi ngBox(); | |
525 FloatPoint sortedCandidateLocalPoint = sortedCandidate->localToParen tTransform().inverse().mapPoint(point); | |
526 float sortedCandidateDistance = sortedCandidateBoundingBox.squaredDi stanceTo(sortedCandidateLocalPoint); | |
527 if (candidateDistance < sortedCandidateDistance) | |
528 break; | |
529 } | |
530 | |
531 sortedCandidates.insert(index, candidate); | |
532 } | |
533 candidates.clear(); | |
534 | |
535 // If not find |LayoutSVGText| on this level of tree, try to search it on su b-tree of |condidate|. | |
536 // This vector called |sortedCandidates| is the sort in order of distance fr om the mouse point. | |
537 // If can not find the |LayoutSVGText| on |sortedCandidates|, after all retu rn nullptr. | |
538 for (LayoutObject* candidate : sortedCandidates) { | |
539 FloatPoint candidateLocalPoint = candidate->localToParentTransform().inv erse().mapPoint(point); | |
540 if (LayoutObject* result = findClosestLayoutSVGText(candidate, candidate LocalPoint)) | |
541 return result; | |
542 } | |
543 | |
544 return nullptr; | |
479 } | 545 } |
546 | |
547 } | |
OLD | NEW |