summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/cocoa/bookmark_bar_folder_controller.mm9
-rw-r--r--chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm5
2 files changed, 14 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm
index e67e6af..07342ca3 100644
--- a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm
@@ -340,6 +340,15 @@ const CGFloat kScrollWindowVerticalMargin = 0.0;
convertPoint:NSZeroPoint toView:nil]];
newWindowTopLeft = NSMakePoint(buttonBottomLeftInScreen.x,
bookmarkBarBottomLeftInScreen.y);
+ // Make sure the window is on-screen; if not, push left. It is
+ // intentional that top level folders "push left" slightly
+ // different than subfolders.
+ NSRect screenFrame = [[[parentButton_ window] screen] frame];
+ CGFloat spillOff = (newWindowTopLeft.x + windowWidth) - NSMaxX(screenFrame);
+ if (spillOff > 0.0) {
+ newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff,
+ NSMinX(screenFrame));
+ }
} else {
// Parent is a folder; grow right/left.
newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth];
diff --git a/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm
index 11598b7..4b5dda2 100644
--- a/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm
@@ -262,6 +262,11 @@ TEST_F(BookmarkBarFolderControllerTest, BasicPosition) {
EXPECT_LE(abs(pt.x - buttonOriginInScreen.x), 2);
EXPECT_LE(abs(pt.y - buttonOriginInScreen.y), 2);
+ // Make sure we see the window shift left if it spills off the screen
+ pt = [bbfc windowTopLeftForWidth:0];
+ NSPoint shifted = [bbfc windowTopLeftForWidth:9999999];
+ EXPECT_LT(shifted.x, pt.x);
+
// If parent is a BookmarkBarFolderController, grow right.
scoped_nsobject<BookmarkBarFolderControllerLow> bbfc2;
bbfc2.reset([[BookmarkBarFolderControllerLow alloc]