webengine/osswebengine/WebKit/win/WebDropSource.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  * 1. Redistributions of source code must retain the above copyright
       
     8  *    notice, this list of conditions and the following disclaimer.
       
     9  * 2. Redistributions in binary form must reproduce the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer in the
       
    11  *    documentation and/or other materials provided with the distribution.
       
    12  *
       
    13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
       
    14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
       
    17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
       
    21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
       
    24  */
       
    25 
       
    26 #include "config.h"
       
    27 #include "WebDropSource.h"
       
    28 #include "WebView.h"
       
    29 
       
    30 #include <WebCore/DragActions.h>
       
    31 #include <WebCore/EventHandler.h>
       
    32 #include <WebCore/Frame.h>
       
    33 #include <WebCore/Page.h>
       
    34 #include <WebCore/PlatformMouseEvent.h>
       
    35 #include <WebCore/SystemTime.h>
       
    36 
       
    37 #include <Windows.h>
       
    38 
       
    39 using namespace WebCore;
       
    40 
       
    41 
       
    42 HRESULT WebDropSource::createInstance(WebView* webView, IDropSource** result)
       
    43 {
       
    44     if (!webView || !result)
       
    45         return E_INVALIDARG;
       
    46     *result = new WebDropSource(webView);
       
    47     return S_OK;
       
    48 }
       
    49 
       
    50 WebDropSource::WebDropSource(WebView* webView)
       
    51 : m_ref(1)
       
    52 , m_dropped(false) 
       
    53 , m_webView(webView)
       
    54 {
       
    55 
       
    56 }
       
    57 
       
    58 STDMETHODIMP WebDropSource::QueryInterface(REFIID riid, void** ppvObject)
       
    59 {
       
    60     *ppvObject = 0;
       
    61     if (IsEqualIID(riid, IID_IUnknown) || 
       
    62         IsEqualIID(riid, IID_IDropSource)) {
       
    63         *ppvObject = this;
       
    64         AddRef();
       
    65 
       
    66         return S_OK;
       
    67     }
       
    68 
       
    69     return E_NOINTERFACE;
       
    70 }
       
    71 
       
    72 STDMETHODIMP_(ULONG) WebDropSource::AddRef(void)
       
    73 {
       
    74     return InterlockedIncrement(&m_ref);
       
    75 }
       
    76 
       
    77 STDMETHODIMP_(ULONG) WebDropSource::Release(void)
       
    78 {
       
    79     long c = InterlockedDecrement(&m_ref);
       
    80     if (c == 0)
       
    81         delete this;
       
    82     return c;
       
    83 }
       
    84 
       
    85 PlatformMouseEvent generateMouseEvent(WebView* webView, bool isDrag) {
       
    86     POINTL pt;
       
    87     ::GetCursorPos((LPPOINT)&pt);
       
    88     POINTL localpt = pt;
       
    89     HWND viewWindow;
       
    90     if (SUCCEEDED(webView->viewWindow((OLE_HANDLE*)&viewWindow)))
       
    91         ::ScreenToClient(viewWindow, (LPPOINT)&localpt);
       
    92     return PlatformMouseEvent(IntPoint(localpt.x, localpt.y), IntPoint(pt.x, pt.y),
       
    93         isDrag ? LeftButton : NoButton, MouseEventMoved, 0, false, false, false, false, currentTime());
       
    94 }
       
    95 
       
    96 STDMETHODIMP WebDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState)
       
    97 {
       
    98     if(fEscapePressed)
       
    99         return DRAGDROP_S_CANCEL;
       
   100 
       
   101     if(!(grfKeyState & (MK_LBUTTON|MK_RBUTTON))) {
       
   102         m_dropped = true;
       
   103         if (Page* page = m_webView->page())
       
   104             if (Frame* frame = page->mainFrame()) 
       
   105                 //FIXME: We need to figure out how to find out what actually happened in the drag <rdar://problem/5015961>
       
   106                 frame->eventHandler()->dragSourceEndedAt(generateMouseEvent(m_webView.get(), false), DragOperationCopy);
       
   107         return DRAGDROP_S_DROP;
       
   108     } else if (Page* page = m_webView->page())
       
   109         if (Frame* frame = page->mainFrame()) 
       
   110             frame->eventHandler()->dragSourceMovedTo(generateMouseEvent(m_webView.get(), true));
       
   111 
       
   112     return S_OK;
       
   113 
       
   114 }
       
   115 
       
   116 STDMETHODIMP WebDropSource::GiveFeedback(DWORD)
       
   117 {
       
   118     return DRAGDROP_S_USEDEFAULTCURSORS;
       
   119 }