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