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 26 matching lines...) Expand all Loading... | |
37 #include "core/layout/svg/LayoutSVGViewportContainer.h" | 37 #include "core/layout/svg/LayoutSVGViewportContainer.h" |
38 #include "core/layout/svg/SVGResources.h" | 38 #include "core/layout/svg/SVGResources.h" |
39 #include "core/layout/svg/SVGResourcesCache.h" | 39 #include "core/layout/svg/SVGResourcesCache.h" |
40 #include "core/paint/PaintLayer.h" | 40 #include "core/paint/PaintLayer.h" |
41 #include "core/svg/SVGElement.h" | 41 #include "core/svg/SVGElement.h" |
42 #include "platform/geometry/TransformState.h" | 42 #include "platform/geometry/TransformState.h" |
43 #include "platform/graphics/StrokeData.h" | 43 #include "platform/graphics/StrokeData.h" |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 struct SearchCandidate { | |
48 SearchCandidate() {} | |
49 SearchCandidate(LayoutObject* layoutObject, float dist) | |
50 : candidateLayoutObject(layoutObject) | |
51 , distance(dist) | |
52 { | |
53 } | |
54 LayoutObject* candidateLayoutObject; | |
55 float distance; | |
56 }; | |
57 | |
47 static inline LayoutRect adjustedEnclosingIntRect(const FloatRect& rect, | 58 static inline LayoutRect adjustedEnclosingIntRect(const FloatRect& rect, |
48 const AffineTransform& rootTransform, float strokeWidthForHairlinePadding) | 59 const AffineTransform& rootTransform, float strokeWidthForHairlinePadding) |
49 { | 60 { |
50 FloatRect adjustedRect = rect; | 61 FloatRect adjustedRect = rect; |
51 | 62 |
52 if (strokeWidthForHairlinePadding) { | 63 if (strokeWidthForHairlinePadding) { |
53 // For hairline strokes (stroke-width < 1 in device space), Skia rasteri zes up to 0.4(9) off | 64 // For hairline strokes (stroke-width < 1 in device space), Skia rasteri zes up to 0.4(9) off |
54 // the stroke center. That means enclosingIntRect is not enough - we mus t also pad to 0.5. | 65 // the stroke center. That means enclosingIntRect is not enough - we mus t also pad to 0.5. |
55 // This is still fragile as it misses out on CC/DSF CTM components. | 66 // This is still fragile as it misses out on CC/DSF CTM components. |
56 const FloatSize strokeSize = rootTransform.mapSize( | 67 const FloatSize strokeSize = rootTransform.mapSize( |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 ASSERT(layoutObject); | 480 ASSERT(layoutObject); |
470 | 481 |
471 // FIXME: trying to compute a device space transform at record time is wrong . All clients | 482 // 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. | 483 // should be updated to avoid relying on this information, and the method sh ould be removed. |
473 AffineTransform ctm = deprecatedCalculateTransformToLayer(layoutObject) * Su btreeContentTransformScope::currentContentTransformation(); | 484 AffineTransform ctm = deprecatedCalculateTransformToLayer(layoutObject) * Su btreeContentTransformScope::currentContentTransformation(); |
474 ctm.scale(layoutObject->document().frameHost()->deviceScaleFactor()); | 485 ctm.scale(layoutObject->document().frameHost()->deviceScaleFactor()); |
475 | 486 |
476 return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2)); | 487 return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2)); |
477 } | 488 } |
478 | 489 |
490 static inline bool compareCandidateDistance(const SearchCandidate& r1, const Sea rchCandidate& r2) | |
491 { | |
492 return r1.distance < r2.distance; | |
479 } | 493 } |
494 | |
495 static inline float distanceToChildLayoutObject(LayoutObject* child, const Float Point& point) | |
496 { | |
497 const AffineTransform& localToParentTransform = child->localToParentTransfor m(); | |
498 if (!localToParentTransform.isInvertible()) | |
499 return std::numeric_limits<float>::max(); | |
500 FloatPoint childLocalPoint = localToParentTransform.inverse().mapPoint(point ); | |
501 return child->objectBoundingBox().squaredDistanceTo(childLocalPoint); | |
502 } | |
503 | |
504 LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObj ect, const FloatPoint& point) | |
505 { | |
506 // Try to find the closest LayoutSVGText. If not find the closest LayoutSVGT ext, try to search on candidates. | |
507 LayoutObject* closestLayoutObject = nullptr; | |
508 float closestDistance = std::numeric_limits<float>::max(); | |
509 Vector<SearchCandidate> candidates; | |
510 for (LayoutObject* child = layoutObject->slowLastChild(); child; child = chi ld->previousSibling()) { | |
511 if (child->isSVGText()) { | |
512 float distance = distanceToChildLayoutObject(child, point); | |
513 if (distance >= closestDistance) | |
514 continue; | |
515 candidates.clear(); | |
516 closestLayoutObject = child; | |
517 closestDistance = distance; | |
518 continue; | |
519 } | |
520 | |
521 if (child->isSVGContainer() && !layoutObject->isSVGHiddenContainer()) { | |
522 float distance = distanceToChildLayoutObject(child, point); | |
523 if (distance > closestDistance) | |
524 continue; | |
525 candidates.append(SearchCandidate(child, distance)); | |
526 } | |
527 } | |
528 | |
529 if (closestLayoutObject && candidates.isEmpty()) | |
fs
2016/01/26 14:24:01
Now closestLayoutObject need to be considered some
hyunjunekim2
2016/01/26 14:43:17
Do you means somehow which check overlap?
Could
hyunjunekim2
2016/01/26 14:53:17
I guess that
if ((!closestLayoutObject || closest
| |
530 return closestLayoutObject; | |
531 | |
532 // Sort using the distance between the mouse point and a candidate. | |
533 // Because if the distance is close, It is high priority to search LayoutSVG Text. | |
534 std::stable_sort(candidates.begin(), candidates.end(), compareCandidateDista nce); | |
535 | |
536 // Try to find the closest LayoutSVGText on candidates. | |
537 for (SearchCandidate& searchCandidate : candidates) { | |
538 LayoutObject* candidateLayoutObject = searchCandidate.candidateLayoutObj ect; | |
539 FloatPoint candidateLocalPoint = candidateLayoutObject->localToParentTra nsform().inverse().mapPoint(point); | |
540 if (LayoutObject* result = findClosestLayoutSVGText(candidateLayoutObjec t, candidateLocalPoint)) | |
541 return result; | |
542 } | |
543 | |
544 return nullptr; | |
545 } | |
546 | |
547 } | |
OLD | NEW |