Changeset 182869 in webkit


Ignore:
Timestamp:
Apr 15, 2015 4:21:42 PM (9 years ago)
Author:
timothy_horton@apple.com
Message:

Custom CSS cursors do not use -webkit-image-set on retina displays
https://bugs.webkit.org/show_bug.cgi?id=120783
.:

Reviewed by Beth Dakin.

Add a manual test for custom CSS cursors on retina displays.

  • ManualTests/retina-cursors.html: Added.

Source/WebCore:

<rdar://problem/14921432>

Reviewed by Beth Dakin.

Scale NSCursor images correctly so custom CSS cursors work with
-webkit-image-set on retina displays.

  • WebCore.exp.in:
  • page/EventHandler.cpp:

(WebCore::EventHandler::selectCursor):

  • platform/mac/CursorMac.mm:

(WebCore::createCustomCursor):
(WebCore::Cursor::ensurePlatformCursor):

Source/WebKit2:

Reviewed by Beth Dakin.

Serialize the cursor image scale for SetCursor messages so custom
CSS cursors work with -webkit-image-set on retina displays.

  • Shared/WebCoreArgumentCoders.cpp:

(CoreIPC::ArgumentCoder<Cursor>::encode):
(CoreIPC::ArgumentCoder<Cursor>::decode):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r182865 r182869  
     12015-04-15  Timothy Horton  <timothy_horton@apple.com>
     2
     3        Custom CSS cursors do not use -webkit-image-set on retina displays
     4        https://bugs.webkit.org/show_bug.cgi?id=120783
     5
     6        Reviewed by Beth Dakin.
     7        Patch by Evan Wallace <evan.exe@gmail.com>.
     8
     9        Add a manual test for custom CSS cursors on retina displays.
     10
     11        * ManualTests/retina-cursors.html: Added.
     12
    1132015-04-15  Alex Christensen  <achristensen@webkit.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r182866 r182869  
     12015-04-15  Timothy Horton  <timothy_horton@apple.com>
     2
     3        Custom CSS cursors do not use -webkit-image-set on retina displays
     4        https://bugs.webkit.org/show_bug.cgi?id=120783
     5        <rdar://problem/14921432>
     6
     7        Reviewed by Beth Dakin.
     8        Patch by Evan Wallace <evan.exe@gmail.com>.
     9
     10        Scale NSCursor images correctly so custom CSS cursors work with
     11        -webkit-image-set on retina displays.
     12
     13        * WebCore.exp.in:
     14        * page/EventHandler.cpp:
     15        (WebCore::EventHandler::selectCursor):
     16        * platform/mac/CursorMac.mm:
     17        (WebCore::createCustomCursor):
     18        (WebCore::Cursor::ensurePlatformCursor):
     19
    1202015-04-15  Alexey Proskuryakov  <ap@apple.com>
    221
  • trunk/Source/WebCore/page/EventHandler.cpp

    r182748 r182869  
    14141414            // Get hotspot and convert from logical pixels to physical pixels.
    14151415            IntPoint hotSpot = (*cursors)[i].hotSpot();
    1416             hotSpot.scale(scale, scale);
    14171416            FloatSize size = cachedImage->imageForRenderer(renderer)->size();
    14181417            if (cachedImage->errorOccurred())
  • trunk/Source/WebCore/platform/Cursor.h

    r179057 r182869  
    147147#if ENABLE(MOUSE_CURSOR_SCALE)
    148148        // Hot spot is in image pixels.
    149         Cursor(Image*, const IntPoint& hotSpot, float imageScaleFactor);
     149        WEBCORE_EXPORT Cursor(Image*, const IntPoint& hotSpot, float imageScaleFactor);
    150150#endif
    151151
  • trunk/Source/WebCore/platform/mac/CursorMac.mm

    r175941 r182869  
    4242// but creating a cursor with a bad image might throw.
    4343
     44#if ENABLE(MOUSE_CURSOR_SCALE)
     45static RetainPtr<NSCursor> createCustomCursor(Image* image, const IntPoint& hotSpot, float scale)
     46#else
    4447static RetainPtr<NSCursor> createCustomCursor(Image* image, const IntPoint& hotSpot)
     48#endif
    4549{
    4650    // FIXME: The cursor won't animate.  Not sure if that's a big deal.
     
    4953        return 0;
    5054    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     55
     56#if ENABLE(MOUSE_CURSOR_SCALE)
     57    NSSize size = NSMakeSize(image->width() / scale, image->height() / scale);
     58    NSSize expandedSize = NSMakeSize(ceil(size.width), ceil(size.height));
     59
     60    // Pad the image with transparent pixels so it has an integer boundary.
     61    if (size.width != expandedSize.width || size.height != expandedSize.height) {
     62        RetainPtr<NSImage> expandedImage = adoptNS([[NSImage alloc] initWithSize:expandedSize]);
     63        NSRect toRect = NSMakeRect(0, expandedSize.height - size.height, size.width, size.height);
     64        NSRect fromRect = NSMakeRect(0, 0, image->width(), image->height());
     65
     66        [expandedImage lockFocus];
     67        [nsImage drawInRect:toRect fromRect:fromRect operation:NSCompositeSourceOver fraction:1];
     68        [expandedImage unlockFocus];
     69
     70        return adoptNS([[NSCursor alloc] initWithImage:expandedImage.get() hotSpot:hotSpot]);
     71    }
     72
     73    // Scale the image and its representation to match retina resolution.
     74    [nsImage setSize:expandedSize];
     75    [[[nsImage representations] objectAtIndex:0] setSize:expandedSize];
     76#endif
     77
    5178    return adoptNS([[NSCursor alloc] initWithImage:nsImage hotSpot:hotSpot]);
    5279    END_BLOCK_OBJC_EXCEPTIONS;
    53     return 0;
     80    return nullptr;
    5481}
    5582
     
    206233
    207234    case Cursor::Custom:
     235#if ENABLE(MOUSE_CURSOR_SCALE)
     236        m_platformCursor = createCustomCursor(m_image.get(), m_hotSpot, m_imageScaleFactor);
     237#else
    208238        m_platformCursor = createCustomCursor(m_image.get(), m_hotSpot);
     239#endif
    209240        break;
    210241    }
  • trunk/Source/WebKit2/ChangeLog

    r182865 r182869  
     12015-04-15  Timothy Horton  <timothy_horton@apple.com>
     2
     3        Custom CSS cursors do not use -webkit-image-set on retina displays
     4        https://bugs.webkit.org/show_bug.cgi?id=120783
     5
     6        Reviewed by Beth Dakin.
     7        Patch by Evan Wallace <evan.exe@gmail.com>.
     8
     9        Serialize the cursor image scale for SetCursor messages so custom
     10        CSS cursors work with -webkit-image-set on retina displays.
     11
     12        * Shared/WebCoreArgumentCoders.cpp:
     13        (CoreIPC::ArgumentCoder<Cursor>::encode):
     14        (CoreIPC::ArgumentCoder<Cursor>::decode):
     15
    1162015-04-15  Alex Christensen  <achristensen@webkit.org>
    217
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r182764 r182869  
    767767    encodeImage(encoder, cursor.image());
    768768    encoder << cursor.hotSpot();
     769#if ENABLE(MOUSE_CURSOR_SCALE)
     770    encoder << cursor.imageScaleFactor();
     771#endif
    769772}
    770773
     
    808811        return false;
    809812
     813#if ENABLE(MOUSE_CURSOR_SCALE)
     814    float scale;
     815    if (!decoder.decode(scale))
     816        return false;
     817
     818    cursor = Cursor(image.get(), hotSpot, scale);
     819#else
    810820    cursor = Cursor(image.get(), hotSpot);
     821#endif
    811822    return true;
    812823}
Note: See TracChangeset for help on using the changeset viewer.