Chromium Code Reviews| 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/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
| 6 | 6 |
| 7 #include "app/mac/nsimage_cache.h" | |
| 8 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 12 #import "chrome/browser/themes/browser_theme_provider.h" | 11 #import "chrome/browser/themes/browser_theme_provider.h" |
| 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
| 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" | 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" |
| 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" | 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" |
| 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" |
| 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | |
| 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
| 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 20 #import "chrome/browser/ui/cocoa/event_utils.h" | 20 #import "chrome/browser/ui/cocoa/event_utils.h" |
| 21 | 21 |
| 22 using bookmarks::kBookmarkBarMenuCornerRadius; | |
| 23 | |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // Frequency of the scrolling timer in seconds. | 26 // Frequency of the scrolling timer in seconds. |
| 25 const NSTimeInterval kBookmarkBarFolderScrollInterval = 0.1; | 27 const NSTimeInterval kBookmarkBarFolderScrollInterval = 0.1; |
| 26 | 28 |
| 27 // Amount to scroll by per timer fire. We scroll rather slowly; to | 29 // Amount to scroll by per timer fire. We scroll rather slowly; to |
| 28 // accomodate we do several at a time. | 30 // accomodate we do several at a time. |
| 29 const CGFloat kBookmarkBarFolderScrollAmount = | 31 const CGFloat kBookmarkBarFolderScrollAmount = |
| 30 3 * bookmarks::kBookmarkButtonVerticalSpan; | 32 3 * bookmarks::kBookmarkButtonVerticalSpan; |
| 31 | 33 |
| 32 // Amount to scroll for each scroll wheel delta. | 34 // Amount to scroll for each scroll wheel roll. |
| 33 const CGFloat kBookmarkBarFolderScrollWheelAmount = | 35 const CGFloat kBookmarkBarFolderScrollWheelAmount = |
| 34 1 * bookmarks::kBookmarkButtonVerticalSpan; | 36 1 * bookmarks::kBookmarkButtonVerticalSpan; |
| 35 | 37 |
| 36 // When constraining a scrolling bookmark bar folder window to the | |
| 37 // screen, shrink the "constrain" by this much vertically. Currently | |
| 38 // this is 0.0 to avoid a problem with tracking areas leaving the | |
| 39 // window, but should probably be 8.0 or something. | |
| 40 // TODO(jrg): http://crbug.com/36225 | |
| 41 const CGFloat kScrollWindowVerticalMargin = 0.0; | |
| 42 | |
| 43 } // namespace | 38 } // namespace |
| 44 | 39 |
| 45 @interface BookmarkBarFolderController(Private) | 40 @interface BookmarkBarFolderController(Private) |
| 46 - (void)configureWindow; | 41 - (void)configureWindow; |
| 47 - (void)addOrUpdateScrollTracking; | 42 - (void)addOrUpdateScrollTracking; |
| 48 - (void)removeScrollTracking; | 43 - (void)removeScrollTracking; |
| 49 - (void)endScroll; | 44 - (void)endScroll; |
| 50 - (void)addScrollTimerWithDelta:(CGFloat)delta; | 45 - (void)addScrollTimerWithDelta:(CGFloat)delta; |
| 51 | 46 |
| 52 // Determine the best button width (which will be the widest button or the | 47 // Determine the best button width (which will be the widest button or the |
| 53 // maximum allowable button width, whichever is less) and resize all buttons. | 48 // maximum allowable button width, whichever is less) and resize all buttons. |
| 54 // Return the new width (so that the window can be adjusted, if necessary). | 49 // Return the new width so that the window can be adjusted. |
| 55 - (CGFloat)adjustButtonWidths; | 50 - (CGFloat)adjustButtonWidths; |
| 56 | 51 |
| 57 // Returns the total menu height needed to display |buttonCount| buttons. | 52 // Returns the total menu height needed to display |buttonCount| buttons. |
| 58 // Does not do any fancy tricks like trimming the height to fit on the screen. | 53 // Does not do any fancy tricks like trimming the height to fit on the screen. |
| 59 - (int)windowHeightForButtonCount:(int)buttonCount; | 54 - (int)menuHeightForButtonCount:(int)buttonCount; |
| 60 | 55 |
| 61 // Adjust the height and horizontal position of the window such that the | 56 // Adjust all of the folder menu window components, showing/hiding the |
| 62 // scroll arrows are shown as needed and the window appears completely | 57 // scroll up/down arrows, and resizing as necessary for a proper disaplay. |
| 63 // on screen. | 58 // In order to reduce window flicker, all layout changes are deferred until |
| 64 - (void)adjustWindowForHeight:(int)windowHeight; | 59 // the final stap of the adjustment. To accommodate this deferral, window |
| 60 // height and width changes needed by callers to this function pass their | |
| 61 // desired window changes in |windowSize|. When scrolling is to be performed | |
|
John Grabowski
2011/01/06 23:30:18
|windowSize| --> |size|
Add a comment saying who s
mrossetti
2011/01/08 01:45:38
Done.
| |
| 62 // any scrolling change is given by |scrollDelta|. The ultimate amount of | |
| 63 // scrolling may be different from |scrollDelta| in order to accommodate | |
| 64 // changes in the scroller view layout. | |
| 65 - (void)adjustWindowLeft:(CGFloat)left | |
| 66 size:(NSSize)size | |
| 67 scrollingBy:(CGFloat)scrollDelta; | |
| 65 | 68 |
| 66 // Show or hide the scroll arrows at the top/bottom of the window. | 69 // This function is called when buttons are added or removed from the folder |
| 67 - (void)showOrHideScrollArrows; | 70 // menu and result in the folder menu window layout being changed accordingly. |
| 71 // |buttonCount| should contain the updated count of menu buttons. | |
| 72 - (void)adjustWindowForButtonCount:(NSUInteger)buttonCount; | |
|
John Grabowski
2011/01/06 23:30:18
State this modifies window size/position.
mrossetti
2011/01/08 01:45:38
Done.
| |
| 73 | |
| 74 // A helper function which takes the desired amount to scroll, given by | |
| 75 // |scrollDelta|, and calculates the actual scrolling change to be applied | |
| 76 // taking into account the layout of the folder menu window and it's | |
| 77 // scrollability. | |
| 78 - (CGFloat)determineFinalScrollDelta:(CGFloat)scrollDelta; | |
|
John Grabowski
2011/01/06 23:30:18
If scrollable, when would the return value be diff
mrossetti
2011/01/08 01:45:38
Done.
| |
| 68 | 79 |
| 69 // |point| is in the base coordinate system of the destination window; | 80 // |point| is in the base coordinate system of the destination window; |
| 70 // it comes from an id<NSDraggingInfo>. |copy| is YES if a copy is to be | 81 // it comes from an id<NSDraggingInfo>. |copy| is YES if a copy is to be |
| 71 // made and inserted into the new location while leaving the bookmark in | 82 // made and inserted into the new location while leaving the bookmark in |
| 72 // the old location, otherwise move the bookmark by removing from its old | 83 // the old location, otherwise move the bookmark by removing from its old |
| 73 // location and inserting into the new location. | 84 // location and inserting into the new location. |
| 74 - (BOOL)dragBookmark:(const BookmarkNode*)sourceNode | 85 - (BOOL)dragBookmark:(const BookmarkNode*)sourceNode |
| 75 to:(NSPoint)point | 86 to:(NSPoint)point |
| 76 copy:(BOOL)copy; | 87 copy:(BOOL)copy; |
| 77 | 88 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 135 |
| 125 parentController_.reset([parentController retain]); | 136 parentController_.reset([parentController retain]); |
| 126 if (!parentController_) | 137 if (!parentController_) |
| 127 [self setSubFolderGrowthToRight:YES]; | 138 [self setSubFolderGrowthToRight:YES]; |
| 128 else | 139 else |
| 129 [self setSubFolderGrowthToRight:[parentController | 140 [self setSubFolderGrowthToRight:[parentController |
| 130 subFolderGrowthToRight]]; | 141 subFolderGrowthToRight]]; |
| 131 barController_ = barController; // WEAK | 142 barController_ = barController; // WEAK |
| 132 buttons_.reset([[NSMutableArray alloc] init]); | 143 buttons_.reset([[NSMutableArray alloc] init]); |
| 133 folderTarget_.reset([[BookmarkFolderTarget alloc] initWithController:self]); | 144 folderTarget_.reset([[BookmarkFolderTarget alloc] initWithController:self]); |
| 134 NSImage* image = app::mac::GetCachedImageWithName(@"menu_overflow_up.pdf"); | |
| 135 DCHECK(image); | |
| 136 verticalScrollArrowHeight_ = [image size].height; | |
| 137 [self configureWindow]; | 145 [self configureWindow]; |
| 138 hoverState_.reset([[BookmarkBarFolderHoverState alloc] init]); | 146 hoverState_.reset([[BookmarkBarFolderHoverState alloc] init]); |
| 139 } | 147 } |
| 140 return self; | 148 return self; |
| 141 } | 149 } |
| 142 | 150 |
| 143 - (void)dealloc { | 151 - (void)dealloc { |
| 144 // The button is no longer part of the menu path. | 152 // The button is no longer part of the menu path. |
| 145 [parentButton_ forceButtonBorderToStayOnAlways:NO]; | 153 [parentButton_ forceButtonBorderToStayOnAlways:NO]; |
| 146 [parentButton_ setNeedsDisplay]; | 154 [parentButton_ setNeedsDisplay]; |
| 147 | 155 |
| 148 [self removeScrollTracking]; | 156 [self removeScrollTracking]; |
| 149 [self endScroll]; | 157 [self endScroll]; |
| 150 [hoverState_ draggingExited]; | 158 [hoverState_ draggingExited]; |
| 151 | 159 |
| 152 // Delegate pattern does not retain; make sure pointers to us are removed. | 160 // Delegate pattern does not retain; make sure pointers to us are removed. |
| 153 for (BookmarkButton* button in buttons_.get()) { | 161 for (BookmarkButton* button in buttons_.get()) { |
| 154 [button setDelegate:nil]; | 162 [button setDelegate:nil]; |
| 155 [button setTarget:nil]; | 163 [button setTarget:nil]; |
| 156 [button setAction:nil]; | 164 [button setAction:nil]; |
| 157 } | 165 } |
| 158 | 166 |
| 159 // Note: we don't need to | 167 // Note: we don't need to |
| 160 // [NSObject cancelPreviousPerformRequestsWithTarget:self]; | 168 // [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
| 161 // Because all of our performSelector: calls use withDelay: which | 169 // Because all of our performSelector: calls use withDelay: which |
| 162 // retains us. | 170 // retains us. |
| 163 [super dealloc]; | 171 [super dealloc]; |
| 164 } | 172 } |
| 165 | 173 |
| 174 - (void)awakeFromNib { | |
| 175 NSRect windowFrame = [[self window] frame]; | |
| 176 NSRect buttonViewFrame = [scrollView_ frame]; | |
| 177 leftPadding_ = buttonViewFrame.origin.x; | |
| 178 rightPadding_ = | |
| 179 NSWidth(windowFrame) - NSWidth(buttonViewFrame) - leftPadding_; | |
| 180 verticalScrollArrowHeight_ = NSHeight([scrollUpArrowView_ frame]); | |
| 181 } | |
| 182 | |
| 166 // Overriden from NSWindowController to call childFolderWillShow: before showing | 183 // Overriden from NSWindowController to call childFolderWillShow: before showing |
| 167 // the window. | 184 // the window. |
| 168 - (void)showWindow:(id)sender { | 185 - (void)showWindow:(id)sender { |
| 169 [barController_ childFolderWillShow:self]; | 186 [barController_ childFolderWillShow:self]; |
| 170 [super showWindow:sender]; | 187 [super showWindow:sender]; |
| 171 } | 188 } |
| 172 | 189 |
| 173 - (BookmarkButton*)parentButton { | 190 - (BookmarkButton*)parentButton { |
| 174 return parentButton_.get(); | 191 return parentButton_.get(); |
| 175 } | 192 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 urlString.c_str()]; | 286 urlString.c_str()]; |
| 270 [button setToolTip:tooltip]; | 287 [button setToolTip:tooltip]; |
| 271 } | 288 } |
| 272 } else { | 289 } else { |
| 273 [button setEnabled:NO]; | 290 [button setEnabled:NO]; |
| 274 [button setBordered:NO]; | 291 [button setBordered:NO]; |
| 275 } | 292 } |
| 276 return button; | 293 return button; |
| 277 } | 294 } |
| 278 | 295 |
| 279 // Exposed for testing. | |
| 280 - (NSView*)mainView { | |
| 281 return mainView_; | |
| 282 } | |
| 283 | |
| 284 - (id)folderTarget { | 296 - (id)folderTarget { |
| 285 return folderTarget_.get(); | 297 return folderTarget_.get(); |
| 286 } | 298 } |
| 287 | 299 |
| 288 | 300 |
| 289 // Our parent controller is another BookmarkBarFolderController, so | 301 // Our parent controller is another BookmarkBarFolderController, so |
| 290 // our window is to the right or left of it. We use a little overlap | 302 // our window is to the right or left of it. We use a little overlap |
| 291 // since it looks much more menu-like than with none. If we would | 303 // since it looks much more menu-like than with none. If we would |
| 292 // grow off the screen, switch growth to the other direction. Growth | 304 // grow off the screen, switch growth to the other direction. Growth |
| 293 // direction sticks for folder windows which are descendents of us. | 305 // direction sticks for folder windows which are descendents of us. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 // is bottom of button's parent view. | 359 // is bottom of button's parent view. |
| 348 NSPoint buttonBottomLeftInScreen = | 360 NSPoint buttonBottomLeftInScreen = |
| 349 [[parentButton_ window] | 361 [[parentButton_ window] |
| 350 convertBaseToScreen:[parentButton_ | 362 convertBaseToScreen:[parentButton_ |
| 351 convertPoint:NSZeroPoint toView:nil]]; | 363 convertPoint:NSZeroPoint toView:nil]]; |
| 352 NSPoint bookmarkBarBottomLeftInScreen = | 364 NSPoint bookmarkBarBottomLeftInScreen = |
| 353 [[parentButton_ window] | 365 [[parentButton_ window] |
| 354 convertBaseToScreen:[[parentButton_ superview] | 366 convertBaseToScreen:[[parentButton_ superview] |
| 355 convertPoint:NSZeroPoint toView:nil]]; | 367 convertPoint:NSZeroPoint toView:nil]]; |
| 356 newWindowTopLeft = NSMakePoint(buttonBottomLeftInScreen.x, | 368 newWindowTopLeft = NSMakePoint(buttonBottomLeftInScreen.x, |
| 357 bookmarkBarBottomLeftInScreen.y); | 369 bookmarkBarBottomLeftInScreen.y + |
| 370 bookmarks::kBookmarkBarMenuOffset); | |
| 358 // Make sure the window is on-screen; if not, push left. It is | 371 // Make sure the window is on-screen; if not, push left. It is |
| 359 // intentional that top level folders "push left" slightly | 372 // intentional that top level folders "push left" slightly |
| 360 // different than subfolders. | 373 // different than subfolders. |
| 361 NSRect screenFrame = [[[parentButton_ window] screen] frame]; | 374 NSRect screenFrame = [[[parentButton_ window] screen] frame]; |
| 362 CGFloat spillOff = (newWindowTopLeft.x + windowWidth) - NSMaxX(screenFrame); | 375 CGFloat spillOff = (newWindowTopLeft.x + windowWidth) - NSMaxX(screenFrame); |
| 363 if (spillOff > 0.0) { | 376 if (spillOff > 0.0) { |
| 364 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, | 377 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, |
| 365 NSMinX(screenFrame)); | 378 NSMinX(screenFrame)); |
| 366 } | 379 } |
| 367 } else { | 380 } else { |
| 368 // Parent is a folder; grow right/left. | 381 // Parent is a folder; grow right/left. |
| 369 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; | 382 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; |
| 370 NSPoint top = NSMakePoint(0, (NSMaxY([parentButton_ frame]) + | 383 NSPoint topOfWindow = NSMakePoint(0, |
| 371 bookmarks::kBookmarkVerticalPadding)); | 384 (NSMaxY([parentButton_ frame]) + |
| 372 NSPoint topOfWindow = | 385 bookmarks::kBookmarkVerticalPadding)); |
| 373 [[parentButton_ window] | 386 topOfWindow = [[parentButton_ window] |
| 374 convertBaseToScreen:[[parentButton_ superview] | 387 convertBaseToScreen:[[parentButton_ superview] |
| 375 convertPoint:top toView:nil]]; | 388 convertPoint:topOfWindow toView:nil]]; |
| 376 newWindowTopLeft.y = topOfWindow.y; | 389 newWindowTopLeft.y = topOfWindow.y; |
| 377 } | 390 } |
| 378 return newWindowTopLeft; | 391 return newWindowTopLeft; |
| 379 } | 392 } |
| 380 | 393 |
| 381 // Set our window level to the right spot so we're above the menubar, dock, etc. | 394 // Set our window level to the right spot so we're above the menubar, dock, etc. |
| 382 // Factored out so we can override/noop in a unit test. | 395 // Factored out so we can override/noop in a unit test. |
| 383 - (void)configureWindowLevel { | 396 - (void)configureWindowLevel { |
| 384 [[self window] setLevel:NSPopUpMenuWindowLevel]; | 397 [[self window] setLevel:NSPopUpMenuWindowLevel]; |
| 385 } | 398 } |
| 386 | 399 |
| 387 - (int)windowHeightForButtonCount:(int)buttonCount { | 400 - (int)menuHeightForButtonCount:(int)buttonCount { |
| 401 // This does not take into account any padding which may be required at the | |
| 402 // top and/or bottom of the window. | |
| 388 return (buttonCount * bookmarks::kBookmarkButtonVerticalSpan) + | 403 return (buttonCount * bookmarks::kBookmarkButtonVerticalSpan) + |
| 389 bookmarks::kBookmarkVerticalPadding; | 404 bookmarks::kBookmarkVerticalPadding; |
| 390 } | 405 } |
| 391 | 406 |
| 392 - (void)adjustWindowForHeight:(int)windowHeight { | 407 - (void)adjustWindowLeft:(CGFloat)left |
| 393 // Adjust all button widths to be consistent, determine the best size for | 408 size:(NSSize)size |
| 394 // the window, and set the window frame. | 409 scrollingBy:(CGFloat)scrollDelta { |
| 410 // Callers of this function should make adjustments to the vertical | |
| 411 // attributes of the folder view only (height, scroll position). | |
| 412 // This function will then make appropriate layout adjustments in order | |
| 413 // to accommodate screen/dock margins, scroll-up and scroll-down arrow | |
| 414 // presentation, etc. | |
| 415 // The 4 views whose vertical height and origins may be adjusted | |
| 416 // by this function are: | |
| 417 // 1) window, 2) visible content view, 3) scroller view, 4) folder view. | |
| 418 | |
| 419 // Note: Yes, this is a quite long function, but breaking it up makes little | |
| 420 // sense, complicates the logic, and obscures the overall algorithm. | |
| 421 | |
| 422 // Values which are used to calculate new frames and origins. | |
| 423 NSWindow* window = [self window]; | |
| 424 NSRect oldWindowFrame = [window frame]; | |
|
John Grabowski
2011/01/06 23:30:18
Maybe create structs/classes to reflect window/fra
mrossetti
2011/01/08 01:45:38
I refactored this a bit but it doesn't really lend
| |
| 425 CGFloat oldWindowY = NSMinY(oldWindowFrame); | |
| 426 CGFloat oldWindowTop = NSMaxY(oldWindowFrame); | |
| 427 CGFloat deltaWindowHeight = 0.0; | |
| 428 CGFloat deltaWindowY = 0.0; | |
| 429 | |
| 430 NSRect oldVisibleFrame = [visibleView_ frame]; | |
| 431 CGFloat oldVisibleY = oldVisibleFrame.origin.y; | |
| 432 CGFloat deltaVisibleHeight = 0.0; | |
| 433 CGFloat deltaVisibleY = 0.0; | |
| 434 | |
| 435 NSRect oldScrollerFrame = [scrollView_ frame]; | |
| 436 CGFloat oldScrollerY = oldScrollerFrame.origin.y; | |
| 437 CGFloat deltaScrollerHeight = 0.0; | |
| 438 CGFloat deltaScrollerY = 0.0; | |
| 439 | |
| 440 NSPoint oldScrollPoint = [scrollView_ documentVisibleRect].origin; | |
| 441 oldScrollPoint.y -= scrollDelta; | |
| 442 NSRect folderFrame = [folderView_ frame]; | |
| 443 CGFloat folderHeight = NSHeight(folderFrame); | |
| 444 CGFloat folderY = oldScrollerY + oldVisibleY + oldWindowY - oldScrollPoint.y; | |
| 445 CGFloat folderTop = folderY + folderHeight; | |
| 446 | |
| 447 BOOL couldScrollUp = ![scrollUpArrowView_ isHidden]; | |
| 448 BOOL couldScrollDown = ![scrollDownArrowView_ isHidden]; | |
| 449 NSScreen* screen = [window screen]; | |
| 450 NSRect screenFrame = [screen frame]; | |
| 451 CGFloat minimumY = | |
| 452 NSMinY([screen visibleFrame]) + bookmarks::kScrollWindowVerticalMargin; | |
| 453 CGFloat maximumY = | |
| 454 NSMaxY(screenFrame) - bookmarks::kScrollWindowVerticalMargin; | |
| 455 CGFloat effectiveFolderY = folderY; | |
| 456 if (!couldScrollUp && !couldScrollDown) effectiveFolderY -= size.height; | |
| 457 BOOL canScrollUp = effectiveFolderY < minimumY; | |
| 458 BOOL canScrollDown = folderTop > maximumY; | |
| 459 | |
| 460 // Accommodate changes in the bottom of the menu. | |
| 461 if (canScrollUp) { | |
| 462 if (!couldScrollUp) { | |
| 463 // Couldn't -> Can | |
| 464 deltaWindowY = -oldWindowY; | |
| 465 deltaWindowHeight = -deltaWindowY; | |
| 466 deltaVisibleY = minimumY; | |
| 467 deltaVisibleHeight = -deltaVisibleY; | |
| 468 deltaScrollerY = verticalScrollArrowHeight_; | |
| 469 deltaScrollerHeight = -deltaScrollerY; | |
| 470 // Adjust the scroll delta if we've grown the window and it is | |
| 471 // now scroll-up-able, but don't adjust it factor if we've | |
| 472 // scrolled down and it wasn't scroll-up-able but now is. | |
| 473 if (canScrollDown == couldScrollDown) { | |
| 474 CGFloat deltaScroll = deltaWindowY + deltaScrollerY + deltaVisibleY; | |
| 475 oldScrollPoint.y += deltaScroll + size.height; | |
| 476 } | |
| 477 } else { | |
| 478 if (!canScrollDown && size.height > 0.0) { | |
| 479 oldScrollPoint.y += size.height; | |
| 480 } | |
| 481 } | |
| 482 } else { | |
| 483 if (couldScrollUp) { | |
| 484 // Could -> Can't | |
| 485 CGFloat newWindowY = folderY; | |
| 486 deltaWindowY = newWindowY - oldWindowY; | |
| 487 deltaWindowHeight = -deltaWindowY; | |
| 488 deltaVisibleY = -bookmarks::kScrollWindowVerticalMargin; | |
| 489 deltaVisibleHeight = -deltaVisibleY; | |
| 490 deltaScrollerY = -verticalScrollArrowHeight_; | |
| 491 deltaScrollerHeight = -deltaScrollerY; | |
| 492 // Adjust the scroll delta if we are no longer scroll-up-able | |
| 493 // and the scroll-down-able-ness hasn't changed. | |
| 494 if (canScrollDown == couldScrollDown) { | |
| 495 CGFloat deltaScroll = deltaWindowY + deltaScrollerY + deltaVisibleY; | |
| 496 oldScrollPoint.y += deltaScroll; | |
| 497 } | |
| 498 } else { | |
| 499 // Couldn't -> Can't | |
| 500 // Check for menu height change by looking at the relative tops of the | |
| 501 // menu folder and the window folder, which previously would have been | |
| 502 // the same. | |
| 503 deltaWindowY = oldWindowTop - folderTop; | |
| 504 deltaWindowHeight = -deltaWindowY; | |
| 505 } | |
| 506 } | |
| 507 | |
| 508 // Accommodate changes in the top of the menu. | |
| 509 if (canScrollDown == couldScrollDown) { | |
| 510 if (!canScrollDown) { | |
| 511 // Not scroll-down-able but the menu top has changed. | |
| 512 deltaWindowHeight += scrollDelta; | |
| 513 } | |
| 514 } else { | |
| 515 if (canScrollDown) { | |
| 516 // Couldn't -> Can | |
| 517 deltaWindowHeight += (NSMaxY(screenFrame) - oldWindowTop); | |
| 518 deltaVisibleHeight -= bookmarks::kScrollWindowVerticalMargin; | |
| 519 deltaScrollerHeight -= verticalScrollArrowHeight_; | |
| 520 } else { | |
| 521 // Could -> Can't | |
| 522 deltaWindowHeight -= bookmarks::kScrollWindowVerticalMargin; | |
| 523 deltaVisibleHeight += bookmarks::kScrollWindowVerticalMargin; | |
| 524 deltaScrollerHeight += verticalScrollArrowHeight_; | |
| 525 } | |
| 526 } | |
| 527 | |
| 528 // Hide or show the scroll arrows. | |
| 529 if (canScrollUp != couldScrollUp) | |
| 530 [scrollUpArrowView_ setHidden:couldScrollUp]; | |
| 531 if (canScrollDown != couldScrollDown) | |
| 532 [scrollDownArrowView_ setHidden:couldScrollDown]; | |
| 533 | |
| 534 // Adjust the geometry. The order is important because of sizer dependencies. | |
| 535 oldScrollerFrame.origin.y += deltaScrollerY; | |
| 536 oldScrollerFrame.size.height += deltaScrollerHeight; | |
| 537 [scrollView_ setFrame:oldScrollerFrame]; | |
| 538 oldVisibleFrame.origin.y += deltaVisibleY; | |
| 539 oldVisibleFrame.size.height += deltaVisibleHeight; | |
| 540 [visibleView_ setFrame:oldVisibleFrame]; | |
| 541 BOOL scrolled = NO; | |
| 542 // This little bit of trickery detects the one special case where | |
| 543 // the window is now scroll-up-able _and_ going to be resized -- scroll | |
| 544 // first in order to prevent flashing. | |
| 545 if (canScrollUp && !couldScrollUp && | |
| 546 scrollDelta == 0.0 && deltaWindowHeight >= 0.0) { | |
| 547 [[scrollView_ documentView] scrollPoint:oldScrollPoint]; | |
| 548 scrolled = YES; | |
| 549 } | |
| 550 | |
| 551 oldWindowFrame.origin.y += deltaWindowY; | |
| 552 oldWindowFrame.origin.x = left; | |
| 553 oldWindowFrame.size.height += deltaWindowHeight; | |
| 554 oldWindowFrame.size.width = size.width; | |
| 555 [window setFrame:oldWindowFrame display:YES]; | |
| 556 if (!scrolled) { | |
| 557 // In all other cases we defer scrolling until the window has been resized | |
| 558 // in order to prevent flashing. | |
| 559 [[scrollView_ documentView] scrollPoint:oldScrollPoint]; | |
| 560 } | |
| 561 | |
| 562 if (canScrollUp != couldScrollUp || canScrollDown != couldScrollDown || | |
| 563 scrollDelta != 0.0) { | |
| 564 if (canScrollUp || canScrollDown) | |
| 565 [self addOrUpdateScrollTracking]; | |
| 566 else | |
| 567 [self removeScrollTracking]; | |
| 568 } | |
| 569 } | |
| 570 | |
| 571 - (void)adjustWindowForButtonCount:(NSUInteger)buttonCount { | |
| 572 NSRect folderFrame = [folderView_ frame]; | |
| 573 CGFloat newMenuHeight = | |
| 574 (CGFloat)[self menuHeightForButtonCount:[buttons_ count]]; | |
| 575 CGFloat deltaMenuHeight = newMenuHeight - NSHeight(folderFrame); | |
| 576 // If the height has changed then also change the origin, and adjust the | |
| 577 // scroll (if scrolling). | |
| 578 if ([self canScrollUp]) { | |
| 579 NSPoint scrollPoint = [scrollView_ documentVisibleRect].origin; | |
| 580 scrollPoint.y += deltaMenuHeight; | |
| 581 [[scrollView_ documentView] scrollPoint:scrollPoint]; | |
| 582 } | |
| 583 folderFrame.size.height += deltaMenuHeight; | |
| 584 [folderView_ setFrameSize:folderFrame.size]; | |
| 395 CGFloat windowWidth = | 585 CGFloat windowWidth = |
| 396 [self adjustButtonWidths] + | 586 [self adjustButtonWidths] + leftPadding_ + rightPadding_; |
| 397 (2 * bookmarks::kBookmarkSubMenuHorizontalPadding); | |
| 398 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; | 587 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; |
| 399 NSSize windowSize = NSMakeSize(windowWidth, windowHeight); | 588 CGFloat left = newWindowTopLeft.x; |
| 400 windowSize = [scrollView_ convertSize:windowSize toView:nil]; | 589 NSSize newSize = NSMakeSize(windowWidth, deltaMenuHeight); |
| 401 NSWindow* window = [self window]; | 590 [self adjustWindowLeft:left size:newSize scrollingBy:0.0]; |
| 402 // If the window is already visible then make sure its top remains stable. | |
| 403 BOOL windowAlreadyShowing = [window isVisible]; | |
| 404 CGFloat deltaY = windowHeight - NSHeight([mainView_ frame]); | |
| 405 if (windowAlreadyShowing) { | |
| 406 NSRect oldFrame = [window frame]; | |
| 407 newWindowTopLeft.y = oldFrame.origin.y + NSHeight(oldFrame); | |
| 408 } | |
| 409 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, | |
| 410 newWindowTopLeft.y - windowHeight, windowSize.width, windowHeight); | |
| 411 // Make the scrolled content be the right size (full size). | |
| 412 NSRect mainViewFrame = NSMakeRect(0, 0, NSWidth(windowFrame) - | |
| 413 bookmarks::kScrollViewContentWidthMargin, NSHeight(windowFrame)); | |
| 414 [mainView_ setFrame:mainViewFrame]; | |
| 415 // Make sure the window fits on the screen. If not, constrain. | |
| 416 // We'll scroll to allow the user to see all the content. | |
| 417 NSRect screenFrame = [[[self window] screen] frame]; | |
| 418 screenFrame = NSInsetRect(screenFrame, 0, kScrollWindowVerticalMargin); | |
| 419 BOOL wasScrollable = scrollable_; | |
| 420 if (!NSContainsRect(screenFrame, windowFrame)) { | |
| 421 scrollable_ = YES; | |
| 422 windowFrame = NSIntersectionRect(screenFrame, windowFrame); | |
| 423 } else { | |
| 424 scrollable_ = NO; | |
| 425 } | |
| 426 [window setFrame:windowFrame display:NO]; | |
| 427 if (wasScrollable != scrollable_) { | |
| 428 // If scrollability changed then rework visibility of the scroll arrows | |
| 429 // and the scroll offset of the menu view. | |
| 430 NSSize windowLocalSize = | |
| 431 [scrollView_ convertSize:windowFrame.size fromView:nil]; | |
| 432 CGFloat scrollPointY = NSHeight(mainViewFrame) - windowLocalSize.height + | |
| 433 bookmarks::kBookmarkVerticalPadding; | |
| 434 [mainView_ scrollPoint:NSMakePoint(0, scrollPointY)]; | |
| 435 [self showOrHideScrollArrows]; | |
| 436 [self addOrUpdateScrollTracking]; | |
| 437 } else if (scrollable_ && windowAlreadyShowing) { | |
| 438 // If the window was already showing and is still scrollable then make | |
| 439 // sure the main view moves upward, not downward so that the content | |
| 440 // at the bottom of the menu, not the top, appears to move. | |
| 441 // The edge case is when the menu is scrolled all the way to top (hence | |
| 442 // the test of scrollDownArrowShown_) - don't scroll then. | |
| 443 NSView* superView = [mainView_ superview]; | |
| 444 DCHECK([superView isKindOfClass:[NSClipView class]]); | |
| 445 NSClipView* clipView = static_cast<NSClipView*>(superView); | |
| 446 CGFloat scrollPointY = [clipView bounds].origin.y + | |
| 447 bookmarks::kBookmarkVerticalPadding; | |
| 448 if (scrollDownArrowShown_ || deltaY > 0.0) | |
| 449 scrollPointY += deltaY; | |
| 450 [mainView_ scrollPoint:NSMakePoint(0, scrollPointY)]; | |
| 451 } | |
| 452 [window display]; | |
| 453 } | 591 } |
| 454 | 592 |
| 455 // Determine window size and position. | 593 // Determine window size and position. |
| 456 // Create buttons for all our nodes. | 594 // Create buttons for all our nodes. |
| 457 // TODO(jrg): break up into more and smaller routines for easier unit testing. | 595 // TODO(jrg): break up into more and smaller routines for easier unit testing. |
| 458 - (void)configureWindow { | 596 - (void)configureWindow { |
| 459 const BookmarkNode* node = [parentButton_ bookmarkNode]; | 597 const BookmarkNode* node = [parentButton_ bookmarkNode]; |
| 460 DCHECK(node); | 598 DCHECK(node); |
| 461 int startingIndex = [[parentButton_ cell] startingChildIndex]; | 599 int startingIndex = [[parentButton_ cell] startingChildIndex]; |
| 462 DCHECK_LE(startingIndex, node->GetChildCount()); | 600 DCHECK_LE(startingIndex, node->GetChildCount()); |
| 463 // Must have at least 1 button (for "empty") | 601 // Must have at least 1 button (for "empty") |
| 464 int buttons = std::max(node->GetChildCount() - startingIndex, 1); | 602 int buttons = std::max(node->GetChildCount() - startingIndex, 1); |
| 465 | 603 |
| 466 // Prelim height of the window. We'll trim later as needed. | 604 // Prelim height of the window. We'll trim later as needed. |
| 467 int height = [self windowHeightForButtonCount:buttons]; | 605 int height = [self menuHeightForButtonCount:buttons]; |
| 468 // We'll need this soon... | 606 // We'll need this soon... |
| 469 [self window]; | 607 [self window]; |
| 470 | 608 |
| 471 // TODO(jrg): combine with frame code in bookmark_bar_controller.mm | 609 // TODO(jrg): combine with frame code in bookmark_bar_controller.mm |
| 472 // http://crbug.com/35966 | 610 // http://crbug.com/35966 |
| 473 NSRect buttonsOuterFrame = NSMakeRect( | 611 NSRect buttonsOuterFrame = NSMakeRect( |
| 474 bookmarks::kBookmarkSubMenuHorizontalPadding, | 612 0, |
| 475 (height - bookmarks::kBookmarkButtonVerticalSpan), | 613 (height - bookmarks::kBookmarkButtonVerticalSpan), |
| 476 bookmarks::kDefaultBookmarkWidth, | 614 bookmarks::kDefaultBookmarkWidth, |
| 477 bookmarks::kBookmarkButtonHeight); | 615 bookmarks::kBookmarkButtonHeight); |
| 478 | 616 |
| 479 // TODO(jrg): combine with addNodesToButtonList: code from | 617 // TODO(jrg): combine with addNodesToButtonList: code from |
| 480 // bookmark_bar_controller.mm (but use y offset) | 618 // bookmark_bar_controller.mm (but use y offset) |
| 481 // http://crbug.com/35966 | 619 // http://crbug.com/35966 |
| 482 if (!node->GetChildCount()) { | 620 if (!node->GetChildCount()) { |
| 483 // If no children we are the empty button. | 621 // If no children we are the empty button. |
| 484 BookmarkButton* button = [self makeButtonForNode:nil | 622 BookmarkButton* button = [self makeButtonForNode:nil |
| 485 frame:buttonsOuterFrame]; | 623 frame:buttonsOuterFrame]; |
| 486 [buttons_ addObject:button]; | 624 [buttons_ addObject:button]; |
| 487 [mainView_ addSubview:button]; | 625 [folderView_ addSubview:button]; |
| 488 } else { | 626 } else { |
| 489 for (int i = startingIndex; | 627 for (int i = startingIndex; |
| 490 i < node->GetChildCount(); | 628 i < node->GetChildCount(); |
| 491 i++) { | 629 i++) { |
| 492 const BookmarkNode* child = node->GetChild(i); | 630 const BookmarkNode* child = node->GetChild(i); |
| 493 BookmarkButton* button = [self makeButtonForNode:child | 631 BookmarkButton* button = [self makeButtonForNode:child |
| 494 frame:buttonsOuterFrame]; | 632 frame:buttonsOuterFrame]; |
| 495 [buttons_ addObject:button]; | 633 [buttons_ addObject:button]; |
| 496 [mainView_ addSubview:button]; | 634 [folderView_ addSubview:button]; |
| 497 buttonsOuterFrame.origin.y -= bookmarks::kBookmarkButtonVerticalSpan; | 635 buttonsOuterFrame.origin.y -= bookmarks::kBookmarkButtonVerticalSpan; |
| 498 } | 636 } |
| 499 } | 637 } |
| 500 | 638 |
| 501 [self adjustWindowForHeight:height]; | 639 // Newly showing window. Lay out the window. |
|
John Grabowski
2011/01/06 23:30:18
Move all this into a configureWindowLayout method
mrossetti
2011/01/08 01:45:38
Done.
| |
| 502 // Finally pop me up. | 640 // Adjust all button widths to be consistent, then base the window width |
| 641 // on this ideal button width. | |
| 642 CGFloat buttonWidth = [self adjustButtonWidths]; | |
| 643 CGFloat windowWidth = buttonWidth + leftPadding_ + rightPadding_; | |
| 644 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; | |
| 645 // Make sure as much of a submenu is exposed (which otherwise would be a | |
| 646 // problem if the parent button is close to the bottom of the screen). | |
| 647 if ([parentController_ isKindOfClass:[self class]]) { | |
| 648 newWindowTopLeft.y = MAX(newWindowTopLeft.y, | |
| 649 height + bookmarks::kScrollWindowVerticalMargin); | |
| 650 } | |
| 651 NSWindow* window = [self window]; | |
| 652 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, | |
| 653 newWindowTopLeft.y - height, | |
| 654 windowWidth, height); | |
| 655 [window setFrame:windowFrame display:NO]; | |
| 656 NSRect folderFrame = NSMakeRect(0, 0, windowWidth, height); | |
| 657 [folderView_ setFrame:folderFrame]; | |
| 658 NSSize newSize = NSMakeSize(windowWidth, 0.0); | |
| 659 [self adjustWindowLeft:newWindowTopLeft.x size:newSize scrollingBy:0.0]; | |
| 660 [window display]; | |
| 503 [self configureWindowLevel]; | 661 [self configureWindowLevel]; |
| 504 } | 662 } |
| 505 | 663 |
| 506 // TODO(mrossetti): See if the following can be moved into view's viewWillDraw:. | 664 // TODO(mrossetti): See if the following can be moved into view's viewWillDraw:. |
| 507 - (CGFloat)adjustButtonWidths { | 665 - (CGFloat)adjustButtonWidths { |
| 508 CGFloat width = bookmarks::kBookmarkMenuButtonMinimumWidth; | 666 CGFloat width = bookmarks::kBookmarkMenuButtonMinimumWidth; |
| 509 // Use the cell's size as the base for determining the desired width of the | 667 // Use the cell's size as the base for determining the desired width of the |
| 510 // button rather than the button's current width. -[cell cellSize] always | 668 // button rather than the button's current width. -[cell cellSize] always |
| 511 // returns the 'optimum' size of the cell based on the cell's contents even | 669 // returns the 'optimum' size of the cell based on the cell's contents even |
| 512 // if it's less than the current button size. Relying on the button size | 670 // if it's less than the current button size. Relying on the button size |
| 513 // would result in buttons that could only get wider but we want to handle | 671 // would result in buttons that could only get wider but we want to handle |
| 514 // the case where the widest button gets removed from a folder menu. | 672 // the case where the widest button gets removed from a folder menu. |
| 515 for (BookmarkButton* button in buttons_.get()) | 673 for (BookmarkButton* button in buttons_.get()) |
| 516 width = std::max(width, [[button cell] cellSize].width); | 674 width = std::max(width, [[button cell] cellSize].width); |
| 517 width = std::min(width, bookmarks::kBookmarkMenuButtonMaximumWidth); | 675 width = std::min(width, bookmarks::kBookmarkMenuButtonMaximumWidth); |
| 518 // Things look and feel more menu-like if all the buttons are the | 676 // Things look and feel more menu-like if all the buttons are the |
| 519 // full width of the window, especially if there are submenus. | 677 // full width of the window, especially if there are submenus. |
| 520 for (BookmarkButton* button in buttons_.get()) { | 678 for (BookmarkButton* button in buttons_.get()) { |
| 521 NSRect buttonFrame = [button frame]; | 679 NSRect buttonFrame = [button frame]; |
| 522 buttonFrame.size.width = width; | 680 buttonFrame.size.width = width; |
| 523 [button setFrame:buttonFrame]; | 681 [button setFrame:buttonFrame]; |
| 524 } | 682 } |
| 525 return width; | 683 return width; |
| 526 } | 684 } |
| 527 | 685 |
| 528 - (BOOL)canScrollUp { | |
| 529 // If removal of an arrow would make things "finished", state as | |
| 530 // such. | |
| 531 CGFloat scrollY = [scrollView_ documentVisibleRect].origin.y; | |
| 532 if (scrollUpArrowShown_) | |
| 533 scrollY -= verticalScrollArrowHeight_; | |
| 534 | |
| 535 if (scrollY <= 0) | |
| 536 return NO; | |
| 537 return YES; | |
| 538 } | |
| 539 | |
| 540 - (BOOL)canScrollDown { | |
| 541 CGFloat arrowAdjustment = 0.0; | |
| 542 | |
| 543 // We do NOT adjust based on the scrollDOWN arrow. This keeps | |
| 544 // things from "jumping"; if removal of the down arrow (at the top | |
| 545 // of the window) would cause a scroll to end, we'll end. | |
| 546 if (scrollUpArrowShown_) | |
| 547 arrowAdjustment += verticalScrollArrowHeight_; | |
| 548 | |
| 549 NSPoint scrollPosition = [scrollView_ documentVisibleRect].origin; | |
| 550 NSRect documentRect = [[scrollView_ documentView] frame]; | |
| 551 | |
| 552 // If we are exactly the right height, return no. We need this | |
| 553 // extra conditional in the case where we've just scrolled/grown | |
| 554 // into position. | |
| 555 if (NSHeight([[self window] frame]) == NSHeight(documentRect)) | |
| 556 return NO; | |
| 557 | |
| 558 if ((scrollPosition.y + NSHeight([[self window] frame])) >= | |
| 559 (NSHeight(documentRect) + arrowAdjustment)) { | |
| 560 return NO; | |
| 561 } | |
| 562 return YES; | |
| 563 } | |
| 564 | |
| 565 - (void)showOrHideScrollArrows { | |
| 566 NSRect frame = [scrollView_ frame]; | |
| 567 CGFloat scrollDelta = 0.0; | |
| 568 BOOL canScrollDown = [self canScrollDown]; | |
| 569 BOOL canScrollUp = [self canScrollUp]; | |
| 570 | |
| 571 if (canScrollUp != scrollUpArrowShown_) { | |
| 572 if (scrollUpArrowShown_) { | |
| 573 frame.origin.y -= verticalScrollArrowHeight_; | |
| 574 frame.size.height += verticalScrollArrowHeight_; | |
| 575 scrollDelta = verticalScrollArrowHeight_; | |
| 576 } else { | |
| 577 frame.origin.y += verticalScrollArrowHeight_; | |
| 578 frame.size.height -= verticalScrollArrowHeight_; | |
| 579 scrollDelta = -verticalScrollArrowHeight_; | |
| 580 } | |
| 581 } | |
| 582 if (canScrollDown != scrollDownArrowShown_) { | |
| 583 if (scrollDownArrowShown_) { | |
| 584 frame.size.height += verticalScrollArrowHeight_; | |
| 585 } else { | |
| 586 frame.size.height -= verticalScrollArrowHeight_; | |
| 587 } | |
| 588 } | |
| 589 scrollUpArrowShown_ = canScrollUp; | |
| 590 scrollDownArrowShown_ = canScrollDown; | |
| 591 [scrollView_ setFrame:frame]; | |
| 592 | |
| 593 // Adjust scroll based on new frame. For example, if we make room | |
| 594 // for an arrow at the bottom, adjust the scroll so the topmost item | |
| 595 // is still fully visible. | |
| 596 if (scrollDelta) { | |
| 597 NSPoint scrollPosition = [scrollView_ documentVisibleRect].origin; | |
| 598 scrollPosition.y -= scrollDelta; | |
| 599 [[scrollView_ documentView] scrollPoint:scrollPosition]; | |
| 600 } | |
| 601 } | |
| 602 | |
| 603 - (BOOL)scrollable { | |
| 604 return scrollable_; | |
| 605 } | |
| 606 | |
| 607 // Start a "scroll up" timer. | 686 // Start a "scroll up" timer. |
| 608 - (void)beginScrollWindowUp { | 687 - (void)beginScrollWindowUp { |
| 609 [self addScrollTimerWithDelta:kBookmarkBarFolderScrollAmount]; | 688 [self addScrollTimerWithDelta:kBookmarkBarFolderScrollAmount]; |
| 610 } | 689 } |
| 611 | 690 |
| 612 // Start a "scroll down" timer. | 691 // Start a "scroll down" timer. |
| 613 - (void)beginScrollWindowDown { | 692 - (void)beginScrollWindowDown { |
| 614 [self addScrollTimerWithDelta:-kBookmarkBarFolderScrollAmount]; | 693 [self addScrollTimerWithDelta:-kBookmarkBarFolderScrollAmount]; |
| 615 } | 694 } |
| 616 | 695 |
| 617 // End a scrolling timer. Can be called excessively with no harm. | 696 // End a scrolling timer. Can be called excessively with no harm. |
| 618 - (void)endScroll { | 697 - (void)endScroll { |
| 619 if (scrollTimer_) { | 698 if (scrollTimer_) { |
| 620 [scrollTimer_ invalidate]; | 699 [scrollTimer_ invalidate]; |
| 621 scrollTimer_ = nil; | 700 scrollTimer_ = nil; |
| 622 verticalScrollDelta_ = 0; | 701 verticalScrollDelta_ = 0; |
| 623 } | 702 } |
| 624 } | 703 } |
| 625 | 704 |
| 626 // Perform a single scroll of the specified amount. | 705 // Perform a single scroll of the specified amount. |
| 627 // Scroll up: | |
| 628 // Scroll the documentView by the growth amount. | |
| 629 // If we cannot grow the window, simply scroll the documentView. | |
| 630 // If we can grow the window up without falling off the screen, do it. | |
| 631 // Scroll down: | |
| 632 // Never change the window size; only scroll the documentView. | |
| 633 - (void)performOneScroll:(CGFloat)delta { | 706 - (void)performOneScroll:(CGFloat)delta { |
| 634 NSRect windowFrame = [[self window] frame]; | 707 CGFloat finalDelta = [self determineFinalScrollDelta:delta]; |
| 635 NSRect screenFrame = [[[self window] screen] frame]; | 708 if (finalDelta > 0.0 || finalDelta < 0.0) { |
| 709 if (buttonThatMouseIsIn_) | |
| 710 [buttonThatMouseIsIn_ toggleButtonBorderingWhileMouseInside]; | |
| 711 NSRect windowFrame = [[self window] frame]; | |
| 712 NSSize newSize = NSMakeSize(NSWidth(windowFrame), 0.0); | |
| 713 [self adjustWindowLeft:windowFrame.origin.x | |
| 714 size:newSize | |
| 715 scrollingBy:finalDelta]; | |
| 716 } | |
| 717 } | |
| 636 | 718 |
| 637 // First scroll the "document" area. | 719 - (CGFloat)determineFinalScrollDelta:(CGFloat)delta { |
| 638 NSPoint scrollPosition = [scrollView_ documentVisibleRect].origin; | 720 if (delta > 0.0 && ![scrollUpArrowView_ isHidden] || |
| 639 scrollPosition.y -= delta; | 721 delta < 0.0 && ![scrollDownArrowView_ isHidden]) { |
| 640 [[scrollView_ documentView] scrollPoint:scrollPosition]; | 722 NSWindow* window = [self window]; |
| 723 NSRect windowFrame = [window frame]; | |
| 724 NSScreen* screen = [window screen]; | |
| 725 NSPoint scrollPosition = [scrollView_ documentVisibleRect].origin; | |
| 726 CGFloat scrollY = scrollPosition.y; | |
| 727 NSRect scrollerFrame = [scrollView_ frame]; | |
| 728 CGFloat scrollerY = NSMinY(scrollerFrame); | |
| 729 NSRect visibleFrame = [visibleView_ frame]; | |
| 730 CGFloat visibleY = NSMinY(visibleFrame); | |
| 731 CGFloat windowY = NSMinY(windowFrame); | |
| 732 CGFloat offset = scrollerY + visibleY + windowY; | |
| 641 | 733 |
| 642 if (buttonThatMouseIsIn_) | 734 if (delta > 0.0) { |
| 643 [buttonThatMouseIsIn_ toggleButtonBorderingWhileMouseInside]; | 735 // Scrolling up. |
| 644 | 736 CGFloat minimumY = NSMinY([screen visibleFrame]) + |
| 645 // We update the window size after shifting the scroll to avoid a race. | 737 bookmarks::kScrollWindowVerticalMargin; |
| 646 CGFloat screenHeightMinusMargin = (NSHeight(screenFrame) - | 738 CGFloat maxUpDelta = scrollY - offset + minimumY; |
| 647 (2 * kScrollWindowVerticalMargin)); | 739 delta = MIN(delta, maxUpDelta); |
| 648 if (delta) { | 740 } else { |
| 649 // If we can, grow the window (up). | 741 // Scrolling down. |
| 650 if (NSHeight(windowFrame) < screenHeightMinusMargin) { | 742 NSRect screenFrame = [screen frame]; |
| 651 CGFloat growAmount = delta; | 743 CGFloat topOfScreen = NSMaxY(screenFrame); |
| 652 // Don't scroll more than enough to "finish". | 744 NSRect folderFrame = [folderView_ frame]; |
| 653 if (scrollPosition.y < 0) | 745 CGFloat folderHeight = NSHeight(folderFrame); |
| 654 growAmount += scrollPosition.y; | 746 CGFloat folderTop = folderHeight - scrollY + offset; |
| 655 windowFrame.size.height += growAmount; | 747 CGFloat maxDownDelta = |
| 656 windowFrame.size.height = std::min(NSHeight(windowFrame), | 748 topOfScreen - folderTop - bookmarks::kScrollWindowVerticalMargin; |
| 657 screenHeightMinusMargin); | 749 delta = MAX(delta, maxDownDelta); |
| 658 // Watch out for a finish that isn't the full height of the screen. | |
| 659 // We get here if using the scroll wheel to scroll by small amounts. | |
| 660 windowFrame.size.height = std::min(NSHeight(windowFrame), | |
| 661 NSHeight([mainView_ frame])); | |
| 662 // Don't allow scrolling to make the window smaller, ever. This | |
| 663 // conditional is important when processing scrollWheel events. | |
| 664 if (windowFrame.size.height > [[self window] frame].size.height) { | |
| 665 [[self window] setFrame:windowFrame display:YES]; | |
| 666 [self addOrUpdateScrollTracking]; | |
| 667 } | |
| 668 } | 750 } |
| 751 } else { | |
| 752 delta = 0.0; | |
| 669 } | 753 } |
| 670 | 754 return delta; |
| 671 // If we're at either end, happiness. | |
| 672 if ((scrollPosition.y <= 0) || | |
| 673 ((scrollPosition.y + NSHeight(windowFrame) >= | |
| 674 NSHeight([mainView_ frame])) && | |
| 675 (windowFrame.size.height == screenHeightMinusMargin))) { | |
| 676 [self endScroll]; | |
| 677 | |
| 678 // If we can't scroll either up or down we are completely done. | |
| 679 // For example, perhaps we've scrolled a little and grown the | |
| 680 // window on-screen until there is now room for everything. | |
| 681 if (![self canScrollUp] && ![self canScrollDown]) { | |
| 682 scrollable_ = NO; | |
| 683 [self removeScrollTracking]; | |
| 684 } | |
| 685 } | |
| 686 | |
| 687 [self showOrHideScrollArrows]; | |
| 688 } | 755 } |
| 689 | 756 |
| 690 // Perform a scroll of the window on the screen. | 757 // Perform a scroll of the window on the screen. |
| 691 // Called by a timer when scrolling. | 758 // Called by a timer when scrolling. |
| 692 - (void)performScroll:(NSTimer*)timer { | 759 - (void)performScroll:(NSTimer*)timer { |
| 693 DCHECK(verticalScrollDelta_); | 760 DCHECK(verticalScrollDelta_); |
| 694 [self performOneScroll:verticalScrollDelta_]; | 761 [self performOneScroll:verticalScrollDelta_]; |
| 695 } | 762 } |
| 696 | 763 |
| 697 | 764 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 709 userInfo:nil | 776 userInfo:nil |
| 710 repeats:YES]; | 777 repeats:YES]; |
| 711 } | 778 } |
| 712 | 779 |
| 713 // Called as a result of our tracking area. Warning: on the main | 780 // Called as a result of our tracking area. Warning: on the main |
| 714 // screen (of a single-screened machine), the minimum mouse y value is | 781 // screen (of a single-screened machine), the minimum mouse y value is |
| 715 // 1, not 0. Also, we do not get events when the mouse is above the | 782 // 1, not 0. Also, we do not get events when the mouse is above the |
| 716 // menubar (to be fixed by setting the proper window level; see | 783 // menubar (to be fixed by setting the proper window level; see |
| 717 // initializer). | 784 // initializer). |
| 718 - (void)mouseMoved:(NSEvent*)theEvent { | 785 - (void)mouseMoved:(NSEvent*)theEvent { |
| 719 DCHECK([theEvent window] == [self window]); | 786 NSWindow* window = [theEvent window]; |
| 787 DCHECK(window == [self window]); | |
| 720 | 788 |
| 721 NSPoint eventScreenLocation = | 789 NSPoint eventScreenLocation = |
| 722 [[theEvent window] convertBaseToScreen:[theEvent locationInWindow]]; | 790 [window convertBaseToScreen:[theEvent locationInWindow]]; |
| 723 | 791 |
| 724 // We use frame (not visibleFrame) since our bookmark folder is on | 792 // Base hot spot calculations on the positions of the scroll arrow views. |
| 725 // TOP of the menubar. | 793 NSRect testRect = [scrollDownArrowView_ frame]; |
| 726 NSRect visibleRect = [[[self window] screen] frame]; | 794 NSPoint testPoint = [visibleView_ convertPoint:testRect.origin |
| 727 CGFloat closeToTopOfScreen = NSMaxY(visibleRect) - | 795 toView:nil]; |
| 728 verticalScrollArrowHeight_; | 796 testPoint = [window convertBaseToScreen:testPoint]; |
| 729 CGFloat closeToBottomOfScreen = NSMinY(visibleRect) + | 797 CGFloat closeToTopOfScreen = testPoint.y; |
| 730 verticalScrollArrowHeight_; | |
| 731 | 798 |
| 732 if (eventScreenLocation.y <= closeToBottomOfScreen) { | 799 testRect = [scrollUpArrowView_ frame]; |
| 800 testPoint = [visibleView_ convertPoint:testRect.origin toView:nil]; | |
| 801 testPoint = [window convertBaseToScreen:testPoint]; | |
| 802 CGFloat closeToBottomOfScreen = testPoint.y + testRect.size.height; | |
| 803 if (eventScreenLocation.y <= closeToBottomOfScreen && | |
| 804 ![scrollUpArrowView_ isHidden]) { | |
| 733 [self beginScrollWindowUp]; | 805 [self beginScrollWindowUp]; |
| 734 } else if (eventScreenLocation.y > closeToTopOfScreen) { | 806 } else if (eventScreenLocation.y > closeToTopOfScreen && |
| 807 ![scrollDownArrowView_ isHidden]) { | |
| 735 [self beginScrollWindowDown]; | 808 [self beginScrollWindowDown]; |
| 736 } else { | 809 } else { |
| 737 [self endScroll]; | 810 [self endScroll]; |
| 738 } | 811 } |
| 739 } | 812 } |
| 740 | 813 |
| 741 - (void)mouseExited:(NSEvent*)theEvent { | 814 - (void)mouseExited:(NSEvent*)theEvent { |
| 742 [self endScroll]; | 815 [self endScroll]; |
| 743 } | 816 } |
| 744 | 817 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 759 } | 832 } |
| 760 | 833 |
| 761 // Remove the tracking area associated with scrolling. | 834 // Remove the tracking area associated with scrolling. |
| 762 - (void)removeScrollTracking { | 835 - (void)removeScrollTracking { |
| 763 if (scrollTrackingArea_.get()) { | 836 if (scrollTrackingArea_.get()) { |
| 764 [[[self window] contentView] removeTrackingArea:scrollTrackingArea_]; | 837 [[[self window] contentView] removeTrackingArea:scrollTrackingArea_]; |
| 765 } | 838 } |
| 766 scrollTrackingArea_.reset(); | 839 scrollTrackingArea_.reset(); |
| 767 } | 840 } |
| 768 | 841 |
| 769 // Delegate callback. | |
| 770 - (void)windowWillClose:(NSNotification*)notification { | |
| 771 // If a "hover open" is pending when the bookmark bar folder is | |
| 772 // closed, be sure it gets cancelled. | |
| 773 [NSObject cancelPreviousPerformRequestsWithTarget:self]; | |
| 774 | |
| 775 [barController_ childFolderWillClose:self]; | |
| 776 [self closeBookmarkFolder:self]; | |
| 777 [self autorelease]; | |
| 778 } | |
| 779 | |
| 780 // Close the old hover-open bookmark folder, and open a new one. We | 842 // Close the old hover-open bookmark folder, and open a new one. We |
| 781 // do both in one step to allow for a delay in closing the old one. | 843 // do both in one step to allow for a delay in closing the old one. |
| 782 // See comments above kDragHoverCloseDelay (bookmark_bar_controller.h) | 844 // See comments above kDragHoverCloseDelay (bookmark_bar_controller.h) |
| 783 // for more details. | 845 // for more details. |
| 784 - (void)openBookmarkFolderFromButtonAndCloseOldOne:(id)sender { | 846 - (void)openBookmarkFolderFromButtonAndCloseOldOne:(id)sender { |
| 785 // If an old submenu exists, close it immediately. | 847 // If an old submenu exists, close it immediately. |
| 786 [self closeBookmarkFolder:sender]; | 848 [self closeBookmarkFolder:sender]; |
| 787 | 849 |
| 788 // Open a new one if meaningful. | 850 // Open a new one if meaningful. |
| 789 if ([sender isFolder]) | 851 if ([sender isFolder]) |
| 790 [folderTarget_ openBookmarkFolderFromButton:sender]; | 852 [folderTarget_ openBookmarkFolderFromButton:sender]; |
| 791 } | 853 } |
| 792 | 854 |
| 793 - (NSArray*)buttons { | 855 - (NSArray*)buttons { |
| 794 return buttons_.get(); | 856 return buttons_.get(); |
| 795 } | 857 } |
| 796 | 858 |
| 797 - (void)close { | 859 - (void)close { |
| 798 [folderController_ close]; | 860 [folderController_ close]; |
| 799 [super close]; | 861 [super close]; |
| 800 } | 862 } |
| 801 | 863 |
| 802 - (void)scrollWheel:(NSEvent *)theEvent { | 864 - (void)scrollWheel:(NSEvent *)theEvent { |
| 803 if (scrollable_) { | 865 if (![scrollUpArrowView_ isHidden] || ![scrollDownArrowView_ isHidden]) { |
| 804 // We go negative since an NSScrollView has a flipped coordinate frame. | 866 // We go negative since an NSScrollView has a flipped coordinate frame. |
| 805 CGFloat amt = kBookmarkBarFolderScrollWheelAmount * -[theEvent deltaY]; | 867 CGFloat amt = kBookmarkBarFolderScrollWheelAmount * -[theEvent deltaY]; |
| 806 [self performOneScroll:amt]; | 868 [self performOneScroll:amt]; |
| 807 } | 869 } |
| 808 } | 870 } |
| 809 | 871 |
| 810 #pragma mark Actions Forwarded to Parent BookmarkBarController | 872 #pragma mark Actions Forwarded to Parent BookmarkBarController |
| 811 | 873 |
| 812 - (IBAction)openBookmark:(id)sender { | 874 - (IBAction)openBookmark:(id)sender { |
| 813 [barController_ openBookmark:sender]; | 875 [barController_ openBookmark:sender]; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 // exist in the future). | 981 // exist in the future). |
| 920 // http://crbug.com/35966 | 982 // http://crbug.com/35966 |
| 921 - (int)indexForDragToPoint:(NSPoint)point { | 983 - (int)indexForDragToPoint:(NSPoint)point { |
| 922 // Identify which buttons we are between. For now, assume a button | 984 // Identify which buttons we are between. For now, assume a button |
| 923 // location is at the center point of its view, and that an exact | 985 // location is at the center point of its view, and that an exact |
| 924 // match means "place before". | 986 // match means "place before". |
| 925 // TODO(jrg): revisit position info based on UI team feedback. | 987 // TODO(jrg): revisit position info based on UI team feedback. |
| 926 // dropLocation is in bar local coordinates. | 988 // dropLocation is in bar local coordinates. |
| 927 // http://crbug.com/36276 | 989 // http://crbug.com/36276 |
| 928 NSPoint dropLocation = | 990 NSPoint dropLocation = |
| 929 [mainView_ convertPoint:point | 991 [folderView_ convertPoint:point |
| 930 fromView:[[self window] contentView]]; | 992 fromView:[[self window] contentView]]; |
| 931 BookmarkButton* buttonToTheTopOfDraggedButton = nil; | 993 BookmarkButton* buttonToTheTopOfDraggedButton = nil; |
| 932 // Buttons are laid out in this array from top to bottom (screen | 994 // Buttons are laid out in this array from top to bottom (screen |
| 933 // wise), which means "biggest y" --> "smallest y". | 995 // wise), which means "biggest y" --> "smallest y". |
| 934 for (BookmarkButton* button in buttons_.get()) { | 996 for (BookmarkButton* button in buttons_.get()) { |
| 935 CGFloat midpoint = NSMidY([button frame]); | 997 CGFloat midpoint = NSMidY([button frame]); |
| 936 if (dropLocation.y > midpoint) { | 998 if (dropLocation.y > midpoint) { |
| 937 break; | 999 break; |
| 938 } | 1000 } |
| 939 buttonToTheTopOfDraggedButton = button; | 1001 buttonToTheTopOfDraggedButton = button; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 else | 1055 else |
| 994 [self bookmarkModel]->Move(sourceNode, destParent, destIndex); | 1056 [self bookmarkModel]->Move(sourceNode, destParent, destIndex); |
| 995 wasCopiedOrMoved = YES; | 1057 wasCopiedOrMoved = YES; |
| 996 // Movement of a node triggers observers (like us) to rebuild the | 1058 // Movement of a node triggers observers (like us) to rebuild the |
| 997 // bar so we don't have to do so explicitly. | 1059 // bar so we don't have to do so explicitly. |
| 998 } | 1060 } |
| 999 | 1061 |
| 1000 return wasCopiedOrMoved; | 1062 return wasCopiedOrMoved; |
| 1001 } | 1063 } |
| 1002 | 1064 |
| 1065 #pragma mark NSWindowDelegate Functions | |
| 1066 | |
| 1067 - (void)windowWillClose:(NSNotification*)notification { | |
| 1068 // If a "hover open" is pending when the bookmark bar folder is | |
| 1069 // closed, be sure it gets cancelled. | |
| 1070 [NSObject cancelPreviousPerformRequestsWithTarget:self]; | |
| 1071 | |
| 1072 [self endScroll]; // Just in case we were scrolling. | |
| 1073 [barController_ childFolderWillClose:self]; | |
| 1074 [self closeBookmarkFolder:self]; | |
| 1075 [self autorelease]; | |
| 1076 } | |
| 1077 | |
| 1003 #pragma mark BookmarkButtonDelegate Protocol | 1078 #pragma mark BookmarkButtonDelegate Protocol |
| 1004 | 1079 |
| 1005 - (void)fillPasteboard:(NSPasteboard*)pboard | 1080 - (void)fillPasteboard:(NSPasteboard*)pboard |
| 1006 forDragOfButton:(BookmarkButton*)button { | 1081 forDragOfButton:(BookmarkButton*)button { |
| 1007 [[self folderTarget] fillPasteboard:pboard forDragOfButton:button]; | 1082 [[self folderTarget] fillPasteboard:pboard forDragOfButton:button]; |
| 1008 | 1083 |
| 1009 // Close our folder menu and submenus since we know we're going to be dragged. | 1084 // Close our folder menu and submenus since we know we're going to be dragged. |
| 1010 [self closeBookmarkFolder:self]; | 1085 [self closeBookmarkFolder:self]; |
| 1011 } | 1086 } |
| 1012 | 1087 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1273 // which is where the new button will be located. | 1348 // which is where the new button will be located. |
| 1274 newButtonFrame = [button frame]; | 1349 newButtonFrame = [button frame]; |
| 1275 NSRect buttonFrame = [button frame]; | 1350 NSRect buttonFrame = [button frame]; |
| 1276 buttonFrame.origin.y += bookmarks::kBookmarkButtonVerticalSpan; | 1351 buttonFrame.origin.y += bookmarks::kBookmarkButtonVerticalSpan; |
| 1277 [button setFrame:buttonFrame]; | 1352 [button setFrame:buttonFrame]; |
| 1278 } | 1353 } |
| 1279 [[button cell] mouseExited:nil]; // De-highlight. | 1354 [[button cell] mouseExited:nil]; // De-highlight. |
| 1280 BookmarkButton* newButton = [self makeButtonForNode:node | 1355 BookmarkButton* newButton = [self makeButtonForNode:node |
| 1281 frame:newButtonFrame]; | 1356 frame:newButtonFrame]; |
| 1282 [buttons_ insertObject:newButton atIndex:buttonIndex]; | 1357 [buttons_ insertObject:newButton atIndex:buttonIndex]; |
| 1283 [mainView_ addSubview:newButton]; | 1358 [folderView_ addSubview:newButton]; |
| 1284 | 1359 |
| 1285 // Close any child folder(s) which may still be open. | 1360 // Close any child folder(s) which may still be open. |
| 1286 [self closeBookmarkFolder:self]; | 1361 [self closeBookmarkFolder:self]; |
| 1287 | 1362 |
| 1288 // Prelim height of the window. We'll trim later as needed. | 1363 [self adjustWindowForButtonCount:[buttons_ count]]; |
| 1289 int height = [self windowHeightForButtonCount:[buttons_ count]]; | |
| 1290 [self adjustWindowForHeight:height]; | |
| 1291 } | 1364 } |
| 1292 | 1365 |
| 1293 // More code which essentially duplicates that of BookmarkBarController. | 1366 // More code which essentially duplicates that of BookmarkBarController. |
| 1294 // TODO(mrossetti,jrg): http://crbug.com/35966 | 1367 // TODO(mrossetti,jrg): http://crbug.com/35966 |
| 1295 - (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point { | 1368 - (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point { |
| 1296 DCHECK([urls count] == [titles count]); | 1369 DCHECK([urls count] == [titles count]); |
| 1297 BOOL nodesWereAdded = NO; | 1370 BOOL nodesWereAdded = NO; |
| 1298 // Figure out where these new bookmarks nodes are to be added. | 1371 // Figure out where these new bookmarks nodes are to be added. |
| 1299 BookmarkButton* button = [self buttonForDroppingOnAtPoint:point]; | 1372 BookmarkButton* button = [self buttonForDroppingOnAtPoint:point]; |
| 1300 BookmarkModel* bookmarkModel = [self bookmarkModel]; | 1373 BookmarkModel* bookmarkModel = [self bookmarkModel]; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1387 // http://crbug.com/54324 | 1460 // http://crbug.com/54324 |
| 1388 for (NSButton* button in buttons_.get()) { | 1461 for (NSButton* button in buttons_.get()) { |
| 1389 if ([button showsBorderOnlyWhileMouseInside]) { | 1462 if ([button showsBorderOnlyWhileMouseInside]) { |
| 1390 [button setShowsBorderOnlyWhileMouseInside:NO]; | 1463 [button setShowsBorderOnlyWhileMouseInside:NO]; |
| 1391 [button setShowsBorderOnlyWhileMouseInside:YES]; | 1464 [button setShowsBorderOnlyWhileMouseInside:YES]; |
| 1392 } | 1465 } |
| 1393 } | 1466 } |
| 1394 | 1467 |
| 1395 [oldButton setDelegate:nil]; | 1468 [oldButton setDelegate:nil]; |
| 1396 [oldButton removeFromSuperview]; | 1469 [oldButton removeFromSuperview]; |
| 1397 if (animate && !ignoreAnimations_) | |
| 1398 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, | |
| 1399 NSZeroSize, nil, nil, nil); | |
| 1400 [buttons_ removeObjectAtIndex:buttonIndex]; | 1470 [buttons_ removeObjectAtIndex:buttonIndex]; |
| 1401 for (NSInteger i = 0; i < buttonIndex; ++i) { | 1471 for (NSInteger i = 0; i < buttonIndex; ++i) { |
| 1402 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 1472 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 1403 NSRect buttonFrame = [button frame]; | 1473 NSRect buttonFrame = [button frame]; |
| 1404 buttonFrame.origin.y -= bookmarks::kBookmarkButtonVerticalSpan; | 1474 buttonFrame.origin.y -= bookmarks::kBookmarkButtonVerticalSpan; |
| 1405 [button setFrame:buttonFrame]; | 1475 [button setFrame:buttonFrame]; |
| 1406 } | 1476 } |
| 1407 // Search for and adjust submenus, if necessary. | 1477 // Search for and adjust submenus, if necessary. |
| 1408 NSInteger buttonCount = [buttons_ count]; | 1478 NSInteger buttonCount = [buttons_ count]; |
| 1409 if (buttonCount) { | 1479 if (buttonCount) { |
| 1410 BookmarkButton* subButton = [folderController_ parentButton]; | 1480 BookmarkButton* subButton = [folderController_ parentButton]; |
| 1411 for (NSInteger i = buttonIndex; i < buttonCount; ++i) { | 1481 for (NSInteger i = buttonIndex; i < buttonCount; ++i) { |
| 1412 BookmarkButton* aButton = [buttons_ objectAtIndex:i]; | 1482 BookmarkButton* aButton = [buttons_ objectAtIndex:i]; |
| 1413 // If this button is showing its menu then we need to move the menu, too. | 1483 // If this button is showing its menu then we need to move the menu, too. |
| 1414 if (aButton == subButton) | 1484 if (aButton == subButton) |
| 1415 [folderController_ offsetFolderMenuWindow:NSMakeSize(0.0, | 1485 [folderController_ offsetFolderMenuWindow:NSMakeSize(0.0, |
| 1416 bookmarks::kBookmarkBarHeight)]; | 1486 bookmarks::kBookmarkBarHeight)]; |
| 1417 } | 1487 } |
| 1418 } else { | 1488 } else { |
| 1419 // If all nodes have been removed from this folder then add in the | 1489 // If all nodes have been removed from this folder then add in the |
| 1420 // 'empty' placeholder button. | 1490 // 'empty' placeholder button. |
| 1421 NSRect buttonFrame = | 1491 NSRect buttonFrame = |
| 1422 NSMakeRect(bookmarks::kBookmarkSubMenuHorizontalPadding, | 1492 NSMakeRect(0, |
| 1423 bookmarks::kBookmarkButtonHeight - | 1493 bookmarks::kBookmarkButtonHeight - |
| 1424 (bookmarks::kBookmarkBarHeight - | 1494 (bookmarks::kBookmarkBarHeight - |
| 1425 bookmarks::kBookmarkVerticalPadding), | 1495 bookmarks::kBookmarkVerticalPadding), |
| 1426 bookmarks::kDefaultBookmarkWidth, | 1496 bookmarks::kDefaultBookmarkWidth, |
| 1427 (bookmarks::kBookmarkBarHeight - | 1497 (bookmarks::kBookmarkBarHeight - |
| 1428 2 * bookmarks::kBookmarkVerticalPadding)); | 1498 2 * bookmarks::kBookmarkVerticalPadding)); |
| 1429 BookmarkButton* button = [self makeButtonForNode:nil | 1499 BookmarkButton* button = [self makeButtonForNode:nil |
| 1430 frame:buttonFrame]; | 1500 frame:buttonFrame]; |
| 1431 [buttons_ addObject:button]; | 1501 [buttons_ addObject:button]; |
| 1432 [mainView_ addSubview:button]; | 1502 [folderView_ addSubview:button]; |
| 1433 buttonCount = 1; | 1503 buttonCount = 1; |
| 1434 } | 1504 } |
| 1435 | 1505 |
| 1436 // Propose a height for the window. We'll trim later as needed. | 1506 [self adjustWindowForButtonCount:buttonCount]; |
| 1437 [self adjustWindowForHeight:[self windowHeightForButtonCount:buttonCount]]; | 1507 |
| 1508 if (animate && !ignoreAnimations_) | |
| 1509 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, | |
| 1510 NSZeroSize, nil, nil, nil); | |
| 1438 } | 1511 } |
| 1439 | 1512 |
| 1440 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 1513 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 1441 (const BookmarkNode*)node { | 1514 (const BookmarkNode*)node { |
| 1442 // See if we are holding this node, otherwise see if it is in our | 1515 // See if we are holding this node, otherwise see if it is in our |
| 1443 // hierarchy of visible folder menus. | 1516 // hierarchy of visible folder menus. |
| 1444 if ([parentButton_ bookmarkNode] == node) | 1517 if ([parentButton_ bookmarkNode] == node) |
| 1445 return self; | 1518 return self; |
| 1446 return [folderController_ controllerForNode:node]; | 1519 return [folderController_ controllerForNode:node]; |
| 1447 } | 1520 } |
| 1448 | 1521 |
| 1449 #pragma mark TestingAPI Only | 1522 #pragma mark TestingAPI Only |
| 1450 | 1523 |
| 1524 - (BOOL)canScrollUp { | |
| 1525 return ![scrollUpArrowView_ isHidden]; | |
| 1526 } | |
| 1527 | |
| 1528 - (BOOL)canScrollDown { | |
| 1529 return ![scrollDownArrowView_ isHidden]; | |
| 1530 } | |
| 1531 | |
| 1532 - (CGFloat)verticalScrollArrowHeight { | |
| 1533 return verticalScrollArrowHeight_; | |
| 1534 } | |
| 1535 | |
| 1536 - (NSView*)visibleView { | |
| 1537 return visibleView_; | |
| 1538 } | |
| 1539 | |
| 1540 - (NSView*)scrollView { | |
| 1541 return scrollView_; | |
| 1542 } | |
| 1543 | |
| 1544 - (NSView*)folderView { | |
| 1545 return folderView_; | |
| 1546 } | |
| 1547 | |
| 1451 - (void)setIgnoreAnimations:(BOOL)ignore { | 1548 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 1452 ignoreAnimations_ = ignore; | 1549 ignoreAnimations_ = ignore; |
| 1453 } | 1550 } |
| 1454 | 1551 |
| 1455 - (BookmarkButton*)buttonThatMouseIsIn { | 1552 - (BookmarkButton*)buttonThatMouseIsIn { |
| 1456 return buttonThatMouseIsIn_; | 1553 return buttonThatMouseIsIn_; |
| 1457 } | 1554 } |
| 1458 | 1555 |
| 1459 @end // BookmarkBarFolderController | 1556 @end // BookmarkBarFolderController |
| OLD | NEW |