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

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

Issue 2719993004: cocoa: draw tabstrip stroke in white in increase-contrast incognito (Closed)
Patch Set: Created 3 years, 9 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_strip_view.mm ('k') | no next file » | 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_view.h" 5 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/sdk_forward_declarations.h" 9 #include "base/mac/sdk_forward_declarations.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 + (void)drawTabLeftEdgeImage; 73 + (void)drawTabLeftEdgeImage;
74 + (void)drawTabMiddleEdgeImage; 74 + (void)drawTabMiddleEdgeImage;
75 + (void)drawTabRightEdgeImage; 75 + (void)drawTabRightEdgeImage;
76 + (void)setTabEdgeStrokeColor; 76 + (void)setTabEdgeStrokeColor;
77 @end 77 @end
78 78
79 @interface TabHeavyImageMaker : TabImageMaker 79 @interface TabHeavyImageMaker : TabImageMaker
80 + (void)setTabEdgeStrokeColor; 80 + (void)setTabEdgeStrokeColor;
81 @end 81 @end
82 82
83 @interface TabHeavyInvertedImageMaker : TabImageMaker
84 + (void)setTabEdgeStrokeColor;
85 @end
86
83 @interface TabController(Private) 87 @interface TabController(Private)
84 // The TabView's close button. 88 // The TabView's close button.
85 - (HoverCloseButton*)closeButton; 89 - (HoverCloseButton*)closeButton;
86 @end 90 @end
87 91
88 extern NSString* const _Nonnull NSWorkspaceAccessibilityDisplayOptionsDidChangeN otification; 92 extern NSString* const _Nonnull NSWorkspaceAccessibilityDisplayOptionsDidChangeN otification;
89 93
90 namespace { 94 namespace {
91 95
92 enum StrokeType { 96 enum StrokeType {
93 STROKE_NORMAL, 97 STROKE_NORMAL,
94 STROKE_HEAVY, 98 STROKE_HEAVY,
99 STROKE_HEAVY_INVERTED,
95 }; 100 };
96 101
102 Class drawingClassForStrokeType(StrokeType stroke_type) {
103 switch (stroke_type) {
104 case STROKE_NORMAL:
105 return [TabImageMaker class];
106 case STROKE_HEAVY:
107 return [TabHeavyImageMaker class];
108 case STROKE_HEAVY_INVERTED:
109 return [TabHeavyInvertedImageMaker class];
110 }
111 }
112
97 NSImage* imageForResourceID(int resource_id, StrokeType stroke_type) { 113 NSImage* imageForResourceID(int resource_id, StrokeType stroke_type) {
98 CGFloat imageWidth = resource_id == IDR_TAB_ACTIVE_CENTER ? 1 : 18; 114 CGFloat imageWidth = resource_id == IDR_TAB_ACTIVE_CENTER ? 1 : 18;
99 SEL theSelector = 0; 115 SEL theSelector = 0;
100 switch (resource_id) { 116 switch (resource_id) {
101 case IDR_TAB_ACTIVE_LEFT: 117 case IDR_TAB_ACTIVE_LEFT:
102 theSelector = @selector(drawTabLeftEdgeImage); 118 theSelector = @selector(drawTabLeftEdgeImage);
103 break; 119 break;
104 120
105 case IDR_TAB_ACTIVE_CENTER: 121 case IDR_TAB_ACTIVE_CENTER:
106 theSelector = @selector(drawTabMiddleEdgeImage); 122 theSelector = @selector(drawTabMiddleEdgeImage);
107 break; 123 break;
108 124
109 case IDR_TAB_ACTIVE_RIGHT: 125 case IDR_TAB_ACTIVE_RIGHT:
110 theSelector = @selector(drawTabRightEdgeImage); 126 theSelector = @selector(drawTabRightEdgeImage);
111 break; 127 break;
112 128
113 case IDR_TAB_ALPHA_LEFT: 129 case IDR_TAB_ALPHA_LEFT:
114 theSelector = @selector(drawTabLeftMaskImage); 130 theSelector = @selector(drawTabLeftMaskImage);
115 break; 131 break;
116 132
117 case IDR_TAB_ALPHA_RIGHT: 133 case IDR_TAB_ALPHA_RIGHT:
118 theSelector = @selector(drawTabRightMaskImage); 134 theSelector = @selector(drawTabRightMaskImage);
119 break; 135 break;
120 } 136 }
121 DCHECK(theSelector); 137 DCHECK(theSelector);
122 138
123 Class makerClass = stroke_type == STROKE_HEAVY ? [TabHeavyImageMaker class] 139 Class makerClass = drawingClassForStrokeType(stroke_type);
124 : [TabImageMaker class];
125 base::scoped_nsobject<NSCustomImageRep> imageRep([[NSCustomImageRep alloc] 140 base::scoped_nsobject<NSCustomImageRep> imageRep([[NSCustomImageRep alloc]
126 initWithDrawSelector:theSelector 141 initWithDrawSelector:theSelector
127 delegate:makerClass]); 142 delegate:makerClass]);
128 143
129 NSImage* newTabButtonImage = 144 NSImage* newTabButtonImage =
130 [[[NSImage alloc] initWithSize:NSMakeSize(imageWidth, 29)] autorelease]; 145 [[[NSImage alloc] initWithSize:NSMakeSize(imageWidth, 29)] autorelease];
131 [newTabButtonImage setCacheMode:NSImageCacheAlways]; 146 [newTabButtonImage setCacheMode:NSImageCacheAlways];
132 [newTabButtonImage addRepresentation:imageRep]; 147 [newTabButtonImage addRepresentation:imageRep];
133 148
134 return newTabButtonImage; 149 return newTabButtonImage;
(...skipping 12 matching lines...) Expand all
147 CR_DEFINE_STATIC_LOCAL( 162 CR_DEFINE_STATIC_LOCAL(
148 ui::ThreePartImage, stroke, 163 ui::ThreePartImage, stroke,
149 (imageForResourceID(IDR_TAB_ACTIVE_LEFT, STROKE_NORMAL), 164 (imageForResourceID(IDR_TAB_ACTIVE_LEFT, STROKE_NORMAL),
150 imageForResourceID(IDR_TAB_ACTIVE_CENTER, STROKE_NORMAL), 165 imageForResourceID(IDR_TAB_ACTIVE_CENTER, STROKE_NORMAL),
151 imageForResourceID(IDR_TAB_ACTIVE_RIGHT, STROKE_NORMAL))); 166 imageForResourceID(IDR_TAB_ACTIVE_RIGHT, STROKE_NORMAL)));
152 CR_DEFINE_STATIC_LOCAL( 167 CR_DEFINE_STATIC_LOCAL(
153 ui::ThreePartImage, heavyStroke, 168 ui::ThreePartImage, heavyStroke,
154 (imageForResourceID(IDR_TAB_ACTIVE_LEFT, STROKE_HEAVY), 169 (imageForResourceID(IDR_TAB_ACTIVE_LEFT, STROKE_HEAVY),
155 imageForResourceID(IDR_TAB_ACTIVE_CENTER, STROKE_HEAVY), 170 imageForResourceID(IDR_TAB_ACTIVE_CENTER, STROKE_HEAVY),
156 imageForResourceID(IDR_TAB_ACTIVE_RIGHT, STROKE_HEAVY))); 171 imageForResourceID(IDR_TAB_ACTIVE_RIGHT, STROKE_HEAVY)));
172 CR_DEFINE_STATIC_LOCAL(
173 ui::ThreePartImage, heavyInvertedStroke,
174 (imageForResourceID(IDR_TAB_ACTIVE_LEFT, STROKE_HEAVY_INVERTED),
175 imageForResourceID(IDR_TAB_ACTIVE_CENTER, STROKE_HEAVY_INVERTED),
176 imageForResourceID(IDR_TAB_ACTIVE_RIGHT, STROKE_HEAVY_INVERTED)));
157 177
158 return stroke_type == STROKE_HEAVY ? heavyStroke : stroke; 178 switch (stroke_type) {
179 case STROKE_NORMAL:
180 return stroke;
181 case STROKE_HEAVY:
182 return heavyStroke;
183 case STROKE_HEAVY_INVERTED:
184 return heavyInvertedStroke;
185 }
159 } 186 }
160 187
161 CGFloat LineWidthFromContext(CGContextRef context) { 188 CGFloat LineWidthFromContext(CGContextRef context) {
162 CGRect unitRect = CGRectMake(0.0, 0.0, 1.0, 1.0); 189 CGRect unitRect = CGRectMake(0.0, 0.0, 1.0, 1.0);
163 CGRect deviceRect = CGContextConvertRectToDeviceSpace(context, unitRect); 190 CGRect deviceRect = CGContextConvertRectToDeviceSpace(context, unitRect);
164 return 1.0 / deviceRect.size.height; 191 return 1.0 / deviceRect.size.height;
165 } 192 }
166 193
167 } // namespace 194 } // namespace
168 195
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 - (void)drawStroke:(NSRect)dirtyRect { 541 - (void)drawStroke:(NSRect)dirtyRect {
515 // In MD, the tab stroke is always opaque. 542 // In MD, the tab stroke is always opaque.
516 CGFloat alpha = 1; 543 CGFloat alpha = 1;
517 NSRect bounds = [self bounds]; 544 NSRect bounds = [self bounds];
518 // In Material Design the tab strip separator is always 1 pixel high - 545 // In Material Design the tab strip separator is always 1 pixel high -
519 // add a clip rect to avoid drawing the tab edge over it. 546 // add a clip rect to avoid drawing the tab edge over it.
520 NSRect clipRect = bounds; 547 NSRect clipRect = bounds;
521 clipRect.origin.y += [self cr_lineWidth]; 548 clipRect.origin.y += [self cr_lineWidth];
522 NSRectClip(clipRect); 549 NSRectClip(clipRect);
523 const ui::ThemeProvider* provider = [[self window] themeProvider]; 550 const ui::ThemeProvider* provider = [[self window] themeProvider];
524 GetStrokeImage(state_ == NSOnState, 551 StrokeType stroke_type = STROKE_NORMAL;
525 provider && provider->ShouldIncreaseContrast() 552 if (provider && provider->ShouldIncreaseContrast()) {
526 ? STROKE_HEAVY 553 stroke_type =
527 : STROKE_NORMAL) 554 [[self window] hasDarkTheme] ? STROKE_HEAVY_INVERTED : STROKE_HEAVY;
555 }
556 GetStrokeImage(state_ == NSOnState, stroke_type)
528 .DrawInRect(bounds, NSCompositeSourceOver, alpha); 557 .DrawInRect(bounds, NSCompositeSourceOver, alpha);
529 } 558 }
530 559
531 - (void)drawRect:(NSRect)dirtyRect { 560 - (void)drawRect:(NSRect)dirtyRect {
532 [self drawFill:dirtyRect]; 561 [self drawFill:dirtyRect];
533 [self drawStroke:dirtyRect]; 562 [self drawStroke:dirtyRect];
534 563
535 // We draw the title string directly instead of using a NSTextField subview. 564 // We draw the title string directly instead of using a NSTextField subview.
536 // This is so that we can get font smoothing to work on earlier OS, and even 565 // This is so that we can get font smoothing to work on earlier OS, and even
537 // when the tab background is a pattern image (when using themes). 566 // when the tab background is a pattern image (when using themes).
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 1054
1026 // For "Increase Contrast" mode, use flat black instead of semitransparent black 1055 // For "Increase Contrast" mode, use flat black instead of semitransparent black
1027 // for the tab edge stroke. 1056 // for the tab edge stroke.
1028 + (void)setTabEdgeStrokeColor { 1057 + (void)setTabEdgeStrokeColor {
1029 static NSColor* heavyStrokeColor = 1058 static NSColor* heavyStrokeColor =
1030 [skia::SkColorToSRGBNSColor(SK_ColorBLACK) retain]; 1059 [skia::SkColorToSRGBNSColor(SK_ColorBLACK) retain];
1031 [heavyStrokeColor set]; 1060 [heavyStrokeColor set];
1032 } 1061 }
1033 1062
1034 @end 1063 @end
1064
1065 @implementation TabHeavyInvertedImageMaker
1066
1067 // For "Increase Contrast" mode, when using a dark theme, the stroke should be
1068 // drawn in flat white instead of flat black. There is normally no need to
1069 // special-case this since the lower-contrast border is equally visible in light
1070 // or dark themes.
1071 + (void)setTabEdgeStrokeColor {
1072 static NSColor* heavyStrokeColor =
1073 [skia::SkColorToSRGBNSColor(SK_ColorWHITE) retain];
1074 [heavyStrokeColor set];
1075 }
1076
1077 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_strip_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698