ipc/chromium/src/base/base_drop_target.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef BASE_BASE_DROP_TARGET_H_
michael@0 6 #define BASE_BASE_DROP_TARGET_H_
michael@0 7
michael@0 8 #include <objidl.h>
michael@0 9
michael@0 10 #include "base/ref_counted.h"
michael@0 11
michael@0 12 struct IDropTargetHelper;
michael@0 13
michael@0 14 // A DropTarget implementation that takes care of the nitty gritty
michael@0 15 // of dnd. While this class is concrete, subclasses will most likely
michael@0 16 // want to override various OnXXX methods.
michael@0 17 //
michael@0 18 // Because BaseDropTarget is ref counted you shouldn't delete it directly,
michael@0 19 // rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd)
michael@0 20 // before the HWND is deleted too.
michael@0 21 //
michael@0 22 // This class is meant to be used in a STA and is not multithread-safe.
michael@0 23 class BaseDropTarget : public IDropTarget {
michael@0 24 public:
michael@0 25 // Create a new BaseDropTarget associating it with the given HWND.
michael@0 26 explicit BaseDropTarget(HWND hwnd);
michael@0 27 virtual ~BaseDropTarget();
michael@0 28
michael@0 29 // When suspend is set to |true|, the drop target does not receive drops from
michael@0 30 // drags initiated within the owning HWND.
michael@0 31 // TODO(beng): (http://b/1085385) figure out how we will handle legitimate
michael@0 32 // drag-drop operations within the same HWND, such as dragging
michael@0 33 // selected text to an edit field.
michael@0 34 void set_suspend(bool suspend) { suspend_ = suspend; }
michael@0 35
michael@0 36 // IDropTarget implementation:
michael@0 37 HRESULT __stdcall DragEnter(IDataObject* data_object,
michael@0 38 DWORD key_state,
michael@0 39 POINTL cursor_position,
michael@0 40 DWORD* effect);
michael@0 41 HRESULT __stdcall DragOver(DWORD key_state,
michael@0 42 POINTL cursor_position,
michael@0 43 DWORD* effect);
michael@0 44 HRESULT __stdcall DragLeave();
michael@0 45 HRESULT __stdcall Drop(IDataObject* data_object,
michael@0 46 DWORD key_state,
michael@0 47 POINTL cursor_position,
michael@0 48 DWORD* effect);
michael@0 49
michael@0 50 // IUnknown implementation:
michael@0 51 HRESULT __stdcall QueryInterface(const IID& iid, void** object);
michael@0 52 ULONG __stdcall AddRef();
michael@0 53 ULONG __stdcall Release();
michael@0 54
michael@0 55 protected:
michael@0 56 // Returns the hosting HWND.
michael@0 57 HWND GetHWND() { return hwnd_; }
michael@0 58
michael@0 59 // Invoked when the cursor first moves over the hwnd during a dnd session.
michael@0 60 // This should return a bitmask of the supported drop operations:
michael@0 61 // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or
michael@0 62 // DROPEFFECT_MOVE.
michael@0 63 virtual DWORD OnDragEnter(IDataObject* data_object,
michael@0 64 DWORD key_state,
michael@0 65 POINT cursor_position,
michael@0 66 DWORD effect);
michael@0 67
michael@0 68 // Invoked when the cursor moves over the window during a dnd session.
michael@0 69 // This should return a bitmask of the supported drop operations:
michael@0 70 // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or
michael@0 71 // DROPEFFECT_MOVE.
michael@0 72 virtual DWORD OnDragOver(IDataObject* data_object,
michael@0 73 DWORD key_state,
michael@0 74 POINT cursor_position,
michael@0 75 DWORD effect);
michael@0 76
michael@0 77 // Invoked when the cursor moves outside the bounds of the hwnd during a
michael@0 78 // dnd session.
michael@0 79 virtual void OnDragLeave(IDataObject* data_object);
michael@0 80
michael@0 81 // Invoked when the drop ends on the window. This should return the operation
michael@0 82 // that was taken.
michael@0 83 virtual DWORD OnDrop(IDataObject* data_object,
michael@0 84 DWORD key_state,
michael@0 85 POINT cursor_position,
michael@0 86 DWORD effect);
michael@0 87
michael@0 88 // Return the drag identity.
michael@0 89 static int32_t GetDragIdentity() { return drag_identity_; }
michael@0 90
michael@0 91 private:
michael@0 92 // Returns the cached drop helper, creating one if necessary. The returned
michael@0 93 // object is not addrefed. May return NULL if the object couldn't be created.
michael@0 94 static IDropTargetHelper* DropHelper();
michael@0 95
michael@0 96 // The data object currently being dragged over this drop target.
michael@0 97 scoped_refptr<IDataObject> current_data_object_;
michael@0 98
michael@0 99 // A helper object that is used to provide drag image support while the mouse
michael@0 100 // is dragging over the content area.
michael@0 101 //
michael@0 102 // DO NOT ACCESS DIRECTLY! Use DropHelper() instead, which will lazily create
michael@0 103 // this if it doesn't exist yet. This object can take tens of milliseconds to
michael@0 104 // create, and we don't want to block any window opening for this, especially
michael@0 105 // since often, DnD will never be used. Instead, we force this penalty to the
michael@0 106 // first time it is actually used.
michael@0 107 static IDropTargetHelper* cached_drop_target_helper_;
michael@0 108
michael@0 109 // The drag identity (id). An up-counter that increases when the cursor first
michael@0 110 // moves over the HWND in a DnD session (OnDragEnter). 0 is reserved to mean
michael@0 111 // the "no/unknown" identity, and is used for initialization. The identity is
michael@0 112 // sent to the renderer in drag enter notifications. Note: the identity value
michael@0 113 // is passed over the renderer NPAPI interface to gears, so use int32_t instead
michael@0 114 // of int here.
michael@0 115 static int32_t drag_identity_;
michael@0 116
michael@0 117 // The HWND of the source. This HWND is used to determine coordinates for
michael@0 118 // mouse events that are sent to the renderer notifying various drag states.
michael@0 119 HWND hwnd_;
michael@0 120
michael@0 121 // Whether or not we are currently processing drag notifications for drags
michael@0 122 // initiated in this window.
michael@0 123 bool suspend_;
michael@0 124
michael@0 125 LONG ref_count_;
michael@0 126
michael@0 127 DISALLOW_EVIL_CONSTRUCTORS(BaseDropTarget);
michael@0 128 };
michael@0 129
michael@0 130 #endif // BASE_BASE_DROP_TARGET_H_

mercurial