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

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

Issue 2002103003: [Material][Mac] Adjustments to the Omnibox decorations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shift icon to the right 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 using content::WebContents; 80 using content::WebContents;
81 81
82 namespace { 82 namespace {
83 83
84 // Vertical space between the bottom edge of the location_bar and the first run 84 // Vertical space between the bottom edge of the location_bar and the first run
85 // bubble arrow point. 85 // bubble arrow point.
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 const int kMaterialIconSize = 18;
90 89
91 // 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.
92 // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF); 91 // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF);
93 const SkColor kMaterialDarkVectorIconColor = 0xCCFFFFFF; 92 const SkColor kMaterialDarkVectorIconColor = 0xCCFFFFFF;
94 93
95 } // namespace 94 } // namespace
96 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 NSBezierPath* circlePath =
178 [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(2, 2, 12, 12)];
179 [circlePath setLineWidth:1.5];
180 [circlePath stroke];
181
182 NSRectFill(NSMakeRect(7, 4, 2, 5));
183 NSRectFill(NSMakeRect(7, 10, 2, 2));
184 }
185
186 + (void)drawLocationBarIconHTTPSInvalidForScale:(int)scaleFactor {
187 // The vector icon is upside down relative to the default OS X coordinate
188 // system so rotate by 180 degrees.
189 CGContextRef context = static_cast<CGContextRef>(
190 [[NSGraphicsContext currentContext] graphicsPort]);
191 const int kHalfDefaultIconSize = kDefaultIconSize / 2;
192 CGContextTranslateCTM(context, kHalfDefaultIconSize, kHalfDefaultIconSize);
193 CGContextRotateCTM(context, M_PI);
194 CGContextTranslateCTM(context, -kHalfDefaultIconSize, -kHalfDefaultIconSize);
195
196 // If Retina, nudge the icon up 1/2pt.
197 if (scaleFactor == 2) {
198 CGContextTranslateCTM(context, 0, -0.5);
199 }
200
201 NSBezierPath* trianglePath = [NSBezierPath bezierPath];
202 [trianglePath moveToPoint:NSMakePoint(0.5f, 14)];
203 [trianglePath relativeLineToPoint:NSMakePoint(15, 0)];
204 [trianglePath lineToPoint:NSMakePoint(8, 1)];
205 [trianglePath closePath];
206
207 NSBezierPath* cutOutPath = [NSBezierPath bezierPath];
208 [cutOutPath moveToPoint:NSMakePoint(9, 12)];
209 [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
210 [cutOutPath relativeLineToPoint:NSMakePoint(0, -2)];
211 [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
212 [cutOutPath relativeLineToPoint:NSMakePoint(0, 2)];
213 [cutOutPath closePath];
214 [cutOutPath relativeMoveToPoint:NSMakePoint(0, -3)];
215 [cutOutPath relativeLineToPoint:NSMakePoint(-2, 0)];
216 [cutOutPath relativeLineToPoint:NSMakePoint(0, -3)];
217 [cutOutPath relativeLineToPoint:NSMakePoint(2, 0)];
218 [cutOutPath relativeLineToPoint:NSMakePoint(0, 3)];
219 [cutOutPath closePath];
220
221 [trianglePath appendBezierPath:cutOutPath];
222 [trianglePath fill];
223 }
224
225 + (void)drawLocationBarIconHTTPSValidForScale:(int)scaleFactor {
226 NSBezierPath* rectPath =
227 [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(4, 3, 8, 7)
228 xRadius:1
229 yRadius:1];
230 [rectPath fill];
231
232 NSBezierPath* curvePath = [NSBezierPath bezierPath];
233 [curvePath moveToPoint:NSMakePoint(5.5, 9.75)];
234 [curvePath lineToPoint:NSMakePoint(5.5, 10)];
235 [curvePath curveToPoint:NSMakePoint(8, 13)
236 controlPoint1:NSMakePoint(5.5, 13)
237 controlPoint2:NSMakePoint(7.5, 13)];
238 [curvePath curveToPoint:NSMakePoint(10.5, 10)
239 controlPoint1:NSMakePoint(8.5, 13)
240 controlPoint2:NSMakePoint(10.5, 13)];
241 [curvePath lineToPoint:NSMakePoint(10.5, 9.75)];
242 [curvePath setLineWidth:1.25];
243 [curvePath stroke];
244 }
245
246 @end
247
97 // TODO(shess): This code is mostly copied from the gtk 248 // TODO(shess): This code is mostly copied from the gtk
98 // implementation. Make sure it's all appropriate and flesh it out. 249 // implementation. Make sure it's all appropriate and flesh it out.
99 250
100 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, 251 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
101 CommandUpdater* command_updater, 252 CommandUpdater* command_updater,
102 Profile* profile, 253 Profile* profile,
103 Browser* browser) 254 Browser* browser)
104 : LocationBar(profile), 255 : LocationBar(profile),
105 ChromeOmniboxEditController(command_updater), 256 ChromeOmniboxEditController(command_updater),
106 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), 257 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)),
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 713
563 void LocationBarViewMac::UpdateWithoutTabRestore() { 714 void LocationBarViewMac::UpdateWithoutTabRestore() {
564 Update(nullptr); 715 Update(nullptr);
565 } 716 }
566 717
567 void LocationBarViewMac::UpdateLocationIcon() { 718 void LocationBarViewMac::UpdateLocationIcon() {
568 bool in_dark_mode = IsLocationBarDark(); 719 bool in_dark_mode = IsLocationBarDark();
569 720
570 SkColor vector_icon_color = gfx::kPlaceholderColor; 721 SkColor vector_icon_color = gfx::kPlaceholderColor;
571 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; 722 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE;
572 int icon_size = kDefaultIconSize;
573 if (ShouldShowEVBubble()) { 723 if (ShouldShowEVBubble()) {
574 vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; 724 vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID;
575 vector_icon_color = in_dark_mode 725 vector_icon_color = in_dark_mode
576 ? LocationBarDecoration::kMaterialDarkModeTextColor 726 ? LocationBarDecoration::kMaterialDarkModeTextColor
577 : gfx::kGoogleGreen700; 727 : gfx::kGoogleGreen700;
578 icon_size = kMaterialIconSize;
579 } else { 728 } else {
580 vector_icon_id = omnibox_view_->GetVectorIcon(); 729 vector_icon_id = omnibox_view_->GetVectorIcon();
581 if (in_dark_mode) { 730 if (in_dark_mode) {
582 vector_icon_color = SK_ColorWHITE; 731 vector_icon_color = SK_ColorWHITE;
583 } else { 732 } else {
584 security_state::SecurityStateModel::SecurityLevel security_level = 733 security_state::SecurityStateModel::SecurityLevel security_level =
585 GetToolbarModel()->GetSecurityLevel(false); 734 GetToolbarModel()->GetSecurityLevel(false);
586 if (security_level == security_state::SecurityStateModel::NONE) { 735 if (security_level == security_state::SecurityStateModel::NONE) {
587 vector_icon_color = OmniboxViewMac::BaseTextColorSkia(in_dark_mode); 736 vector_icon_color = OmniboxViewMac::BaseTextColorSkia(in_dark_mode);
588 } else { 737 } else {
589 NSColor* sRGBColor = 738 NSColor* sRGBColor =
590 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); 739 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode);
591 NSColor* deviceColor = 740 NSColor* deviceColor =
592 [sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; 741 [sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
593 vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor); 742 vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor);
594 } 743 }
595 } 744 }
596 } 745 }
597 746
598 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); 747 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE);
599 NSImage* image = NSImageFromImageSkiaWithColorSpace( 748 NSImage* image =
600 gfx::CreateVectorIcon(vector_icon_id, icon_size, vector_icon_color), 749 [LocationBarImageRep imageForId:vector_icon_id color:vector_icon_color];
601 base::mac::GetSRGBColorSpace());
602 750
603 location_icon_decoration_->SetImage(image); 751 location_icon_decoration_->SetImage(image);
604 ev_bubble_decoration_->SetImage(image); 752 ev_bubble_decoration_->SetImage(image);
605 Layout(); 753 Layout();
606 } 754 }
607 755
608 void LocationBarViewMac::UpdateColorsToMatchTheme() { 756 void LocationBarViewMac::UpdateColorsToMatchTheme() {
609 if (!ui::MaterialDesignController::IsModeMaterial() || 757 if (!ui::MaterialDesignController::IsModeMaterial() ||
610 ![[field_ window] inIncognitoMode]) { 758 ![[field_ window] inIncognitoMode]) {
611 return; 759 return;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 969
822 return zoom_decoration_->UpdateIfNecessary( 970 return zoom_decoration_->UpdateIfNecessary(
823 ui_zoom::ZoomController::FromWebContents(web_contents), 971 ui_zoom::ZoomController::FromWebContents(web_contents),
824 default_zoom_changed, IsLocationBarDark()); 972 default_zoom_changed, IsLocationBarDark());
825 } 973 }
826 974
827 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 975 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
828 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 976 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
829 OnDecorationsChanged(); 977 OnDecorationsChanged();
830 } 978 }
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