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

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: Fix unit tests. 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (contentShifted) { 534 if (contentShifted) {
511 if (WebContents* contents = 535 if (WebContents* contents =
512 browser_->tab_strip_model()->GetActiveWebContents()) { 536 browser_->tab_strip_model()->GetActiveWebContents()) {
513 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 537 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
514 rwhv->WindowFrameChanged(); 538 rwhv->WindowFrameChanged();
515 } 539 }
516 } 540 }
517 } 541 }
518 542
519 - (void)updateRoundedBottomCorners { 543 - (void)updateRoundedBottomCorners {
520 [[self tabContentArea] setRoundedBottomCorners:![self isFullscreen]]; 544 [[self tabContentArea] setRoundedBottomCorners:![self isInAnyFullscreenMode]];
521 } 545 }
522 546
523 - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression { 547 - (void)adjustToolbarAndBookmarkBarForCompression:(CGFloat)compression {
524 CGFloat newHeight = 548 CGFloat newHeight =
525 [toolbarController_ desiredHeightForCompression:compression]; 549 [toolbarController_ desiredHeightForCompression:compression];
526 NSRect toolbarFrame = [[toolbarController_ view] frame]; 550 NSRect toolbarFrame = [[toolbarController_ view] frame];
527 CGFloat deltaH = newHeight - toolbarFrame.size.height; 551 CGFloat deltaH = newHeight - toolbarFrame.size.height;
528 552
529 if (deltaH == 0) 553 if (deltaH == 0)
530 return; 554 return;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 662
639 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 663 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
640 [center removeObserver:self 664 [center removeObserver:self
641 name:NSWindowWillCloseNotification 665 name:NSWindowWillCloseNotification
642 object:[notification object]]; 666 object:[notification object]];
643 [self releaseBarVisibilityForOwner:[notification object] 667 [self releaseBarVisibilityForOwner:[notification object]
644 withAnimation:YES 668 withAnimation:YES
645 delay:YES]; 669 delay:YES];
646 } 670 }
647 671
648 - (void)setPresentationModeInternal:(BOOL)presentationMode 672 - (void)configurePresentationModeController {
649 forceDropdown:(BOOL)forceDropdown { 673 BOOL fullscreen_for_tab =
650 if (presentationMode == [self inPresentationMode]) 674 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending();
651 return; 675 BOOL kiosk_mode =
676 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode);
677 BOOL showDropdown =
678 !fullscreen_for_tab && !kiosk_mode && ([self floatingBarHasFocus]);
679 if (permissionBubbleCocoa_ && permissionBubbleCocoa_->IsVisible()) {
680 DCHECK(permissionBubbleCocoa_->window());
681 // A visible permission bubble will force the dropdown to remain visible.
682 [self lockBarVisibilityForOwner:permissionBubbleCocoa_->window()
683 withAnimation:NO
684 delay:NO];
685 showDropdown = YES;
686 // Register to be notified when the permission bubble is closed, to
687 // allow fullscreen to hide the dropdown.
688 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
689 [center addObserver:self
690 selector:@selector(permissionBubbleWindowWillClose:)
691 name:NSWindowWillCloseNotification
692 object:permissionBubbleCocoa_->window()];
693 }
694 if (showDropdown) {
695 // Turn on layered mode for the window's root view for the entry
696 // animation. Without this, the OS fullscreen animation for entering
697 // fullscreen mode does not correctly draw the tab strip.
698 // It will be turned off (set back to NO) when the animation finishes,
699 // in -windowDidEnterFullScreen:.
700 // Leaving wantsLayer on for the duration of presentation mode causes
701 // performance issues when the dropdown is animated in/out. It also does
702 // not seem to be required for the exit animation.
703 windowViewWantsLayer_ = [[[self window] cr_windowView] wantsLayer];
704 [[[self window] cr_windowView] setWantsLayer:YES];
705 }
652 706
653 if (presentationMode) { 707 NSView* contentView = [[self window] contentView];
654 BOOL fullscreen_for_tab = 708 [presentationModeController_
655 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); 709 enterPresentationModeForContentView:contentView
656 BOOL kiosk_mode = 710 showDropdown:showDropdown];
657 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); 711 }
658 BOOL showDropdown = !fullscreen_for_tab && 712
659 !kiosk_mode && 713 - (void)adjustUIForExitingFullscreenAndStopOmniboxSliding {
660 (forceDropdown || [self floatingBarHasFocus]); 714 [presentationModeController_ exitPresentationMode];
715 presentationModeController_.reset();
716
717 // Force the bookmark bar z-order to update.
718 [[bookmarkBarController_ view] removeFromSuperview];
719 [self layoutSubviews];
720 }
721
722 - (void)adjustUIForSlidingFullscreenStyle:(fullscreen_mac::SlidingStyle)style {
723 fullscreenStyle_ = style;
724
725 if (!presentationModeController_) {
661 presentationModeController_.reset( 726 presentationModeController_.reset(
662 [[PresentationModeController alloc] initWithBrowserController:self]); 727 [[PresentationModeController alloc] initWithBrowserController:self]);
663 728 [self configurePresentationModeController];
664 if (permissionBubbleCocoa_ && permissionBubbleCocoa_->IsVisible()) {
665 DCHECK(permissionBubbleCocoa_->window());
666 // A visible permission bubble will force the dropdown to remain visible.
667 [self lockBarVisibilityForOwner:permissionBubbleCocoa_->window()
668 withAnimation:NO
669 delay:NO];
670 showDropdown = YES;
671 // Register to be notified when the permission bubble is closed, to
672 // allow fullscreen to hide the dropdown.
673 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
674 [center addObserver:self
675 selector:@selector(permissionBubbleWindowWillClose:)
676 name:NSWindowWillCloseNotification
677 object:permissionBubbleCocoa_->window()];
678 }
679 if (showDropdown) {
680 // Turn on layered mode for the window's root view for the entry
681 // animation. Without this, the OS fullscreen animation for entering
682 // fullscreen mode does not correctly draw the tab strip.
683 // It will be turned off (set back to NO) when the animation finishes,
684 // in -windowDidEnterFullScreen:.
685 // Leaving wantsLayer on for the duration of presentation mode causes
686 // performance issues when the dropdown is animated in/out. It also does
687 // not seem to be required for the exit animation.
688 windowViewWantsLayer_ = [[[self window] cr_windowView] wantsLayer];
689 [[[self window] cr_windowView] setWantsLayer:YES];
690 }
691 NSView* contentView = [[self window] contentView];
692 [presentationModeController_ enterPresentationModeForContentView:contentView
693 showDropdown:showDropdown];
694 } else {
695 [presentationModeController_ exitPresentationMode];
696 presentationModeController_.reset();
697 } 729 }
698 730
699 [self adjustUIForPresentationMode:presentationMode]; 731 if (!floatingBarBackingView_.get() &&
732 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) {
733 floatingBarBackingView_.reset(
734 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]);
735 [floatingBarBackingView_
736 setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
737 }
738
739 // Force the bookmark bar z-order to update.
740 [[bookmarkBarController_ view] removeFromSuperview];
700 [self layoutSubviews]; 741 [self layoutSubviews];
701 } 742 }
702 743
703 - (void)enterImmersiveFullscreen { 744 - (void)enterImmersiveFullscreen {
704 // |-isFullscreen:| will return YES from here onwards. 745 // Set to NO by |-windowDidEnterFullScreen:|.
705 enteringFullscreen_ = YES; // Set to NO by |-windowDidEnterFullScreen:|. 746 enteringImmersiveFullscreen_ = YES;
706 747
707 // Fade to black. 748 // Fade to black.
708 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; 749 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6;
709 Boolean didFadeOut = NO; 750 Boolean didFadeOut = NO;
710 CGDisplayFadeReservationToken token; 751 CGDisplayFadeReservationToken token;
711 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) 752 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token)
712 == kCGErrorSuccess) { 753 == kCGErrorSuccess) {
713 didFadeOut = YES; 754 didFadeOut = YES;
714 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, 755 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal,
715 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); 756 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true);
716 } 757 }
717 758
718 // Create the fullscreen window. 759 // Create the fullscreen window.
719 fullscreenWindow_.reset([[self createFullscreenWindow] retain]); 760 fullscreenWindow_.reset([[self createFullscreenWindow] retain]);
720 savedRegularWindow_ = [[self window] retain]; 761 savedRegularWindow_ = [[self window] retain];
721 savedRegularWindowFrame_ = [savedRegularWindow_ frame]; 762 savedRegularWindowFrame_ = [savedRegularWindow_ frame];
722 763
723 [self moveViewsForImmersiveFullscreen:YES 764 [self moveViewsForImmersiveFullscreen:YES
724 regularWindow:[self window] 765 regularWindow:[self window]
725 fullscreenWindow:fullscreenWindow_.get()]; 766 fullscreenWindow:fullscreenWindow_.get()];
726 767
727 // When simplified fullscreen is enabled, do not enter presentation mode. 768 // When simplified fullscreen is enabled, do not enter presentation mode.
728 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 769 const CommandLine* command_line = CommandLine::ForCurrentProcess();
770 fullscreen_mac::SlidingStyle style;
729 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) { 771 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) {
730 // TODO(rohitrao): Add code to manage the menubar here. 772 style = fullscreen_mac::OMNIBOX_PRESENT;
731 } else { 773 } else {
732 [self adjustUIForPresentationMode:YES]; 774 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN;
733 [self setPresentationModeInternal:YES forceDropdown:NO];
734 } 775 }
776 [self adjustUIForSlidingFullscreenStyle:style];
735 777
736 // AppKit is helpful and prevents NSWindows from having the same height as 778 // AppKit is helpful and prevents NSWindows from having the same height as
737 // the screen while the menu bar is showing. This only applies to windows on 779 // the screen while the menu bar is showing. This only applies to windows on
738 // a secondary screen, in a separate space. Calling [NSWindow 780 // a secondary screen, in a separate space. Calling [NSWindow
739 // setFrame:display:] with the screen's height will always reduce the 781 // setFrame:display:] with the screen's height will always reduce the
740 // height by the height of the MenuBar. Calling the method with any other 782 // height by the height of the MenuBar. Calling the method with any other
741 // height works fine. The relevant method in the 10.10 AppKit SDK is called: 783 // height works fine. The relevant method in the 10.10 AppKit SDK is called:
742 // _canAdjustSizeForScreensHaveSeparateSpacesIfFillingSecondaryScreen 784 // _canAdjustSizeForScreensHaveSeparateSpacesIfFillingSecondaryScreen
743 // 785 //
744 // TODO(erikchen): Refactor the logic to allow the window to be shown after 786 // 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
794 [self windowDidExitFullScreen:nil]; 836 [self windowDidExitFullScreen:nil];
795 837
796 // Fade back in. 838 // Fade back in.
797 if (didFadeOut) { 839 if (didFadeOut) {
798 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, 840 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor,
799 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); 841 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false);
800 CGReleaseDisplayFadeReservation(token); 842 CGReleaseDisplayFadeReservation(token);
801 } 843 }
802 } 844 }
803 845
804 // TODO(rohitrao): This function has shrunk into uselessness, and
805 // |-setFullscreen:| has grown rather large. Find a good way to break up
806 // |-setFullscreen:| into smaller pieces. http://crbug.com/36449
807 - (void)adjustUIForPresentationMode:(BOOL)fullscreen {
808 // Create the floating bar backing view if necessary.
809 if (fullscreen && !floatingBarBackingView_.get() &&
810 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) {
811 floatingBarBackingView_.reset(
812 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]);
813 [floatingBarBackingView_ setAutoresizingMask:(NSViewWidthSizable |
814 NSViewMinYMargin)];
815 }
816
817 // Force the bookmark bar z-order to update.
818 [[bookmarkBarController_ view] removeFromSuperview];
819 [self updateSubviewZOrder:fullscreen];
820 }
821
822 - (void)showFullscreenExitBubbleIfNecessary { 846 - (void)showFullscreenExitBubbleIfNecessary {
823 // This method is called in response to 847 // This method is called in response to
824 // |-updateFullscreenExitBubbleURL:bubbleType:|. If we're in the middle of the 848 // |-updateFullscreenExitBubbleURL:bubbleType:|. If we're in the middle of the
825 // transition into fullscreen (i.e., using the System Fullscreen API), do not 849 // transition into fullscreen (i.e., using the AppKit Fullscreen API), do not
826 // show the bubble because it will cause visual jank 850 // show the bubble because it will cause visual jank
827 // (http://crbug.com/130649). This will be called again as part of 851 // (http://crbug.com/130649). This will be called again as part of
828 // |-windowDidEnterFullScreen:|, so arrange to do that work then instead. 852 // |-windowDidEnterFullScreen:|, so arrange to do that work then instead.
829 if (enteringFullscreen_) 853 if (enteringAppKitFullscreen_)
830 return; 854 return;
831 855
832 [self hideOverlayIfPossibleWithAnimation:NO delay:NO]; 856 [self hideOverlayIfPossibleWithAnimation:NO delay:NO];
833 857
834 if (fullscreenBubbleType_ == FEB_TYPE_NONE || 858 if (fullscreenBubbleType_ == FEB_TYPE_NONE ||
835 fullscreenBubbleType_ == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) { 859 fullscreenBubbleType_ == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) {
836 // Show no exit instruction bubble on Mac when in Browser Fullscreen. 860 // Show no exit instruction bubble on Mac when in Browser Fullscreen.
837 [self destroyFullscreenExitBubbleIfNecessary]; 861 [self destroyFullscreenExitBubbleIfNecessary];
838 } else { 862 } else {
839 [fullscreenExitBubbleController_ closeImmediately]; 863 [fullscreenExitBubbleController_ closeImmediately];
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 } 908 }
885 909
886 - (void)windowWillEnterFullScreen:(NSNotification*)notification { 910 - (void)windowWillEnterFullScreen:(NSNotification*)notification {
887 if (notification) // For System Fullscreen when non-nil. 911 if (notification) // For System Fullscreen when non-nil.
888 [self registerForContentViewResizeNotifications]; 912 [self registerForContentViewResizeNotifications];
889 913
890 NSWindow* window = [self window]; 914 NSWindow* window = [self window];
891 savedRegularWindowFrame_ = [window frame]; 915 savedRegularWindowFrame_ = [window frame];
892 BOOL mode = enteringPresentationMode_ || 916 BOOL mode = enteringPresentationMode_ ||
893 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); 917 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending();
894 enteringFullscreen_ = YES; 918 enteringAppKitFullscreen_ = YES;
895 [self setPresentationModeInternal:mode forceDropdown:NO]; 919
920 fullscreen_mac::SlidingStyle style;
921 const CommandLine* command_line = CommandLine::ForCurrentProcess();
922 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen))
923 style = fullscreen_mac::OMNIBOX_PRESENT;
924 else if (mode)
925 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN;
926 else
927 style = fullscreen_mac::OMNIBOX_TABS_PRESENT;
928
929 [self adjustUIForSlidingFullscreenStyle:style];
896 } 930 }
897 931
898 - (void)windowDidEnterFullScreen:(NSNotification*)notification { 932 - (void)windowDidEnterFullScreen:(NSNotification*)notification {
899 // In Yosemite, some combination of the titlebar and toolbar always show in 933 // In Yosemite, some combination of the titlebar and toolbar always show in
900 // full-screen mode. We do not want either to show. Search for the window that 934 // full-screen mode. We do not want either to show. Search for the window that
901 // contains the views, and hide it. There is no need to ever unhide the view. 935 // contains the views, and hide it. There is no need to ever unhide the view.
902 // http://crbug.com/380235 936 // http://crbug.com/380235
903 if (base::mac::IsOSYosemiteOrLater()) { 937 if (base::mac::IsOSYosemiteOrLater()) {
904 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { 938 for (NSWindow* window in [[NSApplication sharedApplication] windows]) {
905 if ([window 939 if ([window
906 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { 940 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) {
907 [window.contentView setHidden:YES]; 941 [window.contentView setHidden:YES];
908 } 942 }
909 } 943 }
910 } 944 }
911 945
912 if (notification) // For System Fullscreen when non-nil. 946 if (notification) // For System Fullscreen when non-nil.
913 [self deregisterForContentViewResizeNotifications]; 947 [self deregisterForContentViewResizeNotifications];
914 enteringFullscreen_ = NO; 948 enteringAppKitFullscreen_ = NO;
949 enteringImmersiveFullscreen_ = NO;
915 enteringPresentationMode_ = NO; 950 enteringPresentationMode_ = NO;
916 951
917 const CommandLine* command_line = CommandLine::ForCurrentProcess();
918 if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen) &&
919 fullscreenUrl_.is_empty()) {
920 fullscreenModeController_.reset([[FullscreenModeController alloc]
921 initWithBrowserWindowController:self]);
922 }
923
924 [self showFullscreenExitBubbleIfNecessary]; 952 [self showFullscreenExitBubbleIfNecessary];
925 browser_->WindowFullscreenStateChanged(); 953 browser_->WindowFullscreenStateChanged();
926 [[[self window] cr_windowView] setWantsLayer:windowViewWantsLayer_]; 954 [[[self window] cr_windowView] setWantsLayer:windowViewWantsLayer_];
927 [self updateRoundedBottomCorners]; 955 [self updateRoundedBottomCorners];
928 } 956 }
929 957
930 - (void)windowWillExitFullScreen:(NSNotification*)notification { 958 - (void)windowWillExitFullScreen:(NSNotification*)notification {
931 if (notification) // For System Fullscreen when non-nil. 959 if (notification) // For System Fullscreen when non-nil.
932 [self registerForContentViewResizeNotifications]; 960 [self registerForContentViewResizeNotifications];
933 fullscreenModeController_.reset();
934 [self destroyFullscreenExitBubbleIfNecessary]; 961 [self destroyFullscreenExitBubbleIfNecessary];
935 [self setPresentationModeInternal:NO forceDropdown:NO]; 962 [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
936 } 963 }
937 964
938 - (void)windowDidExitFullScreen:(NSNotification*)notification { 965 - (void)windowDidExitFullScreen:(NSNotification*)notification {
939 if (notification) // For System Fullscreen when non-nil. 966 if (notification) // For System Fullscreen when non-nil.
940 [self deregisterForContentViewResizeNotifications]; 967 [self deregisterForContentViewResizeNotifications];
941 browser_->WindowFullscreenStateChanged(); 968 browser_->WindowFullscreenStateChanged();
942 [self updateRoundedBottomCorners]; 969 [self updateRoundedBottomCorners];
943 } 970 }
944 971
945 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { 972 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window {
946 [self deregisterForContentViewResizeNotifications]; 973 [self deregisterForContentViewResizeNotifications];
947 enteringFullscreen_ = NO; 974 enteringAppKitFullscreen_ = NO;
948 [self setPresentationModeInternal:NO forceDropdown:NO]; 975 [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
949
950 // Force a relayout to try and get the window back into a reasonable state.
951 [self layoutSubviews];
952 } 976 }
953 977
954 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { 978 - (void)windowDidFailToExitFullScreen:(NSWindow*)window {
955 [self deregisterForContentViewResizeNotifications]; 979 [self deregisterForContentViewResizeNotifications];
956 980
957 // Force a relayout to try and get the window back into a reasonable state. 981 // Force a relayout to try and get the window back into a reasonable state.
958 [self layoutSubviews]; 982 [self layoutSubviews];
959 } 983 }
960 984
961 - (void)enableBarVisibilityUpdates { 985 - (void)enableBarVisibilityUpdates {
(...skipping 22 matching lines...) Expand all
984 if (!barVisibilityUpdatesEnabled_ || [barVisibilityLocks_ count]) 1008 if (!barVisibilityUpdatesEnabled_ || [barVisibilityLocks_ count])
985 return; 1009 return;
986 [presentationModeController_ ensureOverlayHiddenWithAnimation:animation 1010 [presentationModeController_ ensureOverlayHiddenWithAnimation:animation
987 delay:delay]; 1011 delay:delay];
988 } 1012 }
989 1013
990 - (CGFloat)toolbarDividerOpacity { 1014 - (CGFloat)toolbarDividerOpacity {
991 return [bookmarkBarController_ toolbarDividerOpacity]; 1015 return [bookmarkBarController_ toolbarDividerOpacity];
992 } 1016 }
993 1017
994 - (void)updateSubviewZOrder:(BOOL)inPresentationMode { 1018 // TODO(erikchen): The implementation of this method is quite fragile. The
1019 // method cr_ensureSubview:... does not check that the subview is /directly/
1020 // above/below the given view. e.g. There are 3 subviews: A, B, C, in that
1021 // order. The method cr_ensureSubview:A isPositioned:NSWindowBelow
1022 // relativeTo:C will have no effect, even though the desired result may have
1023 // been: B, A, C. Consider changing it?
1024 - (void)updateSubviewZOrder:(BOOL)inAnyFullscreen {
995 NSView* contentView = [[self window] contentView]; 1025 NSView* contentView = [[self window] contentView];
996 NSView* toolbarView = [toolbarController_ view]; 1026 NSView* toolbarView = [toolbarController_ view];
997 1027
998 if (inPresentationMode) { 1028 if (inAnyFullscreen) {
999 // Toolbar is above tab contents so that it can slide down from top of 1029 // Toolbar is above tab contents so that it can slide down from top of
1000 // screen. 1030 // screen.
1001 [contentView cr_ensureSubview:toolbarView 1031 [contentView cr_ensureSubview:toolbarView
1002 isPositioned:NSWindowAbove 1032 isPositioned:NSWindowAbove
1003 relativeTo:[self tabContentArea]]; 1033 relativeTo:[self tabContentArea]];
1004 } else { 1034 } else {
1005 // Toolbar is below tab contents so that the info bar arrow can appear above 1035 // Toolbar is below tab contents so that the info bar arrow can appear above
1006 // it. 1036 // it.
1007 [contentView cr_ensureSubview:toolbarView 1037 [contentView cr_ensureSubview:toolbarView
1008 isPositioned:NSWindowBelow 1038 isPositioned:NSWindowBelow
1009 relativeTo:[self tabContentArea]]; 1039 relativeTo:[self tabContentArea]];
1010 } 1040 }
1011 1041
1012 // The bookmark bar is always below the toolbar. 1042 // The bookmark bar is always below the toolbar.
1013 [contentView cr_ensureSubview:[bookmarkBarController_ view] 1043 [contentView cr_ensureSubview:[bookmarkBarController_ view]
1014 isPositioned:NSWindowBelow 1044 isPositioned:NSWindowBelow
1015 relativeTo:toolbarView]; 1045 relativeTo:toolbarView];
1016 1046
1017 if (inPresentationMode) { 1047 if (inAnyFullscreen) {
1018 // In presentation mode the info bar is below all other views. 1048 // In presentation mode the info bar is below all other views.
1019 [contentView cr_ensureSubview:[infoBarContainerController_ view] 1049 [contentView cr_ensureSubview:[infoBarContainerController_ view]
1020 isPositioned:NSWindowBelow 1050 isPositioned:NSWindowBelow
1021 relativeTo:[self tabContentArea]]; 1051 relativeTo:[self tabContentArea]];
1022 } else { 1052 } else {
1023 // Above the toolbar but still below tab contents. Similar to the bookmark 1053 // Above the toolbar but still below tab contents. Similar to the bookmark
1024 // bar, this allows Instant results to be above the info bar. 1054 // bar, this allows Instant results to be above the info bar.
1025 [contentView cr_ensureSubview:[infoBarContainerController_ view] 1055 [contentView cr_ensureSubview:[infoBarContainerController_ view]
1026 isPositioned:NSWindowAbove 1056 isPositioned:NSWindowAbove
1027 relativeTo:toolbarView]; 1057 relativeTo:toolbarView];
1028 } 1058 }
1029 1059
1030 // The find bar is above everything. 1060 // The find bar is above everything.
1031 if (findBarCocoaController_) { 1061 if (findBarCocoaController_) {
1032 NSView* relativeView = nil; 1062 NSView* relativeView = nil;
1033 if (inPresentationMode) 1063 if (inAnyFullscreen)
1034 relativeView = toolbarView; 1064 relativeView = toolbarView;
1035 else 1065 else
1036 relativeView = [self tabContentArea]; 1066 relativeView = [self tabContentArea];
1037 [contentView cr_ensureSubview:[findBarCocoaController_ view] 1067 [contentView cr_ensureSubview:[findBarCocoaController_ view]
1038 isPositioned:NSWindowAbove 1068 isPositioned:NSWindowAbove
1039 relativeTo:relativeView]; 1069 relativeTo:relativeView];
1040 } 1070 }
1041 1071
1042 if (floatingBarBackingView_) { 1072 if (floatingBarBackingView_) {
1043 if ([floatingBarBackingView_ cr_isBelowView:[self tabContentArea]]) 1073 if ([floatingBarBackingView_ cr_isBelowView:[self tabContentArea]])
1044 [floatingBarBackingView_ removeFromSuperview]; 1074 [floatingBarBackingView_ removeFromSuperview];
1045 if ([self placeBookmarkBarBelowInfoBar]) { 1075 if ([self placeBookmarkBarBelowInfoBar]) {
1046 [contentView cr_ensureSubview:floatingBarBackingView_ 1076 [contentView cr_ensureSubview:floatingBarBackingView_
1047 isPositioned:NSWindowAbove 1077 isPositioned:NSWindowAbove
1048 relativeTo:[bookmarkBarController_ view]]; 1078 relativeTo:[bookmarkBarController_ view]];
1049 } else { 1079 } else {
1050 [contentView cr_ensureSubview:floatingBarBackingView_ 1080 [contentView cr_ensureSubview:floatingBarBackingView_
1051 isPositioned:NSWindowBelow 1081 isPositioned:NSWindowBelow
1052 relativeTo:[bookmarkBarController_ view]]; 1082 relativeTo:[bookmarkBarController_ view]];
1053 } 1083 }
1084
1085 // TODO(erikchen): This constraint is necessary. See comment at the
1086 // beginning of the method.
1087 [contentView cr_ensureSubview:floatingBarBackingView_
1088 isPositioned:NSWindowAbove
1089 relativeTo:[self tabContentArea]];
1090 }
1091
1092 // TODO(erikchen): Remove and then add the tabStripView to the root NSView.
1093 // This fixes a layer ordering problem that occurs between the contentView
1094 // and the tabStripView. This is a hack required because NSThemeFrame is not
1095 // layer backed, and because Chrome adds subviews directly to the
1096 // NSThemeFrame.
1097 // http://crbug.com/407921
1098 if (enteringAppKitFullscreen_) {
1099 // Disable implicit animations.
1100 [CATransaction begin];
1101 [CATransaction setDisableActions:YES];
1102
1103 // Get the current position of the tabStripView.
1104 NSView* superview = [[self tabStripView] superview];
1105 NSArray* subviews = [superview subviews];
1106 NSInteger index = [subviews indexOfObject:[self tabStripView]];
1107 NSView* siblingBelow = nil;
1108 if (index > 0)
1109 siblingBelow = [subviews objectAtIndex:index - 1];
1110
1111 // Remove the tabStripView.
1112 [[self tabStripView] removeFromSuperview];
1113
1114 // Add it to the same position.
1115 if (siblingBelow) {
1116 [superview addSubview:[self tabStripView]
1117 positioned:NSWindowAbove
1118 relativeTo:siblingBelow];
1119 } else {
1120 [superview addSubview:[self tabStripView]
1121 positioned:NSWindowBelow
1122 relativeTo:nil];
1123 }
1124
1125 [CATransaction commit];
1054 } 1126 }
1055 } 1127 }
1056 1128
1057 - (void)updateInfoBarTipVisibility { 1129 - (void)updateInfoBarTipVisibility {
1058 // If there's no toolbar then hide the infobar tip. 1130 // If there's no toolbar then hide the infobar tip.
1059 [infoBarContainerController_ 1131 [infoBarContainerController_
1060 setShouldSuppressTopInfoBarTip:![self hasToolbar]]; 1132 setShouldSuppressTopInfoBarTip:![self hasToolbar]];
1061 } 1133 }
1062 1134
1063 - (NSInteger)infoBarMaxTopArrowHeight { 1135 - (NSInteger)infoBarMaxTopArrowHeight {
1064 NSInteger topArrowHeight = 0; 1136 NSInteger topArrowHeight = 0;
1065 LocationBarViewMac* locationBarView = [self locationBarBridge]; 1137 LocationBarViewMac* locationBarView = [self locationBarBridge];
1066 NSPoint iconBottom = locationBarView->GetPageInfoBubblePoint(); 1138 NSPoint iconBottom = locationBarView->GetPageInfoBubblePoint();
1067 1139
1068 CGFloat overlappingTipHeight = 1140 CGFloat overlappingTipHeight =
1069 [infoBarContainerController_ overlappingTipHeight]; 1141 [infoBarContainerController_ overlappingTipHeight];
1070 NSPoint infoBarTop = 1142 NSPoint infoBarTop =
1071 NSMakePoint(0, NSHeight([infoBarContainerController_ view].frame) - 1143 NSMakePoint(0, NSHeight([infoBarContainerController_ view].frame) -
1072 overlappingTipHeight); 1144 overlappingTipHeight);
1073 infoBarTop = [[infoBarContainerController_ view] convertPoint:infoBarTop 1145 infoBarTop = [[infoBarContainerController_ view] convertPoint:infoBarTop
1074 toView:nil]; 1146 toView:nil];
1075 1147
1076 topArrowHeight = iconBottom.y - infoBarTop.y; 1148 topArrowHeight = iconBottom.y - infoBarTop.y;
1077 return topArrowHeight; 1149 return topArrowHeight;
1078 } 1150 }
1079 1151
1152 - (void)enterAppKitFullscreen {
1153 DCHECK(base::mac::IsOSLionOrLater());
1154 if (FramedBrowserWindow* framedBrowserWindow =
1155 base::mac::ObjCCast<FramedBrowserWindow>([self window])) {
1156 [framedBrowserWindow toggleSystemFullScreen];
1157 }
1158 }
1159
1160 - (void)exitAppKitFullscreen {
1161 DCHECK(base::mac::IsOSLionOrLater());
1162 if (FramedBrowserWindow* framedBrowserWindow =
1163 base::mac::ObjCCast<FramedBrowserWindow>([self window])) {
1164 [framedBrowserWindow toggleSystemFullScreen];
1165 }
1166 }
1167
1080 @end // @implementation BrowserWindowController(Private) 1168 @end // @implementation BrowserWindowController(Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698