[IPC] Adopt enum class for DragSourceAction
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Jun 2020 18:54:13 +0000 (18:54 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Jun 2020 18:54:13 +0000 (18:54 +0000)
<https://webkit.org/b/212885>
<rdar://problem/64094134>

Reviewed by Darin Adler.

Source/WebCore:

Summary:
- Convert DragSourceAction to enum class.
- Remove DragSourceActionNone by using Optional<> and
  OptionSet<> (as dictated by how the code used the value).
- Remove DragSourceActionAny and replace (as needed) with
  anyDragSourceAction(). (Some--but not all--uses were removed.)
- Add both WTF::EnumTraits<> and WTF::OptionSetTraits<> for
  DragSourceAction since both Optional<> and OptionSet<> are
  used with IPC.

* loader/EmptyClients.cpp:
* page/DragActions.h:
(WebCore::DragSourceAction):
- Convert to enum class.
(WebCore::anyDragSourceAction): Add.
- Replaces WebCore::DragSourceActionAny.
(WTF::EnumTraits<WebCore::DragSourceAction>): Add.
(WTF::OptionSetTraits<WebCore::DragSourceAction>): Add.
* page/DragClient.h:
* page/DragController.cpp:
(WebCore::DragController::delegateDragSourceAction):
(WebCore::DragController::draggableElement const):
(WebCore::DragController::prepareForDragStart const):
(WebCore::DragController::startDrag):
(WebCore::DragController::doSystemDrag):
- Use OptionSet<>::toSingleValue() and add ASSERT() that it does
  not return WTF::nullopt.
* page/DragController.h:
(WebCore::DragController::dragSourceAction const):
* page/DragState.h:
* page/EventHandler.cpp:
(WebCore::EventHandler::updateDragSourceActionsAllowed const):
(WebCore::EventHandler::dragHysteresisExceeded const):
- Use OptionSet<>::toSingleValue() and add ASSERT() that it does
  not return WTF::nullopt.
- Remove case statements for DragSourceActionNone and
  DragSourceActionAny, along with ASSERT_NOT_REACHED(). The
  ASSERT() for toSingleValue() replaces the DragSourceActionNone
  case.
(WebCore::EventHandler::didStartDrag):
(WebCore::ExactlyOneBitSet): Delete.
- Move to WTF::OptionSet<>::hasExactlyOneBitSet().
(WebCore::EventHandler::handleDrag):
- Add code to #ifndef NDEBUG/#endif instead of modifying
  dragState().type in-place since it seemed weird to modify it
  just to check an ASSERT(), even though it was overwritten
  immediately after that.
* page/EventHandler.h:
* platform/DragItem.h:
(WebCore::DragItem::encode const):
(WebCore::DragItem::decode):
- Stop using decodeEnum()/encodeEnum() with
  Optional<DragSourceAction>.

Source/WebKit:

Summary:
- Convert argument parameters from uint64_t to
  OptionSet<DragSourceAction>.
- Convert DragSourceAction to OptionSet<DragSourceAction>.

* Scripts/webkit/messages.py:
- Map DragSourceAction enum to DragActions.h header.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/DragDropInteractionState.h:
* UIProcess/ios/DragDropInteractionState.mm:
(WebKit::shouldUseDragImageToCreatePreviewForDragSource):
(WebKit::shouldUseVisiblePathToCreatePreviewForDragSource):
(WebKit::shouldUseTextIndicatorToCreatePreviewForDragSource):
(WebKit::canUpdatePreviewForActiveDragSource):
(WebKit::DragDropInteractionState::anyActiveDragSourceIs const):
(WebKit::DragDropInteractionState::stageDragItem):
(WebKit::DragDropInteractionState::hasStagedDragSource const):
(WebKit::DragDropInteractionState::updatePreviewsForActiveDragSources):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _startDrag:item:]):
(-[WKContentView _allowedDragSourceActions]):
(-[WKContentView dragInteraction:willAnimateLiftWithAnimator:session:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::requestDragStart):
(WebKit::WebPageProxy::requestAdditionalItemsForDragSession):
* WebProcess/WebCoreSupport/WebDragClient.cpp:
(WebKit::WebDragClient::dragSourceActionMaskForPoint):
* WebProcess/WebCoreSupport/WebDragClient.h:
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::allowedDragSourceActions const):
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestDragStart):
(WebKit::WebPage::requestAdditionalItemsForDragSession):

Source/WebKitLegacy/mac:

Summary:
- Add and use conversion functions between
  OptionSet<WebCore::DragSourceAction> and WebDragSourceAction.
- Update method signatures.

* WebCoreSupport/WebDragClient.h:
* WebCoreSupport/WebDragClient.mm:
(coreDragSourceActionMask): Add.
(WebDragClient::dragSourceActionMaskForPoint):
(WebDragClient::willPerformDragSourceAction):
(WebDragClient::startDrag):
* WebView/WebView.mm:
(kit): Add.
- Convert from Optional<WebCore::DragSourceAction> to
  WebDragSourceAction.
(-[WebView _startDrag:]):
* WebView/WebViewInternal.h:
(kit): Add declaration to reuse function in WebDragClient.mm.

Source/WebKitLegacy/win:

Summary:
- Add and use conversion functions between
  OptionSet<WebCore::DragSourceAction> and WebDragSourceAction.
- Update method signatures.

* WebCoreSupport/WebDragClient.cpp:
(coreDragSourceActionMask): Add.
(kit): Add.
- Convert from WebCore::DragSourceAction to WebDragSourceAction.
(WebDragClient::dragSourceActionMaskForPoint):
(WebDragClient::willPerformDragSourceAction):
(WebDragClient::startDrag):
* WebCoreSupport/WebDragClient.h:
(WebDragClient::dragSourceActionMaskForPoint):

Source/WTF:

* wtf/OptionSet.h:
(WTF::OptionSet::hasExactlyOneBitSet const): Add.
- Move here from WebCore::ExactlyOneBitSet() in
  Source/WebCore/page/EventHandler.cpp.
(WTF::OptionSet::toSingleValue const): Add.
- Use hasExactlyOneBitSet() to determine whether exactly one
  enum bitmask value can be returned.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262913 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/OptionSet.h
Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/page/DragActions.h
Source/WebCore/page/DragClient.h
Source/WebCore/page/DragController.cpp
Source/WebCore/page/DragController.h
Source/WebCore/page/DragState.h
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventHandler.h
Source/WebCore/platform/DragItem.h
Source/WebKit/ChangeLog
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/ios/DragDropInteractionState.h
Source/WebKit/UIProcess/ios/DragDropInteractionState.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit/WebProcess/WebCoreSupport/WebDragClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebDragClient.h
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebDragClient.h
Source/WebKitLegacy/mac/WebCoreSupport/WebDragClient.mm
Source/WebKitLegacy/mac/WebView/WebView.mm
Source/WebKitLegacy/mac/WebView/WebViewInternal.h
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebCoreSupport/WebDragClient.cpp
Source/WebKitLegacy/win/WebCoreSupport/WebDragClient.h

index 7dd19ab..88d8763 100644 (file)
@@ -1,3 +1,19 @@
+2020-06-11  David Kilzer  <ddkilzer@apple.com>
+
+        [IPC] Adopt enum class for DragSourceAction
+        <https://webkit.org/b/212885>
+        <rdar://problem/64094134>
+
+        Reviewed by Darin Adler.
+
+        * wtf/OptionSet.h:
+        (WTF::OptionSet::hasExactlyOneBitSet const): Add.
+        - Move here from WebCore::ExactlyOneBitSet() in
+          Source/WebCore/page/EventHandler.cpp.
+        (WTF::OptionSet::toSingleValue const): Add.
+        - Use hasExactlyOneBitSet() to determine whether exactly one
+          enum bitmask value can be returned.
+
 2020-06-11  Geoffrey Garen  <ggaren@apple.com>
 
         [Cocoa] Build callOnMainThread on WTF::RunLoop rather than on a timer
index 2dcf43c..59bdae6 100644 (file)
@@ -205,6 +205,16 @@ public:
         m_storage &= ~optionSet.m_storage;
     }
 
+    constexpr bool hasExactlyOneBitSet() const
+    {
+        return m_storage && !(m_storage & (m_storage - 1));
+    }
+
+    constexpr Optional<E> toSingleValue() const
+    {
+        return hasExactlyOneBitSet() ? Optional<E>(static_cast<E>(m_storage)) : WTF::nullopt;
+    }
+
     constexpr friend bool operator==(OptionSet lhs, OptionSet rhs)
     {
         return lhs.m_storage == rhs.m_storage;
index abce693..e3bf701 100644 (file)
@@ -1,3 +1,65 @@
+2020-06-11  David Kilzer  <ddkilzer@apple.com>
+
+        [IPC] Adopt enum class for DragSourceAction
+        <https://webkit.org/b/212885>
+        <rdar://problem/64094134>
+
+        Reviewed by Darin Adler.
+
+        Summary:
+        - Convert DragSourceAction to enum class.
+        - Remove DragSourceActionNone by using Optional<> and
+          OptionSet<> (as dictated by how the code used the value).
+        - Remove DragSourceActionAny and replace (as needed) with
+          anyDragSourceAction(). (Some--but not all--uses were removed.)
+        - Add both WTF::EnumTraits<> and WTF::OptionSetTraits<> for
+          DragSourceAction since both Optional<> and OptionSet<> are
+          used with IPC.
+
+        * loader/EmptyClients.cpp:
+        * page/DragActions.h:
+        (WebCore::DragSourceAction):
+        - Convert to enum class.
+        (WebCore::anyDragSourceAction): Add.
+        - Replaces WebCore::DragSourceActionAny.
+        (WTF::EnumTraits<WebCore::DragSourceAction>): Add.
+        (WTF::OptionSetTraits<WebCore::DragSourceAction>): Add.
+        * page/DragClient.h:
+        * page/DragController.cpp:
+        (WebCore::DragController::delegateDragSourceAction):
+        (WebCore::DragController::draggableElement const):
+        (WebCore::DragController::prepareForDragStart const):
+        (WebCore::DragController::startDrag):
+        (WebCore::DragController::doSystemDrag):
+        - Use OptionSet<>::toSingleValue() and add ASSERT() that it does
+          not return WTF::nullopt.
+        * page/DragController.h:
+        (WebCore::DragController::dragSourceAction const):
+        * page/DragState.h:
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::updateDragSourceActionsAllowed const):
+        (WebCore::EventHandler::dragHysteresisExceeded const):
+        - Use OptionSet<>::toSingleValue() and add ASSERT() that it does
+          not return WTF::nullopt.
+        - Remove case statements for DragSourceActionNone and
+          DragSourceActionAny, along with ASSERT_NOT_REACHED(). The
+          ASSERT() for toSingleValue() replaces the DragSourceActionNone
+          case.
+        (WebCore::EventHandler::didStartDrag):
+        (WebCore::ExactlyOneBitSet): Delete.
+        - Move to WTF::OptionSet<>::hasExactlyOneBitSet().
+        (WebCore::EventHandler::handleDrag):
+        - Add code to #ifndef NDEBUG/#endif instead of modifying
+          dragState().type in-place since it seemed weird to modify it
+          just to check an ASSERT(), even though it was overwritten
+          immediately after that.
+        * page/EventHandler.h:
+        * platform/DragItem.h:
+        (WebCore::DragItem::encode const):
+        (WebCore::DragItem::decode):
+        - Stop using decodeEnum()/encodeEnum() with
+          Optional<DragSourceAction>.
+
 2020-06-11  Youenn Fablet  <youenn@apple.com>
 
         End a remote MediaStreamTrack if its source is ended
index 79b0b31..87d0b86 100644 (file)
@@ -178,7 +178,7 @@ class EmptyDiagnosticLoggingClient final : public DiagnosticLoggingClient {
 class EmptyDragClient final : public DragClient {
     void willPerformDragDestinationAction(DragDestinationAction, const DragData&) final { }
     void willPerformDragSourceAction(DragSourceAction, const IntPoint&, DataTransfer&) final { }
-    DragSourceAction dragSourceActionMaskForPoint(const IntPoint&) final { return DragSourceActionNone; }
+    OptionSet<DragSourceAction> dragSourceActionMaskForPoint(const IntPoint&) final { return { }; }
     void startDrag(DragItem, DataTransfer&, Frame&) final { }
 };
 
index e745635..1f01546 100644 (file)
@@ -44,21 +44,35 @@ constexpr OptionSet<DragDestinationAction> anyDragDestinationAction()
     return OptionSet<DragDestinationAction> { DragDestinationAction::DHTML, DragDestinationAction::Edit, DragDestinationAction::Load };
 }
 
-// WebCoreDragSourceAction should be kept in sync with WebDragSourceAction.
-typedef enum {
-    DragSourceActionNone         = 0,
-    DragSourceActionDHTML        = 1,
-    DragSourceActionImage        = 2,
-    DragSourceActionLink         = 4,
-    DragSourceActionSelection    = 8,
+// See WebDragSourceAction.
+enum class DragSourceAction : uint8_t {
+    DHTML      = 1,
+    Image      = 2,
+    Link       = 4,
+    Selection  = 8,
 #if ENABLE(ATTACHMENT_ELEMENT)
-    DragSourceActionAttachment   = 16,
+    Attachment = 16,
 #endif
 #if ENABLE(INPUT_TYPE_COLOR)
-    DragSourceActionColor        = 32,
+    Color      = 32,
 #endif
-    DragSourceActionAny          = UINT_MAX
-} DragSourceAction;
+};
+
+constexpr OptionSet<DragSourceAction> anyDragSourceAction()
+{
+    return OptionSet<DragSourceAction> {
+        DragSourceAction::DHTML,
+        DragSourceAction::Image,
+        DragSourceAction::Link,
+        DragSourceAction::Selection
+#if ENABLE(ATTACHMENT_ELEMENT)
+        , DragSourceAction::Attachment
+#endif
+#if ENABLE(INPUT_TYPE_COLOR)
+        , DragSourceAction::Color
+#endif
+    };
+}
 
 // See NSDragOperation, _UIDragOperation and UIDropOperation.
 enum class DragOperation : uint8_t {
@@ -108,6 +122,22 @@ template<> struct EnumTraits<WebCore::DragOperation> {
     >;
 };
 
+template<> struct EnumTraits<WebCore::DragSourceAction> {
+    using values = EnumValues<
+        WebCore::DragSourceAction,
+        WebCore::DragSourceAction::DHTML,
+        WebCore::DragSourceAction::Image,
+        WebCore::DragSourceAction::Link,
+        WebCore::DragSourceAction::Selection
+#if ENABLE(ATTACHMENT_ELEMENT)
+        , WebCore::DragSourceAction::Attachment
+#endif
+#if ENABLE(INPUT_TYPE_COLOR)
+        , WebCore::DragSourceAction::Color
+#endif
+    >;
+};
+
 template<> struct OptionSetTraits<WebCore::DragDestinationAction> {
     using values = OptionSetValues<
         WebCore::DragDestinationAction,
@@ -129,4 +159,20 @@ template<> struct OptionSetTraits<WebCore::DragOperation> {
     >;
 };
 
+template<> struct OptionSetTraits<WebCore::DragSourceAction> {
+    using values = OptionSetValues<
+        WebCore::DragSourceAction,
+        WebCore::DragSourceAction::DHTML,
+        WebCore::DragSourceAction::Image,
+        WebCore::DragSourceAction::Link,
+        WebCore::DragSourceAction::Selection
+#if ENABLE(ATTACHMENT_ELEMENT)
+        , WebCore::DragSourceAction::Attachment
+#endif
+#if ENABLE(INPUT_TYPE_COLOR)
+        , WebCore::DragSourceAction::Color
+#endif
+    >;
+};
+
 } // namespace WTF
index 7aa8ee5..998b7bf 100644 (file)
@@ -50,7 +50,7 @@ public:
     virtual void willPerformDragDestinationAction(DragDestinationAction, const DragData&) = 0;
     virtual void willPerformDragSourceAction(DragSourceAction, const IntPoint&, DataTransfer&) = 0;
     virtual void didConcludeEditDrag() { }
-    virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint& rootViewPoint) = 0;
+    virtual OptionSet<DragSourceAction> dragSourceActionMaskForPoint(const IntPoint& rootViewPoint) = 0;
     
     virtual void startDrag(DragItem, DataTransfer&, Frame&) = 0;
     virtual void dragEnded() { }
index 2f30208..2385701 100644 (file)
@@ -483,7 +483,7 @@ DragHandlingMethod DragController::tryDocumentDrag(const DragData& dragData, Opt
     return DragHandlingMethod::None;
 }
 
-DragSourceAction DragController::delegateDragSourceAction(const IntPoint& rootViewPoint)
+OptionSet<DragSourceAction> DragController::delegateDragSourceAction(const IntPoint& rootViewPoint)
 {
     m_dragSourceAction = client().dragSourceActionMaskForPoint(rootViewPoint);
     return m_dragSourceAction;
@@ -769,7 +769,7 @@ static RefPtr<HTMLAttachmentElement> enclosingAttachmentElement(Element& element
 
 Element* DragController::draggableElement(const Frame* sourceFrame, Element* startElement, const IntPoint& dragOrigin, DragState& state) const
 {
-    state.type = (sourceFrame->selection().contains(dragOrigin)) ? DragSourceActionSelection : DragSourceActionNone;
+    state.type = sourceFrame->selection().contains(dragOrigin) ? DragSourceAction::Selection : OptionSet<DragSourceAction>({ });
     if (!startElement)
         return nullptr;
 #if ENABLE(ATTACHMENT_ELEMENT)
@@ -783,7 +783,7 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
         }
 
         if (!isAttachmentElementInCurrentSelection || isSingleAttachmentSelection) {
-            state.type = DragSourceActionAttachment;
+            state.type = DragSourceAction::Attachment;
             return attachment.get();
         }
     }
@@ -795,32 +795,32 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
             continue;
 
         UserDrag dragMode = renderer->style().userDrag();
-        if ((m_dragSourceAction & DragSourceActionDHTML) && dragMode == UserDrag::Element) {
-            state.type = static_cast<DragSourceAction>(state.type | DragSourceActionDHTML);
+        if (m_dragSourceAction.contains(DragSourceAction::DHTML) && dragMode == UserDrag::Element) {
+            state.type.add(DragSourceAction::DHTML);
             return element;
         }
         if (dragMode == UserDrag::Auto) {
-            if ((m_dragSourceAction & DragSourceActionImage)
+            if ((m_dragSourceAction.contains(DragSourceAction::Image))
                 && is<HTMLImageElement>(*element)
                 && imageElementIsDraggable(downcast<HTMLImageElement>(*element), *sourceFrame)) {
-                state.type = static_cast<DragSourceAction>(state.type | DragSourceActionImage);
+                state.type.add(DragSourceAction::Image);
                 return element;
             }
-            if ((m_dragSourceAction & DragSourceActionLink) && isDraggableLink(*element)) {
-                state.type = static_cast<DragSourceAction>(state.type | DragSourceActionLink);
+            if (m_dragSourceAction.contains(DragSourceAction::Link) && isDraggableLink(*element)) {
+                state.type.add(DragSourceAction::Link);
                 return element;
             }
 #if ENABLE(ATTACHMENT_ELEMENT)
-            if ((m_dragSourceAction & DragSourceActionAttachment)
+            if (m_dragSourceAction.contains(DragSourceAction::Attachment)
                 && is<HTMLAttachmentElement>(*element)
                 && downcast<HTMLAttachmentElement>(*element).file()) {
-                state.type = static_cast<DragSourceAction>(state.type | DragSourceActionAttachment);
+                state.type.add(DragSourceAction::Attachment);
                 return element;
             }
 #endif
 #if ENABLE(INPUT_TYPE_COLOR)
-            if ((m_dragSourceAction & DragSourceActionColor) && isEnabledColorInput(*element)) {
-                state.type = static_cast<DragSourceAction>(state.type | DragSourceActionColor);
+            if (m_dragSourceAction.contains(DragSourceAction::Color) && isEnabledColorInput(*element)) {
+                state.type.add(DragSourceAction::Color);
                 return element;
             }
 #endif
@@ -828,7 +828,7 @@ Element* DragController::draggableElement(const Frame* sourceFrame, Element* sta
     }
 
     // We either have nothing to drag or we have a selection and we're not over a draggable element.
-    if (state.type & DragSourceActionSelection && m_dragSourceAction & DragSourceActionSelection)
+    if (state.type.contains(DragSourceAction::Selection) && m_dragSourceAction.contains(DragSourceAction::Selection))
         return startElement;
 
     return nullptr;
@@ -901,7 +901,7 @@ static IntPoint dragLocForSelectionDrag(Frame& src)
     return IntPoint(xpos, ypos);
 }
 
-void DragController::prepareForDragStart(Frame& source, DragSourceAction action, Element& element, DataTransfer& dataTransfer, const IntPoint& dragOrigin) const
+void DragController::prepareForDragStart(Frame& source, OptionSet<DragSourceAction> actionMask, Element& element, DataTransfer& dataTransfer, const IntPoint& dragOrigin) const
 {
 #if !PLATFORM(WIN)
     Ref<Frame> protector(source);
@@ -911,7 +911,7 @@ void DragController::prepareForDragStart(Frame& source, DragSourceAction action,
 
     auto& pasteboard = dataTransfer.pasteboard();
     auto& editor = source.editor();
-    if (action == DragSourceActionSelection) {
+    if (actionMask == DragSourceAction::Selection) {
         if (enclosingTextFormControl(source.selection().selection().start()))
             pasteboard.writePlainText(editor.selectedTextForDataTransfer(), Pasteboard::CannotSmartReplace);
         else
@@ -921,18 +921,18 @@ void DragController::prepareForDragStart(Frame& source, DragSourceAction action,
 
     auto* image = getImage(element);
     auto imageURL = hitTestResult->absoluteImageURL();
-    if ((action & DragSourceActionImage) && !imageURL.isEmpty() && image && !image->isNull()) {
+    if (actionMask.contains(DragSourceAction::Image) && !imageURL.isEmpty() && image && !image->isNull()) {
         editor.writeImageToPasteboard(pasteboard, element, imageURL, { });
         return;
     }
 
     auto linkURL = hitTestResult->absoluteLinkURL();
-    if ((action & DragSourceActionLink) && !linkURL.isEmpty() && source.document()->securityOrigin().canDisplay(linkURL))
+    if (actionMask.contains(DragSourceAction::Link) && !linkURL.isEmpty() && source.document()->securityOrigin().canDisplay(linkURL))
         editor.copyURL(linkURL, hitTestResult->textContent().simplifyWhiteSpace(), pasteboard);
 #else
     // FIXME: Make this work on Windows by implementing Editor::writeSelectionToPasteboard and Editor::writeImageToPasteboard.
     UNUSED_PARAM(source);
-    UNUSED_PARAM(action);
+    UNUSED_PARAM(actionMask);
     UNUSED_PARAM(element);
     UNUSED_PARAM(dataTransfer);
     UNUSED_PARAM(dragOrigin);
@@ -983,7 +983,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
     ASSERT(state.dataTransfer);
 
     DataTransfer& dataTransfer = *state.dataTransfer;
-    if (state.type == DragSourceActionDHTML) {
+    if (state.type == DragSourceAction::DHTML) {
         dragImage = DragImage { dataTransfer.createDragImage(dragImageOffset) };
         // We allow DHTML/JS to set the drag image, even if its a link, image or text we're dragging.
         // This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp.
@@ -993,7 +993,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
         }
     }
 
-    if (state.type == DragSourceActionSelection || !imageURL.isEmpty() || !linkURL.isEmpty()) {
+    if (state.type == DragSourceAction::Selection || !imageURL.isEmpty() || !linkURL.isEmpty()) {
         // Selection, image, and link drags receive a default set of allowed drag operations that
         // follows from:
         // http://trac.webkit.org/browser/trunk/WebKit/mac/WebView/WebHTMLView.mm?rev=48526#L3430
@@ -1007,7 +1007,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
 
     IntRect dragImageBounds;
     Image* image = getImage(element);
-    if (state.type == DragSourceActionSelection) {
+    if (state.type == DragSourceAction::Selection) {
         PasteboardWriterData pasteboardWriterData;
 
         if (hasData == HasNonDefaultPasteboardData::No) {
@@ -1049,7 +1049,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
 
             src.editor().didWriteSelectionToPasteboard();
         }
-        client().willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, dataTransfer);
+        client().willPerformDragSourceAction(DragSourceAction::Selection, dragOrigin, dataTransfer);
         if (!dragImage) {
             TextIndicatorData textIndicator;
             dragImage = DragImage { dissolveDragImageToFraction(createDragImageForSelection(src, textIndicator), DragImageAlpha) };
@@ -1072,7 +1072,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
         dragItem.image = WTFMove(dragImage);
         dragItem.data = WTFMove(pasteboardWriterData);
 
-        beginDrag(WTFMove(dragItem), src, dragOrigin, mouseDraggedPoint, dataTransfer, DragSourceActionSelection);
+        beginDrag(WTFMove(dragItem), src, dragOrigin, mouseDraggedPoint, dataTransfer, DragSourceAction::Selection);
 
         return true;
     }
@@ -1082,7 +1082,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
         return false;
     }
 
-    if (!imageURL.isEmpty() && image && !image->isNull() && (m_dragSourceAction & DragSourceActionImage)) {
+    if (!imageURL.isEmpty() && image && !image->isNull() && m_dragSourceAction.contains(DragSourceAction::Image)) {
         // We shouldn't be starting a drag for an image that can't provide an extension.
         // This is an early detection for problems encountered later upon drop.
         ASSERT(!image->filenameExtension().isEmpty());
@@ -1101,7 +1101,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
                 declareAndWriteDragImage(dataTransfer, element, !linkURL.isEmpty() ? linkURL : imageURL, hitTestResult->altDisplayString());
         }
 
-        client().willPerformDragSourceAction(DragSourceActionImage, dragOrigin, dataTransfer);
+        client().willPerformDragSourceAction(DragSourceAction::Image, dragOrigin, dataTransfer);
 
         if (!dragImage)
             doImageDrag(element, dragOrigin, hitTestResult->imageRect(), src, m_dragOffset, state, WTFMove(attachmentInfo));
@@ -1113,7 +1113,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
         return true;
     }
 
-    if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) {
+    if (!linkURL.isEmpty() && m_dragSourceAction.contains(DragSourceAction::Link)) {
         PasteboardWriterData pasteboardWriterData;
 
         String textContentWithSimplifiedWhiteSpace = hitTestResult->textContent().simplifyWhiteSpace();
@@ -1145,7 +1145,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
                 src.selection().setSelection(VisibleSelection::selectionFromContentsOfNode(node));
         }
 
-        client().willPerformDragSourceAction(DragSourceActionLink, dragOrigin, dataTransfer);
+        client().willPerformDragSourceAction(DragSourceAction::Link, dragOrigin, dataTransfer);
         if (!dragImage) {
             TextIndicatorData textIndicator;
             dragImage = DragImage { createDragImageForLink(element, linkURL, textContentWithSimplifiedWhiteSpace, textIndicator, src.settings().fontRenderingMode(), m_page.deviceScaleFactor()) };
@@ -1168,13 +1168,13 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
         dragItem.image = WTFMove(dragImage);
         dragItem.data = WTFMove(pasteboardWriterData);
 
-        beginDrag(WTFMove(dragItem), src, dragOrigin, mouseDraggedPoint, dataTransfer, DragSourceActionSelection);
+        beginDrag(WTFMove(dragItem), src, dragOrigin, mouseDraggedPoint, dataTransfer, DragSourceAction::Selection);
 
         return true;
     }
 
 #if ENABLE(ATTACHMENT_ELEMENT)
-    if (is<HTMLAttachmentElement>(element) && m_dragSourceAction & DragSourceActionAttachment) {
+    if (is<HTMLAttachmentElement>(element) && m_dragSourceAction.contains(DragSourceAction::Attachment)) {
         auto& attachment = downcast<HTMLAttachmentElement>(element);
         auto* attachmentRenderer = attachment.renderer();
 
@@ -1196,7 +1196,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
 #endif
         }
         
-        client().willPerformDragSourceAction(DragSourceActionAttachment, dragOrigin, dataTransfer);
+        client().willPerformDragSourceAction(DragSourceAction::Attachment, dragOrigin, dataTransfer);
         
         if (!dragImage) {
             TextIndicatorData textIndicator;
@@ -1220,7 +1220,7 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
 
 #if ENABLE(INPUT_TYPE_COLOR)
     bool isColorControl = is<HTMLInputElement>(state.source) && downcast<HTMLInputElement>(*state.source).isColorControl();
-    if (isColorControl && m_dragSourceAction & DragSourceActionColor) {
+    if (isColorControl && m_dragSourceAction.contains(DragSourceAction::Color)) {
         auto& input = downcast<HTMLInputElement>(*state.source);
         auto color = input.valueAsColor();
 
@@ -1231,15 +1231,15 @@ bool DragController::startDrag(Frame& src, const DragState& state, OptionSet<Dra
         dragImageOffset = IntPoint { dragImageSize(dragImage.get()) };
         dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, false);
 
-        client().willPerformDragSourceAction(DragSourceActionColor, dragOrigin, dataTransfer);
+        client().willPerformDragSourceAction(DragSourceAction::Color, dragOrigin, dataTransfer);
         doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state, { });
         return true;
     }
 #endif
 
-    if (state.type == DragSourceActionDHTML && dragImage) {
-        ASSERT(m_dragSourceAction & DragSourceActionDHTML);
-        client().willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, dataTransfer);
+    if (state.type == DragSourceAction::DHTML && dragImage) {
+        ASSERT(m_dragSourceAction.contains(DragSourceAction::DHTML));
+        client().willPerformDragSourceAction(DragSourceAction::DHTML, dragOrigin, dataTransfer);
         doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state, { });
         return true;
     }
@@ -1329,7 +1329,8 @@ void DragController::doSystemDrag(DragImage image, const IntPoint& dragLoc, cons
 
     DragItem item;
     item.image = WTFMove(image);
-    item.sourceAction = state.type;
+    ASSERT(state.type.hasExactlyOneBitSet());
+    item.sourceAction = state.type.toSingleValue();
     item.promisedAttachmentInfo = WTFMove(promisedAttachmentInfo);
 
     auto eventPositionInRootViewCoordinates = frame.view()->contentsToRootView(eventPos);
@@ -1339,7 +1340,7 @@ void DragController::doSystemDrag(DragImage image, const IntPoint& dragLoc, cons
     item.dragLocationInWindowCoordinates = viewProtector->contentsToWindow(item.dragLocationInContentCoordinates);
     if (auto element = state.source) {
         auto dataTransferImageElement = state.dataTransfer->dragImageElement();
-        if (state.type == DragSourceActionDHTML) {
+        if (state.type == DragSourceAction::DHTML) {
             // If the drag image has been customized, fall back to positioning the preview relative to the drag event location.
             IntSize dragPreviewSize;
             if (dataTransferImageElement)
index ea499e0..9224ab2 100644 (file)
@@ -76,12 +76,12 @@ public:
     const URL& draggingImageURL() const { return m_draggingImageURL; }
     void setDragOffset(const IntPoint& offset) { m_dragOffset = offset; }
     const IntPoint& dragOffset() const { return m_dragOffset; }
-    DragSourceAction dragSourceAction() const { return m_dragSourceAction; }
+    OptionSet<DragSourceAction> dragSourceAction() const { return m_dragSourceAction; }
     DragHandlingMethod dragHandlingMethod() const { return m_dragHandlingMethod; }
 
     Document* documentUnderMouse() const { return m_documentUnderMouse.get(); }
     OptionSet<DragDestinationAction> dragDestinationActionMask() const { return m_dragDestinationActionMask; }
-    DragSourceAction delegateDragSourceAction(const IntPoint& rootViewPoint);
+    OptionSet<DragSourceAction> delegateDragSourceAction(const IntPoint& rootViewPoint);
 
     Element* draggableElement(const Frame*, Element* start, const IntPoint&, DragState&) const;
     WEBCORE_EXPORT void dragEnded();
@@ -94,7 +94,7 @@ public:
     WEBCORE_EXPORT void finalizeDroppedImagePlaceholder(HTMLImageElement&);
     WEBCORE_EXPORT void insertDroppedImagePlaceholdersAtCaret(const Vector<IntSize>& imageSizes);
 
-    void prepareForDragStart(Frame& sourceFrame, DragSourceAction, Element& sourceElement, DataTransfer&, const IntPoint& dragOrigin) const;
+    void prepareForDragStart(Frame& sourceFrame, OptionSet<DragSourceAction>, Element& sourceElement, DataTransfer&, const IntPoint& dragOrigin) const;
     bool startDrag(Frame& src, const DragState&, OptionSet<DragOperation>, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, HasNonDefaultPasteboardData);
     static const IntSize& maxDragImageSize();
 
@@ -154,7 +154,7 @@ private:
     DragHandlingMethod m_dragHandlingMethod { DragHandlingMethod::None };
 
     OptionSet<DragDestinationAction> m_dragDestinationActionMask;
-    DragSourceAction m_dragSourceAction { DragSourceActionNone };
+    OptionSet<DragSourceAction> m_dragSourceAction;
     bool m_didInitiateDrag { false };
     OptionSet<DragOperation> m_sourceDragOperationMask; // Set in startDrag when a drag starts from a mouse down within WebKit.
     IntPoint m_dragOffset;
index 6d16259..7024254 100644 (file)
@@ -35,7 +35,7 @@ namespace WebCore {
 struct DragState {
     RefPtr<Element> source; // Element that may be a drag source, for the current mouse gesture.
     bool shouldDispatchEvents;
-    DragSourceAction type;
+    OptionSet<DragSourceAction> type; // Should be Optional<>. See Bug 213086.
     RefPtr<DataTransfer> dataTransfer; // Used on only the source side of dragging.
 };
 
index 14bcc5b..5e3db4d 100644 (file)
@@ -1190,15 +1190,15 @@ bool EventHandler::panScrollInProgress() const
 }
 
 #if ENABLE(DRAG_SUPPORT)
-DragSourceAction EventHandler::updateDragSourceActionsAllowed() const
+OptionSet<DragSourceAction> EventHandler::updateDragSourceActionsAllowed() const
 {
     Page* page = m_frame.page();
     if (!page)
-        return DragSourceActionNone;
+        return { };
 
     FrameView* view = m_frame.view();
     if (!view)
-        return DragSourceActionNone;
+        return { };
 
     return page->dragController().delegateDragSourceAction(view->contentsToRootView(m_mouseDownContentsPosition));
 }
@@ -3647,35 +3647,36 @@ bool EventHandler::dragHysteresisExceeded(const IntPoint& floatDragViewportLocat
 
 bool EventHandler::dragHysteresisExceeded(const FloatPoint& dragViewportLocation) const
 {
+    auto dragOperation = dragState().type.toSingleValue();
+    ASSERT(dragOperation);
     int threshold = GeneralDragHysteresis;
-    switch (dragState().type) {
-    case DragSourceActionSelection:
-        threshold = TextDragHysteresis;
-        break;
-    case DragSourceActionImage:
+    if (dragOperation) {
+        switch (*dragOperation) {
+        case DragSourceAction::Selection:
+            threshold = TextDragHysteresis;
+            break;
+        case DragSourceAction::Image:
 #if ENABLE(ATTACHMENT_ELEMENT)
-    case DragSourceActionAttachment:
+        case DragSourceAction::Attachment:
 #endif
-        threshold = ImageDragHysteresis;
-        break;
-    case DragSourceActionLink:
-        threshold = LinkDragHysteresis;
-        break;
+            threshold = ImageDragHysteresis;
+            break;
+        case DragSourceAction::Link:
+            threshold = LinkDragHysteresis;
+            break;
 #if ENABLE(INPUT_TYPE_COLOR)
-    case DragSourceActionColor:
-        threshold = ColorDragHystersis;
-        break;
+        case DragSourceAction::Color:
+            threshold = ColorDragHystersis;
+            break;
 #endif
-    case DragSourceActionDHTML:
-        break;
-    case DragSourceActionNone:
-    case DragSourceActionAny:
-        ASSERT_NOT_REACHED();
+        case DragSourceAction::DHTML:
+            break;
+        }
     }
-    
+
     return mouseMovementExceedsThreshold(dragViewportLocation, threshold);
 }
-    
+
 void EventHandler::invalidateDataTransfer()
 {
     if (!dragState().dataTransfer)
@@ -3715,7 +3716,7 @@ void EventHandler::didStartDrag()
         return;
 
     Optional<SimpleRange> draggedContentRange;
-    if (dragState().type & DragSourceActionSelection)
+    if (dragState().type.contains(DragSourceAction::Selection))
         draggedContentRange = m_frame.selection().selection().toNormalizedRange();
     else
         draggedContentRange = makeRangeSelectingNode(*dragSource);
@@ -3775,11 +3776,6 @@ bool EventHandler::dispatchDragStartEventOnSourceElement(DataTransfer& dataTrans
     return !dispatchDragEvent(eventNames().dragstartEvent, *dragState().source, m_mouseDownEvent, dataTransfer) && !m_frame.selection().selection().isInPasswordField();
 }
 
-static bool ExactlyOneBitSet(DragSourceAction n)
-{
-    return n && !(n & (n - 1));
-}
-
 RefPtr<Element> EventHandler::draggedElement() const
 {
     return dragState().source;
@@ -3803,7 +3799,7 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
     
     // Careful that the drag starting logic stays in sync with eventMayStartDrag().
     if (m_mouseDownMayStartDrag && !dragState().source) {
-        dragState().shouldDispatchEvents = (updateDragSourceActionsAllowed() & DragSourceActionDHTML);
+        dragState().shouldDispatchEvents = updateDragSourceActionsAllowed().contains(DragSourceAction::DHTML);
 
         // Try to find an element that wants to be dragged.
         HitTestResult result(m_mouseDownContentsPosition);
@@ -3814,17 +3810,17 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
         if (!dragState().source)
             m_mouseDownMayStartDrag = false; // no element is draggable
         else
-            m_dragMayStartSelectionInstead = (dragState().type & DragSourceActionSelection);
+            m_dragMayStartSelectionInstead = dragState().type.contains(DragSourceAction::Selection);
     }
     
     // For drags starting in the selection, the user must wait between the mousedown and mousedrag,
     // or else we bail on the dragging stuff and allow selection to occur
-    if (m_mouseDownMayStartDrag && m_dragMayStartSelectionInstead && (dragState().type & DragSourceActionSelection) && event.event().timestamp() - m_mouseDownTimestamp < TextDragDelay) {
+    if (m_mouseDownMayStartDrag && m_dragMayStartSelectionInstead && dragState().type.contains(DragSourceAction::Selection) && event.event().timestamp() - m_mouseDownTimestamp < TextDragDelay) {
         ASSERT(event.event().type() == PlatformEvent::MouseMoved);
-        if ((dragState().type & DragSourceActionImage)) {
+        if (dragState().type.contains(DragSourceAction::Image)) {
             // ... unless the mouse is over an image, then we start dragging just the image
-            dragState().type = DragSourceActionImage;
-        } else if (!(dragState().type & (DragSourceActionDHTML | DragSourceActionLink))) {
+            dragState().type = DragSourceAction::Image;
+        } else if (!dragState().type.containsAny({ DragSourceAction::DHTML, DragSourceAction::Link })) {
             // ... but only bail if we're not over an unselectable element.
             m_mouseDownMayStartDrag = false;
             dragState().source = nullptr;
@@ -3845,11 +3841,15 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
         return !mouseDownMayStartSelect() && !m_mouseDownMayStartAutoscroll;
     ASSERT(dragState().source);
 
-    if (!ExactlyOneBitSet(dragState().type)) {
-        ASSERT(dragState().type & DragSourceActionSelection);
-        ASSERT(ExactlyOneBitSet(static_cast<DragSourceAction>(dragState().type & ~DragSourceActionSelection)));
+    if (!dragState().type.hasExactlyOneBitSet()) {
+        ASSERT(dragState().type.contains(DragSourceAction::Selection));
+#ifndef NDEBUG
+        auto actionMaskCopy = dragState().type;
+        actionMaskCopy.remove(DragSourceAction::Selection);
+        ASSERT(actionMaskCopy.hasExactlyOneBitSet());
+#endif
 
-        dragState().type = DragSourceActionSelection;
+        dragState().type = DragSourceAction::Selection;
     }
 
     // We are starting a text/image/url drag, so the cursor should be an arrow
@@ -3881,7 +3881,7 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
             hasNonDefaultPasteboardData = HasNonDefaultPasteboardData::Yes;
         dragState().dataTransfer->moveDragState(WTFMove(dragStartDataTransfer));
 
-        if (dragState().source && dragState().type == DragSourceActionDHTML && !dragState().dataTransfer->hasDragImage()) {
+        if (dragState().source && dragState().type == DragSourceAction::DHTML && !dragState().dataTransfer->hasDragImage()) {
             dragState().source->document().updateStyleIfNeeded();
             if (auto* renderer = dragState().source->renderer()) {
                 auto absolutePosition = renderer->localToAbsolute();
index 27cae61..f7a16c1 100644 (file)
@@ -465,7 +465,7 @@ private:
     void defaultArrowEventHandler(FocusDirection, KeyboardEvent&);
 
 #if ENABLE(DRAG_SUPPORT)
-    DragSourceAction updateDragSourceActionsAllowed() const;
+    OptionSet<DragSourceAction> updateDragSourceActionsAllowed() const;
     bool supportsSelectionUpdatesOnMouseDrag() const;
 #endif
 
index e5859c4..1d1f2a7 100644 (file)
@@ -41,7 +41,7 @@ struct DragItem final {
     // Where the image should be positioned relative to the cursor.
     FloatPoint imageAnchorPoint;
 
-    DragSourceAction sourceAction { DragSourceActionNone };
+    Optional<DragSourceAction> sourceAction;
     IntPoint eventPositionInContentCoordinates;
     IntPoint dragLocationInContentCoordinates;
     IntPoint dragLocationInWindowCoordinates;
@@ -61,7 +61,7 @@ void DragItem::encode(Encoder& encoder) const
 {
     // FIXME(173815): We should encode and decode PasteboardWriterData and platform drag image data
     // here too, as part of moving off of the legacy dragging codepath.
-    encoder.encodeEnum(sourceAction);
+    encoder << sourceAction;
     encoder << imageAnchorPoint << eventPositionInContentCoordinates << dragLocationInContentCoordinates << dragLocationInWindowCoordinates << title << url << dragPreviewFrameInRootViewCoordinates;
     bool hasIndicatorData = image.hasIndicatorData();
     encoder << hasIndicatorData;
@@ -77,7 +77,7 @@ void DragItem::encode(Encoder& encoder) const
 template<class Decoder>
 bool DragItem::decode(Decoder& decoder, DragItem& result)
 {
-    if (!decoder.decodeEnum(result.sourceAction))
+    if (!decoder.decode(result.sourceAction))
         return false;
     if (!decoder.decode(result.imageAnchorPoint))
         return false;
index e7f849d..7d904f5 100644 (file)
@@ -1,3 +1,46 @@
+2020-06-11  David Kilzer  <ddkilzer@apple.com>
+
+        [IPC] Adopt enum class for DragSourceAction
+        <https://webkit.org/b/212885>
+        <rdar://problem/64094134>
+
+        Reviewed by Darin Adler.
+
+        Summary:
+        - Convert argument parameters from uint64_t to
+          OptionSet<DragSourceAction>.
+        - Convert DragSourceAction to OptionSet<DragSourceAction>.
+
+        * Scripts/webkit/messages.py:
+        - Map DragSourceAction enum to DragActions.h header.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/DragDropInteractionState.h:
+        * UIProcess/ios/DragDropInteractionState.mm:
+        (WebKit::shouldUseDragImageToCreatePreviewForDragSource):
+        (WebKit::shouldUseVisiblePathToCreatePreviewForDragSource):
+        (WebKit::shouldUseTextIndicatorToCreatePreviewForDragSource):
+        (WebKit::canUpdatePreviewForActiveDragSource):
+        (WebKit::DragDropInteractionState::anyActiveDragSourceIs const):
+        (WebKit::DragDropInteractionState::stageDragItem):
+        (WebKit::DragDropInteractionState::hasStagedDragSource const):
+        (WebKit::DragDropInteractionState::updatePreviewsForActiveDragSources):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _startDrag:item:]):
+        (-[WKContentView _allowedDragSourceActions]):
+        (-[WKContentView dragInteraction:willAnimateLiftWithAnimator:session:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::requestDragStart):
+        (WebKit::WebPageProxy::requestAdditionalItemsForDragSession):
+        * WebProcess/WebCoreSupport/WebDragClient.cpp:
+        (WebKit::WebDragClient::dragSourceActionMaskForPoint):
+        * WebProcess/WebCoreSupport/WebDragClient.h:
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::allowedDragSourceActions const):
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestDragStart):
+        (WebKit::WebPage::requestAdditionalItemsForDragSession):
+
 2020-06-11  Eric Carlson  <eric.carlson@apple.com>
 
         [Cocoa] MediaUsageManagerCocoa should use a different USVideoUsage initializer
index 1bfd282..62c508e 100644 (file)
@@ -591,6 +591,7 @@ def headers_for_type(type):
         'WebKit::DocumentEditingContextRequest': ['"DocumentEditingContext.h"'],
         'WebCore::DragHandlingMethod': ['<WebCore/DragActions.h>'],
         'WebCore::DragOperation': ['<WebCore/DragActions.h>'],
+        'WebCore::DragSourceAction': ['<WebCore/DragActions.h>'],
         'WebCore::ExceptionDetails': ['<WebCore/JSDOMExceptionHandling.h>'],
         'WebCore::FileChooserSettings': ['<WebCore/FileChooser.h>'],
         'WebCore::ShareDataWithParsedURL': ['<WebCore/ShareData.h>'],
index 3c84c1c..e1db2ce 100644 (file)
@@ -833,8 +833,8 @@ public:
 #if ENABLE(DRAG_SUPPORT)
     void didHandleDragStartRequest(bool started);
     void didHandleAdditionalDragItemsRequest(bool added);
-    void requestDragStart(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, WebCore::DragSourceAction allowedActions);
-    void requestAdditionalItemsForDragSession(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, WebCore::DragSourceAction allowedActions);
+    void requestDragStart(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask);
+    void requestAdditionalItemsForDragSession(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask);
     void insertDroppedImagePlaceholders(const Vector<WebCore::IntSize>&, CompletionHandler<void(const Vector<WebCore::IntRect>&, Optional<WebCore::TextIndicatorData>)>&& reply);
     void willReceiveEditDragSnapshot();
     void didReceiveEditDragSnapshot(Optional<WebCore::TextIndicatorData>);
index d2e0b90..b7f87b4 100644 (file)
@@ -46,7 +46,7 @@ struct TextIndicatorData;
 namespace WebKit {
 
 struct DragSourceState {
-    WebCore::DragSourceAction action { WebCore::DragSourceActionNone };
+    OptionSet<WebCore::DragSourceAction> action;
     CGPoint adjustedOrigin { CGPointZero };
     CGRect dragPreviewFrameInRootViewCoordinates { CGRectZero };
     RetainPtr<UIImage> image;
index ff4e4fd..902db8e 100644 (file)
@@ -99,11 +99,11 @@ static bool shouldUseDragImageToCreatePreviewForDragSource(const DragSourceState
         return false;
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    if (source.action & DragSourceActionColor)
+    if (source.action.contains(DragSourceAction::Color))
         return true;
 #endif
 
-    return source.action & (DragSourceActionDHTML | DragSourceActionImage);
+    return source.action.containsAny({ DragSourceAction::DHTML, DragSourceAction::Image });
 }
 
 static bool shouldUseVisiblePathToCreatePreviewForDragSource(const DragSourceState& source)
@@ -112,7 +112,7 @@ static bool shouldUseVisiblePathToCreatePreviewForDragSource(const DragSourceSta
         return false;
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    if (source.action & DragSourceActionColor)
+    if (source.action.contains(DragSourceAction::Color))
         return true;
 #endif
 
@@ -124,11 +124,11 @@ static bool shouldUseTextIndicatorToCreatePreviewForDragSource(const DragSourceS
     if (!source.indicatorData)
         return false;
 
-    if (source.action & (DragSourceActionLink | DragSourceActionSelection))
+    if (source.action.containsAny({ DragSourceAction::Link, DragSourceAction::Selection }))
         return true;
 
 #if ENABLE(ATTACHMENT_ELEMENT)
-    if (source.action & DragSourceActionAttachment)
+    if (source.action.contains(DragSourceAction::Attachment))
         return true;
 #endif
 
@@ -141,11 +141,11 @@ static bool canUpdatePreviewForActiveDragSource(const DragSourceState& source)
         return false;
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    if (source.action & DragSourceActionColor)
+    if (source.action.contains(DragSourceAction::Color))
         return true;
 #endif
 
-    if (source.action & DragSourceActionLink && !(source.action & DragSourceActionImage))
+    if (source.action.contains(DragSourceAction::Link) && !source.action.contains(DragSourceAction::Image))
         return true;
 
     return false;
@@ -167,7 +167,7 @@ Optional<DragSourceState> DragDropInteractionState::activeDragSourceForItem(UIDr
 bool DragDropInteractionState::anyActiveDragSourceIs(WebCore::DragSourceAction action) const
 {
     for (auto& source : m_activeDragSources) {
-        if (source.action & action)
+        if (source.action.contains(action))
             return true;
     }
     return false;
@@ -342,7 +342,7 @@ void DragDropInteractionState::stageDragItem(const DragItem& item, UIImage *drag
 
     m_adjustedPositionForDragEnd = item.eventPositionInContentCoordinates;
     m_stagedDragSource = {{
-        static_cast<DragSourceAction>(item.sourceAction),
+        item.sourceAction,
         item.eventPositionInContentCoordinates,
         item.dragPreviewFrameInRootViewCoordinates,
         dragImage,
@@ -357,7 +357,7 @@ void DragDropInteractionState::stageDragItem(const DragItem& item, UIImage *drag
 
 bool DragDropInteractionState::hasStagedDragSource() const
 {
-    return m_stagedDragSource && stagedDragSource().action != WebCore::DragSourceActionNone;
+    return m_stagedDragSource && !stagedDragSource().action.isEmpty();
 }
 
 void DragDropInteractionState::clearStagedDragSource(DidBecomeActive didBecomeActive)
@@ -393,7 +393,7 @@ void DragDropInteractionState::updatePreviewsForActiveDragSources()
         if (!dragItem)
             continue;
 
-        if (source.action & DragSourceActionLink) {
+        if (source.action.contains(DragSourceAction::Link)) {
             dragItem.previewProvider = [title = retainPtr((NSString *)source.linkTitle), url = retainPtr((NSURL *)source.linkURL), center = source.adjustedOrigin] () -> UIDragPreview * {
                 UIURLDragPreviewView *previewView = [UIURLDragPreviewView viewWithTitle:title.get() URL:url.get()];
                 previewView.center = center;
@@ -402,7 +402,7 @@ void DragDropInteractionState::updatePreviewsForActiveDragSources()
             };
         }
 #if ENABLE(INPUT_TYPE_COLOR)
-        else if (source.action & DragSourceActionColor) {
+        else if (source.action.contains(DragSourceAction::Color)) {
             dragItem.previewProvider = [image = source.image] () -> UIDragPreview * {
                 UIImageView *imageView = [[[UIImageView alloc] initWithImage:image.get()] autorelease];
                 UIDragPreviewParameters *parameters = [[[UIDragPreviewParameters alloc] initWithTextLineRects:@[ [NSValue valueWithCGRect:[imageView bounds]] ]] autorelease];
index 509c786..ea9f992 100644 (file)
@@ -7253,7 +7253,7 @@ static BOOL shouldEnableDragInteractionForPolicy(_WKDragInteractionPolicy policy
 
 - (void)_startDrag:(RetainPtr<CGImageRef>)image item:(const WebCore::DragItem&)item
 {
-    ASSERT(item.sourceAction != WebCore::DragSourceActionNone);
+    ASSERT(item.sourceAction);
 
     if (item.promisedAttachmentInfo)
         [self _prepareToDragPromisedAttachment:item.promisedAttachmentInfo];
@@ -7554,12 +7554,12 @@ static NSArray<NSItemProvider *> *extractItemProvidersFromDropSession(id <UIDrop
     return WKDragDestinationActionAny & ~WKDragDestinationActionLoad;
 }
 
-- (WebCore::DragSourceAction)_allowedDragSourceActions
+- (OptionSet<WebCore::DragSourceAction>)_allowedDragSourceActions
 {
-    auto allowedActions = WebCore::DragSourceActionAny;
+    auto allowedActions = WebCore::anyDragSourceAction();
     if (!self.isFirstResponder || !_suppressSelectionAssistantReasons.isEmpty()) {
         // Don't allow starting a drag on a selection when selection views are not visible.
-        allowedActions = static_cast<WebCore::DragSourceAction>(allowedActions & ~WebCore::DragSourceActionSelection);
+        allowedActions.remove(WebCore::DragSourceAction::Selection);
     }
     return allowedActions;
 }
@@ -8030,7 +8030,7 @@ static Vector<WebCore::IntSize> sizesOfPlaceholderElementsToInsertWhenDroppingIt
 - (void)dragInteraction:(UIDragInteraction *)interaction willAnimateLiftWithAnimator:(id <UIDragAnimating>)animator session:(id <UIDragSession>)session
 {
     RELEASE_LOG(DragAndDrop, "Drag session willAnimateLiftWithAnimator: %p", session);
-    if (_dragDropInteractionState.anyActiveDragSourceIs(WebCore::DragSourceActionSelection)) {
+    if (_dragDropInteractionState.anyActiveDragSourceIs(WebCore::DragSourceAction::Selection)) {
         [self cancelActiveTextInteractionGestures];
         if (!_shouldRestoreCalloutBarAfterDrop) {
             // FIXME: This SPI should be renamed in UIKit to reflect a more general purpose of hiding interaction assistant controls.
index ea5e4ef..aeae29a 100644 (file)
@@ -1257,16 +1257,16 @@ void WebPageProxy::didHandleAdditionalDragItemsRequest(bool added)
     pageClient().didHandleAdditionalDragItemsRequest(added);
 }
 
-void WebPageProxy::requestDragStart(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, WebCore::DragSourceAction allowedActions)
+void WebPageProxy::requestDragStart(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask)
 {
     if (hasRunningProcess())
-        m_process->send(Messages::WebPage::RequestDragStart(clientPosition, globalPosition, allowedActions), m_webPageID);
+        m_process->send(Messages::WebPage::RequestDragStart(clientPosition, globalPosition, allowedActionsMask), m_webPageID);
 }
 
-void WebPageProxy::requestAdditionalItemsForDragSession(const IntPoint& clientPosition, const IntPoint& globalPosition, WebCore::DragSourceAction allowedActions)
+void WebPageProxy::requestAdditionalItemsForDragSession(const IntPoint& clientPosition, const IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask)
 {
     if (hasRunningProcess())
-        m_process->send(Messages::WebPage::RequestAdditionalItemsForDragSession(clientPosition, globalPosition, allowedActions), m_webPageID);
+        m_process->send(Messages::WebPage::RequestAdditionalItemsForDragSession(clientPosition, globalPosition, allowedActionsMask), m_webPageID);
 }
 
 void WebPageProxy::insertDroppedImagePlaceholders(const Vector<IntSize>& imageSizes, CompletionHandler<void(const Vector<IntRect>&, Optional<WebCore::TextIndicatorData>)>&& completionHandler)
index 81b79a7..2eb0886 100644 (file)
@@ -45,7 +45,7 @@ void WebDragClient::willPerformDragSourceAction(DragSourceAction, const IntPoint
 {
 }
 
-DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntPoint&)
+OptionSet<DragSourceAction> WebDragClient::dragSourceActionMaskForPoint(const IntPoint&)
 {
     return m_page->allowedDragSourceActions();
 }
index 27c4b27..4dba0d8 100644 (file)
@@ -45,7 +45,7 @@ public:
 private:
     void willPerformDragDestinationAction(WebCore::DragDestinationAction, const WebCore::DragData&) override;
     void willPerformDragSourceAction(WebCore::DragSourceAction, const WebCore::IntPoint&, WebCore::DataTransfer&) override;
-    WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) override;
+    OptionSet<WebCore::DragSourceAction> dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) override;
 
     void startDrag(WebCore::DragItem, WebCore::DataTransfer&, WebCore::Frame&) override;
     void didConcludeEditDrag() override;
index a4b1578..0495602 100644 (file)
@@ -915,7 +915,7 @@ public:
     void willStartDrag() { ASSERT(!m_isStartingDrag); m_isStartingDrag = true; }
     void didStartDrag();
     void dragCancelled();
-    WebCore::DragSourceAction allowedDragSourceActions() const { return m_allowedDragSourceActions; }
+    OptionSet<WebCore::DragSourceAction> allowedDragSourceActions() const { return m_allowedDragSourceActions; }
 #endif
 
     void beginPrinting(WebCore::FrameIdentifier, const PrintInfo&);
@@ -1406,8 +1406,8 @@ private:
 #endif
 
 #if PLATFORM(IOS_FAMILY) && ENABLE(DATA_INTERACTION)
-    void requestDragStart(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t allowedActions);
-    void requestAdditionalItemsForDragSession(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t allowedActions);
+    void requestDragStart(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask);
+    void requestAdditionalItemsForDragSession(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask);
     void insertDroppedImagePlaceholders(const Vector<WebCore::IntSize>&, CompletionHandler<void(const Vector<WebCore::IntRect>&, Optional<WebCore::TextIndicatorData>)>&& reply);
     void computeAndSendEditDragSnapshot();
 #endif
@@ -1933,7 +1933,7 @@ private:
 
 #if ENABLE(DRAG_SUPPORT)
     bool m_isStartingDrag { false };
-    WebCore::DragSourceAction m_allowedDragSourceActions { WebCore::DragSourceActionAny };
+    OptionSet<WebCore::DragSourceAction> m_allowedDragSourceActions { WebCore::anyDragSourceAction() };
 #endif
 
 #if ENABLE(DRAG_SUPPORT) && PLATFORM(IOS_FAMILY)
index ae92747..16af317 100644 (file)
@@ -321,8 +321,8 @@ GenerateSyntheticEditingCommand(enum:uint8_t WebKit::SyntheticEditingCommandType
 #endif
 
 #if PLATFORM(IOS_FAMILY) && ENABLE(DRAG_SUPPORT)
-    RequestDragStart(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t allowedActions)
-    RequestAdditionalItemsForDragSession(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t allowedActions)
+    RequestDragStart(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask)
+    RequestAdditionalItemsForDragSession(WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask)
     InsertDroppedImagePlaceholders(Vector<WebCore::IntSize> imageSize) -> (Vector<WebCore::IntRect> dropPreviewRects, Optional<WebCore::TextIndicatorData> textIndicator) Async
     DidConcludeDrop()
 #endif
index 58034b7..70c8f2a 100644 (file)
@@ -909,16 +909,16 @@ void WebPage::requestFocusedElementInformation(WebKit::CallbackID callbackID)
 }
 
 #if ENABLE(DATA_INTERACTION)
-void WebPage::requestDragStart(const IntPoint& clientPosition, const IntPoint& globalPosition, uint64_t allowedActions)
+void WebPage::requestDragStart(const IntPoint& clientPosition, const IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask)
 {
-    SetForScope<WebCore::DragSourceAction> allowedActionsForScope(m_allowedDragSourceActions, static_cast<WebCore::DragSourceAction>(allowedActions));
+    SetForScope<OptionSet<WebCore::DragSourceAction>> allowedActionsForScope(m_allowedDragSourceActions, allowedActionsMask);
     bool didStart = m_page->mainFrame().eventHandler().tryToBeginDragAtPoint(clientPosition, globalPosition);
     send(Messages::WebPageProxy::DidHandleDragStartRequest(didStart));
 }
 
-void WebPage::requestAdditionalItemsForDragSession(const IntPoint& clientPosition, const IntPoint& globalPosition, uint64_t allowedActions)
+void WebPage::requestAdditionalItemsForDragSession(const IntPoint& clientPosition, const IntPoint& globalPosition, OptionSet<WebCore::DragSourceAction> allowedActionsMask)
 {
-    SetForScope<WebCore::DragSourceAction> allowedActionsForScope(m_allowedDragSourceActions, static_cast<WebCore::DragSourceAction>(allowedActions));
+    SetForScope<OptionSet<WebCore::DragSourceAction>> allowedActionsForScope(m_allowedDragSourceActions, allowedActionsMask);
     // To augment the platform drag session with additional items, end the current drag session and begin a new drag session with the new drag item.
     // This process is opaque to the UI process, which still maintains the old drag item in its drag session. Similarly, this persistent drag session
     // is opaque to the web process, which only sees that the current drag has ended, and that a new one is beginning.
index 89e4683..84543ec 100644 (file)
@@ -1,3 +1,30 @@
+2020-06-11  David Kilzer  <ddkilzer@apple.com>
+
+        [IPC] Adopt enum class for DragSourceAction
+        <https://webkit.org/b/212885>
+        <rdar://problem/64094134>
+
+        Reviewed by Darin Adler.
+
+        Summary:
+        - Add and use conversion functions between
+          OptionSet<WebCore::DragSourceAction> and WebDragSourceAction.
+        - Update method signatures.
+
+        * WebCoreSupport/WebDragClient.h:
+        * WebCoreSupport/WebDragClient.mm:
+        (coreDragSourceActionMask): Add.
+        (WebDragClient::dragSourceActionMaskForPoint):
+        (WebDragClient::willPerformDragSourceAction):
+        (WebDragClient::startDrag):
+        * WebView/WebView.mm:
+        (kit): Add.
+        - Convert from Optional<WebCore::DragSourceAction> to
+          WebDragSourceAction.
+        (-[WebView _startDrag:]):
+        * WebView/WebViewInternal.h:
+        (kit): Add declaration to reuse function in WebDragClient.mm.
+
 2020-06-10  Geoffrey Garen  <ggaren@apple.com>
 
         Some style improvements to main thread code
index 15dcba5..34a75ff 100644 (file)
@@ -38,7 +38,7 @@ public:
 
     void willPerformDragDestinationAction(WebCore::DragDestinationAction, const WebCore::DragData&) override;
     void willPerformDragSourceAction(WebCore::DragSourceAction, const WebCore::IntPoint&, WebCore::DataTransfer&) override;
-    WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) override;
+    OptionSet<WebCore::DragSourceAction> dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint) override;
     void startDrag(WebCore::DragItem, WebCore::DataTransfer&, WebCore::Frame&) override;
 
     void beginDrag(WebCore::DragItem, WebCore::Frame&, const WebCore::IntPoint& mouseDownPosition, const WebCore::IntPoint& mouseDraggedPosition, WebCore::DataTransfer&, WebCore::DragSourceAction) override;
index 3d1a0a3..42ac27b 100644 (file)
@@ -68,6 +68,22 @@ WebDragClient::WebDragClient(WebView* webView)
 
 #if PLATFORM(MAC)
 
+static OptionSet<WebCore::DragSourceAction> coreDragSourceActionMask(WebDragSourceAction action)
+{
+    OptionSet<WebCore::DragSourceAction> result;
+
+    if (action & WebDragSourceActionDHTML)
+        result.add(WebCore::DragSourceAction::DHTML);
+    if (action & WebDragSourceActionImage)
+        result.add(WebCore::DragSourceAction::Image);
+    if (action & WebDragSourceActionLink)
+        result.add(WebCore::DragSourceAction::Link);
+    if (action & WebDragSourceActionSelection)
+        result.add(WebCore::DragSourceAction::Selection);
+
+    return result;
+}
+
 static WebDragDestinationAction kit(WebCore::DragDestinationAction action)
 {
     switch (action) {
@@ -104,15 +120,15 @@ void WebDragClient::willPerformDragDestinationAction(WebCore::DragDestinationAct
 }
 
 
-WebCore::DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntPoint& rootViewPoint)
+OptionSet<WebCore::DragSourceAction> WebDragClient::dragSourceActionMaskForPoint(const IntPoint& rootViewPoint)
 {
     NSPoint viewPoint = [m_webView _convertPointFromRootView:rootViewPoint];
-    return (DragSourceAction)[[m_webView _UIDelegateForwarder] webView:m_webView dragSourceActionMaskForPoint:viewPoint];
+    return coreDragSourceActionMask([[m_webView _UIDelegateForwarder] webView:m_webView dragSourceActionMaskForPoint:viewPoint]);
 }
 
 void WebDragClient::willPerformDragSourceAction(WebCore::DragSourceAction action, const WebCore::IntPoint& mouseDownPoint, WebCore::DataTransfer& dataTransfer)
 {
-    [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:mouseDownPoint withPasteboard:[NSPasteboard pasteboardWithName:dataTransfer.pasteboard().name()]];
+    [[m_webView _UIDelegateForwarder] webView:m_webView willPerformDragSourceAction:kit(action) fromPoint:mouseDownPoint withPasteboard:[NSPasteboard pasteboardWithName:dataTransfer.pasteboard().name()]];
 }
 
 void WebDragClient::startDrag(DragItem dragItem, DataTransfer& dataTransfer, Frame& frame)
@@ -124,7 +140,7 @@ void WebDragClient::startDrag(DragItem dragItem, DataTransfer& dataTransfer, Fra
     if (![htmlView.get() isKindOfClass:[WebHTMLView class]])
         return;
     
-    NSEvent *event = dragItem.sourceAction == DragSourceActionLink ? frame.eventHandler().currentNSEvent() : [htmlView.get() _mouseDownEvent];
+    NSEvent *event = (dragItem.sourceAction && *dragItem.sourceAction == DragSourceAction::Link) ? frame.eventHandler().currentNSEvent() : [htmlView.get() _mouseDownEvent];
     WebHTMLView* topHTMLView = getTopHTMLView(&frame);
     RetainPtr<WebHTMLView> topViewProtector = topHTMLView;
     
@@ -197,9 +213,9 @@ void WebDragClient::willPerformDragDestinationAction(WebCore::DragDestinationAct
 {
 }
 
-WebCore::DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntPoint&)
+OptionSet<WebCore::DragSourceAction> WebDragClient::dragSourceActionMaskForPoint(const IntPoint&)
 {
-    return DragSourceActionNone;
+    return { };
 }
 
 void WebDragClient::willPerformDragSourceAction(WebCore::DragSourceAction, const WebCore::IntPoint&, WebCore::DataTransfer&)
@@ -232,9 +248,9 @@ void WebDragClient::willPerformDragDestinationAction(WebCore::DragDestinationAct
 {
 }
 
-WebCore::DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntPoint&)
+OptionSet<WebCore::DragSourceAction> WebDragClient::dragSourceActionMaskForPoint(const IntPoint&)
 {
-    return DragSourceActionAny;
+    return WebCore::anyDragSourceAction();
 }
 
 void WebDragClient::willPerformDragSourceAction(WebCore::DragSourceAction, const IntPoint&, DataTransfer&)
index 4857b37..8691b44 100644 (file)
@@ -675,6 +675,34 @@ static _UIDragOperation kit(Optional<WebCore::DragOperation> dragOperation)
     return _UIDragOperationNone;
 }
 #endif // USE(APPKIT)
+
+WebDragSourceAction kit(Optional<WebCore::DragSourceAction> action)
+{
+    if (!action)
+        return WebDragSourceActionNone;
+
+    switch (*action) {
+    case WebCore::DragSourceAction::DHTML:
+        return WebDragSourceActionDHTML;
+    case WebCore::DragSourceAction::Image:
+        return WebDragSourceActionImage;
+    case WebCore::DragSourceAction::Link:
+        return WebDragSourceActionLink;
+    case WebCore::DragSourceAction::Selection:
+        return WebDragSourceActionSelection;
+#if ENABLE(ATTACHMENT_ELEMENT)
+    case WebCore::DragSourceAction::Attachment:
+        break;
+#endif
+#if ENABLE(INPUT_TYPE_COLOR)
+    case WebCore::DragSourceAction::Color:
+        break;
+#endif
+    }
+
+    ASSERT_NOT_REACHED();
+    return WebDragSourceActionNone;
+}
 #endif // ENABLE(DRAG_SUPPORT)
 
 WebCore::FindOptions coreOptions(WebFindOptions options)
@@ -1960,7 +1988,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
     _private->draggedLinkURL = dragItem.url.isEmpty() ? nil : (NSURL *)dragItem.url;
     _private->draggedLinkTitle = dragItem.title.isEmpty() ? nil : (NSString *)dragItem.title;
     _private->dragPreviewFrameInRootViewCoordinates = dragItem.dragPreviewFrameInRootViewCoordinates;
-    _private->dragSourceAction = static_cast<WebDragSourceAction>(dragItem.sourceAction);
+    _private->dragSourceAction = kit(dragItem.sourceAction);
 }
 
 - (CGRect)_dataInteractionCaretRect
index ea1f2f3..56250fd 100644 (file)
@@ -32,6 +32,7 @@
 #import "WebPreferences.h"
 #import "WebViewPrivate.h"
 #import "WebTypesInternal.h"
+#import "WebUIDelegate.h"
 
 #ifdef __cplusplus
 
@@ -98,6 +99,8 @@ using CocoaDragOperation = uint64_t;
 #endif
 
 OptionSet<WebCore::DragOperation> coreDragOperationMask(CocoaDragOperation);
+
+WebDragSourceAction kit(Optional<WebCore::DragSourceAction>);
 #endif // ENABLE(DRAG_SUPPORT)
 
 WebCore::FindOptions coreOptions(WebFindOptions);
index 9d530d8..be79e3c 100644 (file)
@@ -1,3 +1,26 @@
+2020-06-11  David Kilzer  <ddkilzer@apple.com>
+
+        [IPC] Adopt enum class for DragSourceAction
+        <https://webkit.org/b/212885>
+        <rdar://problem/64094134>
+
+        Reviewed by Darin Adler.
+
+        Summary:
+        - Add and use conversion functions between
+          OptionSet<WebCore::DragSourceAction> and WebDragSourceAction.
+        - Update method signatures.
+
+        * WebCoreSupport/WebDragClient.cpp:
+        (coreDragSourceActionMask): Add.
+        (kit): Add.
+        - Convert from WebCore::DragSourceAction to WebDragSourceAction.
+        (WebDragClient::dragSourceActionMaskForPoint):
+        (WebDragClient::willPerformDragSourceAction):
+        (WebDragClient::startDrag):
+        * WebCoreSupport/WebDragClient.h:
+        (WebDragClient::dragSourceActionMaskForPoint):
+
 2020-06-10  Geoffrey Garen  <ggaren@apple.com>
 
         Some style improvements to main thread code
index 5b193a7..de8c931 100644 (file)
@@ -72,6 +72,46 @@ static WebDragDestinationAction kit(DragDestinationAction action)
     return WebDragDestinationActionNone;
 }
 
+static OptionSet<DragSourceAction> coreDragSourceActionMask(WebDragSourceAction actionMask)
+{
+    OptionSet<DragSourceAction> result;
+
+    if (actionMask & WebDragSourceActionDHTML)
+        result.add(DragSourceAction::DHTML);
+    if (actionMask & WebDragSourceActionImage)
+        result.add(DragSourceAction::Image);
+    if (actionMask & WebDragSourceActionLink)
+        result.add(DragSourceAction::Link);
+    if (actionMask & WebDragSourceActionSelection)
+        result.add(DragSourceAction::Selection);
+
+    return result;
+}
+
+static WebDragSourceAction kit(DragSourceAction action)
+{
+    switch (action) {
+    case DragSourceAction::DHTML:
+        return WebDragSourceActionDHTML;
+    case DragSourceAction::Image:
+        return WebDragSourceActionImage;
+    case DragSourceAction::Link:
+        return WebDragSourceActionLink;
+    case DragSourceAction::Selection:
+        return WebDragSourceActionSelection;
+#if ENABLE(ATTACHMENT_ELEMENT)
+    case DragSourceAction::Attachment:
+        break;
+#endif
+#if ENABLE(INPUT_TYPE_COLOR)
+    case DragSourceAction::Color:
+        break;
+#endif
+    }
+    ASSERT_NOT_REACHED();
+    return WebDragSourceActionNone;
+}
+
 WebDragClient::WebDragClient(WebView* webView)
     : m_webView(webView) 
 {
@@ -87,14 +127,14 @@ void WebDragClient::willPerformDragDestinationAction(DragDestinationAction actio
         delegateRef->willPerformDragDestinationAction(m_webView, kit(action), dragData.platformData());
 }
 
-DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntPoint& windowPoint)
+OptionSet<DragSourceAction> WebDragClient::dragSourceActionMaskForPoint(const IntPoint& windowPoint)
 {
     COMPtr<IWebUIDelegate> delegateRef = 0;
-    WebDragSourceAction action = WebDragSourceActionAny;
+    WebDragSourceAction actionMask = WebDragSourceActionAny;
     POINT localpt = core(m_webView)->mainFrame().view()->windowToContents(windowPoint);
     if (SUCCEEDED(m_webView->uiDelegate(&delegateRef)))
-        delegateRef->dragSourceActionMaskForPoint(m_webView, &localpt, &action);
-    return (DragSourceAction)action;
+        delegateRef->dragSourceActionMaskForPoint(m_webView, &localpt, &actionMask);
+    return coreDragSourceActionMask(actionMask);
 }
 
 void WebDragClient::willPerformDragSourceAction(DragSourceAction action, const IntPoint& intPoint, DataTransfer& dataTransfer)
@@ -107,7 +147,7 @@ void WebDragClient::willPerformDragSourceAction(DragSourceAction action, const I
     COMPtr<IDataObject> dataObject = dataTransfer.pasteboard().dataObject();
 
     COMPtr<IDataObject> newDataObject;
-    HRESULT result = uiDelegate->willPerformDragSourceAction(m_webView, static_cast<WebDragSourceAction>(action), &point, dataObject.get(), &newDataObject);
+    HRESULT result = uiDelegate->willPerformDragSourceAction(m_webView, kit(action), &point, dataObject.get(), &newDataObject);
     if (result == S_OK && newDataObject != dataObject)
         const_cast<Pasteboard&>(dataTransfer.pasteboard()).setExternalDataObject(newDataObject.get());
 }
@@ -143,7 +183,7 @@ void WebDragClient::startDrag(DragItem item, DataTransfer& dataTransfer, Frame&
                 sdi.hbmpDragImage = image.get();
                 sdi.ptOffset.x = dragPoint.x() - imageOrigin.x();
                 sdi.ptOffset.y = dragPoint.y() - imageOrigin.y();
-                if (item.sourceAction == DragSourceActionLink)
+                if (item.sourceAction && *item.sourceAction == DragSourceAction::Link)
                     sdi.ptOffset.y = b.bmHeight - sdi.ptOffset.y;
 
                 helper->InitializeFromBitmap(&sdi, dataObject.get());
index a51fc01..f58c737 100644 (file)
@@ -37,7 +37,7 @@ class WebDragClient : public WebCore::DragClient {
 public:
     WebDragClient(WebView*);
 
-    virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint&);
+    virtual OptionSet<WebCore::DragSourceAction> dragSourceActionMaskForPoint(const WebCore::IntPoint&);
     virtual void willPerformDragDestinationAction(WebCore::DragDestinationAction, const WebCore::DragData&);
     virtual void willPerformDragSourceAction(WebCore::DragSourceAction, const WebCore::IntPoint&, WebCore::DataTransfer&);
     virtual void startDrag(WebCore::DragItem, WebCore::DataTransfer&, WebCore::Frame&);