summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/bookmarks
diff options
context:
space:
mode:
authormaf@chromium.org <maf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-18 20:49:57 +0000
committermaf@chromium.org <maf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-18 20:49:57 +0000
commit5580fbe8f52193a367e5de5b1d7f798ad8880e74 (patch)
tree72589837d564fe2bb7b6b11c6155782e1e2e692f /chrome/browser/ui/cocoa/bookmarks
parentfca446b95923a78ac6fa26f904dec9d71d63354d (diff)
downloadchromium_src-5580fbe8f52193a367e5de5b1d7f798ad8880e74.zip
chromium_src-5580fbe8f52193a367e5de5b1d7f798ad8880e74.tar.gz
chromium_src-5580fbe8f52193a367e5de5b1d7f798ad8880e74.tar.bz2
Second try - didn't rev the unit test in the first version of this fix.
The bookmark folder menus look bad when squeezed up against the bottom of a screen. Detect this case and automatically switch to showing the menu above the button in this case. BUG=69996 TEST=bookmark_bar_folder_controller_unittest.mm Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=75342 Review URL: http://codereview.chromium.org/6469044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/cocoa/bookmarks')
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h3
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm21
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm8
3 files changed, 24 insertions, 8 deletions
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h
index d974ad8..bf7a85a 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h
@@ -185,7 +185,8 @@
@end
@interface BookmarkBarFolderController(TestingAPI)
-- (NSPoint)windowTopLeftForWidth:(int)windowWidth;
+- (NSPoint)windowTopLeftForWidth:(int)windowWidth
+ height:(int)windowHeight;
- (NSArray*)buttons;
- (BookmarkBarFolderController*)folderController;
- (id)folderTarget;
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm
index 53bb97d..3362886 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm
@@ -458,7 +458,8 @@ struct LayoutMetrics {
// coordinates). The top left is positioned in a manner similar to
// cascading menus. Windows may grow to either the right or left of
// their parent (if a sub-folder) so we need to know |windowWidth|.
-- (NSPoint)windowTopLeftForWidth:(int)windowWidth {
+- (NSPoint)windowTopLeftForWidth:(int)windowWidth height:(int)windowHeight {
+ CGFloat kMinSqueezedMenuHeight = bookmarks::kBookmarkFolderButtonHeight * 2.0;
NSPoint newWindowTopLeft;
if (![parentController_ isKindOfClass:[self class]]) {
// If we're not popping up from one of ourselves, we must be
@@ -485,6 +486,18 @@ struct LayoutMetrics {
newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff,
NSMinX(screenFrame));
}
+ // The menu looks bad when it is squeezed up against the bottom of the
+ // screen and ends up being only a few pixels tall. If it meets the
+ // threshold for this case, instead show the menu above the button.
+ NSRect visFrame = [[[parentButton_ window] screen] visibleFrame];
+ CGFloat availableVerticalSpace = newWindowTopLeft.y -
+ (NSMinY(visFrame) + bookmarks::kScrollWindowVerticalMargin);
+ if ((availableVerticalSpace < kMinSqueezedMenuHeight) &&
+ (windowHeight > availableVerticalSpace)) {
+ newWindowTopLeft.y = std::min(
+ newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]),
+ NSMaxY(visFrame));
+ }
} else {
// Parent is a folder: expose as much as we can vertically; grow right/left.
newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth];
@@ -702,7 +715,8 @@ struct LayoutMetrics {
folderFrame.size.height += deltaMenuHeight;
[folderView_ setFrameSize:folderFrame.size];
CGFloat windowWidth = [self adjustButtonWidths] + padding_;
- NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth];
+ NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth
+ height:deltaMenuHeight];
CGFloat left = newWindowTopLeft.x;
NSSize newSize = NSMakeSize(windowWidth, deltaMenuHeight);
[self adjustWindowLeft:left size:newSize scrollingBy:0.0];
@@ -762,7 +776,8 @@ struct LayoutMetrics {
// base the window width on this ideal button width.
CGFloat buttonWidth = [self adjustButtonWidths];
CGFloat windowWidth = buttonWidth + padding_;
- NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth];
+ NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth
+ height:height];
// Make sure as much of a submenu is exposed (which otherwise would be a
// problem if the parent button is close to the bottom of the screen).
if ([parentController_ isKindOfClass:[self class]]) {
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm
index c0949b8..c1c2441 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm
@@ -256,7 +256,7 @@ TEST_F(BookmarkBarFolderControllerTest, BasicPosition) {
parentController:nil
barController:bar_]);
[bbfc window];
- NSPoint pt = [bbfc windowTopLeftForWidth:0]; // screen coords
+ NSPoint pt = [bbfc windowTopLeftForWidth:0 height:100]; // screen coords
NSPoint buttonOriginInScreen =
[[parentButton window]
convertBaseToScreen:[parentButton
@@ -268,8 +268,8 @@ TEST_F(BookmarkBarFolderControllerTest, BasicPosition) {
bookmarks::kBookmarkMenuOverlap+1);
// Make sure we see the window shift left if it spills off the screen
- pt = [bbfc windowTopLeftForWidth:0];
- NSPoint shifted = [bbfc windowTopLeftForWidth:9999999];
+ pt = [bbfc windowTopLeftForWidth:0 height:100];
+ NSPoint shifted = [bbfc windowTopLeftForWidth:9999999 height:100];
EXPECT_LT(shifted.x, pt.x);
// If parent is a BookmarkBarFolderController, grow right.
@@ -279,7 +279,7 @@ TEST_F(BookmarkBarFolderControllerTest, BasicPosition) {
parentController:bbfc.get()
barController:bar_]);
[bbfc2 window];
- pt = [bbfc2 windowTopLeftForWidth:0];
+ pt = [bbfc2 windowTopLeftForWidth:0 height:100];
// We're now overlapping the window a bit.
EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) -
bookmarks::kBookmarkMenuOverlap);