forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDraggingInfo.mm
171 lines (140 loc) · 5.58 KB
/
TestDraggingInfo.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright (C) 2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "TestDraggingInfo.h"
#if ENABLE(DRAG_SUPPORT) && PLATFORM(MAC)
#import "AppKitTestSPI.h"
#import "DragAndDropSimulator.h"
#import "TestFilePromiseReceiver.h"
#import <wtf/WeakObjCPtr.h>
#import <wtf/cocoa/TypeCastsCocoa.h>
@implementation TestDraggingInfo {
WeakObjCPtr<id> _source;
WeakObjCPtr<DragAndDropSimulator> _dragAndDropSimulator;
RetainPtr<NSPasteboard> _pasteboard;
RetainPtr<NSImage> _draggedImage;
RetainPtr<NSMutableArray<NSFilePromiseReceiver *>> _filePromiseReceivers;
}
- (instancetype)initWithDragAndDropSimulator:(DragAndDropSimulator *)simulator
{
if (self = [super init]) {
_filePromiseReceivers = adoptNS([NSMutableArray new]);
_dragAndDropSimulator = simulator;
}
return self;
}
@synthesize draggingSourceOperationMask = _draggingSourceOperationMask;
@synthesize draggingLocation = _draggingLocation;
@synthesize draggingFormation = _draggingFormation;
@synthesize numberOfValidItemsForDrop = _numberOfValidItemsForDrop;
- (NSArray<NSFilePromiseReceiver *> *)filePromiseReceivers
{
return _filePromiseReceivers.get();
}
- (NSPasteboard *)draggingPasteboard
{
return _pasteboard.get();
}
- (void)setDraggingPasteboard:(NSPasteboard *)draggingPasteboard
{
_pasteboard = draggingPasteboard;
}
- (id)draggingSource
{
return _source.get().get();
}
- (void)setDraggingSource:(id)draggingSource
{
_source = draggingSource;
}
- (void)enumerateDraggingItemsWithOptions:(NSDraggingItemEnumerationOptions)enumerationOptions forView:(NSView *)view classes:(NSArray<Class> *)classes searchOptions:(NSDictionary<NSString *, id> *)searchOptions usingBlock:(void (^)(NSDraggingItem *, NSInteger, BOOL *))block
{
// FIXME: Much of this can be shared with existing drag and drop testing code in DumpRenderTree,
// perhaps by putting it in Tools/TestRunnerShared.
if (enumerationOptions) {
[NSException raise:@"DragAndDropSimulator" format:@"Dragging item enumeration options are currently unsupported. (got: %tu)", enumerationOptions];
return;
}
if (searchOptions.count) {
[NSException raise:@"DragAndDropSimulator" format:@"Search options are currently unsupported. (got: %@)", searchOptions];
return;
}
BOOL stop = NO;
for (Class classObject in classes) {
if (classObject != NSFilePromiseReceiver.class)
continue;
RetainPtr promisedTypeIdentifiers = dynamic_objc_cast<NSArray>([_pasteboard propertyListForType:NSFilesPromisePboardType]);
RetainPtr externalPromisedFiles = [_dragAndDropSimulator externalPromisedFiles];
RELEASE_ASSERT([promisedTypeIdentifiers count] == [externalPromisedFiles count]);
for (id object in promisedTypeIdentifiers.get())
RELEASE_ASSERT([object isKindOfClass:NSString.class]);
NSUInteger itemIndex = 0;
for (NSURL *promisedFileURL in externalPromisedFiles.get()) {
RetainPtr receiver = adoptNS([[TestFilePromiseReceiver alloc] initWithTypeIdentifier:[promisedTypeIdentifiers objectAtIndex:itemIndex] fileURL:promisedFileURL]);
[receiver setDraggingSource:_source.get().get()];
[_filePromiseReceivers addObject:receiver.get()];
RetainPtr item = adoptNS([[NSDraggingItem alloc] _initWithItem:receiver.get()]);
block(item.get(), 0, &stop);
if (stop)
break;
itemIndex++;
}
}
}
// The following methods are not currently used by WebKit.
@synthesize draggedImageLocation = _draggedImageLocation;
@synthesize draggingSequenceNumber = _draggingSequenceNumber;
@synthesize animatesToDestination = _animatesToDestination;
@synthesize springLoadingHighlight = _springLoadingHighlight;
- (NSWindow *)draggingDestinationWindow
{
return nil;
}
- (NSImage *)draggedImage
{
return _draggedImage.get();
}
- (void)setDraggedImage:(NSImage *)draggedImage
{
_draggedImage = draggedImage;
}
- (void)slideDraggedImageTo:(NSPoint)screenPoint
{
}
IGNORE_WARNINGS_BEGIN("deprecated-implementations")
- (NSArray<NSString *> *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
IGNORE_WARNINGS_END
{
return @[ ];
}
- (void)resetSpringLoading
{
}
- (id)localContext
{
return nil;
}
@end
#endif // ENABLE(DRAG_SUPPORT) && PLATFORM(MAC)