OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/page_not_available_controller.h" |
| 6 |
| 7 #include "base/i18n/rtl.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/mac/objc_property_releaser.h" |
| 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/strings/grit/components_strings.h" |
| 14 #include "components/url_formatter/url_formatter.h" |
| 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/l10n/l10n_util_mac.h" |
| 17 |
| 18 namespace { |
| 19 // Top padding for |self.titleLabel|. |
| 20 const CGFloat kTitleLabelTopPadding = 20.0; |
| 21 // Height for |self.titleLabel|. |
| 22 const CGFloat kTitleLabelHeight = 38.0; |
| 23 // Top padding for |self.descriptionView|. |
| 24 const CGFloat kDescriptionViewTopPadding = 66.0; |
| 25 // Bottom padding for |self.descriptionView|. |
| 26 const CGFloat kDescriptionViewBottomPadding = 20.0; |
| 27 // Horizontal padding between subviews and |self.view|. |
| 28 const CGFloat kHorizontalPadding = 20.0; |
| 29 // Font size for |self.titleLabel|. |
| 30 const CGFloat kTitleLabelFontSize = 18.0; |
| 31 // Font size for |self.descriptionView|. |
| 32 const CGFloat kDescriptionViewFontSize = 17.0; |
| 33 } |
| 34 |
| 35 @interface PageNotAvailableController () { |
| 36 base::mac::ObjCPropertyReleaser _propertyReleaser_PageNotAvailableController; |
| 37 } |
| 38 |
| 39 // The title label displayed centered at the top of the screen. |
| 40 @property(nonatomic, retain) UILabel* titleLabel; |
| 41 |
| 42 // TextView containing a detailed description of the problem. |
| 43 @property(nonatomic, retain) UITextView* descriptionView; |
| 44 |
| 45 @end |
| 46 |
| 47 @implementation PageNotAvailableController |
| 48 |
| 49 @synthesize titleLabel = _titleLabel; |
| 50 @synthesize descriptionView = _descriptionView; |
| 51 @synthesize descriptionText = _descriptionText; |
| 52 |
| 53 - (instancetype)initWithUrl:(const GURL&)url { |
| 54 self = [super initWithNibName:nil url:url]; |
| 55 if (self) { |
| 56 _propertyReleaser_PageNotAvailableController.Init( |
| 57 self, [PageNotAvailableController class]); |
| 58 |
| 59 // Use the host as the page title, unless the URL has a custom scheme. |
| 60 if (self.url.SchemeIsHTTPOrHTTPS()) { |
| 61 self.title = base::SysUTF16ToNSString( |
| 62 url_formatter::IDNToUnicode(self.url.host())); |
| 63 } else { |
| 64 base::string16 formattedURL = url_formatter::FormatUrl( |
| 65 self.url, url_formatter::kFormatUrlOmitNothing, |
| 66 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr); |
| 67 if (base::i18n::IsRTL()) { |
| 68 base::i18n::WrapStringWithLTRFormatting(&formattedURL); |
| 69 } |
| 70 self.title = base::SysUTF16ToNSString(formattedURL); |
| 71 } |
| 72 |
| 73 // |self.view| setup. |
| 74 CGRect windowBounds = [UIApplication sharedApplication].keyWindow.bounds; |
| 75 base::scoped_nsobject<UIView> view( |
| 76 [[UIView alloc] initWithFrame:windowBounds]); |
| 77 [view setBackgroundColor:[UIColor whiteColor]]; |
| 78 [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | |
| 79 UIViewAutoresizingFlexibleHeight)]; |
| 80 self.view = view; |
| 81 |
| 82 // |self.titleLabel| setup. |
| 83 CGRect titleLabelFrame = windowBounds; |
| 84 titleLabelFrame.origin.x += kHorizontalPadding; |
| 85 titleLabelFrame.size.width -= 2.0 * kHorizontalPadding; |
| 86 titleLabelFrame.origin.y += kTitleLabelTopPadding; |
| 87 titleLabelFrame.size.height = kTitleLabelHeight; |
| 88 _titleLabel = [[UILabel alloc] initWithFrame:titleLabelFrame]; |
| 89 _titleLabel.text = |
| 90 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); |
| 91 _titleLabel.autoresizingMask = (UIViewAutoresizingFlexibleBottomMargin | |
| 92 UIViewAutoresizingFlexibleWidth); |
| 93 _titleLabel.font = |
| 94 [UIFont fontWithName:@"Helvetica-Bold" size:kTitleLabelFontSize]; |
| 95 _titleLabel.textAlignment = NSTextAlignmentCenter; |
| 96 [self.view addSubview:_titleLabel]; |
| 97 |
| 98 // |self.descriptionView| setup. |
| 99 CGRect descriptionViewFrame = windowBounds; |
| 100 descriptionViewFrame.origin.x += kHorizontalPadding; |
| 101 descriptionViewFrame.size.width -= 2 * kHorizontalPadding; |
| 102 descriptionViewFrame.origin.y = kDescriptionViewTopPadding; |
| 103 descriptionViewFrame.size.height = CGRectGetHeight(windowBounds) - |
| 104 descriptionViewFrame.origin.y - |
| 105 kDescriptionViewBottomPadding; |
| 106 _descriptionView = [[UITextView alloc] initWithFrame:descriptionViewFrame]; |
| 107 _descriptionView.text = l10n_util::GetNSStringF( |
| 108 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE_NO_EMPHASIS, |
| 109 base::UTF8ToUTF16(self.url.spec())); |
| 110 _descriptionView.autoresizingMask = |
| 111 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| 112 _descriptionView.font = [UIFont systemFontOfSize:kDescriptionViewFontSize]; |
| 113 _descriptionView.editable = NO; |
| 114 [self.view addSubview:_descriptionView]; |
| 115 } |
| 116 return self; |
| 117 } |
| 118 |
| 119 - (instancetype)initWithNibName:(NSString*)nibName |
| 120 url:(const GURL&)url NS_UNAVAILABLE { |
| 121 NOTREACHED(); |
| 122 return nil; |
| 123 } |
| 124 |
| 125 - (void)setDescriptionText:(NSString*)descriptionText { |
| 126 _descriptionText = descriptionText; |
| 127 _descriptionView.text = descriptionText; |
| 128 } |
| 129 |
| 130 @end |
OLD | NEW |