Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/tab_contents/web_drop_target_win.cc

Issue 1132003: Hook up HTML5 effectAllowed and dragEffect on Windows. (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include <windows.h> 5 #include <windows.h>
6 #include <shlobj.h> 6 #include <shlobj.h>
7 7
8 #include "chrome/browser/tab_contents/web_drop_target_win.h" 8 #include "chrome/browser/tab_contents/web_drop_target_win.h"
9 9
10 #include "app/clipboard/clipboard_util_win.h" 10 #include "app/clipboard/clipboard_util_win.h"
11 #include "app/os_exchange_data.h" 11 #include "app/os_exchange_data.h"
12 #include "app/os_exchange_data_provider_win.h" 12 #include "app/os_exchange_data_provider_win.h"
13 #include "chrome/browser/bookmarks/bookmark_drag_data.h" 13 #include "chrome/browser/bookmarks/bookmark_drag_data.h"
14 #include "chrome/browser/renderer_host/render_view_host.h" 14 #include "chrome/browser/renderer_host/render_view_host.h"
15 #include "chrome/browser/tab_contents/tab_contents.h" 15 #include "chrome/browser/tab_contents/tab_contents.h"
16 #include "gfx/point.h" 16 #include "gfx/point.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "webkit/glue/webdropdata.h" 19 #include "webkit/glue/webdropdata.h"
20 #include "webkit/glue/window_open_disposition.h" 20 #include "webkit/glue/window_open_disposition.h"
21 21
22 using WebKit::WebDragOperationsMask;
23 using WebKit::WebDragOperationNone;
22 using WebKit::WebDragOperationCopy; 24 using WebKit::WebDragOperationCopy;
25 using WebKit::WebDragOperationLink;
23 using WebKit::WebDragOperationMove; 26 using WebKit::WebDragOperationMove;
24 using WebKit::WebDragOperationsMask;
25 27
26 namespace { 28 namespace {
27 29
28 // A helper method for getting the preferred drop effect. 30 // A helper method for getting the preferred drop effect.
29 DWORD GetPreferredDropEffect(DWORD effect) { 31 DWORD GetPreferredDropEffect(DWORD effect) {
30 if (effect & DROPEFFECT_COPY) 32 if (effect & DROPEFFECT_COPY)
31 return DROPEFFECT_COPY; 33 return DROPEFFECT_COPY;
32 if (effect & DROPEFFECT_LINK) 34 if (effect & DROPEFFECT_LINK)
33 return DROPEFFECT_LINK; 35 return DROPEFFECT_LINK;
34 if (effect & DROPEFFECT_MOVE) 36 if (effect & DROPEFFECT_MOVE)
35 return DROPEFFECT_MOVE; 37 return DROPEFFECT_MOVE;
36 return DROPEFFECT_NONE; 38 return DROPEFFECT_NONE;
37 } 39 }
38 40
41 DWORD GetPreferredDragCursor(WebDragOperationsMask op) {
42 if (op & WebDragOperationCopy)
43 return DROPEFFECT_COPY;
44 if (op & WebDragOperationLink)
45 return DROPEFFECT_LINK;
46 if (op & WebDragOperationMove)
47 return DROPEFFECT_MOVE;
48 return DROPEFFECT_NONE;
49 }
50
51 WebDragOperationsMask WinDragOpToWebDragOp(DWORD effect) {
52 WebDragOperationsMask op = WebDragOperationNone;
53 if (effect & DROPEFFECT_COPY)
54 op = static_cast<WebDragOperationsMask>(op | WebDragOperationCopy);
55 if (effect & DROPEFFECT_LINK)
56 op = static_cast<WebDragOperationsMask>(op | WebDragOperationLink);
57 if (effect & DROPEFFECT_MOVE)
58 op = static_cast<WebDragOperationsMask>(op | WebDragOperationMove);
59 return op;
60 }
61
39 } // anonymous namespace 62 } // anonymous namespace
40 63
41 // InterstitialDropTarget is like a BaseDropTarget implementation that 64 // InterstitialDropTarget is like a BaseDropTarget implementation that
42 // WebDropTarget passes through to if an interstitial is showing. Rather than 65 // WebDropTarget passes through to if an interstitial is showing. Rather than
43 // passing messages on to the renderer, we just check to see if there's a link 66 // passing messages on to the renderer, we just check to see if there's a link
44 // in the drop data and handle links as navigations. 67 // in the drop data and handle links as navigations.
45 class InterstitialDropTarget { 68 class InterstitialDropTarget {
46 public: 69 public:
47 explicit InterstitialDropTarget(TabContents* tab_contents) 70 explicit InterstitialDropTarget(TabContents* tab_contents)
48 : tab_contents_(tab_contents) {} 71 : tab_contents_(tab_contents) {}
(...skipping 29 matching lines...) Expand all
78 DISALLOW_EVIL_CONSTRUCTORS(InterstitialDropTarget); 101 DISALLOW_EVIL_CONSTRUCTORS(InterstitialDropTarget);
79 }; 102 };
80 103
81 /////////////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////////////
82 // WebDropTarget, public: 105 // WebDropTarget, public:
83 106
84 WebDropTarget::WebDropTarget(HWND source_hwnd, TabContents* tab_contents) 107 WebDropTarget::WebDropTarget(HWND source_hwnd, TabContents* tab_contents)
85 : BaseDropTarget(source_hwnd), 108 : BaseDropTarget(source_hwnd),
86 tab_contents_(tab_contents), 109 tab_contents_(tab_contents),
87 current_rvh_(NULL), 110 current_rvh_(NULL),
88 is_drop_target_(false), 111 drag_cursor_(WebDragOperationNone),
89 interstitial_drop_target_(new InterstitialDropTarget(tab_contents)) { 112 interstitial_drop_target_(new InterstitialDropTarget(tab_contents)) {
90 } 113 }
91 114
92 WebDropTarget::~WebDropTarget() { 115 WebDropTarget::~WebDropTarget() {
93 } 116 }
94 117
95 DWORD WebDropTarget::OnDragEnter(IDataObject* data_object, 118 DWORD WebDropTarget::OnDragEnter(IDataObject* data_object,
96 DWORD key_state, 119 DWORD key_state,
97 POINT cursor_position, 120 POINT cursor_position,
98 DWORD effect) { 121 DWORD effect) {
99 current_rvh_ = tab_contents_->render_view_host(); 122 current_rvh_ = tab_contents_->render_view_host();
100 123
101 // Don't pass messages to the renderer if an interstitial page is showing 124 // Don't pass messages to the renderer if an interstitial page is showing
102 // because we don't want the interstitial page to navigate. Instead, 125 // because we don't want the interstitial page to navigate. Instead,
103 // pass the messages on to a separate interstitial DropTarget handler. 126 // pass the messages on to a separate interstitial DropTarget handler.
104 if (tab_contents_->showing_interstitial_page()) 127 if (tab_contents_->showing_interstitial_page())
105 return interstitial_drop_target_->OnDragEnter(data_object, effect); 128 return interstitial_drop_target_->OnDragEnter(data_object, effect);
106 129
107 // TODO(tc): PopulateWebDropData can be slow depending on what is in the 130 // TODO(tc): PopulateWebDropData can be slow depending on what is in the
108 // IDataObject. Maybe we can do this in a background thread. 131 // IDataObject. Maybe we can do this in a background thread.
109 WebDropData drop_data(GetDragIdentity()); 132 WebDropData drop_data(GetDragIdentity());
110 WebDropData::PopulateWebDropData(data_object, &drop_data); 133 WebDropData::PopulateWebDropData(data_object, &drop_data);
111 134
112 if (drop_data.url.is_empty()) 135 if (drop_data.url.is_empty())
113 OSExchangeDataProviderWin::GetPlainTextURL(data_object, &drop_data.url); 136 OSExchangeDataProviderWin::GetPlainTextURL(data_object, &drop_data.url);
114 137
115 is_drop_target_ = true; 138 drag_cursor_ = WebDragOperationNone;
116 139
117 POINT client_pt = cursor_position; 140 POINT client_pt = cursor_position;
118 ScreenToClient(GetHWND(), &client_pt); 141 ScreenToClient(GetHWND(), &client_pt);
119 tab_contents_->render_view_host()->DragTargetDragEnter(drop_data, 142 tab_contents_->render_view_host()->DragTargetDragEnter(drop_data,
120 gfx::Point(client_pt.x, client_pt.y), 143 gfx::Point(client_pt.x, client_pt.y),
121 gfx::Point(cursor_position.x, cursor_position.y), 144 gfx::Point(cursor_position.x, cursor_position.y),
122 static_cast<WebDragOperationsMask>(WebDragOperationCopy | 145 WinDragOpToWebDragOp(effect));
123 WebDragOperationMove));
124 // FIXME(snej): Send actual operation
125 146
126 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with 147 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with
127 // support for (at the moment experimental) drag and drop extensions. 148 // support for (at the moment experimental) drag and drop extensions.
128 if (tab_contents_->GetBookmarkDragDelegate()) { 149 if (tab_contents_->GetBookmarkDragDelegate()) {
129 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); 150 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object));
130 BookmarkDragData bookmark_drag_data; 151 BookmarkDragData bookmark_drag_data;
131 if (bookmark_drag_data.Read(os_exchange_data)) 152 if (bookmark_drag_data.Read(os_exchange_data))
132 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(bookmark_drag_data); 153 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(bookmark_drag_data);
133 } 154 }
134 155
(...skipping 11 matching lines...) Expand all
146 OnDragEnter(data_object, key_state, cursor_position, effect); 167 OnDragEnter(data_object, key_state, cursor_position, effect);
147 168
148 if (tab_contents_->showing_interstitial_page()) 169 if (tab_contents_->showing_interstitial_page())
149 return interstitial_drop_target_->OnDragOver(data_object, effect); 170 return interstitial_drop_target_->OnDragOver(data_object, effect);
150 171
151 POINT client_pt = cursor_position; 172 POINT client_pt = cursor_position;
152 ScreenToClient(GetHWND(), &client_pt); 173 ScreenToClient(GetHWND(), &client_pt);
153 tab_contents_->render_view_host()->DragTargetDragOver( 174 tab_contents_->render_view_host()->DragTargetDragOver(
154 gfx::Point(client_pt.x, client_pt.y), 175 gfx::Point(client_pt.x, client_pt.y),
155 gfx::Point(cursor_position.x, cursor_position.y), 176 gfx::Point(cursor_position.x, cursor_position.y),
156 static_cast<WebDragOperationsMask>(WebDragOperationCopy | 177 WinDragOpToWebDragOp(effect));
157 WebDragOperationMove));
158 // FIXME(snej): Send actual operation
159 178
160 if (tab_contents_->GetBookmarkDragDelegate()) { 179 if (tab_contents_->GetBookmarkDragDelegate()) {
161 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); 180 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object));
162 BookmarkDragData bookmark_drag_data; 181 BookmarkDragData bookmark_drag_data;
163 if (bookmark_drag_data.Read(os_exchange_data)) 182 if (bookmark_drag_data.Read(os_exchange_data))
164 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data); 183 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data);
165 } 184 }
166 185
167 if (!is_drop_target_) 186 return GetPreferredDragCursor(drag_cursor_);
168 return DROPEFFECT_NONE;
169
170 return GetPreferredDropEffect(effect);
171 } 187 }
172 188
173 void WebDropTarget::OnDragLeave(IDataObject* data_object) { 189 void WebDropTarget::OnDragLeave(IDataObject* data_object) {
174 DCHECK(current_rvh_); 190 DCHECK(current_rvh_);
175 if (current_rvh_ != tab_contents_->render_view_host()) 191 if (current_rvh_ != tab_contents_->render_view_host())
176 return; 192 return;
177 193
178 if (tab_contents_->showing_interstitial_page()) { 194 if (tab_contents_->showing_interstitial_page()) {
179 interstitial_drop_target_->OnDragLeave(data_object); 195 interstitial_drop_target_->OnDragLeave(data_object);
180 } else { 196 } else {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (bookmark_drag_data.Read(os_exchange_data)) 231 if (bookmark_drag_data.Read(os_exchange_data))
216 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data); 232 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data);
217 } 233 }
218 234
219 current_rvh_ = NULL; 235 current_rvh_ = NULL;
220 236
221 // We lie and always claim that the drop operation didn't happen because we 237 // We lie and always claim that the drop operation didn't happen because we
222 // don't want to wait for the renderer to respond. 238 // don't want to wait for the renderer to respond.
223 return DROPEFFECT_NONE; 239 return DROPEFFECT_NONE;
224 } 240 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/web_drop_target_win.h ('k') | chrome/browser/views/tab_contents/tab_contents_drag_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698