Pasteboard.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright (C) 2006, 2013 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. #ifndef Pasteboard_h
  26. #define Pasteboard_h
  27. #include "DragImage.h"
  28. #include <wtf/ListHashSet.h>
  29. #include <wtf/Noncopyable.h>
  30. #include <wtf/Vector.h>
  31. #include <wtf/text/WTFString.h>
  32. #if PLATFORM(GTK)
  33. #include "DragData.h"
  34. typedef struct _GtkClipboard GtkClipboard;
  35. #endif
  36. #if PLATFORM(QT)
  37. #include <QMimeData>
  38. #endif
  39. #if PLATFORM(WIN)
  40. #include "COMPtr.h"
  41. #include "WCDataObject.h"
  42. #include <objidl.h>
  43. #include <windows.h>
  44. typedef struct HWND__* HWND;
  45. #endif
  46. // FIXME: This class is too high-level to be in the platform directory, since it
  47. // uses the DOM and makes calls to Editor. It should either be divested of its
  48. // knowledge of the frame and editor or moved into the editing directory.
  49. namespace WebCore {
  50. #if PLATFORM(MAC)
  51. #if PLATFORM(IOS)
  52. // FIXME: This is only temporary until Pasteboard is refactored for iOS.
  53. extern NSString *WebArchivePboardType;
  54. #else
  55. extern const char* WebArchivePboardType;
  56. #endif
  57. extern const char* WebSmartPastePboardType;
  58. extern const char* WebURLNamePboardType;
  59. extern const char* WebURLPboardType;
  60. extern const char* WebURLsWithTitlesPboardType;
  61. #endif
  62. class Clipboard;
  63. class DocumentFragment;
  64. class DragData;
  65. class Element;
  66. class Frame;
  67. class HitTestResult;
  68. class KURL;
  69. class Node;
  70. class Range;
  71. class SharedBuffer;
  72. enum ShouldSerializeSelectedTextForClipboard { DefaultSelectedTextType, IncludeImageAltTextForClipboard };
  73. class Pasteboard {
  74. WTF_MAKE_NONCOPYABLE(Pasteboard); WTF_MAKE_FAST_ALLOCATED;
  75. public:
  76. enum SmartReplaceOption {
  77. CanSmartReplace,
  78. CannotSmartReplace
  79. };
  80. #if PLATFORM(MAC) && !PLATFORM(IOS)
  81. static PassOwnPtr<Pasteboard> create(const String& pasteboardName);
  82. String name() const { return m_pasteboardName; }
  83. void writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard);
  84. explicit Pasteboard(const String& pasteboardName);
  85. static PassRefPtr<SharedBuffer> getDataSelection(Frame*, const String& pasteboardType);
  86. #endif
  87. #if PLATFORM(GTK)
  88. static PassOwnPtr<Pasteboard> create(PassRefPtr<DataObjectGtk>);
  89. static PassOwnPtr<Pasteboard> create(GtkClipboard*);
  90. PassRefPtr<DataObjectGtk> dataObject() const;
  91. #endif
  92. #if PLATFORM(QT)
  93. static PassOwnPtr<Pasteboard> create(const QMimeData* readableClipboard = 0, bool isForDragAndDrop = false);
  94. QMimeData* clipboardData() const { return m_writableData; }
  95. void invalidateWritableData() const { m_writableData = 0; }
  96. bool isForDragAndDrop() const { return m_isForDragAndDrop; }
  97. bool isForCopyAndPaste() const { return !m_isForDragAndDrop; }
  98. #endif
  99. // Deprecated. Use createForCopyAndPaste instead.
  100. static Pasteboard* generalPasteboard();
  101. static PassOwnPtr<Pasteboard> createForCopyAndPaste();
  102. static PassOwnPtr<Pasteboard> createPrivate(); // Corresponds to the "unique pasteboard" concept on Mac. Used in editing, not sure exactly for what purpose.
  103. #if ENABLE(DRAG_SUPPORT)
  104. static PassOwnPtr<Pasteboard> createForDragAndDrop();
  105. static PassOwnPtr<Pasteboard> createForDragAndDrop(const DragData&);
  106. #endif
  107. bool hasData();
  108. ListHashSet<String> types();
  109. String readString(const String& type);
  110. Vector<String> readFilenames();
  111. bool writeString(const String& type, const String& data);
  112. void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard = DefaultSelectedTextType);
  113. void writePlainText(const String&, SmartReplaceOption);
  114. #if !PLATFORM(IOS)
  115. void writeURL(const KURL&, const String&, Frame* = 0);
  116. void writeImage(Node*, const KURL&, const String& title);
  117. #else
  118. void writeImage(Node*, Frame*);
  119. void writePlainText(const String&, Frame*);
  120. static NSArray* supportedPasteboardTypes();
  121. #endif
  122. void writePasteboard(const Pasteboard& sourcePasteboard);
  123. void writeClipboard(Clipboard*);
  124. void clear();
  125. void clear(const String& type);
  126. bool canSmartReplace();
  127. #if ENABLE(DRAG_SUPPORT)
  128. void setDragImage(DragImageRef, const IntPoint& hotSpot);
  129. #endif
  130. // FIXME: Having these functions here is a layering violation.
  131. // These functions need to move to the editing directory even if they have platform-specific aspects.
  132. PassRefPtr<DocumentFragment> documentFragment(Frame*, PassRefPtr<Range>, bool allowPlainText, bool& chosePlainText);
  133. String plainText(Frame* = 0);
  134. #if PLATFORM(QT) || PLATFORM(GTK)
  135. bool isSelectionMode() const;
  136. void setSelectionMode(bool);
  137. #else
  138. bool isSelectionMode() const { return false; }
  139. void setSelectionMode(bool) { }
  140. #endif
  141. #if PLATFORM(WIN)
  142. COMPtr<IDataObject> dataObject() const { return m_dataObject; }
  143. void setExternalDataObject(IDataObject*);
  144. void writeURLToWritableDataObject(const KURL&, const String&);
  145. COMPtr<WCDataObject> writableDataObject() const { return m_writableDataObject; }
  146. void writeImageToDataObject(Element*, const KURL&);
  147. #endif
  148. #if PLATFORM(GTK) || PLATFORM(QT)
  149. ~Pasteboard();
  150. #endif
  151. private:
  152. Pasteboard();
  153. #if PLATFORM(GTK)
  154. Pasteboard(PassRefPtr<DataObjectGtk>);
  155. Pasteboard(GtkClipboard*);
  156. #endif
  157. #if PLATFORM(QT)
  158. Pasteboard(const QMimeData* , bool);
  159. #endif
  160. #if PLATFORM(WIN)
  161. explicit Pasteboard(IDataObject*);
  162. explicit Pasteboard(WCDataObject*);
  163. explicit Pasteboard(const DragDataMap&);
  164. #endif
  165. #if PLATFORM(MAC) && !PLATFORM(IOS)
  166. String m_pasteboardName;
  167. long m_changeCount;
  168. #endif
  169. #if PLATFORM(IOS)
  170. PassRefPtr<DocumentFragment> documentFragmentForPasteboardItemAtIndex(Frame*, int index, bool allowPlainText, bool& chosePlainText);
  171. #endif
  172. #if PLATFORM(WIN)
  173. void finishCreatingPasteboard();
  174. void writeRangeToDataObject(Range*, Frame*);
  175. void writeURLToDataObject(const KURL&, const String&, Frame*);
  176. void writePlainTextToDataObject(const String&, SmartReplaceOption);
  177. HWND m_owner;
  178. COMPtr<IDataObject> m_dataObject;
  179. COMPtr<WCDataObject> m_writableDataObject;
  180. DragDataMap m_dragDataMap;
  181. #endif
  182. #if PLATFORM(QT)
  183. const QMimeData* readData() const;
  184. bool m_selectionMode;
  185. const QMimeData* m_readableData;
  186. mutable QMimeData* m_writableData;
  187. bool m_isForDragAndDrop;
  188. #endif
  189. #if PLATFORM(GTK)
  190. RefPtr<DataObjectGtk> m_dataObject;
  191. GtkClipboard* m_gtkClipboard;
  192. #endif
  193. };
  194. } // namespace WebCore
  195. #endif // Pasteboard_h