Skip to content

Commit

Permalink
[Mac][Material Design] Bring Omnibox stroke and MD colors up to spec.
Browse files Browse the repository at this point in the history
This cl changes the Omnibox's stroke in Incognito mode to match the
recent spec revisions made by sgabriel@.

Changing to the new spec also required switching other MD colors to the
sRGB color space so that everything matched. The plan was to switch to
sRGB (which is correct - the calibrated space is not) eventually, but
to get the Omnibox to look right, now is the time.

[email protected],[email protected]
BUG=613749

Review-Url: https://codereview.chromium.org/2013183003
Cr-Commit-Position: refs/heads/master@{#396986}
  • Loading branch information
shrike authored and Commit bot committed Jun 1, 2016
1 parent b8137c4 commit 7a7f2e3
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 157 deletions.
10 changes: 8 additions & 2 deletions chrome/browser/themes/theme_service_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ void HSLToHSB(const color_utils::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) {
DCHECK(CalledOnValidThread());

int original_id = id;
if (ui::MaterialDesignController::IsModeMaterial() && incognito) {
const bool is_mode_material = ui::MaterialDesignController::IsModeMaterial();
if (is_mode_material && incognito) {
id += kMaterialDesignIdOffset;
}

Expand All @@ -193,7 +194,12 @@ void HSLToHSB(const color_utils::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) {
return nscolor_iter->second;

SkColor sk_color = GetColor(original_id, incognito);
NSColor* color = skia::SkColorToCalibratedNSColor(sk_color);
NSColor* color = nil;
if (is_mode_material) {
color = skia::SkColorToSRGBNSColor(sk_color);
} else {
color = skia::SkColorToCalibratedNSColor(sk_color);
}

// We loaded successfully. Cache the color.
if (color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,10 @@ class AutocompleteTextFieldObserver {

base::scoped_nsobject<NSString> suggestText_;
base::scoped_nsobject<NSColor> suggestColor_;

base::scoped_nsobject<NSView> shadowView_;
}

@property(nonatomic) AutocompleteTextFieldObserver* observer;

// Returns the color of the shadow that's drawn under the AutocompleteTextField
// in Incognito mode in Material Design.
+ (NSColor*)shadowColor;

// Convenience method to return the cell, casted appropriately.
- (AutocompleteTextFieldCell*)cell;

Expand Down
86 changes: 3 additions & 83 deletions chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,79 +22,9 @@

namespace {
const CGFloat kAnimationDuration = 0.2;
const CGFloat kShadowInset = 3;

}

// A view that draws a 1px shadow line beneath the autocomplete textfield.
@interface AutocompleteTextFieldShadowView : NSView {
@private
AutocompleteTextField* textField_; // Weak. Owns this.
}
// This is the designated initializer for AutocompleteTextFieldShadowView.
- (instancetype)initWithTextField:(AutocompleteTextField*)aTextField;
@end

@interface AutocompleteTextFieldShadowView(Private)
// Adjusts the shadow view's position whenever its AutocompleteTextField changes
// its frame.
- (void)adjustFrame;
@end

@implementation AutocompleteTextFieldShadowView

- (instancetype)initWithTextField:(AutocompleteTextField*)aTextField {
if ((self = [self initWithFrame:NSZeroRect])) {
textField_ = aTextField;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(adjustFrame)
name:NSViewFrameDidChangeNotification
object:textField_];
}
return self;
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}

- (void)adjustFrame {
if (![self window]) {
return;
}
// Make the shadow view 1pt tall and slightly inset from the edges of the
// autocomplete textfield.
NSRect frame = [textField_ frame];
frame.origin.x += kShadowInset;
frame.size.width -= kShadowInset * 2;
frame.origin.y -= 1;
frame.size.height = 1;
[self setFrame:frame];
}

- (void)viewDidMoveToWindow {
[self adjustFrame];
}

- (void)drawRect:(NSRect)rect {
// Don't draw anything on a Retina display because on Retina there's room
// for the shadow just beneath the autocomplete textfield path stroke. Why
// even add this view? If the user drags the Incognito window between Retina
// and non-Retina screens there would have to be logic to add and remove the
// view. It's easier just to always add it for Incognito mode and draw
// nothing into it.
if (![[self window] inIncognitoModeWithSystemTheme] ||
[self cr_lineWidth] < 1) {
return;
}
[[AutocompleteTextField shadowColor] set];
NSRectFillUsingOperation(rect, NSCompositeSourceOver);
}

@end

@implementation AutocompleteTextField

@synthesize observer = observer_;
Expand All @@ -103,13 +33,8 @@ + (Class)cellClass {
return [AutocompleteTextFieldCell class];
}

+ (NSColor*)shadowColor {
return [NSColor colorWithGenericGamma22White:0 alpha:0.14];
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[shadowView_ removeFromSuperview];
[super dealloc];
}

Expand Down Expand Up @@ -461,16 +386,16 @@ - (void)updateColorsToMatchTheme {
// Invert the textfield's colors when Material Design and Incognito and not
// a custom theme.
bool inDarkMode = [[self window] inIncognitoModeWithSystemTheme];
const CGFloat kDarkModeGray = 97 / 255.;
[self setBackgroundColor:
inDarkMode ? [NSColor colorWithGenericGamma22White:115 / 255. alpha:1]
inDarkMode ? [NSColor colorWithGenericGamma22White:kDarkModeGray
alpha:1]
: [NSColor whiteColor]];
[self setTextColor:OmniboxViewMac::BaseTextColor(inDarkMode)];
}

- (void)viewDidMoveToWindow {
if (![self window]) {
[shadowView_ removeFromSuperview];
shadowView_.reset();
return;
}

Expand All @@ -481,11 +406,6 @@ - (void)viewDidMoveToWindow {
[BrowserWindowController browserWindowControllerForView:self];
[[browserWindowController toolbarController] locationBarWasAddedToWindow];

// Add a 1px shadow below the autocomplete textfield.
shadowView_.reset(
[[AutocompleteTextFieldShadowView alloc] initWithTextField:self]);
[[self superview] addSubview:shadowView_];

[self updateColorsToMatchTheme];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,56 +351,13 @@ - (void)drawWithFrame:(NSRect)frame inView:(NSView*)controlView {
// Draw the border.
if (isModeMaterial) {
if (!inDarkMode) {
[[NSColor colorWithCalibratedWhite:168 / 255. alpha:1] set];
[path stroke];
const CGFloat kNormalStrokeGray = 168 / 255.;
[[NSColor colorWithCalibratedWhite:kNormalStrokeGray alpha:1] set];
} else {
// In dark mode the top, middle, and bottom portions of the stroke are
// drawn in different colors.
{
gfx::ScopedNSGraphicsContextSaveGState saveState;
[[NSColor colorWithCalibratedWhite:52 / 255. alpha:1] set];
[NSBezierPath clipRect:NSMakeRect(NSMinX(frame), NSMaxY(frame) - 2,
NSWidth(frame), 2)];
[path stroke];
}
{
gfx::ScopedNSGraphicsContextSaveGState saveState;
[[NSColor colorWithCalibratedWhite:61 / 255. alpha:1] set];
[NSBezierPath clipRect:NSMakeRect(NSMinX(frame), NSMinY(frame) + 3,
NSWidth(frame), NSHeight(frame) - 5)];
[path stroke];
}
{
gfx::ScopedNSGraphicsContextSaveGState saveState;
[[NSColor colorWithCalibratedWhite:71 / 255. alpha:1] set];
[NSBezierPath clipRect:NSMakeRect(NSMinX(frame), NSMinY(frame),
NSWidth(frame), 3)];
[path stroke];
}

// Draw a highlight beneath the top edge, and a shadow beneath the bottom
// edge when on a Retina screen.
{
gfx::ScopedNSGraphicsContextSaveGState saveState;
[NSBezierPath setDefaultLineWidth:singlePixelLineWidth_];

[[NSColor colorWithCalibratedWhite:120 / 255. alpha:1] set];
NSPoint origin = NSMakePoint(NSMinX(pathRect) + 3,
NSMinY(pathRect) + singlePixelLineWidth_);
NSPoint destination =
NSMakePoint(NSMaxX(pathRect) - 3,
NSMinY(pathRect) + singlePixelLineWidth_);
[NSBezierPath strokeLineFromPoint:origin
toPoint:destination];

if (singlePixelLineWidth_ < 1) {
origin.y = destination.y = NSMaxY(pathRect) + singlePixelLineWidth_;
[[AutocompleteTextField shadowColor] set];
[NSBezierPath strokeLineFromPoint:origin
toPoint:destination];
}
}
const CGFloat k30PercentAlpha = 0.3;
[[NSColor colorWithCalibratedWhite:0 alpha:k30PercentAlpha] set];
}
[path stroke];
} else {
ui::DrawNinePartImage(frame,
isPopupMode_ ? kPopupBorderImageIds
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/cocoa/location_bar/bubble_decoration.mm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ CGFloat DividerPadding() {

NSColor* text_color =
in_dark_mode
? skia::SkColorToCalibratedNSColor(kMaterialDarkModeTextColor)
? skia::SkColorToSRGBNSColor(kMaterialDarkModeTextColor)
: GetBackgroundBorderColor();
SetTextColor(text_color);
}
Expand Down
14 changes: 9 additions & 5 deletions chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,15 @@ new ManagePasswordsDecoration(command_updater, this)),
} else {
security_state::SecurityStateModel::SecurityLevel security_level =
GetToolbarModel()->GetSecurityLevel(false);
vector_icon_color =
(security_level == security_state::SecurityStateModel::NONE)
? OmniboxViewMac::BaseTextColorSkia(in_dark_mode)
: skia::NSDeviceColorToSkColor(OmniboxViewMac::GetSecureTextColor(
security_level, in_dark_mode));
if (security_level == security_state::SecurityStateModel::NONE) {
vector_icon_color = OmniboxViewMac::BaseTextColorSkia(in_dark_mode);
} else {
NSColor* sRGBColor =
OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode);
NSColor* deviceColor =
[sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
SelectedKeywordDecoration::~SelectedKeywordDecoration() {}

NSColor* SelectedKeywordDecoration::GetBackgroundBorderColor() {
return skia::SkColorToCalibratedNSColor(gfx::kGoogleBlue700);
if (!ui::MaterialDesignController::IsModeMaterial()) {
return skia::SkColorToCalibratedNSColor(gfx::kGoogleBlue700);
}
return skia::SkColorToSRGBNSColor(gfx::kGoogleBlue700);
}

CGFloat SelectedKeywordDecoration::GetWidthForSpace(CGFloat width) {
Expand Down
10 changes: 8 additions & 2 deletions chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,16 @@ NSRect FlipIfRTL(NSRect rect, NSRect frame) {
return skia::SkColorToSRGBNSColor(SkColorSetRGB(0x64, 0x64, 0x64));
}
NSColor* PositiveTextColor() {
return skia::SkColorToCalibratedNSColor(SkColorSetRGB(0x3d, 0x94, 0x00));
if (!ui::MaterialDesignController::IsModeMaterial()) {
return skia::SkColorToCalibratedNSColor(SkColorSetRGB(0x3d, 0x94, 0x00));
}
return skia::SkColorToSRGBNSColor(SkColorSetRGB(0x3d, 0x94, 0x00));
}
NSColor* NegativeTextColor() {
return skia::SkColorToCalibratedNSColor(SkColorSetRGB(0xdd, 0x4b, 0x39));
if (!ui::MaterialDesignController::IsModeMaterial()) {
return skia::SkColorToCalibratedNSColor(SkColorSetRGB(0xdd, 0x4b, 0x39));
}
return skia::SkColorToSRGBNSColor(SkColorSetRGB(0xdd, 0x4b, 0x39));
}
NSColor* URLTextColor(BOOL is_dark_theme) {
if (!ui::MaterialDesignController::IsModeMaterial()) {
Expand Down
17 changes: 10 additions & 7 deletions chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,22 @@
if (!ui::MaterialDesignController::IsModeMaterial()) {
return ColorWithRGBBytes(0x07, 0x95, 0x00);
}
return in_dark_mode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5]
: skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700);
return in_dark_mode
? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F))
: skia::SkColorToSRGBNSColor(gfx::kGoogleGreen700);
}
NSColor* SecurityWarningSchemeColor(bool in_dark_mode) {
return in_dark_mode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5]
: skia::SkColorToCalibratedNSColor(gfx::kGoogleYellow700);
return in_dark_mode
? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F))
: skia::SkColorToSRGBNSColor(gfx::kGoogleYellow700);
}
NSColor* SecurityErrorSchemeColor(bool in_dark_mode) {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return ColorWithRGBBytes(0xa2, 0x00, 0x00);
}
return in_dark_mode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5]
: skia::SkColorToCalibratedNSColor(gfx::kGoogleRed700);
return in_dark_mode
? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F))
: skia::SkColorToSRGBNSColor(gfx::kGoogleRed700);
}

const char kOmniboxViewMacStateKey[] = "OmniboxViewMacState";
Expand Down Expand Up @@ -176,7 +179,7 @@ NSRange ComponentToNSRange(const url::Component& component) {
if (!ui::MaterialDesignController::IsModeMaterial()) {
return [NSColor darkGrayColor];
}
return skia::SkColorToCalibratedNSColor(BaseTextColorSkia(in_dark_mode));
return skia::SkColorToSRGBNSColor(BaseTextColorSkia(in_dark_mode));
}

// static
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/cocoa/tabs/tab_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ + (NSBezierPath*)tabLeftEdgeBezierPathForContext:(CGContextRef)context {

+ (void)setTabEdgeStrokeColor {
static NSColor* strokeColor =
[skia::SkColorToCalibratedNSColor(SkColorSetARGB(76, 0, 0, 0)) retain];
[skia::SkColorToSRGBNSColor(SkColorSetARGB(76, 0, 0, 0)) retain];
[strokeColor set];
}

Expand Down
6 changes: 5 additions & 1 deletion chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ - (NSImage*)browserToolsIconForFillColor:(SkColor)fillColor {
[[BrowserToolsImageRep alloc]
initWithDrawSelector:@selector(drawBrowserToolsIcon:)
delegate:[BrowserToolsImageRep class]];
[imageRep setFillColor:skia::SkColorToCalibratedNSColor(fillColor)];
if (!ui::MaterialDesignController::IsModeMaterial()) {
[imageRep setFillColor:skia::SkColorToCalibratedNSColor(fillColor)];
} else {
[imageRep setFillColor:skia::SkColorToSRGBNSColor(fillColor)];
}

// Create the image from the image rep.
NSImage* browserToolsIcon =
Expand Down

0 comments on commit 7a7f2e3

Please sign in to comment.