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 "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_cell_data.h" | 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_cell_data.h" |
6 #include "ios/chrome/grit/ios_strings.h" | 6 #include "ios/chrome/grit/ios_strings.h" |
7 #include "ui/base/l10n/l10n_util.h" | 7 #include "ui/base/l10n/l10n_util.h" |
8 | 8 |
9 @implementation SessionCellData | 9 @implementation SessionCellData |
10 | 10 |
11 @synthesize type = _type; | 11 @synthesize type = _type; |
12 @synthesize title = _title; | 12 @synthesize title = _title; |
13 @synthesize image = _image; | 13 @synthesize image = _image; |
14 | 14 |
15 + (instancetype)incognitoSessionCellData { | 15 + (instancetype)incognitoSessionCellData { |
16 static SessionCellData* incognitoSessionCellData = nil; | 16 static SessionCellData* incognitoSessionCellData = nil; |
17 static dispatch_once_t onceToken; | 17 static dispatch_once_t onceToken; |
18 dispatch_once(&onceToken, ^{ | 18 dispatch_once(&onceToken, ^{ |
19 incognitoSessionCellData = [[self alloc] | 19 incognitoSessionCellData = |
20 initWithSessionCellType:ios_internal::kIncognitoSessionCell]; | 20 [[self alloc] initWithSessionCellType:kIncognitoSessionCell]; |
21 }); | 21 }); |
22 return incognitoSessionCellData; | 22 return incognitoSessionCellData; |
23 } | 23 } |
24 | 24 |
25 + (instancetype)openTabSessionCellData { | 25 + (instancetype)openTabSessionCellData { |
26 static SessionCellData* openTabSessionCellData = nil; | 26 static SessionCellData* openTabSessionCellData = nil; |
27 static dispatch_once_t onceToken; | 27 static dispatch_once_t onceToken; |
28 dispatch_once(&onceToken, ^{ | 28 dispatch_once(&onceToken, ^{ |
29 openTabSessionCellData = [[self alloc] | 29 openTabSessionCellData = |
30 initWithSessionCellType:ios_internal::kOpenTabSessionCell]; | 30 [[self alloc] initWithSessionCellType:kOpenTabSessionCell]; |
31 }); | 31 }); |
32 return openTabSessionCellData; | 32 return openTabSessionCellData; |
33 } | 33 } |
34 | 34 |
35 + (instancetype)otherDevicesSessionCellData { | 35 + (instancetype)otherDevicesSessionCellData { |
36 static SessionCellData* otherDevicesSessionCellData = nil; | 36 static SessionCellData* otherDevicesSessionCellData = nil; |
37 static dispatch_once_t onceToken; | 37 static dispatch_once_t onceToken; |
38 dispatch_once(&onceToken, ^{ | 38 dispatch_once(&onceToken, ^{ |
39 otherDevicesSessionCellData = [[self alloc] | 39 otherDevicesSessionCellData = |
40 initWithSessionCellType:ios_internal::kGenericRemoteSessionCell]; | 40 [[self alloc] initWithSessionCellType:kGenericRemoteSessionCell]; |
41 }); | 41 }); |
42 return otherDevicesSessionCellData; | 42 return otherDevicesSessionCellData; |
43 } | 43 } |
44 | 44 |
45 - (instancetype)initWithSessionCellType:(ios_internal::SessionCellType)type { | 45 - (instancetype)initWithSessionCellType:(TabSwitcherSessionCellType)type { |
46 self = [super init]; | 46 self = [super init]; |
47 if (self) { | 47 if (self) { |
48 _type = type; | 48 _type = type; |
49 [self loadDefaultsForType]; | 49 [self loadDefaultsForType]; |
50 } | 50 } |
51 return self; | 51 return self; |
52 } | 52 } |
53 | 53 |
54 #pragma mark - Private | 54 #pragma mark - Private |
55 | 55 |
56 - (void)loadDefaultsForType { | 56 - (void)loadDefaultsForType { |
57 NSString* imageName = nil; | 57 NSString* imageName = nil; |
58 int messageId = 0; | 58 int messageId = 0; |
59 switch (self.type) { | 59 switch (self.type) { |
60 case ios_internal::kIncognitoSessionCell: | 60 case kIncognitoSessionCell: |
61 imageName = @"tabswitcher_incognito"; | 61 imageName = @"tabswitcher_incognito"; |
62 messageId = IDS_IOS_TAB_SWITCHER_HEADER_INCOGNITO_TABS; | 62 messageId = IDS_IOS_TAB_SWITCHER_HEADER_INCOGNITO_TABS; |
63 break; | 63 break; |
64 case ios_internal::kOpenTabSessionCell: | 64 case kOpenTabSessionCell: |
65 imageName = @"tabswitcher_open_tabs"; | 65 imageName = @"tabswitcher_open_tabs"; |
66 messageId = IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS; | 66 messageId = IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS; |
67 break; | 67 break; |
68 case ios_internal::kGenericRemoteSessionCell: | 68 case kGenericRemoteSessionCell: |
69 imageName = @"tabswitcher_other_devices"; | 69 imageName = @"tabswitcher_other_devices"; |
70 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; | 70 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
71 break; | 71 break; |
72 case ios_internal::kPhoneRemoteSessionCell: | 72 case kPhoneRemoteSessionCell: |
73 imageName = @"ntp_opentabs_phone"; | 73 imageName = @"ntp_opentabs_phone"; |
74 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; | 74 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
75 break; | 75 break; |
76 case ios_internal::kTabletRemoteSessionCell: | 76 case kTabletRemoteSessionCell: |
77 imageName = @"ntp_opentabs_tablet"; | 77 imageName = @"ntp_opentabs_tablet"; |
78 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; | 78 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
79 break; | 79 break; |
80 case ios_internal::kLaptopRemoteSessionCell: | 80 case kLaptopRemoteSessionCell: |
81 imageName = @"ntp_opentabs_laptop"; | 81 imageName = @"ntp_opentabs_laptop"; |
82 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; | 82 messageId = IDS_IOS_TAB_SWITCHER_HEADER_OTHER_DEVICES_TABS; |
83 break; | 83 break; |
84 } | 84 } |
85 [self setTitle:l10n_util::GetNSString(messageId)]; | 85 [self setTitle:l10n_util::GetNSString(messageId)]; |
86 UIImage* image = [UIImage imageNamed:imageName]; | 86 UIImage* image = [UIImage imageNamed:imageName]; |
87 image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; | 87 image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
88 [self setImage:image]; | 88 [self setImage:image]; |
89 } | 89 } |
90 | 90 |
91 @end | 91 @end |
OLD | NEW |