mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 02:25:34 +00:00
Bug 1701757
- Change clipboard format static initializers to lazy statics r=tkikuchi,bobowen
Differential Revision: https://phabricator.services.mozilla.com/D110147
This commit is contained in:
parent
9ec310f320
commit
3734c86d5b
@ -36,10 +36,18 @@ using mozilla::LogLevel;
|
||||
|
||||
static mozilla::LazyLogModule gWin32ClipboardLog("nsClipboard");
|
||||
|
||||
// oddly, this isn't in the MSVC headers anywhere.
|
||||
UINT nsClipboard::CF_HTML = ::RegisterClipboardFormatW(L"HTML Format");
|
||||
UINT nsClipboard::CF_CUSTOMTYPES =
|
||||
::RegisterClipboardFormatW(L"application/x-moz-custom-clipdata");
|
||||
/* static */
|
||||
UINT nsClipboard::GetHtmlClipboardFormat() {
|
||||
static UINT format = ::RegisterClipboardFormatW(L"HTML Format");
|
||||
return format;
|
||||
}
|
||||
|
||||
/* static */
|
||||
UINT nsClipboard::GetCustomClipboardFormat() {
|
||||
static UINT format =
|
||||
::RegisterClipboardFormatW(L"application/x-moz-custom-clipdata");
|
||||
return format;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
@ -96,9 +104,9 @@ UINT nsClipboard::GetFormat(const char* aMimeStr, bool aMapHTMLMime) {
|
||||
format = CF_HDROP;
|
||||
} else if ((strcmp(aMimeStr, kNativeHTMLMime) == 0) ||
|
||||
(aMapHTMLMime && strcmp(aMimeStr, kHTMLMime) == 0)) {
|
||||
format = CF_HTML;
|
||||
format = GetHtmlClipboardFormat();
|
||||
} else if (strcmp(aMimeStr, kCustomTypesMime) == 0) {
|
||||
format = CF_CUSTOMTYPES;
|
||||
format = GetCustomClipboardFormat();
|
||||
} else {
|
||||
format = ::RegisterClipboardFormatW(NS_ConvertASCIItoUTF16(aMimeStr).get());
|
||||
}
|
||||
@ -180,7 +188,8 @@ nsresult nsClipboard::SetupNativeDataObject(nsITransferable* aTransferable,
|
||||
// if we find text/html, also advertise win32's html flavor (which we will
|
||||
// convert on our own in nsDataObj::GetText().
|
||||
FORMATETC htmlFE;
|
||||
SET_FORMATETC(htmlFE, CF_HTML, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
|
||||
SET_FORMATETC(htmlFE, GetHtmlClipboardFormat(), 0, DVASPECT_CONTENT, -1,
|
||||
TYMED_HGLOBAL);
|
||||
dObj->AddDataFlavor(kHTMLMime, &htmlFE);
|
||||
} else if (flavorStr.EqualsLiteral(kURLMime)) {
|
||||
// if we're a url, in addition to also being text, we need to register
|
||||
@ -549,14 +558,14 @@ nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject* aDataObject,
|
||||
// assumption. Stay tuned.
|
||||
uint32_t allocLen = 0;
|
||||
if (NS_SUCCEEDED(GetGlobalData(stm.hGlobal, aData, &allocLen))) {
|
||||
if (fe.cfFormat == CF_HTML) {
|
||||
if (fe.cfFormat == GetHtmlClipboardFormat()) {
|
||||
// CF_HTML is actually UTF8, not unicode, so disregard the
|
||||
// assumption above. We have to check the header for the
|
||||
// actual length, and we'll do that in FindPlatformHTML().
|
||||
// For now, return the allocLen. This case is mostly to
|
||||
// ensure we don't try to call strlen on the buffer.
|
||||
*aLen = allocLen;
|
||||
} else if (fe.cfFormat == CF_CUSTOMTYPES) {
|
||||
} else if (fe.cfFormat == GetCustomClipboardFormat()) {
|
||||
// Binary data
|
||||
*aLen = allocLen;
|
||||
} else if (fe.cfFormat == preferredDropEffect) {
|
||||
|
@ -61,8 +61,8 @@ class nsClipboard : public nsBaseClipboard, public nsIObserver {
|
||||
// of Gecko.
|
||||
static UINT GetFormat(const char* aMimeStr, bool aMapHTMLMime = true);
|
||||
|
||||
static UINT CF_HTML;
|
||||
static UINT CF_CUSTOMTYPES;
|
||||
static UINT GetHtmlClipboardFormat();
|
||||
static UINT GetCustomClipboardFormat();
|
||||
|
||||
protected:
|
||||
NS_IMETHOD SetNativeClipboardData(int32_t aWhichClipboard) override;
|
||||
|
@ -1490,7 +1490,7 @@ HRESULT nsDataObj::GetText(const nsACString& aDataFlavor, FORMATETC& aFE,
|
||||
NS_WARNING("Oh no, couldn't convert unicode to plain text");
|
||||
return S_OK;
|
||||
}
|
||||
} else if (aFE.cfFormat == nsClipboard::CF_HTML) {
|
||||
} else if (aFE.cfFormat == nsClipboard::GetHtmlClipboardFormat()) {
|
||||
// Someone is asking for win32's HTML flavor. Convert our html fragment
|
||||
// from unicode to UTF-8 then put it into a format specified by msft.
|
||||
NS_ConvertUTF16toUTF8 converter(reinterpret_cast<char16_t*>(data));
|
||||
@ -1507,7 +1507,7 @@ HRESULT nsDataObj::GetText(const nsACString& aDataFlavor, FORMATETC& aFE,
|
||||
NS_WARNING("Oh no, couldn't convert to HTML");
|
||||
return S_OK;
|
||||
}
|
||||
} else if (aFE.cfFormat != nsClipboard::CF_CUSTOMTYPES) {
|
||||
} else if (aFE.cfFormat != nsClipboard::GetCustomClipboardFormat()) {
|
||||
// we assume that any data that isn't caught above is unicode. This may
|
||||
// be an erroneous assumption, but is true so far.
|
||||
allocLen += sizeof(char16_t);
|
||||
|
Loading…
Reference in New Issue
Block a user