1 | /* |
2 | * Copyright (C) 2007 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 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 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 | #pragma once |
27 | |
28 | #include "FloatSize.h" |
29 | #include "ImageOrientation.h" |
30 | #include "IntSize.h" |
31 | #include "Path.h" |
32 | #include "TextFlags.h" |
33 | #include "TextIndicator.h" |
34 | #include <wtf/Forward.h> |
35 | #include <wtf/Optional.h> |
36 | |
37 | #if PLATFORM(IOS_FAMILY) |
38 | #include <wtf/RetainPtr.h> |
39 | typedef struct CGImage *CGImageRef; |
40 | #elif PLATFORM(MAC) |
41 | #include <wtf/RetainPtr.h> |
42 | OBJC_CLASS NSImage; |
43 | #elif PLATFORM(WIN) |
44 | typedef struct HBITMAP__* HBITMAP; |
45 | #elif USE(CAIRO) |
46 | #include "RefPtrCairo.h" |
47 | #endif |
48 | |
49 | // We need to #define YOffset as it needs to be shared with WebKit |
50 | #define DragLabelBorderYOffset 2 |
51 | |
52 | namespace WebCore { |
53 | |
54 | class Element; |
55 | class Frame; |
56 | class Image; |
57 | class IntRect; |
58 | class Node; |
59 | class Range; |
60 | |
61 | #if PLATFORM(IOS_FAMILY) |
62 | typedef RetainPtr<CGImageRef> DragImageRef; |
63 | #elif PLATFORM(MAC) |
64 | typedef RetainPtr<NSImage> DragImageRef; |
65 | #elif PLATFORM(WIN) |
66 | typedef HBITMAP DragImageRef; |
67 | #elif USE(CAIRO) |
68 | typedef RefPtr<cairo_surface_t> DragImageRef; |
69 | #endif |
70 | |
71 | #if PLATFORM(COCOA) |
72 | extern const float ColorSwatchCornerRadius; |
73 | extern const float ColorSwatchStrokeSize; |
74 | extern const float ColorSwatchWidth; |
75 | #endif |
76 | |
77 | IntSize dragImageSize(DragImageRef); |
78 | |
79 | // These functions should be memory neutral, eg. if they return a newly allocated image, |
80 | // they should release the input image. As a corollary these methods don't guarantee |
81 | // the input image ref will still be valid after they have been called. |
82 | DragImageRef fitDragImageToMaxSize(DragImageRef, const IntSize& srcSize, const IntSize& dstSize); |
83 | DragImageRef scaleDragImage(DragImageRef, FloatSize scale); |
84 | DragImageRef platformAdjustDragImageForDeviceScaleFactor(DragImageRef, float deviceScaleFactor); |
85 | DragImageRef dissolveDragImageToFraction(DragImageRef, float delta); |
86 | |
87 | DragImageRef createDragImageFromImage(Image*, ImageOrientationDescription); |
88 | DragImageRef createDragImageIconForCachedImageFilename(const String&); |
89 | |
90 | WEBCORE_EXPORT DragImageRef createDragImageForNode(Frame&, Node&); |
91 | WEBCORE_EXPORT DragImageRef createDragImageForSelection(Frame&, TextIndicatorData&, bool forceBlackText = false); |
92 | WEBCORE_EXPORT DragImageRef createDragImageForRange(Frame&, Range&, bool forceBlackText = false); |
93 | DragImageRef createDragImageForColor(const Color&, const FloatRect&, float, Path&); |
94 | DragImageRef createDragImageForImage(Frame&, Node&, IntRect& imageRect, IntRect& elementRect); |
95 | DragImageRef createDragImageForLink(Element&, URL&, const String& label, TextIndicatorData&, FontRenderingMode, float deviceScaleFactor); |
96 | void deleteDragImage(DragImageRef); |
97 | |
98 | IntPoint dragOffsetForLinkDragImage(DragImageRef); |
99 | FloatPoint anchorPointForLinkDragImage(DragImageRef); |
100 | |
101 | class DragImage final { |
102 | public: |
103 | WEBCORE_EXPORT DragImage(); |
104 | explicit DragImage(DragImageRef); |
105 | WEBCORE_EXPORT DragImage(DragImage&&); |
106 | WEBCORE_EXPORT ~DragImage(); |
107 | |
108 | WEBCORE_EXPORT DragImage& operator=(DragImage&&); |
109 | |
110 | void setIndicatorData(const TextIndicatorData& data) { m_indicatorData = data; } |
111 | bool hasIndicatorData() const { return !!m_indicatorData; } |
112 | Optional<TextIndicatorData> indicatorData() const { return m_indicatorData; } |
113 | |
114 | void setVisiblePath(const Path& path) { m_visiblePath = path; } |
115 | bool hasVisiblePath() const { return !!m_visiblePath; } |
116 | Optional<Path> visiblePath() const { return m_visiblePath; } |
117 | |
118 | explicit operator bool() const { return !!m_dragImageRef; } |
119 | DragImageRef get() const { return m_dragImageRef; } |
120 | |
121 | private: |
122 | DragImageRef m_dragImageRef; |
123 | Optional<TextIndicatorData> m_indicatorData; |
124 | Optional<Path> m_visiblePath; |
125 | }; |
126 | |
127 | } |
128 | |