| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/platform/Cursor.h" | 27 #include "core/platform/Cursor.h" |
| 28 #include "core/platform/graphics/ImageBuffer.h" |
| 28 | 29 |
| 29 namespace WebCore { | 30 namespace WebCore { |
| 30 | 31 |
| 31 IntPoint determineHotSpot(Image* image, const IntPoint& specifiedHotSpot) | 32 IntPoint determineHotSpot(Image* image, const IntPoint& specifiedHotSpot) |
| 32 { | 33 { |
| 33 if (image->isNull()) | 34 if (image->isNull()) |
| 34 return IntPoint(); | 35 return IntPoint(); |
| 35 | 36 |
| 36 // Hot spot must be inside cursor rectangle. | 37 // Hot spot must be inside cursor rectangle. |
| 37 IntRect imageRect = image->rect(); | 38 IntRect imageRect = image->rect(); |
| 38 if (imageRect.contains(specifiedHotSpot)) | 39 if (imageRect.contains(specifiedHotSpot)) |
| 39 return specifiedHotSpot; | 40 return specifiedHotSpot; |
| 40 | 41 |
| 41 // If hot spot is not specified externally, it can be extracted from some im
age formats (e.g. .cur). | 42 // If hot spot is not specified externally, it can be extracted from some im
age formats (e.g. .cur). |
| 42 IntPoint intrinsicHotSpot; | 43 IntPoint intrinsicHotSpot; |
| 43 bool imageHasIntrinsicHotSpot = image->getHotSpot(intrinsicHotSpot); | 44 bool imageHasIntrinsicHotSpot = image->getHotSpot(intrinsicHotSpot); |
| 44 if (imageHasIntrinsicHotSpot && imageRect.contains(intrinsicHotSpot)) | 45 if (imageHasIntrinsicHotSpot && imageRect.contains(intrinsicHotSpot)) |
| 45 return intrinsicHotSpot; | 46 return intrinsicHotSpot; |
| 46 | 47 |
| 47 return IntPoint(); | 48 return IntPoint(); |
| 48 } | 49 } |
| 49 | 50 |
| 51 // Similar to Image::nativeImageForCurrentFrame() but incorporates the image |
| 52 // scale factor. This ensures that SVG cursors are sharp at high DPI settings. |
| 53 Cursor rasterizeSVGCursor(const Cursor& cursor, float imageScaleFactor) |
| 54 { |
| 55 Image* image = cursor.image(); |
| 56 if (!image || !image->isSVGImage() || imageScaleFactor == 1) |
| 57 return cursor; |
| 58 |
| 59 IntSize size = image->size(); |
| 60 IntPoint hotSpot = cursor.hotSpot(); |
| 61 size.scale(imageScaleFactor); |
| 62 hotSpot.scale(imageScaleFactor, imageScaleFactor); |
| 63 |
| 64 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size, 1); |
| 65 if (!buffer) // failed to allocate image |
| 66 return cursor; |
| 67 |
| 68 buffer->context()->drawImage(image, FloatRect(IntRect(IntPoint(), size))); |
| 69 return Cursor(buffer->copyImage(DontCopyBackingStore).get(), hotSpot, imageS
caleFactor); |
| 70 } |
| 71 |
| 50 const Cursor& Cursor::fromType(Cursor::Type type) | 72 const Cursor& Cursor::fromType(Cursor::Type type) |
| 51 { | 73 { |
| 52 switch (type) { | 74 switch (type) { |
| 53 case Cursor::Pointer: | 75 case Cursor::Pointer: |
| 54 return pointerCursor(); | 76 return pointerCursor(); |
| 55 case Cursor::Cross: | 77 case Cursor::Cross: |
| 56 return crossCursor(); | 78 return crossCursor(); |
| 57 case Cursor::Hand: | 79 case Cursor::Hand: |
| 58 return handCursor(); | 80 return handCursor(); |
| 59 case Cursor::IBeam: | 81 case Cursor::IBeam: |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 return c; | 459 return c; |
| 438 } | 460 } |
| 439 | 461 |
| 440 const Cursor& grabbingCursor() | 462 const Cursor& grabbingCursor() |
| 441 { | 463 { |
| 442 DEFINE_STATIC_LOCAL(Cursor, c, (Cursor::Grabbing)); | 464 DEFINE_STATIC_LOCAL(Cursor, c, (Cursor::Grabbing)); |
| 443 return c; | 465 return c; |
| 444 } | 466 } |
| 445 | 467 |
| 446 } // namespace WebCore | 468 } // namespace WebCore |
| OLD | NEW |