Bug 1851041 - Part 2: Add some log in DragService for debugging; r=rkraesig,win-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D189625
This commit is contained in:
Edgar Chen 2023-10-06 21:23:45 +00:00
parent cd03976314
commit d02ac64052
6 changed files with 74 additions and 36 deletions

View file

@ -57,6 +57,8 @@ using namespace mozilla::dom;
using namespace mozilla::gfx;
using namespace mozilla::image;
LazyLogModule sWidgetDragServiceLog("WidgetDragService");
#define DRAGIMAGES_PREF "nglayout.enable_drag_images"
nsBaseDragService::nsBaseDragService()

View file

@ -16,10 +16,17 @@
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/RemoteDragStartData.h"
#include "mozilla/Logging.h"
#include "nsTArray.h"
#include "nsRegion.h"
#include "Units.h"
extern mozilla::LazyLogModule sWidgetDragServiceLog;
#define MOZ_DRAGSERVICE_LOG(...) \
MOZ_LOG(sWidgetDragServiceLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
#define MOZ_DRAGSERVICE_LOG_ENABLED() \
MOZ_LOG_TEST(sWidgetDragServiceLog, mozilla::LogLevel::Debug)
// translucency level for drag images
#define DRAG_TRANSLUCENCY 0.65

View file

@ -1433,6 +1433,42 @@ bool WinUtils::GetAutoRotationState(AR_STATE* aRotationState) {
return false;
}
// static
void WinUtils::GetClipboardFormatAsString(UINT aFormat, nsAString& aOutput) {
wchar_t buf[256] = {};
// Get registered format name and ensure the existence of a terminating '\0'
// if the registered name is more than 256 characters.
if (::GetClipboardFormatNameW(aFormat, buf, ARRAYSIZE(buf) - 1)) {
aOutput.Append(buf);
return;
}
// Standard clipboard formats
// https://learn.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats
switch (aFormat) {
case CF_TEXT: // 1
aOutput.Append(u"CF_TEXT"_ns);
break;
case CF_BITMAP: // 2
aOutput.Append(u"CF_BITMAP"_ns);
break;
case CF_DIB: // 8
aOutput.Append(u"CF_DIB"_ns);
break;
case CF_UNICODETEXT: // 13
aOutput.Append(u"CF_UNICODETEXT"_ns);
break;
case CF_HDROP: // 15
aOutput.Append(u"CF_HDROP"_ns);
break;
case CF_DIBV5: // 17
aOutput.Append(u"CF_DIBV5"_ns);
break;
default:
aOutput.AppendPrintf("%u", aFormat);
break;
}
}
static bool IsTabletDevice() {
// Guarantees that:
// - The device has a touch screen.

View file

@ -592,6 +592,8 @@ class WinUtils {
static bool GetAutoRotationState(AR_STATE* aRotationState);
static void GetClipboardFormatAsString(UINT aFormat, nsAString& aOutput);
private:
static WhitelistVec BuildWhitelist();

View file

@ -47,6 +47,7 @@
#include "nsMimeTypes.h"
#include "imgITools.h"
#include "imgIContainer.h"
#include "WinUtils.h"
/* static */
UINT nsClipboard::GetClipboardFileDescriptorFormatA() {
@ -471,41 +472,6 @@ static void RepeatedlyTryOleSetClipboard(IDataObject* aDataObj) {
RepeatedlyTry(::OleSetClipboard, LogOleSetClipboardResult, aDataObj);
}
static void GetClipboardFormatAsString(UINT aFormat, nsAString& aOutput) {
wchar_t buf[256] = {};
// Get registered format name and ensure the existence of a terminating '\0'
// if the registered name is more than 256 characters.
if (::GetClipboardFormatNameW(aFormat, buf, ARRAYSIZE(buf) - 1)) {
aOutput.Append(buf);
return;
}
// Standard clipboard formats
// https://learn.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats
switch (aFormat) {
case CF_TEXT: // 1
aOutput.Append(u"CF_TEXT"_ns);
break;
case CF_BITMAP: // 2
aOutput.Append(u"CF_BITMAP"_ns);
break;
case CF_DIB: // 8
aOutput.Append(u"CF_DIB"_ns);
break;
case CF_UNICODETEXT: // 13
aOutput.Append(u"CF_UNICODETEXT"_ns);
break;
case CF_HDROP: // 15
aOutput.Append(u"CF_HDROP"_ns);
break;
case CF_DIBV5: // 17
aOutput.Append(u"CF_DIBV5"_ns);
break;
default:
aOutput.AppendPrintf("%u", aFormat);
break;
}
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsClipboard::SetNativeClipboardData(
nsITransferable* aTransferable, nsIClipboardOwner* aOwner,
@ -1361,7 +1327,8 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable,
FORMATETC fEtc;
while (S_OK == pEnum->Next(1, &fEtc, nullptr)) {
nsAutoString format;
GetClipboardFormatAsString(fEtc.cfFormat, format);
mozilla::widget::WinUtils::GetClipboardFormatAsString(fEtc.cfFormat,
format);
MOZ_CLIPBOARD_LOG(" FORMAT %s",
NS_ConvertUTF16toUTF8(format).get());
}

View file

@ -40,6 +40,7 @@
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/gfx/Tools.h"
#include "mozilla/ScopeExit.h"
using namespace mozilla;
using namespace mozilla::gfx;
@ -454,6 +455,24 @@ nsDragService::SetIDataObject(IDataObject* aDataObj) {
mDataObject = aDataObj;
NS_IF_ADDREF(mDataObject);
if (MOZ_DRAGSERVICE_LOG_ENABLED()) {
MOZ_DRAGSERVICE_LOG("nsDragService::SetIDataObject (%p)", mDataObject);
IEnumFORMATETC* pEnum = nullptr;
if (mDataObject &&
S_OK == mDataObject->EnumFormatEtc(DATADIR_GET, &pEnum)) {
MOZ_DRAGSERVICE_LOG(" formats in DataObject:");
FORMATETC fEtc;
while (S_OK == pEnum->Next(1, &fEtc, nullptr)) {
nsAutoString format;
WinUtils::GetClipboardFormatAsString(fEtc.cfFormat, format);
MOZ_DRAGSERVICE_LOG(" FORMAT %s",
NS_ConvertUTF16toUTF8(format).get());
}
pEnum->Release();
}
}
return NS_OK;
}
@ -469,10 +488,15 @@ void nsDragService::SetDroppedLocal() {
NS_IMETHODIMP
nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
if (!aDataFlavor || !mDataObject || !_retval) {
MOZ_DRAGSERVICE_LOG("%s: error", __PRETTY_FUNCTION__);
return NS_ERROR_FAILURE;
}
*_retval = false;
auto logging = MakeScopeExit([&] {
MOZ_DRAGSERVICE_LOG("IsDataFlavorSupported: %s is%s found", aDataFlavor,
*_retval ? "" : " not");
});
FORMATETC fe;
UINT format = 0;