| OLD | NEW |
| 1 // Copyright (c) 2010 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_folder_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.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" |
| 11 #import "chrome/browser/themes/browser_theme_provider.h" | 11 #import "chrome/browser/themes/browser_theme_provider.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 22 using bookmarks::kBookmarkBarMenuCornerRadius; | 22 using bookmarks::kBookmarkBarMenuCornerRadius; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Frequency of the scrolling timer in seconds. | 26 // Frequency of the scrolling timer in seconds. |
| 27 const NSTimeInterval kBookmarkBarFolderScrollInterval = 0.1; | 27 const NSTimeInterval kBookmarkBarFolderScrollInterval = 0.1; |
| 28 | 28 |
| 29 // 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 |
| 30 // accomodate we do several at a time. | 30 // accomodate we do several at a time. |
| 31 const CGFloat kBookmarkBarFolderScrollAmount = | 31 const CGFloat kBookmarkBarFolderScrollAmount = |
| 32 3 * bookmarks::kBookmarkButtonVerticalSpan; | 32 3 * bookmarks::kBookmarkFolderButtonHeight; |
| 33 | 33 |
| 34 // Amount to scroll for each scroll wheel roll. | 34 // Amount to scroll for each scroll wheel roll. |
| 35 const CGFloat kBookmarkBarFolderScrollWheelAmount = | 35 const CGFloat kBookmarkBarFolderScrollWheelAmount = |
| 36 1 * bookmarks::kBookmarkButtonVerticalSpan; | 36 1 * bookmarks::kBookmarkFolderButtonHeight; |
| 37 | 37 |
| 38 // Determining adjustments to the layout of the folder menu window in response | 38 // Determining adjustments to the layout of the folder menu window in response |
| 39 // to resizing and scrolling relies on many visual factors. The following | 39 // to resizing and scrolling relies on many visual factors. The following |
| 40 // struct is used to pass around these factors to the several support | 40 // struct is used to pass around these factors to the several support |
| 41 // functions involved in the adjustment calculations and application. | 41 // functions involved in the adjustment calculations and application. |
| 42 struct LayoutMetrics { | 42 struct LayoutMetrics { |
| 43 // Metrics applied during the final layout adjustments to the window, | 43 // Metrics applied during the final layout adjustments to the window, |
| 44 // the main visible content view, and the menu content view (i.e. the | 44 // the main visible content view, and the menu content view (i.e. the |
| 45 // scroll view). | 45 // scroll view). |
| 46 CGFloat windowLeft; | 46 CGFloat windowLeft; |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // BELOW the parent button. Our left is the button left; our top | 466 // BELOW the parent button. Our left is the button left; our top |
| 467 // is bottom of button's parent view. | 467 // is bottom of button's parent view. |
| 468 NSPoint buttonBottomLeftInScreen = | 468 NSPoint buttonBottomLeftInScreen = |
| 469 [[parentButton_ window] | 469 [[parentButton_ window] |
| 470 convertBaseToScreen:[parentButton_ | 470 convertBaseToScreen:[parentButton_ |
| 471 convertPoint:NSZeroPoint toView:nil]]; | 471 convertPoint:NSZeroPoint toView:nil]]; |
| 472 NSPoint bookmarkBarBottomLeftInScreen = | 472 NSPoint bookmarkBarBottomLeftInScreen = |
| 473 [[parentButton_ window] | 473 [[parentButton_ window] |
| 474 convertBaseToScreen:[[parentButton_ superview] | 474 convertBaseToScreen:[[parentButton_ superview] |
| 475 convertPoint:NSZeroPoint toView:nil]]; | 475 convertPoint:NSZeroPoint toView:nil]]; |
| 476 newWindowTopLeft = NSMakePoint(buttonBottomLeftInScreen.x, | 476 newWindowTopLeft = NSMakePoint( |
| 477 bookmarkBarBottomLeftInScreen.y + | 477 buttonBottomLeftInScreen.x + bookmarks::kBookmarkBarButtonOffset, |
| 478 bookmarks::kBookmarkBarMenuOffset); | 478 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset); |
| 479 // Make sure the window is on-screen; if not, push left. It is | 479 // Make sure the window is on-screen; if not, push left. It is |
| 480 // intentional that top level folders "push left" slightly | 480 // intentional that top level folders "push left" slightly |
| 481 // different than subfolders. | 481 // different than subfolders. |
| 482 NSRect screenFrame = [[[parentButton_ window] screen] frame]; | 482 NSRect screenFrame = [[[parentButton_ window] screen] frame]; |
| 483 CGFloat spillOff = (newWindowTopLeft.x + windowWidth) - NSMaxX(screenFrame); | 483 CGFloat spillOff = (newWindowTopLeft.x + windowWidth) - NSMaxX(screenFrame); |
| 484 if (spillOff > 0.0) { | 484 if (spillOff > 0.0) { |
| 485 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, | 485 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, |
| 486 NSMinX(screenFrame)); | 486 NSMinX(screenFrame)); |
| 487 } | 487 } |
| 488 } else { | 488 } else { |
| 489 // Parent is a folder; grow right/left. | 489 // Parent is a folder: expose as much as we can vertically; grow right/left. |
| 490 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; | 490 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; |
| 491 NSPoint topOfWindow = NSMakePoint(0, | 491 NSPoint topOfWindow = NSMakePoint(0, |
| 492 (NSMaxY([parentButton_ frame]) + | 492 NSMaxY([parentButton_ frame]) - |
| 493 bookmarks::kBookmarkVerticalPadding)); | 493 bookmarks::kBookmarkVerticalPadding); |
| 494 topOfWindow = [[parentButton_ window] | 494 topOfWindow = [[parentButton_ window] |
| 495 convertBaseToScreen:[[parentButton_ superview] | 495 convertBaseToScreen:[[parentButton_ superview] |
| 496 convertPoint:topOfWindow toView:nil]]; | 496 convertPoint:topOfWindow toView:nil]]; |
| 497 newWindowTopLeft.y = topOfWindow.y; | 497 newWindowTopLeft.y = topOfWindow.y; |
| 498 } | 498 } |
| 499 return newWindowTopLeft; | 499 return newWindowTopLeft; |
| 500 } | 500 } |
| 501 | 501 |
| 502 // Set our window level to the right spot so we're above the menubar, dock, etc. | 502 // Set our window level to the right spot so we're above the menubar, dock, etc. |
| 503 // Factored out so we can override/noop in a unit test. | 503 // Factored out so we can override/noop in a unit test. |
| 504 - (void)configureWindowLevel { | 504 - (void)configureWindowLevel { |
| 505 [[self window] setLevel:NSPopUpMenuWindowLevel]; | 505 [[self window] setLevel:NSPopUpMenuWindowLevel]; |
| 506 } | 506 } |
| 507 | 507 |
| 508 - (int)menuHeightForButtonCount:(int)buttonCount { | 508 - (int)menuHeightForButtonCount:(int)buttonCount { |
| 509 // This does not take into account any padding which may be required at the | 509 // This does not take into account any padding which may be required at the |
| 510 // top and/or bottom of the window. | 510 // top and/or bottom of the window. |
| 511 return (buttonCount * bookmarks::kBookmarkButtonVerticalSpan) + | 511 return (buttonCount * bookmarks::kBookmarkFolderButtonHeight) + |
| 512 bookmarks::kBookmarkVerticalPadding; | 512 2 * bookmarks::kBookmarkVerticalPadding; |
| 513 } | 513 } |
| 514 | 514 |
| 515 - (void)adjustWindowLeft:(CGFloat)windowLeft | 515 - (void)adjustWindowLeft:(CGFloat)windowLeft |
| 516 size:(NSSize)windowSize | 516 size:(NSSize)windowSize |
| 517 scrollingBy:(CGFloat)scrollDelta { | 517 scrollingBy:(CGFloat)scrollDelta { |
| 518 // Callers of this function should make adjustments to the vertical | 518 // Callers of this function should make adjustments to the vertical |
| 519 // attributes of the folder view only (height, scroll position). | 519 // attributes of the folder view only (height, scroll position). |
| 520 // This function will then make appropriate layout adjustments in order | 520 // This function will then make appropriate layout adjustments in order |
| 521 // to accommodate screen/dock margins, scroll-up and scroll-down arrow | 521 // to accommodate screen/dock margins, scroll-up and scroll-down arrow |
| 522 // presentation, etc. | 522 // presentation, etc. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 NSScreen* screen = [[self window] screen]; | 562 NSScreen* screen = [[self window] screen]; |
| 563 CGFloat effectiveFolderY = metrics.folderY; | 563 CGFloat effectiveFolderY = metrics.folderY; |
| 564 if (!metrics.couldScrollUp && !metrics.couldScrollDown) | 564 if (!metrics.couldScrollUp && !metrics.couldScrollDown) |
| 565 effectiveFolderY -= metrics.windowSize.height; | 565 effectiveFolderY -= metrics.windowSize.height; |
| 566 metrics.canScrollUp = effectiveFolderY < metrics.minimumY; | 566 metrics.canScrollUp = effectiveFolderY < metrics.minimumY; |
| 567 CGFloat maximumY = | 567 CGFloat maximumY = |
| 568 NSMaxY([screen frame]) - bookmarks::kScrollWindowVerticalMargin; | 568 NSMaxY([screen frame]) - bookmarks::kScrollWindowVerticalMargin; |
| 569 metrics.canScrollDown = metrics.folderTop > maximumY; | 569 metrics.canScrollDown = metrics.folderTop > maximumY; |
| 570 | 570 |
| 571 // Accommodate changes in the bottom of the menu. | 571 // Accommodate changes in the bottom of the menu. |
| 572 [self adjustMetricsForMenuTopChanges:layoutMetrics]; | 572 [self adjustMetricsForMenuBottomChanges:layoutMetrics]; |
| 573 | 573 |
| 574 // Accommodate changes in the top of the menu. | 574 // Accommodate changes in the top of the menu. |
| 575 [self adjustMetricsForMenuBottomChanges:layoutMetrics]; | 575 [self adjustMetricsForMenuTopChanges:layoutMetrics]; |
| 576 | 576 |
| 577 metrics.scrollerFrame.origin.y += metrics.deltaScrollerY; | 577 metrics.scrollerFrame.origin.y += metrics.deltaScrollerY; |
| 578 metrics.scrollerFrame.size.height += metrics.deltaScrollerHeight; | 578 metrics.scrollerFrame.size.height += metrics.deltaScrollerHeight; |
| 579 metrics.visibleFrame.origin.y += metrics.deltaVisibleY; | 579 metrics.visibleFrame.origin.y += metrics.deltaVisibleY; |
| 580 metrics.visibleFrame.size.height += metrics.deltaVisibleHeight; | 580 metrics.visibleFrame.size.height += metrics.deltaVisibleHeight; |
| 581 metrics.preScroll = metrics.canScrollUp && !metrics.couldScrollUp && | 581 metrics.preScroll = metrics.canScrollUp && !metrics.couldScrollUp && |
| 582 metrics.scrollDelta == 0.0 && metrics.deltaWindowHeight >= 0.0; | 582 metrics.scrollDelta == 0.0 && metrics.deltaWindowHeight >= 0.0; |
| 583 metrics.windowFrame.origin.y += metrics.deltaWindowY; | 583 metrics.windowFrame.origin.y += metrics.deltaWindowY; |
| 584 metrics.windowFrame.origin.x = metrics.windowLeft; | 584 metrics.windowFrame.origin.x = metrics.windowLeft; |
| 585 metrics.windowFrame.size.height += metrics.deltaWindowHeight; | 585 metrics.windowFrame.size.height += metrics.deltaWindowHeight; |
| 586 metrics.windowFrame.size.width = metrics.windowSize.width; | 586 metrics.windowFrame.size.width = metrics.windowSize.width; |
| 587 } | 587 } |
| 588 | 588 |
| 589 - (void)adjustMetricsForMenuTopChanges:(LayoutMetrics*)layoutMetrics { | 589 - (void)adjustMetricsForMenuBottomChanges:(LayoutMetrics*)layoutMetrics { |
| 590 LayoutMetrics& metrics(*layoutMetrics); | 590 LayoutMetrics& metrics(*layoutMetrics); |
| 591 if (metrics.canScrollUp) { | 591 if (metrics.canScrollUp) { |
| 592 if (!metrics.couldScrollUp) { | 592 if (!metrics.couldScrollUp) { |
| 593 // Couldn't -> Can | 593 // Couldn't -> Can |
| 594 metrics.deltaWindowY = -metrics.oldWindowY; | 594 metrics.deltaWindowY = -metrics.oldWindowY; |
| 595 metrics.deltaWindowHeight = -metrics.deltaWindowY; | 595 metrics.deltaWindowHeight = -metrics.deltaWindowY; |
| 596 metrics.deltaVisibleY = metrics.minimumY; | 596 metrics.deltaVisibleY = metrics.minimumY; |
| 597 metrics.deltaVisibleHeight = -metrics.deltaVisibleY; | 597 metrics.deltaVisibleHeight = -metrics.deltaVisibleY; |
| 598 metrics.deltaScrollerY = verticalScrollArrowHeight_; | 598 metrics.deltaScrollerY = verticalScrollArrowHeight_; |
| 599 metrics.deltaScrollerHeight = -metrics.deltaScrollerY; | 599 metrics.deltaScrollerHeight = -metrics.deltaScrollerY; |
| 600 // Adjust the scroll delta if we've grown the window and it is | 600 // Adjust the scroll delta if we've grown the window and it is |
| 601 // now scroll-up-able, but don't adjust it factor if we've | 601 // now scroll-up-able, but don't adjust it if we've |
| 602 // scrolled down and it wasn't scroll-up-able but now is. | 602 // scrolled down and it wasn't scroll-up-able but now is. |
| 603 if (metrics.canScrollDown == metrics.couldScrollDown) { | 603 if (metrics.canScrollDown == metrics.couldScrollDown) { |
| 604 CGFloat deltaScroll = metrics.deltaWindowY + metrics.deltaScrollerY + | 604 CGFloat deltaScroll = metrics.deltaWindowY + metrics.deltaScrollerY + |
| 605 metrics.deltaVisibleY; | 605 metrics.deltaVisibleY; |
| 606 metrics.scrollPoint.y += deltaScroll + metrics.windowSize.height; | 606 metrics.scrollPoint.y += deltaScroll + metrics.windowSize.height; |
| 607 } | 607 } |
| 608 } else if (!metrics.canScrollDown && metrics.windowSize.height > 0.0) { | 608 } else if (!metrics.canScrollDown && metrics.windowSize.height > 0.0) { |
| 609 metrics.scrollPoint.y += metrics.windowSize.height; | 609 metrics.scrollPoint.y += metrics.windowSize.height; |
| 610 } | 610 } |
| 611 } else { | 611 } else { |
| 612 if (metrics.couldScrollUp) { | 612 if (metrics.couldScrollUp) { |
| 613 // Could -> Can't | 613 // Could -> Can't |
| 614 metrics.deltaWindowY = metrics.folderY - metrics.oldWindowY; | 614 metrics.deltaWindowY = metrics.folderY - metrics.oldWindowY; |
| 615 metrics.deltaWindowHeight = -metrics.deltaWindowY; | 615 metrics.deltaWindowHeight = -metrics.deltaWindowY; |
| 616 metrics.deltaVisibleY = -bookmarks::kScrollWindowVerticalMargin; | 616 metrics.deltaVisibleY = -metrics.visibleFrame.origin.y; |
| 617 metrics.deltaVisibleHeight = -metrics.deltaVisibleY; | 617 metrics.deltaVisibleHeight = -metrics.deltaVisibleY; |
| 618 metrics.deltaScrollerY = -verticalScrollArrowHeight_; | 618 metrics.deltaScrollerY = -verticalScrollArrowHeight_; |
| 619 metrics.deltaScrollerHeight = -metrics.deltaScrollerY; | 619 metrics.deltaScrollerHeight = -metrics.deltaScrollerY; |
| 620 // Adjust the scroll delta if we are no longer scroll-up-able | 620 // We are no longer scroll-up-able so the scroll point drops to zero. |
| 621 // and the scroll-down-able-ness hasn't changed. | 621 metrics.scrollPoint.y = 0.0; |
| 622 if (metrics.canScrollDown == metrics.couldScrollDown) { | |
| 623 CGFloat deltaScroll = metrics.deltaWindowY + metrics.deltaScrollerY + | |
| 624 metrics.deltaVisibleY; | |
| 625 metrics.scrollPoint.y += deltaScroll; | |
| 626 } | |
| 627 } else { | 622 } else { |
| 628 // Couldn't -> Can't | 623 // Couldn't -> Can't |
| 629 // Check for menu height change by looking at the relative tops of the | 624 // Check for menu height change by looking at the relative tops of the |
| 630 // menu folder and the window folder, which previously would have been | 625 // menu folder and the window folder, which previously would have been |
| 631 // the same. | 626 // the same. |
| 632 metrics.deltaWindowY = NSMaxY(metrics.windowFrame) - metrics.folderTop; | 627 metrics.deltaWindowY = NSMaxY(metrics.windowFrame) - metrics.folderTop; |
| 633 metrics.deltaWindowHeight = -metrics.deltaWindowY; | 628 metrics.deltaWindowHeight = -metrics.deltaWindowY; |
| 634 } | 629 } |
| 635 } | 630 } |
| 636 } | 631 } |
| 637 | 632 |
| 638 - (void)adjustMetricsForMenuBottomChanges:(LayoutMetrics*)layoutMetrics { | 633 - (void)adjustMetricsForMenuTopChanges:(LayoutMetrics*)layoutMetrics { |
| 639 LayoutMetrics& metrics(*layoutMetrics); | 634 LayoutMetrics& metrics(*layoutMetrics); |
| 640 if (metrics.canScrollDown == metrics.couldScrollDown) { | 635 if (metrics.canScrollDown == metrics.couldScrollDown) { |
| 641 if (!metrics.canScrollDown) { | 636 if (!metrics.canScrollDown) { |
| 642 // Not scroll-down-able but the menu top has changed. | 637 // Not scroll-down-able but the menu top has changed. |
| 643 metrics.deltaWindowHeight += metrics.scrollDelta; | 638 metrics.deltaWindowHeight += metrics.scrollDelta; |
| 644 } | 639 } |
| 645 } else { | 640 } else { |
| 646 if (metrics.canScrollDown) { | 641 if (metrics.canScrollDown) { |
| 647 // Couldn't -> Can | 642 // Couldn't -> Can |
| 648 metrics.deltaWindowHeight += (NSMaxY([[[self window] screen] frame]) - | 643 metrics.deltaWindowHeight += (NSMaxY([[[self window] screen] frame]) - |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 | 721 |
| 727 // Prelim height of the window. We'll trim later as needed. | 722 // Prelim height of the window. We'll trim later as needed. |
| 728 int height = [self menuHeightForButtonCount:buttons]; | 723 int height = [self menuHeightForButtonCount:buttons]; |
| 729 // We'll need this soon... | 724 // We'll need this soon... |
| 730 [self window]; | 725 [self window]; |
| 731 | 726 |
| 732 // TODO(jrg): combine with frame code in bookmark_bar_controller.mm | 727 // TODO(jrg): combine with frame code in bookmark_bar_controller.mm |
| 733 // http://crbug.com/35966 | 728 // http://crbug.com/35966 |
| 734 NSRect buttonsOuterFrame = NSMakeRect( | 729 NSRect buttonsOuterFrame = NSMakeRect( |
| 735 0, | 730 0, |
| 736 (height - bookmarks::kBookmarkButtonVerticalSpan), | 731 height - bookmarks::kBookmarkFolderButtonHeight - |
| 732 bookmarks::kBookmarkVerticalPadding, |
| 737 bookmarks::kDefaultBookmarkWidth, | 733 bookmarks::kDefaultBookmarkWidth, |
| 738 bookmarks::kBookmarkButtonHeight); | 734 bookmarks::kBookmarkFolderButtonHeight); |
| 739 | 735 |
| 740 // TODO(jrg): combine with addNodesToButtonList: code from | 736 // TODO(jrg): combine with addNodesToButtonList: code from |
| 741 // bookmark_bar_controller.mm (but use y offset) | 737 // bookmark_bar_controller.mm (but use y offset) |
| 742 // http://crbug.com/35966 | 738 // http://crbug.com/35966 |
| 743 if (!node->GetChildCount()) { | 739 if (!node->GetChildCount()) { |
| 744 // If no children we are the empty button. | 740 // If no children we are the empty button. |
| 745 BookmarkButton* button = [self makeButtonForNode:nil | 741 BookmarkButton* button = [self makeButtonForNode:nil |
| 746 frame:buttonsOuterFrame]; | 742 frame:buttonsOuterFrame]; |
| 747 [buttons_ addObject:button]; | 743 [buttons_ addObject:button]; |
| 748 [folderView_ addSubview:button]; | 744 [folderView_ addSubview:button]; |
| 749 } else { | 745 } else { |
| 750 for (int i = startingIndex; | 746 for (int i = startingIndex; |
| 751 i < node->GetChildCount(); | 747 i < node->GetChildCount(); |
| 752 i++) { | 748 i++) { |
| 753 const BookmarkNode* child = node->GetChild(i); | 749 const BookmarkNode* child = node->GetChild(i); |
| 754 BookmarkButton* button = [self makeButtonForNode:child | 750 BookmarkButton* button = [self makeButtonForNode:child |
| 755 frame:buttonsOuterFrame]; | 751 frame:buttonsOuterFrame]; |
| 756 [buttons_ addObject:button]; | 752 [buttons_ addObject:button]; |
| 757 [folderView_ addSubview:button]; | 753 [folderView_ addSubview:button]; |
| 758 buttonsOuterFrame.origin.y -= bookmarks::kBookmarkButtonVerticalSpan; | 754 buttonsOuterFrame.origin.y -= bookmarks::kBookmarkFolderButtonHeight; |
| 759 } | 755 } |
| 760 } | 756 } |
| 761 [self layOutWindowWithHeight:height]; | 757 [self layOutWindowWithHeight:height]; |
| 762 } | 758 } |
| 763 | 759 |
| 764 - (void)layOutWindowWithHeight:(CGFloat)height { | 760 - (void)layOutWindowWithHeight:(CGFloat)height { |
| 765 // Lay out the window by adjusting all button widths to be consistent, then | 761 // Lay out the window by adjusting all button widths to be consistent, then |
| 766 // base the window width on this ideal button width. | 762 // base the window width on this ideal button width. |
| 767 CGFloat buttonWidth = [self adjustButtonWidths]; | 763 CGFloat buttonWidth = [self adjustButtonWidths]; |
| 768 CGFloat windowWidth = buttonWidth + padding_; | 764 CGFloat windowWidth = buttonWidth + padding_; |
| 769 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; | 765 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; |
| 770 // Make sure as much of a submenu is exposed (which otherwise would be a | 766 // Make sure as much of a submenu is exposed (which otherwise would be a |
| 771 // problem if the parent button is close to the bottom of the screen). | 767 // problem if the parent button is close to the bottom of the screen). |
| 772 if ([parentController_ isKindOfClass:[self class]]) { | 768 if ([parentController_ isKindOfClass:[self class]]) { |
| 773 newWindowTopLeft.y = MAX(newWindowTopLeft.y, | 769 CGFloat minimumY = NSMinY([[[self window] screen] visibleFrame]) + |
| 774 height + bookmarks::kScrollWindowVerticalMargin); | 770 bookmarks::kScrollWindowVerticalMargin + |
| 771 height; |
| 772 newWindowTopLeft.y = MAX(newWindowTopLeft.y, minimumY); |
| 775 } | 773 } |
| 776 NSWindow* window = [self window]; | 774 NSWindow* window = [self window]; |
| 777 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, | 775 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, |
| 778 newWindowTopLeft.y - height, | 776 newWindowTopLeft.y - height, |
| 779 windowWidth, height); | 777 windowWidth, height); |
| 780 [window setFrame:windowFrame display:NO]; | 778 [window setFrame:windowFrame display:NO]; |
| 781 NSRect folderFrame = NSMakeRect(0, 0, windowWidth, height); | 779 NSRect folderFrame = NSMakeRect(0, 0, windowWidth, height); |
| 782 [folderView_ setFrame:folderFrame]; | 780 [folderView_ setFrame:folderFrame]; |
| 783 NSSize newSize = NSMakeSize(windowWidth, 0.0); | 781 NSSize newSize = NSMakeSize(windowWidth, 0.0); |
| 784 [self adjustWindowLeft:newWindowTopLeft.x size:newSize scrollingBy:0.0]; | 782 [self adjustWindowLeft:newWindowTopLeft.x size:newSize scrollingBy:0.0]; |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 disposition:(WindowOpenDisposition)disposition { | 1440 disposition:(WindowOpenDisposition)disposition { |
| 1443 [barController_ openAll:node disposition:disposition]; | 1441 [barController_ openAll:node disposition:disposition]; |
| 1444 } | 1442 } |
| 1445 | 1443 |
| 1446 - (void)addButtonForNode:(const BookmarkNode*)node | 1444 - (void)addButtonForNode:(const BookmarkNode*)node |
| 1447 atIndex:(NSInteger)buttonIndex { | 1445 atIndex:(NSInteger)buttonIndex { |
| 1448 // Propose the frame for the new button. By default, this will be set to the | 1446 // Propose the frame for the new button. By default, this will be set to the |
| 1449 // topmost button's frame (and there will always be one) offset upward in | 1447 // topmost button's frame (and there will always be one) offset upward in |
| 1450 // anticipation of insertion. | 1448 // anticipation of insertion. |
| 1451 NSRect newButtonFrame = [[buttons_ objectAtIndex:0] frame]; | 1449 NSRect newButtonFrame = [[buttons_ objectAtIndex:0] frame]; |
| 1452 newButtonFrame.origin.y += bookmarks::kBookmarkButtonVerticalSpan; | 1450 newButtonFrame.origin.y += bookmarks::kBookmarkFolderButtonHeight; |
| 1453 // When adding a button to an empty folder we must remove the 'empty' | 1451 // When adding a button to an empty folder we must remove the 'empty' |
| 1454 // placeholder button. This can be detected by checking for a parent | 1452 // placeholder button. This can be detected by checking for a parent |
| 1455 // child count of 1. | 1453 // child count of 1. |
| 1456 const BookmarkNode* parentNode = node->GetParent(); | 1454 const BookmarkNode* parentNode = node->GetParent(); |
| 1457 if (parentNode->GetChildCount() == 1) { | 1455 if (parentNode->GetChildCount() == 1) { |
| 1458 BookmarkButton* emptyButton = [buttons_ lastObject]; | 1456 BookmarkButton* emptyButton = [buttons_ lastObject]; |
| 1459 newButtonFrame = [emptyButton frame]; | 1457 newButtonFrame = [emptyButton frame]; |
| 1460 [emptyButton setDelegate:nil]; | 1458 [emptyButton setDelegate:nil]; |
| 1461 [emptyButton removeFromSuperview]; | 1459 [emptyButton removeFromSuperview]; |
| 1462 [buttons_ removeLastObject]; | 1460 [buttons_ removeLastObject]; |
| 1463 } | 1461 } |
| 1464 | 1462 |
| 1465 if (buttonIndex == -1 || buttonIndex > (NSInteger)[buttons_ count]) | 1463 if (buttonIndex == -1 || buttonIndex > (NSInteger)[buttons_ count]) |
| 1466 buttonIndex = [buttons_ count]; | 1464 buttonIndex = [buttons_ count]; |
| 1467 | 1465 |
| 1468 // Offset upward by one button height all buttons above insertion location. | 1466 // Offset upward by one button height all buttons above insertion location. |
| 1469 BookmarkButton* button = nil; // Remember so it can be de-highlighted. | 1467 BookmarkButton* button = nil; // Remember so it can be de-highlighted. |
| 1470 for (NSInteger i = 0; i < buttonIndex; ++i) { | 1468 for (NSInteger i = 0; i < buttonIndex; ++i) { |
| 1471 button = [buttons_ objectAtIndex:i]; | 1469 button = [buttons_ objectAtIndex:i]; |
| 1472 // Remember this location in case it's the last button being moved | 1470 // Remember this location in case it's the last button being moved |
| 1473 // which is where the new button will be located. | 1471 // which is where the new button will be located. |
| 1474 newButtonFrame = [button frame]; | 1472 newButtonFrame = [button frame]; |
| 1475 NSRect buttonFrame = [button frame]; | 1473 NSRect buttonFrame = [button frame]; |
| 1476 buttonFrame.origin.y += bookmarks::kBookmarkButtonVerticalSpan; | 1474 buttonFrame.origin.y += bookmarks::kBookmarkFolderButtonHeight; |
| 1477 [button setFrame:buttonFrame]; | 1475 [button setFrame:buttonFrame]; |
| 1478 } | 1476 } |
| 1479 [[button cell] mouseExited:nil]; // De-highlight. | 1477 [[button cell] mouseExited:nil]; // De-highlight. |
| 1480 BookmarkButton* newButton = [self makeButtonForNode:node | 1478 BookmarkButton* newButton = [self makeButtonForNode:node |
| 1481 frame:newButtonFrame]; | 1479 frame:newButtonFrame]; |
| 1482 [buttons_ insertObject:newButton atIndex:buttonIndex]; | 1480 [buttons_ insertObject:newButton atIndex:buttonIndex]; |
| 1483 [folderView_ addSubview:newButton]; | 1481 [folderView_ addSubview:newButton]; |
| 1484 | 1482 |
| 1485 // Close any child folder(s) which may still be open. | 1483 // Close any child folder(s) which may still be open. |
| 1486 [self closeBookmarkFolder:self]; | 1484 [self closeBookmarkFolder:self]; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1538 [buttons_ removeObjectAtIndex:fromIndex]; | 1536 [buttons_ removeObjectAtIndex:fromIndex]; |
| 1539 NSRect movedFrame = [movedButton frame]; | 1537 NSRect movedFrame = [movedButton frame]; |
| 1540 NSPoint toOrigin = movedFrame.origin; | 1538 NSPoint toOrigin = movedFrame.origin; |
| 1541 [movedButton setHidden:YES]; | 1539 [movedButton setHidden:YES]; |
| 1542 if (fromIndex < toIndex) { | 1540 if (fromIndex < toIndex) { |
| 1543 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex - 1]; | 1541 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex - 1]; |
| 1544 toOrigin = [targetButton frame].origin; | 1542 toOrigin = [targetButton frame].origin; |
| 1545 for (NSInteger i = fromIndex; i < toIndex; ++i) { | 1543 for (NSInteger i = fromIndex; i < toIndex; ++i) { |
| 1546 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 1544 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 1547 NSRect frame = [button frame]; | 1545 NSRect frame = [button frame]; |
| 1548 frame.origin.y += bookmarks::kBookmarkButtonVerticalSpan; | 1546 frame.origin.y += bookmarks::kBookmarkFolderButtonHeight; |
| 1549 [button setFrameOrigin:frame.origin]; | 1547 [button setFrameOrigin:frame.origin]; |
| 1550 } | 1548 } |
| 1551 } else { | 1549 } else { |
| 1552 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex]; | 1550 BookmarkButton* targetButton = [buttons_ objectAtIndex:toIndex]; |
| 1553 toOrigin = [targetButton frame].origin; | 1551 toOrigin = [targetButton frame].origin; |
| 1554 for (NSInteger i = fromIndex - 1; i >= toIndex; --i) { | 1552 for (NSInteger i = fromIndex - 1; i >= toIndex; --i) { |
| 1555 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 1553 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 1556 NSRect buttonFrame = [button frame]; | 1554 NSRect buttonFrame = [button frame]; |
| 1557 buttonFrame.origin.y -= bookmarks::kBookmarkButtonVerticalSpan; | 1555 buttonFrame.origin.y -= bookmarks::kBookmarkFolderButtonHeight; |
| 1558 [button setFrameOrigin:buttonFrame.origin]; | 1556 [button setFrameOrigin:buttonFrame.origin]; |
| 1559 } | 1557 } |
| 1560 } | 1558 } |
| 1561 [buttons_ insertObject:movedButton atIndex:toIndex]; | 1559 [buttons_ insertObject:movedButton atIndex:toIndex]; |
| 1562 [movedButton setFrameOrigin:toOrigin]; | 1560 [movedButton setFrameOrigin:toOrigin]; |
| 1563 [movedButton setHidden:NO]; | 1561 [movedButton setHidden:NO]; |
| 1564 } | 1562 } |
| 1565 } | 1563 } |
| 1566 | 1564 |
| 1567 // TODO(jrg): Refactor BookmarkBarFolder common code. http://crbug.com/35966 | 1565 // TODO(jrg): Refactor BookmarkBarFolder common code. http://crbug.com/35966 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1589 [button setShowsBorderOnlyWhileMouseInside:YES]; | 1587 [button setShowsBorderOnlyWhileMouseInside:YES]; |
| 1590 } | 1588 } |
| 1591 } | 1589 } |
| 1592 | 1590 |
| 1593 [oldButton setDelegate:nil]; | 1591 [oldButton setDelegate:nil]; |
| 1594 [oldButton removeFromSuperview]; | 1592 [oldButton removeFromSuperview]; |
| 1595 [buttons_ removeObjectAtIndex:buttonIndex]; | 1593 [buttons_ removeObjectAtIndex:buttonIndex]; |
| 1596 for (NSInteger i = 0; i < buttonIndex; ++i) { | 1594 for (NSInteger i = 0; i < buttonIndex; ++i) { |
| 1597 BookmarkButton* button = [buttons_ objectAtIndex:i]; | 1595 BookmarkButton* button = [buttons_ objectAtIndex:i]; |
| 1598 NSRect buttonFrame = [button frame]; | 1596 NSRect buttonFrame = [button frame]; |
| 1599 buttonFrame.origin.y -= bookmarks::kBookmarkButtonVerticalSpan; | 1597 buttonFrame.origin.y -= bookmarks::kBookmarkFolderButtonHeight; |
| 1600 [button setFrame:buttonFrame]; | 1598 [button setFrame:buttonFrame]; |
| 1601 } | 1599 } |
| 1602 // Search for and adjust submenus, if necessary. | 1600 // Search for and adjust submenus, if necessary. |
| 1603 NSInteger buttonCount = [buttons_ count]; | 1601 NSInteger buttonCount = [buttons_ count]; |
| 1604 if (buttonCount) { | 1602 if (buttonCount) { |
| 1605 BookmarkButton* subButton = [folderController_ parentButton]; | 1603 BookmarkButton* subButton = [folderController_ parentButton]; |
| 1606 for (NSInteger i = buttonIndex; i < buttonCount; ++i) { | 1604 for (NSInteger i = buttonIndex; i < buttonCount; ++i) { |
| 1607 BookmarkButton* aButton = [buttons_ objectAtIndex:i]; | 1605 BookmarkButton* aButton = [buttons_ objectAtIndex:i]; |
| 1608 // If this button is showing its menu then we need to move the menu, too. | 1606 // If this button is showing its menu then we need to move the menu, too. |
| 1609 if (aButton == subButton) | 1607 if (aButton == subButton) |
| 1610 [folderController_ offsetFolderMenuWindow:NSMakeSize(0.0, | 1608 [folderController_ offsetFolderMenuWindow:NSMakeSize(0.0, |
| 1611 bookmarks::kBookmarkBarHeight)]; | 1609 bookmarks::kBookmarkBarHeight)]; |
| 1612 } | 1610 } |
| 1613 } else { | 1611 } else { |
| 1614 // If all nodes have been removed from this folder then add in the | 1612 // If all nodes have been removed from this folder then add in the |
| 1615 // 'empty' placeholder button. | 1613 // 'empty' placeholder button. |
| 1616 NSRect buttonFrame = | 1614 NSRect buttonFrame = |
| 1617 NSMakeRect(0, | 1615 NSMakeRect(0.0, 0.0, bookmarks::kDefaultBookmarkWidth, |
| 1618 bookmarks::kBookmarkButtonHeight - | 1616 bookmarks::kBookmarkFolderButtonHeight); |
| 1619 (bookmarks::kBookmarkBarHeight - | |
| 1620 bookmarks::kBookmarkVerticalPadding), | |
| 1621 bookmarks::kDefaultBookmarkWidth, | |
| 1622 (bookmarks::kBookmarkBarHeight - | |
| 1623 2 * bookmarks::kBookmarkVerticalPadding)); | |
| 1624 BookmarkButton* button = [self makeButtonForNode:nil | 1617 BookmarkButton* button = [self makeButtonForNode:nil |
| 1625 frame:buttonFrame]; | 1618 frame:buttonFrame]; |
| 1626 [buttons_ addObject:button]; | 1619 [buttons_ addObject:button]; |
| 1627 [folderView_ addSubview:button]; | 1620 [folderView_ addSubview:button]; |
| 1628 buttonCount = 1; | 1621 buttonCount = 1; |
| 1629 } | 1622 } |
| 1630 | 1623 |
| 1631 [self adjustWindowForButtonCount:buttonCount]; | 1624 [self adjustWindowForButtonCount:buttonCount]; |
| 1632 | 1625 |
| 1633 if (animate && !ignoreAnimations_) | 1626 if (animate && !ignoreAnimations_) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 | 1665 |
| 1673 - (void)setIgnoreAnimations:(BOOL)ignore { | 1666 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 1674 ignoreAnimations_ = ignore; | 1667 ignoreAnimations_ = ignore; |
| 1675 } | 1668 } |
| 1676 | 1669 |
| 1677 - (BookmarkButton*)buttonThatMouseIsIn { | 1670 - (BookmarkButton*)buttonThatMouseIsIn { |
| 1678 return buttonThatMouseIsIn_; | 1671 return buttonThatMouseIsIn_; |
| 1679 } | 1672 } |
| 1680 | 1673 |
| 1681 @end // BookmarkBarFolderController | 1674 @end // BookmarkBarFolderController |
| OLD | NEW |