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

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

Issue 2050623004: [Material][Mac] Adjustments to the Omnibox decorations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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 | « chrome/browser/ui/cocoa/location_bar/bubble_decoration.mm ('k') | 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/location_bar_view_mac.h" 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #import "base/mac/mac_util.h" 9 #import "base/mac/mac_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 using content::WebContents; 79 using content::WebContents;
80 80
81 namespace { 81 namespace {
82 82
83 // Vertical space between the bottom edge of the location_bar and the first run 83 // Vertical space between the bottom edge of the location_bar and the first run
84 // bubble arrow point. 84 // bubble arrow point.
85 const static int kFirstRunBubbleYOffset = 1; 85 const static int kFirstRunBubbleYOffset = 1;
86 86
87 const int kDefaultIconSize = 16; 87 const int kDefaultIconSize = 16;
88 const int kMaterialSmallIconSize = 12; 88
89 // Color of the vector graphic icons when the location bar is dark.
90 // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF);
91 const SkColor kMaterialDarkVectorIconColor = 0xCCFFFFFF;
89 92
90 } // namespace 93 } // namespace
91 94
95 // A temporary class that draws hardcoded HTTP graphic icons for Material
96 // design. This class will be removed once the Material icons are available
97 // in M53.
98 @interface LocationBarImageRep : NSCustomImageRep
99 @property(assign, nonatomic) gfx::VectorIconId iconId;
100 @property(retain, nonatomic) NSColor* fillColor;
101
102 + (NSImage*)imageForId:(gfx::VectorIconId)vectorIconId
103 color:(SkColor)vectorIconColor;
104
105 // NSCustomImageRep delegate method that performs the drawing.
106 + (void)drawLocationBarIcon:(LocationBarImageRep*)imageRep;
107
108 @end
109
110 @implementation LocationBarImageRep
111
112 @synthesize iconId = iconId_;
113 @synthesize fillColor = fillColor_;
114
115 - (void)dealloc {
116 [fillColor_ release];
117 [super dealloc];
118 }
119
120 + (NSImage*)imageForId:(gfx::VectorIconId)vectorIconId
121 color:(SkColor)vectorIconColor {
122 if (vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTP &&
123 vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID &&
124 vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID) {
125 return NSImageFromImageSkiaWithColorSpace(
126 gfx::CreateVectorIcon(vectorIconId, kDefaultIconSize, vectorIconColor),
127 base::mac::GetSRGBColorSpace());
128 }
129
130 base::scoped_nsobject<LocationBarImageRep> imageRep =
131 [[LocationBarImageRep alloc]
132 initWithDrawSelector:@selector(drawLocationBarIcon:)
133 delegate:[LocationBarImageRep class]];
134 [imageRep setIconId:vectorIconId];
135 [imageRep setFillColor:skia::SkColorToSRGBNSColor(vectorIconColor)];
136
137 // Create the image from the image rep.
138 const NSSize kImageSize = NSMakeSize(kDefaultIconSize, kDefaultIconSize);
139 NSImage* locationBarImage =
140 [[[NSImage alloc] initWithSize:kImageSize] autorelease];
141 [locationBarImage setCacheMode:NSImageCacheAlways];
142 [locationBarImage addRepresentation:imageRep];
143
144 return locationBarImage;
145 }
146
147 + (void)drawLocationBarIcon:(LocationBarImageRep*)imageRep {
148 [[imageRep fillColor] set];
149
150 // Determine the scale factor.
151 CGContextRef context = static_cast<CGContextRef>(
152 [[NSGraphicsContext currentContext] graphicsPort]);
153 CGRect unitRect = CGRectMake(0.0, 0.0, 1.0, 1.0);
154 CGRect deviceRect = CGContextConvertRectToDeviceSpace(context, unitRect);
155 int scaleFactor = deviceRect.size.height;
156
157 switch ([imageRep iconId]) {
158 case gfx::VectorIconId::LOCATION_BAR_HTTP:
159 [self drawLocationBarIconHTTPForScale:scaleFactor];
160 break;
161 case gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID:
162 [self drawLocationBarIconHTTPSInvalidForScale:scaleFactor];
163 break;
164 case gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID:
165 [self drawLocationBarIconHTTPSValidForScale:scaleFactor];
166 break;
167 default:
168 // Make it obvious that there's a problem.
169 [[NSColor redColor] set];
170 NSRectFill(NSMakeRect(0, 0, kDefaultIconSize, kDefaultIconSize));
171 break;
172 }
173 }
174
175 + (void)drawLocationBarIconHTTPForScale:(int)scaleFactor {
176 NSBezierPath* circlePath =
177 [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(2, 2, 12, 12)];
178 [circlePath setLineWidth:1.5];
179 [circlePath stroke];
180
181 NSRectFill(NSMakeRect(7, 4, 2, 5));
182 NSRectFill(NSMakeRect(7, 10, 2, 2));
183 }
184
185 + (void)drawLocationBarIconHTTPSInvalidForScale:(int)scaleFactor {
186 // The vector icon is upside down relative to the default OS X coordinate
187 // system so rotate by 180 degrees.
188 CGContextRef context = static_cast<CGContextRef>(
189 [[NSGraphicsContext currentContext] graphicsPort]);
190 const int kHalfDefaultIconSize = kDefaultIconSize / 2;
191 CGContextTranslateCTM(context, kHalfDefaultIconSize, kHalfDefaultIconSize);
192 CGContextRotateCTM(context, M_PI);
193 CGContextTranslateCTM(context, -kHalfDefaultIconSize, -kHalfDefaultIconSize);
194
195 // If Retina, nudge the icon up 1/2pt.
196 if (scaleFactor == 2) {
197 CGContextTranslateCTM(context, 0, -0.5);
198 }
199
200 NSBezierPath* trianglePath = [NSBezierPath bezierPath];
201 [trianglePath moveToPoint:NSMakePoint(0.5f, 14)];
202 [trianglePath relativeLineToPoint:NSMakePoint(15, 0)];
203 [trianglePath lineToPoint:NSMakePoint(8, 1)];
204 [trianglePath closePath];
205
206 NSBezierPath* cutOutPath = [NSBezierPath bezierPath];
207 [cutOutPath moveToPoint:NSMakePoint(9, 12)];
208 [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
209 [cutOutPath relativeLineToPoint:NSMakePoint(0, -2)];
210 [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
211 [cutOutPath relativeLineToPoint:NSMakePoint(0, 2)];
212 [cutOutPath closePath];
213 [cutOutPath relativeMoveToPoint:NSMakePoint(0, -3)];
214 [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
215 [cutOutPath relativeLineToPoint:NSMakePoint(0, -3)];
216 [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
217 [cutOutPath relativeLineToPoint:NSMakePoint(0, 3)];
218 [cutOutPath closePath];
219
220 [trianglePath appendBezierPath:cutOutPath];
221 [trianglePath fill];
222 }
223
224 + (void)drawLocationBarIconHTTPSValidForScale:(int)scaleFactor {
225 NSBezierPath* rectPath =
226 [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(4, 3, 8, 7)
227 xRadius:1
228 yRadius:1];
229 [rectPath fill];
230
231 NSBezierPath* curvePath = [NSBezierPath bezierPath];
232 [curvePath moveToPoint:NSMakePoint(5.5, 9.75)];
233 [curvePath lineToPoint:NSMakePoint(5.5, 10)];
234 [curvePath curveToPoint:NSMakePoint(8, 13)
235 controlPoint1:NSMakePoint(5.5, 13)
236 controlPoint2:NSMakePoint(7.5, 13)];
237 [curvePath curveToPoint:NSMakePoint(10.5, 10)
238 controlPoint1:NSMakePoint(8.5, 13)
239 controlPoint2:NSMakePoint(10.5, 13)];
240 [curvePath lineToPoint:NSMakePoint(10.5, 9.75)];
241 [curvePath setLineWidth:1.25];
242 [curvePath stroke];
243 }
244
245 @end
246
92 // TODO(shess): This code is mostly copied from the gtk 247 // TODO(shess): This code is mostly copied from the gtk
93 // implementation. Make sure it's all appropriate and flesh it out. 248 // implementation. Make sure it's all appropriate and flesh it out.
94 249
95 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, 250 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
96 CommandUpdater* command_updater, 251 CommandUpdater* command_updater,
97 Profile* profile, 252 Profile* profile,
98 Browser* browser) 253 Browser* browser)
99 : LocationBar(profile), 254 : LocationBar(profile),
100 ChromeOmniboxEditController(command_updater), 255 ChromeOmniboxEditController(command_updater),
101 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), 256 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)),
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 712
558 void LocationBarViewMac::UpdateWithoutTabRestore() { 713 void LocationBarViewMac::UpdateWithoutTabRestore() {
559 Update(nullptr); 714 Update(nullptr);
560 } 715 }
561 716
562 void LocationBarViewMac::UpdateLocationIcon() { 717 void LocationBarViewMac::UpdateLocationIcon() {
563 bool in_dark_mode = IsLocationBarDark(); 718 bool in_dark_mode = IsLocationBarDark();
564 719
565 SkColor vector_icon_color = gfx::kPlaceholderColor; 720 SkColor vector_icon_color = gfx::kPlaceholderColor;
566 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; 721 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE;
567 int icon_size = kDefaultIconSize;
568 if (ShouldShowEVBubble()) { 722 if (ShouldShowEVBubble()) {
569 vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; 723 vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID;
570 vector_icon_color = gfx::kGoogleGreen700; 724 vector_icon_color = in_dark_mode
571 icon_size = kMaterialSmallIconSize; 725 ? kMaterialDarkVectorIconColor
726 : gfx::kGoogleGreen700;
572 } else { 727 } else {
573 vector_icon_id = omnibox_view_->GetVectorIcon(in_dark_mode); 728 vector_icon_id = omnibox_view_->GetVectorIcon(in_dark_mode);
574 if (in_dark_mode) { 729 if (in_dark_mode) {
575 vector_icon_color = SK_ColorWHITE; 730 vector_icon_color = SK_ColorWHITE;
576 } else { 731 } else {
577 vector_icon_color = OmniboxViewMac::BaseTextColorSkia(in_dark_mode); 732 vector_icon_color = OmniboxViewMac::BaseTextColorSkia(in_dark_mode);
578 } 733 }
579 } 734 }
580 735
581 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); 736 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE);
582 NSImage* image = NSImageFromImageSkiaWithColorSpace( 737 NSImage* image =
583 gfx::CreateVectorIcon(vector_icon_id, icon_size, vector_icon_color), 738 [LocationBarImageRep imageForId:vector_icon_id color:vector_icon_color];
584 base::mac::GetSRGBColorSpace());
585 739
586 location_icon_decoration_->SetImage(image); 740 location_icon_decoration_->SetImage(image);
587 ev_bubble_decoration_->SetImage(image); 741 ev_bubble_decoration_->SetImage(image);
588 Layout(); 742 Layout();
589 } 743 }
590 744
591 void LocationBarViewMac::UpdateColorsToMatchTheme() { 745 void LocationBarViewMac::UpdateColorsToMatchTheme() {
592 if (!ui::MaterialDesignController::IsModeMaterial() || 746 if (!ui::MaterialDesignController::IsModeMaterial() ||
593 ![[field_ window] inIncognitoMode]) { 747 ![[field_ window] inIncognitoMode]) {
594 return; 748 return;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 961
808 return zoom_decoration_->UpdateIfNecessary( 962 return zoom_decoration_->UpdateIfNecessary(
809 ui_zoom::ZoomController::FromWebContents(web_contents), 963 ui_zoom::ZoomController::FromWebContents(web_contents),
810 default_zoom_changed, IsLocationBarDark()); 964 default_zoom_changed, IsLocationBarDark());
811 } 965 }
812 966
813 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 967 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
814 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 968 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
815 OnDecorationsChanged(); 969 OnDecorationsChanged();
816 } 970 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/bubble_decoration.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698