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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
===================================================================
--- chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm (revision 83097)
+++ chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm (working copy)
@@ -1393,6 +1393,35 @@
}
}
+// Scans through all buttons from left to right, calculating from scratch where
+// they should be based on the preceding widths, until it finds the one
+// requested.
+// Returns NSZeroRect if there is no such button in the bookmark bar.
+// Enables you to work out where a button will end up when it is done animating.
+- (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton {
+ CGFloat left = bookmarks::kBookmarkHorizontalPadding;
+ NSRect buttonFrame = NSZeroRect;
+
+ for (NSButton* button in buttons_.get()) {
+ // Hidden buttons get no space.
+ if ([button isHidden])
+ continue;
+ buttonFrame = [button frame];
+ buttonFrame.origin.x = left;
+ left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding;
+ if (button == wantedButton)
+ return buttonFrame;
+ }
+ return NSZeroRect;
+}
+
+// Calculates the final position of the last button in the bar.
+// We can't just use [[self buttons] lastObject] frame] because the button
+// may be animating currently.
+- (NSRect)finalRectOfLastButton {
+ return [self finalRectOfButton:[[self buttons] lastObject]];
+}
+
- (void)redistributeButtonsOnBarAsNeeded {
const BookmarkNode* node = bookmarkModel_->GetBookmarkBarNode();
NSInteger barCount = node->GetChildCount();
@@ -1414,7 +1443,7 @@
// the off-the-side folder.
while (displayedButtonCount_ > 0) {
BookmarkButton* button = [buttons_ lastObject];
- if (NSMaxX([button frame]) < maxViewX)
+ if (NSMaxX([self finalRectOfLastButton]) < maxViewX)
break;
[buttons_ removeLastObject];
[button setDelegate:nil];
@@ -1425,7 +1454,7 @@
// As a result of cutting, deleting and dragging, the bar may now have room
// for more buttons.
int xOffset = displayedButtonCount_ > 0 ?
- NSMaxX([[buttons_ lastObject] frame]) +
+ NSMaxX([self finalRectOfLastButton]) +
bookmarks::kBookmarkHorizontalPadding : 0;
for (int i = displayedButtonCount_; i < barCount; ++i) {
const BookmarkNode* child = node->GetChild(i);
« 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