| 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/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 Loading... |
| 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 setCustomTitleColor:UIColorFromRGB(kLinkColor)]; | 122 [learnMore setCustomTitleColor:UIColorFromRGB(kLinkColor)]; |
| 120 UIFont* buttonFont = [[MDCTypography fontLoader] boldFontOfSize:14]; | 123 UIFont* buttonFont = [[MDCTypography fontLoader] boldFontOfSize:14]; |
| 121 [[learnMore titleLabel] setFont:buttonFont]; | 124 [[learnMore titleLabel] setFont:buttonFont]; |
| 122 [learnMore addTarget:self | 125 [learnMore addTarget:self |
| 123 action:@selector(learnMoreButtonPressed) | 126 action:@selector(learnMoreButtonPressed) |
| 124 forControlEvents:UIControlEventTouchUpInside]; | 127 forControlEvents:UIControlEventTouchUpInside]; |
| 125 [_containerView addSubview:learnMore]; | 128 [_containerView addSubview:learnMore]; |
| 126 | 129 |
| 127 // |topGuide| and |bottomGuide| exist to vertically center the sibling views | 130 // |topGuide| and |bottomGuide| exist to vertically center the sibling views |
| 128 // located in between them. | 131 // located in between them. |
| 129 base::scoped_nsobject<UILayoutGuide> topGuide([[UILayoutGuide alloc] init]); | 132 UILayoutGuide* topGuide = [[UILayoutGuide alloc] init]; |
| 130 base::scoped_nsobject<UILayoutGuide> bottomGuide( | 133 UILayoutGuide* bottomGuide = [[UILayoutGuide alloc] init]; |
| 131 [[UILayoutGuide alloc] init]); | |
| 132 [_containerView addLayoutGuide:topGuide]; | 134 [_containerView addLayoutGuide:topGuide]; |
| 133 [_containerView addLayoutGuide:bottomGuide]; | 135 [_containerView addLayoutGuide:bottomGuide]; |
| 134 | 136 |
| 135 NSDictionary* viewsDictionary = @{ | 137 NSDictionary* viewsDictionary = @{ |
| 136 @"topGuide" : topGuide.get(), | 138 @"topGuide" : topGuide, |
| 137 @"image" : incognitoImage.get(), | 139 @"image" : incognitoImage, |
| 138 @"heading" : incognitoTabHeading.get(), | 140 @"heading" : incognitoTabHeading, |
| 139 @"description" : incognitoTabDescription.get(), | 141 @"description" : incognitoTabDescription, |
| 140 @"warning" : incognitoTabWarning.get(), | 142 @"warning" : incognitoTabWarning, |
| 141 @"learnMoreButton" : learnMore.get(), | 143 @"learnMoreButton" : learnMore, |
| 142 @"bottomGuide" : bottomGuide.get(), | 144 @"bottomGuide" : bottomGuide, |
| 143 }; | 145 }; |
| 144 NSArray* constraints = @[ | 146 NSArray* constraints = @[ |
| 145 @"V:|-0-[topGuide(>=12)]-[image]-24-[heading]-32-[description]", | 147 @"V:|-0-[topGuide(>=12)]-[image]-24-[heading]-32-[description]", |
| 146 @"V:[description]-32-[warning]-32-[learnMoreButton]", | 148 @"V:[description]-32-[warning]-32-[learnMoreButton]", |
| 147 @"V:[learnMoreButton]-[bottomGuide]-0-|", | 149 @"V:[learnMoreButton]-[bottomGuide]-0-|", |
| 148 @"H:|-(>=24)-[heading]-(>=24)-|", | 150 @"H:|-(>=24)-[heading]-(>=24)-|", |
| 149 @"H:|-(>=24)-[description(==416@999)]-(>=24)-|", | 151 @"H:|-(>=24)-[description(==416@999)]-(>=24)-|", |
| 150 @"H:|-(>=24)-[warning(==416@999)]-(>=24)-|" | 152 @"H:|-(>=24)-[warning(==416@999)]-(>=24)-|" |
| 151 ]; | 153 ]; |
| 152 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, | 154 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 toItem:topGuide | 169 toItem:topGuide |
| 168 attribute:NSLayoutAttributeHeight | 170 attribute:NSLayoutAttributeHeight |
| 169 multiplier:2 | 171 multiplier:2 |
| 170 constant:0]]; | 172 constant:0]]; |
| 171 | 173 |
| 172 [self addSubview:_containerView]; | 174 [self addSubview:_containerView]; |
| 173 | 175 |
| 174 // Constraints comunicating the size of the contentView to the scrollview. | 176 // Constraints comunicating the size of the contentView to the scrollview. |
| 175 // See UIScrollView autolayout information at | 177 // See UIScrollView autolayout information at |
| 176 // https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_
0/index.html | 178 // https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_
0/index.html |
| 177 viewsDictionary = @{ @"containerView" : _containerView.get() }; | 179 viewsDictionary = @{@"containerView" : _containerView}; |
| 178 constraints = @[ | 180 constraints = @[ |
| 179 @"V:|-0-[containerView]-0-|", | 181 @"V:|-0-[containerView]-0-|", |
| 180 @"H:|-0-[containerView]-0-|", | 182 @"H:|-0-[containerView]-0-|", |
| 181 ]; | 183 ]; |
| 182 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, | 184 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary, |
| 183 LayoutOptionForRTLSupport(), self); | 185 LayoutOptionForRTLSupport(), self); |
| 184 } | 186 } |
| 185 return self; | 187 return self; |
| 186 } | 188 } |
| 187 | 189 |
| 188 - (UILabel*)labelWithString:(NSString*)string | 190 - (UILabel*)labelWithString:(NSString*)string |
| 189 font:(UIFont*)font | 191 font:(UIFont*)font |
| 190 alpha:(float)alpha { | 192 alpha:(float)alpha { |
| 191 base::scoped_nsobject<NSMutableAttributedString> attributedString( | 193 NSMutableAttributedString* attributedString = |
| 192 [[NSMutableAttributedString alloc] initWithString:string]); | 194 [[NSMutableAttributedString alloc] initWithString:string]; |
| 193 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 195 NSMutableParagraphStyle* paragraphStyle = |
| 194 [[NSMutableParagraphStyle alloc] init]); | 196 [[NSMutableParagraphStyle alloc] init]; |
| 195 [paragraphStyle setLineSpacing:4]; | 197 [paragraphStyle setLineSpacing:4]; |
| 196 [paragraphStyle setAlignment:NSTextAlignmentJustified]; | 198 [paragraphStyle setAlignment:NSTextAlignmentJustified]; |
| 197 [attributedString addAttribute:NSParagraphStyleAttributeName | 199 [attributedString addAttribute:NSParagraphStyleAttributeName |
| 198 value:paragraphStyle | 200 value:paragraphStyle |
| 199 range:NSMakeRange(0, string.length)]; | 201 range:NSMakeRange(0, string.length)]; |
| 200 base::scoped_nsobject<UILabel> label( | 202 UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 201 [[UILabel alloc] initWithFrame:CGRectZero]); | |
| 202 [label setTranslatesAutoresizingMaskIntoConstraints:NO]; | 203 [label setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 203 [label setNumberOfLines:0]; | 204 [label setNumberOfLines:0]; |
| 204 [label setFont:font]; | 205 [label setFont:font]; |
| 205 [label setAttributedText:attributedString]; | 206 [label setAttributedText:attributedString]; |
| 206 [label setTextColor:[UIColor colorWithWhite:1.0 alpha:alpha]]; | 207 [label setTextColor:[UIColor colorWithWhite:1.0 alpha:alpha]]; |
| 207 return label.autorelease(); | 208 return label; |
| 208 } | 209 } |
| 209 | 210 |
| 210 - (void)learnMoreButtonPressed { | 211 - (void)learnMoreButtonPressed { |
| 211 GURL gurl = GetUrlWithLang(GURL(kLearnMoreIncognitoUrl)); | 212 GURL gurl = GetUrlWithLang(GURL(kLearnMoreIncognitoUrl)); |
| 212 [_loader loadURL:gurl | 213 [_loader loadURL:gurl |
| 213 referrer:web::Referrer() | 214 referrer:web::Referrer() |
| 214 transition:ui::PAGE_TRANSITION_LINK | 215 transition:ui::PAGE_TRANSITION_LINK |
| 215 rendererInitiated:NO]; | 216 rendererInitiated:NO]; |
| 216 } | 217 } |
| 217 | 218 |
| 218 #pragma mark - UIView overrides | 219 #pragma mark - UIView overrides |
| 219 | 220 |
| 220 - (void)didMoveToSuperview { | 221 - (void)didMoveToSuperview { |
| 221 [super didMoveToSuperview]; | 222 [super didMoveToSuperview]; |
| 222 _containerHorizontalConstraint.reset( | 223 _containerHorizontalConstraint = |
| 223 [[NSLayoutConstraint constraintWithItem:_containerView.get() | 224 [NSLayoutConstraint constraintWithItem:_containerView |
| 224 attribute:NSLayoutAttributeWidth | 225 attribute:NSLayoutAttributeWidth |
| 225 relatedBy:NSLayoutRelationEqual | 226 relatedBy:NSLayoutRelationEqual |
| 226 toItem:[self superview] | 227 toItem:[self superview] |
| 227 attribute:NSLayoutAttributeWidth | 228 attribute:NSLayoutAttributeWidth |
| 228 multiplier:1 | 229 multiplier:1 |
| 229 constant:0] retain]); | 230 constant:0]; |
| 230 _containerVerticalConstraint.reset( | 231 _containerVerticalConstraint = |
| 231 [[NSLayoutConstraint constraintWithItem:_containerView.get() | 232 [NSLayoutConstraint constraintWithItem:_containerView |
| 232 attribute:NSLayoutAttributeHeight | 233 attribute:NSLayoutAttributeHeight |
| 233 relatedBy:NSLayoutRelationGreaterThanOrEqual | 234 relatedBy:NSLayoutRelationGreaterThanOrEqual |
| 234 toItem:[self superview] | 235 toItem:[self superview] |
| 235 attribute:NSLayoutAttributeHeight | 236 attribute:NSLayoutAttributeHeight |
| 236 multiplier:1 | 237 multiplier:1 |
| 237 constant:0] retain]); | 238 constant:0]; |
| 238 [[self superview] addConstraint:_containerHorizontalConstraint.get()]; | 239 [[self superview] addConstraint:_containerHorizontalConstraint]; |
| 239 [[self superview] addConstraint:_containerVerticalConstraint.get()]; | 240 [[self superview] addConstraint:_containerVerticalConstraint]; |
| 240 } | 241 } |
| 241 | 242 |
| 242 - (void)willMoveToSuperview:(UIView*)newSuperview { | 243 - (void)willMoveToSuperview:(UIView*)newSuperview { |
| 243 [[self superview] removeConstraint:_containerHorizontalConstraint.get()]; | 244 [[self superview] removeConstraint:_containerHorizontalConstraint]; |
| 244 [[self superview] removeConstraint:_containerVerticalConstraint.get()]; | 245 [[self superview] removeConstraint:_containerVerticalConstraint]; |
| 245 _containerHorizontalConstraint.reset(); | 246 _containerHorizontalConstraint = nil; |
| 246 _containerVerticalConstraint.reset(); | 247 _containerVerticalConstraint = nil; |
| 247 [super willMoveToSuperview:newSuperview]; | 248 [super willMoveToSuperview:newSuperview]; |
| 248 } | 249 } |
| 249 | 250 |
| 250 @end | 251 @end |
| 251 | 252 |
| 252 @interface IncognitoPanelController ()<UIScrollViewDelegate> | 253 @interface IncognitoPanelController ()<UIScrollViewDelegate> |
| 253 // Calculate the background alpha for the toolbar based on how much |scrollView| | 254 // Calculate the background alpha for the toolbar based on how much |scrollView| |
| 254 // has scrolled up. | 255 // has scrolled up. |
| 255 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView; | 256 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView; |
| 256 @end | 257 @end |
| 257 | 258 |
| 258 @implementation IncognitoPanelController { | 259 @implementation IncognitoPanelController { |
| 259 // Delegate for updating the toolbar's background alpha. | 260 // Delegate for updating the toolbar's background alpha. |
| 260 base::WeakNSProtocol<id<WebToolbarDelegate>> _webToolbarDelegate; | 261 __weak id<WebToolbarDelegate> _webToolbarDelegate; |
| 261 | |
| 262 // The view containing the scrollview. | |
| 263 // The purpose of this view is to be used to set the size | |
| 264 // of the contentView of the scrollview with constraints. | |
| 265 base::scoped_nsobject<UIView> _view; | |
| 266 | 262 |
| 267 // The scrollview containing the actual views. | 263 // The scrollview containing the actual views. |
| 268 base::scoped_nsobject<IncognitoNTPView> _incognitoView; | 264 IncognitoNTPView* _incognitoView; |
| 269 } | 265 } |
| 270 | 266 |
| 271 // Property declared in NewTabPagePanelProtocol. | 267 // Property declared in NewTabPagePanelProtocol. |
| 272 @synthesize delegate = _delegate; | 268 @synthesize delegate = _delegate; |
| 269 @synthesize view = _view; |
| 273 | 270 |
| 274 - (id)initWithLoader:(id<UrlLoader>)loader | 271 - (id)initWithLoader:(id<UrlLoader>)loader |
| 275 browserState:(ios::ChromeBrowserState*)browserState | 272 browserState:(ios::ChromeBrowserState*)browserState |
| 276 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate { | 273 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate { |
| 277 self = [super init]; | 274 self = [super init]; |
| 278 if (self) { | 275 if (self) { |
| 279 _view.reset([[UIView alloc] | 276 _view = [[UIView alloc] |
| 280 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds]); | 277 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds]; |
| 281 [_view setAccessibilityIdentifier:@"NTP Incognito Panel"]; | 278 [_view setAccessibilityIdentifier:@"NTP Incognito Panel"]; |
| 282 [_view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | 279 [_view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
| 283 UIViewAutoresizingFlexibleWidth]; | 280 UIViewAutoresizingFlexibleWidth]; |
| 284 _incognitoView.reset([[IncognitoNTPView alloc] | 281 _incognitoView = [[IncognitoNTPView alloc] |
| 285 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds | 282 initWithFrame:[UIApplication sharedApplication].keyWindow.bounds |
| 286 urlLoader:loader]); | 283 urlLoader:loader]; |
| 287 [_incognitoView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | 284 [_incognitoView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
| 288 UIViewAutoresizingFlexibleWidth]; | 285 UIViewAutoresizingFlexibleWidth]; |
| 289 | 286 |
| 290 if (IsIPadIdiom()) { | 287 if (IsIPadIdiom()) { |
| 291 [_incognitoView setBackgroundColor:[UIColor clearColor]]; | 288 [_incognitoView setBackgroundColor:[UIColor clearColor]]; |
| 292 } else { | 289 } else { |
| 293 [_incognitoView | 290 [_incognitoView |
| 294 setBackgroundColor:[UIColor colorWithWhite:34 / 255.0 alpha:1.0]]; | 291 setBackgroundColor:[UIColor colorWithWhite:34 / 255.0 alpha:1.0]]; |
| 295 } | 292 } |
| 296 if (!IsIPadIdiom()) { | 293 if (!IsIPadIdiom()) { |
| 297 [_incognitoView setDelegate:self]; | 294 [_incognitoView setDelegate:self]; |
| 298 _webToolbarDelegate.reset(webToolbarDelegate); | 295 _webToolbarDelegate = webToolbarDelegate; |
| 299 [_webToolbarDelegate updateToolbarBackgroundAlpha:0]; | 296 [_webToolbarDelegate updateToolbarBackgroundAlpha:0]; |
| 300 } | 297 } |
| 301 [_view addSubview:_incognitoView]; | 298 [_view addSubview:_incognitoView]; |
| 302 } | 299 } |
| 303 return self; | 300 return self; |
| 304 } | 301 } |
| 305 | 302 |
| 306 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView { | 303 - (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView { |
| 307 CGFloat alpha = scrollView.contentOffset.y / kDistanceToFadeToolbar; | 304 CGFloat alpha = scrollView.contentOffset.y / kDistanceToFadeToolbar; |
| 308 return MAX(MIN(alpha, 1), 0); | 305 return MAX(MIN(alpha, 1), 0); |
| 309 } | 306 } |
| 310 | 307 |
| 311 - (void)dealloc { | 308 - (void)dealloc { |
| 312 [_webToolbarDelegate updateToolbarBackgroundAlpha:1]; | 309 [_webToolbarDelegate updateToolbarBackgroundAlpha:1]; |
| 313 [_incognitoView setDelegate:nil]; | 310 [_incognitoView setDelegate:nil]; |
| 314 [super dealloc]; | 311 ; |
| 315 } | 312 } |
| 316 | 313 |
| 317 #pragma mark - | 314 #pragma mark - |
| 318 #pragma mark NewTabPagePanelProtocol | 315 #pragma mark NewTabPagePanelProtocol |
| 319 | 316 |
| 320 - (void)reload { | 317 - (void)reload { |
| 321 } | 318 } |
| 322 | 319 |
| 323 - (void)wasShown { | 320 - (void)wasShown { |
| 324 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; | 321 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 335 - (void)dismissKeyboard { | 332 - (void)dismissKeyboard { |
| 336 } | 333 } |
| 337 | 334 |
| 338 - (void)setScrollsToTop:(BOOL)enable { | 335 - (void)setScrollsToTop:(BOOL)enable { |
| 339 } | 336 } |
| 340 | 337 |
| 341 - (CGFloat)alphaForBottomShadow { | 338 - (CGFloat)alphaForBottomShadow { |
| 342 return 0; | 339 return 0; |
| 343 } | 340 } |
| 344 | 341 |
| 345 - (UIView*)view { | |
| 346 return _view.get(); | |
| 347 } | |
| 348 | |
| 349 #pragma mark - | 342 #pragma mark - |
| 350 #pragma mark UIScrollViewDelegate methods | 343 #pragma mark UIScrollViewDelegate methods |
| 351 | 344 |
| 352 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { | 345 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { |
| 353 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; | 346 CGFloat alpha = [self toolbarAlphaForScrollView:_incognitoView]; |
| 354 [_webToolbarDelegate updateToolbarBackgroundAlpha:alpha]; | 347 [_webToolbarDelegate updateToolbarBackgroundAlpha:alpha]; |
| 355 } | 348 } |
| 356 | 349 |
| 357 @end | 350 @end |
| OLD | NEW |