Home | History | Annotate | Download | only in mac
      1 /*
      2  * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      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.
     12  *
     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.
     24  */
     25 
     26 #ifndef ClipboardMac_h
     27 #define ClipboardMac_h
     28 
     29 #include "CachedResourceClient.h"
     30 #include "Clipboard.h"
     31 #include <wtf/RetainPtr.h>
     32 
     33 #ifdef __OBJC__
     34 @class NSImage;
     35 @class NSPasteboard;
     36 #else
     37 class NSImage;
     38 class NSPasteboard;
     39 #endif
     40 
     41 namespace WebCore {
     42 
     43 class Frame;
     44 class FileList;
     45 
     46 class ClipboardMac : public Clipboard, public CachedResourceClient {
     47 public:
     48     static PassRefPtr<ClipboardMac> create(bool forDragging, NSPasteboard *pasteboard, ClipboardAccessPolicy policy, Frame* frame)
     49     {
     50         return adoptRef(new ClipboardMac(forDragging, pasteboard, policy, frame));
     51     }
     52 
     53     virtual ~ClipboardMac();
     54 
     55     void clearData(const String& type);
     56     void clearAllData();
     57     String getData(const String& type, bool& success) const;
     58     bool setData(const String& type, const String& data);
     59 
     60     virtual bool hasData();
     61 
     62     // extensions beyond IE's API
     63     virtual HashSet<String> types() const;
     64     virtual PassRefPtr<FileList> files() const;
     65 
     66     void setDragImage(CachedImage*, const IntPoint&);
     67     void setDragImageElement(Node *, const IntPoint&);
     68 
     69     virtual DragImageRef createDragImage(IntPoint& dragLoc) const;
     70 #if ENABLE(DRAG_SUPPORT)
     71     virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*);
     72 #endif
     73     virtual void writeRange(Range*, Frame* frame);
     74     virtual void writeURL(const KURL&, const String&, Frame* frame);
     75     virtual void writePlainText(const String&);
     76 
     77     // Methods for getting info in Cocoa's type system
     78     NSImage *dragNSImage(NSPoint&) const; // loc converted from dragLoc, based on whole image size
     79     NSPasteboard *pasteboard() { return m_pasteboard.get(); }
     80 
     81 private:
     82     ClipboardMac(bool forDragging, NSPasteboard *, ClipboardAccessPolicy, Frame*);
     83 
     84     void setDragImage(CachedImage*, Node*, const IntPoint&);
     85 
     86     RetainPtr<NSPasteboard> m_pasteboard;
     87     int m_changeCount;
     88     Frame* m_frame; // used on the source side to generate dragging images
     89 };
     90 
     91 }
     92 
     93 #endif
     94