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

Side by Side Diff: ui/native_theme/native_theme_mac.mm

Issue 2355433002: macviews: use system text selection color (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "ui/native_theme/native_theme_mac.h" 5 #include "ui/native_theme/native_theme_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 // static 121 // static
122 SkColor NativeThemeMac::ApplySystemControlTint(SkColor color) { 122 SkColor NativeThemeMac::ApplySystemControlTint(SkColor color) {
123 if ([NSColor currentControlTint] == NSGraphiteControlTint) 123 if ([NSColor currentControlTint] == NSGraphiteControlTint)
124 return ColorToGrayscale(color); 124 return ColorToGrayscale(color);
125 return color; 125 return color;
126 } 126 }
127 127
128 SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const { 128 SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const {
129 // Even with --secondary-ui-md, menus use the platform colors and styling, and 129 // Even with --secondary-ui-md, menus use the platform colors and styling, and
130 // Mac has a couple of specific color overrides. 130 // Mac has a couple of specific color overrides, documented below.
131 switch (color_id) { 131 switch (color_id) {
132 case kColorId_EnabledMenuItemForegroundColor: 132 case kColorId_EnabledMenuItemForegroundColor:
133 return NSSystemColorToSkColor([NSColor controlTextColor]); 133 return NSSystemColorToSkColor([NSColor controlTextColor]);
134 case kColorId_DisabledMenuItemForegroundColor: 134 case kColorId_DisabledMenuItemForegroundColor:
135 case kColorId_DisabledEmphasizedMenuItemForegroundColor: 135 case kColorId_DisabledEmphasizedMenuItemForegroundColor:
136 return NSSystemColorToSkColor([NSColor disabledControlTextColor]); 136 return NSSystemColorToSkColor([NSColor disabledControlTextColor]);
137 case kColorId_SelectedMenuItemForegroundColor: 137 case kColorId_SelectedMenuItemForegroundColor:
138 return NSSystemColorToSkColor([NSColor selectedMenuItemTextColor]); 138 return NSSystemColorToSkColor([NSColor selectedMenuItemTextColor]);
139 case kColorId_FocusedMenuItemBackgroundColor: 139 case kColorId_FocusedMenuItemBackgroundColor:
140 case kColorId_HoverMenuItemBackgroundColor: 140 case kColorId_HoverMenuItemBackgroundColor:
141 return NSSystemColorToSkColor([NSColor selectedMenuItemColor]); 141 return NSSystemColorToSkColor([NSColor selectedMenuItemColor]);
142 case kColorId_MenuBackgroundColor: 142 case kColorId_MenuBackgroundColor:
143 return kMenuPopupBackgroundColor; 143 return kMenuPopupBackgroundColor;
144 case kColorId_MenuSeparatorColor: 144 case kColorId_MenuSeparatorColor:
145 return base::mac::IsOS10_9() ? kMenuSeparatorColorMavericks 145 return base::mac::IsOS10_9() ? kMenuSeparatorColorMavericks
146 : kMenuSeparatorColor; 146 : kMenuSeparatorColor;
147 case kColorId_MenuBorderColor: 147 case kColorId_MenuBorderColor:
148 return kMenuBorderColor; 148 return kMenuBorderColor;
149 149
150 // Mac has a different "pressed button" styling because it doesn't use
151 // ripples.
150 case kColorId_ButtonPressedShade: 152 case kColorId_ButtonPressedShade:
151 return SkColorSetA(SK_ColorBLACK, 0x08); 153 return SkColorSetA(SK_ColorBLACK, 0x08);
154
155 // There's a system setting General > Highlight color which sets the
156 // background color for text selections. We honor that setting.
157 // TODO(ellyjones): Listen for NSSystemColorsDidChangeNotification somewhere
158 // and propagate it to the View hierarchy.
159 case kColorId_TextfieldSelectionBackgroundFocused:
Evan Stade 2016/09/19 16:03:49 Is it not possible to change other textfield color
160 return NSSystemColorToSkColor([NSColor selectedTextBackgroundColor]);
152 default: 161 default:
153 break; 162 break;
154 } 163 }
155 164
156 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) 165 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
157 return ApplySystemControlTint(GetAuraColor(color_id, this)); 166 return ApplySystemControlTint(GetAuraColor(color_id, this));
158 167
159 // TODO(tapted): Add caching for these, and listen for 168 // TODO(tapted): Add caching for these, and listen for
160 // NSSystemColorsDidChangeNotification. 169 // NSSystemColorsDidChangeNotification.
161 switch (color_id) { 170 switch (color_id) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 214
206 // Text fields. 215 // Text fields.
207 case kColorId_TextfieldDefaultColor: 216 case kColorId_TextfieldDefaultColor:
208 case kColorId_TextfieldReadOnlyColor: 217 case kColorId_TextfieldReadOnlyColor:
209 return NSSystemColorToSkColor([NSColor textColor]); 218 return NSSystemColorToSkColor([NSColor textColor]);
210 case kColorId_TextfieldDefaultBackground: 219 case kColorId_TextfieldDefaultBackground:
211 case kColorId_TextfieldReadOnlyBackground: 220 case kColorId_TextfieldReadOnlyBackground:
212 return NSSystemColorToSkColor([NSColor textBackgroundColor]); 221 return NSSystemColorToSkColor([NSColor textBackgroundColor]);
213 case kColorId_TextfieldSelectionColor: 222 case kColorId_TextfieldSelectionColor:
214 return NSSystemColorToSkColor([NSColor selectedTextColor]); 223 return NSSystemColorToSkColor([NSColor selectedTextColor]);
215 case kColorId_TextfieldSelectionBackgroundFocused:
216 return NSSystemColorToSkColor([NSColor selectedTextBackgroundColor]);
217 224
218 // Trees/Tables. For focused text, use the alternate* versions, which 225 // Trees/Tables. For focused text, use the alternate* versions, which
219 // NSColor documents as "the table and list view equivalent to the 226 // NSColor documents as "the table and list view equivalent to the
220 // selectedControlTextColor". 227 // selectedControlTextColor".
221 case kColorId_TreeBackground: 228 case kColorId_TreeBackground:
222 case kColorId_TableBackground: 229 case kColorId_TableBackground:
223 return NSSystemColorToSkColor([NSColor controlBackgroundColor]); 230 return NSSystemColorToSkColor([NSColor controlBackgroundColor]);
224 case kColorId_TreeText: 231 case kColorId_TreeText:
225 case kColorId_TableText: 232 case kColorId_TableText:
226 case kColorId_TableSelectedTextUnfocused: 233 case kColorId_TableSelectedTextUnfocused:
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 canvas->drawDRRect(outer_shape, shape, paint); 436 canvas->drawDRRect(outer_shape, shape, paint);
430 } 437 }
431 438
432 NativeThemeMac::NativeThemeMac() { 439 NativeThemeMac::NativeThemeMac() {
433 } 440 }
434 441
435 NativeThemeMac::~NativeThemeMac() { 442 NativeThemeMac::~NativeThemeMac() {
436 } 443 }
437 444
438 } // namespace ui 445 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698