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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.mm

Issue 1854223002: mac: Fix bookmark drag and drop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp37_dnd
Patch Set: Fix memory leak. Created 4 years, 8 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) 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_folder_target.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h"
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
12 #include "components/bookmarks/browser/bookmark_model.h" 12 #include "components/bookmarks/browser/bookmark_model.h"
13 #include "components/bookmarks/browser/bookmark_node_data.h" 13 #include "components/bookmarks/browser/bookmark_node_data.h"
14 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h" 14 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h"
15 #include "ui/base/clipboard/clipboard_util_mac.h" 15 #include "ui/base/clipboard/clipboard_util_mac.h"
16 #import "ui/base/cocoa/cocoa_base_utils.h" 16 #import "ui/base/cocoa/cocoa_base_utils.h"
17 17
18 using bookmarks::BookmarkNode; 18 using bookmarks::BookmarkNode;
19 using bookmarks::BookmarkNodeData; 19 using bookmarks::BookmarkNodeData;
20 20
21 NSString* kBookmarkButtonDragType = @"com.google.chrome.BookmarkButtonDrag"; 21 NSString* kBookmarkButtonDragType = @"com.google.chrome.BookmarkButtonDrag";
22 22
23 @interface BookmarkFolderTarget()
24 // Copies the given bookmark node to the given pasteboard, declaring appropriate
25 // types (to paste a URL with a title).
26 - (void)copyBookmarkNode:(const BookmarkNode*)node
27 toDragPasteboard:(NSPasteboard*)pboard;
28 @end
29
30 @implementation BookmarkFolderTarget 23 @implementation BookmarkFolderTarget
31 24
32 - (id)initWithController:(id<BookmarkButtonControllerProtocol>)controller 25 - (id)initWithController:(id<BookmarkButtonControllerProtocol>)controller
33 profile:(Profile*)profile { 26 profile:(Profile*)profile {
34 if ((self = [super init])) { 27 if ((self = [super init])) {
35 controller_ = controller; 28 controller_ = controller;
36 profile_ = profile; 29 profile_ = profile;
37 } 30 }
38 return self; 31 return self;
39 } 32 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // If click on same folder, close it and be done. 77 // If click on same folder, close it and be done.
85 // Else we clicked on a different folder so more work to do. 78 // Else we clicked on a different folder so more work to do.
86 if ([[controller_ folderController] parentButton] == sender) { 79 if ([[controller_ folderController] parentButton] == sender) {
87 [controller_ closeBookmarkFolder:controller_]; 80 [controller_ closeBookmarkFolder:controller_];
88 return; 81 return;
89 } 82 }
90 83
91 [controller_ addNewFolderControllerWithParentButton:sender]; 84 [controller_ addNewFolderControllerWithParentButton:sender];
92 } 85 }
93 86
94 - (void)copyBookmarkNode:(const BookmarkNode*)node 87 - (NSPasteboardItem*)pasteboardItemForDragOfButton:(BookmarkButton*)button {
95 toDragPasteboard:(NSPasteboard*)pboard { 88 const BookmarkNode* node = [button bookmarkNode];
96 if (!node) { 89 DCHECK(node);
97 NOTREACHED();
98 return;
99 }
100 90
91 NSPasteboardItem* item = nil;
101 if (node->is_folder()) { 92 if (node->is_folder()) {
102 // TODO(viettrungluu): I'm not sure what we should do, so just declare the 93 // TODO(viettrungluu): I'm not sure what we should do, so just declare the
103 // "additional" types we're given for now. Maybe we want to add a list of 94 // "additional" types we're given for now. Maybe we want to add a list of
104 // URLs? Would we then have to recurse if there were subfolders? 95 // URLs? Would we then have to recurse if there were subfolders?
105 // In the meanwhile, we *must* set it to a known state. 96 item = [[[NSPasteboardItem alloc] init] autorelease];
106 [pboard clearContents];
107 } else { 97 } else {
108 BookmarkNodeData data(node); 98 BookmarkNodeData data(node);
109 data.SetOriginatingProfilePath(profile_->GetPath()); 99 data.SetOriginatingProfilePath(profile_->GetPath());
110 data.WriteToClipboard(ui::CLIPBOARD_TYPE_DRAG); 100 item = PasteboardItemFromBookmarks(data.elements, profile_->GetPath());
111 } 101 }
112 }
113 102
114 - (void)fillPasteboard:(NSPasteboard*)pboard 103 [item
115 forDragOfButton:(BookmarkButton*)button { 104 setData:[NSData dataWithBytes:&button length:sizeof(button)]
116 if (const BookmarkNode* node = [button bookmarkNode]) { 105 forType:ui::ClipboardUtil::UTIForPasteboardType(kBookmarkButtonDragType)];
117 // Put the bookmark information into the pasteboard, and then write our own 106 return item;
118 // data for
119 // |ui::ClipboardUtil::UTIForPasteboardType(kBookmarkButtonDragType)|.
120 [self copyBookmarkNode:node toDragPasteboard:pboard];
121 [pboard addTypes:@[ ui::ClipboardUtil::UTIForPasteboardType(
122 kBookmarkButtonDragType) ]
123 owner:nil];
124 [pboard setData:[NSData dataWithBytes:&button length:sizeof(button)]
125 forType:ui::ClipboardUtil::UTIForPasteboardType(
126 kBookmarkButtonDragType)];
127 } else {
128 NOTREACHED();
129 }
130 } 107 }
131 108
132 @end 109 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698