Changeset 21437 in webkit
- Timestamp:
- May 12, 2007, 10:15:05 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r21436 r21437 1 2007-05-12 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Hyatt. 4 5 Add test to verify files can be dragged to <input type="file"> 6 7 * fast/forms/dragging-to-file-input-expected.txt: Added. 8 * fast/forms/dragging-to-file-input.html: Added. 9 1 10 2007-05-12 Mitz Pettel <mitz@webkit.org> 2 11 -
trunk/WebCore/ChangeLog
r21436 r21437 1 2007-05-12 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Hyatt. 4 5 <rdar://problem/4728842> Can't drag-and-drop files onto <input type="file"> 6 7 This patch allows a file to be dropped on to a file input field. There 8 are a few changes for data handling and a few to allow the data to be 9 threaded to the appropriate places. 10 11 * page/DragController.cpp: 12 (WebCore::asFileInput): 13 When dropping a file onto a file input we may mouse over either 14 the element itself, or the contained button element. This method 15 returns the base element for the file input in either of these 16 cases. 17 (WebCore::DragController::tryDocumentDrag): 18 Don't try to set the drag caret to a file input. 19 (WebCore::DragController::concludeDrag): 20 Handle dropping onto a file input element. 21 (WebCore::DragController::canProcessDrag): 22 We can now process a file being dragged onto a file input element. 23 24 * platform/DragData.h: 25 New accessors 26 27 * platform/gdk/DragDataGdk.cpp: 28 (WebCore::DragData::containsFiles): 29 (WebCore::DragData::asFilenames): 30 Link stubs. 31 32 * platform/mac/DragDataMac.mm: 33 (WebCore::DragData::containsFiles): 34 (WebCore::DragData::asFilenames): 35 Implement new accessors 36 (WebCore::DragData::containsCompatibleContent): 37 Update containsCompatibleContent to allow standalone files. 38 39 * platform/qt/DragDataQt.cpp: 40 (WebCore::DragData::containsFiles): 41 (WebCore::DragData::asFilenames): 42 Link stubs 43 44 * rendering/RenderFileUploadControl.cpp: 45 (WebCore::RenderFileUploadControl::receiveDroppedFile): 46 * rendering/RenderFileUploadControl.h: 47 For security reasons we don't have an api to allow us to set 48 a value directly on a file input -- attempts to do so are 49 blocked. By adding a method to set the target through the 50 render we bypass such restrictions, and ensure the renderer 51 is updated correctly. 52 1 53 2007-05-12 Mitz Pettel <mitz@webkit.org> 2 54 -
trunk/WebCore/page/DragController.cpp
r21387 r21437 45 45 #include "FrameView.h" 46 46 #include "HTMLAnchorElement.h" 47 #include "HTMLInputElement.h" 48 #include "HTMLNames.h" 47 49 #include "Image.h" 48 50 #include "markup.h" … … 51 53 #include "Page.h" 52 54 #include "PlugInInfoStore.h" 55 #include "RenderFileUploadControl.h" 53 56 #include "RenderImage.h" 54 57 #include "ReplaceSelectionCommand.h" … … 249 252 return operation; 250 253 } 254 255 static HTMLInputElement* asFileInput(Node* node) 256 { 257 ASSERT(node); 258 259 // The button for a FILE input is a sub element with no set input type 260 // In order to get around this problem we assume any non-FILE input element 261 // is this internal button, and try querying the shadow parent node. 262 if (node->hasTagName(HTMLNames::inputTag) && node->isShadowNode() && static_cast<HTMLInputElement*>(node)->inputType() != HTMLInputElement::FILE) 263 node = node->shadowParentNode(); 264 265 if (!node || !node->hasTagName(HTMLNames::inputTag)) 266 return 0; 267 268 HTMLInputElement* inputElem = static_cast<HTMLInputElement*>(node); 269 if (inputElem->inputType() == HTMLInputElement::FILE) 270 return inputElem; 271 272 return 0; 273 } 251 274 252 275 DragOperation DragController::tryDocumentDrag(DragData* dragData, DragDestinationAction actionMask) … … 272 295 IntPoint dragPos = dragData->clientPosition(); 273 296 IntPoint point = frameView->windowToContents(dragPos); 274 Selection dragCaret(visiblePositionForPoint(m_document->frame(), point));275 m_page->dragCaretController()->setSelection(dragCaret);276 297 Element* element = m_document->elementFromPoint(point.x(), point.y()); 277 298 ASSERT(element); 278 299 Frame* innerFrame = element->document()->frame(); 279 300 ASSERT(innerFrame); 301 if (!asFileInput(element)) { 302 Selection dragCaret(visiblePositionForPoint(m_document->frame(), point)); 303 m_page->dragCaretController()->setSelection(dragCaret); 304 } 305 280 306 return dragIsMove(innerFrame->selectionController(), dragData) ? DragOperationMove : DragOperationCopy; 281 307 } … … 342 368 return true; 343 369 } 344 370 345 371 if (!m_page->dragController()->canProcessDrag(dragData)) { 346 372 m_page->dragCaretController()->clear(); 347 373 return false; 374 } 375 376 if (HTMLInputElement* fileInput = asFileInput(element)) { 377 if (!dragData->containsFiles()) 378 return false; 379 380 Vector<String> filenames; 381 dragData->asFilenames(filenames); 382 if (filenames.isEmpty()) 383 return false; 384 385 // Ugly. For security none of the API's available to us to set the input value 386 // on file inputs. Even forcing a change in HTMLInputElement doesn't work as 387 // RenderFileUploadControl clears the file when doing updateFromElement() 388 RenderFileUploadControl* renderer = static_cast<RenderFileUploadControl*>(fileInput->renderer()); 389 390 if (!renderer) 391 return false; 392 393 // Only take the first filename as <input type="file" /> can only accept one 394 renderer->receiveDroppedFile(filenames[0]); 395 return true; 348 396 } 349 397 … … 401 449 402 450 result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, true); 403 if (!result.innerNonSharedNode() || !result.innerNonSharedNode()->isContentEditable()) 404 return false; 405 451 452 if (!result.innerNonSharedNode()) 453 return false; 454 455 if (dragData->containsFiles() && asFileInput(result.innerNonSharedNode())) 456 return true; 457 458 if (!result.innerNonSharedNode()->isContentEditable()) 459 return false; 460 406 461 if (m_didInitiateDrag && m_document == m_dragInitiator && result.isSelected()) 407 462 return false; -
trunk/WebCore/platform/DragData.h
r21180 r21437 33 33 34 34 #include <wtf/Forward.h> 35 #include <wtf/Vector.h> 35 36 36 37 #if PLATFORM(MAC) … … 86 87 String asURL(String* title = 0) const; 87 88 String asPlainText() const; 89 void asFilenames(Vector<String>&) const; 88 90 Color asColor() const; 89 91 PassRefPtr<DocumentFragment> asFragment(Document*) const; 90 92 bool canSmartReplace() const; 91 93 bool containsColor() const; 92 94 bool containsFiles() const; 93 95 private: 94 96 IntPoint m_clientPosition; -
trunk/WebCore/platform/gdk/DragDataGdk.cpp
r19477 r21437 40 40 { 41 41 return false; 42 } 43 44 bool DragData::containsFiles() const 45 { 46 return false; 47 } 48 49 void DragData::asFilenames(Vector<String>& result) const 50 { 42 51 } 43 52 -
trunk/WebCore/platform/mac/DragDataMac.mm
r19832 r21437 56 56 return [[[m_platformDragData draggingPasteboard] types] containsObject:WebSmartPastePboardType]; 57 57 } 58 58 59 59 bool DragData::containsColor() const 60 60 { 61 61 return [[[m_platformDragData draggingPasteboard] types] containsObject:NSColorPboardType]; 62 } 63 64 bool DragData::containsFiles() const 65 { 66 return [[[m_platformDragData draggingPasteboard] types] containsObject:NSFilenamesPboardType]; 67 } 68 69 void DragData::asFilenames(Vector<String>& result) const 70 { 71 NSArray *filenames = [[m_platformDragData draggingPasteboard] propertyListForType:NSFilenamesPboardType]; 72 NSEnumerator *fileEnumerator = [filenames objectEnumerator]; 73 74 while (NSString *filename = [fileEnumerator nextObject]) 75 result.append(filename); 62 76 } 63 77 … … 91 105 } 92 106 93 static bool imageExistsAtPaths(NSArray* paths)94 {95 NSEnumerator *enumerator = [paths objectEnumerator];96 NSString *path;97 98 while ((path = [enumerator nextObject]) != nil)99 if (MimeTypeRegistry::isSupportedImageResourceMIMEType(MimeTypeRegistry::getMIMETypeForExtension([path pathExtension])))100 return true;101 102 return false;103 }104 105 107 bool DragData::containsCompatibleContent() const 106 108 { … … 109 111 NSMutableSet *types = [NSMutableSet setWithArray:[pasteboard types]]; 110 112 [types intersectSet:[NSSet setWithArray:m_pasteboardHelper->insertablePasteboardTypes()]]; 111 if ([types count] == 0) 112 return false; 113 return !([types count] == 1 && [types containsObject:NSFilenamesPboardType] && 114 !imageExistsAtPaths([pasteboard propertyListForType:NSFilenamesPboardType])); 113 return [types count] != 0; 115 114 } 116 115 -
trunk/WebCore/platform/qt/DragDataQt.cpp
r21180 r21437 49 49 notImplemented(); 50 50 return false; 51 } 52 53 bool DragData::containsFiles() const 54 { 55 notImplemented(); 56 return false; 57 } 58 59 void DragData::asFilenames(Vector<String>& result) const 60 { 51 61 } 52 62 -
trunk/WebCore/rendering/RenderFileUploadControl.cpp
r21093 r21437 267 267 } 268 268 269 void RenderFileUploadControl::receiveDroppedFile(const String& filename) 270 { 271 m_fileChooser->chooseFile(filename); 272 } 273 269 274 HTMLFileUploadInnerButtonElement::HTMLFileUploadInnerButtonElement(Document* doc, Node* shadowParent) 270 275 : HTMLInputElement(doc) -
trunk/WebCore/rendering/RenderFileUploadControl.h
r21079 r21437 48 48 49 49 void valueChanged(); 50 51 void receiveDroppedFile(const String&); 50 52 51 53 private: -
trunk/WebKitTools/ChangeLog
r21416 r21437 1 2007-05-12 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Hyatt. 4 5 Add new api to DRT to allow us to test a file being dragged 6 onto <input type="file"> 7 8 * DumpRenderTree/DumpRenderTree.h: 9 * DumpRenderTree/DumpRenderTree.m: 10 (+[LayoutTestController isSelectorExcludedFromWebScript:]): 11 (-[LayoutTestController addFileToPasteboardOnDrag]): 12 (runTest): 13 * DumpRenderTree/UIDelegate.m: 14 (-[UIDelegate webView:dragImage:at:offset:event:pasteboard:source:slideBack:forView:]): 15 1 16 2007-05-11 Holger Hans Peter Freyther <zecke@selfish.org> 2 17 -
trunk/WebKitTools/DumpRenderTree/DumpRenderTree.h
r20742 r21437 40 40 extern BOOL canOpenWindows; 41 41 extern BOOL closeWebViews; 42 extern BOOL addFileToPasteboardOnDrag; 42 43 43 44 WebView *createWebView(); -
trunk/WebKitTools/DumpRenderTree/DumpRenderTree.m
r21413 r21437 111 111 BOOL closeWebViews; 112 112 BOOL closeRemainingWindowsWhenComplete = YES; 113 BOOL addFileToPasteboardOnDrag = NO; 113 114 114 115 static void runTest(const char *pathOrURL); … … 1069 1070 || aSelector == @selector(setCallCloseOnWebViews:) 1070 1071 || aSelector == @selector(setCloseRemainingWindowsWhenComplete:) 1071 || aSelector == @selector(setUseDashboardCompatibilityMode:)) 1072 return NO; 1072 || aSelector == @selector(setUseDashboardCompatibilityMode:) 1073 || aSelector == @selector(addFileToPasteboardOnDrag)) 1074 return NO; 1073 1075 return YES; 1074 1076 } … … 1179 1181 } 1180 1182 1183 - (void)addFileToPasteboardOnDrag 1184 { 1185 addFileToPasteboardOnDrag = YES; 1186 } 1187 1181 1188 - (void)addDisallowedURL:(NSString *)urlString 1182 1189 { … … 1469 1476 return; 1470 1477 } 1471 1478 1472 1479 CFURLRef URL; 1473 1480 if (CFStringHasPrefix(pathOrURLString, CFSTR("http://"))) … … 1499 1506 canOpenWindows = NO; 1500 1507 closeWebViews = YES; 1508 addFileToPasteboardOnDrag = NO; 1501 1509 [[frame webView] _setDashboardBehavior:WebDashboardBehaviorUseBackwardCompatibilityMode to:NO]; 1502 1510 testRepaint = testRepaintDefault; -
trunk/WebKitTools/DumpRenderTree/UIDelegate.m
r20742 r21437 57 57 { 58 58 assert(!draggingInfo); 59 if (addFileToPasteboardOnDrag) { 60 [pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil]; 61 [pboard setPropertyList:[NSArray arrayWithObject:@"DRTFakeFile"] forType:NSFilenamesPboardType]; 62 } 59 63 draggingInfo = [[DumpRenderTreeDraggingInfo alloc] initWithImage:anImage offset:initialOffset pasteboard:pboard source:sourceObj]; 60 64 [EventSendingController replaySavedEvents];
Note:
See TracChangeset
for help on using the changeset viewer.