2
* Copyright (C) 2007 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
28
#import "CachedImage.h"
31
#import "PlatformString.h"
32
#import "ResourceResponse.h"
33
#import <FoundationExtras.h>
39
IntSize dragImageSize(DragImageRef image)
41
return (IntSize)[image.get() size];
44
void deleteDragImage(DragImageRef image)
46
//DragImageRef is a RetainPtr, so we don't need to explicitly delete it
49
DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
51
NSSize originalSize = [image.get() size];
52
NSSize newSize = NSMakeSize((originalSize.width * scale.width()), (originalSize.height * scale.height()));
53
newSize.width = roundf(newSize.width);
54
newSize.height = roundf(newSize.height);
55
[image.get() setScalesWhenResized:YES];
56
[image.get() setSize:newSize];
60
DragImageRef dissolveDragImageToFraction(DragImageRef image, float delta)
62
RetainPtr<NSImage> dissolvedImage(AdoptNS, [[NSImage alloc] initWithSize:[image.get() size]]);
64
NSPoint point = [image.get() isFlipped] ? NSMakePoint(0, [image.get() size].height) : NSZeroPoint;
66
// In this case the dragging image is always correct.
67
[dissolvedImage.get() setFlipped:[image.get() isFlipped]];
69
[dissolvedImage.get() lockFocus];
70
[image.get() dissolveToPoint:point fraction: delta];
71
[dissolvedImage.get() unlockFocus];
73
[image.get() lockFocus];
74
[dissolvedImage.get() compositeToPoint:point operation:NSCompositeCopy];
75
[image.get() unlockFocus];
80
DragImageRef createDragImageFromImage(Image* image)
82
DragImageRef dragImage(AdoptNS, [image->getNSImage() copy]);
83
[dragImage.get() setSize:(NSSize)(image->size())];
87
DragImageRef createDragImageIconForCachedImage(CachedImage* image)
89
const String& filename = image->response().suggestedFilename();
90
NSString *extension = nil;
91
int dotIndex = filename.reverseFind('.');
93
if (dotIndex > 0 && dotIndex < (int)(filename.length() - 1)) // require that a . exists after the first character and before the last
94
extension = filename.substring(dotIndex + 1);
96
//It might be worth doing a further look up to pull the extension from the mimetype
99
return DragImageRef([[NSWorkspace sharedWorkspace] iconForFileType:extension]);