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

Side by Side Diff: ios/chrome/browser/ui/sad_tab/sad_tab_view.mm

Issue 2905953003: Use UITextView for better bulleted list presentation (Closed)
Patch Set: Small tweaks Created 3 years, 7 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 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/sad_tab/sad_tab_view.h" 5 #import "ios/chrome/browser/ui/sad_tab/sad_tab_view.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "components/grit/components_scaled_resources.h" 8 #include "components/grit/components_scaled_resources.h"
9 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
10 #include "ios/chrome/browser/chrome_url_constants.h" 10 #include "ios/chrome/browser/chrome_url_constants.h"
(...skipping 12 matching lines...) Expand all
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 24
25 #if !defined(__has_feature) || !__has_feature(objc_arc) 25 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support." 26 #error "This file requires ARC support."
27 #endif 27 #endif
28 28
29 namespace { 29 namespace {
30 // Color constants. 30 // Color constants.
31 const CGFloat kBackgroundColorBrightness = 247.0f / 255.0f; 31 const CGFloat kBackgroundColorBrightness = 247.0f / 255.0f;
32 const CGFloat kTitleLabelTextColorBrightness = 22.0f / 255.0f; 32 const CGFloat kTitleLabelTextColorBrightness = 22.0f / 255.0f;
33 const CGFloat kMessageLabelTextColorBrightness = 80.0f / 255.0f; 33 const CGFloat kGeneralTextColorBrightness = 80.0f / 255.0f;
34 // Layout constants. 34 // Layout constants.
35 const UIEdgeInsets kLayoutInsets = {24.0f, 24.0f, 24.0f, 24.0f}; 35 const UIEdgeInsets kLayoutInsets = {24.0f, 24.0f, 24.0f, 24.0f};
36 const CGFloat kLayoutBoundsMaxWidth = 600.0f; 36 const CGFloat kLayoutBoundsMaxWidth = 600.0f;
37 const CGFloat kContainerViewLandscapeTopPadding = 22.0f; 37 const CGFloat kContainerViewLandscapeTopPadding = 22.0f;
38 const CGFloat kTitleLabelTopPadding = 26.0f; 38 const CGFloat kTitleLabelTopPadding = 26.0f;
39 const CGFloat kMessageLabelTopPadding = 16.0f; 39 const CGFloat kMessageTextViewTopPadding = 16.0f;
40 const CGFloat kFooterLabelTopPadding = 16.0f; 40 const CGFloat kFooterLabelTopPadding = 16.0f;
41 const CGFloat kActionButtonHeight = 48.0f; 41 const CGFloat kActionButtonHeight = 48.0f;
42 const CGFloat kActionButtonTopPadding = 16.0f; 42 const CGFloat kActionButtonTopPadding = 16.0f;
43 // Label font sizes. 43 // Label font sizes.
44 const CGFloat kTitleLabelFontSize = 23.0f; 44 const CGFloat kTitleLabelFontSize = 23.0f;
45 const CGFloat kMessageLabelFontSize = 14.0f; 45 const CGFloat kMessageTextViewFontSize = 14.0f;
46 const CGFloat kFooterLabelFontSize = 14.0f; 46 const CGFloat kFooterLabelFontSize = 14.0f;
47 // String constants for formatting bullets. 47 // Feedback message bullet indentation.
48 // "<5xSpace><Bullet><4xSpace><Content>". 48 const CGFloat kBulletIndent = 17.0f; // Left margin to bullet indent.
49 NSString* const kMessageLabelBulletPrefix = @" \u2022 "; 49 const CGFloat kBulletedTextIndent = 15.0f; // Bullet to text indent.
50 // "<newline>". 50 // Format for bulleted line (<tab><bullet><tab><string>).
51 NSString* const kMessageLabelBulletSuffix = @"\n"; 51 NSString* const kMessageTextViewBulletPrefix = @"\t\u2022\t";
52 // Separator for each new bullet line.
53 NSString* const kMessageTextViewBulletSuffix = @"\n";
52 // "<RTL Begin Indicator><NSString Token><RTL End Indicator>". 54 // "<RTL Begin Indicator><NSString Token><RTL End Indicator>".
53 NSString* const kMessageLabelBulletRTLFormat = @"\u202E%@\u202C"; 55 NSString* const kMessageTextViewBulletRTLFormat = @"\u202E%@\u202C";
54 } // namespace 56 } // namespace
55 57
56 @interface SadTabView () 58 @interface SadTabView ()
57 59
58 // Container view that displays all other subviews. 60 // Container view that displays all other subviews.
59 @property(nonatomic, readonly, strong) UIView* containerView; 61 @property(nonatomic, readonly, strong) UIView* containerView;
60 // Displays the Sad Tab face. 62 // Displays the Sad Tab face.
61 @property(nonatomic, readonly, strong) UIImageView* imageView; 63 @property(nonatomic, readonly, strong) UIImageView* imageView;
62 // Displays the Sad Tab title. 64 // Displays the Sad Tab title.
63 @property(nonatomic, readonly, strong) UILabel* titleLabel; 65 @property(nonatomic, readonly, strong) UILabel* titleLabel;
64 // Displays the Sad Tab message. 66 // Displays the Sad Tab message.
65 @property(nonatomic, readonly, strong) UILabel* messageLabel; 67 @property(nonatomic, readonly, strong) UITextView* messageTextView;
66 // Displays the Sad Tab footer message (including a link to more help). 68 // Displays the Sad Tab footer message (including a link to more help).
67 @property(nonatomic, readonly, strong) UILabel* footerLabel; 69 @property(nonatomic, readonly, strong) UILabel* footerLabel;
68 // Provides Link functionality to the footerLabel. 70 // Provides Link functionality to the footerLabel.
69 @property(nonatomic, readonly, strong) 71 @property(nonatomic, readonly, strong)
70 LabelLinkController* footerLabelLinkController; 72 LabelLinkController* footerLabelLinkController;
71 // Triggers a reload or feedback action. 73 // Triggers a reload or feedback action.
72 @property(nonatomic, readonly, strong) MDCFlatButton* actionButton; 74 @property(nonatomic, readonly, strong) MDCFlatButton* actionButton;
73 // The bounds of |containerView|, with a height updated to CGFLOAT_MAX to allow 75 // The bounds of |containerView|, with a height updated to CGFLOAT_MAX to allow
74 // text to be laid out using as many lines as necessary. 76 // text to be laid out using as many lines as necessary.
75 @property(nonatomic, readonly) CGRect containerBounds; 77 @property(nonatomic, readonly) CGRect containerBounds;
76 // Allows this view to perform navigation actions such as reloading. 78 // Allows this view to perform navigation actions such as reloading.
77 @property(nonatomic, readonly) web::NavigationManager* navigationManager; 79 @property(nonatomic, readonly) web::NavigationManager* navigationManager;
78 80
79 // Subview layout methods. Must be called in the following order, as subsequent 81 // Subview layout methods. Must be called in the following order, as subsequent
80 // layouts reference the values set in previous functions. 82 // layouts reference the values set in previous functions.
81 - (void)layoutImageView; 83 - (void)layoutImageView;
82 - (void)layoutTitleLabel; 84 - (void)layoutTitleLabel;
83 - (void)layoutMessageLabel; 85 - (void)layoutMessageTextView;
84 - (void)layoutFooterLabel; 86 - (void)layoutFooterLabel;
85 - (void)layoutActionButton; 87 - (void)layoutActionButton;
86 - (void)layoutContainerView; 88 - (void)layoutContainerView;
87 89
88 // Takes an array of strings and bulletizes them into a single multi-line string 90 // Takes an array of strings and bulletizes them into a single multi-line string
89 // for display. 91 // for display. The string has NSParagraphStyle attributes for tab alignment.
90 + (nonnull NSString*)bulletedStringFromStrings: 92 + (nonnull NSAttributedString*)bulletedAttributedStringFromStrings:
91 (nonnull NSArray<NSString*>*)strings; 93 (nonnull NSArray<NSString*>*)strings;
92 94
93 // Returns the appropriate title for the view, e.g. 'Aw Snap!'. 95 // Returns the appropriate title for the view, e.g. 'Aw Snap!'.
94 - (nonnull NSString*)titleLabelText; 96 - (nonnull NSString*)titleLabelText;
95 // Returns the appropriate message label body for the view, this will typically 97 // Returns the appropriate message text body for the view, this will typically
96 // be a larger body of explanation or help text. 98 // be a larger body of explanation or help text. Returns an attributed string
97 - (nonnull NSString*)messageLabelText; 99 // to allow for text formatting and layout to be applied to the returned string.
100 - (nonnull NSAttributedString*)messageTextViewAttributedText;
98 // Returns the full footer string containing a link, intended to be the last 101 // Returns the full footer string containing a link, intended to be the last
99 // piece of text. 102 // piece of text.
100 - (nonnull NSString*)footerLabelText; 103 - (nonnull NSString*)footerLabelText;
101 // Returns the substring of the footer string which is to be the underlined link 104 // Returns the substring of the footer string which is to be the underlined link
102 // text. (May be the entire footer label string). 105 // text. (May be the entire footer label string).
103 - (nonnull NSString*)footerLinkText; 106 - (nonnull NSString*)footerLinkText;
104 // Returns the string to be used for the main action button. 107 // Returns the string to be used for the main action button.
105 - (nonnull NSString*)buttonText; 108 - (nonnull NSString*)buttonText;
106 109
107 // Attaches a link controller to |label|, finding the |linkString| 110 // Attaches a link controller to |label|, finding the |linkString|
108 // within the |label| text to use as the link. 111 // within the |label| text to use as the link.
109 - (void)attachLinkControllerToLabel:(nonnull UILabel*)label 112 - (void)attachLinkControllerToLabel:(nonnull UILabel*)label
110 forLinkText:(nonnull NSString*)linkText; 113 forLinkText:(nonnull NSString*)linkText;
111 114
112 // The action selector for |_actionButton|. 115 // The action selector for |_actionButton|.
113 - (void)handleActionButtonTapped:(id)sender; 116 - (void)handleActionButtonTapped:(id)sender;
114 117
115 // Returns the desired background color. 118 // Returns the desired background color.
116 + (UIColor*)sadTabBackgroundColor; 119 + (UIColor*)sadTabBackgroundColor;
117 120
118 @end 121 @end
119 122
120 #pragma mark - SadTabView 123 #pragma mark - SadTabView
121 124
122 @implementation SadTabView 125 @implementation SadTabView
123 126
124 @synthesize imageView = _imageView; 127 @synthesize imageView = _imageView;
125 @synthesize containerView = _containerView; 128 @synthesize containerView = _containerView;
126 @synthesize titleLabel = _titleLabel; 129 @synthesize titleLabel = _titleLabel;
127 @synthesize messageLabel = _messageLabel; 130 @synthesize messageTextView = _messageTextView;
128 @synthesize footerLabel = _footerLabel; 131 @synthesize footerLabel = _footerLabel;
129 @synthesize footerLabelLinkController = _footerLabelLinkController; 132 @synthesize footerLabelLinkController = _footerLabelLinkController;
130 @synthesize actionButton = _actionButton; 133 @synthesize actionButton = _actionButton;
131 @synthesize mode = _mode; 134 @synthesize mode = _mode;
132 @synthesize navigationManager = _navigationManager; 135 @synthesize navigationManager = _navigationManager;
133 136
134 - (instancetype)initWithMode:(SadTabViewMode)mode 137 - (instancetype)initWithMode:(SadTabViewMode)mode
135 navigationManager:(web::NavigationManager*)navigationManager { 138 navigationManager:(web::NavigationManager*)navigationManager {
136 self = [super initWithFrame:CGRectZero]; 139 self = [super initWithFrame:CGRectZero];
137 if (self) { 140 if (self) {
(...skipping 14 matching lines...) Expand all
152 return nil; 155 return nil;
153 } 156 }
154 157
155 - (instancetype)initWithCoder:(NSCoder*)aDecoder { 158 - (instancetype)initWithCoder:(NSCoder*)aDecoder {
156 NOTREACHED(); 159 NOTREACHED();
157 return nil; 160 return nil;
158 } 161 }
159 162
160 #pragma mark - Text Utilities 163 #pragma mark - Text Utilities
161 164
162 + (nonnull NSString*)bulletedStringFromStrings: 165 + (nonnull NSAttributedString*)bulletedAttributedStringFromStrings:
163 (nonnull NSArray<NSString*>*)strings { 166 (nonnull NSArray<NSString*>*)strings {
164 // Ensures the bullet string is appropriately directional. 167 // Ensures the bullet string is appropriately directional.
165 NSString* directionalBulletPrefix = 168 NSString* directionalBulletPrefix =
166 base::i18n::IsRTL() 169 base::i18n::IsRTL()
167 ? [NSString stringWithFormat:kMessageLabelBulletRTLFormat, 170 ? [NSString stringWithFormat:kMessageTextViewBulletRTLFormat,
168 kMessageLabelBulletPrefix] 171 kMessageTextViewBulletPrefix]
169 : kMessageLabelBulletPrefix; 172 : kMessageTextViewBulletPrefix;
170 NSMutableString* bulletedString = [NSMutableString string]; 173
174 // Assemble the strings into a single string with each line preceded by a
175 // bullet point.
176 NSMutableString* bulletedString = [[NSMutableString string];
pkl (ping after 24h if needed) 2017/05/26 21:51:17 Looks like you have one too many (stray) [ here.
PL 2017/05/26 21:56:30 Ha wow, thanks amazing spot! This was a last minut
171 for (NSString* string in strings) { 177 for (NSString* string in strings) {
172 // If content line has been added to the bulletedString already, ensure the 178 // If content line has been added to the bulletedString already, ensure the
173 // suffix is applied, otherwise don't (e.g. don't for the first item). 179 // suffix is applied, otherwise don't (e.g. don't for the first item).
174 NSArray* newStringArray = 180 NSArray* newStringArray =
175 bulletedString.length 181 bulletedString.length
176 ? @[ kMessageLabelBulletSuffix, directionalBulletPrefix, string ] 182 ? @[ kMessageTextViewBulletSuffix, directionalBulletPrefix, string ]
177 : @[ directionalBulletPrefix, string ]; 183 : @[ directionalBulletPrefix, string ];
178 [bulletedString appendString:[newStringArray componentsJoinedByString:@""]]; 184 [bulletedString appendString:[newStringArray componentsJoinedByString:@""]];
179 } 185 }
180 DCHECK(bulletedString); 186
181 return bulletedString; 187 // Prepare a paragraph style that will allow for the alignment of lines of
188 // text separately to the alignment of the bullet-points.
189 NSMutableParagraphStyle* paragraphStyle =
190 [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
191 paragraphStyle.tabStops = @[
192 [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentNatural
193 location:kBulletIndent
194 options:@{}],
195 [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentNatural
196 location:kBulletIndent + kBulletedTextIndent
197 options:@{}]
198 ];
199 paragraphStyle.firstLineHeadIndent = 0.0f;
200 paragraphStyle.headIndent = kBulletIndent + kBulletedTextIndent;
201
202 // Use the paragraph style on the full string.
203 NSAttributedString* bulletedAttributedString = [[NSAttributedString alloc]
204 initWithString:bulletedString
205 attributes:@{NSParagraphStyleAttributeName : paragraphStyle}];
206
207 DCHECK(bulletedAttributedString);
208 return bulletedAttributedString;
182 } 209 }
183 210
184 #pragma mark - Label Text 211 #pragma mark - Label Text
185 212
186 - (nonnull NSString*)titleLabelText { 213 - (nonnull NSString*)titleLabelText {
187 NSString* label = nil; 214 NSString* label = nil;
188 switch (self.mode) { 215 switch (self.mode) {
189 case SadTabViewMode::RELOAD: 216 case SadTabViewMode::RELOAD:
190 label = l10n_util::GetNSString(IDS_SAD_TAB_TITLE); 217 label = l10n_util::GetNSString(IDS_SAD_TAB_TITLE);
191 break; 218 break;
192 case SadTabViewMode::FEEDBACK: 219 case SadTabViewMode::FEEDBACK:
193 label = l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_TITLE); 220 label = l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_TITLE);
194 break; 221 break;
195 } 222 }
196 DCHECK(label); 223 DCHECK(label);
197 return label; 224 return label;
198 } 225 }
199 226
200 - (nonnull NSString*)messageLabelText { 227 - (nonnull NSAttributedString*)messageTextViewAttributedText {
201 NSString* label = nil; 228 NSAttributedString* label = nil;
202 switch (self.mode) { 229 switch (self.mode) {
203 case SadTabViewMode::RELOAD: 230 case SadTabViewMode::RELOAD:
204 label = l10n_util::GetNSString(IDS_SAD_TAB_MESSAGE); 231 label = [[NSAttributedString alloc]
232 initWithString:l10n_util::GetNSString(IDS_SAD_TAB_MESSAGE)];
205 break; 233 break;
206 case SadTabViewMode::FEEDBACK: 234 case SadTabViewMode::FEEDBACK: {
207 label = l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_TRY); 235 NSMutableAttributedString* feedbackString =
208 label = [label 236 [[NSMutableAttributedString alloc]
209 stringByAppendingFormat: 237 initWithString:[NSString
210 @"\n\n%@", [[self class] bulletedStringFromStrings:@[ 238 stringWithFormat:@"%@\n\n",
211 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_CLOSE_NOTABS), 239 l10n_util::GetNSString(
212 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_INCOGNITO), 240 IDS_SAD_TAB_RELOAD_TRY)]];
kkhorimoto 2017/05/26 21:40:22 Can we break this out into some local variables to
PL 2017/05/26 21:56:30 Absolutely, will do, thanks!
213 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_RESTART_BROWSER), 241 NSAttributedString* bulletedListString =
214 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_RESTART_DEVICE) 242 [[self class] bulletedAttributedStringFromStrings:@[
215 ]]]; 243 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_CLOSE_NOTABS),
244 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_INCOGNITO),
245 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_RESTART_BROWSER),
246 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_RESTART_DEVICE)
247 ]];
248 [feedbackString appendAttributedString:bulletedListString];
249 label = feedbackString;
250 }
216 251
217 break; 252 break;
pkl (ping after 24h if needed) 2017/05/26 21:51:17 "break" should go inside the {} blocks, based on m
PL 2017/05/26 21:56:30 Thanks! Will do.
218 } 253 }
219 DCHECK(label); 254 DCHECK(label);
220 return label; 255 return label;
221 } 256 }
222 257
223 - (nonnull NSString*)footerLabelText { 258 - (nonnull NSString*)footerLabelText {
224 NSString* label = nil; 259 NSString* label = nil;
225 switch (self.mode) { 260 switch (self.mode) {
226 case SadTabViewMode::RELOAD: { 261 case SadTabViewMode::RELOAD: {
227 base::string16 footerLinkText( 262 base::string16 footerLinkText(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 [_titleLabel setNumberOfLines:0]; 351 [_titleLabel setNumberOfLines:0];
317 [_titleLabel 352 [_titleLabel
318 setTextColor:[UIColor colorWithWhite:kTitleLabelTextColorBrightness 353 setTextColor:[UIColor colorWithWhite:kTitleLabelTextColorBrightness
319 alpha:1.0]]; 354 alpha:1.0]];
320 [_titleLabel setFont:[[MDFRobotoFontLoader sharedInstance] 355 [_titleLabel setFont:[[MDFRobotoFontLoader sharedInstance]
321 regularFontOfSize:kTitleLabelFontSize]]; 356 regularFontOfSize:kTitleLabelFontSize]];
322 } 357 }
323 return _titleLabel; 358 return _titleLabel;
324 } 359 }
325 360
326 - (UILabel*)messageLabel { 361 - (UITextView*)messageTextView {
327 if (!_messageLabel) { 362 if (!_messageTextView) {
328 _messageLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 363 _messageTextView = [[UITextView alloc] initWithFrame:CGRectZero];
329 [_messageLabel setBackgroundColor:self.backgroundColor]; 364 [_messageTextView setBackgroundColor:self.backgroundColor];
330 [_messageLabel setText:[self messageLabelText]]; 365 [_messageTextView setAttributedText:[self messageTextViewAttributedText]];
331 [_messageLabel setLineBreakMode:NSLineBreakByWordWrapping]; 366 _messageTextView.textContainer.lineFragmentPadding = 0.0f;
332 [_messageLabel setNumberOfLines:0]; 367 [_messageTextView
333 [_messageLabel 368 setTextColor:[UIColor colorWithWhite:kGeneralTextColorBrightness
334 setTextColor:[UIColor colorWithWhite:kMessageLabelTextColorBrightness
335 alpha:1.0]]; 369 alpha:1.0]];
336 [_messageLabel setFont:[[MDFRobotoFontLoader sharedInstance] 370 [_messageTextView setFont:[[MDFRobotoFontLoader sharedInstance]
337 regularFontOfSize:kMessageLabelFontSize]]; 371 regularFontOfSize:kMessageTextViewFontSize]];
338 } 372 }
339 return _messageLabel; 373 return _messageTextView;
340 } 374 }
341 375
342 - (UILabel*)footerLabel { 376 - (UILabel*)footerLabel {
343 if (!_footerLabel) { 377 if (!_footerLabel) {
344 _footerLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 378 _footerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
345 [_footerLabel setBackgroundColor:self.backgroundColor]; 379 [_footerLabel setBackgroundColor:self.backgroundColor];
346 [_footerLabel setNumberOfLines:0]; 380 [_footerLabel setNumberOfLines:0];
347 [_footerLabel setFont:[[MDFRobotoFontLoader sharedInstance] 381 [_footerLabel setFont:[[MDFRobotoFontLoader sharedInstance]
348 regularFontOfSize:kFooterLabelFontSize]]; 382 regularFontOfSize:kFooterLabelFontSize]];
349 [_footerLabel 383 [_footerLabel
350 setTextColor:[UIColor colorWithWhite:kMessageLabelTextColorBrightness 384 setTextColor:[UIColor colorWithWhite:kGeneralTextColorBrightness
351 alpha:1.0]]; 385 alpha:1.0]];
352 386
353 [_footerLabel setText:[self footerLabelText]]; 387 [_footerLabel setText:[self footerLabelText]];
354 [self attachLinkControllerToLabel:_footerLabel 388 [self attachLinkControllerToLabel:_footerLabel
355 forLinkText:[self footerLinkText]]; 389 forLinkText:[self footerLinkText]];
356 } 390 }
357 return _footerLabel; 391 return _footerLabel;
358 } 392 }
359 393
360 - (UIButton*)actionButton { 394 - (UIButton*)actionButton {
(...skipping 30 matching lines...) Expand all
391 [super willMoveToSuperview:newSuperview]; 425 [super willMoveToSuperview:newSuperview];
392 426
393 if (self.containerView.superview) { 427 if (self.containerView.superview) {
394 DCHECK_EQ(self.containerView.superview, self); 428 DCHECK_EQ(self.containerView.superview, self);
395 return; 429 return;
396 } 430 }
397 431
398 [self addSubview:self.containerView]; 432 [self addSubview:self.containerView];
399 [self.containerView addSubview:self.imageView]; 433 [self.containerView addSubview:self.imageView];
400 [self.containerView addSubview:self.titleLabel]; 434 [self.containerView addSubview:self.titleLabel];
401 [self.containerView addSubview:self.messageLabel]; 435 [self.containerView addSubview:self.messageTextView];
402 [self.containerView addSubview:self.footerLabel]; 436 [self.containerView addSubview:self.footerLabel];
403 } 437 }
404 438
405 - (void)layoutSubviews { 439 - (void)layoutSubviews {
406 [super layoutSubviews]; 440 [super layoutSubviews];
407 441
408 [self layoutImageView]; 442 [self layoutImageView];
409 [self layoutTitleLabel]; 443 [self layoutTitleLabel];
410 [self layoutMessageLabel]; 444 [self layoutMessageTextView];
411 [self layoutFooterLabel]; 445 [self layoutFooterLabel];
412 [self layoutActionButton]; 446 [self layoutActionButton];
413 [self layoutContainerView]; 447 [self layoutContainerView];
414 } 448 }
415 449
416 - (CGSize)sizeThatFits:(CGSize)size { 450 - (CGSize)sizeThatFits:(CGSize)size {
417 return size; 451 return size;
418 } 452 }
419 453
420 - (void)layoutImageView { 454 - (void)layoutImageView {
421 LayoutRect imageViewLayout = LayoutRectZero; 455 LayoutRect imageViewLayout = LayoutRectZero;
422 imageViewLayout.boundingWidth = CGRectGetWidth(self.containerBounds); 456 imageViewLayout.boundingWidth = CGRectGetWidth(self.containerBounds);
423 imageViewLayout.size = self.imageView.bounds.size; 457 imageViewLayout.size = self.imageView.bounds.size;
424 self.imageView.frame = 458 self.imageView.frame =
425 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(imageViewLayout)); 459 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(imageViewLayout));
426 } 460 }
427 461
428 - (void)layoutTitleLabel { 462 - (void)layoutTitleLabel {
429 CGRect containerBounds = self.containerBounds; 463 CGRect containerBounds = self.containerBounds;
430 LayoutRect titleLabelLayout = LayoutRectZero; 464 LayoutRect titleLabelLayout = LayoutRectZero;
431 titleLabelLayout.boundingWidth = CGRectGetWidth(containerBounds); 465 titleLabelLayout.boundingWidth = CGRectGetWidth(containerBounds);
432 titleLabelLayout.size = [self.titleLabel sizeThatFits:containerBounds.size]; 466 titleLabelLayout.size = [self.titleLabel sizeThatFits:containerBounds.size];
433 titleLabelLayout.position.originY = 467 titleLabelLayout.position.originY =
434 CGRectGetMaxY(self.imageView.frame) + kTitleLabelTopPadding; 468 CGRectGetMaxY(self.imageView.frame) + kTitleLabelTopPadding;
435 self.titleLabel.frame = 469 self.titleLabel.frame =
436 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(titleLabelLayout)); 470 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(titleLabelLayout));
437 } 471 }
438 472
439 - (void)layoutMessageLabel { 473 - (void)layoutMessageTextView {
440 CGRect containerBounds = self.containerBounds; 474 CGRect containerBounds = self.containerBounds;
441 LayoutRect messageLabelLayout = LayoutRectZero; 475 LayoutRect messageTextViewLayout = LayoutRectZero;
442 messageLabelLayout.boundingWidth = CGRectGetWidth(containerBounds); 476 messageTextViewLayout.boundingWidth = CGRectGetWidth(containerBounds);
443 messageLabelLayout.size = 477 messageTextViewLayout.size =
444 [self.messageLabel sizeThatFits:containerBounds.size]; 478 [self.messageTextView sizeThatFits:containerBounds.size];
445 messageLabelLayout.position.originY = 479 messageTextViewLayout.position.originY =
446 CGRectGetMaxY(self.titleLabel.frame) + kMessageLabelTopPadding; 480 CGRectGetMaxY(self.titleLabel.frame) + kMessageTextViewTopPadding;
447 self.messageLabel.frame = 481 self.messageTextView.frame =
448 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(messageLabelLayout)); 482 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(messageTextViewLayout));
449 } 483 }
450 484
451 - (void)layoutFooterLabel { 485 - (void)layoutFooterLabel {
452 CGRect containerBounds = self.containerBounds; 486 CGRect containerBounds = self.containerBounds;
453 LayoutRect footerLabelLayout = LayoutRectZero; 487 LayoutRect footerLabelLayout = LayoutRectZero;
454 footerLabelLayout.boundingWidth = CGRectGetWidth(containerBounds); 488 footerLabelLayout.boundingWidth = CGRectGetWidth(containerBounds);
455 footerLabelLayout.size = [self.footerLabel sizeThatFits:containerBounds.size]; 489 footerLabelLayout.size = [self.footerLabel sizeThatFits:containerBounds.size];
456 footerLabelLayout.position.originY = 490 footerLabelLayout.position.originY =
457 CGRectGetMaxY(self.messageLabel.frame) + kFooterLabelTopPadding; 491 CGRectGetMaxY(self.messageTextView.frame) + kFooterLabelTopPadding;
458 self.footerLabel.frame = 492 self.footerLabel.frame =
459 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(footerLabelLayout)); 493 AlignRectOriginAndSizeToPixels(LayoutRectGetRect(footerLabelLayout));
460 } 494 }
461 495
462 - (void)layoutActionButton { 496 - (void)layoutActionButton {
463 CGRect containerBounds = self.containerBounds; 497 CGRect containerBounds = self.containerBounds;
464 BOOL isIPadIdiom = IsIPadIdiom(); 498 BOOL isIPadIdiom = IsIPadIdiom();
465 BOOL isPortrait = IsPortrait(); 499 BOOL isPortrait = IsPortrait();
466 BOOL shouldAddActionButtonToContainer = isIPadIdiom || !isPortrait; 500 BOOL shouldAddActionButtonToContainer = isIPadIdiom || !isPortrait;
467 LayoutRect actionButtonLayout = LayoutRectZero; 501 LayoutRect actionButtonLayout = LayoutRectZero;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 break; 566 break;
533 } 567 }
534 }; 568 };
535 } 569 }
536 570
537 + (UIColor*)sadTabBackgroundColor { 571 + (UIColor*)sadTabBackgroundColor {
538 return [UIColor colorWithWhite:kBackgroundColorBrightness alpha:1.0]; 572 return [UIColor colorWithWhite:kBackgroundColorBrightness alpha:1.0];
539 } 573 }
540 574
541 @end 575 @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