| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_folder_controller.h" | 5 #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" |
| 6 #include "base/mac_util.h" | 6 #include "base/mac_util.h" |
| 7 #include "base/nsimage_cache_mac.h" | 7 #include "base/nsimage_cache_mac.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| (...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 [folderController_ showWindow:self]; | 1205 [folderController_ showWindow:self]; |
| 1206 } | 1206 } |
| 1207 | 1207 |
| 1208 - (void)openAll:(const BookmarkNode*)node | 1208 - (void)openAll:(const BookmarkNode*)node |
| 1209 disposition:(WindowOpenDisposition)disposition { | 1209 disposition:(WindowOpenDisposition)disposition { |
| 1210 [barController_ openAll:node disposition:disposition]; | 1210 [barController_ openAll:node disposition:disposition]; |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 - (void)addButtonForNode:(const BookmarkNode*)node | 1213 - (void)addButtonForNode:(const BookmarkNode*)node |
| 1214 atIndex:(NSInteger)buttonIndex { | 1214 atIndex:(NSInteger)buttonIndex { |
| 1215 NSRect buttonFrame = NSMakeRect(bookmarks::kBookmarkHorizontalPadding, | 1215 // Propose the frame for the new button. |
| 1216 bookmarks::kBookmarkVerticalPadding, | 1216 NSRect newButtonFrame = NSMakeRect(0, 0, 500, 500); // Placeholder values. |
| 1217 NSWidth([mainView_ frame]) - 2 * bookmarks::kBookmarkHorizontalPadding - | |
| 1218 bookmarks::kScrollViewContentWidthMargin, | |
| 1219 bookmarks::kBookmarkBarHeight - 2 * | |
| 1220 bookmarks::kBookmarkVerticalPadding); | |
| 1221 // When adding a button to an empty folder we must remove the 'empty' | 1217 // When adding a button to an empty folder we must remove the 'empty' |
| 1222 // placeholder button. This can be detected by checking for a parent | 1218 // placeholder button. This can be detected by checking for a parent |
| 1223 // child count of 1. | 1219 // child count of 1. |
| 1224 const BookmarkNode* parentNode = node->GetParent(); | 1220 const BookmarkNode* parentNode = node->GetParent(); |
| 1225 if (parentNode->GetChildCount() == 1) { | 1221 if (parentNode->GetChildCount() == 1) { |
| 1226 BookmarkButton* emptyButton = [buttons_ lastObject]; | 1222 BookmarkButton* emptyButton = [buttons_ lastObject]; |
| 1223 newButtonFrame = [emptyButton frame]; |
| 1227 [emptyButton removeFromSuperview]; | 1224 [emptyButton removeFromSuperview]; |
| 1228 [buttons_ removeLastObject]; | 1225 [buttons_ removeLastObject]; |
| 1229 } else { | |
| 1230 // Set us up to remember the last moved button's frame. | |
| 1231 buttonFrame.origin.y += NSHeight([mainView_ frame]) + | |
| 1232 bookmarks::kBookmarkBarHeight; | |
| 1233 } | 1226 } |
| 1234 | 1227 |
| 1235 if (buttonIndex == -1) | 1228 if (buttonIndex == -1) |
| 1236 buttonIndex = [buttons_ count]; | 1229 buttonIndex = [buttons_ count]; |
| 1237 | 1230 |
| 1231 // Offset upward by one button height all buttons above insertion location. |
| 1238 BookmarkButton* button = nil; // Remember so it can be de-highlighted. | 1232 BookmarkButton* button = nil; // Remember so it can be de-highlighted. |
| 1239 for (NSInteger i = 0; i < buttonIndex; ++i) { | 1233 for (NSInteger i = 0; i < buttonIndex; ++i) { |
| 1240 button = [buttons_ objectAtIndex:i]; | 1234 button = [buttons_ objectAtIndex:i]; |
| 1241 buttonFrame = [button frame]; | 1235 // Remember this location in case it's the last button being moved |
| 1242 buttonFrame.origin.y += bookmarks::kBookmarkBarHeight; | 1236 // which is where the new button will be located. |
| 1237 newButtonFrame = [button frame]; |
| 1238 NSRect buttonFrame = [button frame]; |
| 1239 buttonFrame.origin.y += bookmarks::kBookmarkBarHeight + |
| 1240 bookmarks::kBookmarkVerticalPadding; |
| 1243 [button setFrame:buttonFrame]; | 1241 [button setFrame:buttonFrame]; |
| 1244 } | 1242 } |
| 1245 [[button cell] mouseExited:nil]; // De-highlight. | 1243 [[button cell] mouseExited:nil]; // De-highlight. |
| 1246 if (parentNode->GetChildCount() > 1) | |
| 1247 buttonFrame.origin.y -= bookmarks::kBookmarkBarHeight; | |
| 1248 BookmarkButton* newButton = [self makeButtonForNode:node | 1244 BookmarkButton* newButton = [self makeButtonForNode:node |
| 1249 frame:buttonFrame]; | 1245 frame:newButtonFrame]; |
| 1250 [buttons_ insertObject:newButton atIndex:buttonIndex]; | 1246 [buttons_ insertObject:newButton atIndex:buttonIndex]; |
| 1251 [mainView_ addSubview:newButton]; | 1247 [mainView_ addSubview:newButton]; |
| 1252 | 1248 |
| 1253 // Close any child folder(s) which may still be open. | 1249 // Close any child folder(s) which may still be open. |
| 1254 [self closeBookmarkFolder:self]; | 1250 [self closeBookmarkFolder:self]; |
| 1255 | 1251 |
| 1256 // Prelim height of the window. We'll trim later as needed. | 1252 // Prelim height of the window. We'll trim later as needed. |
| 1257 int height = [buttons_ count] * bookmarks::kBookmarkButtonHeight + | 1253 int height = [buttons_ count] * bookmarks::kBookmarkButtonHeight + |
| 1258 bookmarks::kBookmarkVerticalPadding; | 1254 bookmarks::kBookmarkVerticalPadding; |
| 1259 [self adjustWindowForHeight:height]; | 1255 [self adjustWindowForHeight:height]; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 [buttons_ removeObjectAtIndex:fromIndex]; | 1305 [buttons_ removeObjectAtIndex:fromIndex]; |
| 1310 NSRect movedFrame = [movedButton frame]; | 1306 NSRect movedFrame = [movedButton frame]; |
| 1311 NSPoint toOrigin = movedFrame.origin; | 1307 NSPoint toOrigin = movedFrame.origin; |
| 1312 [movedButton setHidden:YES]; | 1308 [movedButton setHidden:YES]; |
| 1313 if (fromIndex < toIndex) { | 1309 if (fromIndex < toIndex) { |
| 1314 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex - 1]; | 1310 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex - 1]; |
| 1315 toOrigin = [targetButton frame].origin; | 1311 toOrigin = [targetButton frame].origin; |
| 1316 for (NSInteger i = fromIndex; i < toIndex; ++i) { | 1312 for (NSInteger i = fromIndex; i < toIndex; ++i) { |
| 1317 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 1313 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 1318 NSRect frame = [button frame]; | 1314 NSRect frame = [button frame]; |
| 1319 frame.origin.y += bookmarks::kBookmarkBarHeight; | 1315 frame.origin.y += bookmarks::kBookmarkBarHeight + |
| 1316 bookmarks::kBookmarkVerticalPadding; |
| 1320 [button setFrameOrigin:frame.origin]; | 1317 [button setFrameOrigin:frame.origin]; |
| 1321 } | 1318 } |
| 1322 } else { | 1319 } else { |
| 1323 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex]; | 1320 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex]; |
| 1324 toOrigin = [targetButton frame].origin; | 1321 toOrigin = [targetButton frame].origin; |
| 1325 for (NSInteger i = fromIndex - 1; i >= toIndex; --i) { | 1322 for (NSInteger i = fromIndex - 1; i >= toIndex; --i) { |
| 1326 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 1323 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 1327 NSRect buttonFrame = [button frame]; | 1324 NSRect buttonFrame = [button frame]; |
| 1328 buttonFrame.origin.y -= bookmarks::kBookmarkBarHeight; | 1325 buttonFrame.origin.y -= bookmarks::kBookmarkBarHeight + |
| 1326 bookmarks::kBookmarkVerticalPadding; |
| 1329 [button setFrameOrigin:buttonFrame.origin]; | 1327 [button setFrameOrigin:buttonFrame.origin]; |
| 1330 } | 1328 } |
| 1331 } | 1329 } |
| 1332 [buttons_ insertObject:movedButton atIndex:toIndex]; | 1330 [buttons_ insertObject:movedButton atIndex:toIndex]; |
| 1333 [movedButton setFrameOrigin:toOrigin]; | 1331 [movedButton setFrameOrigin:toOrigin]; |
| 1334 [movedButton setHidden:NO]; | 1332 [movedButton setHidden:NO]; |
| 1335 } | 1333 } |
| 1336 } | 1334 } |
| 1337 | 1335 |
| 1338 // TODO(jrg): Refactor BookmarkBarFolder common code. http://crbug.com/35966 | 1336 // TODO(jrg): Refactor BookmarkBarFolder common code. http://crbug.com/35966 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1351 } | 1349 } |
| 1352 | 1350 |
| 1353 [oldButton removeFromSuperview]; | 1351 [oldButton removeFromSuperview]; |
| 1354 if (animate && !ignoreAnimations_) | 1352 if (animate && !ignoreAnimations_) |
| 1355 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, | 1353 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, |
| 1356 NSZeroSize, nil, nil, nil); | 1354 NSZeroSize, nil, nil, nil); |
| 1357 [buttons_ removeObjectAtIndex:buttonIndex]; | 1355 [buttons_ removeObjectAtIndex:buttonIndex]; |
| 1358 for (NSInteger i = 0; i < buttonIndex; ++i) { | 1356 for (NSInteger i = 0; i < buttonIndex; ++i) { |
| 1359 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 1357 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 1360 NSRect buttonFrame = [button frame]; | 1358 NSRect buttonFrame = [button frame]; |
| 1361 buttonFrame.origin.y -= bookmarks::kBookmarkBarHeight; | 1359 buttonFrame.origin.y -= bookmarks::kBookmarkBarHeight + |
| 1360 bookmarks::kBookmarkVerticalPadding; |
| 1362 [button setFrame:buttonFrame]; | 1361 [button setFrame:buttonFrame]; |
| 1363 } | 1362 } |
| 1364 // Search for and adjust submenus, if necessary. | 1363 // Search for and adjust submenus, if necessary. |
| 1365 NSInteger buttonCount = [buttons_ count]; | 1364 NSInteger buttonCount = [buttons_ count]; |
| 1366 if (buttonCount) { | 1365 if (buttonCount) { |
| 1367 BookmarkButton* subButton = [folderController_ parentButton]; | 1366 BookmarkButton* subButton = [folderController_ parentButton]; |
| 1368 for (NSInteger i = buttonIndex; i < buttonCount; ++i) { | 1367 for (NSInteger i = buttonIndex; i < buttonCount; ++i) { |
| 1369 BookmarkButton* aButton = [buttons_ objectAtIndex:i]; | 1368 BookmarkButton* aButton = [buttons_ objectAtIndex:i]; |
| 1370 // If this button is showing its menu then we need to move the menu, too. | 1369 // If this button is showing its menu then we need to move the menu, too. |
| 1371 if (aButton == subButton) | 1370 if (aButton == subButton) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 | 1407 |
| 1409 - (void)setIgnoreAnimations:(BOOL)ignore { | 1408 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 1410 ignoreAnimations_ = ignore; | 1409 ignoreAnimations_ = ignore; |
| 1411 } | 1410 } |
| 1412 | 1411 |
| 1413 - (BookmarkButton*)buttonThatMouseIsIn { | 1412 - (BookmarkButton*)buttonThatMouseIsIn { |
| 1414 return buttonThatMouseIsIn_; | 1413 return buttonThatMouseIsIn_; |
| 1415 } | 1414 } |
| 1416 | 1415 |
| 1417 @end // BookmarkBarFolderController | 1416 @end // BookmarkBarFolderController |
| OLD | NEW |