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 #import "content/browser/web_contents/web_drag_dest_mac.h" | 5 #import "content/browser/web_contents/web_drag_dest_mac.h" |
6 | 6 |
| 7 #import <Carbon/Carbon.h> |
| 8 |
7 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/web_drag_dest_delegate.h" | 12 #include "content/public/browser/web_drag_dest_delegate.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
11 #import "third_party/mozilla/NSPasteboard+Utils.h" | 14 #import "third_party/mozilla/NSPasteboard+Utils.h" |
12 #include "ui/base/clipboard/custom_data_helper.h" | 15 #include "ui/base/clipboard/custom_data_helper.h" |
13 #import "ui/base/dragdrop/cocoa_dnd_util.h" | 16 #import "ui/base/dragdrop/cocoa_dnd_util.h" |
14 #include "webkit/glue/webdropdata.h" | 17 #include "webkit/glue/webdropdata.h" |
15 #include "webkit/glue/window_open_disposition.h" | 18 #include "webkit/glue/window_open_disposition.h" |
16 | 19 |
17 using WebKit::WebDragOperationsMask; | 20 using WebKit::WebDragOperationsMask; |
18 using content::OpenURLParams; | 21 using content::OpenURLParams; |
19 using content::Referrer; | 22 using content::Referrer; |
20 | 23 |
| 24 int GetModifierFlags() { |
| 25 int modifier_state = 0; |
| 26 UInt32 currentModifiers = GetCurrentKeyModifiers(); |
| 27 if (currentModifiers & ::shiftKey) |
| 28 modifier_state |= WebKit::WebInputEvent::ShiftKey; |
| 29 if (currentModifiers & ::controlKey) |
| 30 modifier_state |= WebKit::WebInputEvent::ControlKey; |
| 31 if (currentModifiers & ::optionKey) |
| 32 modifier_state |= WebKit::WebInputEvent::AltKey; |
| 33 if (currentModifiers & ::cmdKey) |
| 34 modifier_state |= WebKit::WebInputEvent::MetaKey; |
| 35 return modifier_state; |
| 36 } |
| 37 |
21 @implementation WebDragDest | 38 @implementation WebDragDest |
22 | 39 |
23 // |contents| is the WebContentsImpl representing this tab, used to communicate | 40 // |contents| is the WebContentsImpl representing this tab, used to communicate |
24 // drag&drop messages to WebCore and handle navigation on a successful drop | 41 // drag&drop messages to WebCore and handle navigation on a successful drop |
25 // (if necessary). | 42 // (if necessary). |
26 - (id)initWithWebContentsImpl:(WebContentsImpl*)contents { | 43 - (id)initWithWebContentsImpl:(WebContentsImpl*)contents { |
27 if ((self = [super init])) { | 44 if ((self = [super init])) { |
28 webContents_ = contents; | 45 webContents_ = contents; |
29 } | 46 } |
30 return self; | 47 return self; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // Create the appropriate mouse locations for WebCore. The draggingLocation | 121 // Create the appropriate mouse locations for WebCore. The draggingLocation |
105 // is in window coordinates. Both need to be flipped. | 122 // is in window coordinates. Both need to be flipped. |
106 NSPoint windowPoint = [info draggingLocation]; | 123 NSPoint windowPoint = [info draggingLocation]; |
107 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 124 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
108 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 125 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
109 NSDragOperation mask = [info draggingSourceOperationMask]; | 126 NSDragOperation mask = [info draggingSourceOperationMask]; |
110 webContents_->GetRenderViewHost()->DragTargetDragEnter( | 127 webContents_->GetRenderViewHost()->DragTargetDragEnter( |
111 *dropData_, | 128 *dropData_, |
112 gfx::Point(viewPoint.x, viewPoint.y), | 129 gfx::Point(viewPoint.x, viewPoint.y), |
113 gfx::Point(screenPoint.x, screenPoint.y), | 130 gfx::Point(screenPoint.x, screenPoint.y), |
114 static_cast<WebDragOperationsMask>(mask)); | 131 static_cast<WebDragOperationsMask>(mask), |
| 132 GetModifierFlags()); |
115 | 133 |
116 // We won't know the true operation (whether the drag is allowed) until we | 134 // We won't know the true operation (whether the drag is allowed) until we |
117 // hear back from the renderer. For now, be optimistic: | 135 // hear back from the renderer. For now, be optimistic: |
118 currentOperation_ = NSDragOperationCopy; | 136 currentOperation_ = NSDragOperationCopy; |
119 return currentOperation_; | 137 return currentOperation_; |
120 } | 138 } |
121 | 139 |
122 - (void)draggingExited:(id<NSDraggingInfo>)info { | 140 - (void)draggingExited:(id<NSDraggingInfo>)info { |
123 DCHECK(currentRVH_); | 141 DCHECK(currentRVH_); |
124 if (currentRVH_ != webContents_->GetRenderViewHost()) | 142 if (currentRVH_ != webContents_->GetRenderViewHost()) |
(...skipping 22 matching lines...) Expand all Loading... |
147 | 165 |
148 // Create the appropriate mouse locations for WebCore. The draggingLocation | 166 // Create the appropriate mouse locations for WebCore. The draggingLocation |
149 // is in window coordinates. | 167 // is in window coordinates. |
150 NSPoint windowPoint = [info draggingLocation]; | 168 NSPoint windowPoint = [info draggingLocation]; |
151 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 169 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
152 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 170 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
153 NSDragOperation mask = [info draggingSourceOperationMask]; | 171 NSDragOperation mask = [info draggingSourceOperationMask]; |
154 webContents_->GetRenderViewHost()->DragTargetDragOver( | 172 webContents_->GetRenderViewHost()->DragTargetDragOver( |
155 gfx::Point(viewPoint.x, viewPoint.y), | 173 gfx::Point(viewPoint.x, viewPoint.y), |
156 gfx::Point(screenPoint.x, screenPoint.y), | 174 gfx::Point(screenPoint.x, screenPoint.y), |
157 static_cast<WebDragOperationsMask>(mask)); | 175 static_cast<WebDragOperationsMask>(mask), |
| 176 GetModifierFlags()); |
158 | 177 |
159 if (delegate_) | 178 if (delegate_) |
160 delegate_->OnDragOver(); | 179 delegate_->OnDragOver(); |
161 | 180 |
162 return currentOperation_; | 181 return currentOperation_; |
163 } | 182 } |
164 | 183 |
165 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info | 184 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info |
166 view:(NSView*)view { | 185 view:(NSView*)view { |
167 if (currentRVH_ != webContents_->GetRenderViewHost()) | 186 if (currentRVH_ != webContents_->GetRenderViewHost()) |
(...skipping 19 matching lines...) Expand all Loading... |
187 | 206 |
188 currentRVH_ = NULL; | 207 currentRVH_ = NULL; |
189 | 208 |
190 // Create the appropriate mouse locations for WebCore. The draggingLocation | 209 // Create the appropriate mouse locations for WebCore. The draggingLocation |
191 // is in window coordinates. Both need to be flipped. | 210 // is in window coordinates. Both need to be flipped. |
192 NSPoint windowPoint = [info draggingLocation]; | 211 NSPoint windowPoint = [info draggingLocation]; |
193 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; | 212 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; |
194 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; | 213 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; |
195 webContents_->GetRenderViewHost()->DragTargetDrop( | 214 webContents_->GetRenderViewHost()->DragTargetDrop( |
196 gfx::Point(viewPoint.x, viewPoint.y), | 215 gfx::Point(viewPoint.x, viewPoint.y), |
197 gfx::Point(screenPoint.x, screenPoint.y)); | 216 gfx::Point(screenPoint.x, screenPoint.y), |
| 217 GetModifierFlags()); |
198 | 218 |
199 dropData_.reset(); | 219 dropData_.reset(); |
200 | 220 |
201 return result; | 221 return result; |
202 } | 222 } |
203 | 223 |
204 // Given |data|, which should not be nil, fill it in using the contents of the | 224 // Given |data|, which should not be nil, fill it in using the contents of the |
205 // given pasteboard. | 225 // given pasteboard. |
206 - (void)populateWebDropData:(WebDropData*)data | 226 - (void)populateWebDropData:(WebDropData*)data |
207 fromPasteboard:(NSPasteboard*)pboard { | 227 fromPasteboard:(NSPasteboard*)pboard { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // Get custom MIME data. | 273 // Get custom MIME data. |
254 if ([types containsObject:ui::kWebCustomDataPboardType]) { | 274 if ([types containsObject:ui::kWebCustomDataPboardType]) { |
255 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; | 275 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; |
256 ui::ReadCustomDataIntoMap([customData bytes], | 276 ui::ReadCustomDataIntoMap([customData bytes], |
257 [customData length], | 277 [customData length], |
258 &data->custom_data); | 278 &data->custom_data); |
259 } | 279 } |
260 } | 280 } |
261 | 281 |
262 @end | 282 @end |
OLD | NEW |