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>
39typedef struct CGImage *CGImageRef;
40#elif PLATFORM(MAC)
41#include <wtf/RetainPtr.h>
42OBJC_CLASS NSImage;
43#elif PLATFORM(WIN)
44typedef 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
52namespace WebCore {
53
54class Element;
55class Frame;
56class Image;
57class IntRect;
58class Node;
59class Range;
60
61#if PLATFORM(IOS_FAMILY)
62typedef RetainPtr<CGImageRef> DragImageRef;
63#elif PLATFORM(MAC)
64typedef RetainPtr<NSImage> DragImageRef;
65#elif PLATFORM(WIN)
66typedef HBITMAP DragImageRef;
67#elif USE(CAIRO)
68typedef RefPtr<cairo_surface_t> DragImageRef;
69#endif
70
71#if PLATFORM(COCOA)
72extern const float ColorSwatchCornerRadius;
73extern const float ColorSwatchStrokeSize;
74extern const float ColorSwatchWidth;
75#endif
76
77IntSize 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.
82DragImageRef fitDragImageToMaxSize(DragImageRef, const IntSize& srcSize, const IntSize& dstSize);
83DragImageRef scaleDragImage(DragImageRef, FloatSize scale);
84DragImageRef platformAdjustDragImageForDeviceScaleFactor(DragImageRef, float deviceScaleFactor);
85DragImageRef dissolveDragImageToFraction(DragImageRef, float delta);
86
87DragImageRef createDragImageFromImage(Image*, ImageOrientationDescription);
88DragImageRef createDragImageIconForCachedImageFilename(const String&);
89
90WEBCORE_EXPORT DragImageRef createDragImageForNode(Frame&, Node&);
91WEBCORE_EXPORT DragImageRef createDragImageForSelection(Frame&, TextIndicatorData&, bool forceBlackText = false);
92WEBCORE_EXPORT DragImageRef createDragImageForRange(Frame&, Range&, bool forceBlackText = false);
93DragImageRef createDragImageForColor(const Color&, const FloatRect&, float, Path&);
94DragImageRef createDragImageForImage(Frame&, Node&, IntRect& imageRect, IntRect& elementRect);
95DragImageRef createDragImageForLink(Element&, URL&, const String& label, TextIndicatorData&, FontRenderingMode, float deviceScaleFactor);
96void deleteDragImage(DragImageRef);
97
98IntPoint dragOffsetForLinkDragImage(DragImageRef);
99FloatPoint anchorPointForLinkDragImage(DragImageRef);
100
101class DragImage final {
102public:
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
121private:
122 DragImageRef m_dragImageRef;
123 Optional<TextIndicatorData> m_indicatorData;
124 Optional<Path> m_visiblePath;
125};
126
127}
128