1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/base_drop_target.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_BASE_DROP_TARGET_H_ 1.9 +#define BASE_BASE_DROP_TARGET_H_ 1.10 + 1.11 +#include <objidl.h> 1.12 + 1.13 +#include "base/ref_counted.h" 1.14 + 1.15 +struct IDropTargetHelper; 1.16 + 1.17 +// A DropTarget implementation that takes care of the nitty gritty 1.18 +// of dnd. While this class is concrete, subclasses will most likely 1.19 +// want to override various OnXXX methods. 1.20 +// 1.21 +// Because BaseDropTarget is ref counted you shouldn't delete it directly, 1.22 +// rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd) 1.23 +// before the HWND is deleted too. 1.24 +// 1.25 +// This class is meant to be used in a STA and is not multithread-safe. 1.26 +class BaseDropTarget : public IDropTarget { 1.27 + public: 1.28 + // Create a new BaseDropTarget associating it with the given HWND. 1.29 + explicit BaseDropTarget(HWND hwnd); 1.30 + virtual ~BaseDropTarget(); 1.31 + 1.32 + // When suspend is set to |true|, the drop target does not receive drops from 1.33 + // drags initiated within the owning HWND. 1.34 + // TODO(beng): (http://b/1085385) figure out how we will handle legitimate 1.35 + // drag-drop operations within the same HWND, such as dragging 1.36 + // selected text to an edit field. 1.37 + void set_suspend(bool suspend) { suspend_ = suspend; } 1.38 + 1.39 + // IDropTarget implementation: 1.40 + HRESULT __stdcall DragEnter(IDataObject* data_object, 1.41 + DWORD key_state, 1.42 + POINTL cursor_position, 1.43 + DWORD* effect); 1.44 + HRESULT __stdcall DragOver(DWORD key_state, 1.45 + POINTL cursor_position, 1.46 + DWORD* effect); 1.47 + HRESULT __stdcall DragLeave(); 1.48 + HRESULT __stdcall Drop(IDataObject* data_object, 1.49 + DWORD key_state, 1.50 + POINTL cursor_position, 1.51 + DWORD* effect); 1.52 + 1.53 + // IUnknown implementation: 1.54 + HRESULT __stdcall QueryInterface(const IID& iid, void** object); 1.55 + ULONG __stdcall AddRef(); 1.56 + ULONG __stdcall Release(); 1.57 + 1.58 + protected: 1.59 + // Returns the hosting HWND. 1.60 + HWND GetHWND() { return hwnd_; } 1.61 + 1.62 + // Invoked when the cursor first moves over the hwnd during a dnd session. 1.63 + // This should return a bitmask of the supported drop operations: 1.64 + // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or 1.65 + // DROPEFFECT_MOVE. 1.66 + virtual DWORD OnDragEnter(IDataObject* data_object, 1.67 + DWORD key_state, 1.68 + POINT cursor_position, 1.69 + DWORD effect); 1.70 + 1.71 + // Invoked when the cursor moves over the window during a dnd session. 1.72 + // This should return a bitmask of the supported drop operations: 1.73 + // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or 1.74 + // DROPEFFECT_MOVE. 1.75 + virtual DWORD OnDragOver(IDataObject* data_object, 1.76 + DWORD key_state, 1.77 + POINT cursor_position, 1.78 + DWORD effect); 1.79 + 1.80 + // Invoked when the cursor moves outside the bounds of the hwnd during a 1.81 + // dnd session. 1.82 + virtual void OnDragLeave(IDataObject* data_object); 1.83 + 1.84 + // Invoked when the drop ends on the window. This should return the operation 1.85 + // that was taken. 1.86 + virtual DWORD OnDrop(IDataObject* data_object, 1.87 + DWORD key_state, 1.88 + POINT cursor_position, 1.89 + DWORD effect); 1.90 + 1.91 + // Return the drag identity. 1.92 + static int32_t GetDragIdentity() { return drag_identity_; } 1.93 + 1.94 + private: 1.95 + // Returns the cached drop helper, creating one if necessary. The returned 1.96 + // object is not addrefed. May return NULL if the object couldn't be created. 1.97 + static IDropTargetHelper* DropHelper(); 1.98 + 1.99 + // The data object currently being dragged over this drop target. 1.100 + scoped_refptr<IDataObject> current_data_object_; 1.101 + 1.102 + // A helper object that is used to provide drag image support while the mouse 1.103 + // is dragging over the content area. 1.104 + // 1.105 + // DO NOT ACCESS DIRECTLY! Use DropHelper() instead, which will lazily create 1.106 + // this if it doesn't exist yet. This object can take tens of milliseconds to 1.107 + // create, and we don't want to block any window opening for this, especially 1.108 + // since often, DnD will never be used. Instead, we force this penalty to the 1.109 + // first time it is actually used. 1.110 + static IDropTargetHelper* cached_drop_target_helper_; 1.111 + 1.112 + // The drag identity (id). An up-counter that increases when the cursor first 1.113 + // moves over the HWND in a DnD session (OnDragEnter). 0 is reserved to mean 1.114 + // the "no/unknown" identity, and is used for initialization. The identity is 1.115 + // sent to the renderer in drag enter notifications. Note: the identity value 1.116 + // is passed over the renderer NPAPI interface to gears, so use int32_t instead 1.117 + // of int here. 1.118 + static int32_t drag_identity_; 1.119 + 1.120 + // The HWND of the source. This HWND is used to determine coordinates for 1.121 + // mouse events that are sent to the renderer notifying various drag states. 1.122 + HWND hwnd_; 1.123 + 1.124 + // Whether or not we are currently processing drag notifications for drags 1.125 + // initiated in this window. 1.126 + bool suspend_; 1.127 + 1.128 + LONG ref_count_; 1.129 + 1.130 + DISALLOW_EVIL_CONSTRUCTORS(BaseDropTarget); 1.131 +}; 1.132 + 1.133 +#endif // BASE_BASE_DROP_TARGET_H_