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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.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_view_cocoa.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #import "chrome/browser/themes/theme_properties.h" 8 #import "chrome/browser/themes/theme_properties.h"
9 #import "chrome/browser/themes/theme_service.h" 9 #import "chrome/browser/themes/theme_service.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle r.h" 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle r.h"
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h"
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #import "chrome/browser/ui/cocoa/themed_window.h" 15 #import "chrome/browser/ui/cocoa/themed_window.h"
16 #import "chrome/browser/ui/cocoa/view_id_util.h" 16 #import "chrome/browser/ui/cocoa/view_id_util.h"
17 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h" 17 #include "components/bookmarks/browser/bookmark_pasteboard_helper_mac.h"
18 #include "components/bookmarks/browser/bookmark_utils.h" 18 #include "components/bookmarks/browser/bookmark_utils.h"
19 #include "content/public/browser/user_metrics.h" 19 #include "content/public/browser/user_metrics.h"
20 #import "third_party/mozilla/NSPasteboard+Utils.h" 20 #import "third_party/mozilla/NSPasteboard+Utils.h"
21 #include "ui/base/clipboard/clipboard_util_mac.h"
21 #import "ui/base/cocoa/nsview_additions.h" 22 #import "ui/base/cocoa/nsview_additions.h"
22 23
23 using base::UserMetricsAction; 24 using base::UserMetricsAction;
24 using bookmarks::BookmarkModel; 25 using bookmarks::BookmarkModel;
25 using bookmarks::BookmarkNode; 26 using bookmarks::BookmarkNode;
26 27
27 @interface BookmarkBarView (Private) 28 @interface BookmarkBarView (Private)
28 - (void)themeDidChangeNotification:(NSNotification*)aNotification; 29 - (void)themeDidChangeNotification:(NSNotification*)aNotification;
29 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider; 30 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider;
30 31
(...skipping 30 matching lines...) Expand all
61 } 62 }
62 63
63 - (void)awakeFromNib { 64 - (void)awakeFromNib {
64 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 65 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
65 [defaultCenter addObserver:self 66 [defaultCenter addObserver:self
66 selector:@selector(themeDidChangeNotification:) 67 selector:@selector(themeDidChangeNotification:)
67 name:kBrowserThemeDidChangeNotification 68 name:kBrowserThemeDidChangeNotification
68 object:nil]; 69 object:nil];
69 70
70 DCHECK(controller_) << "Expected this to be hooked up via Interface Builder"; 71 DCHECK(controller_) << "Expected this to be hooked up via Interface Builder";
71 NSArray* types = [NSArray arrayWithObjects: 72 NSArray* types = @[
72 NSStringPboardType, 73 NSStringPboardType, NSHTMLPboardType, NSURLPboardType,
73 NSHTMLPboardType, 74 ui::ClipboardUtil::UTIForPasteboardType(kBookmarkButtonDragType),
74 NSURLPboardType, 75 ui::ClipboardUtil::UTIForPasteboardType(kBookmarkDictionaryListPboardType)
75 kBookmarkButtonDragType, 76 ];
76 kBookmarkDictionaryListPboardType,
77 nil];
78 [self registerForDraggedTypes:types]; 77 [self registerForDraggedTypes:types];
79 } 78 }
80 79
81 // We need the theme to color the bookmark buttons properly. But our 80 // We need the theme to color the bookmark buttons properly. But our
82 // controller desn't have access to it until it's placed in the view 81 // controller desn't have access to it until it's placed in the view
83 // hierarchy. This is the spot where we close the loop. 82 // hierarchy. This is the spot where we close the loop.
84 - (void)viewWillMoveToWindow:(NSWindow*)window { 83 - (void)viewWillMoveToWindow:(NSWindow*)window {
85 const ui::ThemeProvider* themeProvider = [window themeProvider]; 84 const ui::ThemeProvider* themeProvider = [window themeProvider];
86 [self updateTheme:themeProvider]; 85 [self updateTheme:themeProvider];
87 [controller_ updateTheme:themeProvider]; 86 [controller_ updateTheme:themeProvider];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 [controller_ setDropInsertionPos:dropIndicatorPosition_]; 133 [controller_ setDropInsertionPos:dropIndicatorPosition_];
135 else 134 else
136 [controller_ clearDropInsertionPos]; 135 [controller_ clearDropInsertionPos];
137 } 136 }
138 137
139 // NSDraggingDestination methods 138 // NSDraggingDestination methods
140 139
141 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info { 140 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
142 if (![controller_ draggingAllowed:info]) 141 if (![controller_ draggingAllowed:info])
143 return NSDragOperationNone; 142 return NSDragOperationNone;
144 if ([[info draggingPasteboard] dataForType:kBookmarkButtonDragType] || 143 if ([[info draggingPasteboard]
144 dataForType:ui::ClipboardUtil::UTIForPasteboardType(
145 kBookmarkButtonDragType)] ||
145 bookmarks::PasteboardContainsBookmarks(ui::CLIPBOARD_TYPE_DRAG) || 146 bookmarks::PasteboardContainsBookmarks(ui::CLIPBOARD_TYPE_DRAG) ||
146 [[info draggingPasteboard] containsURLData]) { 147 [[info draggingPasteboard] containsURLData]) {
147 // We only show the drop indicator if we're not in a position to 148 // We only show the drop indicator if we're not in a position to
148 // perform a hover-open since it doesn't make sense to do both. 149 // perform a hover-open since it doesn't make sense to do both.
149 BOOL showIt = [controller_ shouldShowIndicatorShownForPoint: 150 BOOL showIt = [controller_ shouldShowIndicatorShownForPoint:
150 [info draggingLocation]]; 151 [info draggingLocation]];
151 if (!showIt) { 152 if (!showIt) {
152 if (dropIndicatorShown_) { 153 if (dropIndicatorShown_) {
153 dropIndicatorShown_ = NO; 154 dropIndicatorShown_ = NO;
154 [self dropIndicatorChanged]; 155 [self dropIndicatorChanged];
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return [controller_ addURLs:urls 221 return [controller_ addURLs:urls
221 withTitles:titles 222 withTitles:titles
222 at:[info draggingLocation]]; 223 at:[info draggingLocation]];
223 } 224 }
224 225
225 // Implement NSDraggingDestination protocol method 226 // Implement NSDraggingDestination protocol method
226 // performDragOperation: for bookmark buttons. 227 // performDragOperation: for bookmark buttons.
227 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info { 228 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info {
228 BOOL rtn = NO; 229 BOOL rtn = NO;
229 NSData* data = [[info draggingPasteboard] 230 NSData* data = [[info draggingPasteboard]
230 dataForType:kBookmarkButtonDragType]; 231 dataForType:ui::ClipboardUtil::UTIForPasteboardType(
232 kBookmarkButtonDragType)];
231 // [info draggingSource] is nil if not the same application. 233 // [info draggingSource] is nil if not the same application.
232 if (data && [info draggingSource]) { 234 if (data && [info draggingSource]) {
233 BookmarkButton* button = nil; 235 BookmarkButton* button = nil;
234 [data getBytes:&button length:sizeof(button)]; 236 [data getBytes:&button length:sizeof(button)];
235 237
236 // If we're dragging from one profile to another, disallow moving (only 238 // If we're dragging from one profile to another, disallow moving (only
237 // allow copying). Each profile has its own bookmark model, so one way to 239 // allow copying). Each profile has its own bookmark model, so one way to
238 // check whether we are dragging across profiles is to see if the 240 // check whether we are dragging across profiles is to see if the
239 // |BookmarkNode| corresponding to |button| exists in this profile. If it 241 // |BookmarkNode| corresponding to |button| exists in this profile. If it
240 // does, we're dragging within a profile; otherwise, we're dragging across 242 // does, we're dragging within a profile; otherwise, we're dragging across
(...skipping 11 matching lines...) Expand all
252 copy:copy]; 254 copy:copy];
253 content::RecordAction(UserMetricsAction("BookmarkBar_DragEnd")); 255 content::RecordAction(UserMetricsAction("BookmarkBar_DragEnd"));
254 } 256 }
255 return rtn; 257 return rtn;
256 } 258 }
257 259
258 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info { 260 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info {
259 if ([controller_ dragBookmarkData:info]) 261 if ([controller_ dragBookmarkData:info])
260 return YES; 262 return YES;
261 NSPasteboard* pboard = [info draggingPasteboard]; 263 NSPasteboard* pboard = [info draggingPasteboard];
262 if ([pboard dataForType:kBookmarkButtonDragType]) { 264 if ([pboard dataForType:ui::ClipboardUtil::UTIForPasteboardType(
265 kBookmarkButtonDragType)]) {
263 if ([self performDragOperationForBookmarkButton:info]) 266 if ([self performDragOperationForBookmarkButton:info])
264 return YES; 267 return YES;
265 // Fall through.... 268 // Fall through....
266 } 269 }
267 if ([pboard containsURLData]) { 270 if ([pboard containsURLData]) {
268 if ([self performDragOperationForURL:info]) 271 if ([self performDragOperationForURL:info])
269 return YES; 272 return YES;
270 } 273 }
271 return NO; 274 return NO;
272 } 275 }
(...skipping 20 matching lines...) Expand all
293 296
294 @end // @implementation BookmarkBarTextField 297 @end // @implementation BookmarkBarTextField
295 298
296 @implementation BookmarkBarItemContainer 299 @implementation BookmarkBarItemContainer
297 300
298 - (NSMenu*)menu { 301 - (NSMenu*)menu {
299 return [barView_ menu]; 302 return [barView_ menu];
300 } 303 }
301 304
302 @end // @implementation BookmarkBarItemContainer 305 @end // @implementation BookmarkBarItemContainer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698