Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/autofill/form_input_accessory_view.h" | 5 #import "ios/chrome/browser/autofill/form_input_accessory_view.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/ios/weak_nsobject.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/scoped_nsobject.h" | |
| 12 #import "ios/chrome/browser/autofill/form_input_accessory_view_delegate.h" | 11 #import "ios/chrome/browser/autofill/form_input_accessory_view_delegate.h" |
| 13 #import "ios/chrome/browser/ui/image_util.h" | 12 #import "ios/chrome/browser/ui/image_util.h" |
| 14 #include "ios/chrome/browser/ui/ui_util.h" | 13 #include "ios/chrome/browser/ui/ui_util.h" |
| 15 #include "ios/chrome/grit/ios_strings.h" | 14 #include "ios/chrome/grit/ios_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.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 | 22 |
| 20 // The alpha value of the background color. | 23 // The alpha value of the background color. |
| 21 const CGFloat kBackgroundColorAlpha = 1.0; | 24 const CGFloat kBackgroundColorAlpha = 1.0; |
| 22 | 25 |
| 23 // Horizontal margin around the custom view. | 26 // Horizontal margin around the custom view. |
| 24 const CGFloat kCustomViewHorizontalMargin = 2; | 27 const CGFloat kCustomViewHorizontalMargin = 2; |
| 25 | 28 |
| 26 // The width of the previous and next buttons. | 29 // The width of the previous and next buttons. |
| 27 const CGFloat kNavigationButtonWidth = 44; | 30 const CGFloat kNavigationButtonWidth = 44; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 + (void)addImageViewWithImageName:(NSString*)imageName | 93 + (void)addImageViewWithImageName:(NSString*)imageName |
| 91 originX:(CGFloat)originX | 94 originX:(CGFloat)originX |
| 92 originY:(CGFloat)originY | 95 originY:(CGFloat)originY |
| 93 width:(CGFloat)width | 96 width:(CGFloat)width |
| 94 inView:(UIView*)view; | 97 inView:(UIView*)view; |
| 95 | 98 |
| 96 @end | 99 @end |
| 97 | 100 |
| 98 @implementation FormInputAccessoryView { | 101 @implementation FormInputAccessoryView { |
| 99 // The custom view that is displayed in the input accessory view. | 102 // The custom view that is displayed in the input accessory view. |
| 100 base::scoped_nsobject<UIView> _customView; | 103 UIView* _customView; |
| 101 | 104 |
| 102 // Delegate of this view. | 105 // Delegate of this view. |
| 103 base::WeakNSProtocol<id<FormInputAccessoryViewDelegate>> _delegate; | 106 __weak id<FormInputAccessoryViewDelegate> _delegate; |
| 104 } | 107 } |
| 105 | 108 |
| 106 - (instancetype)initWithFrame:(CGRect)frame | 109 - (instancetype)initWithFrame:(CGRect)frame |
| 107 delegate:(id<FormInputAccessoryViewDelegate>)delegate | 110 delegate:(id<FormInputAccessoryViewDelegate>)delegate |
| 108 customView:(UIView*)customView | 111 customView:(UIView*)customView |
| 109 leftFrame:(CGRect)leftFrame | 112 leftFrame:(CGRect)leftFrame |
| 110 rightFrame:(CGRect)rightFrame { | 113 rightFrame:(CGRect)rightFrame { |
| 111 DCHECK(delegate); | 114 DCHECK(delegate); |
| 112 self = [super initWithFrame:frame]; | 115 self = [super initWithFrame:frame]; |
| 113 if (self) { | 116 if (self) { |
| 114 _delegate.reset(delegate); | 117 _delegate = delegate; |
| 115 _customView.reset([customView retain]); | 118 _customView = customView; |
| 116 [self initializeViewWithCustomView:_customView | 119 [self initializeViewWithCustomView:_customView |
| 117 leftFrame:leftFrame | 120 leftFrame:leftFrame |
| 118 rightFrame:rightFrame]; | 121 rightFrame:rightFrame]; |
| 119 } | 122 } |
| 120 return self; | 123 return self; |
| 121 } | 124 } |
| 122 | 125 |
| 123 - (instancetype)initWithFrame:(CGRect)frame customView:(UIView*)customView { | 126 - (instancetype)initWithFrame:(CGRect)frame customView:(UIView*)customView { |
| 124 self = [super initWithFrame:frame]; | 127 self = [super initWithFrame:frame]; |
| 125 if (self) { | 128 if (self) { |
| 126 _customView.reset([customView retain]); | 129 _customView = nil; |
|
Justin Donnelly
2017/06/13 20:08:05
Shouldn't this be _customView = customView; ?
marq (ping after 24h)
2017/06/14 12:06:13
It should have been, yes. But it looks like it doe
| |
| 127 customView.frame = | 130 customView.frame = |
| 128 CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame)); | 131 CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame)); |
| 129 [self addSubview:customView]; | 132 [self addSubview:customView]; |
| 130 | 133 |
| 131 [[self class] addBackgroundImageInView:self | 134 [[self class] addBackgroundImageInView:self |
| 132 withImageName:@"autofill_keyboard_background"]; | 135 withImageName:@"autofill_keyboard_background"]; |
| 133 } | 136 } |
| 134 return self; | 137 return self; |
| 135 } | 138 } |
| 136 | 139 |
| 137 #pragma mark - | 140 #pragma mark - |
| 138 #pragma mark UIInputViewAudioFeedback | 141 #pragma mark UIInputViewAudioFeedback |
| 139 | 142 |
| 140 - (BOOL)enableInputClicksWhenVisible { | 143 - (BOOL)enableInputClicksWhenVisible { |
| 141 return YES; | 144 return YES; |
| 142 } | 145 } |
| 143 | 146 |
| 144 #pragma mark - | 147 #pragma mark - |
| 145 #pragma mark Private Methods | 148 #pragma mark Private Methods |
| 146 | 149 |
| 147 - (void)initializeViewWithCustomView:(UIView*)customView | 150 - (void)initializeViewWithCustomView:(UIView*)customView |
| 148 leftFrame:(CGRect)leftFrame | 151 leftFrame:(CGRect)leftFrame |
| 149 rightFrame:(CGRect)rightFrame { | 152 rightFrame:(CGRect)rightFrame { |
| 150 UIView* customViewContainer = [[[UIView alloc] init] autorelease]; | 153 UIView* customViewContainer = [[UIView alloc] init]; |
| 151 [self addSubview:customViewContainer]; | 154 [self addSubview:customViewContainer]; |
| 152 UIView* navView = [[[UIView alloc] init] autorelease]; | 155 UIView* navView = [[UIView alloc] init]; |
| 153 [self addSubview:navView]; | 156 [self addSubview:navView]; |
| 154 | 157 |
| 155 bool splitKeyboard = CGRectGetWidth(rightFrame) != 0; | 158 bool splitKeyboard = CGRectGetWidth(rightFrame) != 0; |
| 156 BOOL isRTL = base::i18n::IsRTL(); | 159 BOOL isRTL = base::i18n::IsRTL(); |
| 157 | 160 |
| 158 // The computed frame for |customView|. | 161 // The computed frame for |customView|. |
| 159 CGRect customViewFrame; | 162 CGRect customViewFrame; |
| 160 // Frame of a subview of |navView| in which navigation buttons will be shown. | 163 // Frame of a subview of |navView| in which navigation buttons will be shown. |
| 161 CGRect navFrame = CGRectZero; | 164 CGRect navFrame = CGRectZero; |
| 162 if (splitKeyboard) { | 165 if (splitKeyboard) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 [customViewContainer addSubview:customView]; | 229 [customViewContainer addSubview:customView]; |
| 227 [navView addSubview:[self viewForNavigationButtonsInFrame:navFrame]]; | 230 [navView addSubview:[self viewForNavigationButtonsInFrame:navFrame]]; |
| 228 } | 231 } |
| 229 | 232 |
| 230 UIImage* ButtonImage(NSString* name) { | 233 UIImage* ButtonImage(NSString* name) { |
| 231 UIImage* rawImage = [UIImage imageNamed:name]; | 234 UIImage* rawImage = [UIImage imageNamed:name]; |
| 232 return StretchableImageFromUIImage(rawImage, 1, 0); | 235 return StretchableImageFromUIImage(rawImage, 1, 0); |
| 233 } | 236 } |
| 234 | 237 |
| 235 - (UIView*)viewForNavigationButtonsInFrame:(CGRect)frame { | 238 - (UIView*)viewForNavigationButtonsInFrame:(CGRect)frame { |
| 236 UIView* navView = [[[UIView alloc] initWithFrame:frame] autorelease]; | 239 UIView* navView = [[UIView alloc] initWithFrame:frame]; |
| 237 | 240 |
| 238 BOOL isRTL = base::i18n::IsRTL(); | 241 BOOL isRTL = base::i18n::IsRTL(); |
| 239 | 242 |
| 240 // Vertical space is left for a dividing line. | 243 // Vertical space is left for a dividing line. |
| 241 CGFloat firstRow = 1; | 244 CGFloat firstRow = 1; |
| 242 | 245 |
| 243 CGFloat currentX = 0; | 246 CGFloat currentX = 0; |
| 244 | 247 |
| 245 // Navigation view is at the right side if not RTL. Add a left separator in | 248 // Navigation view is at the right side if not RTL. Add a left separator in |
| 246 // this case. | 249 // this case. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 action:action | 370 action:action |
| 368 forControlEvents:UIControlEventTouchUpInside]; | 371 forControlEvents:UIControlEventTouchUpInside]; |
| 369 return button; | 372 return button; |
| 370 } | 373 } |
| 371 | 374 |
| 372 + (void)addBackgroundImageInView:(UIView*)view | 375 + (void)addBackgroundImageInView:(UIView*)view |
| 373 withImageName:(NSString*)imageName { | 376 withImageName:(NSString*)imageName { |
| 374 UIImage* backgroundImage = StretchableImageNamed(imageName); | 377 UIImage* backgroundImage = StretchableImageNamed(imageName); |
| 375 | 378 |
| 376 UIImageView* backgroundImageView = | 379 UIImageView* backgroundImageView = |
| 377 [[[UIImageView alloc] initWithFrame:view.bounds] autorelease]; | 380 [[UIImageView alloc] initWithFrame:view.bounds]; |
| 378 [backgroundImageView setImage:backgroundImage]; | 381 [backgroundImageView setImage:backgroundImage]; |
| 379 [backgroundImageView setAlpha:kBackgroundColorAlpha]; | 382 [backgroundImageView setAlpha:kBackgroundColorAlpha]; |
| 380 [view addSubview:backgroundImageView]; | 383 [view addSubview:backgroundImageView]; |
| 381 [view sendSubviewToBack:backgroundImageView]; | 384 [view sendSubviewToBack:backgroundImageView]; |
| 382 } | 385 } |
| 383 | 386 |
| 384 + (void)addImageViewWithImageName:(NSString*)imageName | 387 + (void)addImageViewWithImageName:(NSString*)imageName |
| 385 originX:(CGFloat)originX | 388 originX:(CGFloat)originX |
| 386 originY:(CGFloat)originY | 389 originY:(CGFloat)originY |
| 387 width:(CGFloat)width | 390 width:(CGFloat)width |
| 388 inView:(UIView*)view { | 391 inView:(UIView*)view { |
| 389 UIImage* image = | 392 UIImage* image = |
| 390 StretchableImageFromUIImage([UIImage imageNamed:imageName], 0, 0); | 393 StretchableImageFromUIImage([UIImage imageNamed:imageName], 0, 0); |
| 391 base::scoped_nsobject<UIImageView> imageView( | 394 UIImageView* imageView = [[UIImageView alloc] initWithImage:image]; |
| 392 [[UIImageView alloc] initWithImage:image]); | |
| 393 [imageView setFrame:CGRectMake(originX, originY, width, | 395 [imageView setFrame:CGRectMake(originX, originY, width, |
| 394 CGRectGetHeight(view.bounds) - originY)]; | 396 CGRectGetHeight(view.bounds) - originY)]; |
| 395 [view addSubview:imageView]; | 397 [view addSubview:imageView]; |
| 396 } | 398 } |
| 397 | 399 |
| 398 @end | 400 @end |
| OLD | NEW |