OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/page_not_available_controller.h" | 5 #import "ios/chrome/browser/ui/page_not_available_controller.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/mac/objc_property_releaser.h" | 9 |
10 #include "base/mac/scoped_nsobject.h" | |
11 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
13 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
14 #include "components/url_formatter/url_formatter.h" | 13 #include "components/url_formatter/url_formatter.h" |
15 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/l10n/l10n_util_mac.h" | 15 #include "ui/base/l10n/l10n_util_mac.h" |
17 | 16 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." |
| 19 #endif |
| 20 |
18 namespace { | 21 namespace { |
19 // Top padding for |self.titleLabel|. | 22 // Top padding for |self.titleLabel|. |
20 const CGFloat kTitleLabelTopPadding = 20.0; | 23 const CGFloat kTitleLabelTopPadding = 20.0; |
21 // Height for |self.titleLabel|. | 24 // Height for |self.titleLabel|. |
22 const CGFloat kTitleLabelHeight = 38.0; | 25 const CGFloat kTitleLabelHeight = 38.0; |
23 // Top padding for |self.descriptionView|. | 26 // Top padding for |self.descriptionView|. |
24 const CGFloat kDescriptionViewTopPadding = 66.0; | 27 const CGFloat kDescriptionViewTopPadding = 66.0; |
25 // Bottom padding for |self.descriptionView|. | 28 // Bottom padding for |self.descriptionView|. |
26 const CGFloat kDescriptionViewBottomPadding = 20.0; | 29 const CGFloat kDescriptionViewBottomPadding = 20.0; |
27 // Horizontal padding between subviews and |self.view|. | 30 // Horizontal padding between subviews and |self.view|. |
28 const CGFloat kHorizontalPadding = 20.0; | 31 const CGFloat kHorizontalPadding = 20.0; |
29 // Font size for |self.titleLabel|. | 32 // Font size for |self.titleLabel|. |
30 const CGFloat kTitleLabelFontSize = 18.0; | 33 const CGFloat kTitleLabelFontSize = 18.0; |
31 // Font size for |self.descriptionView|. | 34 // Font size for |self.descriptionView|. |
32 const CGFloat kDescriptionViewFontSize = 17.0; | 35 const CGFloat kDescriptionViewFontSize = 17.0; |
33 } | 36 } |
34 | 37 |
35 @interface PageNotAvailableController () { | 38 @interface PageNotAvailableController () { |
36 base::mac::ObjCPropertyReleaser _propertyReleaser_PageNotAvailableController; | |
37 } | 39 } |
38 | 40 |
39 // The title label displayed centered at the top of the screen. | 41 // The title label displayed centered at the top of the screen. |
40 @property(nonatomic, retain) UILabel* titleLabel; | 42 @property(nonatomic, strong) UILabel* titleLabel; |
41 | 43 |
42 // TextView containing a detailed description of the problem. | 44 // TextView containing a detailed description of the problem. |
43 @property(nonatomic, retain) UITextView* descriptionView; | 45 @property(nonatomic, strong) UITextView* descriptionView; |
44 | 46 |
45 @end | 47 @end |
46 | 48 |
47 @implementation PageNotAvailableController | 49 @implementation PageNotAvailableController |
48 | 50 |
49 @synthesize titleLabel = _titleLabel; | 51 @synthesize titleLabel = _titleLabel; |
50 @synthesize descriptionView = _descriptionView; | 52 @synthesize descriptionView = _descriptionView; |
51 @synthesize descriptionText = _descriptionText; | 53 @synthesize descriptionText = _descriptionText; |
52 | 54 |
53 - (instancetype)initWithUrl:(const GURL&)url { | 55 - (instancetype)initWithUrl:(const GURL&)url { |
54 self = [super initWithNibName:nil url:url]; | 56 self = [super initWithNibName:nil url:url]; |
55 if (self) { | 57 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. | 58 // Use the host as the page title, unless the URL has a custom scheme. |
60 if (self.url.SchemeIsHTTPOrHTTPS()) { | 59 if (self.url.SchemeIsHTTPOrHTTPS()) { |
61 self.title = base::SysUTF16ToNSString( | 60 self.title = base::SysUTF16ToNSString( |
62 url_formatter::IDNToUnicode(self.url.host())); | 61 url_formatter::IDNToUnicode(self.url.host())); |
63 } else { | 62 } else { |
64 base::string16 formattedURL = url_formatter::FormatUrl( | 63 base::string16 formattedURL = url_formatter::FormatUrl( |
65 self.url, url_formatter::kFormatUrlOmitNothing, | 64 self.url, url_formatter::kFormatUrlOmitNothing, |
66 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr); | 65 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr); |
67 if (base::i18n::IsRTL()) { | 66 if (base::i18n::IsRTL()) { |
68 base::i18n::WrapStringWithLTRFormatting(&formattedURL); | 67 base::i18n::WrapStringWithLTRFormatting(&formattedURL); |
69 } | 68 } |
70 self.title = base::SysUTF16ToNSString(formattedURL); | 69 self.title = base::SysUTF16ToNSString(formattedURL); |
71 } | 70 } |
72 | 71 |
73 // |self.view| setup. | 72 // |self.view| setup. |
74 CGRect windowBounds = [UIApplication sharedApplication].keyWindow.bounds; | 73 CGRect windowBounds = [UIApplication sharedApplication].keyWindow.bounds; |
75 base::scoped_nsobject<UIView> view( | 74 UIView* view = [[UIView alloc] initWithFrame:windowBounds]; |
76 [[UIView alloc] initWithFrame:windowBounds]); | |
77 [view setBackgroundColor:[UIColor whiteColor]]; | 75 [view setBackgroundColor:[UIColor whiteColor]]; |
78 [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | | 76 [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | |
79 UIViewAutoresizingFlexibleHeight)]; | 77 UIViewAutoresizingFlexibleHeight)]; |
80 self.view = view; | 78 self.view = view; |
81 | 79 |
82 // |self.titleLabel| setup. | 80 // |self.titleLabel| setup. |
83 CGRect titleLabelFrame = windowBounds; | 81 CGRect titleLabelFrame = windowBounds; |
84 titleLabelFrame.origin.x += kHorizontalPadding; | 82 titleLabelFrame.origin.x += kHorizontalPadding; |
85 titleLabelFrame.size.width -= 2.0 * kHorizontalPadding; | 83 titleLabelFrame.size.width -= 2.0 * kHorizontalPadding; |
86 titleLabelFrame.origin.y += kTitleLabelTopPadding; | 84 titleLabelFrame.origin.y += kTitleLabelTopPadding; |
(...skipping 29 matching lines...) Expand all Loading... |
116 return self; | 114 return self; |
117 } | 115 } |
118 | 116 |
119 - (instancetype)initWithNibName:(NSString*)nibName | 117 - (instancetype)initWithNibName:(NSString*)nibName |
120 url:(const GURL&)url NS_UNAVAILABLE { | 118 url:(const GURL&)url NS_UNAVAILABLE { |
121 NOTREACHED(); | 119 NOTREACHED(); |
122 return nil; | 120 return nil; |
123 } | 121 } |
124 | 122 |
125 - (void)setDescriptionText:(NSString*)descriptionText { | 123 - (void)setDescriptionText:(NSString*)descriptionText { |
126 _descriptionText = descriptionText; | 124 _descriptionText = [descriptionText copy]; |
127 _descriptionView.text = descriptionText; | 125 _descriptionView.text = _descriptionText; |
128 } | 126 } |
129 | 127 |
130 @end | 128 @end |
OLD | NEW |