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

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

Issue 2824004: Not meant to be reviewed or checked in: bookmark bar dragging 06/14/2010 Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 6 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_controller.h" 5 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
6 #include "app/l10n_util_mac.h" 6 #include "app/l10n_util_mac.h"
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/mac_util.h" 8 #include "base/mac_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_editor.h" 10 #include "chrome/browser/bookmarks/bookmark_editor.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 if (node->is_folder()) 425 if (node->is_folder())
426 return folderImage_; 426 return folderImage_;
427 427
428 const SkBitmap& favIcon = bookmarkModel_->GetFavIcon(node); 428 const SkBitmap& favIcon = bookmarkModel_->GetFavIcon(node);
429 if (!favIcon.isNull()) 429 if (!favIcon.isNull())
430 return gfx::SkBitmapToNSImage(favIcon); 430 return gfx::SkBitmapToNSImage(favIcon);
431 431
432 return defaultImage_; 432 return defaultImage_;
433 } 433 }
434 434
435 - (void)performPeriodicDraggingUpdates:(id<NSDraggingInfo>)info {
436 NSLog(@"performPeriodicDraggingUpdates Ran!");
437 // Get the button being dragged from the pasteboard
438 NSData* data = [[info draggingPasteboard]
439 dataForType:kBookmarkButtonDragType];
440
441 if (data && [info draggingSource]) {
442 BookmarkButton* sourceButton = nil;
443 [data getBytes:&sourceButton length:sizeof(sourceButton)];
444
445 NSRect dragButtonFrame = [sourceButton frame];
446
447 // Get the offset amount that other buttons will be moved
448 CGFloat xOffset =
449 NSWidth(dragButtonFrame) + bookmarks::kBookmarkHorizontalPadding;
450
451 // Get the current point the mouse located at during the drag
452 NSPoint point = [info draggingLocation];
453
454 NSArray* array = buttons_.get();
455 NSUInteger startIndex = [array indexOfObject:sourceButton];
456
457 for (BookmarkButton* button in array) {
458 NSRect buttonFrame = [button frame];
459 NSUInteger endIndex = [array indexOfObject:button];
460 if (NSMinX(buttonFrame) < point.x && NSMaxX(buttonFrame) > point.x) {
461 if (endIndex < startIndex && NSMidX(buttonFrame) > point.x) {
462 buttonFrame.origin.x += xOffset;
463 [button setFrame:buttonFrame];
464 } else if (startIndex < endIndex && NSMidX(buttonFrame) < point.x) {
465 buttonFrame.origin.x -= xOffset;
466 [button setFrame:buttonFrame];
467 }
468 }
469 }
470 }
471 }
472
435 - (void)closeFolderAndStopTrackingMenus { 473 - (void)closeFolderAndStopTrackingMenus {
436 showFolderMenus_ = NO; 474 showFolderMenus_ = NO;
437 [self closeAllBookmarkFolders]; 475 [self closeAllBookmarkFolders];
438 } 476 }
439 477
440 #pragma mark Actions 478 #pragma mark Actions
441 479
442 - (IBAction)openBookmark:(id)sender { 480 - (IBAction)openBookmark:(id)sender {
443 [self closeFolderAndStopTrackingMenus]; 481 [self closeFolderAndStopTrackingMenus];
444 DCHECK([sender respondsToSelector:@selector(bookmarkNode)]); 482 DCHECK([sender respondsToSelector:@selector(bookmarkNode)]);
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 if (fromIndex != toIndex) { 2246 if (fromIndex != toIndex) {
2209 NSInteger buttonCount = (NSInteger)[buttons_ count]; 2247 NSInteger buttonCount = (NSInteger)[buttons_ count];
2210 if (toIndex == -1) 2248 if (toIndex == -1)
2211 toIndex = buttonCount; 2249 toIndex = buttonCount;
2212 // See if we have a simple move within the bar, which will be the case if 2250 // See if we have a simple move within the bar, which will be the case if
2213 // both button indexes are in the visible space. 2251 // both button indexes are in the visible space.
2214 if (fromIndex < buttonCount && toIndex < buttonCount) { 2252 if (fromIndex < buttonCount && toIndex < buttonCount) {
2215 BookmarkButton* movedButton = [buttons_ objectAtIndex:fromIndex]; 2253 BookmarkButton* movedButton = [buttons_ objectAtIndex:fromIndex];
2216 NSRect movedFrame = [movedButton frame]; 2254 NSRect movedFrame = [movedButton frame];
2217 NSPoint toOrigin = movedFrame.origin; 2255 NSPoint toOrigin = movedFrame.origin;
2218 CGFloat xOffset =
2219 NSWidth(movedFrame) + bookmarks::kBookmarkHorizontalPadding;
2220 // Hide the button to reduce flickering while drawing the window. 2256 // Hide the button to reduce flickering while drawing the window.
2221 [movedButton setHidden:YES]; 2257 [movedButton setHidden:YES];
2222 [buttons_ removeObjectAtIndex:fromIndex]; 2258 [buttons_ removeObjectAtIndex:fromIndex];
2223 if (fromIndex < toIndex) { 2259 if (fromIndex < toIndex) {
2224 // Move the button from left to right within the bar. 2260 // Move the button from left to right within the bar.
2225 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex - 1]; 2261 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex - 1];
2226 NSRect toFrame = [targetButton frame]; 2262 NSRect toFrame = [targetButton frame];
2227 toOrigin.x = toFrame.origin.x - NSWidth(movedFrame) + NSWidth(toFrame); 2263 toOrigin.x = toFrame.origin.x + NSWidth(toFrame);
2228 for (NSInteger i = fromIndex; i < toIndex; ++i) {
2229 BookmarkButton* button = [buttons_ objectAtIndex:i];
2230 NSRect frame = [button frame];
2231 frame.origin.x -= xOffset;
2232 [button setFrameOrigin:frame.origin];
2233 }
2234 } else { 2264 } else {
2235 // Move the button from right to left within the bar. 2265 // Move the button from right to left within the bar.
2236 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex]; 2266 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex];
2237 toOrigin = [targetButton frame].origin; 2267 NSRect toFrame = [targetButton frame];
2238 for (NSInteger i = fromIndex - 1; i >= toIndex; --i) { 2268 toOrigin.x = toFrame.origin.x - NSWidth(movedFrame);
2239 BookmarkButton* button = [buttons_ objectAtIndex:i];
2240 NSRect buttonFrame = [button frame];
2241 buttonFrame.origin.x += xOffset;
2242 [button setFrameOrigin:buttonFrame.origin];
2243 }
2244 } 2269 }
2245 [buttons_ insertObject:movedButton atIndex:toIndex]; 2270 [buttons_ insertObject:movedButton atIndex:toIndex];
2246 [movedButton setFrameOrigin:toOrigin]; 2271 [movedButton setFrameOrigin:toOrigin];
2247 [movedButton setHidden:NO]; 2272 [movedButton setHidden:NO];
2248 } else if (fromIndex < buttonCount) { 2273 } else if (fromIndex < buttonCount) {
2249 // A button is being removed from the bar and added to off-the-side. 2274 // A button is being removed from the bar and added to off-the-side.
2250 // By now the node has already been inserted into the model so the 2275 // By now the node has already been inserted into the model so the
2251 // button to be added is represented by |toIndex|. Things get 2276 // button to be added is represented by |toIndex|. Things get
2252 // complicated because the off-the-side is showing and must be redrawn 2277 // complicated because the off-the-side is showing and must be redrawn
2253 // while possibly re-laying out the bookmark bar. 2278 // while possibly re-laying out the bookmark bar.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 // to minimize touching the object passed in (likely a mock). 2363 // to minimize touching the object passed in (likely a mock).
2339 - (void)setButtonContextMenu:(id)menu { 2364 - (void)setButtonContextMenu:(id)menu {
2340 buttonContextMenu_ = menu; 2365 buttonContextMenu_ = menu;
2341 } 2366 }
2342 2367
2343 - (void)setIgnoreAnimations:(BOOL)ignore { 2368 - (void)setIgnoreAnimations:(BOOL)ignore {
2344 ignoreAnimations_ = ignore; 2369 ignoreAnimations_ = ignore;
2345 } 2370 }
2346 2371
2347 @end 2372 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_controller.h ('k') | chrome/browser/cocoa/bookmark_bar_view.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698