• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DROP_TARGET_WIN_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_WEB_DROP_TARGET_WIN_H_
7 #pragma once
8 
9 #include "base/memory/scoped_ptr.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h"
11 #include "ui/base/dragdrop/drop_target.h"
12 
13 class InterstitialDropTarget;
14 class RenderViewHost;
15 class TabContents;
16 
17 // A helper object that provides drop capabilities to a TabContents. The
18 // DropTarget handles drags that enter the region of the TabContents by
19 // passing on the events to the renderer.
20 class WebDropTarget : public ui::DropTarget {
21  public:
22   // Create a new WebDropTarget associating it with the given HWND and
23   // TabContents.
24   WebDropTarget(HWND source_hwnd, TabContents* contents);
25   virtual ~WebDropTarget();
26 
set_drag_cursor(WebKit::WebDragOperation op)27   void set_drag_cursor(WebKit::WebDragOperation op) {
28     drag_cursor_ = op;
29   }
30 
31  protected:
32   virtual DWORD OnDragEnter(IDataObject* data_object,
33                             DWORD key_state,
34                             POINT cursor_position,
35                             DWORD effect);
36 
37   virtual DWORD OnDragOver(IDataObject* data_object,
38                            DWORD key_state,
39                            POINT cursor_position,
40                            DWORD effect);
41 
42   virtual void OnDragLeave(IDataObject* data_object);
43 
44   virtual DWORD OnDrop(IDataObject* data_object,
45                        DWORD key_state,
46                        POINT cursor_position,
47                        DWORD effect);
48 
49  private:
50   // Our associated TabContents.
51   TabContents* tab_contents_;
52 
53   // We keep track of the render view host we're dragging over.  If it changes
54   // during a drag, we need to re-send the DragEnter message.  WARNING:
55   // this pointer should never be dereferenced.  We only use it for comparing
56   // pointers.
57   RenderViewHost* current_rvh_;
58 
59   // Used to determine what cursor we should display when dragging over web
60   // content area.  This can be updated async during a drag operation.
61   WebKit::WebDragOperation drag_cursor_;
62 
63   // A special drop target handler for when we try to d&d while an interstitial
64   // page is showing.
65   scoped_ptr<InterstitialDropTarget> interstitial_drop_target_;
66 
67   DISALLOW_COPY_AND_ASSIGN(WebDropTarget);
68 };
69 
70 #endif  // CHROME_BROWSER_TAB_CONTENTS_WEB_DROP_TARGET_WIN_H_
71