Changeset 106016 in webkit


Ignore:
Timestamp:
Jan 26, 2012 11:18:18 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

REGRESSION (r91125): Polyline tool in google docs is broken
https://bugs.webkit.org/show_bug.cgi?id=65796

Patch by Stephen Chenney <schenney@chromium.org> on 2012-01-26
Reviewed by Nikolas Zimmermann.

It turns out that the CG problem is a design decision. The bounding code
returns CGRectNull for cases where a bound is ill-defined, rather than the
empty bound as expected.

I'm also removing the workaround for isEmpty to get correct zero length paths.
It is no longer necessary.

Tested by existing layout tests.

  • platform/graphics/cg/PathCG.cpp: Removed path empty and path bound testing classes.

(WebCore::Path::boundingRect): Added check for CGRectNull
(WebCore::Path::fastBoundingRect): Added check for CGRectNull
(WebCore::Path::strokeBoundingRect): Added check for CGRectNull
(WebCore::Path::isEmpty): Reverted to former behavior, just using CGPathIsEmpty.
(WebCore::Path::hasCurrentPoint): Reverted to former behavior, using isEmpty.
(WebCore::Path::transform): Reverted to former behavior, using isEmpty.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106015 r106016  
     12012-01-26  Stephen Chenney  <schenney@chromium.org>
     2
     3        REGRESSION (r91125): Polyline tool in google docs is broken
     4        https://bugs.webkit.org/show_bug.cgi?id=65796
     5
     6        Reviewed by Nikolas Zimmermann.
     7
     8        It turns out that the CG problem is a design decision. The bounding code
     9        returns CGRectNull for cases where a bound is ill-defined, rather than the
     10        empty bound as expected.
     11
     12        I'm also removing the workaround for isEmpty to get correct zero length paths.
     13        It is no longer necessary.
     14
     15        Tested by existing layout tests.
     16
     17        * platform/graphics/cg/PathCG.cpp: Removed path empty and path bound testing classes.
     18        (WebCore::Path::boundingRect): Added check for CGRectNull
     19        (WebCore::Path::fastBoundingRect): Added check for CGRectNull
     20        (WebCore::Path::strokeBoundingRect): Added check for CGRectNull
     21        (WebCore::Path::isEmpty): Reverted to former behavior, just using CGPathIsEmpty.
     22        (WebCore::Path::hasCurrentPoint): Reverted to former behavior, using isEmpty.
     23        (WebCore::Path::transform): Reverted to former behavior, using isEmpty.
     24
    1252012-01-26  Andreas Kling  <awesomekling@apple.com>
    226
  • trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp

    r101903 r106016  
    4242namespace WebCore {
    4343
    44 // A class to provide an isEmpty test that considers a one-element path with only a MoveTo element
    45 // to be empty. This behavior is consistent with other platforms in WebKit, and is needed to prevent
    46 // incorrect (according to the spec) linecap stroking for zero length paths in SVG.
    47 class PathIsEmptyOrSingleMoveTester {
    48 public:
    49     PathIsEmptyOrSingleMoveTester() : m_moveCount(0) { }
    50 
    51     bool isEmpty() const
    52     {
    53         return m_moveCount <= 1;
    54     }
    55 
    56     static void testPathElement(void* info, const CGPathElement* element)
    57     {
    58         PathIsEmptyOrSingleMoveTester* tester = static_cast<PathIsEmptyOrSingleMoveTester*>(info);
    59         if (element->type == kCGPathElementMoveToPoint)
    60             ++tester->m_moveCount;
    61         else {
    62             // Any non move element implies a non-empty path; set the count to 2 to force
    63             // isEmpty to return false.
    64             tester->m_moveCount = 2;
    65         }
    66     }
    67 
    68 private:
    69     // Any non-move-to element, or more than one move-to element, will make the count >= 2.
    70     unsigned m_moveCount;
    71 };
    72 
    73 // Paths with only move-to elements do not draw under any circumstances, so their bound should
    74 // be empty. Currently, CoreGraphics returns non-empty bounds for such paths. Radar 10450621
    75 // tracks this. This class reports paths that have only move-to elements, allowing the
    76 // bounding box code to work around the CoreGraphics problem.
    77 class PathHasOnlyMoveToTester {
    78 public:
    79     PathHasOnlyMoveToTester() : m_hasSeenOnlyMoveTo(true) { }
    80 
    81     bool hasOnlyMoveTo() const
    82     {
    83         return m_hasSeenOnlyMoveTo;
    84     }
    85 
    86     static void testPathElement(void* info, const CGPathElement* element)
    87     {
    88         PathHasOnlyMoveToTester* tester = static_cast<PathHasOnlyMoveToTester*>(info);
    89         if (tester->m_hasSeenOnlyMoveTo && element->type != kCGPathElementMoveToPoint)
    90             tester->m_hasSeenOnlyMoveTo = false;
    91     }
    92 
    93 private:
    94     bool m_hasSeenOnlyMoveTo;
    95 };
    96 
    9744static size_t putBytesNowhere(void*, const void*, size_t count)
    9845{
     
    219166    // CGPathGetBoundingBox includes the path's control points, CGPathGetPathBoundingBox
    220167    // does not, but only exists on 10.6 and above.
    221     // A bug in CoreGraphics leads to an incorrect bound on paths containing only move-to elements
    222     // with a linecap style that is non-butt. All paths with only move-to elements (regardless of
    223     // linecap) are effectively empty for bounding purposes and here we make it so.
    224     PathHasOnlyMoveToTester tester;
    225     CGPathApply(m_path, &tester, PathHasOnlyMoveToTester::testPathElement);
    226     if (tester.hasOnlyMoveTo())
    227         return FloatRect(0, 0, 0, 0);
    228 
     168
     169    CGRect bound = CGRectZero;
    229170#if !defined(BUILDING_ON_LEOPARD)
    230     return CGPathGetPathBoundingBox(m_path);
     171    bound = CGPathGetPathBoundingBox(m_path);
    231172#else
    232     return CGPathGetBoundingBox(m_path);
     173    bound = CGPathGetBoundingBox(m_path);
    233174#endif
     175    return CGRectIsNull(bound) ? CGRectZero : bound;
    234176}
    235177
    236178FloatRect Path::fastBoundingRect() const
    237179{
    238     // A bug in CoreGraphics leads to an incorrect bound on paths containing only move-to elements
    239     // with a linecap style that is non-butt. All paths with only move-to elements (regardless of
    240     // linecap) are effectively empty for bounding purposes and here we make it so.
    241     PathHasOnlyMoveToTester tester;
    242     CGPathApply(m_path, &tester, PathHasOnlyMoveToTester::testPathElement);
    243     if (tester.hasOnlyMoveTo())
    244         return FloatRect(0, 0, 0, 0);
    245 
    246     return CGPathGetBoundingBox(m_path);
     180    CGRect bound = CGPathGetBoundingBox(m_path);
     181    return CGRectIsNull(bound) ? CGRectZero : bound;
    247182}
    248183
     
    264199    CGContextRestoreGState(context);
    265200
    266     return box;
     201    return CGRectIsNull(box) ? CGRectZero : box;
    267202}
    268203
     
    322257bool Path::isEmpty() const
    323258{
    324     // The SVG rendering code that uses this method relies on paths with a single move-to
    325     // element, and nothing else, as being empty. Until that code is refactored to avoid
    326     // the dependence on isEmpty, we match the behavior of other platforms.
    327     // When the SVG code is refactored, we could use CGPathIsEmpty(m_path);
    328     PathIsEmptyOrSingleMoveTester tester;
    329     CGPathApply(m_path, &tester, PathIsEmptyOrSingleMoveTester::testPathElement);
    330     return tester.isEmpty();
     259    return CGPathIsEmpty(m_path);
    331260}
    332261
    333262bool Path::hasCurrentPoint() const
    334263{
    335     return !CGPathIsEmpty(m_path);
     264    return !isEmpty();
    336265}
    337266   
     
    387316void Path::transform(const AffineTransform& transform)
    388317{
    389     if (transform.isIdentity() || CGPathIsEmpty(m_path))
     318    if (transform.isIdentity() || isEmpty())
    390319        return;
    391320
Note: See TracChangeset for help on using the changeset viewer.