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

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_window_controller.mm

Issue 2430493002: [Mac] Fix rough-looking profile picker text, especially with a dark theme. (Closed)
Patch Set: Scopify! Created 3 years, 11 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
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_window_controller.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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(sdy): Remove once we no longer support 10.9 (-Wunguarded-availability).
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 30 matching lines...) Expand all
78 [window setAutorecalculatesKeyViewLoop:YES]; 64 [window setAutorecalculatesKeyViewLoop:YES];
79 65
80 if ((self = [super initWithWindow:window])) { 66 if ((self = [super initWithWindow:window])) {
81 [[self window] setDelegate:self]; 67 [[self window] setDelegate:self];
82 68
83 chromeContentView_.reset([[NSView alloc] 69 chromeContentView_.reset([[NSView alloc]
84 initWithFrame:NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight)]); 70 initWithFrame:NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight)]);
85 [chromeContentView_ 71 [chromeContentView_
86 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 72 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
87 [chromeContentView_ setWantsLayer:YES]; 73 [chromeContentView_ setWantsLayer:YES];
88 [[[self window] contentView] addSubview:chromeContentView_]; 74
75 NSView* contentView = self.window.contentView;
76 [contentView addSubview:chromeContentView_];
89 77
90 tabContentArea_.reset( 78 tabContentArea_.reset(
91 [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]); 79 [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]);
92 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | 80 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable |
93 NSViewHeightSizable]; 81 NSViewHeightSizable];
94 [chromeContentView_ addSubview:tabContentArea_]; 82 [chromeContentView_ addSubview:tabContentArea_];
95 83
96 // tabStripBackgroundView_ draws the theme image behind the tab strip area. 84 // tabStripBackgroundView_ draws the theme image behind the tab strip area.
97 // When making a tab dragging window (setUseOverlay:), this view stays in 85 // 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 86 // the parent window so that it can be translucent, while the tab strip view
99 // moves to the child window and stays opaque. 87 // moves to the child window and stays opaque.
100 NSView* windowView = [window contentView];
101 CGFloat paintHeight = [FramedBrowserWindow browserFrameViewPaintHeight]; 88 CGFloat paintHeight = [FramedBrowserWindow browserFrameViewPaintHeight];
102 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] 89 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc]
103 initWithFrame:NSMakeRect(0, NSMaxY([windowView bounds]) - paintHeight, 90 initWithFrame:NSMakeRect(0, NSMaxY([contentView bounds]) - paintHeight,
104 NSWidth([windowView bounds]), paintHeight)]); 91 NSWidth([contentView bounds]), paintHeight)]);
105 [tabStripBackgroundView_ 92 [tabStripBackgroundView_
106 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; 93 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
107 [self insertTabStripBackgroundViewIntoWindow:window titleBar:hasTitleBar];
108 94
109 tabStripView_.reset([[TabStripView alloc] 95 tabStripView_.reset([[TabStripView alloc]
110 initWithFrame:NSMakeRect( 96 initWithFrame:NSMakeRect(
111 0, 0, kDefaultWidth, chrome::kTabStripHeight)]); 97 0, 0, kDefaultWidth, chrome::kTabStripHeight)]);
112 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | 98 [tabStripView_ setAutoresizingMask:NSViewWidthSizable |
113 NSViewMinYMargin]; 99 NSViewMinYMargin];
114 if (hasTabStrip) 100 if (hasTabStrip)
115 [windowView addSubview:tabStripView_]; 101 [contentView addSubview:tabStripView_];
102
103 if ([window respondsToSelector:@selector(setTitlebarAppearsTransparent:)])
104 [window setTitlebarAppearsTransparent:YES];
116 105
117 if (chrome::ShouldUseFullSizeContentView()) { 106 if (chrome::ShouldUseFullSizeContentView()) {
118 // |windowWillEnterFullScreen:| and |windowWillExitFullScreen:| are 107 [contentView addSubview:tabStripBackgroundView_];
119 // already called because self is a delegate for the window. However this 108 } else {
120 // class is designed for subclassing and can not implement 109 NSView* rootView = contentView.superview;
121 // NSWindowDelegate methods (because subclasses can do so as well and they 110 [rootView addSubview:tabStripBackgroundView_
122 // should be able to). TODO(crbug.com/654656): Move |visualEffectView_| to 111 positioned:NSWindowBelow
123 // subclass. 112 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 } 113 }
135 } 114 }
136 return self; 115 return self;
137 } 116 }
138 117
139 - (void)dealloc { 118 - (void)dealloc {
140 [[NSNotificationCenter defaultCenter] removeObserver:self]; 119 [[NSNotificationCenter defaultCenter] removeObserver:self];
141 [super dealloc]; 120 [super dealloc];
142 } 121 }
143 122
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // followed by RenderWidgetHost::Blur(), which would result in an unexpected 182 // followed by RenderWidgetHost::Blur(), which would result in an unexpected
204 // loss of focus. 183 // loss of focus.
205 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]); 184 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]);
206 [window makeFirstResponder:nil]; 185 [window makeFirstResponder:nil];
207 186
208 // Move the original window's tab strip view and content view to the overlay 187 // 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 188 // window. The content view is added as a subview of the overlay window's
210 // content view (rather than using setContentView:) because the overlay 189 // content view (rather than using setContentView:) because the overlay
211 // window has a different content size (due to it being borderless). 190 // window has a different content size (due to it being borderless).
212 [[overlayWindow_ contentView] addSubview:[self tabStripView]]; 191 [[overlayWindow_ contentView] addSubview:[self tabStripView]];
213 [[self tabStripView] setInATabDraggingOverlayWindow:YES]; 192 [tabStripBackgroundView_ setInATabDraggingOverlayWindow:YES];
214 [[overlayWindow_ contentView] addSubview:originalContentView_]; 193 [[overlayWindow_ contentView] addSubview:originalContentView_];
215 194
216 [overlayWindow_ orderFront:nil]; 195 [overlayWindow_ orderFront:nil];
217 } else if (!useOverlay && overlayWindow_) { 196 } else if (!useOverlay && overlayWindow_) {
218 DCHECK(originalContentView_); 197 DCHECK(originalContentView_);
219 198
220 // Return the original window's tab strip view and content view to their 199 // 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 200 // 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 201 // 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 202 // view is set. It needs to be positioned below the avatar button to ensure
224 // that its overlay will not overlap it. 203 // that its overlay will not overlap it.
225 [[window contentView] addSubview:originalContentView_ 204 [[window contentView] addSubview:originalContentView_
226 positioned:NSWindowBelow 205 positioned:NSWindowBelow
227 relativeTo:nil]; 206 relativeTo:nil];
228 originalContentView_.frame = [[window contentView] bounds]; 207 originalContentView_.frame = [[window contentView] bounds];
229 [[window contentView] addSubview:[self tabStripView] 208 [[window contentView] addSubview:[self tabStripView]
230 positioned:NSWindowBelow 209 positioned:NSWindowBelow
231 relativeTo:[self avatarView]]; 210 relativeTo:[self avatarView]];
232 [[self tabStripView] setInATabDraggingOverlayWindow:NO]; 211 [tabStripBackgroundView_ setInATabDraggingOverlayWindow:NO];
233 [[window contentView] updateTrackingAreas]; 212 [[window contentView] updateTrackingAreas];
234 213
235 [focusBeforeOverlay_ restoreFocusInWindow:window]; 214 [focusBeforeOverlay_ restoreFocusInWindow:window];
236 focusBeforeOverlay_.reset(); 215 focusBeforeOverlay_.reset();
237 216
238 [window display]; 217 [window display];
239 [window removeChildWindow:overlayWindow_]; 218 [window removeChildWindow:overlayWindow_];
240 219
241 [overlayWindow_ orderOut:nil]; 220 [overlayWindow_ orderOut:nil];
242 [overlayWindow_ release]; 221 [overlayWindow_ release];
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 return YES; 354 return YES;
376 } 355 }
377 356
378 // Tell the window that it needs to call performClose: as soon as the current 357 // 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 358 // drag is complete. This prevents a window (and its overlay) from going away
380 // during a drag. 359 // during a drag.
381 - (void)deferPerformClose { 360 - (void)deferPerformClose {
382 closeDeferred_ = YES; 361 closeDeferred_ = YES;
383 } 362 }
384 363
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 364 // Called when the size of the window content area has changed. Override to
443 // position specific views. Base class implementation does nothing. 365 // position specific views. Base class implementation does nothing.
444 - (void)layoutSubviews { 366 - (void)layoutSubviews {
445 NOTIMPLEMENTED(); 367 NOTIMPLEMENTED();
446 } 368 }
447 369
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 370 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_window_controller.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698