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/ui/contextual_search/contextual_search_header_view.h
" | 5 #import "ios/chrome/browser/ui/contextual_search/contextual_search_header_view.h
" |
6 | 6 |
7 #import "base/ios/weak_nsobject.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
10 #include "base/mac/scoped_nsobject.h" | |
11 #import "ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.h" | 9 #import "ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.h" |
12 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
13 #import "ios/chrome/common/material_timing.h" | 11 #import "ios/chrome/common/material_timing.h" |
14 #include "ios/chrome/common/string_util.h" | 12 #include "ios/chrome/common/string_util.h" |
15 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 13 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
16 #include "ios/public/provider/chrome/browser/images/branded_image_provider.h" | 14 #include "ios/public/provider/chrome/browser/images/branded_image_provider.h" |
17 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
18 | 16 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." |
| 19 #endif |
| 20 |
19 namespace { | 21 namespace { |
20 const CGFloat kHorizontalMargin = 24.0; | 22 const CGFloat kHorizontalMargin = 24.0; |
21 const CGFloat kHorizontalLayoutGap = 16.0; | 23 const CGFloat kHorizontalLayoutGap = 16.0; |
22 | 24 |
23 const NSTimeInterval kTextTransformAnimationDuration = | 25 const NSTimeInterval kTextTransformAnimationDuration = |
24 ios::material::kDuration1; | 26 ios::material::kDuration1; |
25 const NSTimeInterval kLogoIrisAnimationDuration = ios::material::kDuration1; | 27 const NSTimeInterval kLogoIrisAnimationDuration = ios::material::kDuration1; |
26 } // namespace | 28 } // namespace |
27 | 29 |
28 // An image that can "iris" in/out. Assumes a square image and will do a stupid- | 30 // An image that can "iris" in/out. Assumes a square image and will do a stupid- |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 CGFloat _height; | 100 CGFloat _height; |
99 // Circular logo positioned leading side. | 101 // Circular logo positioned leading side. |
100 __unsafe_unretained IrisingImageView* _logo; | 102 __unsafe_unretained IrisingImageView* _logo; |
101 // Up/down caret positioned trailing side. | 103 // Up/down caret positioned trailing side. |
102 __unsafe_unretained UIImageView* _caret; | 104 __unsafe_unretained UIImageView* _caret; |
103 // Close control position identically to the caret. | 105 // Close control position identically to the caret. |
104 __unsafe_unretained TappableButton* _closeButton; | 106 __unsafe_unretained TappableButton* _closeButton; |
105 // Label showing the text the user tapped on in the web page, and any | 107 // Label showing the text the user tapped on in the web page, and any |
106 // additional context that will be displayed. | 108 // additional context that will be displayed. |
107 __unsafe_unretained UILabel* _textLabel; | 109 __unsafe_unretained UILabel* _textLabel; |
108 base::WeakNSProtocol<id<ContextualSearchPanelTapHandler>> _tapHandler; | 110 __weak id<ContextualSearchPanelTapHandler> _tapHandler; |
109 base::scoped_nsobject<UIGestureRecognizer> _tapRecognizer; | 111 UIGestureRecognizer* _tapRecognizer; |
110 } | 112 } |
111 | 113 |
112 + (BOOL)requiresConstraintBasedLayout { | 114 + (BOOL)requiresConstraintBasedLayout { |
113 return YES; | 115 return YES; |
114 } | 116 } |
115 | 117 |
116 - (instancetype)initWithHeight:(CGFloat)height { | 118 - (instancetype)initWithHeight:(CGFloat)height { |
117 if (!(self = [super initWithFrame:CGRectZero])) | 119 if (!(self = [super initWithFrame:CGRectZero])) |
118 return nil; | 120 return nil; |
119 | 121 |
120 DCHECK(height > 0); | 122 DCHECK(height > 0); |
121 _height = height; | 123 _height = height; |
122 | 124 |
123 self.translatesAutoresizingMaskIntoConstraints = NO; | 125 self.translatesAutoresizingMaskIntoConstraints = NO; |
124 self.backgroundColor = [UIColor whiteColor]; | 126 self.backgroundColor = [UIColor whiteColor]; |
125 _tapRecognizer.reset([[UITapGestureRecognizer alloc] init]); | 127 _tapRecognizer = [[UITapGestureRecognizer alloc] init]; |
126 [self addGestureRecognizer:_tapRecognizer]; | 128 [self addGestureRecognizer:_tapRecognizer]; |
127 [_tapRecognizer addTarget:self action:@selector(panelWasTapped:)]; | 129 [_tapRecognizer addTarget:self action:@selector(panelWasTapped:)]; |
128 | 130 |
129 UIImage* logoImage = ios::GetChromeBrowserProvider() | 131 UIImage* logoImage = ios::GetChromeBrowserProvider() |
130 ->GetBrandedImageProvider() | 132 ->GetBrandedImageProvider() |
131 ->GetContextualSearchHeaderImage(); | 133 ->GetContextualSearchHeaderImage(); |
132 _logo = [[[IrisingImageView alloc] initWithImage:logoImage] autorelease]; | 134 IrisingImageView* logo = [[IrisingImageView alloc] initWithImage:logoImage]; |
| 135 _logo = logo; |
133 _logo.translatesAutoresizingMaskIntoConstraints = NO; | 136 _logo.translatesAutoresizingMaskIntoConstraints = NO; |
134 _logo.iris = 0.0; | 137 _logo.iris = 0.0; |
135 | 138 |
136 _caret = [[[UIImageView alloc] | 139 UIImageView* caret = |
137 initWithImage:[UIImage imageNamed:@"expand_less"]] autorelease]; | 140 [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"expand_less"]]; |
| 141 _caret = caret; |
138 _caret.translatesAutoresizingMaskIntoConstraints = NO; | 142 _caret.translatesAutoresizingMaskIntoConstraints = NO; |
139 [_caret setContentHuggingPriority:UILayoutPriorityDefaultHigh | 143 [_caret setContentHuggingPriority:UILayoutPriorityDefaultHigh |
140 forAxis:UILayoutConstraintAxisVertical]; | 144 forAxis:UILayoutConstraintAxisVertical]; |
141 [_caret setContentHuggingPriority:UILayoutPriorityDefaultHigh | 145 [_caret setContentHuggingPriority:UILayoutPriorityDefaultHigh |
142 forAxis:UILayoutConstraintAxisHorizontal]; | 146 forAxis:UILayoutConstraintAxisHorizontal]; |
143 | 147 |
144 _closeButton = | 148 TappableButton* closeButton = |
145 [[[TappableButton alloc] initWithFrame:CGRectZero] autorelease]; | 149 [[TappableButton alloc] initWithFrame:CGRectZero]; |
| 150 _closeButton = closeButton; |
146 _closeButton.translatesAutoresizingMaskIntoConstraints = NO; | 151 _closeButton.translatesAutoresizingMaskIntoConstraints = NO; |
147 [_closeButton setImage:[UIImage imageNamed:@"card_close_button"] | 152 [_closeButton setImage:[UIImage imageNamed:@"card_close_button"] |
148 forState:UIControlStateNormal]; | 153 forState:UIControlStateNormal]; |
149 [_closeButton setImage:[UIImage imageNamed:@"card_close_button_pressed"] | 154 [_closeButton setImage:[UIImage imageNamed:@"card_close_button_pressed"] |
150 forState:UIControlStateHighlighted]; | 155 forState:UIControlStateHighlighted]; |
151 [_closeButton setContentHuggingPriority:UILayoutPriorityDefaultHigh | 156 [_closeButton setContentHuggingPriority:UILayoutPriorityDefaultHigh |
152 forAxis:UILayoutConstraintAxisVertical]; | 157 forAxis:UILayoutConstraintAxisVertical]; |
153 [_closeButton setContentHuggingPriority:UILayoutPriorityDefaultHigh | 158 [_closeButton setContentHuggingPriority:UILayoutPriorityDefaultHigh |
154 forAxis:UILayoutConstraintAxisHorizontal]; | 159 forAxis:UILayoutConstraintAxisHorizontal]; |
155 _closeButton.alpha = 0; | 160 _closeButton.alpha = 0; |
156 | 161 |
157 _textLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; | 162 UILabel* textLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 163 _textLabel = textLabel; |
158 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; | 164 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; |
159 _textLabel.font = [MDCTypography subheadFont]; | 165 _textLabel.font = [MDCTypography subheadFont]; |
160 _textLabel.textAlignment = NSTextAlignmentNatural; | 166 _textLabel.textAlignment = NSTextAlignmentNatural; |
161 _textLabel.lineBreakMode = NSLineBreakByCharWrapping; | 167 _textLabel.lineBreakMode = NSLineBreakByCharWrapping; |
162 // Ensure that |_textLabel| doesn't expand past the space defined for it | 168 // Ensure that |_textLabel| doesn't expand past the space defined for it |
163 // regardless of how long its text is. | 169 // regardless of how long its text is. |
164 [_textLabel setContentHuggingPriority:UILayoutPriorityDefaultLow | 170 [_textLabel setContentHuggingPriority:UILayoutPriorityDefaultLow |
165 forAxis:UILayoutConstraintAxisHorizontal]; | 171 forAxis:UILayoutConstraintAxisHorizontal]; |
166 | 172 |
167 [self setAccessibilityIdentifier:@"header"]; | 173 [self setAccessibilityIdentifier:@"header"]; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 226 } |
221 | 227 |
222 #pragma mark - property implementation. | 228 #pragma mark - property implementation. |
223 | 229 |
224 - (void)setTapHandler:(id<ContextualSearchPanelTapHandler>)tapHandler { | 230 - (void)setTapHandler:(id<ContextualSearchPanelTapHandler>)tapHandler { |
225 if (_tapHandler) { | 231 if (_tapHandler) { |
226 [_closeButton removeTarget:_tapHandler | 232 [_closeButton removeTarget:_tapHandler |
227 action:@selector(closePanel) | 233 action:@selector(closePanel) |
228 forControlEvents:UIControlEventTouchUpInside]; | 234 forControlEvents:UIControlEventTouchUpInside]; |
229 } | 235 } |
230 _tapHandler.reset(tapHandler); | 236 _tapHandler = tapHandler; |
231 if (_tapHandler) { | 237 if (_tapHandler) { |
232 [_closeButton addTarget:_tapHandler | 238 [_closeButton addTarget:_tapHandler |
233 action:@selector(closePanel) | 239 action:@selector(closePanel) |
234 forControlEvents:UIControlEventTouchUpInside]; | 240 forControlEvents:UIControlEventTouchUpInside]; |
235 } | 241 } |
236 } | 242 } |
237 | 243 |
238 - (id<ContextualSearchPanelTapHandler>)tapHandler { | 244 - (id<ContextualSearchPanelTapHandler>)tapHandler { |
239 return _tapHandler; | 245 return _tapHandler; |
240 } | 246 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 _caret.alpha = caretGradation * caretGradation; | 301 _caret.alpha = caretGradation * caretGradation; |
296 _closeButton.alpha = closeGradation * closeGradation; | 302 _closeButton.alpha = closeGradation * closeGradation; |
297 } | 303 } |
298 | 304 |
299 #pragma mark - Animated transitions | 305 #pragma mark - Animated transitions |
300 | 306 |
301 - (void)setText:(NSString*)text | 307 - (void)setText:(NSString*)text |
302 followingTextRange:(NSRange)followingTextRange | 308 followingTextRange:(NSRange)followingTextRange |
303 animated:(BOOL)animated { | 309 animated:(BOOL)animated { |
304 NSMutableAttributedString* styledText = | 310 NSMutableAttributedString* styledText = |
305 [[[NSMutableAttributedString alloc] initWithString:text] autorelease]; | 311 [[NSMutableAttributedString alloc] initWithString:text]; |
306 [styledText addAttribute:NSForegroundColorAttributeName | 312 [styledText addAttribute:NSForegroundColorAttributeName |
307 value:[UIColor colorWithWhite:0 alpha:0.71f] | 313 value:[UIColor colorWithWhite:0 alpha:0.71f] |
308 range:followingTextRange]; | 314 range:followingTextRange]; |
309 | 315 |
310 void (^transform)(void) = ^{ | 316 void (^transform)(void) = ^{ |
311 _textLabel.attributedText = styledText; | 317 _textLabel.attributedText = styledText; |
312 }; | 318 }; |
313 void (^complete)(BOOL) = ^(BOOL finished) { | 319 void (^complete)(BOOL) = ^(BOOL finished) { |
314 [self showLogoAnimated:animated]; | 320 [self showLogoAnimated:animated]; |
315 }; | 321 }; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 curve:ios::material::CurveEaseOut | 392 curve:ios::material::CurveEaseOut |
387 options:0 | 393 options:0 |
388 animations:transform | 394 animations:transform |
389 completion:nil]; | 395 completion:nil]; |
390 } else { | 396 } else { |
391 transform(); | 397 transform(); |
392 } | 398 } |
393 } | 399 } |
394 | 400 |
395 @end | 401 @end |
OLD | NEW |