1/* 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 * 19 */ 20 21#import "config.h" 22#import "Icon.h" 23 24#import "GraphicsContext.h" 25#import "LocalCurrentGraphicsContext.h" 26#import "PlatformString.h" 27#import <wtf/PassRefPtr.h> 28 29namespace WebCore { 30 31Icon::Icon(NSImage *image) 32 : m_nsImage(image) 33{ 34 // Need this because WebCore uses AppKit's flipped coordinate system exclusively. 35 [image setFlipped:YES]; 36} 37 38Icon::~Icon() 39{ 40} 41 42// FIXME: Move the code to ChromeClient::iconForFiles(). 43PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames) 44{ 45 if (filenames.isEmpty()) 46 return 0; 47 48 bool useIconFromFirstFile; 49#ifdef BUILDING_ON_TIGER 50 // FIXME: find a better image for multiple files to use on Tiger. 51 useIconFromFirstFile = true; 52#else 53 useIconFromFirstFile = filenames.size() == 1; 54#endif 55 if (useIconFromFirstFile) { 56 // Don't pass relative filenames -- we don't want a result that depends on the current directory. 57 // Need 0U here to disambiguate String::operator[] from operator(NSString*, int)[] 58 if (filenames[0].isEmpty() || filenames[0][0U] != '/') 59 return 0; 60 61 NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile:filenames[0]]; 62 if (!image) 63 return 0; 64 65 return adoptRef(new Icon(image)); 66 } 67#ifdef BUILDING_ON_TIGER 68 return 0; 69#else 70 NSImage* image = [NSImage imageNamed:NSImageNameMultipleDocuments]; 71 if (!image) 72 return 0; 73 74 return adoptRef(new Icon(image)); 75#endif 76} 77 78void Icon::paint(GraphicsContext* context, const IntRect& rect) 79{ 80 if (context->paintingDisabled()) 81 return; 82 83 LocalCurrentGraphicsContext localCurrentGC(context); 84 85 [m_nsImage.get() drawInRect:rect 86 fromRect:NSMakeRect(0, 0, [m_nsImage.get() size].width, [m_nsImage.get() size].height) 87 operation:NSCompositeSourceOver fraction:1.0f]; 88} 89 90} 91