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 // TODO: Remove once we no longer support 10.9 (-Wunguarded-availability) |
|
Robert Sesek
2017/01/13 19:39:42
Same comment.
Sidney San Martín
2017/01/13 20:05:17
Done.
| |
| 20 - (void)setUseOverlay:(BOOL)useOverlay; | 20 @interface NSWindow (TitlebarAppearsTransparent) |
| 21 | 21 @property BOOL titlebarAppearsTransparent; |
| 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 | |
| 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. | |
| 26 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window | |
| 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 | |
| 37 @end | 22 @end |
| 23 // /TODO | |
| 38 | 24 |
| 39 @interface TabWindowOverlayWindow : NSWindow | 25 @interface TabWindowOverlayWindow : NSWindow |
| 40 @end | 26 @end |
| 41 | 27 |
| 42 @implementation TabWindowOverlayWindow | 28 @implementation TabWindowOverlayWindow |
| 43 | 29 |
| 44 - (const ui::ThemeProvider*)themeProvider { | 30 - (const ui::ThemeProvider*)themeProvider { |
| 45 return [[self parentWindow] themeProvider]; | 31 return [[self parentWindow] themeProvider]; |
| 46 } | 32 } |
| 47 | 33 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // When making a tab dragging window (setUseOverlay:), this view stays in | 83 // When making a tab dragging window (setUseOverlay:), this view stays in |
| 98 // the parent window so that it can be translucent, while the tab strip view | 84 // the parent window so that it can be translucent, while the tab strip view |
| 99 // moves to the child window and stays opaque. | 85 // moves to the child window and stays opaque. |
| 100 NSView* windowView = [window contentView]; | 86 NSView* windowView = [window contentView]; |
| 101 CGFloat paintHeight = [FramedBrowserWindow browserFrameViewPaintHeight]; | 87 CGFloat paintHeight = [FramedBrowserWindow browserFrameViewPaintHeight]; |
| 102 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] | 88 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] |
| 103 initWithFrame:NSMakeRect(0, NSMaxY([windowView bounds]) - paintHeight, | 89 initWithFrame:NSMakeRect(0, NSMaxY([windowView bounds]) - paintHeight, |
| 104 NSWidth([windowView bounds]), paintHeight)]); | 90 NSWidth([windowView bounds]), paintHeight)]); |
| 105 [tabStripBackgroundView_ | 91 [tabStripBackgroundView_ |
| 106 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; | 92 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
| 107 [self insertTabStripBackgroundViewIntoWindow:window titleBar:hasTitleBar]; | |
| 108 | 93 |
| 109 tabStripView_.reset([[TabStripView alloc] | 94 tabStripView_.reset([[TabStripView alloc] |
| 110 initWithFrame:NSMakeRect( | 95 initWithFrame:NSMakeRect( |
| 111 0, 0, kDefaultWidth, chrome::kTabStripHeight)]); | 96 0, 0, kDefaultWidth, chrome::kTabStripHeight)]); |
| 112 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | | 97 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | |
| 113 NSViewMinYMargin]; | 98 NSViewMinYMargin]; |
| 114 if (hasTabStrip) | 99 if (hasTabStrip) |
| 115 [windowView addSubview:tabStripView_]; | 100 [windowView addSubview:tabStripView_]; |
| 116 | 101 |
| 102 if ([window respondsToSelector:@selector(setTitlebarAppearsTransparent:)]) | |
| 103 [window setTitlebarAppearsTransparent:YES]; | |
| 104 | |
| 117 if (chrome::ShouldUseFullSizeContentView()) { | 105 if (chrome::ShouldUseFullSizeContentView()) { |
| 118 // |windowWillEnterFullScreen:| and |windowWillExitFullScreen:| are | 106 [[window contentView] addSubview:tabStripBackgroundView_]; |
|
Robert Sesek
2017/01/13 19:39:42
Use the windowView local here and on line 108 inst
Sidney San Martín
2017/01/13 20:05:17
I renamed it and moved it up to use in more places
| |
| 119 // already called because self is a delegate for the window. However this | 107 } else { |
| 120 // class is designed for subclassing and can not implement | 108 NSView* rootView = [[self.window contentView] superview]; |
| 121 // NSWindowDelegate methods (because subclasses can do so as well and they | 109 [rootView addSubview:tabStripBackgroundView_ |
| 122 // should be able to). TODO(crbug.com/654656): Move |visualEffectView_| to | 110 positioned:NSWindowBelow |
| 123 // subclass. | 111 relativeTo:nil]; |
| 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 } | 112 } |
| 135 } | 113 } |
| 136 return self; | 114 return self; |
| 137 } | 115 } |
| 138 | 116 |
| 139 - (void)dealloc { | 117 - (void)dealloc { |
| 140 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 118 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 141 [super dealloc]; | 119 [super dealloc]; |
| 142 } | 120 } |
| 143 | 121 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 // followed by RenderWidgetHost::Blur(), which would result in an unexpected | 181 // followed by RenderWidgetHost::Blur(), which would result in an unexpected |
| 204 // loss of focus. | 182 // loss of focus. |
| 205 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]); | 183 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]); |
| 206 [window makeFirstResponder:nil]; | 184 [window makeFirstResponder:nil]; |
| 207 | 185 |
| 208 // Move the original window's tab strip view and content view to the overlay | 186 // Move the original window's tab strip view and content view to the overlay |
| 209 // window. The content view is added as a subview of the overlay window's | 187 // window. The content view is added as a subview of the overlay window's |
| 210 // content view (rather than using setContentView:) because the overlay | 188 // content view (rather than using setContentView:) because the overlay |
| 211 // window has a different content size (due to it being borderless). | 189 // window has a different content size (due to it being borderless). |
| 212 [[overlayWindow_ contentView] addSubview:[self tabStripView]]; | 190 [[overlayWindow_ contentView] addSubview:[self tabStripView]]; |
| 213 [[self tabStripView] setInATabDraggingOverlayWindow:YES]; | 191 [tabStripBackgroundView_ setInATabDraggingOverlayWindow:YES]; |
| 214 [[overlayWindow_ contentView] addSubview:originalContentView_]; | 192 [[overlayWindow_ contentView] addSubview:originalContentView_]; |
| 215 | 193 |
| 216 [overlayWindow_ orderFront:nil]; | 194 [overlayWindow_ orderFront:nil]; |
| 217 } else if (!useOverlay && overlayWindow_) { | 195 } else if (!useOverlay && overlayWindow_) { |
| 218 DCHECK(originalContentView_); | 196 DCHECK(originalContentView_); |
| 219 | 197 |
| 220 // Return the original window's tab strip view and content view to their | 198 // Return the original window's tab strip view and content view to their |
| 221 // places. The TabStripView always needs to be in front of the window's | 199 // places. The TabStripView always needs to be in front of the window's |
| 222 // content view and therefore it should always be added after the content | 200 // content view and therefore it should always be added after the content |
| 223 // view is set. It needs to be positioned below the avatar button to ensure | 201 // view is set. It needs to be positioned below the avatar button to ensure |
| 224 // that its overlay will not overlap it. | 202 // that its overlay will not overlap it. |
| 225 [[window contentView] addSubview:originalContentView_ | 203 [[window contentView] addSubview:originalContentView_ |
| 226 positioned:NSWindowBelow | 204 positioned:NSWindowBelow |
| 227 relativeTo:nil]; | 205 relativeTo:nil]; |
| 228 originalContentView_.frame = [[window contentView] bounds]; | 206 originalContentView_.frame = [[window contentView] bounds]; |
| 229 [[window contentView] addSubview:[self tabStripView] | 207 [[window contentView] addSubview:[self tabStripView] |
| 230 positioned:NSWindowBelow | 208 positioned:NSWindowBelow |
| 231 relativeTo:[self avatarView]]; | 209 relativeTo:[self avatarView]]; |
| 232 [[self tabStripView] setInATabDraggingOverlayWindow:NO]; | 210 [tabStripBackgroundView_ setInATabDraggingOverlayWindow:NO]; |
| 233 [[window contentView] updateTrackingAreas]; | 211 [[window contentView] updateTrackingAreas]; |
| 234 | 212 |
| 235 [focusBeforeOverlay_ restoreFocusInWindow:window]; | 213 [focusBeforeOverlay_ restoreFocusInWindow:window]; |
| 236 focusBeforeOverlay_.reset(); | 214 focusBeforeOverlay_.reset(); |
| 237 | 215 |
| 238 [window display]; | 216 [window display]; |
| 239 [window removeChildWindow:overlayWindow_]; | 217 [window removeChildWindow:overlayWindow_]; |
| 240 | 218 |
| 241 [overlayWindow_ orderOut:nil]; | 219 [overlayWindow_ orderOut:nil]; |
| 242 [overlayWindow_ release]; | 220 [overlayWindow_ release]; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 return YES; | 353 return YES; |
| 376 } | 354 } |
| 377 | 355 |
| 378 // Tell the window that it needs to call performClose: as soon as the current | 356 // Tell the window that it needs to call performClose: as soon as the current |
| 379 // drag is complete. This prevents a window (and its overlay) from going away | 357 // drag is complete. This prevents a window (and its overlay) from going away |
| 380 // during a drag. | 358 // during a drag. |
| 381 - (void)deferPerformClose { | 359 - (void)deferPerformClose { |
| 382 closeDeferred_ = YES; | 360 closeDeferred_ = YES; |
| 383 } | 361 } |
| 384 | 362 |
| 385 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window | |
| 386 titleBar:(BOOL)hasTitleBar { | |
| 387 DCHECK(tabStripBackgroundView_); | |
| 388 NSView* rootView = [[window contentView] superview]; | |
| 389 | |
| 390 // In Material Design on 10.10 and higher, the top portion of the window is | |
| 391 // blurred using an NSVisualEffectView. | |
| 392 Class nsVisualEffectViewClass = NSClassFromString(@"NSVisualEffectView"); | |
| 393 if (!nsVisualEffectViewClass) { | |
| 394 DCHECK(!chrome::ShouldUseFullSizeContentView()); | |
| 395 [rootView addSubview:tabStripBackgroundView_ | |
| 396 positioned:NSWindowBelow | |
| 397 relativeTo:nil]; | |
| 398 return; | |
| 399 } | |
| 400 | |
| 401 [window setTitlebarAppearsTransparent:YES]; | |
| 402 | |
| 403 // If the window has a normal titlebar, then do not add NSVisualEffectView. | |
| 404 if (hasTitleBar) | |
| 405 return; | |
| 406 | |
| 407 visualEffectView_.reset( | |
| 408 [[nsVisualEffectViewClass alloc] | |
| 409 initWithFrame:[tabStripBackgroundView_ frame]]); | |
| 410 DCHECK(visualEffectView_); | |
| 411 | |
| 412 [visualEffectView_ setAutoresizingMask: | |
| 413 [tabStripBackgroundView_ autoresizingMask]]; | |
| 414 [tabStripBackgroundView_ | |
| 415 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | |
| 416 | |
| 417 // Set to a default appearance and material. If this is an Incognito window | |
| 418 // the material and vibrancy should be dark but this method gets called at | |
| 419 // the start of -[BrowserWindowController initWithBrowser:takeOwnership:], | |
| 420 // before the |browser_| ivar has been set. Without a browser object we | |
| 421 // can't check the window's theme. The final setup happens in | |
| 422 // -[TabStripView setController:], at which point we have access to the theme. | |
| 423 [visualEffectView_ setAppearance: | |
| 424 [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight]]; | |
| 425 [visualEffectView_ setMaterial:NSVisualEffectMaterialLight]; | |
| 426 [visualEffectView_ setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; | |
| 427 [visualEffectView_ setState:NSVisualEffectStateFollowsWindowActiveState]; | |
| 428 | |
| 429 if (chrome::ShouldUseFullSizeContentView()) { | |
| 430 [[window contentView] addSubview:visualEffectView_]; | |
| 431 } else { | |
| 432 [rootView addSubview:visualEffectView_ | |
| 433 positioned:NSWindowBelow | |
| 434 relativeTo:nil]; | |
| 435 } | |
| 436 | |
| 437 // Make the |tabStripBackgroundView_| a child of the NSVisualEffectView. | |
| 438 [tabStripBackgroundView_ setFrame:[visualEffectView_ bounds]]; | |
| 439 [visualEffectView_ addSubview:tabStripBackgroundView_]; | |
| 440 } | |
| 441 | |
| 442 // Called when the size of the window content area has changed. Override to | 363 // Called when the size of the window content area has changed. Override to |
| 443 // position specific views. Base class implementation does nothing. | 364 // position specific views. Base class implementation does nothing. |
| 444 - (void)layoutSubviews { | 365 - (void)layoutSubviews { |
| 445 NOTIMPLEMENTED(); | 366 NOTIMPLEMENTED(); |
| 446 } | 367 } |
| 447 | 368 |
| 448 - (void)windowWillEnterFullScreenNotification:(NSNotification*)notification { | |
| 449 [[visualEffectView_ animator] setAlphaValue:0.0]; | |
| 450 } | |
| 451 | |
| 452 - (void)windowWillExitFullScreenNotification:(NSNotification*)notification { | |
| 453 [[visualEffectView_ animator] setAlphaValue:1.0]; | |
| 454 } | |
| 455 | |
| 456 @end | 369 @end |
| OLD | NEW |