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_strip_view.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
6 | 6 |
7 #include <cmath> // floor | 7 #include <cmath> // floor |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 // Draw the bottom edge of the tab strip. Each tab is responsible for mimicking | 56 // Draw the bottom edge of the tab strip. Each tab is responsible for mimicking |
57 // this bottom border, unless it's the selected tab. | 57 // this bottom border, unless it's the selected tab. |
58 - (void)drawBottomEdge:(NSRect)dirtyRect { | 58 - (void)drawBottomEdge:(NSRect)dirtyRect { |
59 NSWindow* window = [self window]; | 59 NSWindow* window = [self window]; |
60 const ui::ThemeProvider* themeProvider = [window themeProvider]; | 60 const ui::ThemeProvider* themeProvider = [window themeProvider]; |
61 if (!themeProvider) | 61 if (!themeProvider) |
62 return; | 62 return; |
63 | 63 |
64 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
65 // First draw the toolbar bitmap, so that theme colors can shine through. | |
66 NSRect backgroundRect = [self bounds]; | |
67 backgroundRect.size.height = 2 * [self cr_lineWidth]; | |
68 if (NSIntersectsRect(backgroundRect, dirtyRect)) | |
69 [self drawBackground:backgroundRect]; | |
70 | |
71 // Draw the border bitmap, which is partially transparent. | |
72 NSImage* image = themeProvider->GetNSImageNamed(IDR_TOOLBAR_SHADE_TOP); | |
73 NSRect borderRect = backgroundRect; | |
74 borderRect.size.height = [image size].height; | |
75 if (NSIntersectsRect(borderRect, dirtyRect)) { | |
76 BOOL focused = [window isMainWindow]; | |
77 NSDrawThreePartImage(borderRect, nil, image, nil, /*vertical=*/ NO, | |
78 NSCompositeSourceOver, | |
79 focused ? 1.0 : tabs::kImageNoFocusAlpha, | |
80 /*flipped=*/ NO); | |
81 } | |
82 | |
83 return; | |
84 } | |
85 | |
86 NSColor* strokeColor; | 64 NSColor* strokeColor; |
87 if (themeProvider->HasCustomImage(IDR_THEME_TOOLBAR) || | 65 if (themeProvider->HasCustomImage(IDR_THEME_TOOLBAR) || |
88 themeProvider->HasCustomColor(ThemeProperties::COLOR_TOOLBAR)) { | 66 themeProvider->HasCustomColor(ThemeProperties::COLOR_TOOLBAR)) { |
89 // First draw the toolbar bitmap, so that theme colors can shine through. | 67 // First draw the toolbar bitmap, so that theme colors can shine through. |
90 NSRect backgroundRect = [self bounds]; | 68 NSRect backgroundRect = [self bounds]; |
91 backgroundRect.size.height = [self cr_lineWidth]; | 69 backgroundRect.size.height = [self cr_lineWidth]; |
92 if (NSIntersectsRect(backgroundRect, dirtyRect)) { | 70 if (NSIntersectsRect(backgroundRect, dirtyRect)) { |
93 [self drawBackground:backgroundRect]; | 71 [self drawBackground:backgroundRect]; |
94 } | 72 } |
95 | 73 |
(...skipping 19 matching lines...) Expand all Loading... |
115 NSRect borderRect = NSMakeRect(0.0, 0.0, self.bounds.size.width, | 93 NSRect borderRect = NSMakeRect(0.0, 0.0, self.bounds.size.width, |
116 [self cr_lineWidth]); | 94 [self cr_lineWidth]); |
117 NSRectFillUsingOperation(NSIntersectionRect(dirtyRect, borderRect), | 95 NSRectFillUsingOperation(NSIntersectionRect(dirtyRect, borderRect), |
118 NSCompositeSourceOver); | 96 NSCompositeSourceOver); |
119 } | 97 } |
120 | 98 |
121 - (void)drawRect:(NSRect)dirtyRect { | 99 - (void)drawRect:(NSRect)dirtyRect { |
122 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | 100 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; |
123 bool hasCustomThemeImage = themeProvider && | 101 bool hasCustomThemeImage = themeProvider && |
124 themeProvider->HasCustomImage(IDR_THEME_FRAME); | 102 themeProvider->HasCustomImage(IDR_THEME_FRAME); |
125 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | |
126 BOOL supportsVibrancy = [self visualEffectView] != nil; | 103 BOOL supportsVibrancy = [self visualEffectView] != nil; |
127 BOOL isMainWindow = [[self window] isMainWindow]; | 104 BOOL isMainWindow = [[self window] isMainWindow]; |
128 | 105 |
129 // If in Material Design mode, decrease the tabstrip background's translucency | 106 // If in Material Design mode, decrease the tabstrip background's translucency |
130 // by overlaying it with a partially-transparent gray (but only if not themed, | 107 // by overlaying it with a partially-transparent gray (but only if not themed, |
131 // and not being used to drag tabs between browser windows). The gray is | 108 // and not being used to drag tabs between browser windows). The gray is |
132 // somewhat opaque for Incognito mode, very opaque for non-Incognito mode, and | 109 // somewhat opaque for Incognito mode, very opaque for non-Incognito mode, and |
133 // completely opaque when the window is not active. | 110 // completely opaque when the window is not active. |
134 if (themeProvider && !hasCustomThemeImage && isModeMaterial && | 111 if (themeProvider && !hasCustomThemeImage && !inATabDraggingOverlayWindow_) { |
135 !inATabDraggingOverlayWindow_) { | |
136 NSColor* theColor = nil; | 112 NSColor* theColor = nil; |
137 if (isMainWindow) { | 113 if (isMainWindow) { |
138 if (supportsVibrancy && | 114 if (supportsVibrancy && |
139 !themeProvider->HasCustomColor(ThemeProperties::COLOR_FRAME)) { | 115 !themeProvider->HasCustomColor(ThemeProperties::COLOR_FRAME)) { |
140 theColor = themeProvider->GetNSColor( | 116 theColor = themeProvider->GetNSColor( |
141 ThemeProperties::COLOR_FRAME_VIBRANCY_OVERLAY); | 117 ThemeProperties::COLOR_FRAME_VIBRANCY_OVERLAY); |
142 } else if (!supportsVibrancy && themeProvider->InIncognitoMode()) { | 118 } else if (!supportsVibrancy && themeProvider->InIncognitoMode()) { |
143 theColor = [NSColor colorWithSRGBRed:20 / 255. | 119 theColor = [NSColor colorWithSRGBRed:20 / 255. |
144 green:22 / 255. | 120 green:22 / 255. |
145 blue:24 / 255. | 121 blue:24 / 255. |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 340 |
365 - (NewTabButton*)getNewTabButton { | 341 - (NewTabButton*)getNewTabButton { |
366 return newTabButton_; | 342 return newTabButton_; |
367 } | 343 } |
368 | 344 |
369 - (void)setNewTabButton:(NewTabButton*)button { | 345 - (void)setNewTabButton:(NewTabButton*)button { |
370 newTabButton_.reset([button retain]); | 346 newTabButton_.reset([button retain]); |
371 } | 347 } |
372 | 348 |
373 - (NSVisualEffectView*)visualEffectView { | 349 - (NSVisualEffectView*)visualEffectView { |
374 // NSVisualEffectView is only used in Material Design, and only available on | 350 // NSVisualEffectView is only available on OS X 10.10 and higher. |
375 // OS X 10.10 and higher. | 351 if (!base::mac::IsAtLeastOS10_10()) |
376 if (!ui::MaterialDesignController::IsModeMaterial() || | |
377 !base::mac::IsAtLeastOS10_10()) { | |
378 return nil; | 352 return nil; |
379 } | |
380 | 353 |
381 NSView* rootView = [[[self window] contentView] superview]; | 354 NSView* rootView = [[[self window] contentView] superview]; |
382 Class nsVisualEffectViewClass = NSClassFromString(@"NSVisualEffectView"); | 355 Class nsVisualEffectViewClass = NSClassFromString(@"NSVisualEffectView"); |
383 DCHECK(nsVisualEffectViewClass); | 356 DCHECK(nsVisualEffectViewClass); |
384 for (NSView* view in [rootView subviews]) { | 357 for (NSView* view in [rootView subviews]) { |
385 if ([view isKindOfClass:nsVisualEffectViewClass]) { | 358 if ([view isKindOfClass:nsVisualEffectViewClass]) { |
386 return base::mac::ObjCCast<NSVisualEffectView>(view); | 359 return base::mac::ObjCCast<NSVisualEffectView>(view); |
387 } | 360 } |
388 } | 361 } |
389 return nil; | 362 return nil; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 if (visualEffectsDisabledForFullscreen_ || | 417 if (visualEffectsDisabledForFullscreen_ || |
445 themeProvider->HasCustomImage(IDR_THEME_FRAME) || | 418 themeProvider->HasCustomImage(IDR_THEME_FRAME) || |
446 themeProvider->HasCustomColor(ThemeProperties::COLOR_FRAME)) { | 419 themeProvider->HasCustomColor(ThemeProperties::COLOR_FRAME)) { |
447 [visualEffectView setState:NSVisualEffectStateInactive]; | 420 [visualEffectView setState:NSVisualEffectStateInactive]; |
448 } else { | 421 } else { |
449 [visualEffectView setState:NSVisualEffectStateFollowsWindowActiveState]; | 422 [visualEffectView setState:NSVisualEffectStateFollowsWindowActiveState]; |
450 } | 423 } |
451 } | 424 } |
452 | 425 |
453 @end | 426 @end |
OLD | NEW |