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

Side by Side Diff: content/browser/web_contents/web_drag_dest_mac.mm

Issue 10386014: Implement WebContentsView::GetDropData for Mac; disable on Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert more aura changes. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/web_contents/web_drag_dest_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/web_drag_dest_delegate.h" 10 #include "content/public/browser/web_drag_dest_delegate.h"
(...skipping 12 matching lines...) Expand all
23 // |contents| is the WebContentsImpl representing this tab, used to communicate 23 // |contents| is the WebContentsImpl representing this tab, used to communicate
24 // drag&drop messages to WebCore and handle navigation on a successful drop 24 // drag&drop messages to WebCore and handle navigation on a successful drop
25 // (if necessary). 25 // (if necessary).
26 - (id)initWithWebContentsImpl:(WebContentsImpl*)contents { 26 - (id)initWithWebContentsImpl:(WebContentsImpl*)contents {
27 if ((self = [super init])) { 27 if ((self = [super init])) {
28 webContents_ = contents; 28 webContents_ = contents;
29 } 29 }
30 return self; 30 return self;
31 } 31 }
32 32
33 - (WebDropData*)currentDropData {
34 return dropData_.get();
35 }
36
33 - (void)setDragDelegate:(content::WebDragDestDelegate*)delegate { 37 - (void)setDragDelegate:(content::WebDragDestDelegate*)delegate {
34 delegate_ = delegate; 38 delegate_ = delegate;
35 } 39 }
36 40
37 // Call to set whether or not we should allow the drop. Takes effect the 41 // Call to set whether or not we should allow the drop. Takes effect the
38 // next time |-draggingUpdated:| is called. 42 // next time |-draggingUpdated:| is called.
39 - (void)setCurrentOperation:(NSDragOperation)operation { 43 - (void)setCurrentOperation:(NSDragOperation)operation {
40 current_operation_ = operation; 44 currentOperation_ = operation;
41 } 45 }
42 46
43 // Given a point in window coordinates and a view in that window, return a 47 // Given a point in window coordinates and a view in that window, return a
44 // flipped point in the coordinate system of |view|. 48 // flipped point in the coordinate system of |view|.
45 - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint 49 - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint
46 view:(NSView*)view { 50 view:(NSView*)view {
47 DCHECK(view); 51 DCHECK(view);
48 NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil]; 52 NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil];
49 NSRect viewFrame = [view frame]; 53 NSRect viewFrame = [view frame];
50 viewPoint.y = viewFrame.size.height - viewPoint.y; 54 viewPoint.y = viewFrame.size.height - viewPoint.y;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return NSDragOperationCopy; 90 return NSDragOperationCopy;
87 return NSDragOperationNone; 91 return NSDragOperationNone;
88 } 92 }
89 93
90 if (delegate_) { 94 if (delegate_) {
91 delegate_->DragInitialize(webContents_); 95 delegate_->DragInitialize(webContents_);
92 delegate_->OnDragEnter(); 96 delegate_->OnDragEnter();
93 } 97 }
94 98
95 // Fill out a WebDropData from pasteboard. 99 // Fill out a WebDropData from pasteboard.
96 WebDropData data; 100 dropData_.reset(new WebDropData());
97 [self populateWebDropData:&data fromPasteboard:[info draggingPasteboard]]; 101 [self populateWebDropData:dropData_.get()
102 fromPasteboard:[info draggingPasteboard]];
98 103
99 // Create the appropriate mouse locations for WebCore. The draggingLocation 104 // Create the appropriate mouse locations for WebCore. The draggingLocation
100 // is in window coordinates. Both need to be flipped. 105 // is in window coordinates. Both need to be flipped.
101 NSPoint windowPoint = [info draggingLocation]; 106 NSPoint windowPoint = [info draggingLocation];
102 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 107 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
103 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 108 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
104 NSDragOperation mask = [info draggingSourceOperationMask]; 109 NSDragOperation mask = [info draggingSourceOperationMask];
105 webContents_->GetRenderViewHost()->DragTargetDragEnter( 110 webContents_->GetRenderViewHost()->DragTargetDragEnter(
106 data, 111 *dropData_,
107 gfx::Point(viewPoint.x, viewPoint.y), 112 gfx::Point(viewPoint.x, viewPoint.y),
108 gfx::Point(screenPoint.x, screenPoint.y), 113 gfx::Point(screenPoint.x, screenPoint.y),
109 static_cast<WebDragOperationsMask>(mask)); 114 static_cast<WebDragOperationsMask>(mask));
110 115
111 // We won't know the true operation (whether the drag is allowed) until we 116 // We won't know the true operation (whether the drag is allowed) until we
112 // hear back from the renderer. For now, be optimistic: 117 // hear back from the renderer. For now, be optimistic:
113 current_operation_ = NSDragOperationCopy; 118 currentOperation_ = NSDragOperationCopy;
114 return current_operation_; 119 return currentOperation_;
115 } 120 }
116 121
117 - (void)draggingExited:(id<NSDraggingInfo>)info { 122 - (void)draggingExited:(id<NSDraggingInfo>)info {
118 DCHECK(currentRVH_); 123 DCHECK(currentRVH_);
119 if (currentRVH_ != webContents_->GetRenderViewHost()) 124 if (currentRVH_ != webContents_->GetRenderViewHost())
120 return; 125 return;
121 126
122 // Nothing to do in the interstitial case. 127 // Nothing to do in the interstitial case.
123 128
124 if (delegate_) 129 if (delegate_)
125 delegate_->OnDragLeave(); 130 delegate_->OnDragLeave();
126 131
127 webContents_->GetRenderViewHost()->DragTargetDragLeave(); 132 webContents_->GetRenderViewHost()->DragTargetDragLeave();
133 dropData_.reset();
128 } 134 }
129 135
130 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info 136 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info
131 view:(NSView*)view { 137 view:(NSView*)view {
132 DCHECK(currentRVH_); 138 DCHECK(currentRVH_);
133 if (currentRVH_ != webContents_->GetRenderViewHost()) 139 if (currentRVH_ != webContents_->GetRenderViewHost())
134 [self draggingEntered:info view:view]; 140 [self draggingEntered:info view:view];
135 141
136 if ([self onlyAllowsNavigation]) { 142 if ([self onlyAllowsNavigation]) {
137 if ([[info draggingPasteboard] containsURLData]) 143 if ([[info draggingPasteboard] containsURLData])
138 return NSDragOperationCopy; 144 return NSDragOperationCopy;
139 return NSDragOperationNone; 145 return NSDragOperationNone;
140 } 146 }
141 147
142 // Create the appropriate mouse locations for WebCore. The draggingLocation 148 // Create the appropriate mouse locations for WebCore. The draggingLocation
143 // is in window coordinates. 149 // is in window coordinates.
144 NSPoint windowPoint = [info draggingLocation]; 150 NSPoint windowPoint = [info draggingLocation];
145 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 151 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
146 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 152 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
147 NSDragOperation mask = [info draggingSourceOperationMask]; 153 NSDragOperation mask = [info draggingSourceOperationMask];
148 webContents_->GetRenderViewHost()->DragTargetDragOver( 154 webContents_->GetRenderViewHost()->DragTargetDragOver(
149 gfx::Point(viewPoint.x, viewPoint.y), 155 gfx::Point(viewPoint.x, viewPoint.y),
150 gfx::Point(screenPoint.x, screenPoint.y), 156 gfx::Point(screenPoint.x, screenPoint.y),
151 static_cast<WebDragOperationsMask>(mask)); 157 static_cast<WebDragOperationsMask>(mask));
152 158
153 if (delegate_) 159 if (delegate_)
154 delegate_->OnDragOver(); 160 delegate_->OnDragOver();
155 161
156 return current_operation_; 162 return currentOperation_;
157 } 163 }
158 164
159 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info 165 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info
160 view:(NSView*)view { 166 view:(NSView*)view {
161 if (currentRVH_ != webContents_->GetRenderViewHost()) 167 if (currentRVH_ != webContents_->GetRenderViewHost())
162 [self draggingEntered:info view:view]; 168 [self draggingEntered:info view:view];
163 169
164 // Check if we only allow navigation and navigate to a url on the pasteboard. 170 // Check if we only allow navigation and navigate to a url on the pasteboard.
171 BOOL result = YES;
165 if ([self onlyAllowsNavigation]) { 172 if ([self onlyAllowsNavigation]) {
166 NSPasteboard* pboard = [info draggingPasteboard]; 173 NSPasteboard* pboard = [info draggingPasteboard];
167 if ([pboard containsURLData]) { 174 if ([pboard containsURLData]) {
168 GURL url; 175 GURL url;
169 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES); 176 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES);
170 webContents_->OpenURL(OpenURLParams( 177 webContents_->OpenURL(OpenURLParams(
171 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, 178 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK,
172 false)); 179 false));
173 return YES; 180 } else {
181 result = NO;
174 } 182 }
175 return NO; 183 } else {
184 if (delegate_)
185 delegate_->OnDrop();
176 } 186 }
177 187
178 if (delegate_)
179 delegate_->OnDrop();
180
181 currentRVH_ = NULL; 188 currentRVH_ = NULL;
182 189
183 // Create the appropriate mouse locations for WebCore. The draggingLocation 190 // Create the appropriate mouse locations for WebCore. The draggingLocation
184 // is in window coordinates. Both need to be flipped. 191 // is in window coordinates. Both need to be flipped.
185 NSPoint windowPoint = [info draggingLocation]; 192 NSPoint windowPoint = [info draggingLocation];
186 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 193 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
187 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 194 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
188 webContents_->GetRenderViewHost()->DragTargetDrop( 195 webContents_->GetRenderViewHost()->DragTargetDrop(
189 gfx::Point(viewPoint.x, viewPoint.y), 196 gfx::Point(viewPoint.x, viewPoint.y),
190 gfx::Point(screenPoint.x, screenPoint.y)); 197 gfx::Point(screenPoint.x, screenPoint.y));
191 198
192 return YES; 199 dropData_.reset();
200
201 return result;
193 } 202 }
194 203
195 // Given |data|, which should not be nil, fill it in using the contents of the 204 // Given |data|, which should not be nil, fill it in using the contents of the
196 // given pasteboard. 205 // given pasteboard.
197 - (void)populateWebDropData:(WebDropData*)data 206 - (void)populateWebDropData:(WebDropData*)data
198 fromPasteboard:(NSPasteboard*)pboard { 207 fromPasteboard:(NSPasteboard*)pboard {
199 DCHECK(data); 208 DCHECK(data);
200 DCHECK(pboard); 209 DCHECK(pboard);
201 NSArray* types = [pboard types]; 210 NSArray* types = [pboard types];
202 211
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Get custom MIME data. 251 // Get custom MIME data.
243 if ([types containsObject:ui::kWebCustomDataPboardType]) { 252 if ([types containsObject:ui::kWebCustomDataPboardType]) {
244 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType]; 253 NSData* customData = [pboard dataForType:ui::kWebCustomDataPboardType];
245 ui::ReadCustomDataIntoMap([customData bytes], 254 ui::ReadCustomDataIntoMap([customData bytes],
246 [customData length], 255 [customData length],
247 &data->custom_data); 256 &data->custom_data);
248 } 257 }
249 } 258 }
250 259
251 @end 260 @end
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_drag_dest_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698