1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_SOURCE_WIN_H_
6#define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_SOURCE_WIN_H_
7#pragma once
8
9#include "base/basictypes.h"
10#include "content/common/notification_observer.h"
11#include "content/common/notification_registrar.h"
12#include "ui/base/dragdrop/drag_source.h"
13#include "ui/gfx/native_widget_types.h"
14#include "ui/gfx/point.h"
15
16class RenderViewHost;
17class TabContents;
18
19// An IDropSource implementation for a TabContents. Handles notifications sent
20// by an active drag-drop operation as the user mouses over other drop targets
21// on their system. This object tells Windows whether or not the drag should
22// continue, and supplies the appropriate cursors.
23class WebDragSource : public ui::DragSource,
24                      public NotificationObserver {
25 public:
26  // Create a new DragSource for a given HWND and TabContents.
27  WebDragSource(gfx::NativeWindow source_wnd, TabContents* tab_contents);
28  virtual ~WebDragSource();
29
30  // NotificationObserver implementation.
31  virtual void Observe(NotificationType type,
32                       const NotificationSource& source,
33                       const NotificationDetails& details);
34
35  void set_effect(DWORD effect) { effect_ = effect; }
36
37 protected:
38  // ui::DragSource
39  virtual void OnDragSourceCancel();
40  virtual void OnDragSourceDrop();
41  virtual void OnDragSourceMove();
42
43 private:
44  // Cannot construct thusly.
45  WebDragSource();
46
47  // OnDragSourceDrop schedules its main work to be done after IDropTarget::Drop
48  // by posting a task to this function.
49  void DelayedOnDragSourceDrop();
50
51  // Keep a reference to the window so we can translate the cursor position.
52  gfx::NativeWindow source_wnd_;
53
54  // We use this as a channel to the renderer to tell it about various drag
55  // drop events that it needs to know about (such as when a drag operation it
56  // initiated terminates).
57  RenderViewHost* render_view_host_;
58
59  NotificationRegistrar registrar_;
60
61  DWORD effect_;
62
63  DISALLOW_COPY_AND_ASSIGN(WebDragSource);
64};
65
66#endif  // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_SOURCE_WIN_H_
67