Changeset 134874 in webkit


Ignore:
Timestamp:
Nov 15, 2012 6:28:00 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

custom CSS cursors ignore hotspot values embedded in CUR files
https://bugs.webkit.org/show_bug.cgi?id=100059

Patch by Rick Byers <rbyers@chromium.org> on 2012-11-15
Reviewed by Kenneth Russell.

Source/WebCore:

Add reading the hotspot values to the ICOImageDecoder (for CUR files only),
and plumb it through so that the existing calls to ImageSource::getHotSpot
actually return the hot spot value when there is one.

Tests: fast/events/mouse-cursor.html, fast/events/mouse-cursor-multiframecur.html

  • platform/graphics/ImageSource.cpp:

(WebCore::ImageSource::getHotSpot):

  • platform/graphics/chromium/DeferredImageDecoder.cpp:

(WebCore::DeferredImageDecoder::hotSpot):
(WebCore::DeferredImageDecoder::hotSpotAtIndex):

  • platform/graphics/chromium/DeferredImageDecoder.h:

(DeferredImageDecoder):

  • platform/image-decoders/ImageDecoder.h:

(WebCore::ImageDecoder::hotSpot):
(WebCore::ImageDecoder::hotSpotAtIndex):
(ImageDecoder):

  • platform/image-decoders/ico/ICOImageDecoder.cpp:

(WebCore::ICOImageDecoder::hotSpot):
(WebCore::ICOImageDecoder::hotSpotAtIndex):
(WebCore::ICOImageDecoder::processDirectory):
(WebCore::ICOImageDecoder::readDirectoryEntry):

  • platform/image-decoders/ico/ICOImageDecoder.h:

(ICOImageDecoder):
(IconDirectoryEntry):

LayoutTests:

Add mouse cursor test cases that use CUR files that have embedded hotspot values.

  • fast/events/mouse-cursor-expected.txt:
  • fast/events/mouse-cursor-multiframecur-expected.txt: Added.
  • fast/events/mouse-cursor-multiframecur.html: Copied from LayoutTests/fast/events/mouse-cursor.html.
  • fast/events/mouse-cursor.html:
  • fast/events/resources/greenbox-3frames.cur: Added.
  • fast/events/resources/greenbox-hotspot35-4.cur: Added.
  • fast/events/resources/greenbox-hotspot5-4.cur: Added.
  • platform/mac/TestExpectations: Skip the multi-frame case on mac because it causes a hang
Location:
trunk
Files:
5 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r134870 r134874  
     12012-11-15  Rick Byers  <rbyers@chromium.org>
     2
     3        custom CSS cursors ignore hotspot values embedded in CUR files
     4        https://bugs.webkit.org/show_bug.cgi?id=100059
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Add mouse cursor test cases that use CUR files that have embedded hotspot values.
     9
     10        * fast/events/mouse-cursor-expected.txt:
     11        * fast/events/mouse-cursor-multiframecur-expected.txt: Added.
     12        * fast/events/mouse-cursor-multiframecur.html: Copied from LayoutTests/fast/events/mouse-cursor.html.
     13        * fast/events/mouse-cursor.html:
     14        * fast/events/resources/greenbox-3frames.cur: Added.
     15        * fast/events/resources/greenbox-hotspot35-4.cur: Added.
     16        * fast/events/resources/greenbox-hotspot5-4.cur: Added.
     17        * platform/mac/TestExpectations: Skip the multi-frame case on mac because it causes a hang
     18
    1192012-11-15  Kenichi Ishibashi  <bashi@chromium.org>
    220
  • trunk/LayoutTests/fast/events/mouse-cursor-expected.txt

    r134803 r134874  
    4646Cursor Info: type=Custom hotSpot=0,0 image=25x25
    4747
     48TEST CASE: Image with implicit hot spot at (5,4)
     49Cursor Info: type=Custom hotSpot=5,4 image=25x25
     50
     51TEST CASE: Image with explicit hot spot at (20,10) overriding implicit hot spot
     52Cursor Info: type=Custom hotSpot=20,10 image=25x25
     53
     54TEST CASE: Image with implicit hot spot outside image at (35,4)
     55Cursor Info: type=Custom hotSpot=0,0 image=25x25
     56
    4857TEST CASE: Over large image with fallback to pointer
    4958Cursor Info: type=Hand hotSpot=0,0
  • trunk/LayoutTests/fast/events/mouse-cursor.html

    r134803 r134874  
    2929  <div style='cursor: url(resources/greenbox.png) -1 -1, pointer'>Image with explicit hot spot at (-1,-1)</div>
    3030  <div style='cursor: url(resources/greenbox.png) 30 30, pointer'>Image with explicit hot spot outside image at (30,30)</div>
     31  <div style='cursor: url(resources/greenbox-hotspot5-4.cur), pointer'>Image with implicit hot spot at (5,4)</div>
     32  <div style='cursor: url(resources/greenbox-hotspot5-4.cur) 20 10, pointer'>Image with explicit hot spot at (20,10) overriding implicit hot spot</div>
     33  <div style='cursor: url(resources/greenbox-hotspot35-4.cur), pointer'>Image with implicit hot spot outside image at (35,4)</div>
    3134  <div style='cursor: url(resources/onload-image.png), pointer'>Over large image with fallback to pointer</div>
    3235  <div style='cursor: url(#greenbox), pointer'>SVG cursor</div>
     
    6871            var node = nodesToTest[i];
    6972            debug('TEST CASE: ' + node.textContent);
    70             eventSender.mouseMoveTo(node.offsetLeft + 3, node.offsetTop + 3);
     73
     74            // Make sure the node is visible and move the mouse over top of it.
     75            document.body.scrollTop = node.offsetTop - 50;
     76            eventSender.mouseMoveTo(node.offsetLeft + 3, node.offsetTop - document.body.scrollTop + 3);
     77
     78            // Get details of the current mouse cursor.
    7179            // Note that we could return structured data which we then validate, but that's a lot more
    7280            // work and is redundant with relying on the expected output anyway.  Better to just dump
     
    99107    { url: 'resources/greenbox.png' },
    100108    { url: 'resources/onload-image.png' },
     109    { url: 'resources/greenbox-hotspot5-4.cur' },
     110    { url: 'resources/greenbox-hotspot35-4.cur' },
    101111    { url: 'doesntexist.png', error: true },
    102112    { url: 'unknown-scheme:cursor.png', error: true },
  • trunk/LayoutTests/platform/mac/TestExpectations

    r134802 r134874  
    11861186# Mountain Lion and prior do not support custom media data loading
    11871187Bug(jernoble) [ MountainLion Lion SnowLeopard ] media/video-src-blob.html
     1188
     1189# Hangs safari apparently due to an issue with weird multi-frame CUR image files
     1190webkit.org/b/101811 fast/events/mouse-cursor-multiframecur.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r134871 r134874  
     12012-11-15  Rick Byers  <rbyers@chromium.org>
     2
     3        custom CSS cursors ignore hotspot values embedded in CUR files
     4        https://bugs.webkit.org/show_bug.cgi?id=100059
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Add reading the hotspot values to the ICOImageDecoder (for CUR files only),
     9        and plumb it through so that the existing calls to ImageSource::getHotSpot
     10        actually return the hot spot value when there is one.
     11
     12        Tests: fast/events/mouse-cursor.html, fast/events/mouse-cursor-multiframecur.html
     13
     14        * platform/graphics/ImageSource.cpp:
     15        (WebCore::ImageSource::getHotSpot):
     16        * platform/graphics/chromium/DeferredImageDecoder.cpp:
     17        (WebCore::DeferredImageDecoder::hotSpot):
     18        (WebCore::DeferredImageDecoder::hotSpotAtIndex):
     19        * platform/graphics/chromium/DeferredImageDecoder.h:
     20        (DeferredImageDecoder):
     21        * platform/image-decoders/ImageDecoder.h:
     22        (WebCore::ImageDecoder::hotSpot):
     23        (WebCore::ImageDecoder::hotSpotAtIndex):
     24        (ImageDecoder):
     25        * platform/image-decoders/ico/ICOImageDecoder.cpp:
     26        (WebCore::ICOImageDecoder::hotSpot):
     27        (WebCore::ICOImageDecoder::hotSpotAtIndex):
     28        (WebCore::ICOImageDecoder::processDirectory):
     29        (WebCore::ICOImageDecoder::readDirectoryEntry):
     30        * platform/image-decoders/ico/ICOImageDecoder.h:
     31        (ICOImageDecoder):
     32        (IconDirectoryEntry):
     33
    1342012-11-15  Kenichi Ishibashi  <bashi@chromium.org>
    235
  • trunk/Source/WebCore/platform/graphics/ImageSource.cpp

    r132433 r134874  
    122122}
    123123
    124 bool ImageSource::getHotSpot(IntPoint&) const
    125 {
    126     return false;
     124bool ImageSource::getHotSpot(IntPoint& hotSpot) const
     125{
     126    return m_decoder ? m_decoder->hotSpot(hotSpot) : false;
    127127}
    128128
  • trunk/Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.cpp

    r134822 r134874  
    220220}
    221221
     222bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const
     223{
     224    return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false;
     225}
     226
    222227} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/chromium/DeferredImageDecoder.h

    r134822 r134874  
    6363    unsigned frameBytesAtIndex(size_t index) const;
    6464    ImageOrientation orientation() const;
     65    bool hotSpot(IntPoint&) const;
    6566
    6667private:
  • trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h

    r132260 r134874  
    377377#endif
    378378
     379        // If the image has a cursor hot-spot, stores it in the argument
     380        // and returns true. Otherwise returns false.
     381        virtual bool hotSpot(IntPoint&) const { return false; }
     382
    379383        virtual void reportMemoryUsage(MemoryObjectInfo*) const;
    380384
  • trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp

    r125769 r134874  
    134134}
    135135
     136bool ICOImageDecoder::hotSpot(IntPoint& hotSpot) const
     137{
     138    // When unspecified, the default frame is always frame 0. This is consistent with
     139    // BitmapImage where currentFrame() starts at 0 and only increases when animation is
     140    // requested.
     141    return hotSpotAtIndex(0, hotSpot);
     142}
     143
     144bool ICOImageDecoder::hotSpotAtIndex(size_t index, IntPoint& hotSpot) const
     145{
     146    if (index >= m_dirEntries.size() || m_fileType != CURSOR)
     147        return false;
     148
     149    hotSpot = m_dirEntries[index].m_hotSpot;
     150    return true;
     151}
     152
     153
    136154// static
    137155bool ICOImageDecoder::compareEntries(const IconDirectoryEntry& a, const IconDirectoryEntry& b)
     
    233251    // See if this is an icon filetype we understand, and make sure we have at
    234252    // least one entry in the directory.
    235     enum {
    236         ICON = 1,
    237         CURSOR = 2,
    238     };
    239253    if (((fileType != ICON) && (fileType != CURSOR)) || (!idCount))
    240254        return setFailed();
     255
     256    m_fileType = static_cast<FileType>(fileType);
    241257
    242258    // Enlarge member vectors to hold all the entries.
     
    288304    IconDirectoryEntry entry;
    289305    entry.m_size = IntSize(width, height);
    290     entry.m_bitCount = readUint16(6);
     306    if (m_fileType == CURSOR) {
     307        entry.m_bitCount = 0;
     308        entry.m_hotSpot = IntPoint(readUint16(4), readUint16(6));
     309    } else {
     310        entry.m_bitCount = readUint16(6);
     311        entry.m_hotSpot = IntPoint();
     312    }
    291313    entry.m_imageOffset = readUint32(12);
    292314
  • trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h

    r95901 r134874  
    5757        // inside BMPImageReader!
    5858        virtual bool setFailed();
     59        virtual bool hotSpot(IntPoint&) const;
    5960
    6061    private:
     
    6566        };
    6667
     68        enum FileType {
     69            ICON = 1,
     70            CURSOR = 2,
     71        };
     72
    6773        struct IconDirectoryEntry {
    6874            IntSize m_size;
    6975            uint16_t m_bitCount;
     76            IntPoint m_hotSpot;
    7077            uint32_t m_imageOffset;
    7178        };
     
    110117        bool processDirectoryEntries();
    111118
     119        // Stores the hot-spot for |index| in |hotSpot| and returns true,
     120        // or returns false if there is none.
     121        bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const;
     122
    112123        // Reads and returns a directory entry from the current offset into
    113124        // |data|.
     
    122133        // BMPImageReader takes over this will not be updated further.
    123134        size_t m_decodedOffset;
     135
     136        // Which type of file (ICO/CUR) this is.
     137        FileType m_fileType;
    124138
    125139        // The headers for the ICO.
Note: See TracChangeset for help on using the changeset viewer.