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/cocoa/bookmark_bar_folder_controller.h" | 5 #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" |
6 #include "base/mac_util.h" | 6 #include "base/mac_util.h" |
7 #include "base/nsimage_cache_mac.h" | 7 #include "base/nsimage_cache_mac.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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 [[self window] setLevel:NSPopUpMenuWindowLevel]; | 370 [[self window] setLevel:NSPopUpMenuWindowLevel]; |
371 } | 371 } |
372 | 372 |
373 - (void)adjustWindowForHeight:(int)windowHeight { | 373 - (void)adjustWindowForHeight:(int)windowHeight { |
374 // Adjust all button widths to be consistent, determine the best size for | 374 // Adjust all button widths to be consistent, determine the best size for |
375 // the window, and set the window frame. | 375 // the window, and set the window frame. |
376 CGFloat windowWidth = | 376 CGFloat windowWidth = |
377 [self adjustButtonWidths] + (2 * bookmarks::kBookmarkVerticalPadding) + | 377 [self adjustButtonWidths] + (2 * bookmarks::kBookmarkVerticalPadding) + |
378 bookmarks::kScrollViewContentWidthMargin; | 378 bookmarks::kScrollViewContentWidthMargin; |
379 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; | 379 NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; |
| 380 NSSize windowSize = [scrollView_ convertSize:NSMakeSize(windowWidth, |
| 381 windowHeight) |
| 382 toView:nil]; |
| 383 newWindowTopLeft.y -= windowSize.height; |
380 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, | 384 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, |
381 newWindowTopLeft.y - windowHeight, | 385 newWindowTopLeft.y, |
382 windowWidth, | 386 windowSize.width, |
383 windowHeight); | 387 windowSize.height); |
384 | 388 |
385 // Make the scrolled content be the right size (full size). | 389 // Make the scrolled content be the right size (full size). |
386 NSRect mainViewFrame = NSMakeRect(0, 0, | 390 NSRect mainViewFrame = NSMakeRect(0, 0, |
387 NSWidth(windowFrame) - | 391 windowWidth - |
388 bookmarks::kScrollViewContentWidthMargin, | 392 bookmarks::kScrollViewContentWidthMargin, |
389 NSHeight(windowFrame)); | 393 windowHeight); |
390 [mainView_ setFrame:mainViewFrame]; | 394 [mainView_ setFrame:mainViewFrame]; |
391 | 395 |
392 // Make sure the window fits on the screen. If not, constrain. | 396 // Make sure the window fits on the screen. If not, constrain. |
393 // We'll scroll to allow the user to see all the content. | 397 // We'll scroll to allow the user to see all the content. |
394 NSRect screenFrame = [[[self window] screen] frame]; | 398 NSRect screenFrame = [[[self window] screen] frame]; |
395 screenFrame = NSInsetRect(screenFrame, 0, kScrollWindowVerticalMargin); | 399 screenFrame = NSInsetRect(screenFrame, 0, kScrollWindowVerticalMargin); |
396 if (!NSContainsRect(screenFrame, windowFrame)) { | 400 if (!NSContainsRect(screenFrame, windowFrame)) { |
397 scrollable_ = YES; | 401 scrollable_ = YES; |
398 windowFrame = NSIntersectionRect(screenFrame, windowFrame); | 402 windowFrame = NSIntersectionRect(screenFrame, windowFrame); |
399 } else { | 403 } else { |
400 scrollable_ = NO; | 404 scrollable_ = NO; |
401 } | 405 } |
402 [[self window] setFrame:windowFrame display:YES]; | 406 [[self window] setFrame:windowFrame display:YES]; |
403 // If scrollable then offset the view and show the arrows. | 407 // If scrollable then offset the view and show the arrows. |
404 if (scrollable_) { | 408 if (scrollable_) { |
405 [mainView_ scrollPoint:NSMakePoint(0, (NSHeight(mainViewFrame) - | 409 [mainView_ scrollPoint:NSMakePoint(0, (NSHeight(mainViewFrame) - |
406 NSHeight(windowFrame)))]; | 410 windowHeight))]; |
407 [self showOrHideScrollArrows]; | 411 [self showOrHideScrollArrows]; |
408 [self addOrUpdateScrollTracking]; | 412 [self addOrUpdateScrollTracking]; |
409 } | 413 } |
410 } | 414 } |
411 | 415 |
412 // Determine window size and position. | 416 // Determine window size and position. |
413 // Create buttons for all our nodes. | 417 // Create buttons for all our nodes. |
414 // TODO(jrg): break up into more and smaller routines for easier unit testing. | 418 // TODO(jrg): break up into more and smaller routines for easier unit testing. |
415 - (void)configureWindow { | 419 - (void)configureWindow { |
416 const BookmarkNode* node = [parentButton_ bookmarkNode]; | 420 const BookmarkNode* node = [parentButton_ bookmarkNode]; |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 return [folderController_ controllerForNode:node]; | 1379 return [folderController_ controllerForNode:node]; |
1376 } | 1380 } |
1377 | 1381 |
1378 #pragma mark TestingAPI Only | 1382 #pragma mark TestingAPI Only |
1379 | 1383 |
1380 - (void)setIgnoreAnimations:(BOOL)ignore { | 1384 - (void)setIgnoreAnimations:(BOOL)ignore { |
1381 ignoreAnimations_ = ignore; | 1385 ignoreAnimations_ = ignore; |
1382 } | 1386 } |
1383 | 1387 |
1384 @end // BookmarkBarFolderController | 1388 @end // BookmarkBarFolderController |
OLD | NEW |