Home | History | Annotate | Download | only in gtk
      1 /*
      2  * Copyright (C) 2010, Igalia S.L.
      3  *
      4  *  This library is free software; you can redistribute it and/or
      5  *  modify it under the terms of the GNU Lesser General Public
      6  *  License as published by the Free Software Foundation; either
      7  *  version 2 of the License, or (at your option) any later version.
      8  *
      9  *  This library is distributed in the hope that it will be useful,
     10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  *  Lesser General Public License for more details.
     13  *
     14  *  You should have received a copy of the GNU Lesser General Public
     15  *  License along with this library; if not, write to the Free Software
     16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     17  */
     18 
     19 #include "config.h"
     20 #include "ClipboardUtilitiesGtk.h"
     21 
     22 namespace WebCore {
     23 
     24 GdkDragAction dragOperationToGdkDragActions(DragOperation coreAction)
     25 {
     26     GdkDragAction gdkAction = static_cast<GdkDragAction>(0);
     27     if (coreAction == DragOperationNone)
     28         return gdkAction;
     29 
     30     if (coreAction & DragOperationCopy)
     31         gdkAction = static_cast<GdkDragAction>(GDK_ACTION_COPY | gdkAction);
     32     if (coreAction & DragOperationMove)
     33         gdkAction = static_cast<GdkDragAction>(GDK_ACTION_MOVE | gdkAction);
     34     if (coreAction & DragOperationLink)
     35         gdkAction = static_cast<GdkDragAction>(GDK_ACTION_LINK | gdkAction);
     36     if (coreAction & DragOperationPrivate)
     37         gdkAction = static_cast<GdkDragAction>(GDK_ACTION_PRIVATE | gdkAction);
     38 
     39     return gdkAction;
     40 }
     41 
     42 GdkDragAction dragOperationToSingleGdkDragAction(DragOperation coreAction)
     43 {
     44     if (coreAction == DragOperationEvery || coreAction & DragOperationCopy)
     45         return GDK_ACTION_COPY;
     46     if (coreAction & DragOperationMove)
     47         return GDK_ACTION_MOVE;
     48     if (coreAction & DragOperationLink)
     49         return GDK_ACTION_LINK;
     50     if (coreAction & DragOperationPrivate)
     51         return GDK_ACTION_PRIVATE;
     52     return static_cast<GdkDragAction>(0);
     53 }
     54 
     55 DragOperation gdkDragActionToDragOperation(GdkDragAction gdkAction)
     56 {
     57     // We have no good way to detect DragOperationEvery other than
     58     // to use it when all applicable flags are on.
     59     if (gdkAction & GDK_ACTION_COPY && gdkAction & GDK_ACTION_MOVE
     60         && gdkAction & GDK_ACTION_LINK && gdkAction & GDK_ACTION_PRIVATE)
     61         return DragOperationEvery;
     62 
     63     unsigned int action = DragOperationNone;
     64     if (gdkAction & GDK_ACTION_COPY)
     65         action |= DragOperationCopy;
     66     if (gdkAction & GDK_ACTION_MOVE)
     67         action |= DragOperationMove;
     68     if (gdkAction & GDK_ACTION_LINK)
     69         action |= DragOperationLink;
     70     if (gdkAction & GDK_ACTION_PRIVATE)
     71         action |= DragOperationPrivate;
     72     return static_cast<DragOperation>(action);
     73 }
     74 
     75 }
     76