1 | /* |
2 | * Copyright (C) 2010,2017 Igalia S.L. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser 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 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #include "config.h" |
20 | #include "DragImage.h" |
21 | |
22 | #include "Element.h" |
23 | #include "Image.h" |
24 | #include "TextFlags.h" |
25 | #include "TextIndicator.h" |
26 | #include <cairo.h> |
27 | #include <gdk/gdk.h> |
28 | #include <wtf/URL.h> |
29 | |
30 | namespace WebCore { |
31 | |
32 | IntSize dragImageSize(DragImageRef image) |
33 | { |
34 | if (image) |
35 | return { cairo_image_surface_get_width(image.get()), cairo_image_surface_get_height(image.get()) }; |
36 | |
37 | return { 0, 0 }; |
38 | } |
39 | |
40 | void deleteDragImage(DragImageRef) |
41 | { |
42 | // Since this is a RefPtr, there's nothing additional we need to do to |
43 | // delete it. It will be released when it falls out of scope. |
44 | } |
45 | |
46 | DragImageRef scaleDragImage(DragImageRef image, FloatSize scale) |
47 | { |
48 | if (!image) |
49 | return nullptr; |
50 | |
51 | IntSize imageSize = dragImageSize(image); |
52 | IntSize scaledSize(imageSize); |
53 | scaledSize.scale(scale.width(), scale.height()); |
54 | if (imageSize == scaledSize) |
55 | return image; |
56 | |
57 | RefPtr<cairo_surface_t> scaledSurface = adoptRef(cairo_surface_create_similar(image.get(), CAIRO_CONTENT_COLOR_ALPHA, scaledSize.width(), scaledSize.height())); |
58 | |
59 | RefPtr<cairo_t> context = adoptRef(cairo_create(scaledSurface.get())); |
60 | cairo_scale(context.get(), scale.width(), scale.height()); |
61 | cairo_pattern_set_extend(cairo_get_source(context.get()), CAIRO_EXTEND_PAD); |
62 | cairo_pattern_set_filter(cairo_get_source(context.get()), CAIRO_FILTER_BEST); |
63 | cairo_set_operator(context.get(), CAIRO_OPERATOR_SOURCE); |
64 | cairo_set_source_surface(context.get(), image.get(), 0, 0); |
65 | cairo_paint(context.get()); |
66 | |
67 | return scaledSurface; |
68 | } |
69 | |
70 | DragImageRef dissolveDragImageToFraction(DragImageRef image, float fraction) |
71 | { |
72 | if (!image) |
73 | return nullptr; |
74 | |
75 | if (!gdk_screen_is_composited(gdk_screen_get_default())) |
76 | return image; |
77 | |
78 | RefPtr<cairo_t> context = adoptRef(cairo_create(image.get())); |
79 | cairo_set_operator(context.get(), CAIRO_OPERATOR_DEST_IN); |
80 | cairo_set_source_rgba(context.get(), 0, 0, 0, fraction); |
81 | cairo_paint(context.get()); |
82 | return image; |
83 | } |
84 | |
85 | DragImageRef createDragImageFromImage(Image* image, ImageOrientationDescription) |
86 | { |
87 | return image->nativeImageForCurrentFrame(); |
88 | } |
89 | |
90 | DragImageRef createDragImageIconForCachedImageFilename(const String&) |
91 | { |
92 | return nullptr; |
93 | } |
94 | |
95 | DragImageRef createDragImageForLink(Element&, URL&, const String&, TextIndicatorData&, FontRenderingMode, float) |
96 | { |
97 | return nullptr; |
98 | } |
99 | |
100 | DragImageRef createDragImageForColor(const Color&, const FloatRect&, float, Path&) |
101 | { |
102 | return nullptr; |
103 | } |
104 | |
105 | } |
106 | |