OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" |
6 | 6 |
7 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" | 7 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info { | 180 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info { |
181 BOOL doDrag = NO; | 181 BOOL doDrag = NO; |
182 NSData* data = [[info draggingPasteboard] | 182 NSData* data = [[info draggingPasteboard] |
183 dataForType:kBookmarkButtonDragType]; | 183 dataForType:kBookmarkButtonDragType]; |
184 // [info draggingSource] is nil if not the same application. | 184 // [info draggingSource] is nil if not the same application. |
185 if (data && [info draggingSource]) { | 185 if (data && [info draggingSource]) { |
186 BookmarkButton* button = nil; | 186 BookmarkButton* button = nil; |
187 [data getBytes:&button length:sizeof(button)]; | 187 [data getBytes:&button length:sizeof(button)]; |
188 | 188 |
189 // If we're dragging from one profile to another, disallow moving (only | 189 // If we're dragging from one profile to another, disallow moving (only |
190 // allow copying). Note that we need to call |GetOriginalProfile()| to make | 190 // allow copying). Each profile has its own bookmark model, so one way to |
191 // sure that Incognito profiles are handled correctly. | 191 // check whether we are dragging across profiles is to see if the |
192 NSWindow* source_window = [[button delegate] browserWindow]; | 192 // |BookmarkNode| corresponding to |button| exists in this profile. If it |
193 BrowserWindowController* source_window_controller = | 193 // does, we're dragging within a profile; otherwise, we're dragging across |
194 [BrowserWindowController | 194 // profiles. |
195 browserWindowControllerForWindow:source_window]; | 195 const BookmarkModel* const model = [[self controller] bookmarkModel]; |
196 const Profile* source_profile = | 196 const BookmarkNode* const source_node = [button bookmarkNode]; |
197 [source_window_controller profile]->GetOriginalProfile(); | 197 const BookmarkNode* const target_node = |
198 const Profile* target_profile = | 198 model->GetNodeByID(source_node->id()); |
199 [[self controller] bookmarkModel]->profile()->GetOriginalProfile(); | |
200 | 199 |
201 BOOL copy = | 200 BOOL copy = |
202 !([info draggingSourceOperationMask] & NSDragOperationMove) || | 201 !([info draggingSourceOperationMask] & NSDragOperationMove) || |
203 source_profile != target_profile; | 202 (source_node != target_node); |
204 doDrag = [[self controller] dragButton:button | 203 doDrag = [[self controller] dragButton:button |
205 to:[info draggingLocation] | 204 to:[info draggingLocation] |
206 copy:copy]; | 205 copy:copy]; |
207 UserMetrics::RecordAction(UserMetricsAction("BookmarkBarFolder_DragEnd")); | 206 UserMetrics::RecordAction(UserMetricsAction("BookmarkBarFolder_DragEnd")); |
208 } | 207 } |
209 return doDrag; | 208 return doDrag; |
210 } | 209 } |
211 | 210 |
212 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info { | 211 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info { |
213 if ([[self controller] dragBookmarkData:info]) | 212 if ([[self controller] dragBookmarkData:info]) |
214 return YES; | 213 return YES; |
215 NSPasteboard* pboard = [info draggingPasteboard]; | 214 NSPasteboard* pboard = [info draggingPasteboard]; |
216 if ([pboard dataForType:kBookmarkButtonDragType] && | 215 if ([pboard dataForType:kBookmarkButtonDragType] && |
217 [self performDragOperationForBookmarkButton:info]) | 216 [self performDragOperationForBookmarkButton:info]) |
218 return YES; | 217 return YES; |
219 if ([pboard containsURLData] && [self performDragOperationForURL:info]) | 218 if ([pboard containsURLData] && [self performDragOperationForURL:info]) |
220 return YES; | 219 return YES; |
221 return NO; | 220 return NO; |
222 } | 221 } |
223 | 222 |
224 @end | 223 @end |
OLD | NEW |