Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/sdk_forward_declarations.h" | 8 #import "base/mac/sdk_forward_declarations.h" |
| 9 #import "chrome/browser/ui/cocoa/browser_window_layout.h" | 9 #import "chrome/browser/ui/cocoa/browser_window_layout.h" |
| 10 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 10 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| 11 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 11 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h" |
| 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 14 #import "chrome/browser/ui/cocoa/themed_window.h" | 14 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 15 #import "ui/base/cocoa/focus_tracker.h" | 15 #import "ui/base/cocoa/focus_tracker.h" |
| 16 #include "ui/base/material_design/material_design_controller.h" | 16 #include "ui/base/material_design/material_design_controller.h" |
| 17 #include "ui/base/theme_provider.h" | 17 #include "ui/base/theme_provider.h" |
| 18 | 18 |
| 19 @interface TabWindowController () | 19 @interface TabWindowController () |
| 20 - (void)setUseOverlay:(BOOL)useOverlay; | 20 - (void)setUseOverlay:(BOOL)useOverlay; |
| 21 | 21 |
| 22 // The tab strip background view should always be inserted as the back-most | 22 // The tab strip background view should always be inserted as the back-most |
| 23 // subview of the root view. It cannot be a subview of the contentView, as that | 23 // subview of the root view. It cannot be a subview of the contentView, as that |
| 24 // would cause it to become layer backed, which would cause it to draw on top | 24 // would cause it to become layer backed, which would cause it to draw on top |
| 25 // of non-layer backed content like the window controls. | 25 // of non-layer backed content like the window controls. |
| 26 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window | 26 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window |
| 27 titleBar:(BOOL)hasTitleBar; | 27 titleBar:(BOOL)hasTitleBar; |
| 28 | |
| 29 // Called when NSWindowWillEnterFullScreenNotification notification received. | |
| 30 // Makes visual effects view hidden as it should not be displayed in fullscreen. | |
| 31 - (void)windowWillEnterFullScreenNotification:(NSNotification*)notification; | |
| 32 | |
| 33 // Called when NSWindowWillExitFullScreenNotification notification received. | |
| 34 // Makes visual effects view visible since it was hidden in fullscreen. | |
| 35 - (void)windowWillExitFullScreenNotification:(NSNotification*)notification; | |
| 36 | |
| 28 @end | 37 @end |
| 29 | 38 |
| 30 @interface TabWindowOverlayWindow : NSWindow | 39 @interface TabWindowOverlayWindow : NSWindow |
| 31 @end | 40 @end |
| 32 | 41 |
| 33 @implementation TabWindowOverlayWindow | 42 @implementation TabWindowOverlayWindow |
| 34 | 43 |
| 35 - (const ui::ThemeProvider*)themeProvider { | 44 - (const ui::ThemeProvider*)themeProvider { |
| 36 return [[self parentWindow] themeProvider]; | 45 return [[self parentWindow] themeProvider]; |
| 37 } | 46 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]); | 91 [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]); |
| 83 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | | 92 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | |
| 84 NSViewHeightSizable]; | 93 NSViewHeightSizable]; |
| 85 [chromeContentView_ addSubview:tabContentArea_]; | 94 [chromeContentView_ addSubview:tabContentArea_]; |
| 86 | 95 |
| 87 // tabStripBackgroundView_ draws the theme image behind the tab strip area. | 96 // tabStripBackgroundView_ draws the theme image behind the tab strip area. |
| 88 // When making a tab dragging window (setUseOverlay:), this view stays in | 97 // When making a tab dragging window (setUseOverlay:), this view stays in |
| 89 // the parent window so that it can be translucent, while the tab strip view | 98 // the parent window so that it can be translucent, while the tab strip view |
| 90 // moves to the child window and stays opaque. | 99 // moves to the child window and stays opaque. |
| 91 NSView* windowView = [window contentView]; | 100 NSView* windowView = [window contentView]; |
| 101 CGFloat paintHeight = [FramedBrowserWindow browserFrameViewPaintHeight]; | |
| 92 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] | 102 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] |
| 93 initWithFrame:NSMakeRect(0, | 103 initWithFrame:NSMakeRect(0, NSMaxY([windowView bounds]) - paintHeight, |
| 94 NSMaxY([windowView bounds]) - | 104 NSWidth([windowView bounds]), paintHeight)]); |
| 95 kBrowserFrameViewPaintHeight, | |
| 96 NSWidth([windowView bounds]), | |
| 97 kBrowserFrameViewPaintHeight)]); | |
| 98 [tabStripBackgroundView_ | 105 [tabStripBackgroundView_ |
| 99 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; | 106 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
| 100 [self insertTabStripBackgroundViewIntoWindow:window titleBar:hasTitleBar]; | 107 [self insertTabStripBackgroundViewIntoWindow:window titleBar:hasTitleBar]; |
| 101 | 108 |
| 102 tabStripView_.reset([[TabStripView alloc] | 109 tabStripView_.reset([[TabStripView alloc] |
| 103 initWithFrame:NSMakeRect( | 110 initWithFrame:NSMakeRect( |
| 104 0, 0, kDefaultWidth, chrome::kTabStripHeight)]); | 111 0, 0, kDefaultWidth, chrome::kTabStripHeight)]); |
| 105 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | | 112 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | |
| 106 NSViewMinYMargin]; | 113 NSViewMinYMargin]; |
| 107 if (hasTabStrip) | 114 if (hasTabStrip) |
| 108 [windowView addSubview:tabStripView_]; | 115 [windowView addSubview:tabStripView_]; |
| 116 | |
| 117 if (chrome::ShouldUseFullSizeContentView()) { | |
| 118 // |windowWillEnterFullScreen:| and |windowWillExitFullScreen:| are | |
| 119 // already called because self is a delegate for the window. However this | |
| 120 // class is designed for subclassing and can not implement | |
| 121 // NSWindowDelegate methods (because subclasses can do so as well and they | |
| 122 // should be able to). TODO(crbug.com/654656): Move |visualEffectView_| to | |
| 123 // subclass. | |
| 124 [[NSNotificationCenter defaultCenter] | |
| 125 addObserver:self | |
| 126 selector:@selector(windowWillEnterFullScreenNotification:) | |
| 127 name:NSWindowWillEnterFullScreenNotification | |
| 128 object:window]; | |
| 129 [[NSNotificationCenter defaultCenter] | |
| 130 addObserver:self | |
| 131 selector:@selector(windowWillExitFullScreenNotification:) | |
| 132 name:NSWindowWillExitFullScreenNotification | |
| 133 object:window]; | |
| 134 } | |
| 109 } | 135 } |
| 110 return self; | 136 return self; |
| 111 } | 137 } |
| 112 | 138 |
| 139 - (void)dealloc { | |
| 140 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| 141 [super dealloc]; | |
| 142 } | |
| 143 | |
| 113 - (NSView*)tabStripBackgroundView { | 144 - (NSView*)tabStripBackgroundView { |
| 114 return tabStripBackgroundView_; | 145 return tabStripBackgroundView_; |
| 115 } | 146 } |
| 116 | 147 |
| 117 - (TabStripView*)tabStripView { | 148 - (TabStripView*)tabStripView { |
| 118 return tabStripView_; | 149 return tabStripView_; |
| 119 } | 150 } |
| 120 | 151 |
| 121 - (FastResizeView*)tabContentArea { | 152 - (FastResizeView*)tabContentArea { |
| 122 return tabContentArea_; | 153 return tabContentArea_; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 | 384 |
| 354 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window | 385 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window |
| 355 titleBar:(BOOL)hasTitleBar { | 386 titleBar:(BOOL)hasTitleBar { |
| 356 DCHECK(tabStripBackgroundView_); | 387 DCHECK(tabStripBackgroundView_); |
| 357 NSView* rootView = [[window contentView] superview]; | 388 NSView* rootView = [[window contentView] superview]; |
| 358 | 389 |
| 359 // In Material Design on 10.10 and higher, the top portion of the window is | 390 // In Material Design on 10.10 and higher, the top portion of the window is |
| 360 // blurred using an NSVisualEffectView. | 391 // blurred using an NSVisualEffectView. |
| 361 Class nsVisualEffectViewClass = NSClassFromString(@"NSVisualEffectView"); | 392 Class nsVisualEffectViewClass = NSClassFromString(@"NSVisualEffectView"); |
| 362 if (!nsVisualEffectViewClass) { | 393 if (!nsVisualEffectViewClass) { |
| 394 DCHECK(!chrome::ShouldUseFullSizeContentView()); | |
| 363 [rootView addSubview:tabStripBackgroundView_ | 395 [rootView addSubview:tabStripBackgroundView_ |
| 364 positioned:NSWindowBelow | 396 positioned:NSWindowBelow |
| 365 relativeTo:nil]; | 397 relativeTo:nil]; |
| 366 return; | 398 return; |
| 367 } | 399 } |
| 368 | 400 |
| 369 [window setTitlebarAppearsTransparent:YES]; | 401 [window setTitlebarAppearsTransparent:YES]; |
| 370 | 402 |
| 371 // If the window has a normal titlebar, then do not add NSVisualEffectView. | 403 // If the window has a normal titlebar, then do not add NSVisualEffectView. |
| 372 if (hasTitleBar) | 404 if (hasTitleBar) |
| 373 return; | 405 return; |
| 374 | 406 |
| 375 base::scoped_nsobject<NSVisualEffectView> visualEffectView( | 407 visualEffectView_.reset( |
| 376 [[nsVisualEffectViewClass alloc] | 408 [[nsVisualEffectViewClass alloc] |
| 377 initWithFrame:[tabStripBackgroundView_ frame]]); | 409 initWithFrame:[tabStripBackgroundView_ frame]]); |
| 378 DCHECK(visualEffectView); | 410 DCHECK(visualEffectView_); |
| 379 | 411 |
| 380 [visualEffectView setAutoresizingMask: | 412 [visualEffectView_ setAutoresizingMask: |
| 381 [tabStripBackgroundView_ autoresizingMask]]; | 413 [tabStripBackgroundView_ autoresizingMask]]; |
| 382 [tabStripBackgroundView_ | 414 [tabStripBackgroundView_ |
| 383 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 415 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 384 | 416 |
| 385 // Set to a default appearance and material. If this is an Incognito window | 417 // Set to a default appearance and material. If this is an Incognito window |
| 386 // the material and vibrancy should be dark but this method gets called at | 418 // the material and vibrancy should be dark but this method gets called at |
| 387 // the start of -[BrowserWindowController initWithBrowser:takeOwnership:], | 419 // the start of -[BrowserWindowController initWithBrowser:takeOwnership:], |
| 388 // before the |browser_| ivar has been set. Without a browser object we | 420 // before the |browser_| ivar has been set. Without a browser object we |
| 389 // can't check the window's theme. The final setup happens in | 421 // can't check the window's theme. The final setup happens in |
| 390 // -[TabStripView setController:], at which point we have access to the theme. | 422 // -[TabStripView setController:], at which point we have access to the theme. |
| 391 [visualEffectView setAppearance: | 423 [visualEffectView_ setAppearance: |
| 392 [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight]]; | 424 [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight]]; |
| 393 [visualEffectView setMaterial:NSVisualEffectMaterialLight]; | 425 [visualEffectView_ setMaterial:NSVisualEffectMaterialLight]; |
| 394 [visualEffectView setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; | 426 [visualEffectView_ setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; |
| 395 [visualEffectView setState:NSVisualEffectStateFollowsWindowActiveState]; | 427 [visualEffectView_ setState:NSVisualEffectStateFollowsWindowActiveState]; |
| 396 | 428 |
| 397 [rootView addSubview:visualEffectView | 429 if (chrome::ShouldUseFullSizeContentView()) { |
| 398 positioned:NSWindowBelow | 430 [[window contentView] addSubview:visualEffectView_]; |
| 399 relativeTo:nil]; | 431 } else { |
| 432 [rootView addSubview:visualEffectView_ | |
| 433 positioned:NSWindowBelow | |
| 434 relativeTo:nil]; | |
| 435 } | |
| 400 | 436 |
| 401 // Make the |tabStripBackgroundView_| a child of the NSVisualEffectView. | 437 // Make the |tabStripBackgroundView_| a child of the NSVisualEffectView. |
| 402 [tabStripBackgroundView_ setFrame:[visualEffectView bounds]]; | 438 [tabStripBackgroundView_ setFrame:[visualEffectView_ bounds]]; |
| 403 [visualEffectView addSubview:tabStripBackgroundView_]; | 439 [visualEffectView_ addSubview:tabStripBackgroundView_]; |
| 404 } | 440 } |
| 405 | 441 |
| 406 // Called when the size of the window content area has changed. Override to | 442 // Called when the size of the window content area has changed. Override to |
| 407 // position specific views. Base class implementation does nothing. | 443 // position specific views. Base class implementation does nothing. |
| 408 - (void)layoutSubviews { | 444 - (void)layoutSubviews { |
| 409 NOTIMPLEMENTED(); | 445 NOTIMPLEMENTED(); |
| 410 } | 446 } |
| 411 | 447 |
| 448 - (void)windowWillEnterFullScreenNotification:(NSNotification*)notification { | |
| 449 [[visualEffectView_ animator] setAlphaValue:0.0]; | |
|
erikchen
2016/10/11 17:39:45
why is this necessary now but not before?
Eugene But (OOO till 7-30)
2016/10/11 21:06:16
With old view hierarchy NSVisualEffectVew was move
| |
| 450 } | |
| 451 | |
| 452 - (void)windowWillExitFullScreenNotification:(NSNotification*)notification { | |
| 453 [[visualEffectView_ animator] setAlphaValue:1.0]; | |
| 454 } | |
| 455 | |
| 412 @end | 456 @end |
| OLD | NEW |