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

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

Issue 6544010: Revert 75342 - The bookmark folder menus look bad when squeezed up against th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 451 }
452 // Unhappy; do the best we can. 452 // Unhappy; do the best we can.
453 return NSMaxX([[[self window] screen] frame]) - windowWidth; 453 return NSMaxX([[[self window] screen] frame]) - windowWidth;
454 } 454 }
455 455
456 456
457 // Compute and return the top left point of our window (screen 457 // Compute and return the top left point of our window (screen
458 // coordinates). The top left is positioned in a manner similar to 458 // coordinates). The top left is positioned in a manner similar to
459 // cascading menus. Windows may grow to either the right or left of 459 // cascading menus. Windows may grow to either the right or left of
460 // their parent (if a sub-folder) so we need to know |windowWidth|. 460 // their parent (if a sub-folder) so we need to know |windowWidth|.
461 - (NSPoint)windowTopLeftForWidth:(int)windowWidth height:(int)windowHeight { 461 - (NSPoint)windowTopLeftForWidth:(int)windowWidth {
462 CGFloat kMinSqueezedMenuHeight = bookmarks::kBookmarkFolderButtonHeight * 2.0;
463 NSPoint newWindowTopLeft; 462 NSPoint newWindowTopLeft;
464 if (![parentController_ isKindOfClass:[self class]]) { 463 if (![parentController_ isKindOfClass:[self class]]) {
465 // If we're not popping up from one of ourselves, we must be 464 // If we're not popping up from one of ourselves, we must be
466 // popping up from the bookmark bar itself. In this case, start 465 // popping up from the bookmark bar itself. In this case, start
467 // 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
468 // is bottom of button's parent view. 467 // is bottom of button's parent view.
469 NSPoint buttonBottomLeftInScreen = 468 NSPoint buttonBottomLeftInScreen =
470 [[parentButton_ window] 469 [[parentButton_ window]
471 convertBaseToScreen:[parentButton_ 470 convertBaseToScreen:[parentButton_
472 convertPoint:NSZeroPoint toView:nil]]; 471 convertPoint:NSZeroPoint toView:nil]];
473 NSPoint bookmarkBarBottomLeftInScreen = 472 NSPoint bookmarkBarBottomLeftInScreen =
474 [[parentButton_ window] 473 [[parentButton_ window]
475 convertBaseToScreen:[[parentButton_ superview] 474 convertBaseToScreen:[[parentButton_ superview]
476 convertPoint:NSZeroPoint toView:nil]]; 475 convertPoint:NSZeroPoint toView:nil]];
477 newWindowTopLeft = NSMakePoint( 476 newWindowTopLeft = NSMakePoint(
478 buttonBottomLeftInScreen.x + bookmarks::kBookmarkBarButtonOffset, 477 buttonBottomLeftInScreen.x + bookmarks::kBookmarkBarButtonOffset,
479 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset); 478 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset);
480 // 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
481 // intentional that top level folders "push left" slightly 480 // intentional that top level folders "push left" slightly
482 // different than subfolders. 481 // different than subfolders.
483 NSRect screenFrame = [[[parentButton_ window] screen] frame]; 482 NSRect screenFrame = [[[parentButton_ window] screen] frame];
484 CGFloat spillOff = (newWindowTopLeft.x + windowWidth) - NSMaxX(screenFrame); 483 CGFloat spillOff = (newWindowTopLeft.x + windowWidth) - NSMaxX(screenFrame);
485 if (spillOff > 0.0) { 484 if (spillOff > 0.0) {
486 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, 485 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff,
487 NSMinX(screenFrame)); 486 NSMinX(screenFrame));
488 } 487 }
489 // The menu looks bad when it is squeezed up against the bottom of the
490 // screen and ends up being only a few pixels tall. If it meets the
491 // threshold for this case, instead show the menu above the button.
492 NSRect visFrame = [[[parentButton_ window] screen] visibleFrame];
493 CGFloat availableVerticalSpace = newWindowTopLeft.y -
494 (NSMinY(visFrame) + bookmarks::kScrollWindowVerticalMargin);
495 if ((availableVerticalSpace < kMinSqueezedMenuHeight) &&
496 (windowHeight > availableVerticalSpace)) {
497 newWindowTopLeft.y = std::min(
498 newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]),
499 NSMaxY(visFrame));
500 }
501 } else { 488 } else {
502 // Parent is a folder: expose as much as we can vertically; grow right/left. 489 // Parent is a folder: expose as much as we can vertically; grow right/left.
503 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; 490 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth];
504 NSPoint topOfWindow = NSMakePoint(0, 491 NSPoint topOfWindow = NSMakePoint(0,
505 NSMaxY([parentButton_ frame]) - 492 NSMaxY([parentButton_ frame]) -
506 bookmarks::kBookmarkVerticalPadding); 493 bookmarks::kBookmarkVerticalPadding);
507 topOfWindow = [[parentButton_ window] 494 topOfWindow = [[parentButton_ window]
508 convertBaseToScreen:[[parentButton_ superview] 495 convertBaseToScreen:[[parentButton_ superview]
509 convertPoint:topOfWindow toView:nil]]; 496 convertPoint:topOfWindow toView:nil]];
510 newWindowTopLeft.y = topOfWindow.y; 497 newWindowTopLeft.y = topOfWindow.y;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 // If the height has changed then also change the origin, and adjust the 695 // If the height has changed then also change the origin, and adjust the
709 // scroll (if scrolling). 696 // scroll (if scrolling).
710 if ([self canScrollUp]) { 697 if ([self canScrollUp]) {
711 NSPoint scrollPoint = [scrollView_ documentVisibleRect].origin; 698 NSPoint scrollPoint = [scrollView_ documentVisibleRect].origin;
712 scrollPoint.y += deltaMenuHeight; 699 scrollPoint.y += deltaMenuHeight;
713 [[scrollView_ documentView] scrollPoint:scrollPoint]; 700 [[scrollView_ documentView] scrollPoint:scrollPoint];
714 } 701 }
715 folderFrame.size.height += deltaMenuHeight; 702 folderFrame.size.height += deltaMenuHeight;
716 [folderView_ setFrameSize:folderFrame.size]; 703 [folderView_ setFrameSize:folderFrame.size];
717 CGFloat windowWidth = [self adjustButtonWidths] + padding_; 704 CGFloat windowWidth = [self adjustButtonWidths] + padding_;
718 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth 705 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth];
719 height:deltaMenuHeight];
720 CGFloat left = newWindowTopLeft.x; 706 CGFloat left = newWindowTopLeft.x;
721 NSSize newSize = NSMakeSize(windowWidth, deltaMenuHeight); 707 NSSize newSize = NSMakeSize(windowWidth, deltaMenuHeight);
722 [self adjustWindowLeft:left size:newSize scrollingBy:0.0]; 708 [self adjustWindowLeft:left size:newSize scrollingBy:0.0];
723 } 709 }
724 710
725 // Determine window size and position. 711 // Determine window size and position.
726 // Create buttons for all our nodes. 712 // Create buttons for all our nodes.
727 // TODO(jrg): break up into more and smaller routines for easier unit testing. 713 // TODO(jrg): break up into more and smaller routines for easier unit testing.
728 - (void)configureWindow { 714 - (void)configureWindow {
729 const BookmarkNode* node = [parentButton_ bookmarkNode]; 715 const BookmarkNode* node = [parentButton_ bookmarkNode];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 755 }
770 } 756 }
771 [self layOutWindowWithHeight:height]; 757 [self layOutWindowWithHeight:height];
772 } 758 }
773 759
774 - (void)layOutWindowWithHeight:(CGFloat)height { 760 - (void)layOutWindowWithHeight:(CGFloat)height {
775 // 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
776 // base the window width on this ideal button width. 762 // base the window width on this ideal button width.
777 CGFloat buttonWidth = [self adjustButtonWidths]; 763 CGFloat buttonWidth = [self adjustButtonWidths];
778 CGFloat windowWidth = buttonWidth + padding_; 764 CGFloat windowWidth = buttonWidth + padding_;
779 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth 765 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth];
780 height:height];
781 // 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
782 // 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).
783 if ([parentController_ isKindOfClass:[self class]]) { 768 if ([parentController_ isKindOfClass:[self class]]) {
784 CGFloat minimumY = NSMinY([[[self window] screen] visibleFrame]) + 769 CGFloat minimumY = NSMinY([[[self window] screen] visibleFrame]) +
785 bookmarks::kScrollWindowVerticalMargin + 770 bookmarks::kScrollWindowVerticalMargin +
786 height; 771 height;
787 newWindowTopLeft.y = MAX(newWindowTopLeft.y, minimumY); 772 newWindowTopLeft.y = MAX(newWindowTopLeft.y, minimumY);
788 } 773 }
789 NSWindow* window = [self window]; 774 NSWindow* window = [self window];
790 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, 775 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x,
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 1665
1681 - (void)setIgnoreAnimations:(BOOL)ignore { 1666 - (void)setIgnoreAnimations:(BOOL)ignore {
1682 ignoreAnimations_ = ignore; 1667 ignoreAnimations_ = ignore;
1683 } 1668 }
1684 1669
1685 - (BookmarkButton*)buttonThatMouseIsIn { 1670 - (BookmarkButton*)buttonThatMouseIsIn {
1686 return buttonThatMouseIsIn_; 1671 return buttonThatMouseIsIn_;
1687 } 1672 }
1688 1673
1689 @end // BookmarkBarFolderController 1674 @end // BookmarkBarFolderController
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698