Title: [212267] trunk/Source/WebCore
Revision
212267
Author
ander...@apple.com
Date
2017-02-13 17:44:31 -0800 (Mon, 13 Feb 2017)

Log Message

Simplify DragController::startDrag
https://bugs.webkit.org/show_bug.cgi?id=168240

Reviewed by Tim Horton.

Use early returns instead of assigning to a variable that's returned at the end of the function.

* page/DragController.cpp:
(WebCore::DragController::startDrag):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (212266 => 212267)


--- trunk/Source/WebCore/ChangeLog	2017-02-14 01:32:37 UTC (rev 212266)
+++ trunk/Source/WebCore/ChangeLog	2017-02-14 01:44:31 UTC (rev 212267)
@@ -1,3 +1,15 @@
+2017-02-13  Anders Carlsson  <ander...@apple.com>
+
+        Simplify DragController::startDrag
+        https://bugs.webkit.org/show_bug.cgi?id=168240
+
+        Reviewed by Tim Horton.
+
+        Use early returns instead of assigning to a variable that's returned at the end of the function.
+
+        * page/DragController.cpp:
+        (WebCore::DragController::startDrag):
+
 2017-02-13  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         The current frame of an image should not deleted if another frame is asynchronously being decoded

Modified: trunk/Source/WebCore/page/DragController.cpp (212266 => 212267)


--- trunk/Source/WebCore/page/DragController.cpp	2017-02-14 01:32:37 UTC (rev 212266)
+++ trunk/Source/WebCore/page/DragController.cpp	2017-02-14 01:44:31 UTC (rev 212267)
@@ -813,8 +813,6 @@
         m_dragOffset = dragImageOffset;
     }
 
-    bool startedDrag = true; // optimism - we almost always manage to start the drag
-
     ASSERT(state.source);
     Element& element = *state.source;
 
@@ -823,7 +821,6 @@
     if (state.type == DragSourceActionSelection) {
         if (!dataTransfer.pasteboard().hasData()) {
             // FIXME: This entire block is almost identical to the code in Editor::copy, and the code should be shared.
-
             RefPtr<Range> selectionRange = src.selection().toNormalizedRange();
             ASSERT(selectionRange);
 
@@ -861,10 +858,15 @@
             return false;
 
         doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, dragImageBounds, dataTransfer, src, false);
-    } else if (!src.document()->securityOrigin().canDisplay(linkURL)) {
+        return true;
+    }
+
+    if (!src.document()->securityOrigin().canDisplay(linkURL)) {
         src.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to drag local resource: " + linkURL.stringCenterEllipsizedToLength());
-        startedDrag = false;
-    } else if (!imageURL.isEmpty() && image && !image->isNull() && (m_dragSourceAction & DragSourceActionImage)) {
+        return false;
+    }
+
+    if (!imageURL.isEmpty() && image && !image->isNull() && (m_dragSourceAction & DragSourceActionImage)) {
         // 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());
@@ -885,7 +887,10 @@
             // DHTML defined drag image
             doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
         }
-    } else if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) {
+        return true;
+    }
+
+    if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) {
         if (!dataTransfer.pasteboard().hasData()) {
             // Simplify whitespace so the title put on the dataTransfer resembles what the user sees
             // on the web page. This includes replacing newlines with spaces.
@@ -920,8 +925,12 @@
             dragImage = DragImage { scaleDragImage(dragImage.get(), FloatSize(m_page.deviceScaleFactor(), m_page.deviceScaleFactor())) };
         }
         doSystemDrag(WTFMove(dragImage), dragLoc, mouseDraggedPoint, { }, dataTransfer, src, true);
+
+        return true;
+    }
+
 #if ENABLE(ATTACHMENT_ELEMENT)
-    } else if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) {
+    if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) {
         if (!dataTransfer.pasteboard().hasData()) {
             m_draggingAttachmentURL = attachmentURL;
             selectElement(element);
@@ -936,21 +945,18 @@
             m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y());
         }
         doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
+        return true;
+    }
 #endif
-    } else if (state.type == DragSourceActionDHTML) {
-        if (dragImage) {
-            ASSERT(m_dragSourceAction & DragSourceActionDHTML);
-            m_client.willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, dataTransfer);
-            doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
-        } else
-            startedDrag = false;
-    } else {
-        // draggableElement() determined an image or link node was draggable, but it turns out the
-        // image or link had no URL, so there is nothing to drag.
-        startedDrag = false;
+
+    if (state.type == DragSourceActionDHTML && dragImage) {
+        ASSERT(m_dragSourceAction & DragSourceActionDHTML);
+        m_client.willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, dataTransfer);
+        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
+        return true;
     }
 
-    return startedDrag;
+    return false;
 }
 
 void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& layoutRect, DataTransfer& dataTransfer, Frame& frame, IntPoint& dragImageOffset)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to