Changeset 87499 in webkit


Ignore:
Timestamp:
May 27, 2011 5:37:48 AM (13 years ago)
Author:
yael.aharon@nokia.com
Message:

webkit should implement the dropzone attribute
https://bugs.webkit.org/show_bug.cgi?id=58210

Reviewed by Tony Chang.

Source/WebCore:

Add support for dropzone attribute.
http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#the-dropzone-attribute
If a drag event was not canceled by JavaScript, look for an element with a dropzone attribute.
If there is such an element, and it matches the drag data store, set the action defined by that
element and continue processing the drag and drop operation.

Tests: fast/events/dropzone-001.html

fast/events/dropzone-002.html
fast/events/dropzone-003.html
fast/events/dropzone-004.html

  • dom/Clipboard.cpp:

(WebCore::Clipboard::hasFileOfType):
(WebCore::Clipboard::hasStringOfType):
(WebCore::convertDropZoneOperationToDragOperation):
(WebCore::convertDragOperationToDropZoneOperation):
(WebCore::Clipboard::processDropZoneKeyword):

  • dom/Clipboard.h:
  • html/HTMLAttributeNames.in:
  • html/HTMLElement.idl:
  • page/EventHandler.cpp:

(WebCore::EventHandler::findDropZone):
(WebCore::EventHandler::updateDragAndDrop):

  • page/EventHandler.h:

LayoutTests:

  • fast/events/dropzone-001-expected.txt: Added.
  • fast/events/dropzone-001.html: Added.
  • fast/events/dropzone-002-expected.txt: Added.
  • fast/events/dropzone-002.html: Added.
  • fast/events/dropzone-003-expected.txt: Added.
  • fast/events/dropzone-003.html: Added.
  • fast/events/dropzone-004-expected.txt: Added.
  • fast/events/dropzone-004.html: Added.
  • fast/events/resources/dropzone.js: Added.
Location:
trunk
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r87498 r87499  
     12011-05-26  Yael Aharon  <yael.aharon@nokia.com>
     2
     3        Reviewed by Tony Chang.
     4
     5        webkit should implement the dropzone attribute
     6        https://bugs.webkit.org/show_bug.cgi?id=58210
     7
     8        * fast/events/dropzone-001-expected.txt: Added.
     9        * fast/events/dropzone-001.html: Added.
     10        * fast/events/dropzone-002-expected.txt: Added.
     11        * fast/events/dropzone-002.html: Added.
     12        * fast/events/dropzone-003-expected.txt: Added.
     13        * fast/events/dropzone-003.html: Added.
     14        * fast/events/dropzone-004-expected.txt: Added.
     15        * fast/events/dropzone-004.html: Added.
     16        * fast/events/resources/dropzone.js: Added.
     17
    1182011-05-27  Csaba Osztrogonác  <ossy@webkit.org>
    219
  • trunk/Source/WebCore/ChangeLog

    r87494 r87499  
     12011-05-26  Yael Aharon  <yael.aharon@nokia.com>
     2
     3        Reviewed by Tony Chang.
     4
     5        webkit should implement the dropzone attribute
     6        https://bugs.webkit.org/show_bug.cgi?id=58210
     7
     8        Add support for dropzone attribute.
     9        http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#the-dropzone-attribute
     10        If a drag event was not canceled by JavaScript, look for an element with a dropzone attribute.
     11        If there is such an element, and it matches the drag data store, set the action defined by that
     12        element and continue processing the drag and drop operation.
     13
     14        Tests: fast/events/dropzone-001.html
     15               fast/events/dropzone-002.html
     16               fast/events/dropzone-003.html
     17               fast/events/dropzone-004.html
     18
     19        * dom/Clipboard.cpp:
     20        (WebCore::Clipboard::hasFileOfType):
     21        (WebCore::Clipboard::hasStringOfType):
     22        (WebCore::convertDropZoneOperationToDragOperation):
     23        (WebCore::convertDragOperationToDropZoneOperation):
     24        (WebCore::Clipboard::processDropZoneKeyword):
     25        * dom/Clipboard.h:
     26        * html/HTMLAttributeNames.in:
     27        * html/HTMLElement.idl:
     28        * page/EventHandler.cpp:
     29        (WebCore::EventHandler::findDropZone):
     30        (WebCore::EventHandler::updateDragAndDrop):
     31        * page/EventHandler.h:
     32
    1332011-05-27  Patrick Gansterer  <paroga@webkit.org>
    234
  • trunk/Source/WebCore/dom/Clipboard.cpp

    r67973 r87499  
    2828
    2929#include "CachedImage.h"
     30#include "FileList.h"
    3031#include "Frame.h"
    3132#include "FrameLoader.h"
     
    126127}
    127128
     129bool Clipboard::hasFileOfType(const String& type) const
     130{
     131    if (m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)
     132        return false;
     133   
     134    RefPtr<FileList> fileList = files();
     135    if (fileList->isEmpty())
     136        return false;
     137   
     138    for (unsigned int f = 0; f < fileList->length(); f++) {
     139        if (equalIgnoringCase(fileList->item(f)->type(), type))
     140            return true;
     141    }
     142    return false;
     143}
     144
     145bool Clipboard::hasStringOfType(const String& type) const
     146{
     147    if (m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)
     148        return false;
     149   
     150    return types().contains(type);
     151}
     152   
    128153void Clipboard::setDropEffect(const String &effect)
    129154{
     
    158183        m_effectAllowed = effect;
    159184}
     185   
     186DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation)
     187{
     188    if (dragOperation == "copy")
     189        return DragOperationCopy;
     190    if (dragOperation == "move")
     191        return DragOperationMove;
     192    if (dragOperation == "link")
     193        return DragOperationLink;
     194    return DragOperationNone;
     195}
     196
     197String convertDragOperationToDropZoneOperation(DragOperation operation)
     198{
     199    switch (operation) {
     200    case DragOperationCopy:
     201        return String("copy");
     202    case DragOperationMove:
     203        return String("move");
     204    case DragOperationLink:
     205        return String("link");
     206    default:
     207        return String("copy");
     208    }
     209}
     210
     211bool Clipboard::hasDropZoneType(const String& keyword)
     212{
     213    if (keyword.length() < 3 || keyword[1] != ':')
     214        return false;
     215       
     216    switch (keyword[0]) {
     217    case 'f':
     218        return hasFileOfType(keyword.substring(2));
     219    case 's':
     220        return hasStringOfType(keyword.substring(2));
     221    default:
     222        return false;
     223    }
     224}
    160225
    161226} // namespace WebCore
  • trunk/Source/WebCore/dom/Clipboard.h

    r80536 r87499  
    4747            DragAndDrop,
    4848        };
     49       
    4950        static PassRefPtr<Clipboard> create(ClipboardAccessPolicy, DragData*, Frame*);
    5051
     
    9394        void setDestinationOperation(DragOperation);
    9495       
     96        bool hasDropZoneType(const String&);
     97       
    9598        void setDragHasStarted() { m_dragStarted = true; }
    9699
     
    105108       
    106109    private:
     110        bool hasFileOfType(const String&) const;
     111        bool hasStringOfType(const String&) const;
     112       
    107113        ClipboardAccessPolicy m_policy;
    108114        String m_dropEffect;
     
    117123    };
    118124
     125    DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation);
     126    String convertDragOperationToDropZoneOperation(DragOperation);
     127   
    119128} // namespace WebCore
    120129
  • trunk/Source/WebCore/html/HTMLAttributeNames.in

    r87473 r87499  
    9393disabled
    9494draggable
     95webkitdropzone
    9596enctype
    9697end
  • trunk/Source/WebCore/html/HTMLElement.idl

    r76301 r87499  
    3636                 attribute long              tabIndex;
    3737                 attribute boolean           draggable;
     38                 attribute [Reflect] DOMString webkitdropzone;
    3839                 attribute [Reflect] boolean hidden;
    3940
  • trunk/Source/WebCore/page/EventHandler.cpp

    r87096 r87499  
    17901790}
    17911791
     1792static bool findDropZone(Node* target, Clipboard* clipboard)
     1793{
     1794    Element* element = target->isElementNode() ? toElement(target) : target->parentElement();
     1795    for (; element; element = element->parentElement()) {
     1796        bool matched = false;
     1797        String dropZoneStr = element->fastGetAttribute(webkitdropzoneAttr);
     1798
     1799        if (dropZoneStr.isEmpty())
     1800            continue;
     1801       
     1802        dropZoneStr.makeLower();
     1803       
     1804        SpaceSplitString keywords(dropZoneStr, false);
     1805        if (keywords.isNull())
     1806            continue;
     1807       
     1808        DragOperation dragOperation = DragOperationNone;
     1809        for (unsigned int i = 0; i < keywords.size(); i++) {
     1810            DragOperation op = convertDropZoneOperationToDragOperation(keywords[i]);
     1811            if (op != DragOperationNone) {
     1812                if (dragOperation == DragOperationNone)
     1813                    dragOperation = op;
     1814            } else
     1815                matched = matched || clipboard->hasDropZoneType(keywords[i].string());
     1816
     1817            if (matched && dragOperation != DragOperationNone)
     1818                break;
     1819        }
     1820        if (matched) {
     1821            clipboard->setDropEffect(convertDragOperationToDropZoneOperation(dragOperation));
     1822            return true;
     1823        }
     1824    }
     1825    return false;
     1826}
     1827   
    17921828bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard* clipboard)
    17931829{
     
    18201856            }
    18211857            accept = dispatchDragEvent(eventNames().dragenterEvent, newTarget, event, clipboard);
     1858            if (!accept)
     1859                accept = findDropZone(newTarget, clipboard);
    18221860        }
    18231861
     
    18381876            }
    18391877            accept = dispatchDragEvent(eventNames().dragoverEvent, newTarget, event, clipboard);
     1878            if (!accept)
     1879                accept = findDropZone(newTarget, clipboard);
    18401880            m_shouldOnlyFireDragOverEvent = false;
    18411881        }
Note: See TracChangeset for help on using the changeset viewer.