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