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

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

Issue 1855783002: mac: More pasteboard fixes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp23_dnd
Patch Set: 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_bar_folder_view.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h"
10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
11 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h" 11 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h"
12 #include "components/bookmarks/browser/bookmark_utils.h" 12 #include "components/bookmarks/browser/bookmark_utils.h"
13 #include "content/public/browser/user_metrics.h" 13 #include "content/public/browser/user_metrics.h"
14 14
15 using base::UserMetricsAction; 15 using base::UserMetricsAction;
16 using bookmarks::BookmarkModel; 16 using bookmarks::BookmarkModel;
17 using bookmarks::BookmarkNode; 17 using bookmarks::BookmarkNode;
18 18
19 #import "third_party/mozilla/NSPasteboard+Utils.h" 19 #import "third_party/mozilla/NSPasteboard+Utils.h"
20 #include "ui/base/clipboard/clipboard_util_mac.h"
20 21
21 @interface BookmarkBarFolderView() 22 @interface BookmarkBarFolderView()
22 23
23 @property(readonly, nonatomic) id<BookmarkButtonControllerProtocol> controller; 24 @property(readonly, nonatomic) id<BookmarkButtonControllerProtocol> controller;
24 25
25 - (void)setDropIndicatorShown:(BOOL)flag; 26 - (void)setDropIndicatorShown:(BOOL)flag;
26 27
27 @end 28 @end
28 29
29 @implementation BookmarkBarFolderView 30 @implementation BookmarkBarFolderView
30 31
31 - (void)awakeFromNib { 32 - (void)awakeFromNib {
32 NSArray* types = [NSArray arrayWithObjects: 33 NSArray* types = @[
33 NSStringPboardType, 34 NSStringPboardType, NSHTMLPboardType, NSURLPboardType,
34 NSHTMLPboardType, 35 ui::ClipboardUtil::UTIForPasteboardType(kBookmarkButtonDragType),
35 NSURLPboardType, 36 ui::ClipboardUtil::UTIForPasteboardType(kBookmarkDictionaryListPboardType)
36 kBookmarkButtonDragType, 37 ];
37 kBookmarkDictionaryListPboardType,
38 nil];
39 [self registerForDraggedTypes:types]; 38 [self registerForDraggedTypes:types];
40 } 39 }
41 40
42 - (void)dealloc { 41 - (void)dealloc {
43 [self unregisterDraggedTypes]; 42 [self unregisterDraggedTypes];
44 [super dealloc]; 43 [super dealloc];
45 } 44 }
46 45
47 - (id<BookmarkButtonControllerProtocol>)controller { 46 - (id<BookmarkButtonControllerProtocol>)controller {
48 // When needed for testing, set the local data member |controller_| to 47 // When needed for testing, set the local data member |controller_| to
49 // the test controller. 48 // the test controller.
50 return controller_ ? controller_ : [[self window] windowController]; 49 return controller_ ? controller_ : [[self window] windowController];
51 } 50 }
52 51
53 // Virtually identical to [BookmarkBarView draggingEntered:]. 52 // Virtually identical to [BookmarkBarView draggingEntered:].
54 // TODO(jrg): find a way to share code. Lack of multiple inheritance 53 // TODO(jrg): find a way to share code. Lack of multiple inheritance
55 // makes things more of a pain but there should be no excuse for laziness. 54 // makes things more of a pain but there should be no excuse for laziness.
56 // http://crbug.com/35966 55 // http://crbug.com/35966
57 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info { 56 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
58 inDrag_ = YES; 57 inDrag_ = YES;
59 if (![[self controller] draggingAllowed:info]) 58 if (![[self controller] draggingAllowed:info])
60 return NSDragOperationNone; 59 return NSDragOperationNone;
61 if ([[info draggingPasteboard] dataForType:kBookmarkButtonDragType] || 60 if ([[info draggingPasteboard]
61 dataForType:ui::ClipboardUtil::UTIForPasteboardType(
62 kBookmarkButtonDragType)] ||
62 bookmarks::PasteboardContainsBookmarks(ui::CLIPBOARD_TYPE_DRAG) || 63 bookmarks::PasteboardContainsBookmarks(ui::CLIPBOARD_TYPE_DRAG) ||
63 [[info draggingPasteboard] containsURLData]) { 64 [[info draggingPasteboard] containsURLData]) {
64 // Find the position of the drop indicator. 65 // Find the position of the drop indicator.
65 BOOL showIt = [[self controller] 66 BOOL showIt = [[self controller]
66 shouldShowIndicatorShownForPoint:[info draggingLocation]]; 67 shouldShowIndicatorShownForPoint:[info draggingLocation]];
67 if (!showIt) { 68 if (!showIt) {
68 [self setDropIndicatorShown:NO]; 69 [self setDropIndicatorShown:NO];
69 } else { 70 } else {
70 [self setDropIndicatorShown:YES]; 71 [self setDropIndicatorShown:YES];
71 72
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 143 }
143 144
144 // This code is practically identical to the same function in BookmarkBarView 145 // This code is practically identical to the same function in BookmarkBarView
145 // with the only difference being how the controller is retrieved. 146 // with the only difference being how the controller is retrieved.
146 // http://crbug.com/35966 147 // http://crbug.com/35966
147 // Implement NSDraggingDestination protocol method 148 // Implement NSDraggingDestination protocol method
148 // performDragOperation: for bookmark buttons. 149 // performDragOperation: for bookmark buttons.
149 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info { 150 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info {
150 BOOL doDrag = NO; 151 BOOL doDrag = NO;
151 NSData* data = [[info draggingPasteboard] 152 NSData* data = [[info draggingPasteboard]
152 dataForType:kBookmarkButtonDragType]; 153 dataForType:ui::ClipboardUtil::UTIForPasteboardType(
154 kBookmarkButtonDragType)];
153 // [info draggingSource] is nil if not the same application. 155 // [info draggingSource] is nil if not the same application.
154 if (data && [info draggingSource]) { 156 if (data && [info draggingSource]) {
155 BookmarkButton* button = nil; 157 BookmarkButton* button = nil;
156 [data getBytes:&button length:sizeof(button)]; 158 [data getBytes:&button length:sizeof(button)];
157 159
158 // If we're dragging from one profile to another, disallow moving (only 160 // If we're dragging from one profile to another, disallow moving (only
159 // allow copying). Each profile has its own bookmark model, so one way to 161 // allow copying). Each profile has its own bookmark model, so one way to
160 // check whether we are dragging across profiles is to see if the 162 // check whether we are dragging across profiles is to see if the
161 // |BookmarkNode| corresponding to |button| exists in this profile. If it 163 // |BookmarkNode| corresponding to |button| exists in this profile. If it
162 // does, we're dragging within a profile; otherwise, we're dragging across 164 // does, we're dragging within a profile; otherwise, we're dragging across
(...skipping 11 matching lines...) Expand all
174 copy:copy]; 176 copy:copy];
175 content::RecordAction(UserMetricsAction("BookmarkBarFolder_DragEnd")); 177 content::RecordAction(UserMetricsAction("BookmarkBarFolder_DragEnd"));
176 } 178 }
177 return doDrag; 179 return doDrag;
178 } 180 }
179 181
180 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info { 182 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info {
181 if ([[self controller] dragBookmarkData:info]) 183 if ([[self controller] dragBookmarkData:info])
182 return YES; 184 return YES;
183 NSPasteboard* pboard = [info draggingPasteboard]; 185 NSPasteboard* pboard = [info draggingPasteboard];
184 if ([pboard dataForType:kBookmarkButtonDragType] && 186 if ([pboard dataForType:ui::ClipboardUtil::UTIForPasteboardType(
187 kBookmarkButtonDragType)] &&
185 [self performDragOperationForBookmarkButton:info]) 188 [self performDragOperationForBookmarkButton:info])
186 return YES; 189 return YES;
187 if ([pboard containsURLData] && [self performDragOperationForURL:info]) 190 if ([pboard containsURLData] && [self performDragOperationForURL:info])
188 return YES; 191 return YES;
189 return NO; 192 return NO;
190 } 193 }
191 194
192 - (void)setDropIndicatorShown:(BOOL)flag { 195 - (void)setDropIndicatorShown:(BOOL)flag {
193 if (dropIndicatorShown_ == flag) 196 if (dropIndicatorShown_ == flag)
194 return; 197 return;
195 198
196 dropIndicatorShown_ = flag; 199 dropIndicatorShown_ = flag;
197 if (dropIndicatorShown_) { 200 if (dropIndicatorShown_) {
198 NSRect frame = NSInsetRect([self bounds], 4, 0); 201 NSRect frame = NSInsetRect([self bounds], 4, 0);
199 frame.size.height = 1; 202 frame.size.height = 1;
200 dropIndicator_.reset([[NSBox alloc] initWithFrame:frame]); 203 dropIndicator_.reset([[NSBox alloc] initWithFrame:frame]);
201 [dropIndicator_ setBoxType:NSBoxSeparator]; 204 [dropIndicator_ setBoxType:NSBoxSeparator];
202 [dropIndicator_ setBorderType:NSLineBorder]; 205 [dropIndicator_ setBorderType:NSLineBorder];
203 [dropIndicator_ setAlphaValue:0.85]; 206 [dropIndicator_ setAlphaValue:0.85];
204 [self addSubview:dropIndicator_]; 207 [self addSubview:dropIndicator_];
205 } else { 208 } else {
206 [dropIndicator_ removeFromSuperview]; 209 [dropIndicator_ removeFromSuperview];
207 dropIndicator_.reset(); 210 dropIndicator_.reset();
208 } 211 }
209 } 212 }
210 213
211 @end 214 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698