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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.mm

Issue 1928783003: Revert of [Mac][Material Design] Rework how location bar shadow is drawn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/location_bar/autocomplete_text_field.h" 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #import "base/mac/sdk_forward_declarations.h" 9 #import "base/mac/sdk_forward_declarations.h"
10 #include "chrome/browser/themes/theme_service.h" 10 #include "chrome/browser/themes/theme_service.h"
11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
15 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 15 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
17 #import "chrome/browser/ui/cocoa/url_drop_target.h" 17 #import "chrome/browser/ui/cocoa/url_drop_target.h"
18 #import "chrome/browser/ui/cocoa/view_id_util.h" 18 #import "chrome/browser/ui/cocoa/view_id_util.h"
19 #import "ui/base/cocoa/nsview_additions.h" 19 #import "ui/base/cocoa/nsview_additions.h"
20 #include "ui/base/material_design/material_design_controller.h" 20 #include "ui/base/material_design/material_design_controller.h"
21 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 21 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
22 22
23 namespace { 23 namespace {
24 const CGFloat kAnimationDuration = 0.2; 24 const CGFloat kAnimationDuration = 0.2;
25 const CGFloat kShadowInset = 3;
26 const CGFloat kShadowColor = 69 / 255.;
27
28 } 25 }
29 26
30 // A view that draws a 1px shadow line beneath the autocomplete textfield.
31 @interface AutocompleteTextFieldShadowView : NSView {
32 @private
33 AutocompleteTextField* textField_; // Weak. Owns this.
34 }
35 // This is the designated initializer for AutocompleteTextFieldShadowView.
36 - (instancetype)initWithTextField:(AutocompleteTextField*)aTextField;
37 @end
38
39 @interface AutocompleteTextFieldShadowView(Private)
40 // Adjusts the shadow view's position whenever its AutocompleteTextField changes
41 // its frame.
42 - (void)adjustFrame;
43 @end
44
45 @implementation AutocompleteTextFieldShadowView
46
47 - (instancetype)initWithTextField:(AutocompleteTextField*)aTextField {
48 if ((self = [self initWithFrame:NSZeroRect])) {
49 textField_ = aTextField;
50 [[NSNotificationCenter defaultCenter]
51 addObserver:self
52 selector:@selector(adjustFrame)
53 name:NSViewFrameDidChangeNotification
54 object:textField_];
55 }
56 return self;
57 }
58
59 - (void)dealloc {
60 [[NSNotificationCenter defaultCenter] removeObserver:self];
61 [super dealloc];
62 }
63
64 - (void)adjustFrame {
65 if (![self window]) {
66 return;
67 }
68 // Make the shadow view 1pt tall and slightly inset from the edges of the
69 // autocomplete textfield.
70 NSRect frame = [textField_ frame];
71 frame.origin.x += kShadowInset;
72 frame.size.width -= kShadowInset * 2;
73 frame.origin.y -= 1;
74 frame.size.height = 1;
75 [self setFrame:frame];
76 }
77
78 - (void)viewDidMoveToWindow {
79 [self adjustFrame];
80 }
81
82 - (void)drawRect:(NSRect)rect {
83 // Don't draw anything on a Retina display because on Retina there's room
84 // for the shadow just beneath the autocomplete textfield path stroke. Why
85 // even add this view? If the user drags the Incognito window between Retina
86 // and non-Retina screens there would have to be logic to add and remove the
87 // view. It's easier just to always add it for Incognito mode and draw
88 // nothing into it.
89 if ([self cr_lineWidth] < 1) {
90 return;
91 }
92 [[AutocompleteTextField shadowColor] set];
93 NSRectFill(rect);
94 }
95
96 @end
97
98 @implementation AutocompleteTextField 27 @implementation AutocompleteTextField
99 28
100 @synthesize observer = observer_; 29 @synthesize observer = observer_;
101 30
102 + (Class)cellClass { 31 + (Class)cellClass {
103 return [AutocompleteTextFieldCell class]; 32 return [AutocompleteTextFieldCell class];
104 } 33 }
105 34
106 + (NSColor*)shadowColor {
107 return [NSColor colorWithGenericGamma22White:kShadowColor alpha:1];
108 }
109
110 - (void)dealloc { 35 - (void)dealloc {
111 [[NSNotificationCenter defaultCenter] removeObserver:self]; 36 [[NSNotificationCenter defaultCenter] removeObserver:self];
112 [shadowView_ removeFromSuperview];
113 [super dealloc]; 37 [super dealloc];
114 } 38 }
115 39
116 - (void)awakeFromNib { 40 - (void)awakeFromNib {
117 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); 41 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]);
118 [[self cell] setTruncatesLastVisibleLine:YES]; 42 [[self cell] setTruncatesLastVisibleLine:YES];
119 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; 43 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail];
120 currentToolTips_.reset([[NSMutableArray alloc] init]); 44 currentToolTips_.reset([[NSMutableArray alloc] init]);
121 resizeAnimation_.reset([[NSViewAnimation alloc] init]); 45 resizeAnimation_.reset([[NSViewAnimation alloc] init]);
122 [resizeAnimation_ setDuration:kAnimationDuration]; 46 [resizeAnimation_ setDuration:kAnimationDuration];
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 - (void)windowDidChangeScreen { 372 - (void)windowDidChangeScreen {
449 // Inform the AutocompleteTextFieldCell's of the coordinate system line 373 // Inform the AutocompleteTextFieldCell's of the coordinate system line
450 // width needed to draw a single-pixel line. This value changes as we move 374 // width needed to draw a single-pixel line. This value changes as we move
451 // between Retina and non-Retina displays. 375 // between Retina and non-Retina displays.
452 [[self cell] setSinglePixelLineWidth:[self cr_lineWidth]]; 376 [[self cell] setSinglePixelLineWidth:[self cr_lineWidth]];
453 [self setNeedsDisplay]; 377 [self setNeedsDisplay];
454 } 378 }
455 379
456 - (void)updateColorsToMatchTheme { 380 - (void)updateColorsToMatchTheme {
457 if (![[self window] inIncognitoMode]) { 381 if (![[self window] inIncognitoMode]) {
458 [shadowView_ removeFromSuperview];
459 return; 382 return;
460 } 383 }
461 384
462 // Add 1px shadow below the autocomplete textfield.
463 if (!shadowView_.get()) {
464 shadowView_.reset(
465 [[AutocompleteTextFieldShadowView alloc] initWithTextField:self]);
466 }
467 [[self superview] addSubview:shadowView_];
468
469 // Invert the textfield's colors when Material Design and Incognito and not 385 // Invert the textfield's colors when Material Design and Incognito and not
470 // a custom theme. 386 // a custom theme.
471 bool inDarkMode = [[self window] inIncognitoModeWithSystemTheme]; 387 bool inDarkMode = [[self window] inIncognitoModeWithSystemTheme];
472 [self setBackgroundColor: 388 [self setBackgroundColor:
473 inDarkMode ? [NSColor colorWithGenericGamma22White:115 / 255. alpha:1] 389 inDarkMode ? [NSColor colorWithCalibratedWhite:115 / 255. alpha:1]
474 : [NSColor whiteColor]]; 390 : [NSColor whiteColor]];
475 [self setTextColor:OmniboxViewMac::BaseTextColor(inDarkMode)]; 391 [self setTextColor:OmniboxViewMac::BaseTextColor(inDarkMode)];
476 } 392 }
477 393
478 - (void)viewDidMoveToWindow { 394 - (void)viewDidMoveToWindow {
479 if (![self window]) { 395 if (![self window]) {
480 return; 396 return;
481 } 397 }
482 398
483 // Allow the ToolbarController to take action upon the 399 // Allow the ToolbarController to take action upon the
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 NSMinY(frame), 582 NSMinY(frame),
667 suggestWidth, 583 suggestWidth,
668 NSHeight(frame)); 584 NSHeight(frame));
669 585
670 gfx::ScopedNSGraphicsContextSaveGState saveGState; 586 gfx::ScopedNSGraphicsContextSaveGState saveGState;
671 NSRectClip(suggestRect); 587 NSRectClip(suggestRect);
672 [cell drawInteriorWithFrame:frame inView:controlView]; 588 [cell drawInteriorWithFrame:frame inView:controlView];
673 } 589 }
674 590
675 } // namespace autocomplete_text_field 591 } // namespace autocomplete_text_field
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698