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/first_run/welcome_to_chrome_view.h" | 5 #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h" | 10 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 // The width of the container view for a REGULAR width size class. | 38 // The width of the container view for a REGULAR width size class. |
39 const CGFloat kContainerViewRegularWidth = 510.0; | 39 const CGFloat kContainerViewRegularWidth = 510.0; |
40 | 40 |
41 // The percentage of the view's width taken up by the container view for a | 41 // The percentage of the view's width taken up by the container view for a |
42 // COMPACT width size class. | 42 // COMPACT width size class. |
43 const CGFloat kContainerViewCompactWidthPercentage = 0.8; | 43 const CGFloat kContainerViewCompactWidthPercentage = 0.8; |
44 | 44 |
45 // Layout constants. | 45 // Layout constants. |
46 const CGFloat kImageTopPadding[SIZE_CLASS_COUNT] = {32.0, 50.0}; | 46 const CGFloat kImageTopPadding[SIZE_CLASS_COUNT] = {32.0, 50.0}; |
47 const CGFloat kTOSLabelTopPadding[SIZE_CLASS_COUNT] = {34.0, 40.0}; | 47 const CGFloat kTOSLabelTopPadding[SIZE_CLASS_COUNT] = {34.0, 40.0}; |
48 const CGFloat kOptInLabelTopPadding[SIZE_CLASS_COUNT] = {10.0, 14.0}; | 48 const CGFloat kOptInLabelPadding[SIZE_CLASS_COUNT] = {10.0, 14.0}; |
49 const CGFloat kCheckBoxPadding[SIZE_CLASS_COUNT] = {10.0, 16.0}; | 49 const CGFloat kCheckBoxPadding[SIZE_CLASS_COUNT] = {10.0, 16.0}; |
50 const CGFloat kOKButtonBottomPadding[SIZE_CLASS_COUNT] = {32.0, 32.0}; | 50 const CGFloat kOKButtonBottomPadding[SIZE_CLASS_COUNT] = {32.0, 32.0}; |
51 const CGFloat kOKButtonHeight[SIZE_CLASS_COUNT] = {36.0, 54.0}; | 51 const CGFloat kOKButtonHeight[SIZE_CLASS_COUNT] = {36.0, 54.0}; |
52 // Multiplier matches that used in LaunchScreen.xib to determine size of logo. | 52 // Multiplier matches that used in LaunchScreen.xib to determine size of logo. |
53 const CGFloat kAppLogoProportionMultiplier = 0.381966; | 53 const CGFloat kAppLogoProportionMultiplier = 0.381966; |
54 | 54 |
55 // Font sizes. | 55 // Font sizes. |
56 const CGFloat kTitleLabelFontSize[SIZE_CLASS_COUNT] = {24.0, 36.0}; | 56 const CGFloat kTitleLabelFontSize[SIZE_CLASS_COUNT] = {24.0, 36.0}; |
57 const CGFloat kTOSLabelFontSize[SIZE_CLASS_COUNT] = {14.0, 21.0}; | 57 const CGFloat kTOSLabelFontSize[SIZE_CLASS_COUNT] = {14.0, 21.0}; |
58 const CGFloat kTOSLabelLineHeight[SIZE_CLASS_COUNT] = {20.0, 32.0}; | 58 const CGFloat kTOSLabelLineHeight[SIZE_CLASS_COUNT] = {20.0, 32.0}; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 [self configureSubviews]; | 319 [self configureSubviews]; |
320 } | 320 } |
321 | 321 |
322 - (void)layoutSubviews { | 322 - (void)layoutSubviews { |
323 [super layoutSubviews]; | 323 [super layoutSubviews]; |
324 [self layoutTitleLabel]; | 324 [self layoutTitleLabel]; |
325 [self layoutImageView]; | 325 [self layoutImageView]; |
326 [self layoutTOSLabel]; | 326 [self layoutTOSLabel]; |
327 [self layoutOptInLabel]; | 327 [self layoutOptInLabel]; |
328 [self layoutCheckBoxButton]; | 328 [self layoutCheckBoxButton]; |
| 329 // The OK Button must be laid out before the container view so that the |
| 330 // container view can take its position into account. |
| 331 [self layoutOKButton]; |
329 [self layoutContainerView]; | 332 [self layoutContainerView]; |
330 [self layoutOKButton]; | |
331 } | 333 } |
332 | 334 |
333 - (void)layoutTitleLabel { | 335 - (void)layoutTitleLabel { |
334 // The label is centered and top-aligned with the container view. | 336 // The label is centered and top-aligned with the container view. |
335 CGSize containerSize = self.containerView.bounds.size; | 337 CGSize containerSize = self.containerView.bounds.size; |
336 containerSize.height = CGFLOAT_MAX; | 338 containerSize.height = CGFLOAT_MAX; |
337 CGSize titleLabelSize = [self.titleLabel sizeThatFits:containerSize]; | 339 CGSize titleLabelSize = [self.titleLabel sizeThatFits:containerSize]; |
338 self.titleLabel.frame = AlignRectOriginAndSizeToPixels( | 340 self.titleLabel.frame = AlignRectOriginAndSizeToPixels( |
339 CGRectMake((containerSize.width - titleLabelSize.width) / 2.0, 0.0, | 341 CGRectMake((containerSize.width - titleLabelSize.width) / 2.0, 0.0, |
340 titleLabelSize.width, titleLabelSize.height)); | 342 titleLabelSize.width, titleLabelSize.height)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 CGSize TOSLabelSize = [self.TOSLabel sizeThatFits:containerSize]; | 393 CGSize TOSLabelSize = [self.TOSLabel sizeThatFits:containerSize]; |
392 CGFloat TOSLabelTopPadding = kTOSLabelTopPadding[self.cr_heightSizeClass]; | 394 CGFloat TOSLabelTopPadding = kTOSLabelTopPadding[self.cr_heightSizeClass]; |
393 self.TOSLabel.frame = AlignRectOriginAndSizeToPixels( | 395 self.TOSLabel.frame = AlignRectOriginAndSizeToPixels( |
394 CGRectMake((containerSize.width - TOSLabelSize.width) / 2.0, | 396 CGRectMake((containerSize.width - TOSLabelSize.width) / 2.0, |
395 CGRectGetMaxY(self.imageView.frame) + TOSLabelTopPadding, | 397 CGRectGetMaxY(self.imageView.frame) + TOSLabelTopPadding, |
396 TOSLabelSize.width, TOSLabelSize.height)); | 398 TOSLabelSize.width, TOSLabelSize.height)); |
397 } | 399 } |
398 | 400 |
399 - (void)layoutOptInLabel { | 401 - (void)layoutOptInLabel { |
400 // The opt in label is laid out to the right (or left in RTL) of the check box | 402 // The opt in label is laid out to the right (or left in RTL) of the check box |
401 // button and below |TOSLabel| as specified by kOptInLabelTopPadding. | 403 // button and below |TOSLabel| as specified by kOptInLabelPadding. |
402 CGSize checkBoxSize = | 404 CGSize checkBoxSize = |
403 [self.checkBoxButton imageForState:self.checkBoxButton.state].size; | 405 [self.checkBoxButton imageForState:self.checkBoxButton.state].size; |
404 CGFloat checkBoxPadding = kCheckBoxPadding[self.cr_widthSizeClass]; | 406 CGFloat checkBoxPadding = kCheckBoxPadding[self.cr_widthSizeClass]; |
405 CGFloat optInLabelSidePadding = checkBoxSize.width + 2.0 * checkBoxPadding; | 407 CGFloat optInLabelSidePadding = checkBoxSize.width + 2.0 * checkBoxPadding; |
406 CGSize optInLabelSize = [self.optInLabel | 408 CGSize optInLabelSize = [self.optInLabel |
407 sizeThatFits:CGSizeMake(CGRectGetWidth(self.containerView.bounds) - | 409 sizeThatFits:CGSizeMake(CGRectGetWidth(self.containerView.bounds) - |
408 optInLabelSidePadding, | 410 optInLabelSidePadding, |
409 CGFLOAT_MAX)]; | 411 CGFLOAT_MAX)]; |
410 CGFloat optInLabelTopPadding = kOptInLabelTopPadding[self.cr_heightSizeClass]; | 412 CGFloat optInLabelTopPadding = kOptInLabelPadding[self.cr_heightSizeClass]; |
411 CGFloat optInLabelOriginX = | 413 CGFloat optInLabelOriginX = |
412 base::i18n::IsRTL() ? 0.0f : optInLabelSidePadding; | 414 base::i18n::IsRTL() ? 0.0f : optInLabelSidePadding; |
413 self.optInLabel.frame = AlignRectOriginAndSizeToPixels( | 415 self.optInLabel.frame = AlignRectOriginAndSizeToPixels( |
414 CGRectMake(optInLabelOriginX, | 416 CGRectMake(optInLabelOriginX, |
415 CGRectGetMaxY(self.TOSLabel.frame) + optInLabelTopPadding, | 417 CGRectGetMaxY(self.TOSLabel.frame) + optInLabelTopPadding, |
416 optInLabelSize.width, optInLabelSize.height)); | 418 optInLabelSize.width, optInLabelSize.height)); |
417 ios_internal::FixOrphanWord(self.optInLabel); | 419 ios_internal::FixOrphanWord(self.optInLabel); |
418 } | 420 } |
419 | 421 |
420 - (void)layoutCheckBoxButton { | 422 - (void)layoutCheckBoxButton { |
(...skipping 19 matching lines...) Expand all Loading... |
440 self.checkBoxButton.imageEdgeInsets = UIEdgeInsetsMake( | 442 self.checkBoxButton.imageEdgeInsets = UIEdgeInsetsMake( |
441 (checkBoxButtonSize.height - checkBoxSize.height) / 2.0, | 443 (checkBoxButtonSize.height - checkBoxSize.height) / 2.0, |
442 base::i18n::IsRTL() ? largeHorizontalInset : smallHorizontalInset, | 444 base::i18n::IsRTL() ? largeHorizontalInset : smallHorizontalInset, |
443 (checkBoxButtonSize.height - checkBoxSize.height) / 2.0, | 445 (checkBoxButtonSize.height - checkBoxSize.height) / 2.0, |
444 base::i18n::IsRTL() ? smallHorizontalInset : largeHorizontalInset); | 446 base::i18n::IsRTL() ? smallHorizontalInset : largeHorizontalInset); |
445 } | 447 } |
446 | 448 |
447 - (void)layoutContainerView { | 449 - (void)layoutContainerView { |
448 // The container view is resized according to the final layout of | 450 // The container view is resized according to the final layout of |
449 // |checkBoxButton|, which is its lowest subview. The resized view is then | 451 // |checkBoxButton|, which is its lowest subview. The resized view is then |
450 // centered horizontally and vertically. | 452 // centered horizontally and vertically. If necessary, it is shifted up to |
| 453 // allow |kOptInLabelPadding| between |optInLabel| and |OKButton|. |
451 CGSize containerViewSize = self.containerView.bounds.size; | 454 CGSize containerViewSize = self.containerView.bounds.size; |
452 containerViewSize.height = CGRectGetMaxY(self.checkBoxButton.frame); | 455 containerViewSize.height = CGRectGetMaxY(self.checkBoxButton.frame); |
| 456 |
| 457 CGFloat padding = kOptInLabelPadding[self.cr_heightSizeClass]; |
| 458 CGFloat originY = fmin( |
| 459 (CGRectGetHeight(self.bounds) - containerViewSize.height) / 2.0, |
| 460 CGRectGetMinY(self.OKButton.frame) - padding - containerViewSize.height); |
| 461 |
453 self.containerView.frame = AlignRectOriginAndSizeToPixels(CGRectMake( | 462 self.containerView.frame = AlignRectOriginAndSizeToPixels(CGRectMake( |
454 (CGRectGetWidth(self.bounds) - containerViewSize.width) / 2.0, | 463 (CGRectGetWidth(self.bounds) - containerViewSize.width) / 2.0, originY, |
455 (CGRectGetHeight(self.bounds) - containerViewSize.height) / 2.0, | |
456 containerViewSize.width, CGRectGetMaxY(self.checkBoxButton.frame))); | 464 containerViewSize.width, CGRectGetMaxY(self.checkBoxButton.frame))); |
457 } | 465 } |
458 | 466 |
459 - (void)layoutOKButton { | 467 - (void)layoutOKButton { |
460 // The OK button is laid out at the bottom of the view as specified by | 468 // The OK button is laid out at the bottom of the view as specified by |
461 // kOKButtonBottomPadding. | 469 // kOKButtonBottomPadding. |
462 CGFloat OKButtonBottomPadding = | 470 CGFloat OKButtonBottomPadding = |
463 kOKButtonBottomPadding[self.cr_widthSizeClass]; | 471 kOKButtonBottomPadding[self.cr_widthSizeClass]; |
464 CGSize OKButtonSize = self.OKButton.bounds.size; | 472 CGSize OKButtonSize = self.OKButton.bounds.size; |
465 self.OKButton.frame = AlignRectOriginAndSizeToPixels(CGRectMake( | 473 self.OKButton.frame = AlignRectOriginAndSizeToPixels(CGRectMake( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 552 |
545 - (void)OKButtonWasTapped { | 553 - (void)OKButtonWasTapped { |
546 [self.delegate welcomeToChromeViewDidTapOKButton:self]; | 554 [self.delegate welcomeToChromeViewDidTapOKButton:self]; |
547 } | 555 } |
548 | 556 |
549 - (void)TOSLinkWasTapped { | 557 - (void)TOSLinkWasTapped { |
550 [self.delegate welcomeToChromeViewDidTapTOSLink:self]; | 558 [self.delegate welcomeToChromeViewDidTapTOSLink:self]; |
551 } | 559 } |
552 | 560 |
553 @end | 561 @end |
OLD | NEW |