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

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

Issue 6903056: Fix redistributeButtonsOnBarAsNeeded to not be confused by animation. Fixes bug where adding or d... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/696/src/
Patch Set: '' Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.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 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 [noItemTextfield setHidden:NO]; 1386 [noItemTextfield setHidden:NO];
1387 NSButton* importBookmarksButton = [buttonView_ importBookmarksButton]; 1387 NSButton* importBookmarksButton = [buttonView_ importBookmarksButton];
1388 [importBookmarksButton setFrame:originalImportBookmarksRect_]; 1388 [importBookmarksButton setFrame:originalImportBookmarksRect_];
1389 [importBookmarksButton setHidden:NO]; 1389 [importBookmarksButton setHidden:NO];
1390 // Check each to see if they need to be shrunk or hidden. 1390 // Check each to see if they need to be shrunk or hidden.
1391 if ([self shrinkOrHideView:importBookmarksButton forMaxX:maxViewX]) 1391 if ([self shrinkOrHideView:importBookmarksButton forMaxX:maxViewX])
1392 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX]; 1392 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX];
1393 } 1393 }
1394 } 1394 }
1395 1395
1396 // Scans through all buttons from left to right, calculating from scratch where
1397 // they should be based on the preceding widths, until it finds the one
1398 // requested.
1399 // Returns NSZeroRect if there is no such button in the bookmark bar.
1400 // Enables you to work out where a button will end up when it is done animating.
1401 - (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton {
1402 CGFloat left = bookmarks::kBookmarkHorizontalPadding;
1403 NSRect buttonFrame = NSZeroRect;
1404
1405 for (NSButton* button in buttons_.get()) {
1406 // Hidden buttons get no space.
1407 if ([button isHidden])
1408 continue;
1409 buttonFrame = [button frame];
1410 buttonFrame.origin.x = left;
1411 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding;
1412 if (button == wantedButton)
1413 return buttonFrame;
1414 }
1415 return NSZeroRect;
1416 }
1417
1418 // Calculates the final position of the last button in the bar.
1419 // We can't just use [[self buttons] lastObject] frame] because the button
1420 // may be animating currently.
1421 - (NSRect)finalRectOfLastButton {
1422 return [self finalRectOfButton:[[self buttons] lastObject]];
1423 }
1424
1396 - (void)redistributeButtonsOnBarAsNeeded { 1425 - (void)redistributeButtonsOnBarAsNeeded {
1397 const BookmarkNode* node = bookmarkModel_->GetBookmarkBarNode(); 1426 const BookmarkNode* node = bookmarkModel_->GetBookmarkBarNode();
1398 NSInteger barCount = node->GetChildCount(); 1427 NSInteger barCount = node->GetChildCount();
1399 1428
1400 // Determine the current maximum extent of the visible buttons. 1429 // Determine the current maximum extent of the visible buttons.
1401 CGFloat maxViewX = NSMaxX([[self view] bounds]); 1430 CGFloat maxViewX = NSMaxX([[self view] bounds]);
1402 NSButton* otherBookmarksButton = otherBookmarksButton_.get(); 1431 NSButton* otherBookmarksButton = otherBookmarksButton_.get();
1403 // If necessary, pull in the width to account for the Other Bookmarks button. 1432 // If necessary, pull in the width to account for the Other Bookmarks button.
1404 if (otherBookmarksButton_) 1433 if (otherBookmarksButton_)
1405 maxViewX = [otherBookmarksButton frame].origin.x - 1434 maxViewX = [otherBookmarksButton frame].origin.x -
1406 bookmarks::kBookmarkHorizontalPadding; 1435 bookmarks::kBookmarkHorizontalPadding;
1407 // If we're already overflowing, then we need to account for the chevron. 1436 // If we're already overflowing, then we need to account for the chevron.
1408 if (barCount > displayedButtonCount_) 1437 if (barCount > displayedButtonCount_)
1409 maxViewX = [offTheSideButton_ frame].origin.x - 1438 maxViewX = [offTheSideButton_ frame].origin.x -
1410 bookmarks::kBookmarkHorizontalPadding; 1439 bookmarks::kBookmarkHorizontalPadding;
1411 1440
1412 // As a result of pasting or dragging, the bar may now have more buttons 1441 // As a result of pasting or dragging, the bar may now have more buttons
1413 // than will fit so remove any which overflow. They will be shown in 1442 // than will fit so remove any which overflow. They will be shown in
1414 // the off-the-side folder. 1443 // the off-the-side folder.
1415 while (displayedButtonCount_ > 0) { 1444 while (displayedButtonCount_ > 0) {
1416 BookmarkButton* button = [buttons_ lastObject]; 1445 BookmarkButton* button = [buttons_ lastObject];
1417 if (NSMaxX([button frame]) < maxViewX) 1446 if (NSMaxX([self finalRectOfLastButton]) < maxViewX)
1418 break; 1447 break;
1419 [buttons_ removeLastObject]; 1448 [buttons_ removeLastObject];
1420 [button setDelegate:nil]; 1449 [button setDelegate:nil];
1421 [button removeFromSuperview]; 1450 [button removeFromSuperview];
1422 --displayedButtonCount_; 1451 --displayedButtonCount_;
1423 } 1452 }
1424 1453
1425 // As a result of cutting, deleting and dragging, the bar may now have room 1454 // As a result of cutting, deleting and dragging, the bar may now have room
1426 // for more buttons. 1455 // for more buttons.
1427 int xOffset = displayedButtonCount_ > 0 ? 1456 int xOffset = displayedButtonCount_ > 0 ?
1428 NSMaxX([[buttons_ lastObject] frame]) + 1457 NSMaxX([self finalRectOfLastButton]) +
1429 bookmarks::kBookmarkHorizontalPadding : 0; 1458 bookmarks::kBookmarkHorizontalPadding : 0;
1430 for (int i = displayedButtonCount_; i < barCount; ++i) { 1459 for (int i = displayedButtonCount_; i < barCount; ++i) {
1431 const BookmarkNode* child = node->GetChild(i); 1460 const BookmarkNode* child = node->GetChild(i);
1432 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 1461 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
1433 // If we're testing against the last possible button then account 1462 // If we're testing against the last possible button then account
1434 // for the chevron no longer needing to be shown. 1463 // for the chevron no longer needing to be shown.
1435 if (i == barCount + 1) 1464 if (i == barCount + 1)
1436 maxViewX += NSWidth([offTheSideButton_ frame]) + 1465 maxViewX += NSWidth([offTheSideButton_ frame]) +
1437 bookmarks::kBookmarkHorizontalPadding; 1466 bookmarks::kBookmarkHorizontalPadding;
1438 if (NSMaxX([button frame]) >= maxViewX) 1467 if (NSMaxX([button frame]) >= maxViewX)
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
2494 // to minimize touching the object passed in (likely a mock). 2523 // to minimize touching the object passed in (likely a mock).
2495 - (void)setButtonContextMenu:(id)menu { 2524 - (void)setButtonContextMenu:(id)menu {
2496 buttonContextMenu_ = menu; 2525 buttonContextMenu_ = menu;
2497 } 2526 }
2498 2527
2499 - (void)setIgnoreAnimations:(BOOL)ignore { 2528 - (void)setIgnoreAnimations:(BOOL)ignore {
2500 ignoreAnimations_ = ignore; 2529 ignoreAnimations_ = ignore;
2501 } 2530 }
2502 2531
2503 @end 2532 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698