Chromium Code Reviews| 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 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #import "base/mac/scoped_nsobject.h" | 11 #import "base/mac/scoped_nsobject.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/prefs/scoped_user_pref_update.h" | 13 #include "base/prefs/scoped_user_pref_update.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/fullscreen.h" | 15 #include "chrome/browser/fullscreen.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 18 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 18 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_window_state.h" | 20 #include "chrome/browser/ui/browser_window_state.h" |
| 21 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 21 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
| 22 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 22 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| 23 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 23 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
| 24 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h" | 24 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h" |
| 25 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 25 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 26 #import "chrome/browser/ui/cocoa/fullscreen_mode_controller.h" | |
| 27 #import "chrome/browser/ui/cocoa/fullscreen_window.h" | 26 #import "chrome/browser/ui/cocoa/fullscreen_window.h" |
| 28 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 27 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 29 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | 28 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
| 30 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 29 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 31 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 30 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
| 32 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" | 31 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" |
| 33 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" | 32 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" |
| 34 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 33 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 35 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" | 34 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" |
| 36 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 35 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 browser:browser_.get() | 82 browser:browser_.get() |
| 84 delegate:self]); | 83 delegate:self]); |
| 85 } | 84 } |
| 86 | 85 |
| 87 - (void)saveWindowPositionIfNeeded { | 86 - (void)saveWindowPositionIfNeeded { |
| 88 if (!chrome::ShouldSaveWindowPlacement(browser_.get())) | 87 if (!chrome::ShouldSaveWindowPlacement(browser_.get())) |
| 89 return; | 88 return; |
| 90 | 89 |
| 91 // If we're in fullscreen mode, save the position of the regular window | 90 // If we're in fullscreen mode, save the position of the regular window |
| 92 // instead. | 91 // instead. |
| 93 NSWindow* window = [self isFullscreen] ? savedRegularWindow_ : [self window]; | 92 NSWindow* window = [self isInOrEnteringAnyFullscreenMode] |
| 93 ? savedRegularWindow_ | |
| 94 : [self window]; | |
| 94 | 95 |
| 95 // Window positions are stored relative to the origin of the primary monitor. | 96 // Window positions are stored relative to the origin of the primary monitor. |
| 96 NSRect monitorFrame = [[[NSScreen screens] objectAtIndex:0] frame]; | 97 NSRect monitorFrame = [[[NSScreen screens] objectAtIndex:0] frame]; |
| 97 NSScreen* windowScreen = [window screen]; | 98 NSScreen* windowScreen = [window screen]; |
| 98 | 99 |
| 99 // Start with the window's frame, which is in virtual coordinates. | 100 // Start with the window's frame, which is in virtual coordinates. |
| 100 // Do some y twiddling to flip the coordinate system. | 101 // Do some y twiddling to flip the coordinate system. |
| 101 gfx::Rect bounds(NSRectToCGRect([window frame])); | 102 gfx::Rect bounds(NSRectToCGRect([window frame])); |
| 102 bounds.set_y(monitorFrame.size.height - bounds.y() - bounds.height()); | 103 bounds.set_y(monitorFrame.size.height - bounds.y() - bounds.height()); |
| 103 | 104 |
| 104 // Browser::SaveWindowPlacement saves information for session restore. | 105 // Browser::SaveWindowPlacement saves information for session restore. |
| 105 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; | 106 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; |
| 106 if ([window isMiniaturized]) | 107 if ([window isMiniaturized]) |
| 107 show_state = ui::SHOW_STATE_MINIMIZED; | 108 show_state = ui::SHOW_STATE_MINIMIZED; |
| 108 else if ([self isFullscreen]) | 109 else if ([self isInOrEnteringAnyFullscreenMode]) |
| 109 show_state = ui::SHOW_STATE_FULLSCREEN; | 110 show_state = ui::SHOW_STATE_FULLSCREEN; |
| 110 chrome::SaveWindowPlacement(browser_.get(), bounds, show_state); | 111 chrome::SaveWindowPlacement(browser_.get(), bounds, show_state); |
| 111 | 112 |
| 112 // |windowScreen| can be nil (for example, if the monitor arrangement was | 113 // |windowScreen| can be nil (for example, if the monitor arrangement was |
| 113 // changed while in fullscreen mode). If we see a nil screen, return without | 114 // changed while in fullscreen mode). If we see a nil screen, return without |
| 114 // saving. | 115 // saving. |
| 115 // TODO(rohitrao): We should just not save anything for fullscreen windows. | 116 // TODO(rohitrao): We should just not save anything for fullscreen windows. |
| 116 // http://crbug.com/36479. | 117 // http://crbug.com/36479. |
| 117 if (!windowScreen) | 118 if (!windowScreen) |
| 118 return; | 119 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 // subviews of the content view, so we mainly work in the content view's | 182 // subviews of the content view, so we mainly work in the content view's |
| 182 // coordinate system. Note, however, that the content view's coordinate system | 183 // coordinate system. Note, however, that the content view's coordinate system |
| 183 // and the window's base coordinate system should coincide. | 184 // and the window's base coordinate system should coincide. |
| 184 NSWindow* window = [self window]; | 185 NSWindow* window = [self window]; |
| 185 NSView* contentView = [window contentView]; | 186 NSView* contentView = [window contentView]; |
| 186 NSRect contentBounds = [contentView bounds]; | 187 NSRect contentBounds = [contentView bounds]; |
| 187 CGFloat minX = NSMinX(contentBounds); | 188 CGFloat minX = NSMinX(contentBounds); |
| 188 CGFloat minY = NSMinY(contentBounds); | 189 CGFloat minY = NSMinY(contentBounds); |
| 189 CGFloat width = NSWidth(contentBounds); | 190 CGFloat width = NSWidth(contentBounds); |
| 190 | 191 |
| 191 BOOL useSimplifiedFullscreen = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 192 switches::kEnableSimplifiedFullscreen); | |
| 193 | |
| 194 // Suppress title drawing if necessary. | 192 // Suppress title drawing if necessary. |
| 195 if ([window respondsToSelector:@selector(setShouldHideTitle:)]) | 193 if ([window respondsToSelector:@selector(setShouldHideTitle:)]) |
| 196 [(id)window setShouldHideTitle:![self hasTitleBar]]; | 194 [(id)window setShouldHideTitle:![self hasTitleBar]]; |
| 197 | 195 |
| 198 // Update z-order. The code below depends on this. | 196 // Update z-order. The code below depends on this. |
| 199 [self updateSubviewZOrder:[self inPresentationMode]]; | 197 [self updateSubviewZOrder:[self isInFullscreenWithOmniboxSliding]]; |
| 200 | 198 |
| 201 BOOL inPresentationMode = [self inPresentationMode]; | |
| 202 CGFloat floatingBarHeight = [self floatingBarHeight]; | 199 CGFloat floatingBarHeight = [self floatingBarHeight]; |
| 203 // In presentation mode, |yOffset| accounts for the sliding position of the | 200 CGFloat yOffset = 0; |
| 204 // floating bar and the extra offset needed to dodge the menu bar. | 201 if ([self isInFullscreenWithOmniboxSliding]) { |
| 205 CGFloat yOffset = inPresentationMode && !useSimplifiedFullscreen ? | 202 switch (fullscreenStyle_) { |
| 206 (std::floor((1 - floatingBarShownFraction_) * floatingBarHeight) - | 203 case fullscreen_mac::OMNIBOX_TABS_PRESENT: |
| 207 [presentationModeController_ floatingBarVerticalOffset]) : 0; | 204 // In system fullscreen mode, |yOffset| accounts for the extra offset |
| 205 // needed to dodge the menu bar. | |
| 206 yOffset = -std::floor( | |
| 207 (floatingBarShownFraction_) * | |
| 208 [presentationModeController_ floatingBarVerticalOffset]); | |
| 209 break; | |
| 210 case fullscreen_mac::OMNIBOX_PRESENT: { | |
| 211 // At rest: omnibox showing. yOffset should be tabstrip height | |
| 212 // When cursor is at top: everything shows. yOffset should be -menubar | |
| 213 // height. | |
| 214 CGFloat tabStripHeight = 0; | |
| 215 if ([self hasTabStrip]) | |
| 216 tabStripHeight = NSHeight([[self tabStripView] frame]); | |
| 217 yOffset = std::floor( | |
| 218 (1 - floatingBarShownFraction_) * tabStripHeight - | |
| 219 floatingBarShownFraction_ * | |
| 220 [presentationModeController_ floatingBarVerticalOffset]); | |
| 221 break; | |
| 222 } | |
| 223 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: | |
| 224 // In presentation mode, |yOffset| accounts for the sliding position of | |
| 225 // the floating bar and the extra offset needed to dodge the menu bar. | |
| 226 yOffset = | |
| 227 std::floor((1 - floatingBarShownFraction_) * floatingBarHeight) - | |
| 228 [presentationModeController_ floatingBarVerticalOffset]; | |
| 229 break; | |
| 230 } | |
| 231 } | |
| 232 | |
| 208 CGFloat maxY = NSMaxY(contentBounds) + yOffset; | 233 CGFloat maxY = NSMaxY(contentBounds) + yOffset; |
| 209 | 234 |
| 210 if ([self hasTabStrip]) { | 235 if ([self hasTabStrip]) { |
| 211 // If we need to lay out the top tab strip, replace |maxY| with a higher | 236 // If we need to lay out the top tab strip, replace |maxY| with a higher |
| 212 // value, and then lay out the tab strip. | 237 // value, and then lay out the tab strip. |
| 213 NSRect windowFrame = [contentView convertRect:[window frame] fromView:nil]; | 238 NSRect windowFrame = [contentView convertRect:[window frame] fromView:nil]; |
| 214 maxY = NSHeight(windowFrame) + yOffset; | 239 maxY = NSHeight(windowFrame) + yOffset; |
| 215 if (useSimplifiedFullscreen && [self isFullscreen]) { | |
| 216 CGFloat tabStripHeight = NSHeight([[self tabStripView] frame]); | |
| 217 CGFloat revealAmount = (1 - floatingBarShownFraction_) * tabStripHeight; | |
| 218 // In simplified fullscreen, only the toolbar is visible by default, and | |
| 219 // the tabstrip and menu bar come down (each separately) when the user | |
| 220 // mouses near the top of the window. Push the maxY of the toolbar up by | |
| 221 // the amount of the tabstrip that is revealed, while removing the amount | |
| 222 // of space needed by the menu bar. | |
| 223 maxY += std::floor( | |
| 224 revealAmount - [fullscreenModeController_ menuBarHeight]); | |
| 225 } | |
| 226 maxY = [self layoutTabStripAtMaxY:maxY | 240 maxY = [self layoutTabStripAtMaxY:maxY |
| 227 width:width | 241 width:width |
| 228 fullscreen:[self isFullscreen]]; | 242 fullscreen:[self isInOrEnteringAnyFullscreenMode]]; |
| 229 } | 243 } |
| 230 | 244 |
| 231 // Sanity-check |maxY|. | 245 // Sanity-check |maxY|. |
| 232 DCHECK_GE(maxY, minY); | 246 DCHECK_GE(maxY, minY); |
| 233 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset); | 247 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset); |
| 234 | 248 |
| 235 // Place the toolbar at the top of the reserved area. | 249 // Place the toolbar at the top of the reserved area. |
| 236 maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width]; | 250 maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width]; |
| 237 | 251 |
| 238 // If we're not displaying the bookmark bar below the info bar, then it goes | 252 // If we're not displaying the bookmark bar below the info bar, then it goes |
| 239 // immediately below the toolbar. | 253 // immediately below the toolbar. |
| 240 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; | 254 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; |
| 241 if (!placeBookmarkBarBelowInfoBar) | 255 if (!placeBookmarkBarBelowInfoBar) |
| 242 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; | 256 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; |
| 243 | 257 |
| 244 // The floating bar backing view doesn't actually add any height. | 258 // The floating bar backing view doesn't actually add any height. |
| 245 NSRect floatingBarBackingRect = | 259 NSRect floatingBarBackingRect = |
| 246 NSMakeRect(minX, maxY, width, floatingBarHeight); | 260 NSMakeRect(minX, maxY, width, floatingBarHeight); |
| 247 [self layoutFloatingBarBackingView:floatingBarBackingRect | 261 [self layoutFloatingBarBackingView:floatingBarBackingRect |
| 248 presentationMode:inPresentationMode]; | 262 presentationMode:[self isInFullscreenWithOmniboxSliding]]; |
| 249 | 263 |
| 250 // Place the find bar immediately below the toolbar/attached bookmark bar. In | 264 // Place the find bar immediately below the toolbar/attached bookmark bar. In |
| 251 // presentation mode, it hangs off the top of the screen when the bar is | 265 // presentation mode, it hangs off the top of the screen when the bar is |
| 252 // hidden. | 266 // hidden. |
| 253 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width]; | 267 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width]; |
| 254 [fullscreenExitBubbleController_ positionInWindowAtTop:maxY width:width]; | 268 [fullscreenExitBubbleController_ positionInWindowAtTop:maxY width:width]; |
| 255 | 269 |
| 256 // If in presentation mode, reset |maxY| to top of screen, so that the | 270 if ([self isInFullscreenWithOmniboxSliding]) { |
| 257 // floating bar slides over the things which appear to be in the content area. | 271 switch (fullscreenStyle_) { |
| 258 if (inPresentationMode || | 272 case fullscreen_mac::OMNIBOX_TABS_PRESENT: |
| 259 (useSimplifiedFullscreen && !fullscreenUrl_.is_empty())) { | 273 case fullscreen_mac::OMNIBOX_PRESENT: |
| 260 maxY = NSMaxY(contentBounds); | 274 // Do nothing in system fullscreen and simplified fullscreen. All |
| 275 // content slides. | |
| 276 break; | |
| 277 case fullscreen_mac::OMNIBOX_TABS_HIDDEN: | |
| 278 // If in presentation mode, reset |maxY| to top of screen, so that the | |
| 279 // floating bar slides over the things which appear to be in the content | |
| 280 // area. | |
| 281 maxY = NSMaxY(contentBounds); | |
| 282 break; | |
| 283 } | |
| 261 } | 284 } |
| 262 | 285 |
| 263 // Also place the info bar container immediate below the toolbar, except in | 286 // Also place the info bar container immediate below the toolbar, except in |
| 264 // presentation mode in which case it's at the top of the visual content area. | 287 // presentation mode in which case it's at the top of the visual content area. |
| 265 maxY = [self layoutInfoBarAtMinX:minX maxY:maxY width:width]; | 288 maxY = [self layoutInfoBarAtMinX:minX maxY:maxY width:width]; |
| 266 | 289 |
| 267 // If the bookmark bar is detached, place it next in the visual content area. | 290 // If the bookmark bar is detached, place it next in the visual content area. |
| 268 if (placeBookmarkBarBelowInfoBar) | 291 if (placeBookmarkBarBelowInfoBar) |
| 269 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; | 292 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; |
| 270 | 293 |
| 271 // Place the download shelf, if any, at the bottom of the view. | 294 // Place the download shelf, if any, at the bottom of the view. |
| 272 minY = [self layoutDownloadShelfAtMinX:minX minY:minY width:width]; | 295 minY = [self layoutDownloadShelfAtMinX:minX minY:minY width:width]; |
| 273 | 296 |
| 274 // Finally, the content area takes up all of the remaining space. | 297 // Finally, the content area takes up all of the remaining space. |
| 275 NSRect contentAreaRect = NSMakeRect(minX, minY, width, maxY - minY); | 298 NSRect contentAreaRect = NSMakeRect(minX, minY, width, maxY - minY); |
| 276 [self layoutTabContentArea:contentAreaRect]; | 299 [self layoutTabContentArea:contentAreaRect]; |
| 277 | 300 |
| 278 // Normally, we don't need to tell the toolbar whether or not to show the | 301 // Normally, we don't need to tell the toolbar whether or not to show the |
| 279 // divider, but things break down during animation. | 302 // divider, but things break down during animation. |
| 280 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]]; | 303 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]]; |
| 281 } | 304 } |
| 282 | 305 |
| 283 - (CGFloat)floatingBarHeight { | 306 - (CGFloat)floatingBarHeight { |
| 284 if (![self inPresentationMode]) | 307 if (![self isInFullscreenWithOmniboxSliding]) |
| 285 return 0; | 308 return 0; |
| 286 | 309 |
| 287 CGFloat totalHeight = [presentationModeController_ floatingBarVerticalOffset]; | 310 CGFloat totalHeight = 0; |
| 311 if (presentationModeController_) | |
| 312 totalHeight = [presentationModeController_ floatingBarVerticalOffset]; | |
| 288 | 313 |
| 289 if ([self hasTabStrip]) | 314 if ([self hasTabStrip]) |
| 290 totalHeight += NSHeight([[self tabStripView] frame]); | 315 totalHeight += NSHeight([[self tabStripView] frame]); |
| 291 | 316 |
| 292 if ([self hasToolbar]) { | 317 if ([self hasToolbar]) { |
| 293 totalHeight += NSHeight([[toolbarController_ view] frame]); | 318 totalHeight += NSHeight([[toolbarController_ view] frame]); |
| 294 } else if ([self hasLocationBar]) { | 319 } else if ([self hasLocationBar]) { |
| 295 totalHeight += NSHeight([[toolbarController_ view] frame]) + | 320 totalHeight += NSHeight([[toolbarController_ view] frame]) + |
| 296 kLocBarTopInset + kLocBarBottomInset; | 321 kLocBarTopInset + kLocBarBottomInset; |
| 297 } | 322 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 321 // Lay out the icognito/avatar badge because calculating the indentation on | 346 // Lay out the icognito/avatar badge because calculating the indentation on |
| 322 // the right depends on it. | 347 // the right depends on it. |
| 323 NSView* avatarButton = [avatarButtonController_ view]; | 348 NSView* avatarButton = [avatarButtonController_ view]; |
| 324 if ([self shouldShowAvatar]) { | 349 if ([self shouldShowAvatar]) { |
| 325 CGFloat badgeXOffset = -kAvatarRightOffset; | 350 CGFloat badgeXOffset = -kAvatarRightOffset; |
| 326 CGFloat badgeYOffset = 0; | 351 CGFloat badgeYOffset = 0; |
| 327 CGFloat buttonHeight = NSHeight([avatarButton frame]); | 352 CGFloat buttonHeight = NSHeight([avatarButton frame]); |
| 328 | 353 |
| 329 if ([self shouldUseNewAvatarButton]) { | 354 if ([self shouldUseNewAvatarButton]) { |
| 330 // The fullscreen icon is displayed to the right of the avatar button. | 355 // The fullscreen icon is displayed to the right of the avatar button. |
| 331 if (![self isFullscreen]) | 356 if (![self isInOrEnteringAnyFullscreenMode]) |
| 332 badgeXOffset -= kFullscreenIconWidth; | 357 badgeXOffset -= kFullscreenIconWidth; |
| 333 // Center the button vertically on the tabstrip. | 358 // Center the button vertically on the tabstrip. |
| 334 badgeYOffset = (tabStripHeight - buttonHeight) / 2; | 359 badgeYOffset = (tabStripHeight - buttonHeight) / 2; |
| 335 } else { | 360 } else { |
| 336 // Actually place the badge *above* |maxY|, by +2 to miss the divider. | 361 // Actually place the badge *above* |maxY|, by +2 to miss the divider. |
| 337 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth]; | 362 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth]; |
| 338 } | 363 } |
| 339 | 364 |
| 340 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), | 365 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), |
| 341 std::min(buttonHeight, tabStripHeight))]; | 366 std::min(buttonHeight, tabStripHeight))]; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 357 static_cast<FramedBrowserWindow*>([self window]); | 382 static_cast<FramedBrowserWindow*>([self window]); |
| 358 rightIndent += -[window fullScreenButtonOriginAdjustment].x; | 383 rightIndent += -[window fullScreenButtonOriginAdjustment].x; |
| 359 | 384 |
| 360 if ([self shouldUseNewAvatarButton]) { | 385 if ([self shouldUseNewAvatarButton]) { |
| 361 // The new avatar is wider than the default indentation, so we need to | 386 // The new avatar is wider than the default indentation, so we need to |
| 362 // account for its width. | 387 // account for its width. |
| 363 rightIndent += NSWidth([avatarButton frame]) + kAvatarTabStripShrink; | 388 rightIndent += NSWidth([avatarButton frame]) + kAvatarTabStripShrink; |
| 364 | 389 |
| 365 // When the fullscreen icon is not displayed, return its width to the | 390 // When the fullscreen icon is not displayed, return its width to the |
| 366 // tabstrip. | 391 // tabstrip. |
| 367 if ([self isFullscreen]) | 392 if ([self isInOrEnteringAnyFullscreenMode]) |
| 368 rightIndent -= kFullscreenIconWidth; | 393 rightIndent -= kFullscreenIconWidth; |
| 369 } | 394 } |
| 370 } else if ([self shouldShowAvatar]) { | 395 } else if ([self shouldShowAvatar]) { |
| 371 rightIndent += kAvatarTabStripShrink + | 396 rightIndent += kAvatarTabStripShrink + |
| 372 NSWidth([avatarButton frame]) + kAvatarRightOffset; | 397 NSWidth([avatarButton frame]) + kAvatarRightOffset; |
| 373 } | 398 } |
| 374 [tabStripController_ setRightIndentForControls:rightIndent]; | 399 [tabStripController_ setRightIndentForControls:rightIndent]; |
| 375 | 400 |
| 376 // Go ahead and layout the tabs. | 401 // Go ahead and layout the tabs. |
| 377 [tabStripController_ layoutTabsWithoutAnimation]; | 402 [tabStripController_ layoutTabsWithoutAnimation]; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 if (contentShifted) { | 533 if (contentShifted) { |
| 509 if (WebContents* contents = | 534 if (WebContents* contents = |
| 510 browser_->tab_strip_model()->GetActiveWebContents()) { | 535 browser_->tab_strip_model()->GetActiveWebContents()) { |
| 511 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) | 536 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) |
| 512 rwhv->WindowFrameChanged(); | 537 rwhv->WindowFrameChanged(); |
| 513 } | 538 } |
| 514 } | 539 } |
| 515 } | 540 } |
| 516 | 541 |
| 517 - (void)updateRoundedBottomCorners { | 542 - (void)updateRoundedBottomCorners { |
| 518 [[self tabContentArea] setRoundedBottomCorners:![self isFullscreen]]; | 543 [[self tabContentArea] |
| 544 setRoundedBottomCorners:![self isInOrEnteringAnyFullscreenMode]]; | |
| 519 } | 545 } |
| 520 | 546 |
| 521 - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression { | 547 - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression { |
| 522 CGFloat newHeight = | 548 CGFloat newHeight = |
| 523 [toolbarController_ desiredHeightForCompression:compression]; | 549 [toolbarController_ desiredHeightForCompression:compression]; |
| 524 NSRect toolbarFrame = [[toolbarController_ view] frame]; | 550 NSRect toolbarFrame = [[toolbarController_ view] frame]; |
| 525 CGFloat deltaH = newHeight - toolbarFrame.size.height; | 551 CGFloat deltaH = newHeight - toolbarFrame.size.height; |
| 526 | 552 |
| 527 if (deltaH == 0) | 553 if (deltaH == 0) |
| 528 return; | 554 return; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 | 662 |
| 637 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 663 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 638 [center removeObserver:self | 664 [center removeObserver:self |
| 639 name:NSWindowWillCloseNotification | 665 name:NSWindowWillCloseNotification |
| 640 object:[notification object]]; | 666 object:[notification object]]; |
| 641 [self releaseBarVisibilityForOwner:[notification object] | 667 [self releaseBarVisibilityForOwner:[notification object] |
| 642 withAnimation:YES | 668 withAnimation:YES |
| 643 delay:YES]; | 669 delay:YES]; |
| 644 } | 670 } |
| 645 | 671 |
| 646 - (void)setPresentationModeInternal:(BOOL)presentationMode | 672 - (BOOL)commonAppKitFullscreenSetup { |
|
Robert Sesek
2014/08/27 22:04:30
nit: method indention is off
erikchen
2014/08/28 00:50:28
You're right. Wonder why clang-format didn't catch
| |
| 647 forceDropdown:(BOOL)forceDropdown { | |
| 648 if (presentationMode == [self inPresentationMode]) | |
| 649 return; | |
| 650 | |
| 651 if (presentationMode) { | |
| 652 BOOL fullscreen_for_tab = | 673 BOOL fullscreen_for_tab = |
| 653 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); | 674 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); |
| 654 BOOL kiosk_mode = | 675 BOOL kiosk_mode = |
| 655 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); | 676 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); |
| 656 BOOL showDropdown = !fullscreen_for_tab && | 677 BOOL showDropdown = |
| 657 !kiosk_mode && | 678 !fullscreen_for_tab && !kiosk_mode && ([self floatingBarHasFocus]); |
| 658 (forceDropdown || [self floatingBarHasFocus]); | |
| 659 presentationModeController_.reset( | |
| 660 [[PresentationModeController alloc] initWithBrowserController:self]); | |
| 661 | |
| 662 if (permissionBubbleCocoa_ && permissionBubbleCocoa_->IsVisible()) { | 679 if (permissionBubbleCocoa_ && permissionBubbleCocoa_->IsVisible()) { |
| 663 DCHECK(permissionBubbleCocoa_->window()); | 680 DCHECK(permissionBubbleCocoa_->window()); |
| 664 // A visible permission bubble will force the dropdown to remain visible. | 681 // A visible permission bubble will force the dropdown to remain visible. |
| 665 [self lockBarVisibilityForOwner:permissionBubbleCocoa_->window() | 682 [self lockBarVisibilityForOwner:permissionBubbleCocoa_->window() |
| 666 withAnimation:NO | 683 withAnimation:NO |
| 667 delay:NO]; | 684 delay:NO]; |
| 668 showDropdown = YES; | 685 showDropdown = YES; |
| 669 // Register to be notified when the permission bubble is closed, to | 686 // Register to be notified when the permission bubble is closed, to |
| 670 // allow fullscreen to hide the dropdown. | 687 // allow fullscreen to hide the dropdown. |
| 671 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 688 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 672 [center addObserver:self | 689 [center addObserver:self |
| 673 selector:@selector(permissionBubbleWindowWillClose:) | 690 selector:@selector(permissionBubbleWindowWillClose:) |
| 674 name:NSWindowWillCloseNotification | 691 name:NSWindowWillCloseNotification |
| 675 object:permissionBubbleCocoa_->window()]; | 692 object:permissionBubbleCocoa_->window()]; |
| 676 } | 693 } |
| 677 if (showDropdown) { | 694 if (showDropdown) { |
| 678 // Turn on layered mode for the window's root view for the entry | 695 // Turn on layered mode for the window's root view for the entry |
| 679 // animation. Without this, the OS fullscreen animation for entering | 696 // animation. Without this, the OS fullscreen animation for entering |
| 680 // fullscreen mode does not correctly draw the tab strip. | 697 // fullscreen mode does not correctly draw the tab strip. |
| 681 // It will be turned off (set back to NO) when the animation finishes, | 698 // It will be turned off (set back to NO) when the animation finishes, |
| 682 // in -windowDidEnterFullScreen:. | 699 // in -windowDidEnterFullScreen:. |
| 683 // Leaving wantsLayer on for the duration of presentation mode causes | 700 // Leaving wantsLayer on for the duration of presentation mode causes |
| 684 // performance issues when the dropdown is animated in/out. It also does | 701 // performance issues when the dropdown is animated in/out. It also does |
| 685 // not seem to be required for the exit animation. | 702 // not seem to be required for the exit animation. |
| 686 windowViewWantsLayer_ = [[[self window] cr_windowView] wantsLayer]; | 703 windowViewWantsLayer_ = [[[self window] cr_windowView] wantsLayer]; |
| 687 [[[self window] cr_windowView] setWantsLayer:YES]; | 704 [[[self window] cr_windowView] setWantsLayer:YES]; |
| 688 } | 705 } |
| 706 return showDropdown; | |
| 707 } | |
| 708 | |
| 709 - (void)adjustUIForExitingFullscreenAndStopOmniboxSliding { | |
| 710 [presentationModeController_ exitPresentationMode]; | |
| 711 presentationModeController_.reset(); | |
| 712 | |
| 713 // Force the bookmark bar z-order to update. | |
| 714 [[bookmarkBarController_ view] removeFromSuperview]; | |
| 715 [self layoutSubviews]; | |
| 716 } | |
| 717 | |
| 718 - (void)adjustUIForSlidingFullscreenStyle:(fullscreen_mac::SlidingStyle)style { | |
| 719 fullscreenStyle_ = style; | |
| 720 | |
| 721 if (!presentationModeController_) { | |
| 722 // Kill the "fullscreen" controller if needed. | |
| 723 // TODO: consider not doing this? | |
| 724 [presentationModeController_ exitPresentationMode]; | |
| 725 presentationModeController_.reset( | |
| 726 [[PresentationModeController alloc] initWithBrowserController:self]); | |
| 727 | |
| 728 BOOL showDropdown = [self commonAppKitFullscreenSetup]; | |
| 729 | |
| 689 NSView* contentView = [[self window] contentView]; | 730 NSView* contentView = [[self window] contentView]; |
| 690 [presentationModeController_ enterPresentationModeForContentView:contentView | 731 [presentationModeController_ |
| 691 showDropdown:showDropdown]; | 732 enterPresentationModeForContentView:contentView |
| 692 } else { | 733 showDropdown:showDropdown]; |
| 693 [presentationModeController_ exitPresentationMode]; | |
| 694 presentationModeController_.reset(); | |
| 695 } | 734 } |
| 696 | 735 |
| 697 [self adjustUIForPresentationMode:presentationMode]; | 736 if (!floatingBarBackingView_.get() && |
| 737 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) { | |
| 738 floatingBarBackingView_.reset( | |
| 739 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]); | |
| 740 [floatingBarBackingView_ | |
| 741 setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; | |
| 742 } | |
| 743 | |
| 744 // Force the bookmark bar z-order to update. | |
| 745 [[bookmarkBarController_ view] removeFromSuperview]; | |
| 698 [self layoutSubviews]; | 746 [self layoutSubviews]; |
| 699 } | 747 } |
| 700 | 748 |
| 701 - (void)enterImmersiveFullscreen { | 749 - (void)enterImmersiveFullscreen { |
| 702 // |-isFullscreen:| will return YES from here onwards. | 750 // |-isInOrEnteringAnyFullscreenMode| will return YES from here onwards. |
| 703 enteringFullscreen_ = YES; // Set to NO by |-windowDidEnterFullScreen:|. | 751 enteringFullscreen_ = YES; // Set to NO by |-windowDidEnterFullScreen:|. |
| 704 | 752 |
| 705 // Fade to black. | 753 // Fade to black. |
| 706 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; | 754 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; |
| 707 Boolean didFadeOut = NO; | 755 Boolean didFadeOut = NO; |
| 708 CGDisplayFadeReservationToken token; | 756 CGDisplayFadeReservationToken token; |
| 709 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) | 757 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) |
| 710 == kCGErrorSuccess) { | 758 == kCGErrorSuccess) { |
| 711 didFadeOut = YES; | 759 didFadeOut = YES; |
| 712 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, | 760 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, |
| 713 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); | 761 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); |
| 714 } | 762 } |
| 715 | 763 |
| 716 // Create the fullscreen window. | 764 // Create the fullscreen window. |
| 717 fullscreenWindow_.reset([[self createFullscreenWindow] retain]); | 765 fullscreenWindow_.reset([[self createFullscreenWindow] retain]); |
| 718 savedRegularWindow_ = [[self window] retain]; | 766 savedRegularWindow_ = [[self window] retain]; |
| 719 savedRegularWindowFrame_ = [savedRegularWindow_ frame]; | 767 savedRegularWindowFrame_ = [savedRegularWindow_ frame]; |
| 720 | 768 |
| 721 [self moveViewsForImmersiveFullscreen:YES | 769 [self moveViewsForImmersiveFullscreen:YES |
| 722 regularWindow:[self window] | 770 regularWindow:[self window] |
| 723 fullscreenWindow:fullscreenWindow_.get()]; | 771 fullscreenWindow:fullscreenWindow_.get()]; |
| 724 | 772 |
| 725 // When simplified fullscreen is enabled, do not enter presentation mode. | 773 // When simplified fullscreen is enabled, do not enter presentation mode. |
| 726 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 774 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 775 fullscreen_mac::SlidingStyle style; | |
| 727 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) { | 776 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) { |
| 728 // TODO(rohitrao): Add code to manage the menubar here. | 777 style = fullscreen_mac::OMNIBOX_PRESENT; |
| 729 } else { | 778 } else { |
| 730 [self adjustUIForPresentationMode:YES]; | 779 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN; |
| 731 [self setPresentationModeInternal:YES forceDropdown:NO]; | |
| 732 } | 780 } |
| 781 [self adjustUIForSlidingFullscreenStyle:style]; | |
| 733 | 782 |
| 734 // AppKit is helpful and prevents NSWindows from having the same height as | 783 // AppKit is helpful and prevents NSWindows from having the same height as |
| 735 // the screen while the menu bar is showing. This only applies to windows on | 784 // the screen while the menu bar is showing. This only applies to windows on |
| 736 // a secondary screen, in a separate space. Calling [NSWindow | 785 // a secondary screen, in a separate space. Calling [NSWindow |
| 737 // setFrame:display:] with the screen's height will always reduce the | 786 // setFrame:display:] with the screen's height will always reduce the |
| 738 // height by the height of the MenuBar. Calling the method with any other | 787 // height by the height of the MenuBar. Calling the method with any other |
| 739 // height works fine. The relevant method in the 10.10 AppKit SDK is called: | 788 // height works fine. The relevant method in the 10.10 AppKit SDK is called: |
| 740 // _canAdjustSizeForScreensHaveSeparateSpacesIfFillingSecondaryScreen | 789 // _canAdjustSizeForScreensHaveSeparateSpacesIfFillingSecondaryScreen |
| 741 // | 790 // |
| 742 // TODO(erikchen): Refactor the logic to allow the window to be shown after | 791 // TODO(erikchen): Refactor the logic to allow the window to be shown after |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 [self windowDidExitFullScreen:nil]; | 841 [self windowDidExitFullScreen:nil]; |
| 793 | 842 |
| 794 // Fade back in. | 843 // Fade back in. |
| 795 if (didFadeOut) { | 844 if (didFadeOut) { |
| 796 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, | 845 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, |
| 797 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); | 846 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); |
| 798 CGReleaseDisplayFadeReservation(token); | 847 CGReleaseDisplayFadeReservation(token); |
| 799 } | 848 } |
| 800 } | 849 } |
| 801 | 850 |
| 802 // TODO(rohitrao): This function has shrunk into uselessness, and | |
| 803 // |-setFullscreen:| has grown rather large. Find a good way to break up | |
| 804 // |-setFullscreen:| into smaller pieces. http://crbug.com/36449 | |
| 805 - (void)adjustUIForPresentationMode:(BOOL)fullscreen { | |
| 806 // Create the floating bar backing view if necessary. | |
| 807 if (fullscreen && !floatingBarBackingView_.get() && | |
| 808 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) { | |
| 809 floatingBarBackingView_.reset( | |
| 810 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]); | |
| 811 [floatingBarBackingView_ setAutoresizingMask:(NSViewWidthSizable | | |
| 812 NSViewMinYMargin)]; | |
| 813 } | |
| 814 | |
| 815 // Force the bookmark bar z-order to update. | |
| 816 [[bookmarkBarController_ view] removeFromSuperview]; | |
| 817 [self updateSubviewZOrder:fullscreen]; | |
| 818 } | |
| 819 | |
| 820 - (void)showFullscreenExitBubbleIfNecessary { | 851 - (void)showFullscreenExitBubbleIfNecessary { |
| 821 // This method is called in response to | 852 // This method is called in response to |
| 822 // |-updateFullscreenExitBubbleURL:bubbleType:|. If we're in the middle of the | 853 // |-updateFullscreenExitBubbleURL:bubbleType:|. If we're in the middle of the |
| 823 // transition into fullscreen (i.e., using the System Fullscreen API), do not | 854 // transition into fullscreen (i.e., using the System Fullscreen API), do not |
| 824 // show the bubble because it will cause visual jank | 855 // show the bubble because it will cause visual jank |
| 825 // (http://crbug.com/130649). This will be called again as part of | 856 // (http://crbug.com/130649). This will be called again as part of |
| 826 // |-windowDidEnterFullScreen:|, so arrange to do that work then instead. | 857 // |-windowDidEnterFullScreen:|, so arrange to do that work then instead. |
| 827 if (enteringFullscreen_) | 858 if (enteringFullscreen_) |
| 828 return; | 859 return; |
| 829 | 860 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 | 914 |
| 884 - (void)windowWillEnterFullScreen:(NSNotification*)notification { | 915 - (void)windowWillEnterFullScreen:(NSNotification*)notification { |
| 885 if (notification) // For System Fullscreen when non-nil. | 916 if (notification) // For System Fullscreen when non-nil. |
| 886 [self registerForContentViewResizeNotifications]; | 917 [self registerForContentViewResizeNotifications]; |
| 887 | 918 |
| 888 NSWindow* window = [self window]; | 919 NSWindow* window = [self window]; |
| 889 savedRegularWindowFrame_ = [window frame]; | 920 savedRegularWindowFrame_ = [window frame]; |
| 890 BOOL mode = enteringPresentationMode_ || | 921 BOOL mode = enteringPresentationMode_ || |
| 891 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); | 922 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); |
| 892 enteringFullscreen_ = YES; | 923 enteringFullscreen_ = YES; |
| 893 [self setPresentationModeInternal:mode forceDropdown:NO]; | 924 |
| 925 fullscreen_mac::SlidingStyle style; | |
| 926 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 927 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) | |
| 928 style = fullscreen_mac::OMNIBOX_PRESENT; | |
| 929 else if (mode) | |
| 930 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN; | |
| 931 else | |
| 932 style = fullscreen_mac::OMNIBOX_TABS_PRESENT; | |
| 933 | |
| 934 [self adjustUIForSlidingFullscreenStyle:style]; | |
| 894 } | 935 } |
| 895 | 936 |
| 896 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 937 - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
| 897 // In Yosemite, some combination of the titlebar and toolbar always show in | 938 // In Yosemite, some combination of the titlebar and toolbar always show in |
| 898 // full-screen mode. We do not want either to show. Search for the window that | 939 // full-screen mode. We do not want either to show. Search for the window that |
| 899 // contains the views, and hide it. There is no need to ever unhide the view. | 940 // contains the views, and hide it. There is no need to ever unhide the view. |
| 900 // http://crbug.com/380235 | 941 // http://crbug.com/380235 |
| 901 if (base::mac::IsOSYosemiteOrLater()) { | 942 if (base::mac::IsOSYosemiteOrLater()) { |
| 902 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { | 943 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { |
| 903 if ([window | 944 if ([window |
| 904 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { | 945 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { |
| 905 [window.contentView setHidden:YES]; | 946 [window.contentView setHidden:YES]; |
| 906 } | 947 } |
| 907 } | 948 } |
| 908 } | 949 } |
| 909 | 950 |
| 910 if (notification) // For System Fullscreen when non-nil. | 951 if (notification) // For System Fullscreen when non-nil. |
| 911 [self deregisterForContentViewResizeNotifications]; | 952 [self deregisterForContentViewResizeNotifications]; |
| 912 enteringFullscreen_ = NO; | 953 enteringFullscreen_ = NO; |
| 913 enteringPresentationMode_ = NO; | 954 enteringPresentationMode_ = NO; |
| 914 | 955 |
| 915 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 916 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen) && | |
| 917 fullscreenUrl_.is_empty()) { | |
| 918 fullscreenModeController_.reset([[FullscreenModeController alloc] | |
| 919 initWithBrowserWindowController:self]); | |
| 920 } | |
| 921 | |
| 922 [self showFullscreenExitBubbleIfNecessary]; | 956 [self showFullscreenExitBubbleIfNecessary]; |
| 923 browser_->WindowFullscreenStateChanged(); | 957 browser_->WindowFullscreenStateChanged(); |
| 924 [[[self window] cr_windowView] setWantsLayer:windowViewWantsLayer_]; | 958 [[[self window] cr_windowView] setWantsLayer:windowViewWantsLayer_]; |
| 925 [self updateRoundedBottomCorners]; | 959 [self updateRoundedBottomCorners]; |
| 926 } | 960 } |
| 927 | 961 |
| 928 - (void)windowWillExitFullScreen:(NSNotification*)notification { | 962 - (void)windowWillExitFullScreen:(NSNotification*)notification { |
| 929 if (notification) // For System Fullscreen when non-nil. | 963 if (notification) // For System Fullscreen when non-nil. |
| 930 [self registerForContentViewResizeNotifications]; | 964 [self registerForContentViewResizeNotifications]; |
| 931 fullscreenModeController_.reset(); | |
| 932 [self destroyFullscreenExitBubbleIfNecessary]; | 965 [self destroyFullscreenExitBubbleIfNecessary]; |
| 933 [self setPresentationModeInternal:NO forceDropdown:NO]; | 966 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; |
| 934 } | 967 } |
| 935 | 968 |
| 936 - (void)windowDidExitFullScreen:(NSNotification*)notification { | 969 - (void)windowDidExitFullScreen:(NSNotification*)notification { |
| 937 if (notification) // For System Fullscreen when non-nil. | 970 if (notification) // For System Fullscreen when non-nil. |
| 938 [self deregisterForContentViewResizeNotifications]; | 971 [self deregisterForContentViewResizeNotifications]; |
| 939 browser_->WindowFullscreenStateChanged(); | 972 browser_->WindowFullscreenStateChanged(); |
| 940 [self updateRoundedBottomCorners]; | 973 [self updateRoundedBottomCorners]; |
| 941 } | 974 } |
| 942 | 975 |
| 943 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { | 976 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { |
| 944 [self deregisterForContentViewResizeNotifications]; | 977 [self deregisterForContentViewResizeNotifications]; |
| 945 enteringFullscreen_ = NO; | 978 enteringFullscreen_ = NO; |
| 946 [self setPresentationModeInternal:NO forceDropdown:NO]; | 979 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; |
| 947 | |
| 948 // Force a relayout to try and get the window back into a reasonable state. | |
| 949 [self layoutSubviews]; | |
| 950 } | 980 } |
| 951 | 981 |
| 952 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { | 982 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { |
| 953 [self deregisterForContentViewResizeNotifications]; | 983 [self deregisterForContentViewResizeNotifications]; |
| 954 | 984 |
| 955 // Force a relayout to try and get the window back into a reasonable state. | 985 // Force a relayout to try and get the window back into a reasonable state. |
| 956 [self layoutSubviews]; | 986 [self layoutSubviews]; |
| 957 } | 987 } |
| 958 | 988 |
| 959 - (void)enableBarVisibilityUpdates { | 989 - (void)enableBarVisibilityUpdates { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 982 if (!barVisibilityUpdatesEnabled_ || [barVisibilityLocks_ count]) | 1012 if (!barVisibilityUpdatesEnabled_ || [barVisibilityLocks_ count]) |
| 983 return; | 1013 return; |
| 984 [presentationModeController_ ensureOverlayHiddenWithAnimation:animation | 1014 [presentationModeController_ ensureOverlayHiddenWithAnimation:animation |
| 985 delay:delay]; | 1015 delay:delay]; |
| 986 } | 1016 } |
| 987 | 1017 |
| 988 - (CGFloat)toolbarDividerOpacity { | 1018 - (CGFloat)toolbarDividerOpacity { |
| 989 return [bookmarkBarController_ toolbarDividerOpacity]; | 1019 return [bookmarkBarController_ toolbarDividerOpacity]; |
| 990 } | 1020 } |
| 991 | 1021 |
| 992 - (void)updateSubviewZOrder:(BOOL)inPresentationMode { | 1022 // TODO(erikchen): The implementation of this method is quite fragile. The |
| 1023 // method cr_ensureSubview:... does not check that the subview is /directly/ | |
| 1024 // above/below the given view. e.g. I have 3 subviews: A, B, C, in that order. | |
| 1025 // The method cr_ensureSubviuw:A isPositioned:NSWindowBelow relativeTo:C will | |
| 1026 // have no effect, even though the desired result may have been: B, A, C. | |
| 1027 // Consider changing it? | |
| 1028 - (void)updateSubviewZOrder:(BOOL)inAnyFullscreen { | |
| 993 NSView* contentView = [[self window] contentView]; | 1029 NSView* contentView = [[self window] contentView]; |
| 994 NSView* toolbarView = [toolbarController_ view]; | 1030 NSView* toolbarView = [toolbarController_ view]; |
| 995 | 1031 |
| 996 if (inPresentationMode) { | 1032 if (inAnyFullscreen) { |
| 997 // Toolbar is above tab contents so that it can slide down from top of | 1033 // Toolbar is above tab contents so that it can slide down from top of |
| 998 // screen. | 1034 // screen. |
| 999 [contentView cr_ensureSubview:toolbarView | 1035 [contentView cr_ensureSubview:toolbarView |
| 1000 isPositioned:NSWindowAbove | 1036 isPositioned:NSWindowAbove |
| 1001 relativeTo:[self tabContentArea]]; | 1037 relativeTo:[self tabContentArea]]; |
| 1002 } else { | 1038 } else { |
| 1003 // Toolbar is below tab contents so that the info bar arrow can appear above | 1039 // Toolbar is below tab contents so that the info bar arrow can appear above |
| 1004 // it. | 1040 // it. |
| 1005 [contentView cr_ensureSubview:toolbarView | 1041 [contentView cr_ensureSubview:toolbarView |
| 1006 isPositioned:NSWindowBelow | 1042 isPositioned:NSWindowBelow |
| 1007 relativeTo:[self tabContentArea]]; | 1043 relativeTo:[self tabContentArea]]; |
| 1008 } | 1044 } |
| 1009 | 1045 |
| 1010 // The bookmark bar is always below the toolbar. | 1046 // The bookmark bar is always below the toolbar. |
| 1011 [contentView cr_ensureSubview:[bookmarkBarController_ view] | 1047 [contentView cr_ensureSubview:[bookmarkBarController_ view] |
| 1012 isPositioned:NSWindowBelow | 1048 isPositioned:NSWindowBelow |
| 1013 relativeTo:toolbarView]; | 1049 relativeTo:toolbarView]; |
| 1014 | 1050 |
| 1015 if (inPresentationMode) { | 1051 if (inAnyFullscreen) { |
| 1016 // In presentation mode the info bar is below all other views. | 1052 // In presentation mode the info bar is below all other views. |
| 1017 [contentView cr_ensureSubview:[infoBarContainerController_ view] | 1053 [contentView cr_ensureSubview:[infoBarContainerController_ view] |
| 1018 isPositioned:NSWindowBelow | 1054 isPositioned:NSWindowBelow |
| 1019 relativeTo:[self tabContentArea]]; | 1055 relativeTo:[self tabContentArea]]; |
| 1020 } else { | 1056 } else { |
| 1021 // Above the toolbar but still below tab contents. Similar to the bookmark | 1057 // Above the toolbar but still below tab contents. Similar to the bookmark |
| 1022 // bar, this allows Instant results to be above the info bar. | 1058 // bar, this allows Instant results to be above the info bar. |
| 1023 [contentView cr_ensureSubview:[infoBarContainerController_ view] | 1059 [contentView cr_ensureSubview:[infoBarContainerController_ view] |
| 1024 isPositioned:NSWindowAbove | 1060 isPositioned:NSWindowAbove |
| 1025 relativeTo:toolbarView]; | 1061 relativeTo:toolbarView]; |
| 1026 } | 1062 } |
| 1027 | 1063 |
| 1028 // The find bar is above everything. | 1064 // The find bar is above everything. |
| 1029 if (findBarCocoaController_) { | 1065 if (findBarCocoaController_) { |
| 1030 NSView* relativeView = nil; | 1066 NSView* relativeView = nil; |
| 1031 if (inPresentationMode) | 1067 if (inAnyFullscreen) |
| 1032 relativeView = toolbarView; | 1068 relativeView = toolbarView; |
| 1033 else | 1069 else |
| 1034 relativeView = [self tabContentArea]; | 1070 relativeView = [self tabContentArea]; |
| 1035 [contentView cr_ensureSubview:[findBarCocoaController_ view] | 1071 [contentView cr_ensureSubview:[findBarCocoaController_ view] |
| 1036 isPositioned:NSWindowAbove | 1072 isPositioned:NSWindowAbove |
| 1037 relativeTo:relativeView]; | 1073 relativeTo:relativeView]; |
| 1038 } | 1074 } |
| 1039 | 1075 |
| 1040 if (floatingBarBackingView_) { | 1076 if (floatingBarBackingView_) { |
| 1041 if ([floatingBarBackingView_ cr_isBelowView:[self tabContentArea]]) | 1077 if ([floatingBarBackingView_ cr_isBelowView:[self tabContentArea]]) |
| 1042 [floatingBarBackingView_ removeFromSuperview]; | 1078 [floatingBarBackingView_ removeFromSuperview]; |
| 1043 if ([self placeBookmarkBarBelowInfoBar]) { | 1079 if ([self placeBookmarkBarBelowInfoBar]) { |
| 1044 [contentView cr_ensureSubview:floatingBarBackingView_ | 1080 [contentView cr_ensureSubview:floatingBarBackingView_ |
| 1045 isPositioned:NSWindowAbove | 1081 isPositioned:NSWindowAbove |
| 1046 relativeTo:[bookmarkBarController_ view]]; | 1082 relativeTo:[bookmarkBarController_ view]]; |
| 1047 } else { | 1083 } else { |
| 1048 [contentView cr_ensureSubview:floatingBarBackingView_ | 1084 [contentView cr_ensureSubview:floatingBarBackingView_ |
| 1049 isPositioned:NSWindowBelow | 1085 isPositioned:NSWindowBelow |
| 1050 relativeTo:[bookmarkBarController_ view]]; | 1086 relativeTo:[bookmarkBarController_ view]]; |
| 1051 } | 1087 } |
| 1088 | |
| 1089 // TODO(erikchen): This constraint is necessary. See comment at the | |
| 1090 // beginning of the method. | |
| 1091 [contentView cr_ensureSubview:floatingBarBackingView_ | |
| 1092 isPositioned:NSWindowAbove | |
| 1093 relativeTo:[self tabContentArea]]; | |
| 1094 } | |
| 1095 | |
| 1096 // TODO(erikchen): Remove and then add the tabStripView to the root NSView. | |
| 1097 // This fixes a layer ordering problem that occurs between the contentView | |
| 1098 // and the tabStripView. This is a hack required because NSThemeFrame is not | |
| 1099 // layer backed, and because we add subviews directly to the NSThemeFrame. | |
| 1100 // http://crbug.com/407921 | |
| 1101 if (enteringFullscreen_) { | |
| 1102 // Disable implicit animations. | |
| 1103 [CATransaction begin]; | |
| 1104 [CATransaction setDisableActions:YES]; | |
| 1105 | |
| 1106 // Get the current position of the tabStripView. | |
| 1107 NSView* superview = [[self tabStripView] superview]; | |
| 1108 NSArray* subviews = [superview subviews]; | |
| 1109 NSInteger index = [subviews indexOfObject:[self tabStripView]]; | |
| 1110 NSView* siblingBelow = nil; | |
| 1111 if (index > 0) | |
| 1112 siblingBelow = [subviews objectAtIndex:index - 1]; | |
| 1113 | |
| 1114 // Remove the tabStripView. | |
| 1115 [[self tabStripView] removeFromSuperview]; | |
| 1116 | |
| 1117 // Add it to the same position. | |
| 1118 if (siblingBelow) | |
|
Robert Sesek
2014/08/27 22:04:30
nit: needs braces since body is multi-line
erikchen
2014/08/28 00:50:28
Done.
| |
| 1119 [superview addSubview:[self tabStripView] | |
| 1120 positioned:NSWindowAbove | |
| 1121 relativeTo:siblingBelow]; | |
| 1122 else | |
| 1123 [superview addSubview:[self tabStripView] | |
| 1124 positioned:NSWindowBelow | |
| 1125 relativeTo:nil]; | |
| 1126 | |
| 1127 [CATransaction commit]; | |
| 1052 } | 1128 } |
| 1053 } | 1129 } |
| 1054 | 1130 |
| 1055 - (void)updateInfoBarTipVisibility { | 1131 - (void)updateInfoBarTipVisibility { |
| 1056 // If there's no toolbar then hide the infobar tip. | 1132 // If there's no toolbar then hide the infobar tip. |
| 1057 [infoBarContainerController_ | 1133 [infoBarContainerController_ |
| 1058 setShouldSuppressTopInfoBarTip:![self hasToolbar]]; | 1134 setShouldSuppressTopInfoBarTip:![self hasToolbar]]; |
| 1059 } | 1135 } |
| 1060 | 1136 |
| 1137 - (void)enterAppKitFullscreen { | |
| 1138 if (FramedBrowserWindow* framedBrowserWindow = | |
| 1139 base::mac::ObjCCast<FramedBrowserWindow>([self window])) { | |
| 1140 [framedBrowserWindow toggleSystemFullScreen]; | |
| 1141 } | |
| 1142 } | |
| 1143 | |
| 1144 - (void)exitAppKitFullscreen { | |
| 1145 if (FramedBrowserWindow* framedBrowserWindow = | |
| 1146 base::mac::ObjCCast<FramedBrowserWindow>([self window])) { | |
| 1147 [framedBrowserWindow toggleSystemFullScreen]; | |
| 1148 } | |
| 1149 } | |
| 1150 | |
| 1061 @end // @implementation BrowserWindowController(Private) | 1151 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |