Changeset 234930 in webkit
- Timestamp:
- Aug 16, 2018 9:44:17 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 47 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r234928 r234930 1 2018-08-16 Aditya Keerthi <akeerthi@apple.com> 2 3 Support drag-and-drop for input[type=color] 4 https://bugs.webkit.org/show_bug.cgi?id=188464 5 6 Reviewed by Wenson Hsieh. 7 8 Added tests to verify that dragging from one color input to another behaves as 9 expected in WK1. The tests consider disabled and read-only inputs in addition to 10 default color inputs. The WK2 implementation is tested through API tests. 11 12 * editing/pasteboard/drag-and-drop-color-input-events-expected.txt: Added. 13 * editing/pasteboard/drag-and-drop-color-input-events.html: Added. 14 * editing/pasteboard/drag-and-drop-color-input-expected.txt: Added. 15 * editing/pasteboard/drag-and-drop-color-input.html: Added. 16 * platform/ios/TestExpectations: 17 * platform/mac/TestExpectations: 18 * platform/wk2/TestExpectations: 19 1 20 2018-08-16 Simon Fraser <simon.fraser@apple.com> 2 21 -
trunk/LayoutTests/platform/ios/TestExpectations
r234898 r234930 1009 1009 editing/pasteboard/drop-link.html [ Skip ] 1010 1010 editing/pasteboard/drop-text-events.html [ Skip ] 1011 editing/pasteboard/drag-and-drop-color-input.html [ Skip ] 1012 editing/pasteboard/drag-and-drop-color-input-events.html [ Skip ] 1011 1013 editing/pasteboard/drag-and-drop-image-contenteditable.html [ Skip ] 1012 1014 editing/pasteboard/drag-and-drop-inputimage-contenteditable.html [ Skip ] -
trunk/LayoutTests/platform/mac/TestExpectations
r234821 r234930 1728 1728 accessibility/color-well.html [ Skip ] 1729 1729 fast/forms/color [ Skip ] 1730 editing/pasteboard/drag-and-drop-color-input.html [ Skip ] 1731 editing/pasteboard/drag-and-drop-color-input-events.html [ Skip ] 1730 1732 imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/color.html [ Skip ] 1731 1733 fast/css/read-only-read-write-input-basics.html [ ImageOnlyFailure ] -
trunk/LayoutTests/platform/wk2/TestExpectations
r234718 r234930 571 571 editing/pasteboard/datatransfer-items-drop-plaintext-file.html 572 572 editing/pasteboard/datatransfer-types-dropping-text-file.html 573 editing/pasteboard/drag-and-drop-color-input.html 574 editing/pasteboard/drag-and-drop-color-input-events.html 573 575 editing/pasteboard/drag-and-drop-image-contenteditable.html 574 576 editing/pasteboard/drag-and-drop-inputimage-contenteditable.html -
trunk/Source/WebCore/ChangeLog
r234927 r234930 1 2018-08-16 Aditya Keerthi <akeerthi@apple.com> 2 3 Support drag-and-drop for input[type=color] 4 https://bugs.webkit.org/show_bug.cgi?id=188464 5 6 Reviewed by Wenson Hsieh. 7 8 input[type=color] should support native drag and drop on both macOS and iOS. 9 10 Added methods to Pasteboard and PlatformPasteboard to enable colors to be read 11 from and written to the pasteboard. On macOS, colors are managed through the 12 NSColorPboardType, whereas on iOS, colors are managed through the 13 'com.apple.uikit.color' identifier. 14 15 DragSourceActionColor was added to the list of DragSourceActions to identify 16 when a color input is being dragged. 17 18 Tests: editing/pasteboard/drag-and-drop-color-input-events.html 19 editing/pasteboard/drag-and-drop-color-input.html 20 21 * page/DragActions.h: 22 * page/DragController.cpp: 23 (WebCore::DragController::dragEnteredOrUpdated): 24 (WebCore::isEnabledColorInput): 25 (WebCore::DragController::concludeEditDrag): 26 (WebCore::DragController::canProcessDrag): 27 (WebCore::DragController::draggableElement const): 28 (WebCore::DragController::startDrag): 29 * page/EventHandler.cpp: 30 (WebCore::EventHandler::dragHysteresisExceeded const): 31 (WebCore::EventHandler::handleDrag): 32 * page/EventHandler.h: 33 * page/mac/DragControllerMac.mm: 34 (WebCore::DragController::updateSupportedTypeIdentifiersForDragHandlingMethod const): 35 * platform/DragData.h: 36 * platform/DragImage.cpp: 37 (WebCore::DragImage::operator=): 38 * platform/DragImage.h: Added the visiblePath property to DragImage, in order for 39 us to be able to clip images in the UITargetedDragPreview on iOS. 40 * platform/DragItem.h: 41 (WebCore::DragItem::encode const): 42 (WebCore::DragItem::decode): 43 * platform/Pasteboard.h: 44 * platform/PasteboardStrategy.h: 45 * platform/PlatformPasteboard.h: 46 * platform/gtk/DragImageGtk.cpp: 47 (WebCore::createDragImageForColor): 48 * platform/gtk/PasteboardGtk.cpp: 49 (WebCore::Pasteboard::write): 50 * platform/ios/DragImageIOS.mm: 51 (WebCore::createDragImageForColor): 52 * platform/ios/PasteboardIOS.mm: 53 (WebCore::Pasteboard::write): 54 * platform/ios/PlatformPasteboardIOS.mm: 55 (WebCore::PlatformPasteboard::color): 56 (WebCore::PlatformPasteboard::setColor): 57 * platform/mac/DragDataMac.mm: 58 (WebCore::colorPasteboardType): 59 (WebCore::DragData::containsCompatibleContent const): 60 * platform/mac/DragImageMac.mm: 61 (WebCore::createDragImageForColor): Draw a rounded rectangle with a fill color 62 matching the value of the dragged color input. The rendered image is designed to 63 mimic the preview shown when dragging an NSColorWell. 64 * platform/mac/PasteboardMac.mm: 65 (WebCore::Pasteboard::write): 66 * platform/mac/PlatformPasteboardMac.mm: 67 (WebCore::PlatformPasteboard::setColor): 68 * platform/win/PasteboardWin.cpp: 69 (WebCore::Pasteboard::write): 70 * platform/wpe/PasteboardWPE.cpp: 71 (WebCore::Pasteboard::write): 72 1 73 2018-08-16 Zalan Bujtas <zalan@apple.com> 2 74 -
trunk/Source/WebCore/page/DragActions.h
r221900 r234930 49 49 DragSourceActionAttachment = 16, 50 50 #endif 51 #if ENABLE(INPUT_TYPE_COLOR) 52 DragSourceActionColor = 32, 53 #endif 51 54 DragSourceActionAny = UINT_MAX 52 55 } DragSourceAction; -
trunk/Source/WebCore/page/DragController.cpp
r234885 r234930 322 322 if (dragOperation != DragOperationNone) 323 323 m_dragHandlingMethod = DragHandlingMethod::PageLoad; 324 } 324 } else if (m_dragHandlingMethod == DragHandlingMethod::SetColor) 325 dragOperation = DragOperationCopy; 325 326 326 327 updateSupportedTypeIdentifiersForDragHandlingMethod(m_dragHandlingMethod, dragData); … … 343 344 return inputElement && inputElement->isFileUpload() ? inputElement : nullptr; 344 345 } 346 347 #if ENABLE(INPUT_TYPE_COLOR) 348 static bool isEnabledColorInput(Node& node, bool setToShadowAncestor) 349 { 350 Node* candidate = setToShadowAncestor ? node.deprecatedShadowAncestorNode() : &node; 351 if (is<HTMLInputElement>(*candidate)) { 352 auto& input = downcast<HTMLInputElement>(*candidate); 353 if (input.isColorControl() && !input.isDisabledFormControl()) 354 return true; 355 } 356 357 return false; 358 } 359 #endif 345 360 346 361 // This can return null if an empty document is loaded. … … 540 555 if (!color.isValid()) 541 556 return false; 557 #if ENABLE(INPUT_TYPE_COLOR) 558 if (isEnabledColorInput(*element, false)) { 559 auto& input = downcast<HTMLInputElement>(*element); 560 input.setValue(color.serialized(), DispatchInputAndChangeEvent); 561 return true; 562 } 563 #endif 542 564 auto innerRange = innerFrame->selection().toNormalizedRange(); 543 565 if (!innerRange) … … 644 666 if (asFileInput(*result.innerNonSharedNode())) 645 667 dragPurpose = DragData::DraggingPurpose::ForFileUpload; 668 #if ENABLE(INPUT_TYPE_COLOR) 669 else if (isEnabledColorInput(*result.innerNonSharedNode(), true)) 670 dragPurpose = DragData::DraggingPurpose::ForColorControl; 671 #endif 646 672 647 673 if (!dragData.containsCompatibleContent(dragPurpose)) … … 650 676 if (dragPurpose == DragData::DraggingPurpose::ForFileUpload) 651 677 return true; 678 679 #if ENABLE(INPUT_TYPE_COLOR) 680 if (dragPurpose == DragData::DraggingPurpose::ForColorControl) 681 return true; 682 #endif 652 683 653 684 if (is<HTMLPlugInElement>(*result.innerNonSharedNode())) { … … 786 817 } 787 818 #endif 819 #if ENABLE(INPUT_TYPE_COLOR) 820 if ((m_dragSourceAction & DragSourceActionColor) 821 && isEnabledColorInput(*element, false)) { 822 state.type = static_cast<DragSourceAction>(state.type | DragSourceActionColor); 823 return element; 824 } 825 #endif 788 826 } 789 827 } … … 875 913 #if ENABLE(ATTACHMENT_ELEMENT) 876 914 includeShadowDOM = includeShadowDOM || is<HTMLAttachmentElement>(state.source.get()); 915 #endif 916 #if ENABLE(INPUT_TYPE_COLOR) 917 bool isColorControl = is<HTMLInputElement>(state.source) && downcast<HTMLInputElement>(*state.source).isColorControl(); 918 includeShadowDOM = includeShadowDOM || isColorControl; 877 919 #endif 878 920 bool sourceContainsHitNode; … … 1127 1169 src.selection().setSelection(previousSelection); 1128 1170 src.editor().setIgnoreSelectionChanges(false); 1171 return true; 1172 } 1173 #endif 1174 1175 #if ENABLE(INPUT_TYPE_COLOR) 1176 if (isColorControl && m_dragSourceAction & DragSourceActionColor) { 1177 auto& input = downcast<HTMLInputElement>(*state.source); 1178 auto color = input.valueAsColor(); 1179 1180 Path visiblePath; 1181 dragImage = DragImage { createDragImageForColor(color, input.boundsInRootViewSpace(), input.document().page()->pageScaleFactor(), visiblePath) }; 1182 dragImage.setVisiblePath(visiblePath); 1183 dataTransfer.pasteboard().write(color); 1184 dragImageOffset = IntPoint { dragImageSize(dragImage.get()) }; 1185 dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, false); 1186 1187 m_client.willPerformDragSourceAction(DragSourceActionColor, dragOrigin, dataTransfer); 1188 doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state, { }); 1129 1189 return true; 1130 1190 } -
trunk/Source/WebCore/page/EventHandler.cpp
r234718 r234930 135 135 const int ImageDragHysteresis = 5; 136 136 const int TextDragHysteresis = 3; 137 const int ColorDragHystersis = 3; 137 138 const int GeneralDragHysteresis = 3; 138 139 #if PLATFORM(COCOA) … … 3511 3512 threshold = LinkDragHysteresis; 3512 3513 break; 3514 #if ENABLE(INPUT_TYPE_COLOR) 3515 case DragSourceActionColor: 3516 threshold = ColorDragHystersis; 3517 break; 3518 #endif 3513 3519 case DragSourceActionDHTML: 3514 3520 break; … … 3691 3697 if (!ExactlyOneBitSet(dragState().type)) { 3692 3698 ASSERT((dragState().type & DragSourceActionSelection)); 3693 #if ENABLE(ATTACHMENT_ELEMENT)3694 ASSERT((dragState().type & ~DragSourceActionSelection) == DragSourceActionDHTML3695 || (dragState().type & ~DragSourceActionSelection) == DragSourceActionImage3696 || (dragState().type & ~DragSourceActionSelection) == DragSourceActionAttachment3697 || (dragState().type & ~DragSourceActionSelection) == DragSourceActionLink);3698 #else3699 3699 ASSERT((dragState().type & ~DragSourceActionSelection) == DragSourceActionDHTML 3700 3700 || (dragState().type & ~DragSourceActionSelection) == DragSourceActionImage 3701 #if ENABLE(ATTACHMENT_ELEMENT) 3702 || (dragState().type & ~DragSourceActionSelection) == DragSourceActionAttachment 3703 #endif 3704 #if ENABLE(INPUT_TYPE_COLOR) 3705 || (dragState().type & ~DragSourceActionSelection) == DragSourceActionColor 3706 #endif 3701 3707 || (dragState().type & ~DragSourceActionSelection) == DragSourceActionLink); 3702 #endif 3708 3703 3709 dragState().type = DragSourceActionSelection; 3704 3710 } -
trunk/Source/WebCore/page/EventHandler.h
r233022 r234930 101 101 extern const int ImageDragHysteresis; 102 102 extern const int TextDragHysteresis; 103 extern const int ColorDragHystersis; 103 104 extern const int GeneralDragHysteresis; 104 105 #endif -
trunk/Source/WebCore/page/mac/DragControllerMac.mm
r230211 r234930 145 145 } 146 146 break; 147 case DragHandlingMethod::SetColor: 148 supportedTypes.append(UIColorPboardType); 149 break; 147 150 default: 148 151 for (NSString *type in Pasteboard::supportedFileUploadPasteboardTypes()) -
trunk/Source/WebCore/platform/DragData.h
r228974 r234930 74 74 public: 75 75 enum FilenameConversionPolicy { DoNotConvertFilenames, ConvertFilenames }; 76 enum class DraggingPurpose { ForEditing, ForFileUpload };76 enum class DraggingPurpose { ForEditing, ForFileUpload, ForColorControl }; 77 77 78 78 // clientPosition is taken to be the position of the drag event within the target window, with (0,0) at the top left -
trunk/Source/WebCore/platform/DragImage.cpp
r226425 r234930 39 39 namespace WebCore { 40 40 41 #if PLATFORM(COCOA) 42 const float ColorSwatchCornerRadius = 4; 43 const float ColorSwatchStrokeSize = 4; 44 const float ColorSwatchWidth = 24; 45 #endif 46 41 47 DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& layoutSize, const IntSize& maxSize) 42 48 { … … 260 266 { 261 267 m_indicatorData = other.m_indicatorData; 268 m_visiblePath = other.m_visiblePath; 262 269 } 263 270 … … 269 276 m_dragImageRef = std::exchange(other.m_dragImageRef, nullptr); 270 277 m_indicatorData = other.m_indicatorData; 278 m_visiblePath = other.m_visiblePath; 271 279 272 280 return *this; -
trunk/Source/WebCore/platform/DragImage.h
r218837 r234930 29 29 #include "ImageOrientation.h" 30 30 #include "IntSize.h" 31 #include "Path.h" 31 32 #include "TextFlags.h" 32 33 #include "TextIndicator.h" … … 70 71 71 72 #if PLATFORM(COCOA) 72 static const float SelectionDragImagePadding = 15; 73 extern const float ColorSwatchCornerRadius; 74 extern const float ColorSwatchStrokeSize; 75 extern const float ColorSwatchWidth; 73 76 #endif 74 77 … … 89 92 WEBCORE_EXPORT DragImageRef createDragImageForSelection(Frame&, TextIndicatorData&, bool forceBlackText = false); 90 93 WEBCORE_EXPORT DragImageRef createDragImageForRange(Frame&, Range&, bool forceBlackText = false); 94 DragImageRef createDragImageForColor(const Color&, const FloatRect&, float, Path&); 91 95 DragImageRef createDragImageForImage(Frame&, Node&, IntRect& imageRect, IntRect& elementRect); 92 96 DragImageRef createDragImageForLink(Element&, URL&, const String& label, TextIndicatorData&, FontRenderingMode, float deviceScaleFactor); … … 109 113 std::optional<TextIndicatorData> indicatorData() const { return m_indicatorData; } 110 114 115 void setVisiblePath(const Path& path) { m_visiblePath = path; } 116 bool hasVisiblePath() const { return !!m_visiblePath; } 117 std::optional<Path> visiblePath() const { return m_visiblePath; } 118 111 119 explicit operator bool() const { return !!m_dragImageRef; } 112 120 DragImageRef get() const { return m_dragImageRef; } … … 115 123 DragImageRef m_dragImageRef; 116 124 std::optional<TextIndicatorData> m_indicatorData; 125 std::optional<Path> m_visiblePath; 117 126 }; 118 127 -
trunk/Source/WebCore/platform/DragItem.h
r234333 r234930 68 68 if (hasIndicatorData) 69 69 encoder << image.indicatorData().value(); 70 bool hasVisiblePath = image.hasVisiblePath(); 71 encoder << hasVisiblePath; 72 if (hasVisiblePath) 73 encoder << image.visiblePath().value(); 70 74 encoder << promisedBlob; 71 75 } … … 100 104 result.image.setIndicatorData(*indicatorData); 101 105 } 106 bool hasVisiblePath; 107 if (!decoder.decode(hasVisiblePath)) 108 return false; 109 if (hasVisiblePath) { 110 std::optional<Path> visiblePath; 111 decoder >> visiblePath; 112 if (!visiblePath) 113 return false; 114 result.image.setVisiblePath(*visiblePath); 115 } 102 116 if (!decoder.decode(result.promisedBlob)) 103 117 return false; -
trunk/Source/WebCore/platform/Pasteboard.h
r229503 r234930 214 214 virtual WEBCORE_EXPORT void read(PasteboardFileReader&); 215 215 216 virtual WEBCORE_EXPORT void write(const Color&); 216 217 virtual WEBCORE_EXPORT void write(const PasteboardURL&); 217 218 virtual WEBCORE_EXPORT void writeTrustworthyWebURLsPboardType(const PasteboardURL&); … … 332 333 #if PLATFORM(IOS) 333 334 extern NSString *WebArchivePboardType; 335 extern NSString *UIColorPboardType; 334 336 #endif 335 337 -
trunk/Source/WebCore/platform/PasteboardStrategy.h
r233753 r234930 72 72 virtual long setBufferForType(SharedBuffer*, const String& pasteboardType, const String& pasteboardName) = 0; 73 73 virtual long setURL(const PasteboardURL&, const String& pasteboardName) = 0; 74 virtual long setColor(const Color&, const String& pasteboardName) = 0; 74 75 virtual long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) = 0; 75 76 #endif -
trunk/Source/WebCore/platform/PlatformPasteboard.h
r233753 r234930 86 86 WEBCORE_EXPORT long setBufferForType(SharedBuffer*, const String& pasteboardType); 87 87 WEBCORE_EXPORT long setURL(const PasteboardURL&); 88 WEBCORE_EXPORT long setColor(const Color&); 88 89 WEBCORE_EXPORT long setStringForType(const String&, const String& pasteboardType); 89 90 WEBCORE_EXPORT void write(const PasteboardWebContent&); -
trunk/Source/WebCore/platform/gtk/DragImageGtk.cpp
r212669 r234930 98 98 } 99 99 100 DragImageRef createDragImageForColor(const Color&, const FloatRect&, float, Path&) 101 { 102 return nullptr; 100 103 } 104 105 } -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r233122 r234930 21 21 #include "Pasteboard.h" 22 22 23 #include "Color.h" 23 24 #include "DragData.h" 24 25 #include "Image.h" … … 333 334 } 334 335 335 } 336 void Pasteboard::write(const Color&) 337 { 338 } 339 340 } -
trunk/Source/WebCore/platform/ios/DragImageIOS.mm
r219998 r234930 252 252 } 253 253 254 DragImageRef createDragImageForColor(const Color& color, const FloatRect& elementRect, float pageScaleFactor, Path& visiblePath) 255 { 256 FloatRect imageRect { 0, 0, elementRect.width() * pageScaleFactor, elementRect.height() * pageScaleFactor }; 257 FloatRoundedRect swatch { imageRect, FloatRoundedRect::Radii(ColorSwatchCornerRadius * pageScaleFactor) }; 258 259 auto render = adoptNS([allocUIGraphicsImageRendererInstance() initWithSize:imageRect.size()]); 260 UIImage *image = [render imageWithActions:^(UIGraphicsImageRendererContext *rendererContext) { 261 GraphicsContext context { rendererContext.CGContext }; 262 context.translate(0, CGRectGetHeight(imageRect)); 263 context.scale({ 1, -1 }); 264 context.fillRoundedRect(swatch, color); 265 }]; 266 267 visiblePath.addRoundedRect(swatch); 268 return image.CGImage; 269 } 270 254 271 #else 255 272 -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r234809 r234930 84 84 // FIXME: Does this need to be declared in the header file? 85 85 WEBCORE_EXPORT NSString *WebArchivePboardType = @"Apple Web Archive pasteboard type"; 86 NSString *UIColorPboardType = @"com.apple.uikit.color"; 86 87 87 88 Pasteboard::Pasteboard() … … 138 139 // URLs. 139 140 ASSERT_NOT_REACHED(); 141 } 142 143 void Pasteboard::write(const Color& color) 144 { 145 platformStrategies()->pasteboardStrategy()->setColor(color, m_pasteboardName); 140 146 } 141 147 -
trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
r233753 r234930 38 38 #import "WebItemProviderPasteboard.h" 39 39 #import <MobileCoreServices/MobileCoreServices.h> 40 #import <UIKit/UIColor.h> 40 41 #import <UIKit/UIImage.h> 41 42 #import <UIKit/UIPasteboard.h> … … 50 51 51 52 SOFT_LINK_FRAMEWORK(UIKit) 53 SOFT_LINK_CLASS(UIKit, UIColor) 52 54 SOFT_LINK_CLASS(UIKit, UIImage) 53 55 SOFT_LINK_CLASS(UIKit, UIPasteboard) … … 222 224 Color PlatformPasteboard::color() 223 225 { 224 return Color(); 226 NSData *data = [m_pasteboard dataForPasteboardType:UIColorPboardType]; 227 UIColor *uiColor = [NSKeyedUnarchiver unarchivedObjectOfClass:getUIColorClass() fromData:data error:nil]; 228 return Color(uiColor.CGColor); 225 229 } 226 230 … … 307 311 #endif 308 312 313 } 314 315 long PlatformPasteboard::setColor(const Color& color) 316 { 317 auto representationsToRegister = adoptNS([[WebItemProviderRegistrationInfoList alloc] init]); 318 UIColor *uiColor = [getUIColorClass() colorWithCGColor:cachedCGColor(color)]; 319 [representationsToRegister addData:[NSKeyedArchiver archivedDataWithRootObject:uiColor requiringSecureCoding:NO error:nil] forType:UIColorPboardType]; 320 registerItemToPasteboard(representationsToRegister.get(), m_pasteboard.get()); 321 return 0; 309 322 } 310 323 -
trunk/Source/WebCore/platform/mac/DragDataMac.mm
r230221 r234930 92 92 { 93 93 #if PLATFORM(IOS) 94 return "com.apple.uikit.color";94 return String { UIColorPboardType }; 95 95 #else 96 96 return String(legacyColorPasteboardType()); … … 226 226 if (purpose == DraggingPurpose::ForFileUpload) 227 227 return containsFiles(); 228 229 if (purpose == DraggingPurpose::ForColorControl) 230 return containsColor(); 228 231 229 232 if (purpose == DraggingPurpose::ForEditing && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && containsFiles()) -
trunk/Source/WebCore/platform/mac/DragImageMac.mm
r233552 r234930 337 337 return dragImage; 338 338 } 339 340 DragImageRef createDragImageForColor(const Color& color, const FloatRect&, float, Path&) 341 { 342 auto dragImage = adoptNS([[NSImage alloc] initWithSize:NSMakeSize(ColorSwatchWidth, ColorSwatchWidth)]); 343 344 [dragImage lockFocus]; 345 346 NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(0, 0, ColorSwatchWidth, ColorSwatchWidth) xRadius:ColorSwatchCornerRadius yRadius:ColorSwatchCornerRadius]; 347 [path setLineWidth:ColorSwatchStrokeSize]; 348 349 [nsColor(color) setFill]; 350 [path fill]; 351 352 [[NSColor quaternaryLabelColor] setStroke]; 353 [path stroke]; 354 355 [dragImage unlockFocus]; 356 357 return dragImage; 358 } 339 359 340 360 } // namespace WebCore -
trunk/Source/WebCore/platform/mac/PasteboardMac.mm
r233753 r234930 224 224 } 225 225 226 void Pasteboard::write(const Color& color) 227 { 228 Vector<String> types = { legacyColorPasteboardType() }; 229 platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName); 230 m_changeCount = platformStrategies()->pasteboardStrategy()->setColor(color, m_pasteboardName); 231 } 232 226 233 static NSFileWrapper* fileWrapper(const PasteboardImage& pasteboardImage) 227 234 { -
trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm
r233753 r234930 275 275 } 276 276 277 long PlatformPasteboard::setColor(const Color& color) 278 { 279 NSColor *pasteboardColor = nsColor(color); 280 [pasteboardColor writeToPasteboard:m_pasteboard.get()]; 281 return changeCount(); 282 } 283 277 284 long PlatformPasteboard::setStringForType(const String& string, const String& pasteboardType) 278 285 { -
trunk/Source/WebCore/platform/win/PasteboardWin.cpp
r232198 r234930 31 31 #include "CachedImage.h" 32 32 #include "ClipboardUtilitiesWin.h" 33 #include "Color.h" 33 34 #include "Document.h" 34 35 #include "DocumentFragment.h" … … 1086 1087 } 1087 1088 1089 void Pasteboard::write(const Color&) 1090 { 1091 } 1092 1088 1093 } // namespace WebCore -
trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp
r229503 r234930 150 150 } 151 151 152 void Pasteboard::write(const Color&) 153 { 154 } 155 152 156 } // namespace WebCore -
trunk/Source/WebKit/ChangeLog
r234929 r234930 1 2018-08-16 Aditya Keerthi <akeerthi@apple.com> 2 3 Support drag-and-drop for input[type=color] 4 https://bugs.webkit.org/show_bug.cgi?id=188464 5 6 Reviewed by Wenson Hsieh. 7 8 On iOS, the drag preview for the color input is a rounded rectangle. In order to 9 ensure that the corners appear transparent, the visiblePath property of the 10 UIDragPreviewParameters was set to match the preview's shape. This also required 11 the creation of an additional ArgumentCoder for Path. 12 13 When beginning the drag session, the preview should appear centered about the 14 color input. This is managed in createTargetedDragPreview. However, once the 15 preview is dragged, the preview should be at the center of the touch location. 16 Consequently, DragSourceActionColor was added to the list of sources that could 17 update the drag preview after lifting. 18 19 * Shared/WebCoreArgumentCoders.cpp: 20 (IPC::ArgumentCoder<Path>::decode): 21 * Shared/WebCoreArgumentCoders.h: 22 * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm: 23 (WebKit::WebPasteboardProxy::setPasteboardColor): 24 * UIProcess/WebPasteboardProxy.h: 25 * UIProcess/WebPasteboardProxy.messages.in: 26 * UIProcess/ios/DragDropInteractionState.h: 27 * UIProcess/ios/DragDropInteractionState.mm: 28 (WebKit::createTargetedDragPreview): 29 (WebKit::shouldUseDragImageToCreatePreviewForDragSource): 30 (WebKit::shouldUseVisiblePathToCreatePreviewForDragSource): 31 (WebKit::canUpdatePreviewForActiveDragSource): 32 (WebKit::DragDropInteractionState::previewForDragItem const): 33 (WebKit::DragDropInteractionState::stageDragItem): 34 (WebKit::DragDropInteractionState::updatePreviewsForActiveDragSources): 35 * UIProcess/ios/forms/WKFormColorPicker.mm: 36 (-[WKColorPicker initWithView:]): 37 * UIProcess/mac/WebColorPickerMac.h: 38 * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp: 39 (WebKit::WebPlatformStrategies::setColor): 40 * WebProcess/WebCoreSupport/WebPlatformStrategies.h: 41 1 42 2018-08-16 Per Arne Vollan <pvollan@apple.com> 2 43 -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp
r234172 r234930 853 853 } 854 854 855 std::optional<Path> ArgumentCoder<Path>::decode(Decoder& decoder) 856 { 857 Path path; 858 if (!decode(decoder, path)) 859 return std::nullopt; 860 861 return path; 862 } 863 855 864 void ArgumentCoder<RecentSearch>::encode(Encoder& encoder, const RecentSearch& recentSearch) 856 865 { -
trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h
r234172 r234930 307 307 static void encode(Encoder&, const WebCore::Path&); 308 308 static bool decode(Decoder&, WebCore::Path&); 309 static std::optional<WebCore::Path> decode(Decoder&); 309 310 }; 310 311 -
trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
r233753 r234930 139 139 } 140 140 141 void WebPasteboardProxy::setPasteboardColor(const String& pasteboardName, const WebCore::Color& color, uint64_t& newChangeCount) 142 { 143 newChangeCount = PlatformPasteboard(pasteboardName).setColor(color); 144 } 145 141 146 void WebPasteboardProxy::setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String& string, uint64_t& newChangeCount) 142 147 { -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h
r233753 r234930 97 97 void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount); 98 98 void setPasteboardURL(IPC::Connection&, const WebCore::PasteboardURL&, const String& pasteboardName, uint64_t& newChangeCount); 99 void setPasteboardColor(const String&, const WebCore::Color&, uint64_t&); 99 100 void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount); 100 101 void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount); -
trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in
r233753 r234930 55 55 SetPasteboardTypes(String pasteboardName, Vector<String> pasteboardTypes) -> (uint64_t changeCount) 56 56 SetPasteboardURL(struct WebCore::PasteboardURL pasteboardURL, String pasteboardName) -> (uint64_t changeCount) WantsConnection 57 SetPasteboardColor(String pasteboardName, WebCore::Color color) -> (uint64_t changeCount) 57 58 SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (uint64_t changeCount) 58 59 SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (uint64_t changeCount) -
trunk/Source/WebKit/UIProcess/ios/DragDropInteractionState.h
r221907 r234930 31 31 #import <WebCore/DragActions.h> 32 32 #import <WebCore/DragData.h> 33 #import <WebCore/Path.h> 33 34 #import <WebCore/TextIndicator.h> 34 35 #import <WebCore/URL.h> … … 50 51 RetainPtr<UIImage> image; 51 52 std::optional<WebCore::TextIndicatorData> indicatorData; 53 std::optional<WebCore::Path> visiblePath; 52 54 String linkTitle; 53 55 WebCore::URL linkURL; -
trunk/Source/WebKit/UIProcess/ios/DragDropInteractionState.mm
r222253 r234930 47 47 } 48 48 49 static UITargetedDragPreview *createTargetedDragPreview(UIImage *image, UIView *rootView, UIView *previewContainer, const FloatRect& frameInRootViewCoordinates, const Vector<FloatRect>& clippingRectsInFrameCoordinates, UIColor *backgroundColor )49 static UITargetedDragPreview *createTargetedDragPreview(UIImage *image, UIView *rootView, UIView *previewContainer, const FloatRect& frameInRootViewCoordinates, const Vector<FloatRect>& clippingRectsInFrameCoordinates, UIColor *backgroundColor, UIBezierPath *visiblePath) 50 50 { 51 51 if (frameInRootViewCoordinates.isEmpty() || !image) … … 76 76 [parameters setBackgroundColor:backgroundColor]; 77 77 78 if (visiblePath) 79 [parameters setVisiblePath:visiblePath]; 80 78 81 CGPoint centerInContainerCoordinates = { CGRectGetMidX(frameInContainerCoordinates), CGRectGetMidY(frameInContainerCoordinates) }; 79 82 auto target = adoptNS([[UIDragPreviewTarget alloc] initWithContainer:previewContainer center:centerInContainerCoordinates]); … … 99 102 return false; 100 103 104 #if ENABLE(INPUT_TYPE_COLOR) 105 if (source.action & DragSourceActionColor) 106 return true; 107 #endif 108 101 109 return source.action & (DragSourceActionDHTML | DragSourceActionImage); 110 } 111 112 static bool shouldUseVisiblePathToCreatePreviewForDragSource(const DragSourceState& source) 113 { 114 if (!source.visiblePath) 115 return false; 116 117 #if ENABLE(INPUT_TYPE_COLOR) 118 if (source.action & DragSourceActionColor) 119 return true; 120 #endif 121 122 return false; 102 123 } 103 124 … … 114 135 return true; 115 136 #endif 137 138 return false; 139 } 140 141 static bool canUpdatePreviewForActiveDragSource(const DragSourceState& source) 142 { 143 if (!source.possiblyNeedsDragPreviewUpdate) 144 return false; 145 146 #if ENABLE(INPUT_TYPE_COLOR) 147 if (source.action & DragSourceActionColor) 148 return true; 149 #endif 150 151 if (source.action & DragSourceActionLink && !(source.action & DragSourceActionImage)) 152 return true; 116 153 117 154 return false; … … 159 196 160 197 auto& source = foundSource.value(); 161 if (shouldUseDragImageToCreatePreviewForDragSource(source)) 162 return createTargetedDragPreview(source.image.get(), contentView, previewContainer, source.dragPreviewFrameInRootViewCoordinates, { }, nil); 198 if (shouldUseDragImageToCreatePreviewForDragSource(source)) { 199 if (shouldUseVisiblePathToCreatePreviewForDragSource(source)) { 200 auto path = source.visiblePath.value(); 201 UIBezierPath *visiblePath = [UIBezierPath bezierPathWithCGPath:path.ensurePlatformPath()]; 202 return createTargetedDragPreview(source.image.get(), contentView, previewContainer, source.dragPreviewFrameInRootViewCoordinates, { }, nil, visiblePath); 203 } 204 return createTargetedDragPreview(source.image.get(), contentView, previewContainer, source.dragPreviewFrameInRootViewCoordinates, { }, nil, nil); 205 } 163 206 164 207 if (shouldUseTextIndicatorToCreatePreviewForDragSource(source)) { 165 208 auto indicator = source.indicatorData.value(); 166 209 auto textIndicatorImage = uiImageForImage(indicator.contentImage.get()); 167 return createTargetedDragPreview(textIndicatorImage.get(), contentView, previewContainer, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)] );210 return createTargetedDragPreview(textIndicatorImage.get(), contentView, previewContainer, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)], nil); 168 211 } 169 212 … … 204 247 dragImage, 205 248 item.image.indicatorData(), 249 item.image.visiblePath(), 206 250 item.title.isEmpty() ? nil : (NSString *)item.title, 207 251 item.url.isEmpty() ? nil : (NSURL *)item.url, … … 240 284 { 241 285 for (auto& source : m_activeDragSources) { 242 if (! source.possiblyNeedsDragPreviewUpdate)286 if (!canUpdatePreviewForActiveDragSource(source)) 243 287 continue; 244 245 if (source.action & DragSourceActionImage || !(source.action & DragSourceActionLink)) {246 // Currently, non-image links are the only type of source for which we need to update247 // drag preview providers after the initial lift. All other dragged content should maintain248 // the same targeted drag preview used during the lift animation.249 continue;250 }251 288 252 289 UIDragItem *dragItem = dragItemMatchingIdentifier(m_dragSession.get(), source.itemIdentifier); … … 254 291 continue; 255 292 256 auto linkDraggingCenter = source.adjustedOrigin; 257 RetainPtr<NSString> title = (NSString *)source.linkTitle; 258 RetainPtr<NSURL> url = (NSURL *)source.linkURL; 259 dragItem.previewProvider = [title, url, linkDraggingCenter] () -> UIDragPreview * { 260 UIURLDragPreviewView *previewView = [UIURLDragPreviewView viewWithTitle:title.get() URL:url.get()]; 261 previewView.center = linkDraggingCenter; 262 UIDragPreviewParameters *parameters = [[[UIDragPreviewParameters alloc] initWithTextLineRects:@[ [NSValue valueWithCGRect:previewView.bounds] ]] autorelease]; 263 return [[[UIDragPreview alloc] initWithView:previewView parameters:parameters] autorelease]; 264 }; 293 if (source.action & DragSourceActionLink) { 294 dragItem.previewProvider = [title = retainPtr((NSString *)source.linkTitle), url = retainPtr((NSURL *)source.linkURL), center = source.adjustedOrigin] () -> UIDragPreview * { 295 UIURLDragPreviewView *previewView = [UIURLDragPreviewView viewWithTitle:title.get() URL:url.get()]; 296 previewView.center = center; 297 UIDragPreviewParameters *parameters = [[[UIDragPreviewParameters alloc] initWithTextLineRects:@[ [NSValue valueWithCGRect:previewView.bounds] ]] autorelease]; 298 return [[[UIDragPreview alloc] initWithView:previewView parameters:parameters] autorelease]; 299 }; 300 } 301 #if ENABLE(INPUT_TYPE_COLOR) 302 else if (source.action & DragSourceActionColor) { 303 dragItem.previewProvider = [image = source.image] () -> UIDragPreview * { 304 UIImageView *imageView = [[[UIImageView alloc] initWithImage:image.get()] autorelease]; 305 UIDragPreviewParameters *parameters = [[[UIDragPreviewParameters alloc] initWithTextLineRects:@[ [NSValue valueWithCGRect:[imageView bounds]] ]] autorelease]; 306 return [[[UIDragPreview alloc] initWithView:imageView parameters:parameters] autorelease]; 307 }; 308 } 309 #endif 265 310 266 311 source.possiblyNeedsDragPreviewUpdate = false; -
trunk/Source/WebKit/UIProcess/ios/forms/WKFormColorPicker.mm
r234461 r234930 181 181 } 182 182 183 _colorPicker = adoptNS([[UIView alloc] initWith Size:colorPickerSize]);183 _colorPicker = adoptNS([[UIView alloc] initWithFrame:CGRectMake(0, 0, colorPickerSize.width, colorPickerSize.height)]); 184 184 185 185 CGFloat totalRows = [[getPKColorMatrixViewClass() defaultColorMatrix] count] + 1; -
trunk/Source/WebKit/UIProcess/mac/WebColorPickerMac.h
r234172 r234930 39 39 #import <WebCore/IntRect.h> 40 40 #include <wtf/RetainPtr.h> 41 #include <wtf/Vector.h> 41 42 42 43 namespace WebCore { -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
r234376 r234930 275 275 } 276 276 277 long WebPlatformStrategies::setColor(const Color& color, const String& pasteboardName) 278 { 279 uint64_t newChangeCount { 0 }; 280 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardColor(pasteboardName, color), Messages::WebPasteboardProxy::SetPasteboardColor::Reply(newChangeCount), 0); 281 return newChangeCount; 282 } 283 277 284 long WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName) 278 285 { -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h
r233753 r234930 86 86 long setBufferForType(WebCore::SharedBuffer*, const String& pasteboardType, const String& pasteboardName) override; 87 87 long setURL(const WebCore::PasteboardURL&, const String& pasteboardName) override; 88 long setColor(const WebCore::Color&, const String& pasteboardName) override; 88 89 long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override; 89 90 #endif -
trunk/Source/WebKitLegacy/mac/ChangeLog
r234900 r234930 1 2018-08-16 Aditya Keerthi <akeerthi@apple.com> 2 3 Support drag-and-drop for input[type=color] 4 https://bugs.webkit.org/show_bug.cgi?id=188464 5 6 Reviewed by Wenson Hsieh. 7 8 * WebCoreSupport/WebPlatformStrategies.h: 9 * WebCoreSupport/WebPlatformStrategies.mm: 10 (WebPlatformStrategies::setColor): 11 1 12 2018-08-15 Tim Horton <timothy_horton@apple.com> 2 13 -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h
r233753 r234930 89 89 long setBufferForType(WebCore::SharedBuffer*, const String& pasteboardType, const String& pasteboardName) override; 90 90 long setURL(const WebCore::PasteboardURL&, const String& pasteboardName) override; 91 long setColor(const WebCore::Color&, const String& pasteboardName) override; 91 92 long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override; 92 93 }; -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm
r234376 r234930 169 169 } 170 170 171 long WebPlatformStrategies::setColor(const Color& color, const String& pasteboardName) 172 { 173 return PlatformPasteboard(pasteboardName).setColor(color); 174 } 175 171 176 long WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName) 172 177 { -
trunk/Tools/ChangeLog
r234920 r234930 1 2018-08-16 Aditya Keerthi <akeerthi@apple.com> 2 3 Support drag-and-drop for input[type=color] 4 https://bugs.webkit.org/show_bug.cgi?id=188464 5 6 Reviewed by Wenson Hsieh. 7 8 Added five cross-platform API tests, to verify that dragging and dropping with 9 color inputs changes the value of the drop target if and only if both inputs are 10 enabled. Also tests that the change and input events are fired when changing the 11 value of a color input through drag and drop. 12 13 Additionally, added a macOS-specific test to verify that dropping an item with 14 NSColorPboardType changes the value of the color input. 15 16 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 17 * TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm: 18 (TestWebKitAPI::TEST): 19 * TestWebKitAPI/Tests/WebKitCocoa/color-drop.html: Added. 20 * TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm: 21 (TestWebKitAPI::TEST): 22 1 23 2018-08-16 Antti Koivisto <antti@apple.com> 2 24 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r234875 r234930 774 774 E38A0D351FD50CC300E98C8B /* Threading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38A0D341FD50CBC00E98C8B /* Threading.cpp */; }; 775 775 E3DEA8111F0A589000CBC2E8 /* ThreadGroup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3DEA8101F0A588000CBC2E8 /* ThreadGroup.cpp */; }; 776 E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E5036F77211BC22800BFDBE2 /* color-drop.html */; }; 776 777 ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = ECA680CD1E68CC0900731D20 /* StringUtilities.mm */; }; 777 778 F407FE391F1D0DFC0017CF25 /* enormous.svg in Copy Resources */ = {isa = PBXBuildFile; fileRef = F407FE381F1D0DE60017CF25 /* enormous.svg */; }; … … 965 966 1A50AA201A2A51FC00F4C345 /* close-from-within-create-page.html in Copy Resources */, 966 967 9B270FEE1DDC2C0B002D53F3 /* closed-shadow-tree-test.html in Copy Resources */, 968 E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */, 967 969 F4B825D81EF4DBFB006E417F /* compressed-files.zip in Copy Resources */, 968 970 5C9E56871DF914AE00C9EE33 /* contentBlockerCheck.html in Copy Resources */, … … 2007 2009 E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Deque.cpp; sourceTree = "<group>"; }; 2008 2010 E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; }; 2011 E5036F77211BC22800BFDBE2 /* color-drop.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "color-drop.html"; sourceTree = "<group>"; }; 2009 2012 ECA680CD1E68CC0900731D20 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; }; 2010 2013 F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; }; … … 2611 2614 2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */, 2612 2615 2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */, 2616 E5036F77211BC22800BFDBE2 /* color-drop.html */, 2613 2617 F4B825D61EF4DBD4006E417F /* compressed-files.zip */, 2614 2618 F469FB231F01803500401539 /* contenteditable-and-target.html */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm
r234816 r234930 44 44 } 45 45 46 #if ENABLE(INPUT_TYPE_COLOR) 47 48 TEST(DragAndDropTests, ColorInputToColorInput) 49 { 50 auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]); 51 auto webView = [simulator webView]; 52 53 [webView synchronouslyLoadTestPageNamed:@"color-drop"]; 54 [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)]; 55 EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]); 56 EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]); 57 } 58 59 TEST(DragAndDropTests, ColorInputToDisabledColorInput) 60 { 61 auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]); 62 auto webView = [simulator webView]; 63 64 [webView synchronouslyLoadTestPageNamed:@"color-drop"]; 65 [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").disabled = true"]; 66 [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)]; 67 EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]); 68 EXPECT_WK_STREQ(@"#ff0000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]); 69 } 70 71 TEST(DragAndDropTests, DisabledColorInputToColorInput) 72 { 73 auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]); 74 auto webView = [simulator webView]; 75 76 [webView synchronouslyLoadTestPageNamed:@"color-drop"]; 77 [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").disabled = true"]; 78 [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)]; 79 EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]); 80 EXPECT_WK_STREQ(@"#ff0000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]); 81 } 82 83 TEST(DragAndDropTests, ReadOnlyColorInputToReadOnlyColorInput) 84 { 85 auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]); 86 auto webView = [simulator webView]; 87 88 [webView synchronouslyLoadTestPageNamed:@"color-drop"]; 89 [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").readOnly = true"]; 90 [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").readOnly = true"]; 91 [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)]; 92 EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]); 93 EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]); 94 } 95 96 TEST(DragAndDropTests, ColorInputEvents) 97 { 98 auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]); 99 auto webView = [simulator webView]; 100 101 [webView synchronouslyLoadTestPageNamed:@"color-drop"]; 102 103 __block bool changeEventFired = false; 104 [webView performAfterReceivingMessage:@"change" action:^() { 105 changeEventFired = true; 106 }]; 107 108 __block bool inputEventFired = false; 109 [webView performAfterReceivingMessage:@"input" action:^() { 110 inputEventFired = true; 111 }]; 112 113 [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)]; 114 TestWebKitAPI::Util::run(&inputEventFired); 115 TestWebKitAPI::Util::run(&changeEventFired); 116 } 117 118 #endif 119 46 120 #endif // WK_API_ENABLED && ENABLE(DRAG_SUPPORT) -
trunk/Tools/TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm
r234816 r234930 59 59 } 60 60 61 #if ENABLE(INPUT_TYPE_COLOR) 62 TEST(DragAndDropTests, DropColor) 63 { 64 NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName]; 65 [pasteboard declareTypes:@[NSColorPboardType] owner:nil]; 66 [[NSColor redColor] writeToPasteboard:pasteboard]; 67 68 auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:NSMakeRect(0, 0, 400, 400)]); 69 TestWKWebView *webView = [simulator webView]; 70 [simulator setExternalDragPasteboard:pasteboard]; 71 72 [webView synchronouslyLoadTestPageNamed:@"color-drop"]; 73 [simulator runFrom:NSMakePoint(0, 0) to:NSMakePoint(50, 50)]; 74 EXPECT_WK_STREQ(@"#ff0000", [webView stringByEvaluatingJavaScript:@"document.querySelector(\"input\").value"]); 75 } 76 #endif // ENABLE(INPUT_TYPE_COLOR) 77 61 78 #endif // WK_API_ENABLED && ENABLE(DRAG_SUPPORT) && PLATFORM(MAC)
Note: See TracChangeset
for help on using the changeset viewer.