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

Unified Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm

Issue 1905163002: [Mac][Material Design] Rework how location bar shadow is drawn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for Retina screens. Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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 36b9a024ad561c5de3a1eac6b1a9db6e8777a9e6..c1e265c7f149ad311ffcf2d424140bec07263be0 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,32 @@
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 {
tapted 2016/04/22 01:11:46 nit: curlies not needed
shrike 2016/04/26 19:19:30 Done.
+}
+@end
+
+@implementation AutocompleteTextFieldShadowView
+
+- (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 cr_lineWidth] < 1) {
tapted 2016/04/22 01:11:46 optional nit: curlies not needed (but I'd keep a b
shrike 2016/04/26 19:19:30 Acknowledged.
+ return;
+ }
+ [[NSColor colorWithCalibratedWhite:69 / 255. alpha:1] set];
tapted 2016/04/22 01:11:46 hmmmm this should be `colorWithGenericGamma22White
shrike 2016/04/22 02:09:00 I'm confused, because the link you sent says 2.2 i
tapted 2016/04/22 04:41:34 I don't think it's clear what gamma you get with `
+ NSRectFill(rect);
+}
+
+@end
+
@implementation AutocompleteTextField
@synthesize observer = observer_;
@@ -217,6 +241,18 @@ const CGFloat kAnimationDuration = 0.2;
[self updateMouseTracking];
}
+// Overridden to adjust the shadow view whenever the textfield's origin changes.
tapted 2016/04/22 01:11:46 I think the typical solution for this under c/b/ui
shrike 2016/04/22 02:09:00 OK. I can't remember off the top of my head if it'
tapted 2016/04/22 04:41:34 Would it work to pass in `self` into new initializ
+- (void)setFrameOrigin:(NSPoint)frameOrigin {
+ [super setFrameOrigin:frameOrigin];
+ [self adjustShadowViewFrame];
+}
+
+// Overridden to adjust the shadow view whenever the textfield's size changes.
+- (void)setFrameSize:(NSSize)frameSize {
+ [super setFrameSize:frameSize];
+ [self adjustShadowViewFrame];
+}
+
- (void)setAttributedStringValue:(NSAttributedString*)aString {
AutocompleteTextFieldEditor* editor =
static_cast<AutocompleteTextFieldEditor*>([self currentEditor]);
@@ -377,11 +413,31 @@ const CGFloat kAnimationDuration = 0.2;
[self setNeedsDisplay];
}
+- (void)adjustShadowViewFrame {
+ // Make the shadow view 1pt tall and slightly inset from the edges of the
+ // autocomplete textfield.
+ NSRect shadowViewFrame = [self frame];
+ shadowViewFrame.origin.x += kShadowInset;
+ shadowViewFrame.size.width -= kShadowInset * 2;
+ shadowViewFrame.origin.y -= 1;
+ shadowViewFrame.size.height = 1;
+ [shadowView_ setFrame:shadowViewFrame];
+}
+
- (void)updateColorsToMatchTheme {
if (![[self window] inIncognitoMode]) {
+ [shadowView_ removeFromSuperview];
return;
}
+ // Add 1px shadow below the autocomplete textfield.
+ if (!shadowView_.get()) {
+ shadowView_.reset(
+ [[AutocompleteTextFieldShadowView alloc] initWithFrame:NSZeroRect]);
+ }
+ [self adjustShadowViewFrame];
+ [[self superview] addSubview:shadowView_];
+
// Invert the textfield's colors when Material Design and Incognito and not
// a custom theme.
bool inDarkMode = [[self window] inIncognitoModeWithSystemTheme];

Powered by Google App Engine
This is Rietveld 408576698