OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_ | |
7 #pragma once | |
8 | |
9 #include "base/callback.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/threading/platform_thread.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | |
14 #include "third_party/skia/include/core/SkBitmap.h" | |
15 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | |
16 #include "ui/gfx/native_widget_types.h" | |
17 #include "ui/gfx/point.h" | |
18 | |
19 class DragDropThread; | |
20 class WebDragDest; | |
21 class WebDragSource; | |
22 struct WebDropData; | |
23 | |
24 namespace content { | |
25 class WebContents; | |
26 } | |
27 | |
28 // Windows-specific drag-and-drop handling in WebContentsView. | |
29 // If we are dragging a virtual file out of the browser, we use a background | |
30 // thread to do the drag-and-drop because we do not want to run nested | |
31 // message loop in the UI thread. For all other cases, the drag-and-drop happens | |
32 // in the UI thread. | |
33 class TabContentsDragWin | |
34 : public ui::DataObjectImpl::Observer, | |
35 public base::RefCountedThreadSafe<TabContentsDragWin> { | |
36 public: | |
37 TabContentsDragWin(gfx::NativeWindow source_window, | |
38 content::WebContents* web_contents, | |
39 WebDragDest* drag_dest, | |
40 const base::Callback<void()>& drag_end_callback); | |
41 virtual ~TabContentsDragWin(); | |
42 | |
43 // Called on UI thread. | |
44 void StartDragging(const WebDropData& drop_data, | |
45 WebKit::WebDragOperationsMask ops, | |
46 const SkBitmap& image, | |
47 const gfx::Point& image_offset); | |
48 void CancelDrag(); | |
49 | |
50 // DataObjectImpl::Observer implementation. | |
51 // Called on drag-and-drop thread. | |
52 virtual void OnWaitForData(); | |
53 virtual void OnDataObjectDisposed(); | |
54 | |
55 private: | |
56 // Called on either UI thread or drag-and-drop thread. | |
57 void PrepareDragForDownload(const WebDropData& drop_data, | |
58 ui::OSExchangeData* data, | |
59 const GURL& page_url, | |
60 const std::string& page_encoding); | |
61 void PrepareDragForFileContents(const WebDropData& drop_data, | |
62 ui::OSExchangeData* data); | |
63 void PrepareDragForUrl(const WebDropData& drop_data, | |
64 ui::OSExchangeData* data); | |
65 void DoDragging(const WebDropData& drop_data, | |
66 WebKit::WebDragOperationsMask ops, | |
67 const GURL& page_url, | |
68 const std::string& page_encoding, | |
69 const SkBitmap& image, | |
70 const gfx::Point& image_offset); | |
71 | |
72 // Called on drag-and-drop thread. | |
73 void StartBackgroundDragging(const WebDropData& drop_data, | |
74 WebKit::WebDragOperationsMask ops, | |
75 const GURL& page_url, | |
76 const std::string& page_encoding, | |
77 const SkBitmap& image, | |
78 const gfx::Point& image_offset); | |
79 // Called on UI thread. | |
80 void EndDragging(bool restore_suspended_state); | |
81 void CloseThread(); | |
82 | |
83 // For debug check only. Access only on drag-and-drop thread. | |
84 base::PlatformThreadId drag_drop_thread_id_; | |
85 | |
86 // All the member variables below are accessed on UI thread. | |
87 | |
88 gfx::NativeWindow source_window_; | |
89 content::WebContents* web_contents_; | |
90 WebDragDest* drag_dest_; | |
91 | |
92 // |drag_source_| is our callback interface passed to the system when we | |
93 // want to initiate a drag and drop operation. We use it to tell if a | |
94 // drag operation is happening. | |
95 scoped_refptr<WebDragSource> drag_source_; | |
96 | |
97 // The thread used by the drag-out download. This is because we want to avoid | |
98 // running nested message loop in main UI thread. | |
99 scoped_ptr<DragDropThread> drag_drop_thread_; | |
100 | |
101 // The flag to guard that EndDragging is not called twice. | |
102 bool drag_ended_; | |
103 | |
104 // Keep track of the old suspended state of the drop target. | |
105 bool old_drop_target_suspended_state_; | |
106 | |
107 base::Callback<void()> drag_end_callback_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(TabContentsDragWin); | |
110 }; | |
111 | |
112 | |
113 #endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_ | |
OLD | NEW |