| OLD | NEW |
| 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 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 bookmarks::kBookmarkHorizontalPadding; | 1364 bookmarks::kBookmarkHorizontalPadding; |
| 1365 | 1365 |
| 1366 // As a result of pasting or dragging, the bar may now have more buttons | 1366 // As a result of pasting or dragging, the bar may now have more buttons |
| 1367 // than will fit so remove any which overflow. They will be shown in | 1367 // than will fit so remove any which overflow. They will be shown in |
| 1368 // the off-the-side folder. | 1368 // the off-the-side folder. |
| 1369 while (displayedButtonCount_ > 0) { | 1369 while (displayedButtonCount_ > 0) { |
| 1370 BookmarkButton* button = [buttons_ lastObject]; | 1370 BookmarkButton* button = [buttons_ lastObject]; |
| 1371 if (NSMaxX([button frame]) < maxViewX) | 1371 if (NSMaxX([button frame]) < maxViewX) |
| 1372 break; | 1372 break; |
| 1373 [buttons_ removeLastObject]; | 1373 [buttons_ removeLastObject]; |
| 1374 [button setDelegate:nil]; |
| 1374 [button removeFromSuperview]; | 1375 [button removeFromSuperview]; |
| 1375 --displayedButtonCount_; | 1376 --displayedButtonCount_; |
| 1376 } | 1377 } |
| 1377 | 1378 |
| 1378 // As a result of cutting, deleting and dragging, the bar may now have room | 1379 // As a result of cutting, deleting and dragging, the bar may now have room |
| 1379 // for more buttons. | 1380 // for more buttons. |
| 1380 int xOffset = displayedButtonCount_ > 0 ? | 1381 int xOffset = displayedButtonCount_ > 0 ? |
| 1381 NSMaxX([[buttons_ lastObject] frame]) + | 1382 NSMaxX([[buttons_ lastObject] frame]) + |
| 1382 bookmarks::kBookmarkHorizontalPadding : 0; | 1383 bookmarks::kBookmarkHorizontalPadding : 0; |
| 1383 for (int i = displayedButtonCount_; i < barCount; ++i) { | 1384 for (int i = displayedButtonCount_; i < barCount; ++i) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 return folderTarget_.get(); | 1432 return folderTarget_.get(); |
| 1432 } | 1433 } |
| 1433 | 1434 |
| 1434 - (int)displayedButtonCount { | 1435 - (int)displayedButtonCount { |
| 1435 return displayedButtonCount_; | 1436 return displayedButtonCount_; |
| 1436 } | 1437 } |
| 1437 | 1438 |
| 1438 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the | 1439 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the |
| 1439 // bookmark bar; reset knowledge of bookmarks. | 1440 // bookmark bar; reset knowledge of bookmarks. |
| 1440 - (void)clearBookmarkBar { | 1441 - (void)clearBookmarkBar { |
| 1441 [buttons_ makeObjectsPerformSelector:@selector(removeFromSuperview)]; | 1442 for (BookmarkButton* button in buttons_.get()) { |
| 1443 [button setDelegate:nil]; |
| 1444 [button removeFromSuperview]; |
| 1445 } |
| 1442 [buttons_ removeAllObjects]; | 1446 [buttons_ removeAllObjects]; |
| 1443 [self clearMenuTagMap]; | 1447 [self clearMenuTagMap]; |
| 1444 displayedButtonCount_ = 0; | 1448 displayedButtonCount_ = 0; |
| 1445 | 1449 |
| 1446 // Make sure there are no stale pointers in the pasteboard. This | 1450 // Make sure there are no stale pointers in the pasteboard. This |
| 1447 // can be important if a bookmark is deleted (via bookmark sync) | 1451 // can be important if a bookmark is deleted (via bookmark sync) |
| 1448 // while in the middle of a drag. The "drag completed" code | 1452 // while in the middle of a drag. The "drag completed" code |
| 1449 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is | 1453 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is |
| 1450 // careful enough to bail if there is no data found at "drop" time. | 1454 // careful enough to bail if there is no data found at "drop" time. |
| 1451 // | 1455 // |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2370 BookmarkButton* oldButton = [buttons_ objectAtIndex:buttonIndex]; | 2374 BookmarkButton* oldButton = [buttons_ objectAtIndex:buttonIndex]; |
| 2371 if (oldButton == [folderController_ parentButton]) { | 2375 if (oldButton == [folderController_ parentButton]) { |
| 2372 // If we are deleting a button whose folder is currently open, close it! | 2376 // If we are deleting a button whose folder is currently open, close it! |
| 2373 [self closeAllBookmarkFolders]; | 2377 [self closeAllBookmarkFolders]; |
| 2374 } | 2378 } |
| 2375 NSRect poofFrame = [oldButton bounds]; | 2379 NSRect poofFrame = [oldButton bounds]; |
| 2376 NSPoint poofPoint = NSMakePoint(NSMidX(poofFrame), NSMidY(poofFrame)); | 2380 NSPoint poofPoint = NSMakePoint(NSMidX(poofFrame), NSMidY(poofFrame)); |
| 2377 poofPoint = [oldButton convertPoint:poofPoint toView:nil]; | 2381 poofPoint = [oldButton convertPoint:poofPoint toView:nil]; |
| 2378 poofPoint = [[oldButton window] convertBaseToScreen:poofPoint]; | 2382 poofPoint = [[oldButton window] convertBaseToScreen:poofPoint]; |
| 2379 NSRect oldFrame = [oldButton frame]; | 2383 NSRect oldFrame = [oldButton frame]; |
| 2384 [oldButton setDelegate:nil]; |
| 2380 [oldButton removeFromSuperview]; | 2385 [oldButton removeFromSuperview]; |
| 2381 if (animate && !ignoreAnimations_ && [self isVisible]) | 2386 if (animate && !ignoreAnimations_ && [self isVisible]) |
| 2382 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, | 2387 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, |
| 2383 NSZeroSize, nil, nil, nil); | 2388 NSZeroSize, nil, nil, nil); |
| 2384 CGFloat xOffset = NSWidth(oldFrame) + bookmarks::kBookmarkHorizontalPadding; | 2389 CGFloat xOffset = NSWidth(oldFrame) + bookmarks::kBookmarkHorizontalPadding; |
| 2385 [buttons_ removeObjectAtIndex:buttonIndex]; | 2390 [buttons_ removeObjectAtIndex:buttonIndex]; |
| 2386 NSUInteger buttonCount = [buttons_ count]; | 2391 NSUInteger buttonCount = [buttons_ count]; |
| 2387 for (NSUInteger i = buttonIndex; i < buttonCount; ++i) { | 2392 for (NSUInteger i = buttonIndex; i < buttonCount; ++i) { |
| 2388 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 2393 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 2389 NSRect buttonFrame = [button frame]; | 2394 NSRect buttonFrame = [button frame]; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 // to minimize touching the object passed in (likely a mock). | 2435 // to minimize touching the object passed in (likely a mock). |
| 2431 - (void)setButtonContextMenu:(id)menu { | 2436 - (void)setButtonContextMenu:(id)menu { |
| 2432 buttonContextMenu_ = menu; | 2437 buttonContextMenu_ = menu; |
| 2433 } | 2438 } |
| 2434 | 2439 |
| 2435 - (void)setIgnoreAnimations:(BOOL)ignore { | 2440 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 2436 ignoreAnimations_ = ignore; | 2441 ignoreAnimations_ = ignore; |
| 2437 } | 2442 } |
| 2438 | 2443 |
| 2439 @end | 2444 @end |
| OLD | NEW |