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

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

Issue 2889963002: [ObjC ARC] Converts ios/chrome/browser/ui/ntp:ntp_internal to ARC.
Patch Set: Moved testing method accessing ivars to a category Created 3 years, 6 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_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 19 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.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 = 92 UIFont* titleFont =
90 [[MDFRobotoFontLoader sharedInstance] lightFontOfSize:24]; 93 [[MDFRobotoFontLoader sharedInstance] lightFontOfSize:24];
91 base::scoped_nsobject<UILabel> incognitoTabHeading( 94 UILabel* incognitoTabHeading =
92 [[self labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_HEADING) 95 [self labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_HEADING)
93 font:titleFont 96 font:titleFont
94 alpha:0.8] retain]); 97 alpha:0.8];
95 [_containerView addSubview:incognitoTabHeading]; 98 [_containerView addSubview:incognitoTabHeading];
96 99
97 // Description paragraph. 100 // Description paragraph.
98 UIFont* regularFont = 101 UIFont* regularFont =
99 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14]; 102 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14];
100 base::scoped_nsobject<UILabel> incognitoTabDescription([[self 103 UILabel* incognitoTabDescription = [self
101 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_DESCRIPTION) 104 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_DESCRIPTION)
102 font:regularFont 105 font:regularFont
103 alpha:0.7] retain]); 106 alpha:0.7];
104 [_containerView addSubview:incognitoTabDescription]; 107 [_containerView addSubview:incognitoTabDescription];
105 108
106 // Warning paragraph. 109 // Warning paragraph.
107 base::scoped_nsobject<UILabel> incognitoTabWarning([[self 110 UILabel* incognitoTabWarning = [self
108 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_MESSAGE_WARNING) 111 labelWithString:l10n_util::GetNSString(IDS_NEW_TAB_OTR_MESSAGE_WARNING)
109 font:regularFont 112 font:regularFont
110 alpha:0.7] retain]); 113 alpha:0.7];
111 [_containerView addSubview:incognitoTabWarning]; 114 [_containerView addSubview:incognitoTabWarning];
112 115
113 // Learn more button. 116 // Learn more button.
114 base::scoped_nsobject<MDCButton> learnMore([[MDCFlatButton alloc] init]); 117 MDCButton* learnMore = [[MDCFlatButton alloc] init];
115 UIColor* inkColor = 118 UIColor* inkColor =
116 [[[MDCPalette greyPalette] tint300] colorWithAlphaComponent:0.25]; 119 [[[MDCPalette greyPalette] tint300] colorWithAlphaComponent:0.25];
117 [learnMore setInkColor:inkColor]; 120 [learnMore setInkColor:inkColor];
118 [learnMore setTranslatesAutoresizingMaskIntoConstraints:NO]; 121 [learnMore setTranslatesAutoresizingMaskIntoConstraints:NO];
119 [learnMore setTitle:l10n_util::GetNSString(IDS_NEW_TAB_OTR_LEARN_MORE_LINK) 122 [learnMore setTitle:l10n_util::GetNSString(IDS_NEW_TAB_OTR_LEARN_MORE_LINK)
120 forState:UIControlStateNormal]; 123 forState:UIControlStateNormal];
121 [learnMore setTitleColor:UIColorFromRGB(kLinkColor) 124 [learnMore setTitleColor:UIColorFromRGB(kLinkColor)
122 forState:UIControlStateNormal]; 125 forState:UIControlStateNormal];
123 UIFont* buttonFont = 126 UIFont* buttonFont =
124 [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:14]; 127 [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:14];
125 [[learnMore titleLabel] setFont:buttonFont]; 128 [[learnMore titleLabel] setFont:buttonFont];
126 [learnMore addTarget:self 129 [learnMore addTarget:self
127 action:@selector(learnMoreButtonPressed) 130 action:@selector(learnMoreButtonPressed)
128 forControlEvents:UIControlEventTouchUpInside]; 131 forControlEvents:UIControlEventTouchUpInside];
129 [_containerView addSubview:learnMore]; 132 [_containerView addSubview:learnMore];
130 133
131 // |topGuide| and |bottomGuide| exist to vertically center the sibling views 134 // |topGuide| and |bottomGuide| exist to vertically center the sibling views
132 // located in between them. 135 // located in between them.
133 base::scoped_nsobject<UILayoutGuide> topGuide([[UILayoutGuide alloc] init]); 136 UILayoutGuide* topGuide = [[UILayoutGuide alloc] init];
134 base::scoped_nsobject<UILayoutGuide> bottomGuide( 137 UILayoutGuide* bottomGuide = [[UILayoutGuide alloc] init];
135 [[UILayoutGuide alloc] init]);
136 [_containerView addLayoutGuide:topGuide]; 138 [_containerView addLayoutGuide:topGuide];
137 [_containerView addLayoutGuide:bottomGuide]; 139 [_containerView addLayoutGuide:bottomGuide];
138 140
139 NSDictionary* viewsDictionary = @{ 141 NSDictionary* viewsDictionary = @{
140 @"topGuide" : topGuide.get(), 142 @"topGuide" : topGuide,
141 @"image" : incognitoImage.get(), 143 @"image" : incognitoImage,
142 @"heading" : incognitoTabHeading.get(), 144 @"heading" : incognitoTabHeading,
143 @"description" : incognitoTabDescription.get(), 145 @"description" : incognitoTabDescription,
144 @"warning" : incognitoTabWarning.get(), 146 @"warning" : incognitoTabWarning,
145 @"learnMoreButton" : learnMore.get(), 147 @"learnMoreButton" : learnMore,
146 @"bottomGuide" : bottomGuide.get(), 148 @"bottomGuide" : bottomGuide,
147 }; 149 };
148 NSArray* constraints = @[ 150 NSArray* constraints = @[
149 @"V:|-0-[topGuide(>=12)]-[image]-24-[heading]-32-[description]", 151 @"V:|-0-[topGuide(>=12)]-[image]-24-[heading]-32-[description]",
150 @"V:[description]-32-[warning]-32-[learnMoreButton]", 152 @"V:[description]-32-[warning]-32-[learnMoreButton]",
151 @"V:[learnMoreButton]-[bottomGuide]-0-|", 153 @"V:[learnMoreButton]-[bottomGuide]-0-|",
152 @"H:|-(>=24)-[heading]-(>=24)-|", 154 @"H:|-(>=24)-[heading]-(>=24)-|",
153 @"H:|-(>=24)-[description(==416@999)]-(>=24)-|", 155 @"H:|-(>=24)-[description(==416@999)]-(>=24)-|",
154 @"H:|-(>=24)-[warning(==416@999)]-(>=24)-|" 156 @"H:|-(>=24)-[warning(==416@999)]-(>=24)-|"
155 ]; 157 ];
156 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, 158 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary,
(...skipping 14 matching lines...) Expand all
171 toItem:topGuide 173 toItem:topGuide
172 attribute:NSLayoutAttributeHeight 174 attribute:NSLayoutAttributeHeight
173 multiplier:2 175 multiplier:2
174 constant:0]]; 176 constant:0]];
175 177
176 [self addSubview:_containerView]; 178 [self addSubview:_containerView];
177 179
178 // Constraints comunicating the size of the contentView to the scrollview. 180 // Constraints comunicating the size of the contentView to the scrollview.
179 // See UIScrollView autolayout information at 181 // See UIScrollView autolayout information at
180 // https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_ 0/index.html 182 // https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_ 0/index.html
181 viewsDictionary = @{ @"containerView" : _containerView.get() }; 183 viewsDictionary = @{ @"containerView" : _containerView };
182 constraints = @[ 184 constraints = @[
183 @"V:|-0-[containerView]-0-|", 185 @"V:|-0-[containerView]-0-|",
184 @"H:|-0-[containerView]-0-|", 186 @"H:|-0-[containerView]-0-|",
185 ]; 187 ];
186 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, 188 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary,
187 LayoutOptionForRTLSupport(), self); 189 LayoutOptionForRTLSupport(), self);
188 } 190 }
189 return self; 191 return self;
190 } 192 }
191 193
192 - (UILabel*)labelWithString:(NSString*)string 194 - (UILabel*)labelWithString:(NSString*)string
193 font:(UIFont*)font 195 font:(UIFont*)font
194 alpha:(float)alpha { 196 alpha:(float)alpha {
195 base::scoped_nsobject<NSMutableAttributedString> attributedString( 197 NSMutableAttributedString* attributedString =
196 [[NSMutableAttributedString alloc] initWithString:string]); 198 [[NSMutableAttributedString alloc] initWithString:string];
197 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 199 NSMutableParagraphStyle* paragraphStyle =
198 [[NSMutableParagraphStyle alloc] init]); 200 [[NSMutableParagraphStyle alloc] init];
199 [paragraphStyle setLineSpacing:4]; 201 [paragraphStyle setLineSpacing:4];
200 [paragraphStyle setAlignment:NSTextAlignmentJustified]; 202 [paragraphStyle setAlignment:NSTextAlignmentJustified];
201 [attributedString addAttribute:NSParagraphStyleAttributeName 203 [attributedString addAttribute:NSParagraphStyleAttributeName
202 value:paragraphStyle 204 value:paragraphStyle
203 range:NSMakeRange(0, string.length)]; 205 range:NSMakeRange(0, string.length)];
204 base::scoped_nsobject<UILabel> label( 206 UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
205 [[UILabel alloc] initWithFrame:CGRectZero]);
206 [label setTranslatesAutoresizingMaskIntoConstraints:NO]; 207 [label setTranslatesAutoresizingMaskIntoConstraints:NO];
207 [label setNumberOfLines:0]; 208 [label setNumberOfLines:0];
208 [label setFont:font]; 209 [label setFont:font];
209 [label setAttributedText:attributedString]; 210 [label setAttributedText:attributedString];
210 [label setTextColor:[UIColor colorWithWhite:1.0 alpha:alpha]]; 211 [label setTextColor:[UIColor colorWithWhite:1.0 alpha:alpha]];
211 return label.autorelease(); 212 return label = nil;
212 } 213 }
213 214
214 - (void)learnMoreButtonPressed { 215 - (void)learnMoreButtonPressed {
215 GURL gurl = GetUrlWithLang(GURL(kLearnMoreIncognitoUrl)); 216 GURL gurl = GetUrlWithLang(GURL(kLearnMoreIncognitoUrl));
216 [_loader loadURL:gurl 217 [_loader loadURL:gurl
217 referrer:web::Referrer() 218 referrer:web::Referrer()
218 transition:ui::PAGE_TRANSITION_LINK 219 transition:ui::PAGE_TRANSITION_LINK
219 rendererInitiated:NO]; 220 rendererInitiated:NO];
220 } 221 }
221 222
222 #pragma mark - UIView overrides 223 #pragma mark - UIView overrides
223 224
224 - (void)didMoveToSuperview { 225 - (void)didMoveToSuperview {
225 [super didMoveToSuperview]; 226 [super didMoveToSuperview];
226 _containerHorizontalConstraint.reset( 227 _containerHorizontalConstraint =
227 [[NSLayoutConstraint constraintWithItem:_containerView.get() 228 [NSLayoutConstraint constraintWithItem:_containerView
228 attribute:NSLayoutAttributeWidth 229 attribute:NSLayoutAttributeWidth
229 relatedBy:NSLayoutRelationEqual 230 relatedBy:NSLayoutRelationEqual
230 toItem:[self superview] 231 toItem:[self superview]
231 attribute:NSLayoutAttributeWidth 232 attribute:NSLayoutAttributeWidth
232 multiplier:1 233 multiplier:1
233 constant:0] retain]); 234 constant:0];
234 _containerVerticalConstraint.reset( 235 _containerVerticalConstraint =
235 [[NSLayoutConstraint constraintWithItem:_containerView.get() 236 [NSLayoutConstraint constraintWithItem:_containerView
236 attribute:NSLayoutAttributeHeight 237 attribute:NSLayoutAttributeHeight
237 relatedBy:NSLayoutRelationGreaterThanOrEqual 238 relatedBy:NSLayoutRelationGreaterThanOrEqual
238 toItem:[self superview] 239 toItem:[self superview]
239 attribute:NSLayoutAttributeHeight 240 attribute:NSLayoutAttributeHeight
240 multiplier:1 241 multiplier:1
241 constant:0] retain]); 242 constant:0];
242 [[self superview] addConstraint:_containerHorizontalConstraint.get()]; 243 [[self superview] addConstraint:_containerHorizontalConstraint];
243 [[self superview] addConstraint:_containerVerticalConstraint.get()]; 244 [[self superview] addConstraint:_containerVerticalConstraint];
244 } 245 }
245 246
246 - (void)willMoveToSuperview:(UIView*)newSuperview { 247 - (void)willMoveToSuperview:(UIView*)newSuperview {
247 [[self superview] removeConstraint:_containerHorizontalConstraint.get()]; 248 [[self superview] removeConstraint:_containerHorizontalConstraint];
248 [[self superview] removeConstraint:_containerVerticalConstraint.get()]; 249 [[self superview] removeConstraint:_containerVerticalConstraint];
249 _containerHorizontalConstraint.reset(); 250 _containerHorizontalConstraint = nil;
250 _containerVerticalConstraint.reset(); 251 _containerVerticalConstraint = nil;
251 [super willMoveToSuperview:newSuperview]; 252 [super willMoveToSuperview:newSuperview];
252 } 253 }
253 254
254 @end 255 @end
255 256
256 @interface IncognitoPanelController ()<UIScrollViewDelegate> 257 @interface IncognitoPanelController ()<UIScrollViewDelegate>
257 // Calculate the background alpha for the toolbar based on how much |scrollView| 258 // Calculate the background alpha for the toolbar based on how much |scrollView|
258 // has scrolled up. 259 // has scrolled up.
259 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView; 260 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView;
260 @end 261 @end
261 262
262 @implementation IncognitoPanelController { 263 @implementation IncognitoPanelController {
263 // Delegate for updating the toolbar's background alpha. 264 // Delegate for updating the toolbar's background alpha.
264 base::WeakNSProtocol<id<WebToolbarDelegate>> _webToolbarDelegate; 265 __weak id<WebToolbarDelegate> _webToolbarDelegate;
265 266
266 // The view containing the scrollview. 267 // The view containing the scrollview.
267 // The purpose of this view is to be used to set the size 268 // The purpose of this view is to be used to set the size
268 // of the contentView of the scrollview with constraints. 269 // of the contentView of the scrollview with constraints.
269 base::scoped_nsobject<UIView> _view; 270 UIView* _view;
270 271
271 // The scrollview containing the actual views. 272 // The scrollview containing the actual views.
272 base::scoped_nsobject<IncognitoNTPView> _incognitoView; 273 IncognitoNTPView* _incognitoView;
273 } 274 }
274 275
275 // Property declared in NewTabPagePanelProtocol. 276 // Property declared in NewTabPagePanelProtocol.
276 @synthesize delegate = _delegate; 277 @synthesize delegate = _delegate;
277 278
278 - (id)initWithLoader:(id<UrlLoader>)loader 279 - (id)initWithLoader:(id<UrlLoader>)loader
279 browserState:(ios::ChromeBrowserState*)browserState 280 browserState:(ios::ChromeBrowserState*)browserState
280 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate { 281 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate {
281 self = [super init]; 282 self = [super init];
282 if (self) { 283 if (self) {
283 _view.reset([[UIView alloc] 284 _view = [[UIView alloc]
284 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds]); 285 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
285 [_view setAccessibilityIdentifier:@"NTP Incognito Panel"]; 286 [_view setAccessibilityIdentifier:@"NTP Incognito Panel"];
286 [_view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | 287 [_view setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
287 UIViewAutoresizingFlexibleWidth]; 288 UIViewAutoresizingFlexibleWidth];
288 _incognitoView.reset([[IncognitoNTPView alloc] 289 _incognitoView = [[IncognitoNTPView alloc]
289 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds 290 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds
290 urlLoader:loader]); 291 urlLoader:loader];
291 [_incognitoView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | 292 [_incognitoView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
292 UIViewAutoresizingFlexibleWidth]; 293 UIViewAutoresizingFlexibleWidth];
293 294
294 if (IsIPadIdiom()) { 295 if (IsIPadIdiom()) {
295 [_incognitoView setBackgroundColor:[UIColor clearColor]]; 296 [_incognitoView setBackgroundColor:[UIColor clearColor]];
296 } else { 297 } else {
297 [_incognitoView 298 [_incognitoView
298 setBackgroundColor:[UIColor colorWithWhite:34 / 255.0 alpha:1.0]]; 299 setBackgroundColor:[UIColor colorWithWhite:34 / 255.0 alpha:1.0]];
299 } 300 }
300 if (!IsIPadIdiom()) { 301 if (!IsIPadIdiom()) {
301 [_incognitoView setDelegate:self]; 302 [_incognitoView setDelegate:self];
302 _webToolbarDelegate.reset(webToolbarDelegate); 303 _webToolbarDelegate = webToolbarDelegate;
303 [_webToolbarDelegate updateToolbarBackgroundAlpha:0]; 304 [_webToolbarDelegate updateToolbarBackgroundAlpha:0];
304 } 305 }
305 [_view addSubview:_incognitoView]; 306 [_view addSubview:_incognitoView];
306 } 307 }
307 return self; 308 return self;
308 } 309 }
309 310
310 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView { 311 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView {
311 CGFloat alpha = scrollView.contentOffset.y / kDistanceToFadeToolbar; 312 CGFloat alpha = scrollView.contentOffset.y / kDistanceToFadeToolbar;
312 return MAX(MIN(alpha, 1), 0); 313 return MAX(MIN(alpha, 1), 0);
313 } 314 }
314 315
315 - (void)dealloc { 316 - (void)dealloc {
316 [_webToolbarDelegate updateToolbarBackgroundAlpha:1]; 317 [_webToolbarDelegate updateToolbarBackgroundAlpha:1];
317 [_incognitoView setDelegate:nil]; 318 [_incognitoView setDelegate:nil];
318 [super dealloc];
319 } 319 }
320 320
321 #pragma mark - 321 #pragma mark -
322 #pragma mark NewTabPagePanelProtocol 322 #pragma mark NewTabPagePanelProtocol
323 323
324 - (void)reload { 324 - (void)reload {
325 } 325 }
326 326
327 - (void)wasShown { 327 - (void)wasShown {
328 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; 328 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView];
(...skipping 11 matching lines...) Expand all
340 } 340 }
341 341
342 - (void)setScrollsToTop:(BOOL)enable { 342 - (void)setScrollsToTop:(BOOL)enable {
343 } 343 }
344 344
345 - (CGFloat)alphaForBottomShadow { 345 - (CGFloat)alphaForBottomShadow {
346 return 0; 346 return 0;
347 } 347 }
348 348
349 - (UIView*)view { 349 - (UIView*)view {
350 return _view.get(); 350 return _view;
351 } 351 }
352 352
353 #pragma mark - 353 #pragma mark -
354 #pragma mark UIScrollViewDelegate methods 354 #pragma mark UIScrollViewDelegate methods
355 355
356 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { 356 - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
357 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; 357 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView];
358 [_webToolbarDelegate updateToolbarBackgroundAlpha:alpha]; 358 [_webToolbarDelegate updateToolbarBackgroundAlpha:alpha];
359 } 359 }
360 360
361 @end 361 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/ntp/incognito_panel_controller.h ('k') | ios/chrome/browser/ui/ntp/most_visited_cell.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698