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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_private.mm

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

Powered by Google App Engine
This is Rietveld 408576698