| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/browser_window_controller_private.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #import "base/memory/scoped_nsobject.h" | 10 #import "base/memory/scoped_nsobject.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 DCHECK([previewableContentsController_ activeContainer]); | 88 DCHECK([previewableContentsController_ activeContainer]); |
| 89 DCHECK([[previewableContentsController_ activeContainer] window]); | 89 DCHECK([[previewableContentsController_ activeContainer] window]); |
| 90 tabStripController_.reset([[factory alloc] | 90 tabStripController_.reset([[factory alloc] |
| 91 initWithView:[self tabStripView] | 91 initWithView:[self tabStripView] |
| 92 switchView:[previewableContentsController_ activeContainer] | 92 switchView:[previewableContentsController_ activeContainer] |
| 93 browser:browser_.get() | 93 browser:browser_.get() |
| 94 delegate:self]); | 94 delegate:self]); |
| 95 } | 95 } |
| 96 | 96 |
| 97 - (void)createAndInstallPresentationModeToggleButton { | |
| 98 DCHECK(base::mac::IsOSLionOrLater()); | |
| 99 if (presentationModeToggleButton_.get()) | |
| 100 return; | |
| 101 | |
| 102 // TODO(rohitrao): Make this button prettier. | |
| 103 presentationModeToggleButton_.reset( | |
| 104 [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 25, 25)]); | |
| 105 NSButton* button = presentationModeToggleButton_.get(); | |
| 106 [button setButtonType:NSMomentaryLightButton]; | |
| 107 [button setBezelStyle:NSRegularSquareBezelStyle]; | |
| 108 [button setBordered:NO]; | |
| 109 [[button cell] setHighlightsBy:NSContentsCellMask]; | |
| 110 [[button cell] setShowsStateBy:NSContentsCellMask]; | |
| 111 [button setImage:[NSImage imageNamed:NSImageNameIChatTheaterTemplate]]; | |
| 112 [button setTarget:self]; | |
| 113 [button setAction:@selector(togglePresentationModeForLionOrLater:)]; | |
| 114 [[[[self window] contentView] superview] addSubview:button]; | |
| 115 } | |
| 116 | |
| 117 - (void)saveWindowPositionIfNeeded { | 97 - (void)saveWindowPositionIfNeeded { |
| 118 if (!chrome::ShouldSaveWindowPlacement(browser_.get())) | 98 if (!chrome::ShouldSaveWindowPlacement(browser_.get())) |
| 119 return; | 99 return; |
| 120 | 100 |
| 121 // If we're in fullscreen mode, save the position of the regular window | 101 // If we're in fullscreen mode, save the position of the regular window |
| 122 // instead. | 102 // instead. |
| 123 NSWindow* window = [self isFullscreen] ? savedRegularWindow_ : [self window]; | 103 NSWindow* window = [self isFullscreen] ? savedRegularWindow_ : [self window]; |
| 124 | 104 |
| 125 // Window positions are stored relative to the origin of the primary monitor. | 105 // Window positions are stored relative to the origin of the primary monitor. |
| 126 NSRect monitorFrame = [[[NSScreen screens] objectAtIndex:0] frame]; | 106 NSRect monitorFrame = [[[NSScreen screens] objectAtIndex:0] frame]; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 200 |
| 221 BOOL inPresentationMode = [self inPresentationMode]; | 201 BOOL inPresentationMode = [self inPresentationMode]; |
| 222 CGFloat floatingBarHeight = [self floatingBarHeight]; | 202 CGFloat floatingBarHeight = [self floatingBarHeight]; |
| 223 // In presentation mode, |yOffset| accounts for the sliding position of the | 203 // In presentation mode, |yOffset| accounts for the sliding position of the |
| 224 // floating bar and the extra offset needed to dodge the menu bar. | 204 // floating bar and the extra offset needed to dodge the menu bar. |
| 225 CGFloat yOffset = inPresentationMode ? | 205 CGFloat yOffset = inPresentationMode ? |
| 226 (std::floor((1 - floatingBarShownFraction_) * floatingBarHeight) - | 206 (std::floor((1 - floatingBarShownFraction_) * floatingBarHeight) - |
| 227 [presentationModeController_ floatingBarVerticalOffset]) : 0; | 207 [presentationModeController_ floatingBarVerticalOffset]) : 0; |
| 228 CGFloat maxY = NSMaxY(contentBounds) + yOffset; | 208 CGFloat maxY = NSMaxY(contentBounds) + yOffset; |
| 229 | 209 |
| 230 CGFloat overlayMaxY = | |
| 231 NSMaxY([window frame]) + | |
| 232 std::floor((1 - floatingBarShownFraction_) * floatingBarHeight); | |
| 233 [self layoutPresentationModeToggleAtOverlayMaxX:NSMaxX([window frame]) | |
| 234 overlayMaxY:overlayMaxY]; | |
| 235 | |
| 236 if ([self hasTabStrip]) { | 210 if ([self hasTabStrip]) { |
| 237 // If we need to lay out the top tab strip, replace |maxY| with a higher | 211 // If we need to lay out the top tab strip, replace |maxY| with a higher |
| 238 // value, and then lay out the tab strip. | 212 // value, and then lay out the tab strip. |
| 239 NSRect windowFrame = [contentView convertRect:[window frame] fromView:nil]; | 213 NSRect windowFrame = [contentView convertRect:[window frame] fromView:nil]; |
| 240 maxY = NSHeight(windowFrame) + yOffset; | 214 maxY = NSHeight(windowFrame) + yOffset; |
| 241 maxY = [self layoutTabStripAtMaxY:maxY | 215 maxY = [self layoutTabStripAtMaxY:maxY |
| 242 width:width | 216 width:width |
| 243 fullscreen:[self isFullscreen]]; | 217 fullscreen:[self isFullscreen]]; |
| 244 } | 218 } |
| 245 | 219 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 totalHeight += NSHeight([[toolbarController_ view] frame]) + | 283 totalHeight += NSHeight([[toolbarController_ view] frame]) + |
| 310 kLocBarTopInset + kLocBarBottomInset; | 284 kLocBarTopInset + kLocBarBottomInset; |
| 311 } | 285 } |
| 312 | 286 |
| 313 if (![self placeBookmarkBarBelowInfoBar]) | 287 if (![self placeBookmarkBarBelowInfoBar]) |
| 314 totalHeight += NSHeight([[bookmarkBarController_ view] frame]); | 288 totalHeight += NSHeight([[bookmarkBarController_ view] frame]); |
| 315 | 289 |
| 316 return totalHeight; | 290 return totalHeight; |
| 317 } | 291 } |
| 318 | 292 |
| 319 - (void)layoutPresentationModeToggleAtOverlayMaxX:(CGFloat)maxX | |
| 320 overlayMaxY:(CGFloat)maxY { | |
| 321 // Lay out the presentation mode toggle button at the very top of the | |
| 322 // tab strip. | |
| 323 if ([self shouldShowPresentationModeToggle]) { | |
| 324 [self createAndInstallPresentationModeToggleButton]; | |
| 325 | |
| 326 NSPoint origin = | |
| 327 NSMakePoint(maxX - NSWidth([presentationModeToggleButton_ frame]), | |
| 328 maxY - NSHeight([presentationModeToggleButton_ frame])); | |
| 329 [presentationModeToggleButton_ setFrameOrigin:origin]; | |
| 330 } else { | |
| 331 [presentationModeToggleButton_ removeFromSuperview]; | |
| 332 presentationModeToggleButton_.reset(); | |
| 333 } | |
| 334 } | |
| 335 | |
| 336 - (CGFloat)layoutTabStripAtMaxY:(CGFloat)maxY | 293 - (CGFloat)layoutTabStripAtMaxY:(CGFloat)maxY |
| 337 width:(CGFloat)width | 294 width:(CGFloat)width |
| 338 fullscreen:(BOOL)fullscreen { | 295 fullscreen:(BOOL)fullscreen { |
| 339 // Nothing to do if no tab strip. | 296 // Nothing to do if no tab strip. |
| 340 if (![self hasTabStrip]) | 297 if (![self hasTabStrip]) |
| 341 return maxY; | 298 return maxY; |
| 342 | 299 |
| 343 NSView* tabStripView = [self tabStripView]; | 300 NSView* tabStripView = [self tabStripView]; |
| 344 CGFloat tabStripHeight = NSHeight([tabStripView frame]); | 301 CGFloat tabStripHeight = NSHeight([tabStripView frame]); |
| 345 maxY -= tabStripHeight; | 302 maxY -= tabStripHeight; |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 - (void)disableBarVisibilityUpdates { | 883 - (void)disableBarVisibilityUpdates { |
| 927 // Early escape if there's nothing to do. | 884 // Early escape if there's nothing to do. |
| 928 if (!barVisibilityUpdatesEnabled_) | 885 if (!barVisibilityUpdatesEnabled_) |
| 929 return; | 886 return; |
| 930 | 887 |
| 931 barVisibilityUpdatesEnabled_ = NO; | 888 barVisibilityUpdatesEnabled_ = NO; |
| 932 [presentationModeController_ cancelAnimationAndTimers]; | 889 [presentationModeController_ cancelAnimationAndTimers]; |
| 933 } | 890 } |
| 934 | 891 |
| 935 @end // @implementation BrowserWindowController(Private) | 892 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |