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

Side by Side Diff: chrome/browser/cocoa/browser_window_controller.mm

Issue 391035: [Mac] Add support for growing or shrinking the window during animations.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include <Carbon/Carbon.h> 5 #include <Carbon/Carbon.h>
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "base/mac_util.h" 8 #include "base/mac_util.h"
9 #include "base/scoped_nsdisable_screen_updates.h" 9 #include "base/scoped_nsdisable_screen_updates.h"
10 #import "base/scoped_nsobject.h" 10 #import "base/scoped_nsobject.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Repositions the windows subviews. 85 // Repositions the windows subviews.
86 - (void)layoutSubviews; 86 - (void)layoutSubviews;
87 87
88 // Should we show the normal bookmark bar? 88 // Should we show the normal bookmark bar?
89 - (BOOL)shouldShowBookmarkBar; 89 - (BOOL)shouldShowBookmarkBar;
90 90
91 // Is the current page one for which the bookmark should be shown detached *if* 91 // Is the current page one for which the bookmark should be shown detached *if*
92 // the normal bookmark bar is not shown? 92 // the normal bookmark bar is not shown?
93 - (BOOL)shouldShowDetachedBookmarkBar; 93 - (BOOL)shouldShowDetachedBookmarkBar;
94 94
95 // Sets the toolbar's height to a value appropriate for the given compression.
96 // Also adjusts the bookmark bar's height by the opposite amount in order to
97 // keep the total height of the two views constant.
98 - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression;
99
95 @end 100 @end
96 101
97 102
98 @implementation BrowserWindowController 103 @implementation BrowserWindowController
99 104
100 // Load the browser window nib and do any Cocoa-specific initialization. 105 // Load the browser window nib and do any Cocoa-specific initialization.
101 // Takes ownership of |browser|. Note that the nib also sets this controller 106 // Takes ownership of |browser|. Note that the nib also sets this controller
102 // up as the window's delegate. 107 // up as the window's delegate.
103 - (id)initWithBrowser:(Browser*)browser { 108 - (id)initWithBrowser:(Browser*)browser {
104 return [self initWithBrowser:browser takeOwnership:YES]; 109 return [self initWithBrowser:browser takeOwnership:YES];
105 } 110 }
106 111
107 // Private (TestingAPI) init routine with testing options. 112 // Private (TestingAPI) init routine with testing options.
108 - (id)initWithBrowser:(Browser*)browser takeOwnership:(BOOL)ownIt { 113 - (id)initWithBrowser:(Browser*)browser takeOwnership:(BOOL)ownIt {
109 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we 114 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we
110 // can override it in a unit test. 115 // can override it in a unit test.
111 NSString* nibpath = [mac_util::MainAppBundle() 116 NSString* nibpath = [mac_util::MainAppBundle()
112 pathForResource:@"BrowserWindow" 117 pathForResource:@"BrowserWindow"
113 ofType:@"nib"]; 118 ofType:@"nib"];
114 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { 119 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
115 DCHECK(browser); 120 DCHECK(browser);
121 initializing_ = YES;
116 browser_.reset(browser); 122 browser_.reset(browser);
117 ownsBrowser_ = ownIt; 123 ownsBrowser_ = ownIt;
118 tabObserver_.reset( 124 tabObserver_.reset(
119 new TabStripModelObserverBridge(browser->tabstrip_model(), self)); 125 new TabStripModelObserverBridge(browser->tabstrip_model(), self));
120 NSWindow* window = [self window]; 126 NSWindow* window = [self window];
121 windowShim_.reset(new BrowserWindowCocoa(browser, self, window)); 127 windowShim_.reset(new BrowserWindowCocoa(browser, self, window));
122 128
123 129
124 // Sets the window to not have rounded corners, which prevents 130 // Sets the window to not have rounded corners, which prevents
125 // the resize control from being inset slightly and looking ugly. 131 // the resize control from being inset slightly and looking ugly.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 resizeDelegate:self]); 218 resizeDelegate:self]);
213 [[[self window] contentView] addSubview:[extensionShelfController_ view]]; 219 [[[self window] contentView] addSubview:[extensionShelfController_ view]];
214 [extensionShelfController_ wasInsertedIntoWindow]; 220 [extensionShelfController_ wasInsertedIntoWindow];
215 } 221 }
216 222
217 // Force a relayout of all the various bars. 223 // Force a relayout of all the various bars.
218 [self layoutSubviews]; 224 [self layoutSubviews];
219 225
220 // Create the bridge for the status bubble. 226 // Create the bridge for the status bubble.
221 statusBubble_ = new StatusBubbleMac([self window], self); 227 statusBubble_ = new StatusBubbleMac([self window], self);
228
229 // We are done initializing now.
230 initializing_ = NO;
222 } 231 }
223 return self; 232 return self;
224 } 233 }
225 234
226 - (void)dealloc { 235 - (void)dealloc {
227 browser_->CloseAllTabs(); 236 browser_->CloseAllTabs();
228 [downloadShelfController_ exiting]; 237 [downloadShelfController_ exiting];
229 238
230 // Under certain testing configurations we may not actually own the browser. 239 // Under certain testing configurations we may not actually own the browser.
231 if (ownsBrowser_ == NO) 240 if (ownsBrowser_ == NO)
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 NSRect newScrIntersectCurFr = NSIntersectionRect([newScreen frame], curFrame); 470 NSRect newScrIntersectCurFr = NSIntersectionRect([newScreen frame], curFrame);
462 NSRect curScrIntersectCurFr = NSIntersectionRect([curScreen frame], curFrame); 471 NSRect curScrIntersectCurFr = NSIntersectionRect([curScreen frame], curFrame);
463 if (newScrIntersectCurFr.size.width*newScrIntersectCurFr.size.height >= 472 if (newScrIntersectCurFr.size.width*newScrIntersectCurFr.size.height >=
464 (curScrIntersectCurFr.size.width*curScrIntersectCurFr.size.height - 1.0)) 473 (curScrIntersectCurFr.size.width*curScrIntersectCurFr.size.height - 1.0))
465 return YES; 474 return YES;
466 475
467 // If it wasn't reasonable, return NO. 476 // If it wasn't reasonable, return NO.
468 return NO; 477 return NO;
469 } 478 }
470 479
480 // Adjusts the window height by the given amount.
481 - (void)adjustWindowHeightBy:(CGFloat)deltaH {
482 // By not adjusting the window height when initializing, we can ensure that
483 // the window opens with the same size that was saved on close.
484 if (initializing_ || [self isFullscreen] || deltaH == 0)
485 return;
486
487 NSWindow* window = [self window];
488 NSRect windowFrame = [window frame];
489 NSRect workarea = [[window screen] visibleFrame];
490
491 // If the window is not already fully in the workarea, do not adjust its frame
492 // at all.
493 if (!NSContainsRect(workarea, windowFrame))
494 return;
495
496 // If the window spans the full height of the current workspace, do not adjust
497 // its frame at all.
498 if (windowFrame.origin.y == workarea.origin.y &&
499 windowFrame.size.height == workarea.size.height)
500 return;
501
502 // Resize the window down until it hits the bottom of the workarea, then if
503 // needed continue resizing upwards. Do not resize the window to be taller
504 // than the current workarea.
505 // Resize the window as requested, keeping the top left corner fixed.
506 windowFrame.origin.y -= deltaH;
507 windowFrame.size.height += deltaH;
508
509 // If the bottom left corner is now outside the visible frame, move the window
510 // up to make it fit, but make sure not to move the top left corner out of the
511 // visible frame.
512 if (windowFrame.origin.y < workarea.origin.y) {
513 windowFrame.origin.y = workarea.origin.y;
514 windowFrame.size.height =
515 std::min(windowFrame.size.height, workarea.size.height);
516 }
517
518 // Disable subview resizing while resizing the window, or else we will get
519 // unwanted renderer resizes. The calling code must call layoutSubviews to
520 // make things right again.
521 NSView* contentView = [window contentView];
522 [contentView setAutoresizesSubviews:NO];
523 [window setFrame:windowFrame display:NO];
524 [contentView setAutoresizesSubviews:YES];
525 }
526
471 // Main method to resize browser window subviews. This method should be called 527 // Main method to resize browser window subviews. This method should be called
472 // when resizing any child of the content view, rather than resizing the views 528 // when resizing any child of the content view, rather than resizing the views
473 // directly. If the view is already the correct height, does not force a 529 // directly. If the view is already the correct height, does not force a
474 // relayout. 530 // relayout.
475 - (void)resizeView:(NSView*)view newHeight:(float)height { 531 - (void)resizeView:(NSView*)view newHeight:(float)height {
476 // We should only ever be called for one of the following four views. 532 // We should only ever be called for one of the following four views.
477 // |downloadShelfController_| may be nil. If we are asked to size the bookmark 533 // |downloadShelfController_| may be nil. If we are asked to size the bookmark
478 // bar directly, its superview must be this controller's content view. 534 // bar directly, its superview must be this controller's content view.
479 DCHECK(view); 535 DCHECK(view);
480 DCHECK(view == [toolbarController_ view] || 536 DCHECK(view == [toolbarController_ view] ||
481 view == [infoBarContainerController_ view] || 537 view == [infoBarContainerController_ view] ||
482 view == [extensionShelfController_ view] || 538 view == [extensionShelfController_ view] ||
483 view == [downloadShelfController_ view] || 539 view == [downloadShelfController_ view] ||
484 view == [bookmarkBarController_ view]); 540 view == [bookmarkBarController_ view]);
485 541
486 // Change the height of the view and call |-layoutSubViews|. We set the height 542 // Change the height of the view and call |-layoutSubViews|. We set the height
487 // here without regard to where the view is on the screen or whether it needs 543 // here without regard to where the view is on the screen or whether it needs
488 // to "grow up" or "grow down." The below call to |-layoutSubviews| will 544 // to "grow up" or "grow down." The below call to |-layoutSubviews| will
489 // position each view correctly. 545 // position each view correctly.
490 NSRect frame = [view frame]; 546 NSRect frame = [view frame];
491 if (frame.size.height == height) 547 if (frame.size.height == height)
492 return; 548 return;
493 549
550 // Grow or shrink the window by the amount of the height change. We adjust
551 // the window height only in two cases:
552 // 1) We are adjusting the height of the bookmark bar and it is currently
553 // animating either open or closed.
554 // 2) We are adjusting the height of the download shelf.
555 //
556 // We do not adjust the window height for bookmark bar changes on the NTP.
557 BOOL shouldAdjustBookmarkHeight =
558 [bookmarkBarController_ isAnimatingBetweenState:bookmarks::kHiddenState
559 andState:bookmarks::kShowingState];
560 if ((shouldAdjustBookmarkHeight && view == [bookmarkBarController_ view]) ||
561 view == [downloadShelfController_ view]) {
562 [[self window] disableScreenUpdatesUntilFlush];
563 CGFloat deltaH = height - frame.size.height;
564 [self adjustWindowHeightBy:deltaH];
565 }
566
494 frame.size.height = height; 567 frame.size.height = height;
495 // TODO(rohitrao): Determine if calling setFrame: twice is bad. 568 // TODO(rohitrao): Determine if calling setFrame: twice is bad.
496 [view setFrame:frame]; 569 [view setFrame:frame];
497 [self layoutSubviews]; 570 [self layoutSubviews];
498 } 571 }
499 572
500 - (void)setAnimationInProgress:(BOOL)inProgress { 573 - (void)setAnimationInProgress:(BOOL)inProgress {
501 [[self tabContentArea] setFastResizeMode:inProgress]; 574 [[self tabContentArea] setFastResizeMode:inProgress];
502 } 575 }
503 576
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 if (statusBubble_) { 1293 if (statusBubble_) {
1221 statusBubble_->UpdateSizeAndPosition(); 1294 statusBubble_->UpdateSizeAndPosition();
1222 } 1295 }
1223 } 1296 }
1224 1297
1225 // (Needed for |BookmarkBarControllerDelegate| protocol.) 1298 // (Needed for |BookmarkBarControllerDelegate| protocol.)
1226 - (void)bookmarkBar:(BookmarkBarController*)controller 1299 - (void)bookmarkBar:(BookmarkBarController*)controller
1227 didChangeFromState:(bookmarks::VisualState)oldState 1300 didChangeFromState:(bookmarks::VisualState)oldState
1228 toState:(bookmarks::VisualState)newState { 1301 toState:(bookmarks::VisualState)newState {
1229 [toolbarController_ 1302 [toolbarController_
1230 setHeightCompression:[controller getDesiredToolbarHeightCompression]];
1231 [toolbarController_
1232 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; 1303 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
1304 [self adjustToolbarAndBookmarkBarForCompression:
1305 [controller getDesiredToolbarHeightCompression]];
1233 } 1306 }
1234 1307
1235 // (Needed for |BookmarkBarControllerDelegate| protocol.) 1308 // (Needed for |BookmarkBarControllerDelegate| protocol.)
1236 - (void)bookmarkBar:(BookmarkBarController*)controller 1309 - (void)bookmarkBar:(BookmarkBarController*)controller
1237 willAnimateFromState:(bookmarks::VisualState)oldState 1310 willAnimateFromState:(bookmarks::VisualState)oldState
1238 toState:(bookmarks::VisualState)newState { 1311 toState:(bookmarks::VisualState)newState {
1239 [toolbarController_ 1312 [toolbarController_
1240 setHeightCompression:[controller getDesiredToolbarHeightCompression]];
1241 [toolbarController_
1242 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; 1313 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
1314 [self adjustToolbarAndBookmarkBarForCompression:
1315 [controller getDesiredToolbarHeightCompression]];
1243 } 1316 }
1244 1317
1245 @end 1318 @end
1246 1319
1247 @implementation BrowserWindowController (Private) 1320 @implementation BrowserWindowController (Private)
1248 1321
1249 // If the browser is in incognito mode, install the image view to decorate 1322 // If the browser is in incognito mode, install the image view to decorate
1250 // the window at the upper right. Use the same base y coordinate as the 1323 // the window at the upper right. Use the same base y coordinate as the
1251 // tab strip. 1324 // tab strip.
1252 - (void)installIncognitoBadge { 1325 - (void)installIncognitoBadge {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? 1592 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ?
1520 YES : NO; 1593 YES : NO;
1521 } 1594 }
1522 1595
1523 - (BOOL)shouldShowDetachedBookmarkBar { 1596 - (BOOL)shouldShowDetachedBookmarkBar {
1524 DCHECK(browser_.get()); 1597 DCHECK(browser_.get());
1525 TabContents* contents = browser_->GetSelectedTabContents(); 1598 TabContents* contents = browser_->GetSelectedTabContents();
1526 return (contents && contents->ShouldShowBookmarkBar()) ? YES : NO; 1599 return (contents && contents->ShouldShowBookmarkBar()) ? YES : NO;
1527 } 1600 }
1528 1601
1602 - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression {
1603 CGFloat newHeight =
1604 [toolbarController_ desiredHeightForCompression:compression];
1605 NSRect toolbarFrame = [[toolbarController_ view] frame];
1606 CGFloat deltaH = newHeight - toolbarFrame.size.height;
1607
1608 if (deltaH == 0)
1609 return;
1610
1611 toolbarFrame.size.height = newHeight;
1612 NSRect bookmarkFrame = [[bookmarkBarController_ view] frame];
1613 bookmarkFrame.size.height = bookmarkFrame.size.height - deltaH;
1614 [[toolbarController_ view] setFrame:toolbarFrame];
1615 [[bookmarkBarController_ view] setFrame:bookmarkFrame];
1616 [self layoutSubviews];
1617 }
1618
1529 @end 1619 @end
1530 1620
1531 @implementation GTMTheme (BrowserThemeProviderInitialization) 1621 @implementation GTMTheme (BrowserThemeProviderInitialization)
1532 + (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider 1622 + (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider
1533 isOffTheRecord:(BOOL)isOffTheRecord { 1623 isOffTheRecord:(BOOL)isOffTheRecord {
1534 // First check if it's in the cache. 1624 // First check if it's in the cache.
1535 // TODO(pinkerton): This might be a good candidate for a singleton. 1625 // TODO(pinkerton): This might be a good candidate for a singleton.
1536 typedef std::pair<std::string, BOOL> ThemeKey; 1626 typedef std::pair<std::string, BOOL> ThemeKey;
1537 static std::map<ThemeKey, GTMTheme*> cache; 1627 static std::map<ThemeKey, GTMTheme*> cache;
1538 ThemeKey key(provider->GetThemeID(), isOffTheRecord); 1628 ThemeKey key(provider->GetThemeID(), isOffTheRecord);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 if (frameOverlayInactiveImage) { 1768 if (frameOverlayInactiveImage) {
1679 [theme setValue:frameOverlayInactiveImage 1769 [theme setValue:frameOverlayInactiveImage
1680 forAttribute:@"overlay" 1770 forAttribute:@"overlay"
1681 style:GTMThemeStyleWindow 1771 style:GTMThemeStyleWindow
1682 state:GTMThemeStateInactiveWindow]; 1772 state:GTMThemeStateInactiveWindow];
1683 } 1773 }
1684 1774
1685 return theme; 1775 return theme;
1686 } 1776 }
1687 @end 1777 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.h ('k') | chrome/browser/cocoa/browser_window_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698