Changeset 212267 in webkit


Ignore:
Timestamp:
Feb 13, 2017 5:44:31 PM (7 years ago)
Author:
andersca@apple.com
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):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r212265 r212267  
     12017-02-13  Anders Carlsson  <andersca@apple.com>
     2
     3        Simplify DragController::startDrag
     4        https://bugs.webkit.org/show_bug.cgi?id=168240
     5
     6        Reviewed by Tim Horton.
     7
     8        Use early returns instead of assigning to a variable that's returned at the end of the function.
     9
     10        * page/DragController.cpp:
     11        (WebCore::DragController::startDrag):
     12
    1132017-02-13  Said Abou-Hallawa  <sabouhallawa@apple.com>
    214
  • trunk/Source/WebCore/page/DragController.cpp

    r212239 r212267  
    814814    }
    815815
    816     bool startedDrag = true; // optimism - we almost always manage to start the drag
    817 
    818816    ASSERT(state.source);
    819817    Element& element = *state.source;
     
    824822        if (!dataTransfer.pasteboard().hasData()) {
    825823            // FIXME: This entire block is almost identical to the code in Editor::copy, and the code should be shared.
    826 
    827824            RefPtr<Range> selectionRange = src.selection().toNormalizedRange();
    828825            ASSERT(selectionRange);
     
    862859
    863860        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, dragImageBounds, dataTransfer, src, false);
    864     } else if (!src.document()->securityOrigin().canDisplay(linkURL)) {
     861        return true;
     862    }
     863
     864    if (!src.document()->securityOrigin().canDisplay(linkURL)) {
    865865        src.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to drag local resource: " + linkURL.stringCenterEllipsizedToLength());
    866         startedDrag = false;
    867     } else if (!imageURL.isEmpty() && image && !image->isNull() && (m_dragSourceAction & DragSourceActionImage)) {
     866        return false;
     867    }
     868
     869    if (!imageURL.isEmpty() && image && !image->isNull() && (m_dragSourceAction & DragSourceActionImage)) {
    868870        // We shouldn't be starting a drag for an image that can't provide an extension.
    869871        // This is an early detection for problems encountered later upon drop.
     
    886888            doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
    887889        }
    888     } else if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) {
     890        return true;
     891    }
     892
     893    if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) {
    889894        if (!dataTransfer.pasteboard().hasData()) {
    890895            // Simplify whitespace so the title put on the dataTransfer resembles what the user sees
     
    921926        }
    922927        doSystemDrag(WTFMove(dragImage), dragLoc, mouseDraggedPoint, { }, dataTransfer, src, true);
     928
     929        return true;
     930    }
     931
    923932#if ENABLE(ATTACHMENT_ELEMENT)
    924     } else if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) {
     933    if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) {
    925934        if (!dataTransfer.pasteboard().hasData()) {
    926935            m_draggingAttachmentURL = attachmentURL;
     
    937946        }
    938947        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
    939 #endif
    940     } else if (state.type == DragSourceActionDHTML) {
    941         if (dragImage) {
    942             ASSERT(m_dragSourceAction & DragSourceActionDHTML);
    943             m_client.willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, dataTransfer);
    944             doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
    945         } else
    946             startedDrag = false;
    947     } else {
    948         // draggableElement() determined an image or link node was draggable, but it turns out the
    949         // image or link had no URL, so there is nothing to drag.
    950         startedDrag = false;
    951     }
    952 
    953     return startedDrag;
     948        return true;
     949    }
     950#endif
     951
     952    if (state.type == DragSourceActionDHTML && dragImage) {
     953        ASSERT(m_dragSourceAction & DragSourceActionDHTML);
     954        m_client.willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, dataTransfer);
     955        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false);
     956        return true;
     957    }
     958
     959    return false;
    954960}
    955961
Note: See TracChangeset for help on using the changeset viewer.