Title: [118941] trunk
Revision
118941
Author
[email protected]
Date
2012-05-30 11:09:44 -0700 (Wed, 30 May 2012)

Log Message

Source/WebCore: eventSender.beginDragWithFiles should be implemented in Windows, which blocked drag and drop related tests.
https://bugs.webkit.org/show_bug.cgi?id=86296

Patch by Xueqing Huang <[email protected]> on 2012-05-30
Reviewed by Tony Chang.

Test: This change was requirement for eventSender.beginDragWithFiles, update win/Skipped file to remove drag and drop related tests will valiate it.

* platform/win/DragDataWin.cpp:
(WebCore::DragData::numberOfFiles):

Tools: eventSender.beginDragWithFiles should be implemented in Windows, which blocked drag and drop related tests.
https://bugs.webkit.org/show_bug.cgi?id=86296

Patch by Xueqing Huang <[email protected]> on 2012-05-30
Reviewed by Tony Chang.

* DumpRenderTree/win/DRTDataObject.cpp: Added.
(cfHDropFormat):
(cfFileNameWFormat):
(cfUrlWFormat):
(WCEnumFormatEtc):
(WCEnumFormatEtc::WCEnumFormatEtc):
(WCEnumFormatEtc::QueryInterface):
(WCEnumFormatEtc::AddRef):
(WCEnumFormatEtc::Release):
(WCEnumFormatEtc::Next):
(WCEnumFormatEtc::Skip):
(WCEnumFormatEtc::Reset):
(WCEnumFormatEtc::Clone):
(DRTDataObject::createInstance):
(DRTDataObject::DRTDataObject):
(DRTDataObject::~DRTDataObject):
(DRTDataObject::QueryInterface):
(DRTDataObject::AddRef):
(DRTDataObject::Release):
(DRTDataObject::GetData):
(DRTDataObject::GetDataHere):
(DRTDataObject::QueryGetData):
(DRTDataObject::GetCanonicalFormatEtc):
(DRTDataObject::SetData):
(DRTDataObject::CopyMedium):
(DRTDataObject::EnumFormatEtc):
(DRTDataObject::DAdvise):
(DRTDataObject::DUnadvise):
(DRTDataObject::EnumDAdvise):
(DRTDataObject::clearData):
* DumpRenderTree/win/DRTDataObject.h: Added.
(DRTDataObject):
* DumpRenderTree/win/DRTDropSource.cpp: Added.
(DRTDropSource::DRTDropSource):
(DRTDropSource::~DRTDropSource):
(DRTDropSource::QueryInterface):
(DRTDropSource::AddRef):
(DRTDropSource::Release):
(DRTDropSource::createInstance):
(DRTDropSource::QueryContinueDrag):
(DRTDropSource::GiveFeedback):
* DumpRenderTree/win/DRTDropSource.h: Added.
(DRTDropSource):
* DumpRenderTree/win/DumpRenderTree.vcproj:
* DumpRenderTree/win/EventSender.cpp:
(beginDragWithFilesCallback):

LayoutTests: The tests listed in win/Skipped should be removed after this change, but some of these need to rebaseline in Windows, we do that in bug#87610.
https://bugs.webkit.org/show_bug.cgi?id=86296

Patch by Xueqing Huang <[email protected]> on 2012-05-30
Reviewed by Tony Chang.

* platform/win/Skipped:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (118940 => 118941)


--- trunk/LayoutTests/ChangeLog	2012-05-30 18:07:20 UTC (rev 118940)
+++ trunk/LayoutTests/ChangeLog	2012-05-30 18:09:44 UTC (rev 118941)
@@ -1,3 +1,12 @@
+2012-05-30  Xueqing Huang  <[email protected]>
+
+        The tests listed in win/Skipped should be removed after this change, but some of these need to rebaseline in Windows, we do that in bug#87610.
+        https://bugs.webkit.org/show_bug.cgi?id=86296
+
+        Reviewed by Tony Chang.
+
+        * platform/win/Skipped:
+
 2012-05-30  Alexey Proskuryakov  <[email protected]>
 
         * fast/files/read-blob-async-expected.txt: Updating results to what Mac WK1 bot sees

Modified: trunk/LayoutTests/platform/win/Skipped (118940 => 118941)


--- trunk/LayoutTests/platform/win/Skipped	2012-05-30 18:07:20 UTC (rev 118940)
+++ trunk/LayoutTests/platform/win/Skipped	2012-05-30 18:09:44 UTC (rev 118941)
@@ -248,21 +248,16 @@
 editing/pasteboard/drop-file-svg.html
 editing/pasteboard/file-drag-to-editable.html
 editing/pasteboard/file-input-files-access.html
-fast/dom/Window/window-postmessage-clone.html
 fast/dom/Window/window-postmessage-clone-frames.html
 fast/events/drag-dataTransferItemList-file-handling.html
-fast/events/drag-file-crash.html
 fast/events/drag-to-navigate.html
 fast/events/drop-handler-should-not-stop-navigate.html
 fast/events/drop-with-file-paths.html
 fast/events/dropzone-004.html
 fast/events/file-input-hidden-in-ondrop.html
 fast/events/input-element-display-none-in-dragleave-crash.html
-fast/events/prevent-drag-to-navigate.html
-fast/forms/file/file-input-change-event.html
 fast/forms/file/file-input-reset.html
 fast/forms/file/file-reset-in-change.html
-fast/forms/file/get-file-upload.html
 fast/forms/file/input-file-directory-upload.html
 fast/forms/file/input-file-re-render.html
 fast/forms/file/recover-file-input-in-unposted-form.html

Modified: trunk/Source/WebCore/ChangeLog (118940 => 118941)


--- trunk/Source/WebCore/ChangeLog	2012-05-30 18:07:20 UTC (rev 118940)
+++ trunk/Source/WebCore/ChangeLog	2012-05-30 18:09:44 UTC (rev 118941)
@@ -1,3 +1,15 @@
+2012-05-30  Xueqing Huang  <[email protected]>
+
+        eventSender.beginDragWithFiles should be implemented in Windows, which blocked drag and drop related tests.
+        https://bugs.webkit.org/show_bug.cgi?id=86296
+
+        Reviewed by Tony Chang.
+
+        Test: This change was requirement for eventSender.beginDragWithFiles, update win/Skipped file to remove drag and drop related tests will valiate it. 
+
+        * platform/win/DragDataWin.cpp:
+        (WebCore::DragData::numberOfFiles):
+
 2012-05-30  Caio Marcelo de Oliveira Filho  <[email protected]>
 
         HashTable.h has using directives for std::pair and std::make_pair

Modified: trunk/Source/WebCore/platform/win/DragDataWin.cpp (118940 => 118941)


--- trunk/Source/WebCore/platform/win/DragDataWin.cpp	2012-05-30 18:07:20 UTC (rev 118940)
+++ trunk/Source/WebCore/platform/win/DragDataWin.cpp	2012-05-30 18:09:44 UTC (rev 118941)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 Baidu Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -111,7 +112,24 @@
 
 unsigned DragData::numberOfFiles() const
 {
-    return 0;
+    if (!m_platformDragData)
+        return 0;
+
+    STGMEDIUM medium;
+    if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium)))
+        return 0;
+
+    HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal));
+
+    if (!hdrop)
+        return 0;
+
+    unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0);
+
+    DragFinish(hdrop);
+    GlobalUnlock(medium.hGlobal);
+
+    return numFiles;
 }
 
 void DragData::asFilenames(Vector<String>& result) const

Modified: trunk/Tools/ChangeLog (118940 => 118941)


--- trunk/Tools/ChangeLog	2012-05-30 18:07:20 UTC (rev 118940)
+++ trunk/Tools/ChangeLog	2012-05-30 18:09:44 UTC (rev 118941)
@@ -1,3 +1,57 @@
+2012-05-30  Xueqing Huang  <[email protected]>
+
+        eventSender.beginDragWithFiles should be implemented in Windows, which blocked drag and drop related tests.
+        https://bugs.webkit.org/show_bug.cgi?id=86296
+
+        Reviewed by Tony Chang.
+
+        * DumpRenderTree/win/DRTDataObject.cpp: Added.
+        (cfHDropFormat):
+        (cfFileNameWFormat):
+        (cfUrlWFormat):
+        (WCEnumFormatEtc):
+        (WCEnumFormatEtc::WCEnumFormatEtc):
+        (WCEnumFormatEtc::QueryInterface):
+        (WCEnumFormatEtc::AddRef):
+        (WCEnumFormatEtc::Release):
+        (WCEnumFormatEtc::Next):
+        (WCEnumFormatEtc::Skip):
+        (WCEnumFormatEtc::Reset):
+        (WCEnumFormatEtc::Clone):
+        (DRTDataObject::createInstance):
+        (DRTDataObject::DRTDataObject):
+        (DRTDataObject::~DRTDataObject):
+        (DRTDataObject::QueryInterface):
+        (DRTDataObject::AddRef):
+        (DRTDataObject::Release):
+        (DRTDataObject::GetData):
+        (DRTDataObject::GetDataHere):
+        (DRTDataObject::QueryGetData):
+        (DRTDataObject::GetCanonicalFormatEtc):
+        (DRTDataObject::SetData):
+        (DRTDataObject::CopyMedium):
+        (DRTDataObject::EnumFormatEtc):
+        (DRTDataObject::DAdvise):
+        (DRTDataObject::DUnadvise):
+        (DRTDataObject::EnumDAdvise):
+        (DRTDataObject::clearData):
+        * DumpRenderTree/win/DRTDataObject.h: Added.
+        (DRTDataObject):
+        * DumpRenderTree/win/DRTDropSource.cpp: Added.
+        (DRTDropSource::DRTDropSource):
+        (DRTDropSource::~DRTDropSource):
+        (DRTDropSource::QueryInterface):
+        (DRTDropSource::AddRef):
+        (DRTDropSource::Release):
+        (DRTDropSource::createInstance):
+        (DRTDropSource::QueryContinueDrag):
+        (DRTDropSource::GiveFeedback):
+        * DumpRenderTree/win/DRTDropSource.h: Added.
+        (DRTDropSource):
+        * DumpRenderTree/win/DumpRenderTree.vcproj:
+        * DumpRenderTree/win/EventSender.cpp:
+        (beginDragWithFilesCallback):
+
 2012-05-30  Marcelo Lira  <[email protected]>
 
         WebKit2: Implement layoutTestController.setPluginsEnabled() in WebKitTestRunner.

Added: trunk/Tools/DumpRenderTree/win/DRTDataObject.cpp (0 => 118941)


--- trunk/Tools/DumpRenderTree/win/DRTDataObject.cpp	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/win/DRTDataObject.cpp	2012-05-30 18:09:44 UTC (rev 118941)
@@ -0,0 +1,381 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2012 Baidu Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "DRTDataObject.h"
+
+FORMATETC* cfHDropFormat()
+{
+    static FORMATETC urlFormat = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
+    return &urlFormat;
+}
+
+FORMATETC* cfFileNameWFormat()
+{
+    static UINT cf = RegisterClipboardFormat(L"FileNameW");
+    static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
+    return &urlFormat;
+}
+
+FORMATETC* cfUrlWFormat()
+{
+    static UINT cf = RegisterClipboardFormat(L"UniformResourceLocatorW");
+    static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
+    return &urlFormat;
+}
+
+class WCEnumFormatEtc : public IEnumFORMATETC {
+public:
+    explicit WCEnumFormatEtc(const Vector<FORMATETC>& formats);
+    explicit WCEnumFormatEtc(const Vector<FORMATETC*>& formats);
+
+    // IUnknown members
+    STDMETHOD(QueryInterface)(REFIID, void**);
+    STDMETHOD_(ULONG, AddRef)();
+    STDMETHOD_(ULONG, Release)();
+
+    // IEnumFORMATETC members
+    STDMETHOD(Next)(ULONG, LPFORMATETC, ULONG*);
+    STDMETHOD(Skip)(ULONG);
+    STDMETHOD(Reset)();
+    STDMETHOD(Clone)(IEnumFORMATETC**);
+
+private:
+    long m_ref;
+    Vector<FORMATETC> m_formats;
+    size_t m_current;
+};
+
+WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC>& formats)
+    : m_ref(1)
+    , m_current(0)
+    , m_formats(formats)
+{
+}
+
+WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC*>& formats)
+    : m_ref(1)
+    , m_current(0)
+{
+    for (size_t i = 0; i < formats.size(); ++i)
+        m_formats.append(*formats[i]);
+}
+
+STDMETHODIMP WCEnumFormatEtc::QueryInterface(REFIID riid, void** ppvObject)
+{
+    *ppvObject = 0;
+    if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IEnumFORMATETC)) {
+        *ppvObject = this;
+        AddRef();
+        return S_OK;
+    }
+
+    return E_NOINTERFACE;
+}
+
+STDMETHODIMP_(ULONG) WCEnumFormatEtc::AddRef()
+{
+    return InterlockedIncrement(&m_ref);
+}
+
+STDMETHODIMP_(ULONG) WCEnumFormatEtc::Release()
+{
+    long refCount = InterlockedDecrement(&m_ref);
+    if (!refCount)
+        delete this;
+    return refCount;
+}
+
+STDMETHODIMP WCEnumFormatEtc::Next(ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
+{
+    if (pceltFetched)
+        *pceltFetched = 0;
+
+    ULONG cReturn = celt;
+
+    if (celt <= 0 || !lpFormatEtc || m_current >= m_formats.size())
+        return S_FALSE;
+
+    if (!pceltFetched && celt != 1) // pceltFetched can be 0 only for 1 item request
+        return S_FALSE;
+
+    while (m_current < m_formats.size() && cReturn > 0) {
+        *lpFormatEtc++ = m_formats[m_current++];
+        --cReturn;
+    }
+    if (pceltFetched)
+        *pceltFetched = celt - cReturn;
+
+    return !cReturn ? S_OK : S_FALSE;
+}
+
+STDMETHODIMP WCEnumFormatEtc::Skip(ULONG celt)
+{
+    if ((m_current + celt) >= m_formats.size())
+        return S_FALSE;
+    m_current += celt;
+    return S_OK;
+}
+
+STDMETHODIMP WCEnumFormatEtc::Reset()
+{
+    m_current = 0;
+    return S_OK;
+}
+
+STDMETHODIMP WCEnumFormatEtc::Clone(IEnumFORMATETC** ppCloneEnumFormatEtc)
+{
+    if (!ppCloneEnumFormatEtc)
+        return E_POINTER;
+
+    WCEnumFormatEtc* newEnum = new WCEnumFormatEtc(m_formats);
+    if (!newEnum)
+        return E_OUTOFMEMORY;
+
+    newEnum->AddRef();
+    newEnum->m_current = m_current;
+    *ppCloneEnumFormatEtc = newEnum;
+    return S_OK;
+}
+
+//////////////////////////////////////////////////////////////////////////
+HRESULT DRTDataObject::createInstance(DRTDataObject** result)
+{
+    if (!result)
+        return E_POINTER;
+    *result = new DRTDataObject();
+    return S_OK;
+}
+
+DRTDataObject::DRTDataObject()
+    : m_ref(1)
+{
+}
+
+DRTDataObject::~DRTDataObject()
+{
+    for (size_t i = 0; i < m_medium.size(); ++i) {
+        ReleaseStgMedium(m_medium[i]);
+        delete m_medium[i];
+    }
+    WTF::deleteAllValues(m_formats);
+}
+
+STDMETHODIMP DRTDataObject::QueryInterface(REFIID riid, void** ppvObject)
+{
+    *ppvObject = 0;
+    if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDataObject))
+        *ppvObject = this;
+
+    if (*ppvObject) {
+        AddRef();
+        return S_OK;
+    }
+    return E_NOINTERFACE;
+}
+
+STDMETHODIMP_(ULONG) DRTDataObject::AddRef()
+{
+    return InterlockedIncrement(&m_ref);
+}
+
+STDMETHODIMP_(ULONG) DRTDataObject::Release()
+{
+    long refCount = InterlockedDecrement(&m_ref);
+    if (!refCount)
+        delete this;
+    return refCount;
+}
+
+STDMETHODIMP DRTDataObject::GetData(FORMATETC* pformatetcIn, STGMEDIUM* pmedium)
+{ 
+    if (!pformatetcIn || !pmedium)
+        return E_POINTER;
+    pmedium->hGlobal = 0;
+
+    for (size_t i = 0; i < m_formats.size(); ++i) {
+        if (pformatetcIn->lindex == m_formats[i]->lindex && pformatetcIn->dwAspect == m_formats[i]->dwAspect && pformatetcIn->cfFormat == m_formats[i]->cfFormat) {
+            CopyMedium(pmedium, m_medium[i], m_formats[i]);
+            return S_OK;
+        }
+    }
+    return DV_E_FORMATETC;
+}
+
+STDMETHODIMP DRTDataObject::GetDataHere(FORMATETC*, STGMEDIUM*)
+{ 
+    return E_NOTIMPL;
+}
+
+STDMETHODIMP DRTDataObject::QueryGetData(FORMATETC* pformatetc)
+{ 
+    if (!pformatetc)
+        return E_POINTER;
+
+    if (!(DVASPECT_CONTENT & pformatetc->dwAspect))
+        return (DV_E_DVASPECT);
+
+    for (size_t i = 0; i < m_formats.size(); ++i) {
+        if (pformatetc->tymed & m_formats[i]->tymed) {
+            if (pformatetc->cfFormat == m_formats[i]->cfFormat)
+                return S_OK;
+        }
+    }
+    return DV_E_TYMED;
+}
+
+STDMETHODIMP DRTDataObject::GetCanonicalFormatEtc(FORMATETC*, FORMATETC*)
+{ 
+    return DATA_S_SAMEFORMATETC;
+}
+
+STDMETHODIMP DRTDataObject::SetData(FORMATETC* pformatetc, STGMEDIUM* pmedium, BOOL fRelease)
+{ 
+    if (!pformatetc || !pmedium)
+        return E_POINTER;
+
+    FORMATETC* formatetc = new FORMATETC;
+    if (!formatetc)
+        return E_OUTOFMEMORY;
+
+    STGMEDIUM* pStgMed = new STGMEDIUM;
+
+    if (!pStgMed) {
+        delete formatetc;
+        return E_OUTOFMEMORY;
+    }
+
+    ZeroMemory(formatetc, sizeof(FORMATETC));
+    ZeroMemory(pStgMed, sizeof(STGMEDIUM));
+
+    *formatetc = *pformatetc;
+    m_formats.append(formatetc);
+
+    if (fRelease)
+        *pStgMed = *pmedium;
+    else
+        CopyMedium(pStgMed, pmedium, pformatetc);
+    m_medium.append(pStgMed);
+
+    return S_OK;
+}
+
+void DRTDataObject::CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC* pFmtSrc)
+{
+    switch (pMedSrc->tymed) {
+#if !OS(WINCE)
+    case TYMED_HGLOBAL:
+        pMedDest->hGlobal = static_cast<HGLOBAL>(OleDuplicateData(pMedSrc->hGlobal, pFmtSrc->cfFormat, 0));
+        break;
+    case TYMED_GDI:
+        pMedDest->hBitmap = static_cast<HBITMAP>(OleDuplicateData(pMedSrc->hBitmap, pFmtSrc->cfFormat, 0));
+        break;
+    case TYMED_MFPICT:
+        pMedDest->hMetaFilePict = static_cast<HMETAFILEPICT>(OleDuplicateData(pMedSrc->hMetaFilePict, pFmtSrc->cfFormat, 0));
+        break;
+    case TYMED_ENHMF:
+        pMedDest->hEnhMetaFile = static_cast<HENHMETAFILE>(OleDuplicateData(pMedSrc->hEnhMetaFile, pFmtSrc->cfFormat, 0));
+        break;
+    case TYMED_FILE:
+        pMedSrc->lpszFileName = static_cast<LPOLESTR>(OleDuplicateData(pMedSrc->lpszFileName, pFmtSrc->cfFormat, 0));
+        break;
+#endif
+    case TYMED_ISTREAM:
+        pMedDest->pstm = pMedSrc->pstm;
+        pMedSrc->pstm->AddRef();
+        break;
+    case TYMED_ISTORAGE:
+        pMedDest->pstg = pMedSrc->pstg;
+        pMedSrc->pstg->AddRef();
+        break;
+    default:
+        break;
+    }
+    pMedDest->tymed = pMedSrc->tymed;
+    pMedDest->pUnkForRelease = 0;
+    if (pMedSrc->pUnkForRelease) {
+        pMedDest->pUnkForRelease = pMedSrc->pUnkForRelease;
+        pMedSrc->pUnkForRelease->AddRef();
+    }
+}
+STDMETHODIMP DRTDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc)
+{ 
+    if (!ppenumFormatEtc)
+        return E_POINTER;
+
+    *ppenumFormatEtc = 0;
+    switch (dwDirection) {
+    case DATADIR_GET:
+        *ppenumFormatEtc = new WCEnumFormatEtc(m_formats);
+        if (!(*ppenumFormatEtc))
+            return E_OUTOFMEMORY;
+        break;
+
+    case DATADIR_SET:
+    default:
+        return E_NOTIMPL;
+        break;
+    }
+
+    return S_OK;
+}
+
+STDMETHODIMP DRTDataObject::DAdvise(FORMATETC*, DWORD, IAdviseSink*, DWORD*)
+{ 
+    return OLE_E_ADVISENOTSUPPORTED;
+}
+
+STDMETHODIMP DRTDataObject::DUnadvise(DWORD)
+{
+    return E_NOTIMPL;
+}
+
+HRESULT STDMETHODCALLTYPE DRTDataObject::EnumDAdvise(IEnumSTATDATA**)
+{
+    return OLE_E_ADVISENOTSUPPORTED;
+}
+
+void DRTDataObject::clearData(CLIPFORMAT format)
+{
+    size_t position = 0;
+    while (position < m_formats.size()) {
+        if (m_formats[position]->cfFormat == format) {
+            FORMATETC* current = m_formats[position];
+            m_formats[position] = m_formats[m_formats.size() - 1];
+            m_formats[m_formats.size() - 1] = 0;
+            m_formats.removeLast();
+            delete current;
+            STGMEDIUM* medium = m_medium[position];
+            m_medium[position] = m_medium[m_medium.size() - 1];
+            m_medium[m_medium.size() - 1] = 0;
+            m_medium.removeLast();
+            ReleaseStgMedium(medium);
+            delete medium;
+            continue;
+        }
+        position++;
+    }
+}

Added: trunk/Tools/DumpRenderTree/win/DRTDataObject.h (0 => 118941)


--- trunk/Tools/DumpRenderTree/win/DRTDataObject.h	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/win/DRTDataObject.h	2012-05-30 18:09:44 UTC (rev 118941)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2012 Baidu Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef DRTDataObject_h
+#define DRTDataObject_h
+
+#include <ShlObj.h>
+#include <objidl.h>
+#include <wtf/Vector.h>
+
+FORMATETC* cfHDropFormat();
+
+FORMATETC* cfFileNameWFormat();
+
+FORMATETC* cfUrlWFormat();
+
+class DRTDataObject : public IDataObject {
+public:
+    void CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC* pFmtSrc);
+
+    // IUnknown
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);        
+    virtual ULONG STDMETHODCALLTYPE AddRef();
+    virtual ULONG STDMETHODCALLTYPE Release();
+
+    // IDataObject
+    virtual HRESULT STDMETHODCALLTYPE GetData(FORMATETC* pformatIn, STGMEDIUM* pmedium);
+    virtual HRESULT STDMETHODCALLTYPE GetDataHere(FORMATETC* pformat, STGMEDIUM* pmedium);
+    virtual HRESULT STDMETHODCALLTYPE QueryGetData(FORMATETC* pformat);
+    virtual HRESULT STDMETHODCALLTYPE GetCanonicalFormatEtc(FORMATETC* pformatectIn, FORMATETC* pformatOut);
+    virtual HRESULT STDMETHODCALLTYPE SetData(FORMATETC* pformat, STGMEDIUM*pmedium, BOOL release);
+    virtual HRESULT STDMETHODCALLTYPE EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc);
+    virtual HRESULT STDMETHODCALLTYPE DAdvise(FORMATETC*, DWORD, IAdviseSink*, DWORD*);
+    virtual HRESULT STDMETHODCALLTYPE DUnadvise(DWORD);
+    virtual HRESULT STDMETHODCALLTYPE EnumDAdvise(IEnumSTATDATA**);
+
+    void clearData(CLIPFORMAT);
+    
+    static HRESULT createInstance(DRTDataObject**);
+private:
+    DRTDataObject();
+    ~DRTDataObject();
+    long m_ref;
+    Vector<FORMATETC*> m_formats;
+    Vector<STGMEDIUM*> m_medium;
+};
+
+#endif // DRTDataObject_h

Added: trunk/Tools/DumpRenderTree/win/DRTDropSource.cpp (0 => 118941)


--- trunk/Tools/DumpRenderTree/win/DRTDropSource.cpp	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/win/DRTDropSource.cpp	2012-05-30 18:09:44 UTC (rev 118941)
@@ -0,0 +1,86 @@
+/*
+* Copyright (C) 2012 Baidu Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+*/
+
+#include "config.h"
+#include "DRTDropSource.h"
+
+DRTDropSource::DRTDropSource()
+    : m_ref(1)
+    , m_dropped(false)
+{
+}
+
+DRTDropSource::~DRTDropSource()
+{
+}
+
+STDMETHODIMP DRTDropSource::QueryInterface(REFIID riid, void** ppvObject)
+{
+    *ppvObject = 0;
+    if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDropSource)) {
+        *ppvObject = this;
+        AddRef();
+
+        return S_OK;
+    }
+
+    return E_NOINTERFACE;
+}
+
+STDMETHODIMP_(ULONG) DRTDropSource::AddRef()
+{
+    return InterlockedIncrement(&m_ref);
+}
+
+STDMETHODIMP_(ULONG) DRTDropSource::Release()
+{
+    long refCount = InterlockedDecrement(&m_ref);
+    if (!refCount)
+        delete this;
+    return refCount;
+}
+
+HRESULT DRTDropSource::createInstance(IDropSource** result)
+{
+    if (!result)
+        return E_INVALIDARG;
+    *result = new DRTDropSource;
+    return S_OK;
+}
+
+STDMETHODIMP DRTDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState)
+{
+    if (fEscapePressed || !(grfKeyState & (MK_LBUTTON | MK_RBUTTON))) {
+        m_dropped = !fEscapePressed;
+        return fEscapePressed ? DRAGDROP_S_CANCEL : DRAGDROP_S_DROP;
+    }
+
+    return S_OK;
+}
+
+STDMETHODIMP DRTDropSource::GiveFeedback(DWORD dwEffect)
+{
+    return DRAGDROP_S_USEDEFAULTCURSORS;
+}

Added: trunk/Tools/DumpRenderTree/win/DRTDropSource.h (0 => 118941)


--- trunk/Tools/DumpRenderTree/win/DRTDropSource.h	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/win/DRTDropSource.h	2012-05-30 18:09:44 UTC (rev 118941)
@@ -0,0 +1,48 @@
+/*
+* Copyright (C) 2012 Baidu Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+*/
+
+#ifndef DRTDropSource_h
+#define DRTDropSource_h
+
+#include <ShlObj.h>
+#include <windows.h>
+
+class DRTDropSource : public IDropSource {
+public:
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);        
+    virtual ULONG STDMETHODCALLTYPE AddRef();
+    virtual ULONG STDMETHODCALLTYPE Release();
+    virtual HRESULT STDMETHODCALLTYPE QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState);
+    virtual HRESULT STDMETHODCALLTYPE GiveFeedback(DWORD dwEffect);
+
+    static HRESULT createInstance(IDropSource** result);
+private:
+    DRTDropSource();
+    ~DRTDropSource();
+    long m_ref;
+    bool m_dropped;
+};
+
+#endif // DRTDropSource_h

Modified: trunk/Tools/DumpRenderTree/win/DumpRenderTree.vcproj (118940 => 118941)


--- trunk/Tools/DumpRenderTree/win/DumpRenderTree.vcproj	2012-05-30 18:07:20 UTC (rev 118940)
+++ trunk/Tools/DumpRenderTree/win/DumpRenderTree.vcproj	2012-05-30 18:09:44 UTC (rev 118941)
@@ -402,6 +402,22 @@
 				>
 			</File>
 			<File
+				RelativePath=".\DRTDataObject.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\DRTDataObject.h"
+				>
+			</File>
+			<File
+				RelativePath=".\DRTDropSource.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\DRTDropSource.h"
+				>
+			</File>
+			<File
 				RelativePath=".\EventSender.cpp"
 				>
 			</File>

Modified: trunk/Tools/DumpRenderTree/win/EventSender.cpp (118940 => 118941)


--- trunk/Tools/DumpRenderTree/win/EventSender.cpp	2012-05-30 18:07:20 UTC (rev 118940)
+++ trunk/Tools/DumpRenderTree/win/EventSender.cpp	2012-05-30 18:09:44 UTC (rev 118941)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 Baidu Inc. All rights reserved
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,16 +30,19 @@
 #include "config.h"
 #include "EventSender.h"
 
+#include "DRTDataObject.h"
+#include "DRTDropSource.h"
 #include "DraggingInfo.h"
 #include "DumpRenderTree.h"
 
+#include <_javascript_Core/_javascript_Core.h>
 #include <WebCore/COMPtr.h>
+#include <WebKit/WebKit.h>
+#include <windows.h>
 #include <wtf/ASCIICType.h>
 #include <wtf/Assertions.h>
 #include <wtf/Platform.h>
-#include <_javascript_Core/_javascript_Core.h>
-#include <WebKit/WebKit.h>
-#include <windows.h>
+#include <wtf/text/WTFString.h>
 
 #define WM_DRT_SEND_QUEUED_EVENT (WM_APP+1)
 
@@ -642,6 +646,86 @@
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef beginDragWithFilesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    if (argumentCount < 1)
+        return JSValueMakeUndefined(context);
+
+    JSObjectRef filesArray = JSValueToObject(context, arguments[0], 0);
+
+    if (!filesArray)
+        return JSValueMakeUndefined(context);
+
+    JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length");
+    Vector<UChar> files;
+    int filesCount = JSValueToNumber(context, JSObjectGetProperty(context, filesArray, lengthProperty, 0), 0);
+    for (int i = 0; i < filesCount; ++i) {
+        JSValueRef value = JSObjectGetPropertyAtIndex(context, filesArray, i, 0);
+        JSStringRef file = JSValueToStringCopy(context, value, 0);
+        files.append(JSStringGetCharactersPtr(file), JSStringGetLength(file));
+        files.append(0);
+        JSStringRelease(file);
+    }
+
+    if (files.isEmpty())
+        return JSValueMakeUndefined(context);
+
+    // We should append "0" in the end of |files| so that |DragQueryFileW| retrieved the number of files correctly from Ole Clipboard.
+    files.append(0);
+
+    STGMEDIUM hDropMedium = {0};
+    hDropMedium.tymed = TYMED_HGLOBAL;
+    SIZE_T dropFilesSize = sizeof(DROPFILES) + (sizeof(WCHAR) * files.size());
+    hDropMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, dropFilesSize);
+    DROPFILES* dropFiles = reinterpret_cast<DROPFILES*>(GlobalLock(hDropMedium.hGlobal));
+    memset(dropFiles, 0, sizeof(DROPFILES));
+    dropFiles->pFiles = sizeof(DROPFILES);
+    dropFiles->fWide = TRUE;
+
+    UChar* data = "" + sizeof(DROPFILES));
+    for (size_t i = 0; i < files.size(); ++i)
+        data[i] = files[i];
+    GlobalUnlock(hDropMedium.hGlobal); 
+
+    STGMEDIUM hFileNameMedium = {0};
+    hFileNameMedium.tymed = TYMED_HGLOBAL;
+    SIZE_T hFileNameSize = sizeof(WCHAR) * files.size();
+    hFileNameMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, hFileNameSize);
+    WCHAR* hFileName = static_cast<WCHAR*>(GlobalLock(hFileNameMedium.hGlobal));
+    for (size_t i = 0; i < files.size(); i++)
+        hFileName[i] = files[i];
+    GlobalUnlock(hFileNameMedium.hGlobal);
+
+    if (draggingInfo) {
+        delete draggingInfo;
+        draggingInfo = 0;
+    }
+
+    COMPtr<DRTDataObject> dataObeject;
+    COMPtr<IDropSource> source;
+    if (FAILED(DRTDataObject::createInstance(&dataObeject)))
+        dataObeject = 0;
+
+    if (FAILED(DRTDropSource::createInstance(&source)))
+        source = 0;
+
+    if (dataObeject && source) {
+        draggingInfo = new DraggingInfo(dataObeject.get(), source.get());
+        draggingInfo->setPerformedDropEffect(DROPEFFECT_COPY);
+    }
+
+    if (draggingInfo) {
+        draggingInfo->dataObject()->SetData(cfHDropFormat(), &hDropMedium, FALSE);
+        draggingInfo->dataObject()->SetData(cfFileNameWFormat(), &hFileNameMedium, FALSE);
+        draggingInfo->dataObject()->SetData(cfUrlWFormat(), &hFileNameMedium, FALSE);
+        OleSetClipboard(draggingInfo->dataObject());
+        down = true;
+    }
+
+    JSStringRelease(lengthProperty);
+    return JSValueMakeUndefined(context);
+}
+
 static JSStaticFunction staticFunctions[] = {
     { "contextClick", contextClickCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     { "mouseDown", mouseDownCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
@@ -654,6 +738,7 @@
     { "textZoomOut", textZoomOutCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     { "zoomPageIn", zoomPageInCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     { "zoomPageOut", zoomPageOutCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+    { "beginDragWithFiles", beginDragWithFilesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     { 0, 0, 0 }
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to