mirror of
https://github.com/zen-browser/desktop.git
synced 2026-09-24 21:26:26 +00:00
157 lines
6.5 KiB
C++
157 lines
6.5 KiB
C++
diff --git a/widget/cocoa/nsDragService.mm b/widget/cocoa/nsDragService.mm
|
|
index 340a9ad81c5cb23bb7e5f927d11d5cffdde7ce70..ba597ba4373ba3ace7455ce0859f2339349ffc06 100644
|
|
--- a/widget/cocoa/nsDragService.mm
|
|
+++ b/widget/cocoa/nsDragService.mm
|
|
@@ -10,6 +10,7 @@
|
|
#include "mozilla/dom/Document.h"
|
|
#include "mozilla/dom/DocumentInlines.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
+#include "mozilla/nsZenDragAndDrop.h"
|
|
#include "nsArrayUtils.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsClipboard.h"
|
|
@@ -145,6 +146,10 @@
|
|
bitsPerPixel:32];
|
|
|
|
uint8_t* dest = [imageRep bitmapData];
|
|
+ auto drag_translucency = DRAG_TRANSLUCENCY;
|
|
+ if (auto zenDragAndDrop = zen::nsZenDragAndDrop::GetZenDragAndDropInstance()) {
|
|
+ drag_translucency = zenDragAndDrop->GetDragImageOpacity();
|
|
+ }
|
|
for (uint32_t i = 0; i < height; ++i) {
|
|
uint8_t* src = map.mData + i * map.mStride;
|
|
for (uint32_t j = 0; j < width; ++j) {
|
|
@@ -152,15 +157,15 @@
|
|
// is premultipled here. Also, Quartz likes RGBA, so do that translation
|
|
// as well.
|
|
#ifdef IS_BIG_ENDIAN
|
|
- dest[0] = uint8_t(src[1] * DRAG_TRANSLUCENCY);
|
|
- dest[1] = uint8_t(src[2] * DRAG_TRANSLUCENCY);
|
|
- dest[2] = uint8_t(src[3] * DRAG_TRANSLUCENCY);
|
|
- dest[3] = uint8_t(src[0] * DRAG_TRANSLUCENCY);
|
|
+ dest[0] = uint8_t(src[1] * drag_translucency);
|
|
+ dest[1] = uint8_t(src[2] * drag_translucency);
|
|
+ dest[2] = uint8_t(src[3] * drag_translucency);
|
|
+ dest[3] = uint8_t(src[0] * drag_translucency);
|
|
#else
|
|
- dest[0] = uint8_t(src[2] * DRAG_TRANSLUCENCY);
|
|
- dest[1] = uint8_t(src[1] * DRAG_TRANSLUCENCY);
|
|
- dest[2] = uint8_t(src[0] * DRAG_TRANSLUCENCY);
|
|
- dest[3] = uint8_t(src[3] * DRAG_TRANSLUCENCY);
|
|
+ dest[0] = uint8_t(src[2] * drag_translucency);
|
|
+ dest[1] = uint8_t(src[1] * drag_translucency);
|
|
+ dest[2] = uint8_t(src[0] * drag_translucency);
|
|
+ dest[3] = uint8_t(src[3] * drag_translucency);
|
|
#endif
|
|
src += 4;
|
|
dest += 4;
|
|
@@ -249,12 +254,44 @@
|
|
[[[NSDraggingItem alloc] initWithPasteboardWriter:pbItem] autorelease];
|
|
[dragItem setDraggingFrame:localDragRect contents:image];
|
|
|
|
+ NSMutableArray* dragItems = [NSMutableArray arrayWithObject:dragItem];
|
|
+ auto zenDragAndDrop = zen::nsZenDragAndDrop::GetZenDragAndDropInstance();
|
|
+ const nsTArray<nsCOMPtr<nsINode>> noExtraImages;
|
|
+ @try {
|
|
+ for (const auto& extraImageNode :
|
|
+ zenDragAndDrop ? zenDragAndDrop->DragImages() : noExtraImages) {
|
|
+ nsCOMPtr<nsINode> mainImage = std::move(mImage);
|
|
+ mImage = extraImageNode;
|
|
+ NSPoint extraPoint;
|
|
+ NSImage* extraImage = ConstructDragImage(mSourceNode, aRegion, &extraPoint);
|
|
+ mImage = std::move(mainImage);
|
|
+ if (!extraImage) {
|
|
+ continue;
|
|
+ }
|
|
+ NSRect extraRect = extraImage.alignmentRect;
|
|
+ extraRect.origin.x = extraPoint.x;
|
|
+ extraRect.origin.y = extraPoint.y - extraRect.size.height;
|
|
+ NSPasteboardItem* extraPbItem = [[NSPasteboardItem new] autorelease];
|
|
+ [extraPbItem setData:[NSData data]
|
|
+ forType:[UTIHelper stringFromPboardType:kMozWildcardPboardType]];
|
|
+ NSDraggingItem* extraItem = [[[NSDraggingItem alloc]
|
|
+ initWithPasteboardWriter:extraPbItem] autorelease];
|
|
+ [extraItem setDraggingFrame:extraRect contents:extraImage];
|
|
+ [dragItems addObject:extraItem];
|
|
+ }
|
|
+ } @catch (NSException* e) {
|
|
+ dragItems = [NSMutableArray arrayWithObject:dragItem];
|
|
+ }
|
|
+
|
|
OpenDragPopup();
|
|
|
|
mNSDraggingSession = [mNativeDragView
|
|
- beginDraggingSessionWithItems:[NSArray arrayWithObject:dragItem]
|
|
+ beginDraggingSessionWithItems:dragItems
|
|
event:mNativeDragEvent
|
|
source:mNativeDragView];
|
|
+ if (dragItems.count > 1) {
|
|
+ mNSDraggingSession.draggingFormation = NSDraggingFormationStack;
|
|
+ }
|
|
|
|
mNSDraggingSession.animatesToStartingPositionsOnCancelOrFail =
|
|
!mDataTransfer || mDataTransfer->MozShowFailAnimation();
|
|
@@ -455,29 +492,44 @@
|
|
}
|
|
|
|
if (pc) {
|
|
+ nsPoint pt = LayoutDevicePixel::ToAppUnits(
|
|
+ devPoint, pc->DeviceContext()->AppUnitsPerDevPixel());
|
|
+ CSSIntPoint screenPoint =
|
|
+ CSSIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
|
+ nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
|
+
|
|
+ NSMutableArray* images = [NSMutableArray array];
|
|
+ NSMutableArray* rects = [NSMutableArray array];
|
|
+ auto render = [&]() {
|
|
+ LayoutDeviceIntRect newRect;
|
|
+ NSImage* image =
|
|
+ ConstructDragImage(mSourceNode, Nothing(), screenPoint, &newRect);
|
|
+ [images addObject:image ? (id)image : (id)[NSNull null]];
|
|
+ [rects addObject:[NSValue valueWithRect:
|
|
+ image ? nsCocoaUtils::GeckoRectToCocoaRectDevPix(
|
|
+ newRect, scaleFactor)
|
|
+ : NSZeroRect]];
|
|
+ };
|
|
+ render();
|
|
+ if (auto zenDragAndDrop = zen::nsZenDragAndDrop::GetZenDragAndDropInstance()) {
|
|
+ for (const auto& extraImageNode : zenDragAndDrop->DragImages()) {
|
|
+ nsCOMPtr<nsINode> mainImage = std::move(mImage);
|
|
+ mImage = extraImageNode;
|
|
+ render();
|
|
+ mImage = std::move(mainImage);
|
|
+ }
|
|
+ }
|
|
+
|
|
void (^changeImageBlock)(NSDraggingItem*, NSInteger, BOOL*) = ^(
|
|
NSDraggingItem* draggingItem, NSInteger idx, BOOL* stop) {
|
|
- // We never add more than one item right now, but check just in case.
|
|
- if (idx > 0) {
|
|
+ if ((NSUInteger)idx >= images.count || images[idx] == [NSNull null]) {
|
|
return;
|
|
}
|
|
-
|
|
- nsPoint pt = LayoutDevicePixel::ToAppUnits(
|
|
- devPoint, pc->DeviceContext()->AppUnitsPerDevPixel());
|
|
- CSSIntPoint screenPoint =
|
|
- CSSIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
|
- nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
|
-
|
|
- // Create a new image; if one isn't returned don't change the current
|
|
- // one.
|
|
- LayoutDeviceIntRect newRect;
|
|
- NSImage* image =
|
|
- ConstructDragImage(mSourceNode, Nothing(), screenPoint, &newRect);
|
|
- if (image) {
|
|
- NSRect draggingRect =
|
|
- nsCocoaUtils::GeckoRectToCocoaRectDevPix(newRect, scaleFactor);
|
|
- [draggingItem setDraggingFrame:draggingRect contents:image];
|
|
+ NSRect frame = [rects[idx] rectValue];
|
|
+ if (idx > 0) {
|
|
+ frame.origin = draggingItem.draggingFrame.origin;
|
|
}
|
|
+ [draggingItem setDraggingFrame:frame contents:images[idx]];
|
|
};
|
|
|
|
[mNSDraggingSession
|