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

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm

Issue 2604273004: Style the Form-Not-Secure warning on Mac (Closed)
Patch Set: add comment Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/autofill/autofill_popup_view_cocoa.h" 5 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/mac_util.h"
8 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" 11 #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" 12 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
11 #include "chrome/browser/ui/autofill/popup_constants.h" 13 #include "chrome/browser/ui/autofill/popup_constants.h"
12 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" 14 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h"
13 #include "components/autofill/core/browser/popup_item_ids.h" 15 #include "components/autofill/core/browser/popup_item_ids.h"
14 #include "components/autofill/core/browser/suggestion.h" 16 #include "components/autofill/core/browser/suggestion.h"
15 #include "skia/ext/skia_utils_mac.h" 17 #include "skia/ext/skia_utils_mac.h"
16 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/base/cocoa/window_size_constants.h" 19 #include "ui/base/cocoa/window_size_constants.h"
18 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/color_palette.h"
19 #include "ui/gfx/font_list.h" 22 #include "ui/gfx/font_list.h"
20 #include "ui/gfx/geometry/point.h" 23 #include "ui/gfx/geometry/point.h"
21 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/image/image_skia_util_mac.h"
27 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/gfx/vector_icons_public.h"
23 29
24 using autofill::AutofillPopupView; 30 using autofill::AutofillPopupView;
25 using autofill::AutofillPopupLayoutModel; 31 using autofill::AutofillPopupLayoutModel;
26 32
27 @interface AutofillPopupViewCocoa () 33 @interface AutofillPopupViewCocoa ()
28 34
29 #pragma mark - 35 #pragma mark -
30 #pragma mark Private methods 36 #pragma mark Private methods
31 37
32 // Draws an Autofill suggestion in the given |bounds|, labeled with the given 38 // Draws an Autofill suggestion in the given |bounds|, labeled with the given
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 152
147 #pragma mark - 153 #pragma mark -
148 #pragma mark Private API: 154 #pragma mark Private API:
149 155
150 - (void)drawSuggestionWithName:(NSString*)name 156 - (void)drawSuggestionWithName:(NSString*)name
151 subtext:(NSString*)subtext 157 subtext:(NSString*)subtext
152 index:(size_t)index 158 index:(size_t)index
153 bounds:(NSRect)bounds 159 bounds:(NSRect)bounds
154 selected:(BOOL)isSelected 160 selected:(BOOL)isSelected
155 textYOffset:(CGFloat)textYOffset { 161 textYOffset:(CGFloat)textYOffset {
162 BOOL isHTTPWarning =
163 (controller_->GetSuggestionAt(index).frontend_id ==
164 autofill::POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE);
165
156 // If this row is selected, highlight it with this mac system color. 166 // If this row is selected, highlight it with this mac system color.
157 // Otherwise the controller may have a specific background color for this 167 // Otherwise the controller may have a specific background color for this
158 // entry. 168 // entry.
159 if (isSelected) { 169 if (isSelected) {
160 [[self highlightColor] set]; 170 [[self highlightColor] set];
161 [NSBezierPath fillRect:bounds]; 171 [NSBezierPath fillRect:bounds];
162 } else { 172 } else {
163 SkColor backgroundColor = controller_->GetBackgroundColorForRow(index); 173 SkColor backgroundColor = controller_->GetBackgroundColorForRow(index);
164 [skia::SkColorToSRGBNSColor(backgroundColor) set]; 174 [skia::SkColorToSRGBNSColor(backgroundColor) set];
165 [NSBezierPath fillRect:bounds]; 175 [NSBezierPath fillRect:bounds];
166 } 176 }
167 177
168 BOOL isRTL = controller_->IsRTL(); 178 BOOL isRTL = controller_->IsRTL();
169 179
170 // The X values of the left and right borders of the autofill widget. 180 // The X values of the left and right borders of the autofill widget.
171 CGFloat leftX = NSMinX(bounds) + AutofillPopupLayoutModel::kEndPadding; 181 CGFloat leftX = NSMinX(bounds) + AutofillPopupLayoutModel::kEndPadding;
172 CGFloat rightX = NSMaxX(bounds) - AutofillPopupLayoutModel::kEndPadding; 182 CGFloat rightX = NSMaxX(bounds) - AutofillPopupLayoutModel::kEndPadding;
173 183
174 // Draw left side if isRTL == NO, right side if isRTL == YES. 184 // Draw left side if isRTL == NO, right side if isRTL == YES.
175 CGFloat x = isRTL ? rightX : leftX; 185 CGFloat x = isRTL ? rightX : leftX;
186 if (isHTTPWarning) {
187 x = [self drawIconAtIndex:index atX:x rightAlign:isRTL bounds:bounds];
188 }
176 [self drawName:name 189 [self drawName:name
177 atX:x 190 atX:x
178 index:index 191 index:index
179 rightAlign:isRTL 192 rightAlign:isRTL
180 bounds:bounds 193 bounds:bounds
181 textYOffset:textYOffset]; 194 textYOffset:textYOffset];
182 195
183 // Draw right side if isRTL == NO, left side if isRTL == YES. 196 // Draw right side if isRTL == NO, left side if isRTL == YES.
184 x = isRTL ? leftX : rightX; 197 x = isRTL ? leftX : rightX;
185 x = [self drawIconAtIndex:index atX:x rightAlign:!isRTL bounds:bounds]; 198 if (!isHTTPWarning) {
199 x = [self drawIconAtIndex:index atX:x rightAlign:!isRTL bounds:bounds];
200 }
186 [self drawSubtext:subtext 201 [self drawSubtext:subtext
187 atX:x 202 atX:x
188 index:index 203 index:index
189 rightAlign:!isRTL 204 rightAlign:!isRTL
190 bounds:bounds 205 bounds:bounds
191 textYOffset:textYOffset]; 206 textYOffset:textYOffset];
192 } 207 }
193 208
194 - (CGFloat)drawName:(NSString*)name 209 - (CGFloat)drawName:(NSString*)name
195 atX:(CGFloat)x 210 atX:(CGFloat)x
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 x -= rightAlign ? subtextSize.width : 0; 271 x -= rightAlign ? subtextSize.width : 0;
257 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2; 272 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2;
258 y += textYOffset; 273 y += textYOffset;
259 274
260 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; 275 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes];
261 x += rightAlign ? 0 : subtextSize.width; 276 x += rightAlign ? 0 : subtextSize.width;
262 return x; 277 return x;
263 } 278 }
264 279
265 - (NSImage*)iconAtIndex:(size_t)index { 280 - (NSImage*)iconAtIndex:(size_t)index {
281 const int kHttpWarningIconWidth = 16;
266 const base::string16& icon = controller_->GetSuggestionAt(index).icon; 282 const base::string16& icon = controller_->GetSuggestionAt(index).icon;
267 if (icon.empty()) 283 if (icon.empty())
268 return nil; 284 return nil;
269 285
286 // For the Form-Not-Secure warning about password/credit card fields on HTTP
287 // pages, reuse the omnibox vector icons.
288 if (icon == base::ASCIIToUTF16("httpWarning")) {
Mathieu 2017/01/05 20:37:18 could you try removing https://cs.chromium.org/chr
estark 2017/01/05 21:24:45 I think we use rely on those lines on Android, no?
Robert Sesek 2017/01/06 22:28:10 Is there not a constant for this available?
estark 2017/01/07 03:34:40 Hmm, doesn't appear to be; these icons are selecte
289 return NSImageFromImageSkiaWithColorSpace(
290 gfx::CreateVectorIcon(gfx::VectorIconId::LOCATION_BAR_HTTP,
291 kHttpWarningIconWidth, gfx::kChromeIconGrey),
292 base::mac::GetSRGBColorSpace());
293 }
294
295 if (icon == base::ASCIIToUTF16("httpsInvalid")) {
296 return NSImageFromImageSkiaWithColorSpace(
297 gfx::CreateVectorIcon(gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID,
298 kHttpWarningIconWidth, gfx::kGoogleRed700),
299 base::mac::GetSRGBColorSpace());
300 }
301
270 int iconId = delegate_->GetIconResourceID(icon); 302 int iconId = delegate_->GetIconResourceID(icon);
271 DCHECK_NE(-1, iconId); 303 DCHECK_NE(-1, iconId);
272 304
273 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 305 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
274 return rb.GetNativeImageNamed(iconId).ToNSImage(); 306 return rb.GetNativeImageNamed(iconId).ToNSImage();
275 } 307 }
276 308
277 @end 309 @end
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