OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/today_extension/notification_center_url_button.h" | 5 #import "ios/chrome/today_extension/notification_center_url_button.h" |
6 | 6 |
7 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
8 #import "base/mac/scoped_block.h" | 8 #import "base/mac/scoped_block.h" |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #import "ios/chrome/common/physical_web/physical_web_device.h" | 11 #import "ios/chrome/common/physical_web/physical_web_device.h" |
12 #import "ios/chrome/today_extension/ui_util.h" | 12 #import "ios/chrome/today_extension/ui_util.h" |
13 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 const CGFloat kSubtitleFontSize = 14; | 17 const CGFloat kSubtitleFontSize = 14; |
18 } | 18 } |
19 | 19 |
20 @implementation NotificationCenterURLButton { | 20 @implementation NotificationCenterURLButton { |
21 base::mac::ScopedBlock<URLActionBlock> _openURLBlock; | 21 URLActionBlock _openURLBlock; |
22 base::scoped_nsobject<NSString> _url; | 22 base::scoped_nsobject<NSString> _url; |
23 base::scoped_nsobject<UILabel> _subtitleLabel; | 23 base::scoped_nsobject<UILabel> _subtitleLabel; |
24 base::scoped_nsobject<UIView> _bottomSeparator; | 24 base::scoped_nsobject<UIView> _bottomSeparator; |
25 } | 25 } |
26 | 26 |
27 - (void)openURL:(id)sender { | 27 - (void)openURL:(id)sender { |
28 _openURLBlock.get()(_url); | 28 if (_openURLBlock) { |
| 29 _openURLBlock(_url); |
| 30 } |
29 } | 31 } |
30 | 32 |
31 - (NSString*)unescapeURLString:(NSString*)urlString { | 33 - (NSString*)unescapeURLString:(NSString*)urlString { |
32 std::string escapedURL = base::SysNSStringToUTF8(urlString); | 34 std::string escapedURL = base::SysNSStringToUTF8(urlString); |
33 std::string unescapedURL = | 35 std::string unescapedURL = |
34 net::UnescapeURLComponent(escapedURL, net::UnescapeRule::SPACES); | 36 net::UnescapeURLComponent(escapedURL, net::UnescapeRule::SPACES); |
35 NSString* unescapedURLString = base::SysUTF8ToNSString(unescapedURL); | 37 NSString* unescapedURLString = base::SysUTF8ToNSString(unescapedURL); |
36 return unescapedURLString; | 38 return unescapedURLString; |
37 } | 39 } |
38 | 40 |
39 // Create a button with contextual URL layout. | 41 // Create a button with contextual URL layout. |
40 - (instancetype)initWithTitle:(NSString*)title | 42 - (instancetype)initWithTitle:(NSString*)title |
41 url:(NSString*)url | 43 url:(NSString*)url |
42 icon:(NSString*)icon | 44 icon:(NSString*)icon |
43 leftInset:(CGFloat)leftInset | 45 leftInset:(CGFloat)leftInset |
44 block:(URLActionBlock)block { | 46 block:(URLActionBlock)block { |
45 self = [super initWithTitle:title | 47 self = [super initWithTitle:title |
46 icon:nil | 48 icon:nil |
47 target:nil | 49 target:nil |
48 action:@selector(openURL:) | 50 action:@selector(openURL:) |
49 backgroundColor:[UIColor clearColor] | 51 backgroundColor:[UIColor clearColor] |
50 inkColor:ui_util::InkColor() | 52 inkColor:ui_util::InkColor() |
51 titleColor:ui_util::TitleColor()]; | 53 titleColor:ui_util::TitleColor()]; |
52 if (self) { | 54 if (self) { |
53 _openURLBlock.reset(block, base::scoped_policy::RETAIN); | 55 _openURLBlock = [block copy]; |
54 [self setContentVerticalAlignment:UIControlContentVerticalAlignmentTop]; | 56 [self setContentVerticalAlignment:UIControlContentVerticalAlignmentTop]; |
55 | 57 |
56 _url.reset([url copy]); | 58 _url.reset([url copy]); |
57 | 59 |
58 UIImage* iconImage = [[UIImage imageNamed:icon] | 60 UIImage* iconImage = [[UIImage imageNamed:icon] |
59 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; | 61 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
60 [self setImage:iconImage forState:UIControlStateNormal]; | 62 [self setImage:iconImage forState:UIControlStateNormal]; |
61 [[self imageView] setTintColor:ui_util::NormalTintColor()]; | 63 [[self imageView] setTintColor:ui_util::NormalTintColor()]; |
62 | 64 |
63 CGFloat chromeIconXOffset = leftInset + ui_util::ChromeIconOffset(); | 65 CGFloat chromeIconXOffset = leftInset + ui_util::ChromeIconOffset(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 [_subtitleLabel setTextColor:ui_util::TextColor()]; | 172 [_subtitleLabel setTextColor:ui_util::TextColor()]; |
171 [[self imageView] setTintColor:ui_util::NormalTintColor()]; | 173 [[self imageView] setTintColor:ui_util::NormalTintColor()]; |
172 } | 174 } |
173 } | 175 } |
174 | 176 |
175 - (void)setSeparatorVisible:(BOOL)visible { | 177 - (void)setSeparatorVisible:(BOOL)visible { |
176 [_bottomSeparator setHidden:!visible]; | 178 [_bottomSeparator setHidden:!visible]; |
177 } | 179 } |
178 | 180 |
179 @end | 181 @end |
OLD | NEW |