1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef nsDragService_h_
7 #define nsDragService_h_
8 
9 #include "nsBaseDragService.h"
10 #include "nsChildView.h"
11 
12 #include <Cocoa/Cocoa.h>
13 
14 extern NSString* const kPublicUrlPboardType;
15 extern NSString* const kPublicUrlNamePboardType;
16 extern NSString* const kUrlsWithTitlesPboardType;
17 extern NSString* const kMozWildcardPboardType;
18 extern NSString* const kMozCustomTypesPboardType;
19 extern NSString* const kMozFileUrlsPboardType;
20 
21 class nsDragService : public nsBaseDragService {
22  public:
23   nsDragService();
24 
25   // nsBaseDragService
26   MOZ_CAN_RUN_SCRIPT virtual nsresult InvokeDragSessionImpl(
27       nsIArray* anArrayTransferables, const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
28       uint32_t aActionType) override;
29   // nsIDragService
30   MOZ_CAN_RUN_SCRIPT NS_IMETHOD EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) override;
31   NS_IMETHOD UpdateDragImage(nsINode* aImage, int32_t aImageX, int32_t aImageY) override;
32 
33   // nsIDragSession
34   NS_IMETHOD GetData(nsITransferable* aTransferable, uint32_t aItemIndex) override;
35   NS_IMETHOD IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) override;
36   NS_IMETHOD GetNumDropItems(uint32_t* aNumItems) override;
37 
38   void DragMovedWithView(NSDraggingSession* aSession, NSPoint aPoint);
39 
40  protected:
41   virtual ~nsDragService();
42 
43  private:
44   // Creates and returns the drag image for a drag. aImagePoint will be set to
45   // the origin of the drag relative to mNativeDragView.
46   NSImage* ConstructDragImage(nsINode* aDOMNode,
47                               const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
48                               NSPoint* aImagePoint);
49 
50   // Creates and returns the drag image for a drag. aPoint should be the origin
51   // of the drag, for example the mouse coordinate of the mousedown event.
52   // aDragRect will be set the area of the drag relative to this.
53   NSImage* ConstructDragImage(nsINode* aDOMNode,
54                               const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
55                               mozilla::CSSIntPoint aPoint, mozilla::LayoutDeviceIntRect* aDragRect);
56 
57   bool IsValidType(NSString* availableType, bool allowFileURL);
58   NSString* GetStringForType(NSPasteboardItem* item, const NSString* type,
59                              bool allowFileURL = false);
60   NSString* GetTitleForURL(NSPasteboardItem* item);
61   NSString* GetFilePath(NSPasteboardItem* item);
62 
63   nsCOMPtr<nsIArray> mDataItems;  // only valid for a drag started within gecko
64   ChildView* mNativeDragView;
65   NSEvent* mNativeDragEvent;
66 
67   bool mDragImageChanged;
68 };
69 
70 #endif  // nsDragService_h_
71