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

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

Issue 414037: Merge 32560 - [Mac] Add support for growing or shrinking the window during an... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/249/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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 NSRect newScrIntersectCurFr = NSIntersectionRect([newScreen frame], curFrame); 469 NSRect newScrIntersectCurFr = NSIntersectionRect([newScreen frame], curFrame);
461 NSRect curScrIntersectCurFr = NSIntersectionRect([curScreen frame], curFrame); 470 NSRect curScrIntersectCurFr = NSIntersectionRect([curScreen frame], curFrame);
462 if (newScrIntersectCurFr.size.width*newScrIntersectCurFr.size.height >= 471 if (newScrIntersectCurFr.size.width*newScrIntersectCurFr.size.height >=
463 (curScrIntersectCurFr.size.width*curScrIntersectCurFr.size.height - 1.0)) 472 (curScrIntersectCurFr.size.width*curScrIntersectCurFr.size.height - 1.0))
464 return YES; 473 return YES;
465 474
466 // If it wasn't reasonable, return NO. 475 // If it wasn't reasonable, return NO.
467 return NO; 476 return NO;
468 } 477 }
469 478
479 // Adjusts the window height by the given amount.
480 - (void)adjustWindowHeightBy:(CGFloat)deltaH {
481 // By not adjusting the window height when initializing, we can ensure that
482 // the window opens with the same size that was saved on close.
483 if (initializing_ || [self isFullscreen] || deltaH == 0)
484 return;
485
486 NSWindow* window = [self window];
487 NSRect windowFrame = [window frame];
488 NSRect workarea = [[window screen] visibleFrame];
489
490 // If the window is not already fully in the workarea, do not adjust its frame
491 // at all.
492 if (!NSContainsRect(workarea, windowFrame))
493 return;
494
495 // If the window spans the full height of the current workspace, do not adjust
496 // its frame at all.
497 if (windowFrame.origin.y == workarea.origin.y &&
498 windowFrame.size.height == workarea.size.height)
499 return;
500
501 // Resize the window down until it hits the bottom of the workarea, then if
502 // needed continue resizing upwards. Do not resize the window to be taller
503 // than the current workarea.
504 // Resize the window as requested, keeping the top left corner fixed.
505 windowFrame.origin.y -= deltaH;
506 windowFrame.size.height += deltaH;
507
508 // If the bottom left corner is now outside the visible frame, move the window
509 // up to make it fit, but make sure not to move the top left corner out of the
510 // visible frame.
511 if (windowFrame.origin.y < workarea.origin.y) {
512 windowFrame.origin.y = workarea.origin.y;
513 windowFrame.size.height =
514 std::min(windowFrame.size.height, workarea.size.height);
515 }
516
517 // Disable subview resizing while resizing the window, or else we will get
518 // unwanted renderer resizes. The calling code must call layoutSubviews to
519 // make things right again.
520 NSView* contentView = [window contentView];
521 [contentView setAutoresizesSubviews:NO];
522 [window setFrame:windowFrame display:NO];
523 [contentView setAutoresizesSubviews:YES];
524 }
525
470 // Main method to resize browser window subviews. This method should be called 526 // Main method to resize browser window subviews. This method should be called
471 // when resizing any child of the content view, rather than resizing the views 527 // when resizing any child of the content view, rather than resizing the views
472 // directly. If the view is already the correct height, does not force a 528 // directly. If the view is already the correct height, does not force a
473 // relayout. 529 // relayout.
474 - (void)resizeView:(NSView*)view newHeight:(float)height { 530 - (void)resizeView:(NSView*)view newHeight:(float)height {
475 // We should only ever be called for one of the following four views. 531 // We should only ever be called for one of the following four views.
476 // |downloadShelfController_| may be nil. If we are asked to size the bookmark 532 // |downloadShelfController_| may be nil. If we are asked to size the bookmark
477 // bar directly, its superview must be this controller's content view. 533 // bar directly, its superview must be this controller's content view.
478 DCHECK(view); 534 DCHECK(view);
479 DCHECK(view == [toolbarController_ view] || 535 DCHECK(view == [toolbarController_ view] ||
480 view == [infoBarContainerController_ view] || 536 view == [infoBarContainerController_ view] ||
481 view == [extensionShelfController_ view] || 537 view == [extensionShelfController_ view] ||
482 view == [downloadShelfController_ view] || 538 view == [downloadShelfController_ view] ||
483 view == [bookmarkBarController_ view]); 539 view == [bookmarkBarController_ view]);
484 540
485 // Change the height of the view and call |-layoutSubViews|. We set the height 541 // Change the height of the view and call |-layoutSubViews|. We set the height
486 // here without regard to where the view is on the screen or whether it needs 542 // here without regard to where the view is on the screen or whether it needs
487 // to "grow up" or "grow down." The below call to |-layoutSubviews| will 543 // to "grow up" or "grow down." The below call to |-layoutSubviews| will
488 // position each view correctly. 544 // position each view correctly.
489 NSRect frame = [view frame]; 545 NSRect frame = [view frame];
490 if (frame.size.height == height) 546 if (frame.size.height == height)
491 return; 547 return;
492 548
549 // Grow or shrink the window by the amount of the height change. We adjust
550 // the window height only in two cases:
551 // 1) We are adjusting the height of the bookmark bar and it is currently
552 // animating either open or closed.
553 // 2) We are adjusting the height of the download shelf.
554 //
555 // We do not adjust the window height for bookmark bar changes on the NTP.
556 BOOL shouldAdjustBookmarkHeight =
557 [bookmarkBarController_ isAnimatingBetweenState:bookmarks::kHiddenState
558 andState:bookmarks::kShowingState];
559 if ((shouldAdjustBookmarkHeight && view == [bookmarkBarController_ view]) ||
560 view == [downloadShelfController_ view]) {
561 [[self window] disableScreenUpdatesUntilFlush];
562 CGFloat deltaH = height - frame.size.height;
563 [self adjustWindowHeightBy:deltaH];
564 }
565
493 frame.size.height = height; 566 frame.size.height = height;
494 // TODO(rohitrao): Determine if calling setFrame: twice is bad. 567 // TODO(rohitrao): Determine if calling setFrame: twice is bad.
495 [view setFrame:frame]; 568 [view setFrame:frame];
496 [self layoutSubviews]; 569 [self layoutSubviews];
497 } 570 }
498 571
499 - (void)setAnimationInProgress:(BOOL)inProgress { 572 - (void)setAnimationInProgress:(BOOL)inProgress {
500 [[self tabContentArea] setFastResizeMode:inProgress]; 573 [[self tabContentArea] setFastResizeMode:inProgress];
501 } 574 }
502 575
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 if (statusBubble_) { 1277 if (statusBubble_) {
1205 statusBubble_->UpdateSizeAndPosition(); 1278 statusBubble_->UpdateSizeAndPosition();
1206 } 1279 }
1207 } 1280 }
1208 1281
1209 // (Needed for |BookmarkBarControllerDelegate| protocol.) 1282 // (Needed for |BookmarkBarControllerDelegate| protocol.)
1210 - (void)bookmarkBar:(BookmarkBarController*)controller 1283 - (void)bookmarkBar:(BookmarkBarController*)controller
1211 didChangeFromState:(bookmarks::VisualState)oldState 1284 didChangeFromState:(bookmarks::VisualState)oldState
1212 toState:(bookmarks::VisualState)newState { 1285 toState:(bookmarks::VisualState)newState {
1213 [toolbarController_ 1286 [toolbarController_
1214 setHeightCompression:[controller getDesiredToolbarHeightCompression]];
1215 [toolbarController_
1216 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; 1287 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
1288 [self adjustToolbarAndBookmarkBarForCompression:
1289 [controller getDesiredToolbarHeightCompression]];
1217 } 1290 }
1218 1291
1219 // (Needed for |BookmarkBarControllerDelegate| protocol.) 1292 // (Needed for |BookmarkBarControllerDelegate| protocol.)
1220 - (void)bookmarkBar:(BookmarkBarController*)controller 1293 - (void)bookmarkBar:(BookmarkBarController*)controller
1221 willAnimateFromState:(bookmarks::VisualState)oldState 1294 willAnimateFromState:(bookmarks::VisualState)oldState
1222 toState:(bookmarks::VisualState)newState { 1295 toState:(bookmarks::VisualState)newState {
1223 [toolbarController_ 1296 [toolbarController_
1224 setHeightCompression:[controller getDesiredToolbarHeightCompression]];
1225 [toolbarController_
1226 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; 1297 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
1298 [self adjustToolbarAndBookmarkBarForCompression:
1299 [controller getDesiredToolbarHeightCompression]];
1227 } 1300 }
1228 1301
1229 @end 1302 @end
1230 1303
1231 @implementation BrowserWindowController (Private) 1304 @implementation BrowserWindowController (Private)
1232 1305
1233 // If the browser is in incognito mode, install the image view to decorate 1306 // If the browser is in incognito mode, install the image view to decorate
1234 // the window at the upper right. Use the same base y coordinate as the 1307 // the window at the upper right. Use the same base y coordinate as the
1235 // tab strip. 1308 // tab strip.
1236 - (void)installIncognitoBadge { 1309 - (void)installIncognitoBadge {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? 1576 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ?
1504 YES : NO; 1577 YES : NO;
1505 } 1578 }
1506 1579
1507 - (BOOL)shouldShowDetachedBookmarkBar { 1580 - (BOOL)shouldShowDetachedBookmarkBar {
1508 DCHECK(browser_.get()); 1581 DCHECK(browser_.get());
1509 TabContents* contents = browser_->GetSelectedTabContents(); 1582 TabContents* contents = browser_->GetSelectedTabContents();
1510 return (contents && contents->ShouldShowBookmarkBar()) ? YES : NO; 1583 return (contents && contents->ShouldShowBookmarkBar()) ? YES : NO;
1511 } 1584 }
1512 1585
1586 - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression {
1587 CGFloat newHeight =
1588 [toolbarController_ desiredHeightForCompression:compression];
1589 NSRect toolbarFrame = [[toolbarController_ view] frame];
1590 CGFloat deltaH = newHeight - toolbarFrame.size.height;
1591
1592 if (deltaH == 0)
1593 return;
1594
1595 toolbarFrame.size.height = newHeight;
1596 NSRect bookmarkFrame = [[bookmarkBarController_ view] frame];
1597 bookmarkFrame.size.height = bookmarkFrame.size.height - deltaH;
1598 [[toolbarController_ view] setFrame:toolbarFrame];
1599 [[bookmarkBarController_ view] setFrame:bookmarkFrame];
1600 [self layoutSubviews];
1601 }
1602
1513 @end 1603 @end
1514 1604
1515 @implementation GTMTheme (BrowserThemeProviderInitialization) 1605 @implementation GTMTheme (BrowserThemeProviderInitialization)
1516 + (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider 1606 + (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider
1517 isOffTheRecord:(BOOL)isOffTheRecord { 1607 isOffTheRecord:(BOOL)isOffTheRecord {
1518 // First check if it's in the cache. 1608 // First check if it's in the cache.
1519 // TODO(pinkerton): This might be a good candidate for a singleton. 1609 // TODO(pinkerton): This might be a good candidate for a singleton.
1520 typedef std::pair<std::string, BOOL> ThemeKey; 1610 typedef std::pair<std::string, BOOL> ThemeKey;
1521 static std::map<ThemeKey, GTMTheme*> cache; 1611 static std::map<ThemeKey, GTMTheme*> cache;
1522 ThemeKey key(provider->GetThemeID(), isOffTheRecord); 1612 ThemeKey key(provider->GetThemeID(), isOffTheRecord);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 if (frameOverlayInactiveImage) { 1752 if (frameOverlayInactiveImage) {
1663 [theme setValue:frameOverlayInactiveImage 1753 [theme setValue:frameOverlayInactiveImage
1664 forAttribute:@"overlay" 1754 forAttribute:@"overlay"
1665 style:GTMThemeStyleWindow 1755 style:GTMThemeStyleWindow
1666 state:GTMThemeStateInactiveWindow]; 1756 state:GTMThemeStateInactiveWindow];
1667 } 1757 }
1668 1758
1669 return theme; 1759 return theme;
1670 } 1760 }
1671 @end 1761 @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