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

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

Issue 2129723003: [Material][Mac]Replaced hard coded Omnibox vectors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const static int kFirstRunBubbleYOffset = 1; 86 const static int kFirstRunBubbleYOffset = 1;
87 87
88 const int kDefaultIconSize = 16; 88 const int kDefaultIconSize = 16;
89 89
90 // Color of the vector graphic icons when the location bar is dark. 90 // Color of the vector graphic icons when the location bar is dark.
91 // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF); 91 // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF);
92 const SkColor kMaterialDarkVectorIconColor = SK_ColorWHITE; 92 const SkColor kMaterialDarkVectorIconColor = SK_ColorWHITE;
93 93
94 } // namespace 94 } // namespace
95 95
96 // A temporary class that draws hardcoded HTTP graphic icons for Material
97 // design. This class will be removed once the Material icons are available
98 // in M53.
99 @interface LocationBarImageRep : NSCustomImageRep
100 @property(assign, nonatomic) gfx::VectorIconId iconId;
101 @property(retain, nonatomic) NSColor* fillColor;
102
103 + (NSImage*)imageForId:(gfx::VectorIconId)vectorIconId
104 color:(SkColor)vectorIconColor;
105
106 // NSCustomImageRep delegate method that performs the drawing.
107 + (void)drawLocationBarIcon:(LocationBarImageRep*)imageRep;
108
109 @end
110
111 @implementation LocationBarImageRep
112
113 @synthesize iconId = iconId_;
114 @synthesize fillColor = fillColor_;
115
116 - (void)dealloc {
117 [fillColor_ release];
118 [super dealloc];
119 }
120
121 + (NSImage*)imageForId:(gfx::VectorIconId)vectorIconId
122 color:(SkColor)vectorIconColor {
123 if (vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTP &&
124 vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID &&
125 vectorIconId != gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID) {
126 return NSImageFromImageSkiaWithColorSpace(
127 gfx::CreateVectorIcon(vectorIconId, kDefaultIconSize, vectorIconColor),
128 base::mac::GetSRGBColorSpace());
129 }
130
131 base::scoped_nsobject<LocationBarImageRep> imageRep(
132 [[LocationBarImageRep alloc]
133 initWithDrawSelector:@selector(drawLocationBarIcon:)
134 delegate:[LocationBarImageRep class]]);
135 [imageRep setIconId:vectorIconId];
136 [imageRep setFillColor:skia::SkColorToSRGBNSColor(vectorIconColor)];
137
138 // Create the image from the image rep.
139 const NSSize kImageSize = NSMakeSize(kDefaultIconSize, kDefaultIconSize);
140 NSImage* locationBarImage =
141 [[[NSImage alloc] initWithSize:kImageSize] autorelease];
142 [locationBarImage setCacheMode:NSImageCacheAlways];
143 [locationBarImage addRepresentation:imageRep];
144
145 return locationBarImage;
146 }
147
148 + (void)drawLocationBarIcon:(LocationBarImageRep*)imageRep {
149 [[imageRep fillColor] set];
150
151 // Determine the scale factor.
152 CGContextRef context = static_cast<CGContextRef>(
153 [[NSGraphicsContext currentContext] graphicsPort]);
154 CGRect unitRect = CGRectMake(0.0, 0.0, 1.0, 1.0);
155 CGRect deviceRect = CGContextConvertRectToDeviceSpace(context, unitRect);
156 int scaleFactor = deviceRect.size.height;
157
158 switch ([imageRep iconId]) {
159 case gfx::VectorIconId::LOCATION_BAR_HTTP:
160 [self drawLocationBarIconHTTPForScale:scaleFactor];
161 break;
162 case gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID:
163 [self drawLocationBarIconHTTPSInvalidForScale:scaleFactor];
164 break;
165 case gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID:
166 [self drawLocationBarIconHTTPSValidForScale:scaleFactor];
167 break;
168 default:
169 // Make it obvious that there's a problem.
170 [[NSColor redColor] set];
171 NSRectFill(NSMakeRect(0, 0, kDefaultIconSize, kDefaultIconSize));
172 break;
173 }
174 }
175
176 + (void)drawLocationBarIconHTTPForScale:(int)scaleFactor {
177 if (scaleFactor > 1) {
178 NSRect ovalRect = NSMakeRect(2.25, 1.75, 12, 12);
179 NSBezierPath* circlePath =
180 [NSBezierPath bezierPathWithOvalInRect:ovalRect];
181 [circlePath setLineWidth:1.5];
182 [circlePath stroke];
183
184 NSRectFill(NSMakeRect(7.5, 4.5, 1.5, 4));
185 NSRectFill(NSMakeRect(7.5, 9.5, 1.5, 1.5));
186 } else {
187 NSRect ovalRect = NSMakeRect(2, 2, 12, 12);
188 NSBezierPath* circlePath =
189 [NSBezierPath bezierPathWithOvalInRect:ovalRect];
190 [circlePath setLineWidth:1.5];
191 [circlePath stroke];
192
193 NSRectFill(NSMakeRect(7, 4, 2, 5));
194 NSRectFill(NSMakeRect(7, 10, 2, 2));
195 }
196 }
197
198 + (void)drawLocationBarIconHTTPSInvalidForScale:(int)scaleFactor {
199 // The vector icon is upside down relative to the default OS X coordinate
200 // system so rotate by 180 degrees.
201 CGContextRef context = static_cast<CGContextRef>(
202 [[NSGraphicsContext currentContext] graphicsPort]);
203 const int kHalfDefaultIconSize = kDefaultIconSize / 2;
204 CGContextTranslateCTM(context, kHalfDefaultIconSize, kHalfDefaultIconSize);
205 CGContextRotateCTM(context, M_PI);
206 CGContextTranslateCTM(context, -kHalfDefaultIconSize, -kHalfDefaultIconSize);
207
208 // If Retina, nudge the icon up 1/2pt.
209 if (scaleFactor == 2) {
210 CGContextTranslateCTM(context, 0, -0.5);
211 }
212
213 NSBezierPath* trianglePath = [NSBezierPath bezierPath];
214 [trianglePath moveToPoint:NSMakePoint(0.5f, 14)];
215 [trianglePath relativeLineToPoint:NSMakePoint(15, 0)];
216 [trianglePath lineToPoint:NSMakePoint(8, 1)];
217 [trianglePath closePath];
218
219 NSBezierPath* cutOutPath = [NSBezierPath bezierPath];
220 [cutOutPath moveToPoint:NSMakePoint(9, 12)];
221 [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
222 [cutOutPath relativeLineToPoint:NSMakePoint(0, -2)];
223 [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
224 [cutOutPath relativeLineToPoint:NSMakePoint(0, 2)];
225 [cutOutPath closePath];
226 [cutOutPath relativeMoveToPoint:NSMakePoint(0, -3)];
227 [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
228 [cutOutPath relativeLineToPoint:NSMakePoint(0, -3)];
229 [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
230 [cutOutPath relativeLineToPoint:NSMakePoint(0, 3)];
231 [cutOutPath closePath];
232
233 [trianglePath appendBezierPath:cutOutPath];
234 [trianglePath fill];
235 }
236
237 + (void)drawLocationBarIconHTTPSValidForScale:(int)scaleFactor {
238 NSAffineTransform* transform = [NSAffineTransform transform];
239 // Adjust down 1px in Retina, so that the lock sits on the text baseline.
240 if (scaleFactor > 1) {
241 [transform translateXBy:0 yBy:-0.5];
242 }
243
244 NSBezierPath* rectPath =
245 [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(4, 3, 8, 7)
246 xRadius:1
247 yRadius:1];
248 [rectPath transformUsingAffineTransform:transform];
249 [rectPath fill];
250
251 NSBezierPath* curvePath = [NSBezierPath bezierPath];
252 [curvePath moveToPoint:NSMakePoint(5.5, 9.75)];
253 [curvePath lineToPoint:NSMakePoint(5.5, 10)];
254 [curvePath curveToPoint:NSMakePoint(8, 13)
255 controlPoint1:NSMakePoint(5.5, 13)
256 controlPoint2:NSMakePoint(7.5, 13)];
257 [curvePath curveToPoint:NSMakePoint(10.5, 10)
258 controlPoint1:NSMakePoint(8.5, 13)
259 controlPoint2:NSMakePoint(10.5, 13)];
260 [curvePath lineToPoint:NSMakePoint(10.5, 9.75)];
261 [curvePath setLineWidth:1.25];
262 [curvePath transformUsingAffineTransform:transform];
263 [curvePath stroke];
264 }
265
266 @end
267
268 // TODO(shess): This code is mostly copied from the gtk 96 // TODO(shess): This code is mostly copied from the gtk
269 // implementation. Make sure it's all appropriate and flesh it out. 97 // implementation. Make sure it's all appropriate and flesh it out.
270 98
271 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, 99 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
272 CommandUpdater* command_updater, 100 CommandUpdater* command_updater,
273 Profile* profile, 101 Profile* profile,
274 Browser* browser) 102 Browser* browser)
275 : LocationBar(profile), 103 : LocationBar(profile),
276 ChromeOmniboxEditController(command_updater), 104 ChromeOmniboxEditController(command_updater),
277 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), 105 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)),
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor); 585 vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor);
758 } 586 }
759 } 587 }
760 588
761 // If the theme is dark, then the color should always be 589 // If the theme is dark, then the color should always be
762 // kMaterialDarkVectorIconColor. 590 // kMaterialDarkVectorIconColor.
763 if (in_dark_mode) 591 if (in_dark_mode)
764 vector_icon_color = kMaterialDarkVectorIconColor; 592 vector_icon_color = kMaterialDarkVectorIconColor;
765 593
766 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); 594 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE);
767 NSImage* image = 595 NSImage* image = NSImageFromImageSkiaWithColorSpace(
768 [LocationBarImageRep imageForId:vector_icon_id color:vector_icon_color]; 596 gfx::CreateVectorIcon(vector_icon_id, kDefaultIconSize,
769 597 vector_icon_color),
598 base::mac::GetSRGBColorSpace());
770 location_icon_decoration_->SetImage(image); 599 location_icon_decoration_->SetImage(image);
771 ev_bubble_decoration_->SetImage(image); 600 ev_bubble_decoration_->SetImage(image);
772 Layout(); 601 Layout();
773 } 602 }
774 603
775 void LocationBarViewMac::UpdateColorsToMatchTheme() { 604 void LocationBarViewMac::UpdateColorsToMatchTheme() {
776 if (!ui::MaterialDesignController::IsModeMaterial() || 605 if (!ui::MaterialDesignController::IsModeMaterial() ||
777 ![[field_ window] inIncognitoMode]) { 606 ![[field_ window] inIncognitoMode]) {
778 return; 607 return;
779 } 608 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 817
989 return zoom_decoration_->UpdateIfNecessary( 818 return zoom_decoration_->UpdateIfNecessary(
990 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, 819 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed,
991 IsLocationBarDark()); 820 IsLocationBarDark());
992 } 821 }
993 822
994 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 823 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
995 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 824 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
996 OnDecorationsChanged(); 825 OnDecorationsChanged();
997 } 826 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698