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

Side by Side Diff: chrome/browser/cocoa/bookmark_bar_view.mm

Issue 336001: [Mac] Make bookmark bar a primitive drag destination. (Closed)
Patch Set: cleanup Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/bookmark_bar_view.h" 5 #import "chrome/browser/cocoa/bookmark_bar_view.h"
6
7 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
6 #import "third_party/GTM/AppKit/GTMTheme.h" 8 #import "third_party/GTM/AppKit/GTMTheme.h"
9 #import "third_party/mozilla/include/NSPasteboard+Utils.h"
7 10
8 @interface BookmarkBarView (Private) 11 @interface BookmarkBarView (Private)
9 - (void)themeDidChangeNotification:(NSNotification*)aNotification; 12 - (void)themeDidChangeNotification:(NSNotification*)aNotification;
10 - (void)updateTheme:(GTMTheme*)theme; 13 - (void)updateTheme:(GTMTheme*)theme;
11 @end 14 @end
12 15
13 @implementation BookmarkBarView 16 @implementation BookmarkBarView
14 17
15 - (void)dealloc { 18 - (void)dealloc {
16 [[NSNotificationCenter defaultCenter] removeObserver:self]; 19 [[NSNotificationCenter defaultCenter] removeObserver:self];
20 // This probably isn't strictly necessary, but can't hurt.
21 [self unregisterDraggedTypes];
17 [super dealloc]; 22 [super dealloc];
18 } 23 }
19 24
20 - (void)awakeFromNib { 25 - (void)awakeFromNib {
21 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 26 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
22 [defaultCenter addObserver:self 27 [defaultCenter addObserver:self
23 selector:@selector(themeDidChangeNotification:) 28 selector:@selector(themeDidChangeNotification:)
24 name:kGTMThemeDidChangeNotification 29 name:kGTMThemeDidChangeNotification
25 object:nil]; 30 object:nil];
31
32 DCHECK(controller_ && "Expected this to be hooked up via Interface Builder");
33 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType,
34 NSHTMLPboardType, NSURLPboardType, nil];
35 [self registerForDraggedTypes:types];
26 } 36 }
27 37
28 - (void)viewDidMoveToWindow { 38 - (void)viewDidMoveToWindow {
29 if ([self window]) 39 if ([self window])
30 [self updateTheme:[self gtm_theme]]; 40 [self updateTheme:[self gtm_theme]];
31 } 41 }
32 42
33 - (void)themeDidChangeNotification:(NSNotification*)aNotification { 43 - (void)themeDidChangeNotification:(NSNotification*)aNotification {
34 GTMTheme* theme = [aNotification object]; 44 GTMTheme* theme = [aNotification object];
35 [self updateTheme:theme]; 45 [self updateTheme:theme];
36 } 46 }
37 47
38 - (void)updateTheme:(GTMTheme*)theme { 48 - (void)updateTheme:(GTMTheme*)theme {
39 NSColor* color = [theme textColorForStyle:GTMThemeStyleBookmarksBarButton 49 NSColor* color = [theme textColorForStyle:GTMThemeStyleBookmarksBarButton
40 state:GTMThemeStateActiveWindow]; 50 state:GTMThemeStateActiveWindow];
41 [noItemTextfield_ setTextColor:color]; 51 [noItemTextfield_ setTextColor:color];
42 } 52 }
43 53
44 // Mouse down events on the bookmark bar should not allow dragging the parent 54 // Mouse down events on the bookmark bar should not allow dragging the parent
45 // window around. 55 // window around.
46 - (BOOL)mouseDownCanMoveWindow { 56 - (BOOL)mouseDownCanMoveWindow {
47 return NO; 57 return NO;
48 } 58 }
49 59
50 -(NSTextField*)noItemTextfield { 60 -(NSTextField*)noItemTextfield {
51 return noItemTextfield_; 61 return noItemTextfield_;
52 } 62 }
53 63
64 // NSDraggingDestination methods
65
66 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
67 if ([[info draggingPasteboard] containsURLData])
68 return NSDragOperationCopy;
69 return NSDragOperationNone;
70 }
71
72 - (BOOL)wantsPeriodicDraggingUpdates {
73 // TODO(port): This should probably return |YES| and the controller should
pink (ping after 24hrs) 2009/10/27 15:00:43 we've stopped using "port" for TODOs.
Nico 2009/10/27 15:52:42 Will convert it when I touch this file the next ti
74 // slide the existing bookmark buttons interactively to the side to make
75 // room for the about-to-be-dropped bookmark.
76 return NO;
77 }
78
79 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info {
80 if ([[info draggingPasteboard] containsURLData])
pink (ping after 24hrs) 2009/10/27 15:00:43 todo for DragOperationMove when dragging a bookmar
Nico 2009/10/27 15:52:42 Given that http://crbug.com/17609 is set to "start
81 return NSDragOperationCopy;
82 return NSDragOperationNone;
83 }
84
85 - (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)info {
86 return YES;
87 }
88
89 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info {
90 NSPasteboard* pboard = [info draggingPasteboard];
91 DCHECK([pboard containsURLData]);
92
93 NSArray* urls = nil;
94 NSArray* titles = nil;
95 [pboard getURLs:&urls andTitles:&titles];
96
97 return [controller_ addURLs:urls
98 withTitles:titles
99 at:[info draggingLocation]];
100 }
101
54 @end // @implementation BookmarkBarView 102 @end // @implementation BookmarkBarView
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698