Chromium Code Reviews| 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() {} | |
|
fs
2016/02/12 17:05:42
Maybe this should set the layoutObject memeer to n
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 49 SearchCandidate(LayoutObject* layoutObject, float dist) | |
|
fs
2016/02/12 17:05:43
dist -> distance
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 50 : candidateLayoutObject(layoutObject) | |
| 51 , distance(dist) | |
| 52 { | |
| 53 } | |
| 54 LayoutObject* candidateLayoutObject; | |
|
fs
2016/02/12 17:05:42
The 'candidate'-prefix seems redundant.
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 ASSERT(layoutObject); | 491 ASSERT(layoutObject); |
| 481 | 492 |
| 482 // FIXME: trying to compute a device space transform at record time is wrong . All clients | 493 // FIXME: trying to compute a device space transform at record time is wrong . All clients |
| 483 // should be updated to avoid relying on this information, and the method sh ould be removed. | 494 // should be updated to avoid relying on this information, and the method sh ould be removed. |
| 484 AffineTransform ctm = deprecatedCalculateTransformToLayer(layoutObject) * Su btreeContentTransformScope::currentContentTransformation(); | 495 AffineTransform ctm = deprecatedCalculateTransformToLayer(layoutObject) * Su btreeContentTransformScope::currentContentTransformation(); |
| 485 ctm.scale(layoutObject->document().frameHost()->deviceScaleFactor()); | 496 ctm.scale(layoutObject->document().frameHost()->deviceScaleFactor()); |
| 486 | 497 |
| 487 return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2)); | 498 return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2)); |
| 488 } | 499 } |
| 489 | 500 |
| 501 static inline bool compareCandidateDistance(const SearchCandidate& r1, const Sea rchCandidate& r2) | |
| 502 { | |
| 503 return r1.distance < r2.distance; | |
| 504 } | |
| 505 | |
| 506 static inline float distanceToChildLayoutObject(LayoutObject* child, const Float Point& point) | |
| 507 { | |
| 508 const AffineTransform& localToParentTransform = child->localToParentTransfor m(); | |
| 509 if (!localToParentTransform.isInvertible()) | |
| 510 return std::numeric_limits<float>::max(); | |
| 511 FloatPoint childLocalPoint = localToParentTransform.inverse().mapPoint(point ); | |
| 512 return child->objectBoundingBox().squaredDistanceTo(childLocalPoint); | |
| 513 } | |
| 514 | |
| 515 static SearchCandidate searchTreeForFindClosestLayoutSVGText(LayoutObject* layou tObject, const FloatPoint& point) | |
| 516 { | |
| 517 // Try to find the closest LayoutSVGText. | |
| 518 LayoutObject* closestLayoutObject = nullptr; | |
| 519 float closestDistance = std::numeric_limits<float>::max(); | |
|
fs
2016/02/12 17:05:42
Maybe put these two in a SearchCandidate too. Mayb
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 520 Vector<SearchCandidate> candidates; | |
| 521 | |
| 522 // First find LayoutSVGText on the this tree level and also find candidates. | |
|
fs
2016/02/12 17:05:43
"Find the closest LayoutSVGText on this tree level
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 523 for (LayoutObject* child = layoutObject->slowLastChild(); child; child = chi ld->previousSibling()) { | |
| 524 if (child->isSVGText()) { | |
| 525 float distance = distanceToChildLayoutObject(child, point); | |
| 526 if (distance >= closestDistance) | |
| 527 continue; | |
| 528 candidates.clear(); | |
| 529 closestLayoutObject = child; | |
| 530 closestDistance = distance; | |
| 531 continue; | |
| 532 } | |
| 533 | |
| 534 if (child->isSVGContainer() && !layoutObject->isSVGHiddenContainer()) { | |
| 535 float distance = distanceToChildLayoutObject(child, point); | |
| 536 if (distance > closestDistance) | |
| 537 continue; | |
| 538 candidates.append(SearchCandidate(child, distance)); | |
| 539 } | |
| 540 } | |
| 541 | |
| 542 // If find LayoutSVGText and don't have candidates, just return |closestLayo utObject|. | |
|
fs
2016/02/12 17:05:42
"If a LayoutSVGText was found and there are no pot
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 543 if (closestLayoutObject && candidates.isEmpty()) | |
| 544 return SearchCandidate(closestLayoutObject, closestDistance); | |
| 545 | |
| 546 std::stable_sort(candidates.begin(), candidates.end(), compareCandidateDista nce); | |
| 547 | |
| 548 SearchCandidate closestSearchCandidateText = SearchCandidate(nullptr, std::n umeric_limits<float>::max()); | |
|
fs
2016/02/12 17:05:42
SearchCandidate closestSearchCandidateText(nullptr
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 549 // Find the closest LayoutSVGText on |condidates| that is sub-trees. | |
|
fs
2016/02/12 17:05:42
"on |condidates| that is sub-trees." -> "in the su
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 550 // If find layoutSVGText on |searchCandidate| and it is closer then other |s earchCandidate|, stop iteration statement. | |
|
fs
2016/02/12 17:05:42
"If a LayoutSVGText is found that is (strictly) cl
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 551 for (SearchCandidate& searchCandidate : candidates) { | |
|
fs
2016/02/12 17:05:42
const
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 552 if (closestSearchCandidateText.distance < searchCandidate.distance) | |
| 553 break; | |
| 554 LayoutObject* candidateLayoutObject = searchCandidate.candidateLayoutObj ect; | |
| 555 FloatPoint candidateLocalPoint = candidateLayoutObject->localToParentTra nsform().inverse().mapPoint(point); | |
| 556 | |
| 557 SearchCandidate candidateText = searchTreeForFindClosestLayoutSVGText(ca ndidateLayoutObject, candidateLocalPoint); | |
| 558 | |
| 559 if (candidateText.distance < closestSearchCandidateText.distance) | |
| 560 closestSearchCandidateText = candidateText; | |
| 561 } | |
| 562 | |
| 563 // Compare distance between |closestLayoutObject| and |closestSearchCandidat eText|. | |
|
fs
2016/02/12 17:05:42
"Compare" is pretty obvious, maybe "Return the clo
hyunjunekim2
2016/02/15 13:34:21
Done. Remove if statement.
| |
| 564 if (closestDistance <= closestSearchCandidateText.distance) | |
| 565 return SearchCandidate(closestLayoutObject, closestDistance); | |
| 566 | |
| 567 return closestSearchCandidateText; | |
| 568 } | |
| 569 | |
| 570 LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObj ect, const FloatPoint& point) | |
| 571 { | |
| 572 SearchCandidate result = searchTreeForFindClosestLayoutSVGText(layoutObject, point); | |
|
fs
2016/02/12 17:05:42
Could just do:
return searchTree...(...).candidat
hyunjunekim2
2016/02/15 13:34:21
Done.
| |
| 573 return result.candidateLayoutObject; | |
| 574 } | |
| 575 | |
| 490 } // namespace blink | 576 } // namespace blink |
| OLD | NEW |