Changeset 99369 in webkit


Ignore:
Timestamp:
Nov 5, 2011 9:27:39 PM (12 years ago)
Author:
jonlee@apple.com
Message:

Dragging a file onto <input type="file"> should give distinct visual feedback
https://bugs.webkit.org/show_bug.cgi?id=13897
<rdar://problem/5232483>

Reviewed by Dan Bernstein.

When hovering over a file input element, we set the button's state to active
to differentiate dragging one file over the input element (which populates that
element) versus over the document (which would load the file into the view).

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::HTMLInputElement):
(WebCore::HTMLInputElement::canReceiveDroppedFiles):
(WebCore::HTMLInputElement::setCanReceiveDroppedFiles): If set, the element
is updated, which sets the active state on the button control.

  • html/HTMLInputElement.h: Add a boolean member representing whether the file

input can receive dropped files.

  • page/DragController.cpp:

(WebCore::DragController::DragController): Update/set the file input that
can receive dropped files.
(WebCore::DragController::dragExited):
(WebCore::DragController::tryDocumentDrag):
(WebCore::DragController::concludeEditDrag):

  • page/DragController.h:
  • rendering/RenderFileUploadControl.cpp:

(WebCore::RenderFileUploadControl::updateFromElement): Sets the button active
state if the input can receive dropped files.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r99367 r99369  
     12011-11-04  Jon Lee  <jonlee@apple.com>
     2
     3        Dragging a file onto <input type="file"> should give distinct visual feedback
     4        https://bugs.webkit.org/show_bug.cgi?id=13897
     5        <rdar://problem/5232483>
     6
     7        Reviewed by Dan Bernstein.
     8
     9        When hovering over a file input element, we set the button's state to active
     10        to differentiate dragging one file over the input element (which populates that
     11        element) versus over the document (which would load the file into the view).
     12
     13        * html/HTMLInputElement.cpp:
     14        (WebCore::HTMLInputElement::HTMLInputElement):
     15        (WebCore::HTMLInputElement::canReceiveDroppedFiles):
     16        (WebCore::HTMLInputElement::setCanReceiveDroppedFiles): If set, the element
     17        is updated, which sets the active state on the button control.
     18        * html/HTMLInputElement.h: Add a boolean member representing whether the file
     19        input can receive dropped files.
     20        * page/DragController.cpp:
     21        (WebCore::DragController::DragController): Update/set the file input that
     22        can receive dropped files.
     23        (WebCore::DragController::dragExited):
     24        (WebCore::DragController::tryDocumentDrag):
     25        (WebCore::DragController::concludeEditDrag):
     26        * page/DragController.h:
     27        * rendering/RenderFileUploadControl.cpp:
     28        (WebCore::RenderFileUploadControl::updateFromElement): Sets the button active
     29        state if the input can receive dropped files.
     30
    1312011-11-05  Darin Adler  <darin@apple.com>
    232
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r98222 r99369  
    9595    , m_parsingInProgress(createdByParser)
    9696    , m_wasModifiedByUser(false)
     97    , m_canReceiveDroppedFiles(false)
    9798    , m_inputType(InputType::createText(this))
    9899{
     
    14111412}
    14121413
     1414bool HTMLInputElement::canReceiveDroppedFiles() const
     1415{
     1416    return m_canReceiveDroppedFiles;
     1417}
     1418
     1419void HTMLInputElement::setCanReceiveDroppedFiles(bool canReceiveDroppedFiles)
     1420{
     1421    if (m_canReceiveDroppedFiles == canReceiveDroppedFiles)
     1422        return;
     1423    m_canReceiveDroppedFiles = canReceiveDroppedFiles;
     1424    renderer()->updateFromElement();
     1425}
     1426
    14131427String HTMLInputElement::visibleValue() const
    14141428{
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r98054 r99369  
    210210    void receiveDroppedFiles(const Vector<String>&);
    211211    Icon* icon() const;
     212    // These functions are used for rendering the input active during a
     213    // drag-and-drop operation.
     214    bool canReceiveDroppedFiles() const;
     215    void setCanReceiveDroppedFiles(bool);
    212216
    213217    void addSearchResult();
     
    352356    bool m_parsingInProgress : 1;
    353357    bool m_wasModifiedByUser : 1;
     358    bool m_canReceiveDroppedFiles : 1;
    354359    OwnPtr<InputType> m_inputType;
    355360};
  • trunk/Source/WebCore/page/DragController.cpp

    r99108 r99369  
    8989    , m_documentUnderMouse(0)
    9090    , m_dragInitiator(0)
     91    , m_fileInputElementUnderMouse(0)
    9192    , m_dragDestinationAction(DragDestinationActionNone)
    9293    , m_dragSourceAction(DragSourceActionNone)
     
    182183    }
    183184    mouseMovedIntoDocument(0);
     185    if (m_fileInputElementUnderMouse)
     186        m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
     187    m_fileInputElementUnderMouse = 0;
    184188}
    185189
     
    329333       
    330334        HTMLInputElement* elementAsFileInput = asFileInput(element);
    331         if (!elementAsFileInput)
     335        if (m_fileInputElementUnderMouse != elementAsFileInput) {
     336            if (m_fileInputElementUnderMouse)
     337                m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
     338            m_fileInputElementUnderMouse = elementAsFileInput;
     339        }
     340       
     341        if (!m_fileInputElementUnderMouse)
    332342            m_page->dragCaretController()->setCaretPosition(m_documentUnderMouse->frame()->visiblePositionForPoint(point));
    333343
    334344        Frame* innerFrame = element->document()->frame();
    335345        dragSession.operation = dragIsMove(innerFrame->selection(), dragData) ? DragOperationMove : DragOperationCopy;
    336         dragSession.mouseIsOverFileInput = elementAsFileInput;
     346        dragSession.mouseIsOverFileInput = m_fileInputElementUnderMouse;
    337347        dragSession.numberOfItemsToBeAccepted = 0;
    338348
    339349        unsigned numberOfFiles = dragData->numberOfFiles();
    340         if (elementAsFileInput) {
    341             if (elementAsFileInput->disabled())
     350        if (m_fileInputElementUnderMouse) {
     351            if (m_fileInputElementUnderMouse->disabled())
    342352                dragSession.numberOfItemsToBeAccepted = 0;
    343             else if (elementAsFileInput->multiple())
     353            else if (m_fileInputElementUnderMouse->multiple())
    344354                dragSession.numberOfItemsToBeAccepted = numberOfFiles;
    345355            else
     
    348358            if (!dragSession.numberOfItemsToBeAccepted)
    349359                dragSession.operation = DragOperationNone;
     360            m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(dragSession.numberOfItemsToBeAccepted);
    350361        } else {
    351362            // We are not over a file input element. The dragged item(s) will only
     
    356367        return true;
    357368    }
    358     // If we're not over an editable region, make sure we're clearing any prior drag cursor.
     369   
     370    // We are not over an editable region. Make sure we're clearing any prior drag cursor.
    359371    m_page->dragCaretController()->clear();
     372    if (m_fileInputElementUnderMouse)
     373        m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
     374    m_fileInputElementUnderMouse = 0;
    360375    return false;
    361376}
     
    400415    ASSERT(dragData);
    401416    ASSERT(!m_isHandlingDrag);
     417
     418    if (m_fileInputElementUnderMouse) {
     419        m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
     420        m_fileInputElementUnderMouse = 0;
     421    }
    402422
    403423    if (!m_documentUnderMouse)
  • trunk/Source/WebCore/page/DragController.h

    r99108 r99369  
    4343    class Frame;
    4444    class FrameSelection;
     45    class HTMLInputElement;
    4546    class Image;
    4647    class IntRect;
     
    118119        RefPtr<Document> m_documentUnderMouse; // The document the mouse was last dragged over.
    119120        RefPtr<Document> m_dragInitiator; // The Document (if any) that initiated the drag.
     121        RefPtr<HTMLInputElement> m_fileInputElementUnderMouse;
    120122       
    121123        DragDestinationAction m_dragDestinationAction;
  • trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp

    r99083 r99369  
    7272        if (button->disabled() != newDisabled)
    7373            button->setDisabled(newDisabled);
     74       
     75        button->setActive(input->canReceiveDroppedFiles());
    7476    }
    7577
Note: See TracChangeset for help on using the changeset viewer.