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

Side by Side Diff: ios/chrome/browser/ui/ntp/incognito_panel_controller.mm

Issue 2955363002: [ObjC ARC] Converts ios/chrome/browser/ui/ntp:ntp_internal to ARC. (Closed)
Patch Set: adsf Created 3 years, 5 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
OLDNEW
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/ntp/incognito_panel_controller.h" 5 #import "ios/chrome/browser/ui/ntp/incognito_panel_controller.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #import "base/mac/scoped_nsobject.h"
10 #include "components/google/core/browser/google_util.h" 9 #include "components/google/core/browser/google_util.h"
11 #include "components/strings/grit/components_strings.h" 10 #include "components/strings/grit/components_strings.h"
12 #include "ios/chrome/browser/application_context.h" 11 #include "ios/chrome/browser/application_context.h"
13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
14 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" 13 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
15 #include "ios/chrome/browser/ui/ui_util.h" 14 #include "ios/chrome/browser/ui/ui_util.h"
16 #import "ios/chrome/browser/ui/uikit_ui_util.h" 15 #import "ios/chrome/browser/ui/uikit_ui_util.h"
17 #import "ios/chrome/browser/ui/url_loader.h" 16 #import "ios/chrome/browser/ui/url_loader.h"
18 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 17 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
19 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 18 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
20 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 19 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
21 #include "ios/web/public/referrer.h" 20 #include "ios/web/public/referrer.h"
22 #import "net/base/mac/url_conversions.h" 21 #import "net/base/mac/url_conversions.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 #include "url/gurl.h" 23 #include "url/gurl.h"
25 24
25 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support."
27 #endif
28
26 namespace { 29 namespace {
27 // The URL for the the Learn More page shown on incognito new tab. 30 // The URL for the the Learn More page shown on incognito new tab.
28 // Taken from ntp_resource_cache.cc. 31 // Taken from ntp_resource_cache.cc.
29 const char kLearnMoreIncognitoUrl[] = 32 const char kLearnMoreIncognitoUrl[] =
30 "https://www.google.com/support/chrome/bin/answer.py?answer=95464"; 33 "https://www.google.com/support/chrome/bin/answer.py?answer=95464";
31 34
32 GURL GetUrlWithLang(const GURL& url) { 35 GURL GetUrlWithLang(const GURL& url) {
33 std::string locale = GetApplicationContext()->GetApplicationLocale(); 36 std::string locale = GetApplicationContext()->GetApplicationLocale();
34 return google_util::AppendGoogleLocaleParam(url, locale); 37 return google_util::AppendGoogleLocaleParam(url, locale);
35 } 38 }
(...skipping 10 matching lines...) Expand all
46 - (UILabel*)labelWithString:(NSString*)string 49 - (UILabel*)labelWithString:(NSString*)string
47 font:(UIFont*)font 50 font:(UIFont*)font
48 alpha:(float)alpha; 51 alpha:(float)alpha;
49 52
50 // Triggers a navigation to the help page. 53 // Triggers a navigation to the help page.
51 - (void)learnMoreButtonPressed; 54 - (void)learnMoreButtonPressed;
52 55
53 @end 56 @end
54 57
55 @implementation IncognitoNTPView { 58 @implementation IncognitoNTPView {
56 base::WeakNSProtocol<id<UrlLoader>> _loader; 59 __weak id<UrlLoader> _loader;
57 base::scoped_nsobject<UIView> _containerView; 60 UIView* _containerView;
58 61
59 // Constraint ensuring that |containerView| is at least as high as the 62 // Constraint ensuring that |containerView| is at least as high as the
60 // superview of the IncognitoNTPView, i.e. the Incognito panel. 63 // superview of the IncognitoNTPView, i.e. the Incognito panel.
61 // This ensures that if the Incognito panel is higher than a compact 64 // This ensures that if the Incognito panel is higher than a compact
62 // |containerView|, the |containerView|'s |topGuide| and |bottomGuide| are 65 // |containerView|, the |containerView|'s |topGuide| and |bottomGuide| are
63 // forced to expand, centering the views in between them. 66 // forced to expand, centering the views in between them.
64 base::scoped_nsobject<NSLayoutConstraint> _containerVerticalConstraint; 67 NSLayoutConstraint* _containerVerticalConstraint;
65 68
66 // Constraint ensuring that |containerView| is as wide as the superview of the 69 // Constraint ensuring that |containerView| is as wide as the superview of the
67 // the IncognitoNTPView, i.e. the Incognito panel. 70 // the IncognitoNTPView, i.e. the Incognito panel.
68 base::scoped_nsobject<NSLayoutConstraint> _containerHorizontalConstraint; 71 NSLayoutConstraint* _containerHorizontalConstraint;
69 } 72 }
70 73
71 - (instancetype)initWithFrame:(CGRect)frame urlLoader:(id<UrlLoader>)loader { 74 - (instancetype)initWithFrame:(CGRect)frame urlLoader:(id<UrlLoader>)loader {
72 self = [super initWithFrame:frame]; 75 self = [super initWithFrame:frame];
73 if (self) { 76 if (self) {
74 _loader.reset(loader); 77 _loader = loader;
75 78
76 self.alwaysBounceVertical = YES; 79 self.alwaysBounceVertical = YES;
77 80
78 // Container in which all the subviews (image, labels, button) are added. 81 // Container in which all the subviews (image, labels, button) are added.
79 _containerView.reset([[UIView alloc] initWithFrame:frame]); 82 _containerView = [[UIView alloc] initWithFrame:frame];
80 [_containerView setTranslatesAutoresizingMaskIntoConstraints:NO]; 83 [_containerView setTranslatesAutoresizingMaskIntoConstraints:NO];
81 84
82 // Incognito image. 85 // Incognito image.
83 base::scoped_nsobject<UIImageView> incognitoImage([[UIImageView alloc] 86 UIImageView* incognitoImage = [[UIImageView alloc]
84 initWithImage:[UIImage imageNamed:@"incognito_icon"]]); 87 initWithImage:[UIImage imageNamed:@"incognito_icon"]];
85 [incognitoImage setTranslatesAutoresizingMaskIntoConstraints:NO]; 88 [incognitoImage setTranslatesAutoresizingMaskIntoConstraints:NO];
86 [_containerView addSubview:incognitoImage]; 89 [_containerView addSubview:incognitoImage];
87 90
88 // Title. 91 // Title.
89 UIFont* titleFont = [[MDCTypography fontLoader] lightFontOfSize:24]; 92 UIFont* titleFont = [[MDCTypography fontLoader] lightFontOfSize:24];
90 base::scoped_nsobject<UILabel> incognitoTabHeading( 93 UILabel* incognitoTabHeading =
91 [[self labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_HEADING) 94 [self labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_HEADING)
92 font:titleFont 95 font:titleFont
93 alpha:0.8] retain]); 96 alpha:0.8];
94 [_containerView addSubview:incognitoTabHeading]; 97 [_containerView addSubview:incognitoTabHeading];
95 98
96 // Description paragraph. 99 // Description paragraph.
97 UIFont* regularFont = [[MDCTypography fontLoader] regularFontOfSize:14]; 100 UIFont* regularFont = [[MDCTypography fontLoader] regularFontOfSize:14];
98 base::scoped_nsobject<UILabel> incognitoTabDescription([[self 101 UILabel* incognitoTabDescription = [self
99 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_DESCRIPTION) 102 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_DESCRIPTION)
100 font:regularFont 103 font:regularFont
101 alpha:0.7] retain]); 104 alpha:0.7];
102 [_containerView addSubview:incognitoTabDescription]; 105 [_containerView addSubview:incognitoTabDescription];
103 106
104 // Warning paragraph. 107 // Warning paragraph.
105 base::scoped_nsobject<UILabel> incognitoTabWarning([[self 108 UILabel* incognitoTabWarning = [self
106 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_MESSAGE_WARNING) 109 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_MESSAGE_WARNING)
107 font:regularFont 110 font:regularFont
108 alpha:0.7] retain]); 111 alpha:0.7];
109 [_containerView addSubview:incognitoTabWarning]; 112 [_containerView addSubview:incognitoTabWarning];
110 113
111 // Learn more button. 114 // Learn more button.
112 base::scoped_nsobject<MDCButton> learnMore([[MDCFlatButton alloc] init]); 115 MDCButton* learnMore = [[MDCFlatButton alloc] init];
113 UIColor* inkColor = 116 UIColor* inkColor =
114 [[[MDCPalette greyPalette] tint300] colorWithAlphaComponent:0.25]; 117 [[[MDCPalette greyPalette] tint300] colorWithAlphaComponent:0.25];
115 [learnMore setInkColor:inkColor]; 118 [learnMore setInkColor:inkColor];
116 [learnMore setTranslatesAutoresizingMaskIntoConstraints:NO]; 119 [learnMore setTranslatesAutoresizingMaskIntoConstraints:NO];
117 [learnMore setTitle:l10n_util::GetNSString(IDS_NEW_TAB_OTR_LEARN_MORE_LINK) 120 [learnMore setTitle:l10n_util::GetNSString(IDS_NEW_TAB_OTR_LEARN_MORE_LINK)
118 forState:UIControlStateNormal]; 121 forState:UIControlStateNormal];
119 [learnMore setTitleColor:UIColorFromRGB(kLinkColor) 122 [learnMore setTitleColor:UIColorFromRGB(kLinkColor)
120 forState:UIControlStateNormal]; 123 forState:UIControlStateNormal];
121 UIFont* buttonFont = [[MDCTypography fontLoader] boldFontOfSize:14]; 124 UIFont* buttonFont = [[MDCTypography fontLoader] boldFontOfSize:14];
122 [[learnMore titleLabel] setFont:buttonFont]; 125 [[learnMore titleLabel] setFont:buttonFont];
123 [learnMore addTarget:self 126 [learnMore addTarget:self
124 action:@selector(learnMoreButtonPressed) 127 action:@selector(learnMoreButtonPressed)
125 forControlEvents:UIControlEventTouchUpInside]; 128 forControlEvents:UIControlEventTouchUpInside];
126 [_containerView addSubview:learnMore]; 129 [_containerView addSubview:learnMore];
127 130
128 // |topGuide| and |bottomGuide| exist to vertically center the sibling views 131 // |topGuide| and |bottomGuide| exist to vertically center the sibling views
129 // located in between them. 132 // located in between them.
130 base::scoped_nsobject<UILayoutGuide> topGuide([[UILayoutGuide alloc] init]); 133 UILayoutGuide* topGuide = [[UILayoutGuide alloc] init];
131 base::scoped_nsobject<UILayoutGuide> bottomGuide( 134 UILayoutGuide* bottomGuide = [[UILayoutGuide alloc] init];
132 [[UILayoutGuide alloc] init]);
133 [_containerView addLayoutGuide:topGuide]; 135 [_containerView addLayoutGuide:topGuide];
134 [_containerView addLayoutGuide:bottomGuide]; 136 [_containerView addLayoutGuide:bottomGuide];
135 137
136 NSDictionary* viewsDictionary = @{ 138 NSDictionary* viewsDictionary = @{
137 @"topGuide" : topGuide.get(), 139 @"topGuide" : topGuide,
138 @"image" : incognitoImage.get(), 140 @"image" : incognitoImage,
139 @"heading" : incognitoTabHeading.get(), 141 @"heading" : incognitoTabHeading,
140 @"description" : incognitoTabDescription.get(), 142 @"description" : incognitoTabDescription,
141 @"warning" : incognitoTabWarning.get(), 143 @"warning" : incognitoTabWarning,
142 @"learnMoreButton" : learnMore.get(), 144 @"learnMoreButton" : learnMore,
143 @"bottomGuide" : bottomGuide.get(), 145 @"bottomGuide" : bottomGuide,
144 }; 146 };
145 NSArray* constraints = @[ 147 NSArray* constraints = @[
146 @"V:|-0-[topGuide(>=12)]-[image]-24-[heading]-32-[description]", 148 @"V:|-0-[topGuide(>=12)]-[image]-24-[heading]-32-[description]",
147 @"V:[description]-32-[warning]-32-[learnMoreButton]", 149 @"V:[description]-32-[warning]-32-[learnMoreButton]",
148 @"V:[learnMoreButton]-[bottomGuide]-0-|", 150 @"V:[learnMoreButton]-[bottomGuide]-0-|",
149 @"H:|-(>=24)-[heading]-(>=24)-|", 151 @"H:|-(>=24)-[heading]-(>=24)-|",
150 @"H:|-(>=24)-[description(==416@999)]-(>=24)-|", 152 @"H:|-(>=24)-[description(==416@999)]-(>=24)-|",
151 @"H:|-(>=24)-[warning(==416@999)]-(>=24)-|" 153 @"H:|-(>=24)-[warning(==416@999)]-(>=24)-|"
152 ]; 154 ];
153 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, 155 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary,
(...skipping 14 matching lines...) Expand all
168 toItem:topGuide 170 toItem:topGuide
169 attribute:NSLayoutAttributeHeight 171 attribute:NSLayoutAttributeHeight
170 multiplier:2 172 multiplier:2
171 constant:0]]; 173 constant:0]];
172 174
173 [self addSubview:_containerView]; 175 [self addSubview:_containerView];
174 176
175 // Constraints comunicating the size of the contentView to the scrollview. 177 // Constraints comunicating the size of the contentView to the scrollview.
176 // See UIScrollView autolayout information at 178 // See UIScrollView autolayout information at
177 // https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_ 0/index.html 179 // https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_ 0/index.html
178 viewsDictionary = @{ @"containerView" : _containerView.get() }; 180 viewsDictionary = @{@"containerView" : _containerView};
179 constraints = @[ 181 constraints = @[
180 @"V:|-0-[containerView]-0-|", 182 @"V:|-0-[containerView]-0-|",
181 @"H:|-0-[containerView]-0-|", 183 @"H:|-0-[containerView]-0-|",
182 ]; 184 ];
183 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, 185 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary,
184 LayoutOptionForRTLSupport(), self); 186 LayoutOptionForRTLSupport(), self);
185 } 187 }
186 return self; 188 return self;
187 } 189 }
188 190
189 - (UILabel*)labelWithString:(NSString*)string 191 - (UILabel*)labelWithString:(NSString*)string
190 font:(UIFont*)font 192 font:(UIFont*)font
191 alpha:(float)alpha { 193 alpha:(float)alpha {
192 base::scoped_nsobject<NSMutableAttributedString> attributedString( 194 NSMutableAttributedString* attributedString =
193 [[NSMutableAttributedString alloc] initWithString:string]); 195 [[NSMutableAttributedString alloc] initWithString:string];
194 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 196 NSMutableParagraphStyle* paragraphStyle =
195 [[NSMutableParagraphStyle alloc] init]); 197 [[NSMutableParagraphStyle alloc] init];
196 [paragraphStyle setLineSpacing:4]; 198 [paragraphStyle setLineSpacing:4];
197 [paragraphStyle setAlignment:NSTextAlignmentJustified]; 199 [paragraphStyle setAlignment:NSTextAlignmentJustified];
198 [attributedString addAttribute:NSParagraphStyleAttributeName 200 [attributedString addAttribute:NSParagraphStyleAttributeName
199 value:paragraphStyle 201 value:paragraphStyle
200 range:NSMakeRange(0, string.length)]; 202 range:NSMakeRange(0, string.length)];
201 base::scoped_nsobject<UILabel> label( 203 UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
202 [[UILabel alloc] initWithFrame:CGRectZero]);
203 [label setTranslatesAutoresizingMaskIntoConstraints:NO]; 204 [label setTranslatesAutoresizingMaskIntoConstraints:NO];
204 [label setNumberOfLines:0]; 205 [label setNumberOfLines:0];
205 [label setFont:font]; 206 [label setFont:font];
206 [label setAttributedText:attributedString]; 207 [label setAttributedText:attributedString];
207 [label setTextColor:[UIColor colorWithWhite:1.0 alpha:alpha]]; 208 [label setTextColor:[UIColor colorWithWhite:1.0 alpha:alpha]];
208 return label.autorelease(); 209 return label;
209 } 210 }
210 211
211 - (void)learnMoreButtonPressed { 212 - (void)learnMoreButtonPressed {
212 GURL gurl = GetUrlWithLang(GURL(kLearnMoreIncognitoUrl)); 213 GURL gurl = GetUrlWithLang(GURL(kLearnMoreIncognitoUrl));
213 [_loader loadURL:gurl 214 [_loader loadURL:gurl
214 referrer:web::Referrer() 215 referrer:web::Referrer()
215 transition:ui::PAGE_TRANSITION_LINK 216 transition:ui::PAGE_TRANSITION_LINK
216 rendererInitiated:NO]; 217 rendererInitiated:NO];
217 } 218 }
218 219
219 #pragma mark - UIView overrides 220 #pragma mark - UIView overrides
220 221
221 - (void)didMoveToSuperview { 222 - (void)didMoveToSuperview {
222 [super didMoveToSuperview]; 223 [super didMoveToSuperview];
223 _containerHorizontalConstraint.reset( 224 _containerHorizontalConstraint =
224 [[NSLayoutConstraint constraintWithItem:_containerView.get() 225 [NSLayoutConstraint constraintWithItem:_containerView
225 attribute:NSLayoutAttributeWidth 226 attribute:NSLayoutAttributeWidth
226 relatedBy:NSLayoutRelationEqual 227 relatedBy:NSLayoutRelationEqual
227 toItem:[self superview] 228 toItem:[self superview]
228 attribute:NSLayoutAttributeWidth 229 attribute:NSLayoutAttributeWidth
229 multiplier:1 230 multiplier:1
230 constant:0] retain]); 231 constant:0];
231 _containerVerticalConstraint.reset( 232 _containerVerticalConstraint =
232 [[NSLayoutConstraint constraintWithItem:_containerView.get() 233 [NSLayoutConstraint constraintWithItem:_containerView
233 attribute:NSLayoutAttributeHeight 234 attribute:NSLayoutAttributeHeight
234 relatedBy:NSLayoutRelationGreaterThanOrEqual 235 relatedBy:NSLayoutRelationGreaterThanOrEqual
235 toItem:[self superview] 236 toItem:[self superview]
236 attribute:NSLayoutAttributeHeight 237 attribute:NSLayoutAttributeHeight
237 multiplier:1 238 multiplier:1
238 constant:0] retain]); 239 constant:0];
239 [[self superview] addConstraint:_containerHorizontalConstraint.get()]; 240 [[self superview] addConstraint:_containerHorizontalConstraint];
240 [[self superview] addConstraint:_containerVerticalConstraint.get()]; 241 [[self superview] addConstraint:_containerVerticalConstraint];
241 } 242 }
242 243
243 - (void)willMoveToSuperview:(UIView*)newSuperview { 244 - (void)willMoveToSuperview:(UIView*)newSuperview {
244 [[self superview] removeConstraint:_containerHorizontalConstraint.get()]; 245 [[self superview] removeConstraint:_containerHorizontalConstraint];
245 [[self superview] removeConstraint:_containerVerticalConstraint.get()]; 246 [[self superview] removeConstraint:_containerVerticalConstraint];
246 _containerHorizontalConstraint.reset(); 247 _containerHorizontalConstraint = nil;
247 _containerVerticalConstraint.reset(); 248 _containerVerticalConstraint = nil;
248 [super willMoveToSuperview:newSuperview]; 249 [super willMoveToSuperview:newSuperview];
249 } 250 }
250 251
251 @end 252 @end
252 253
253 @interface IncognitoPanelController ()<UIScrollViewDelegate> 254 @interface IncognitoPanelController ()<UIScrollViewDelegate>
254 // Calculate the background alpha for the toolbar based on how much |scrollView| 255 // Calculate the background alpha for the toolbar based on how much |scrollView|
255 // has scrolled up. 256 // has scrolled up.
256 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView; 257 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView;
257 @end 258 @end
258 259
259 @implementation IncognitoPanelController { 260 @implementation IncognitoPanelController {
260 // Delegate for updating the toolbar's background alpha. 261 // Delegate for updating the toolbar's background alpha.
261 base::WeakNSProtocol<id<WebToolbarDelegate>> _webToolbarDelegate; 262 __weak id<WebToolbarDelegate> _webToolbarDelegate;
262 263
263 // The view containing the scrollview. 264 // The view containing the scrollview.
264 // The purpose of this view is to be used to set the size 265 // The purpose of this view is to be used to set the size
265 // of the contentView of the scrollview with constraints. 266 // of the contentView of the scrollview with constraints.
266 base::scoped_nsobject<UIView> _view; 267 UIView* _view;
267 268
268 // The scrollview containing the actual views. 269 // The scrollview containing the actual views.
269 base::scoped_nsobject<IncognitoNTPView> _incognitoView; 270 IncognitoNTPView* _incognitoView;
270 } 271 }
271 272
272 // Property declared in NewTabPagePanelProtocol. 273 // Property declared in NewTabPagePanelProtocol.
273 @synthesize delegate = _delegate; 274 @synthesize delegate = _delegate;
274 275
275 - (id)initWithLoader:(id<UrlLoader>)loader 276 - (id)initWithLoader:(id<UrlLoader>)loader
276 browserState:(ios::ChromeBrowserState*)browserState 277 browserState:(ios::ChromeBrowserState*)browserState
277 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate { 278 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate {
278 self = [super init]; 279 self = [super init];
279 if (self) { 280 if (self) {
280 _view.reset([[UIView alloc] 281 _view = [[UIView alloc]
281 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds]); 282 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
282 [_view setAccessibilityIdentifier:@"NTP Incognito Panel"]; 283 [_view setAccessibilityIdentifier:@"NTP Incognito Panel"];
283 [_view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | 284 [_view setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
284 UIViewAutoresizingFlexibleWidth]; 285 UIViewAutoresizingFlexibleWidth];
285 _incognitoView.reset([[IncognitoNTPView alloc] 286 _incognitoView = [[IncognitoNTPView alloc]
286 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds 287 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds
287 urlLoader:loader]); 288 urlLoader:loader];
288 [_incognitoView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | 289 [_incognitoView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
289 UIViewAutoresizingFlexibleWidth]; 290 UIViewAutoresizingFlexibleWidth];
290 291
291 if (IsIPadIdiom()) { 292 if (IsIPadIdiom()) {
292 [_incognitoView setBackgroundColor:[UIColor clearColor]]; 293 [_incognitoView setBackgroundColor:[UIColor clearColor]];
293 } else { 294 } else {
294 [_incognitoView 295 [_incognitoView
295 setBackgroundColor:[UIColor colorWithWhite:34 / 255.0 alpha:1.0]]; 296 setBackgroundColor:[UIColor colorWithWhite:34 / 255.0 alpha:1.0]];
296 } 297 }
297 if (!IsIPadIdiom()) { 298 if (!IsIPadIdiom()) {
298 [_incognitoView setDelegate:self]; 299 [_incognitoView setDelegate:self];
299 _webToolbarDelegate.reset(webToolbarDelegate); 300 _webToolbarDelegate = webToolbarDelegate;
300 [_webToolbarDelegate updateToolbarBackgroundAlpha:0]; 301 [_webToolbarDelegate updateToolbarBackgroundAlpha:0];
301 } 302 }
302 [_view addSubview:_incognitoView]; 303 [_view addSubview:_incognitoView];
303 } 304 }
304 return self; 305 return self;
305 } 306 }
306 307
307 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView { 308 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView {
308 CGFloat alpha = scrollView.contentOffset.y / kDistanceToFadeToolbar; 309 CGFloat alpha = scrollView.contentOffset.y / kDistanceToFadeToolbar;
309 return MAX(MIN(alpha, 1), 0); 310 return MAX(MIN(alpha, 1), 0);
310 } 311 }
311 312
312 - (void)dealloc { 313 - (void)dealloc {
313 [_webToolbarDelegate updateToolbarBackgroundAlpha:1]; 314 [_webToolbarDelegate updateToolbarBackgroundAlpha:1];
314 [_incognitoView setDelegate:nil]; 315 [_incognitoView setDelegate:nil];
315 [super dealloc]; 316 ;
316 } 317 }
317 318
318 #pragma mark - 319 #pragma mark -
319 #pragma mark NewTabPagePanelProtocol 320 #pragma mark NewTabPagePanelProtocol
320 321
321 - (void)reload { 322 - (void)reload {
322 } 323 }
323 324
324 - (void)wasShown { 325 - (void)wasShown {
325 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; 326 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView];
(...skipping 10 matching lines...) Expand all
336 - (void)dismissKeyboard { 337 - (void)dismissKeyboard {
337 } 338 }
338 339
339 - (void)setScrollsToTop:(BOOL)enable { 340 - (void)setScrollsToTop:(BOOL)enable {
340 } 341 }
341 342
342 - (CGFloat)alphaForBottomShadow { 343 - (CGFloat)alphaForBottomShadow {
343 return 0; 344 return 0;
344 } 345 }
345 346
346 - (UIView*)view { 347 - (UIView*)view {
marq (ping after 24h) 2017/06/29 11:57:15 Replace this with a @synthesize? Or is view not a
stkhapugin 2017/06/29 15:04:50 Done.
347 return _view.get(); 348 return _view;
348 } 349 }
349 350
350 #pragma mark - 351 #pragma mark -
351 #pragma mark UIScrollViewDelegate methods 352 #pragma mark UIScrollViewDelegate methods
352 353
353 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { 354 - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
354 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; 355 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView];
355 [_webToolbarDelegate updateToolbarBackgroundAlpha:alpha]; 356 [_webToolbarDelegate updateToolbarBackgroundAlpha:alpha];
356 } 357 }
357 358
358 @end 359 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698