OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/passwords/passwords_bubble_utils.h" | 5 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #import "chrome/browser/ui/cocoa/passwords/base_passwords_content_view_controlle
r.h" | 9 #include "chrome/browser/ui/chrome_style.h" |
10 #include "components/autofill/core/common/password_form.h" | 10 #include "skia/ext/skia_utils_mac.h" |
| 11 #include "ui/base/cocoa/controls/hyperlink_text_view.h" |
11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/resources/grit/ui_resources.h" | 14 #include "ui/resources/grit/ui_resources.h" |
14 | 15 |
15 NSFont* LabelFont() { | 16 NSFont* LabelFont() { |
16 return [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 17 return [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
17 } | 18 } |
18 | 19 |
19 NSSize LabelSize(int resourceID) { | 20 NSSize LabelSize(int resourceID) { |
20 return [l10n_util::GetNSString(resourceID) | 21 return [l10n_util::GetNSString(resourceID) |
(...skipping 28 matching lines...) Expand all Loading... |
49 columnsWidth.first + freeSpace * firstColumnPercent, | 50 columnsWidth.first + freeSpace * firstColumnPercent, |
50 columnsWidth.second + freeSpace * (1 - firstColumnPercent)); | 51 columnsWidth.second + freeSpace * (1 - firstColumnPercent)); |
51 } | 52 } |
52 | 53 |
53 NSSecureTextField* PasswordLabel(const base::string16& text) { | 54 NSSecureTextField* PasswordLabel(const base::string16& text) { |
54 base::scoped_nsobject<NSSecureTextField> textField( | 55 base::scoped_nsobject<NSSecureTextField> textField( |
55 [[NSSecureTextField alloc] initWithFrame:NSZeroRect]); | 56 [[NSSecureTextField alloc] initWithFrame:NSZeroRect]); |
56 InitLabel(textField, text); | 57 InitLabel(textField, text); |
57 return textField.autorelease(); | 58 return textField.autorelease(); |
58 } | 59 } |
| 60 |
| 61 NSButton* DialogButton(NSString* title) { |
| 62 base::scoped_nsobject<NSButton> button( |
| 63 [[NSButton alloc] initWithFrame:NSZeroRect]); |
| 64 [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 65 [button setTitle:title]; |
| 66 [button setBezelStyle:NSRoundedBezelStyle]; |
| 67 [[button cell] setControlSize:NSSmallControlSize]; |
| 68 [button sizeToFit]; |
| 69 return button.autorelease(); |
| 70 } |
| 71 |
| 72 HyperlinkTextView* TitleLabelWithLink(const base::string16& text, |
| 73 gfx::Range range, |
| 74 id<NSTextViewDelegate> delegate) { |
| 75 base::scoped_nsobject<HyperlinkTextView> titleView( |
| 76 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); |
| 77 NSColor* textColor = [NSColor blackColor]; |
| 78 NSFont* font = ResourceBundle::GetSharedInstance() |
| 79 .GetFontList(ResourceBundle::MediumFont) |
| 80 .GetPrimaryFont() |
| 81 .GetNativeFont(); |
| 82 [titleView setMessage:base::SysUTF16ToNSString(text) |
| 83 withFont:font |
| 84 messageColor:textColor]; |
| 85 NSRange titleBrandLinkRange = range.ToNSRange(); |
| 86 if (titleBrandLinkRange.length) { |
| 87 NSColor* linkColor = |
| 88 skia::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); |
| 89 [titleView addLinkRange:titleBrandLinkRange |
| 90 withURL:nil |
| 91 linkColor:linkColor]; |
| 92 [titleView setDelegate:delegate]; |
| 93 |
| 94 // Create the link with no underlining. |
| 95 [titleView setLinkTextAttributes:nil]; |
| 96 NSTextStorage* text = [titleView textStorage]; |
| 97 [text addAttribute:NSUnderlineStyleAttributeName |
| 98 value:@(NSUnderlineStyleNone) |
| 99 range:titleBrandLinkRange]; |
| 100 } else { |
| 101 // TODO(vasilii): remove if crbug.com/515189 is fixed. |
| 102 [titleView setRefusesFirstResponder:YES]; |
| 103 } |
| 104 |
| 105 return titleView.autorelease(); |
| 106 } |
OLD | NEW |