OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_DRAG_WIN_H_ | 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_DRAG_WIN_H_ |
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_DRAG_WIN_H_ | 6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_DRAG_WIN_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "third_party/WebKit/public/web/WebDragOperation.h" | 14 #include "third_party/WebKit/public/web/WebDragOperation.h" |
15 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 15 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
18 | 18 |
19 class SkBitmap; | 19 class SkBitmap; |
20 struct WebDropData; | |
21 | 20 |
22 namespace gfx { | 21 namespace gfx { |
23 class ImageSkia; | 22 class ImageSkia; |
24 } | 23 } |
25 | 24 |
26 namespace content { | 25 namespace content { |
27 class DragDropThread; | 26 class DragDropThread; |
28 class WebContents; | 27 class WebContents; |
29 class WebDragDest; | 28 class WebDragDest; |
30 class WebDragSource; | 29 class WebDragSource; |
| 30 struct DropData; |
31 | 31 |
32 // Windows-specific drag-and-drop handling in WebContentsView. | 32 // Windows-specific drag-and-drop handling in WebContentsView. |
33 // If we are dragging a virtual file out of the browser, we use a background | 33 // If we are dragging a virtual file out of the browser, we use a background |
34 // thread to do the drag-and-drop because we do not want to run nested | 34 // thread to do the drag-and-drop because we do not want to run nested |
35 // message loop in the UI thread. For all other cases, the drag-and-drop happens | 35 // message loop in the UI thread. For all other cases, the drag-and-drop happens |
36 // in the UI thread. | 36 // in the UI thread. |
37 class CONTENT_EXPORT WebContentsDragWin | 37 class CONTENT_EXPORT WebContentsDragWin |
38 : NON_EXPORTED_BASE(public ui::DataObjectImpl::Observer), | 38 : NON_EXPORTED_BASE(public ui::DataObjectImpl::Observer), |
39 public base::RefCountedThreadSafe<WebContentsDragWin> { | 39 public base::RefCountedThreadSafe<WebContentsDragWin> { |
40 public: | 40 public: |
41 WebContentsDragWin(gfx::NativeWindow source_window, | 41 WebContentsDragWin(gfx::NativeWindow source_window, |
42 WebContents* web_contents, | 42 WebContents* web_contents, |
43 WebDragDest* drag_dest, | 43 WebDragDest* drag_dest, |
44 const base::Callback<void()>& drag_end_callback); | 44 const base::Callback<void()>& drag_end_callback); |
45 virtual ~WebContentsDragWin(); | 45 virtual ~WebContentsDragWin(); |
46 | 46 |
47 // Called on UI thread. | 47 // Called on UI thread. |
48 void StartDragging(const WebDropData& drop_data, | 48 void StartDragging(const DropData& drop_data, |
49 WebKit::WebDragOperationsMask ops, | 49 WebKit::WebDragOperationsMask ops, |
50 const gfx::ImageSkia& image, | 50 const gfx::ImageSkia& image, |
51 const gfx::Vector2d& image_offset); | 51 const gfx::Vector2d& image_offset); |
52 void CancelDrag(); | 52 void CancelDrag(); |
53 | 53 |
54 // DataObjectImpl::Observer implementation. | 54 // DataObjectImpl::Observer implementation. |
55 // Called on drag-and-drop thread. | 55 // Called on drag-and-drop thread. |
56 virtual void OnWaitForData(); | 56 virtual void OnWaitForData(); |
57 virtual void OnDataObjectDisposed(); | 57 virtual void OnDataObjectDisposed(); |
58 | 58 |
59 // Don't invoke OLE DoDragDrop during tests. | 59 // Don't invoke OLE DoDragDrop during tests. |
60 static void DisableDragDropForTesting(); | 60 static void DisableDragDropForTesting(); |
61 | 61 |
62 private: | 62 private: |
63 // Called on either UI thread or drag-and-drop thread. | 63 // Called on either UI thread or drag-and-drop thread. |
64 void PrepareDragForDownload(const WebDropData& drop_data, | 64 void PrepareDragForDownload(const DropData& drop_data, |
65 ui::OSExchangeData* data, | 65 ui::OSExchangeData* data, |
66 const GURL& page_url, | 66 const GURL& page_url, |
67 const std::string& page_encoding); | 67 const std::string& page_encoding); |
68 void PrepareDragForFileContents(const WebDropData& drop_data, | 68 void PrepareDragForFileContents(const DropData& drop_data, |
69 ui::OSExchangeData* data); | 69 ui::OSExchangeData* data); |
70 void PrepareDragForUrl(const WebDropData& drop_data, | 70 void PrepareDragForUrl(const DropData& drop_data, |
71 ui::OSExchangeData* data); | 71 ui::OSExchangeData* data); |
72 // Returns false if the source window becomes invalid when the drag ends. | 72 // Returns false if the source window becomes invalid when the drag ends. |
73 // This could happen when the window gets destroyed when the drag is still in | 73 // This could happen when the window gets destroyed when the drag is still in |
74 // progress. No further processing should be done beyond this return point | 74 // progress. No further processing should be done beyond this return point |
75 // because the instance has been destroyed. | 75 // because the instance has been destroyed. |
76 bool DoDragging(const WebDropData& drop_data, | 76 bool DoDragging(const DropData& drop_data, |
77 WebKit::WebDragOperationsMask ops, | 77 WebKit::WebDragOperationsMask ops, |
78 const GURL& page_url, | 78 const GURL& page_url, |
79 const std::string& page_encoding, | 79 const std::string& page_encoding, |
80 const gfx::ImageSkia& image, | 80 const gfx::ImageSkia& image, |
81 const gfx::Vector2d& image_offset); | 81 const gfx::Vector2d& image_offset); |
82 | 82 |
83 // Called on drag-and-drop thread. | 83 // Called on drag-and-drop thread. |
84 void StartBackgroundDragging(const WebDropData& drop_data, | 84 void StartBackgroundDragging(const DropData& drop_data, |
85 WebKit::WebDragOperationsMask ops, | 85 WebKit::WebDragOperationsMask ops, |
86 const GURL& page_url, | 86 const GURL& page_url, |
87 const std::string& page_encoding, | 87 const std::string& page_encoding, |
88 const gfx::ImageSkia& image, | 88 const gfx::ImageSkia& image, |
89 const gfx::Vector2d& image_offset); | 89 const gfx::Vector2d& image_offset); |
90 // Called on UI thread. | 90 // Called on UI thread. |
91 void EndDragging(); | 91 void EndDragging(); |
92 void CloseThread(); | 92 void CloseThread(); |
93 | 93 |
94 // For debug check only. Access only on drag-and-drop thread. | 94 // For debug check only. Access only on drag-and-drop thread. |
(...skipping 18 matching lines...) Expand all Loading... |
113 bool drag_ended_; | 113 bool drag_ended_; |
114 | 114 |
115 base::Callback<void()> drag_end_callback_; | 115 base::Callback<void()> drag_end_callback_; |
116 | 116 |
117 DISALLOW_COPY_AND_ASSIGN(WebContentsDragWin); | 117 DISALLOW_COPY_AND_ASSIGN(WebContentsDragWin); |
118 }; | 118 }; |
119 | 119 |
120 } // namespace content | 120 } // namespace content |
121 | 121 |
122 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_DRAG_WIN_H_ | 122 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_DRAG_WIN_H_ |
OLD | NEW |