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 BOOL wasScrollable = scrollable_; | 400 BOOL wasScrollable = scrollable_; |
397 if (!NSContainsRect(screenFrame, windowFrame)) { | 401 if (!NSContainsRect(screenFrame, windowFrame)) { |
398 scrollable_ = YES; | 402 scrollable_ = YES; |
399 windowFrame = NSIntersectionRect(screenFrame, windowFrame); | 403 windowFrame = NSIntersectionRect(screenFrame, windowFrame); |
400 } else { | 404 } else { |
401 scrollable_ = NO; | 405 scrollable_ = NO; |
402 } | 406 } |
403 NSWindow* window = [self window]; | 407 NSWindow* window = [self window]; |
404 [window setFrame:windowFrame display:YES]; | 408 [window setFrame:windowFrame display:YES]; |
405 // If scrollable then offset the view and show the arrows. | 409 // If scrollable then offset the view and show the arrows. |
406 if (wasScrollable != scrollable_) { | 410 if (wasScrollable != scrollable_) { |
| 411 NSSize windowLocalSize = [scrollView_ convertSize:windowFrame.size |
| 412 fromView:nil]; |
407 [mainView_ scrollPoint:NSMakePoint(0, (NSHeight(mainViewFrame) - | 413 [mainView_ scrollPoint:NSMakePoint(0, (NSHeight(mainViewFrame) - |
408 NSHeight(windowFrame)))]; | 414 windowLocalSize.height))]; |
409 [self showOrHideScrollArrows]; | 415 [self showOrHideScrollArrows]; |
410 [self addOrUpdateScrollTracking]; | 416 [self addOrUpdateScrollTracking]; |
411 } | 417 } |
412 } | 418 } |
413 | 419 |
414 // Determine window size and position. | 420 // Determine window size and position. |
415 // Create buttons for all our nodes. | 421 // Create buttons for all our nodes. |
416 // TODO(jrg): break up into more and smaller routines for easier unit testing. | 422 // TODO(jrg): break up into more and smaller routines for easier unit testing. |
417 - (void)configureWindow { | 423 - (void)configureWindow { |
418 const BookmarkNode* node = [parentButton_ bookmarkNode]; | 424 const BookmarkNode* node = [parentButton_ bookmarkNode]; |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 return [folderController_ controllerForNode:node]; | 1383 return [folderController_ controllerForNode:node]; |
1378 } | 1384 } |
1379 | 1385 |
1380 #pragma mark TestingAPI Only | 1386 #pragma mark TestingAPI Only |
1381 | 1387 |
1382 - (void)setIgnoreAnimations:(BOOL)ignore { | 1388 - (void)setIgnoreAnimations:(BOOL)ignore { |
1383 ignoreAnimations_ = ignore; | 1389 ignoreAnimations_ = ignore; |
1384 } | 1390 } |
1385 | 1391 |
1386 @end // BookmarkBarFolderController | 1392 @end // BookmarkBarFolderController |
OLD | NEW |