| Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm
|
| diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm
|
| index 7647a1a79956e0b22c3d4b634f852df8efc3e9a0..48a30ef75872f3e03f2e297d33b845509481837a 100644
|
| --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm
|
| +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm
|
| @@ -22,8 +22,78 @@
|
|
|
| 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
|
|
|
| @@ -33,8 +103,13 @@
|
| return [AutocompleteTextFieldCell class];
|
| }
|
|
|
| ++ (NSColor*)shadowColor {
|
| + return [NSColor colorWithGenericGamma22White:0 alpha:0.14];
|
| +}
|
| +
|
| - (void)dealloc {
|
| [[NSNotificationCenter defaultCenter] removeObserver:self];
|
| + [shadowView_ removeFromSuperview];
|
| [super dealloc];
|
| }
|
|
|
| @@ -386,16 +461,16 @@
|
| // 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:kDarkModeGray
|
| - alpha:1]
|
| + inDarkMode ? [NSColor colorWithGenericGamma22White:115 / 255. alpha:1]
|
| : [NSColor whiteColor]];
|
| [self setTextColor:OmniboxViewMac::BaseTextColor(inDarkMode)];
|
| }
|
|
|
| - (void)viewDidMoveToWindow {
|
| if (![self window]) {
|
| + [shadowView_ removeFromSuperview];
|
| + shadowView_.reset();
|
| return;
|
| }
|
|
|
| @@ -405,6 +480,11 @@
|
| BrowserWindowController* browserWindowController =
|
| [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];
|
| }
|
|
|