summaryrefslogtreecommitdiffstats
path: root/widget/windows/nsClipboard.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-02-07 22:06:24 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-02-07 22:06:24 +0100
commit6992106dc7894fab3f620263e99b4083b36bf9e8 (patch)
tree2a3554cf7bfabfeee0cc56ca58b04773a902cb76 /widget/windows/nsClipboard.cpp
parent0b6d9a47051be9ef4d064c6f7c60717da91d0bc2 (diff)
downloadUXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar
UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar.gz
UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar.lz
UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar.xz
UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.zip
Use existing image decoders to handle clipboard BMP data.
This gets rid of the old nsImageClipboard widget code in favor of using the nsBMPDecoder in imglib.
Diffstat (limited to 'widget/windows/nsClipboard.cpp')
-rw-r--r--widget/windows/nsClipboard.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/widget/windows/nsClipboard.cpp b/widget/windows/nsClipboard.cpp
index 432badeb5..c93f351c8 100644
--- a/widget/windows/nsClipboard.cpp
+++ b/widget/windows/nsClipboard.cpp
@@ -26,7 +26,6 @@
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsPrimitiveHelpers.h"
-#include "nsImageClipboard.h"
#include "nsIWidget.h"
#include "nsIComponentManager.h"
#include "nsWidgetsCID.h"
@@ -36,6 +35,8 @@
#include "nsIOutputStream.h"
#include "nsEscape.h"
#include "nsIObserverService.h"
+#include "nsMimeTypes.h"
+#include "imgITools.h"
using mozilla::LogLevel;
@@ -474,17 +475,45 @@ nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject * aDataObject, UINT
if (aMIMEImageFormat)
{
uint32_t allocLen = 0;
- unsigned char * clipboardData;
+ const char * clipboardData;
if (NS_SUCCEEDED(GetGlobalData(stm.hGlobal, (void **)&clipboardData, &allocLen)))
{
- nsImageFromClipboard converter;
- nsIInputStream * inputStream;
- converter.GetEncodedImageStream(clipboardData, aMIMEImageFormat, &inputStream); // addrefs for us, don't release
- if ( inputStream ) {
- *aData = inputStream;
- *aLen = sizeof(nsIInputStream*);
- result = NS_OK;
+ nsCOMPtr<imgIContainer> container;
+ nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
+ nsCOMPtr<nsIInputStream> inputStream;
+ nsresult rv = NS_NewByteInputStream(getter_AddRefs(inputStream),
+ clipboardData,
+ allocLen,
+ NS_ASSIGNMENT_DEPEND);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ result = imgTools->DecodeImage(inputStream,
+ NS_LITERAL_CSTRING(IMAGE_BMP_MS_CLIPBOARD),
+ getter_AddRefs(container));
+ if (NS_FAILED(result)) {
+ break;
}
+
+ nsAutoCString mimeType;
+ if (strcmp(aMIMEImageFormat, kJPGImageMime) == 0) {
+ mimeType.Assign(IMAGE_JPEG);
+ } else {
+ mimeType.Assign(aMIMEImageFormat);
+ }
+
+ result = imgTools->EncodeImage(container, mimeType, EmptyString(),
+ getter_AddRefs(inputStream));
+ if (NS_FAILED(result)) {
+ break;
+ }
+
+ if (!inputStream) {
+ result = NS_ERROR_FAILURE;
+ break;
+ }
+
+ *aData = inputStream.forget().take();
+ *aLen = sizeof(nsIInputStream*);
}
} break;