OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/google_landing_view_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/google_landing_view_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #import "ios/chrome/browser/ui/url_loader.h" | 28 #import "ios/chrome/browser/ui/url_loader.h" |
29 #include "ios/chrome/common/string_util.h" | 29 #include "ios/chrome/common/string_util.h" |
30 #include "ios/chrome/grit/ios_strings.h" | 30 #include "ios/chrome/grit/ios_strings.h" |
31 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" | 31 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" |
32 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 32 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
33 #import "ios/web/public/web_state/context_menu_params.h" | 33 #import "ios/web/public/web_state/context_menu_params.h" |
34 #import "net/base/mac/url_conversions.h" | 34 #import "net/base/mac/url_conversions.h" |
35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/page_transition_types.h" | 36 #include "ui/base/page_transition_types.h" |
37 | 37 |
| 38 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 39 #error "This file requires ARC support." |
| 40 #endif |
| 41 |
38 using base::UserMetricsAction; | 42 using base::UserMetricsAction; |
39 | 43 |
40 namespace { | 44 namespace { |
41 | 45 |
42 enum { | 46 enum { |
43 SectionWithOmnibox, | 47 SectionWithOmnibox, |
44 SectionWithMostVisited, | 48 SectionWithMostVisited, |
45 NumberOfCollectionViewSections, | 49 NumberOfCollectionViewSections, |
46 }; | 50 }; |
47 | 51 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 96 |
93 @end | 97 @end |
94 | 98 |
95 @interface GoogleLandingViewController ()<OverscrollActionsControllerDelegate, | 99 @interface GoogleLandingViewController ()<OverscrollActionsControllerDelegate, |
96 UICollectionViewDataSource, | 100 UICollectionViewDataSource, |
97 UICollectionViewDelegate, | 101 UICollectionViewDelegate, |
98 UICollectionViewDelegateFlowLayout, | 102 UICollectionViewDelegateFlowLayout, |
99 UIGestureRecognizerDelegate, | 103 UIGestureRecognizerDelegate, |
100 WhatsNewHeaderViewDelegate> { | 104 WhatsNewHeaderViewDelegate> { |
101 // Fake omnibox. | 105 // Fake omnibox. |
102 base::scoped_nsobject<UIButton> _searchTapTarget; | 106 UIButton* _searchTapTarget; |
103 | 107 |
104 // A collection view for the most visited sites. | 108 // A collection view for the most visited sites. |
105 base::scoped_nsobject<UICollectionView> _mostVisitedView; | 109 UICollectionView* _mostVisitedView; |
106 | 110 |
107 // The overscroll actions controller managing accelerators over the toolbar. | 111 // The overscroll actions controller managing accelerators over the toolbar. |
108 base::scoped_nsobject<OverscrollActionsController> | 112 OverscrollActionsController* _overscrollActionsController; |
109 _overscrollActionsController; | |
110 | 113 |
111 // |YES| when notifications indicate the omnibox is focused. | 114 // |YES| when notifications indicate the omnibox is focused. |
112 BOOL _omniboxFocused; | 115 BOOL _omniboxFocused; |
113 | 116 |
114 // Tap and swipe gesture recognizers when the omnibox is focused. | 117 // Tap and swipe gesture recognizers when the omnibox is focused. |
115 base::scoped_nsobject<UITapGestureRecognizer> _tapGestureRecognizer; | 118 UITapGestureRecognizer* _tapGestureRecognizer; |
116 base::scoped_nsobject<UISwipeGestureRecognizer> _swipeGestureRecognizer; | 119 UISwipeGestureRecognizer* _swipeGestureRecognizer; |
117 | 120 |
118 // Handles displaying the context menu for all form factors. | 121 // Handles displaying the context menu for all form factors. |
119 base::scoped_nsobject<ContextMenuCoordinator> _contextMenuCoordinator; | 122 ContextMenuCoordinator* _contextMenuCoordinator; |
120 | 123 |
121 // URL of the last deleted most viewed entry. If present the UI to restore it | 124 // URL of the last deleted most viewed entry. If present the UI to restore it |
122 // is shown. | 125 // is shown. |
123 base::scoped_nsobject<NSURL> _deletedUrl; | 126 NSURL* _deletedUrl; |
124 | 127 |
125 // |YES| if the view has finished its first layout. This is useful when | 128 // |YES| if the view has finished its first layout. This is useful when |
126 // determining if the view has sized itself for tablet. | 129 // determining if the view has sized itself for tablet. |
127 BOOL _viewLoaded; | 130 BOOL _viewLoaded; |
128 | 131 |
129 // |YES| if the fakebox header should be animated on scroll. | 132 // |YES| if the fakebox header should be animated on scroll. |
130 BOOL _animateHeader; | 133 BOOL _animateHeader; |
131 | 134 |
132 // |YES| if the collection scrollView is scrolled all the way to the top. Used | 135 // |YES| if the collection scrollView is scrolled all the way to the top. Used |
133 // to lock this position in place on various frame changes. | 136 // to lock this position in place on various frame changes. |
134 BOOL _scrolledToTop; | 137 BOOL _scrolledToTop; |
135 | 138 |
136 // |YES| if this NTP panel is visible. When set to |NO| various UI updates | 139 // |YES| if this NTP panel is visible. When set to |NO| various UI updates |
137 // are ignored. | 140 // are ignored. |
138 BOOL _isShowing; | 141 BOOL _isShowing; |
139 | 142 |
140 CFTimeInterval _shiftTilesDownStartTime; | 143 CFTimeInterval _shiftTilesDownStartTime; |
141 CGSize _mostVisitedCellSize; | 144 CGSize _mostVisitedCellSize; |
142 base::scoped_nsobject<NSLayoutConstraint> _hintLabelLeadingConstraint; | 145 NSLayoutConstraint* _hintLabelLeadingConstraint; |
143 base::scoped_nsobject<NSLayoutConstraint> _voiceTapTrailingConstraint; | 146 NSLayoutConstraint* _voiceTapTrailingConstraint; |
144 base::scoped_nsobject<NSMutableArray> _supplementaryViews; | 147 NSMutableArray* _supplementaryViews; |
145 base::scoped_nsobject<NewTabPageHeaderView> _headerView; | 148 NewTabPageHeaderView* _headerView; |
146 base::scoped_nsobject<WhatsNewHeaderView> _promoHeaderView; | 149 WhatsNewHeaderView* _promoHeaderView; |
147 } | 150 } |
148 | 151 |
149 // Redeclare the |view| property to be the GoogleLandingView subclass instead of | 152 // Redeclare the |view| property to be the GoogleLandingView subclass instead of |
150 // a generic UIView. | 153 // a generic UIView. |
151 @property(nonatomic, readwrite, strong) GoogleLandingView* view; | 154 @property(nonatomic, readwrite, strong) GoogleLandingView* view; |
152 | 155 |
153 // Whether the Google logo or doodle is being shown. | 156 // Whether the Google logo or doodle is being shown. |
154 @property(nonatomic, assign) BOOL logoIsShowing; | 157 @property(nonatomic, assign) BOOL logoIsShowing; |
155 | 158 |
156 // Exposes view and methods to drive the doodle. | 159 // Exposes view and methods to drive the doodle. |
157 @property(nonatomic, assign) id<LogoVendor> logoVendor; | 160 @property(nonatomic, weak) id<LogoVendor> logoVendor; |
158 | 161 |
159 // |YES| if this consumer is incognito. | 162 // |YES| if this consumer is incognito. |
160 @property(nonatomic, assign) BOOL isOffTheRecord; | 163 @property(nonatomic, assign) BOOL isOffTheRecord; |
161 | 164 |
162 // |YES| if this consumer is has voice search enabled. | 165 // |YES| if this consumer is has voice search enabled. |
163 @property(nonatomic, assign) BOOL voiceSearchIsEnabled; | 166 @property(nonatomic, assign) BOOL voiceSearchIsEnabled; |
164 | 167 |
165 // Gets the maximum number of sites shown. | 168 // Gets the maximum number of sites shown. |
166 @property(nonatomic, assign) NSUInteger maximumMostVisitedSitesShown; | 169 @property(nonatomic, assign) NSUInteger maximumMostVisitedSitesShown; |
167 | 170 |
168 // Gets the text of a what's new promo. | 171 // Gets the text of a what's new promo. |
169 @property(nonatomic, retain) NSString* promoText; | 172 @property(nonatomic, strong) NSString* promoText; |
170 | 173 |
171 // Gets the icon of a what's new promo. | 174 // Gets the icon of a what's new promo. |
172 // TODO(crbug.com/694750): This should not be WhatsNewIcon. | 175 // TODO(crbug.com/694750): This should not be WhatsNewIcon. |
173 @property(nonatomic, assign) WhatsNewIcon promoIcon; | 176 @property(nonatomic, assign) WhatsNewIcon promoIcon; |
174 | 177 |
175 // |YES| if a what's new promo can be displayed. | 178 // |YES| if a what's new promo can be displayed. |
176 @property(nonatomic, assign) BOOL promoCanShow; | 179 @property(nonatomic, assign) BOOL promoCanShow; |
177 | 180 |
178 // The number of tabs to show in the google landing fake toolbar. | 181 // The number of tabs to show in the google landing fake toolbar. |
179 @property(nonatomic, assign) int tabCount; | 182 @property(nonatomic, assign) int tabCount; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 @synthesize promoText = _promoText; | 246 @synthesize promoText = _promoText; |
244 @synthesize promoIcon = _promoIcon; | 247 @synthesize promoIcon = _promoIcon; |
245 @synthesize promoCanShow = _promoCanShow; | 248 @synthesize promoCanShow = _promoCanShow; |
246 @synthesize maximumMostVisitedSitesShown = _maximumMostVisitedSitesShown; | 249 @synthesize maximumMostVisitedSitesShown = _maximumMostVisitedSitesShown; |
247 @synthesize tabCount = _tabCount; | 250 @synthesize tabCount = _tabCount; |
248 @synthesize canGoForward = _canGoForward; | 251 @synthesize canGoForward = _canGoForward; |
249 @synthesize canGoBack = _canGoBack; | 252 @synthesize canGoBack = _canGoBack; |
250 @synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled; | 253 @synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled; |
251 | 254 |
252 - (void)loadView { | 255 - (void)loadView { |
253 self.view = [[[GoogleLandingView alloc] | 256 self.view = |
254 initWithFrame:[UIScreen mainScreen].bounds] autorelease]; | 257 [[GoogleLandingView alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
255 } | 258 } |
256 | 259 |
257 - (void)viewDidLoad { | 260 - (void)viewDidLoad { |
258 [super viewDidLoad]; | 261 [super viewDidLoad]; |
259 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | 262 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
260 UIViewAutoresizingFlexibleWidth]; | 263 UIViewAutoresizingFlexibleWidth]; |
261 [self.view setFrameDelegate:self]; | 264 [self.view setFrameDelegate:self]; |
262 | 265 |
263 // Initialise |shiftTilesDownStartTime| to a sentinel value to indicate that | 266 // Initialise |shiftTilesDownStartTime| to a sentinel value to indicate that |
264 // the animation has not yet started. | 267 // the animation has not yet started. |
265 _shiftTilesDownStartTime = -1; | 268 _shiftTilesDownStartTime = -1; |
266 _mostVisitedCellSize = [self mostVisitedCellSize]; | 269 _mostVisitedCellSize = [self mostVisitedCellSize]; |
267 _isShowing = YES; | 270 _isShowing = YES; |
268 _scrolledToTop = NO; | 271 _scrolledToTop = NO; |
269 _animateHeader = YES; | 272 _animateHeader = YES; |
270 | 273 |
271 _tapGestureRecognizer.reset([[UITapGestureRecognizer alloc] | 274 _tapGestureRecognizer = |
272 initWithTarget:self | 275 [[UITapGestureRecognizer alloc] initWithTarget:self |
273 action:@selector(blurOmnibox)]); | 276 action:@selector(blurOmnibox)]; |
274 [_tapGestureRecognizer setDelegate:self]; | 277 [_tapGestureRecognizer setDelegate:self]; |
275 _swipeGestureRecognizer.reset([[UISwipeGestureRecognizer alloc] | 278 _swipeGestureRecognizer = |
276 initWithTarget:self | 279 [[UISwipeGestureRecognizer alloc] initWithTarget:self |
277 action:@selector(blurOmnibox)]); | 280 action:@selector(blurOmnibox)]; |
278 [_swipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown]; | 281 [_swipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown]; |
279 | 282 |
280 [self addSearchField]; | 283 [self addSearchField]; |
281 [self addMostVisited]; | 284 [self addMostVisited]; |
282 [self addOverscrollActions]; | 285 [self addOverscrollActions]; |
283 [self reload]; | 286 [self reload]; |
284 } | 287 } |
285 | 288 |
286 - (void)viewDidLayoutSubviews { | 289 - (void)viewDidLayoutSubviews { |
287 [self updateSubviewFrames]; | 290 [self updateSubviewFrames]; |
(...skipping 24 matching lines...) Expand all Loading... |
312 | 315 |
313 }; | 316 }; |
314 [coordinator animateAlongsideTransition:alongsideBlock completion:nil]; | 317 [coordinator animateAlongsideTransition:alongsideBlock completion:nil]; |
315 } | 318 } |
316 | 319 |
317 - (void)dealloc { | 320 - (void)dealloc { |
318 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 321 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
319 [_mostVisitedView setDelegate:nil]; | 322 [_mostVisitedView setDelegate:nil]; |
320 [_mostVisitedView setDataSource:nil]; | 323 [_mostVisitedView setDataSource:nil]; |
321 [_overscrollActionsController invalidate]; | 324 [_overscrollActionsController invalidate]; |
322 [super dealloc]; | |
323 } | 325 } |
324 | 326 |
325 #pragma mark - Private | 327 #pragma mark - Private |
326 | 328 |
327 - (CGSize)mostVisitedCellSize { | 329 - (CGSize)mostVisitedCellSize { |
328 if (IsIPadIdiom()) { | 330 if (IsIPadIdiom()) { |
329 // On iPads, split-screen and slide-over may require showing smaller cells. | 331 // On iPads, split-screen and slide-over may require showing smaller cells. |
330 CGSize maximumCellSize = [MostVisitedCell maximumSize]; | 332 CGSize maximumCellSize = [MostVisitedCell maximumSize]; |
331 CGSize viewSize = self.view.bounds.size; | 333 CGSize viewSize = self.view.bounds.size; |
332 CGFloat smallestDimension = | 334 CGFloat smallestDimension = |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 393 } |
392 if (IsIPadIdiom()) | 394 if (IsIPadIdiom()) |
393 [_searchTapTarget setHidden:!self.logoIsShowing]; | 395 [_searchTapTarget setHidden:!self.logoIsShowing]; |
394 } | 396 } |
395 } | 397 } |
396 | 398 |
397 // Initialize and add a search field tap target and a voice search button. | 399 // Initialize and add a search field tap target and a voice search button. |
398 - (void)addSearchField { | 400 - (void)addSearchField { |
399 CGRect searchFieldFrame = content_suggestions::searchFieldFrame( | 401 CGRect searchFieldFrame = content_suggestions::searchFieldFrame( |
400 [self viewWidth], self.logoIsShowing); | 402 [self viewWidth], self.logoIsShowing); |
401 _searchTapTarget.reset([[UIButton alloc] initWithFrame:searchFieldFrame]); | 403 _searchTapTarget = [[UIButton alloc] initWithFrame:searchFieldFrame]; |
402 if (IsIPadIdiom()) { | 404 if (IsIPadIdiom()) { |
403 UIImage* searchBoxImage = [[UIImage imageNamed:@"ntp_google_search_box"] | 405 UIImage* searchBoxImage = [[UIImage imageNamed:@"ntp_google_search_box"] |
404 resizableImageWithCapInsets:kSearchBoxStretchInsets]; | 406 resizableImageWithCapInsets:kSearchBoxStretchInsets]; |
405 [_searchTapTarget setBackgroundImage:searchBoxImage | 407 [_searchTapTarget setBackgroundImage:searchBoxImage |
406 forState:UIControlStateNormal]; | 408 forState:UIControlStateNormal]; |
407 } | 409 } |
408 [_searchTapTarget setAdjustsImageWhenHighlighted:NO]; | 410 [_searchTapTarget setAdjustsImageWhenHighlighted:NO]; |
409 [_searchTapTarget addTarget:self | 411 [_searchTapTarget addTarget:self |
410 action:@selector(searchFieldTapped:) | 412 action:@selector(searchFieldTapped:) |
411 forControlEvents:UIControlEventTouchUpInside]; | 413 forControlEvents:UIControlEventTouchUpInside]; |
412 [_searchTapTarget | 414 [_searchTapTarget |
413 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; | 415 setAccessibilityLabel:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; |
414 // Set isAccessibilityElement to NO so that Voice Search button is accessible. | 416 // Set isAccessibilityElement to NO so that Voice Search button is accessible. |
415 [_searchTapTarget setIsAccessibilityElement:NO]; | 417 [_searchTapTarget setIsAccessibilityElement:NO]; |
416 | 418 |
417 // Set up fakebox hint label. | 419 // Set up fakebox hint label. |
418 UILabel* searchHintLabel = [[[UILabel alloc] init] autorelease]; | 420 UILabel* searchHintLabel = [[UILabel alloc] init]; |
419 content_suggestions::configureSearchHintLabel( | 421 content_suggestions::configureSearchHintLabel( |
420 searchHintLabel, _searchTapTarget.get(), searchFieldFrame.size.width); | 422 searchHintLabel, _searchTapTarget, searchFieldFrame.size.width); |
421 | 423 |
422 _hintLabelLeadingConstraint.reset([[searchHintLabel.leadingAnchor | 424 _hintLabelLeadingConstraint = [searchHintLabel.leadingAnchor |
423 constraintEqualToAnchor:[_searchTapTarget leadingAnchor] | 425 constraintEqualToAnchor:[_searchTapTarget leadingAnchor] |
424 constant:kHintLabelSidePadding] retain]); | 426 constant:kHintLabelSidePadding]; |
425 [_hintLabelLeadingConstraint setActive:YES]; | 427 [_hintLabelLeadingConstraint setActive:YES]; |
426 | 428 |
427 // Add a voice search button. | 429 // Add a voice search button. |
428 UIButton* voiceTapTarget = [[[UIButton alloc] init] autorelease]; | 430 UIButton* voiceTapTarget = [[UIButton alloc] init]; |
429 content_suggestions::configureVoiceSearchButton(voiceTapTarget, | 431 content_suggestions::configureVoiceSearchButton(voiceTapTarget, |
430 _searchTapTarget.get()); | 432 _searchTapTarget); |
431 | 433 |
432 _voiceTapTrailingConstraint.reset([[voiceTapTarget.trailingAnchor | 434 _voiceTapTrailingConstraint = [voiceTapTarget.trailingAnchor |
433 constraintEqualToAnchor:[_searchTapTarget trailingAnchor]] retain]); | 435 constraintEqualToAnchor:[_searchTapTarget trailingAnchor]]; |
434 [NSLayoutConstraint activateConstraints:@[ | 436 [NSLayoutConstraint activateConstraints:@[ |
435 [searchHintLabel.trailingAnchor | 437 [searchHintLabel.trailingAnchor |
436 constraintEqualToAnchor:voiceTapTarget.leadingAnchor], | 438 constraintEqualToAnchor:voiceTapTarget.leadingAnchor], |
437 _voiceTapTrailingConstraint | 439 _voiceTapTrailingConstraint |
438 ]]; | 440 ]]; |
439 | 441 |
440 if (self.voiceSearchIsEnabled) { | 442 if (self.voiceSearchIsEnabled) { |
441 [voiceTapTarget addTarget:self | 443 [voiceTapTarget addTarget:self |
442 action:@selector(loadVoiceSearch:) | 444 action:@selector(loadVoiceSearch:) |
443 forControlEvents:UIControlEventTouchUpInside]; | 445 forControlEvents:UIControlEventTouchUpInside]; |
(...skipping 12 matching lines...) Expand all Loading... |
456 } | 458 } |
457 | 459 |
458 - (void)preloadVoiceSearch:(id)sender { | 460 - (void)preloadVoiceSearch:(id)sender { |
459 DCHECK(self.voiceSearchIsEnabled); | 461 DCHECK(self.voiceSearchIsEnabled); |
460 [sender removeTarget:self | 462 [sender removeTarget:self |
461 action:@selector(preloadVoiceSearch:) | 463 action:@selector(preloadVoiceSearch:) |
462 forControlEvents:UIControlEventTouchDown]; | 464 forControlEvents:UIControlEventTouchDown]; |
463 | 465 |
464 // Use a GenericChromeCommand because |sender| already has a tag set for a | 466 // Use a GenericChromeCommand because |sender| already has a tag set for a |
465 // different command. | 467 // different command. |
466 base::scoped_nsobject<GenericChromeCommand> command( | 468 GenericChromeCommand* command = |
467 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]); | 469 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]; |
468 [sender chromeExecuteCommand:command]; | 470 [sender chromeExecuteCommand:command]; |
469 } | 471 } |
470 | 472 |
471 - (void)setFlowLayoutInset:(UICollectionViewFlowLayout*)layout { | 473 - (void)setFlowLayoutInset:(UICollectionViewFlowLayout*)layout { |
472 CGFloat leftMargin = | 474 CGFloat leftMargin = |
473 content_suggestions::centeredTilesMarginForWidth([self viewWidth]); | 475 content_suggestions::centeredTilesMarginForWidth([self viewWidth]); |
474 [layout setSectionInset:UIEdgeInsetsMake(0, leftMargin, 0, leftMargin)]; | 476 [layout setSectionInset:UIEdgeInsetsMake(0, leftMargin, 0, leftMargin)]; |
475 } | 477 } |
476 | 478 |
477 - (void)resetSectionInset { | 479 - (void)resetSectionInset { |
(...skipping 17 matching lines...) Expand all Loading... |
495 setSideMargin:content_suggestions::centeredTilesMarginForWidth( | 497 setSideMargin:content_suggestions::centeredTilesMarginForWidth( |
496 [self viewWidth])]; | 498 [self viewWidth])]; |
497 | 499 |
498 // On the iPhone 6 Plus, if the app is started in landscape after a fresh | 500 // On the iPhone 6 Plus, if the app is started in landscape after a fresh |
499 // install, the UICollectionViewLayout incorrectly sizes the widths of the | 501 // install, the UICollectionViewLayout incorrectly sizes the widths of the |
500 // supplementary views to the portrait width. Correct that here to ensure | 502 // supplementary views to the portrait width. Correct that here to ensure |
501 // that the header is property laid out to the UICollectionView's width. | 503 // that the header is property laid out to the UICollectionView's width. |
502 // crbug.com/491131 | 504 // crbug.com/491131 |
503 CGFloat collectionViewWidth = CGRectGetWidth([_mostVisitedView bounds]); | 505 CGFloat collectionViewWidth = CGRectGetWidth([_mostVisitedView bounds]); |
504 CGFloat collectionViewMinX = CGRectGetMinX([_mostVisitedView bounds]); | 506 CGFloat collectionViewMinX = CGRectGetMinX([_mostVisitedView bounds]); |
505 for (UIView* supplementaryView in _supplementaryViews.get()) { | 507 for (UIView* supplementaryView in _supplementaryViews) { |
506 CGRect supplementaryViewFrame = supplementaryView.frame; | 508 CGRect supplementaryViewFrame = supplementaryView.frame; |
507 supplementaryViewFrame.origin.x = collectionViewMinX; | 509 supplementaryViewFrame.origin.x = collectionViewMinX; |
508 supplementaryViewFrame.size.width = collectionViewWidth; | 510 supplementaryViewFrame.size.width = collectionViewWidth; |
509 supplementaryView.frame = supplementaryViewFrame; | 511 supplementaryView.frame = supplementaryViewFrame; |
510 } | 512 } |
511 | 513 |
512 BOOL isScrollableNTP = !IsIPadIdiom() || IsCompactTablet(); | 514 BOOL isScrollableNTP = !IsIPadIdiom() || IsCompactTablet(); |
513 if (isScrollableNTP && _scrolledToTop) { | 515 if (isScrollableNTP && _scrolledToTop) { |
514 // Set the scroll view's offset to the pinned offset to keep the omnibox | 516 // Set the scroll view's offset to the pinned offset to keep the omnibox |
515 // at the top of the screen if it isn't already. | 517 // at the top of the screen if it isn't already. |
(...skipping 11 matching lines...) Expand all Loading... |
527 if (!_viewLoaded) { | 529 if (!_viewLoaded) { |
528 _viewLoaded = YES; | 530 _viewLoaded = YES; |
529 [self.logoVendor fetchDoodle]; | 531 [self.logoVendor fetchDoodle]; |
530 } | 532 } |
531 [self.delegate updateNtpBarShadowForPanelController:self]; | 533 [self.delegate updateNtpBarShadowForPanelController:self]; |
532 } | 534 } |
533 | 535 |
534 // Initialize and add a panel with most visited sites. | 536 // Initialize and add a panel with most visited sites. |
535 - (void)addMostVisited { | 537 - (void)addMostVisited { |
536 CGRect mostVisitedFrame = [self.view bounds]; | 538 CGRect mostVisitedFrame = [self.view bounds]; |
537 base::scoped_nsobject<UICollectionViewFlowLayout> flowLayout; | 539 UICollectionViewFlowLayout* flowLayout; |
538 if (IsIPadIdiom()) | 540 if (IsIPadIdiom()) |
539 flowLayout.reset([[UICollectionViewFlowLayout alloc] init]); | 541 flowLayout = [[UICollectionViewFlowLayout alloc] init]; |
540 else | 542 else |
541 flowLayout.reset([[MostVisitedLayout alloc] init]); | 543 flowLayout = [[MostVisitedLayout alloc] init]; |
542 | 544 |
543 [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; | 545 [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; |
544 [flowLayout setItemSize:_mostVisitedCellSize]; | 546 [flowLayout setItemSize:_mostVisitedCellSize]; |
545 [flowLayout setMinimumInteritemSpacing:8]; | 547 [flowLayout setMinimumInteritemSpacing:8]; |
546 [flowLayout setMinimumLineSpacing:content_suggestions::spacingBetweenTiles()]; | 548 [flowLayout setMinimumLineSpacing:content_suggestions::spacingBetweenTiles()]; |
547 DCHECK(!_mostVisitedView); | 549 DCHECK(!_mostVisitedView); |
548 _mostVisitedView.reset([[UICollectionView alloc] | 550 _mostVisitedView = [[UICollectionView alloc] initWithFrame:mostVisitedFrame |
549 initWithFrame:mostVisitedFrame | 551 collectionViewLayout:flowLayout]; |
550 collectionViewLayout:flowLayout]); | |
551 [_mostVisitedView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | 552 [_mostVisitedView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
552 UIViewAutoresizingFlexibleWidth]; | 553 UIViewAutoresizingFlexibleWidth]; |
553 [_mostVisitedView setDelegate:self]; | 554 [_mostVisitedView setDelegate:self]; |
554 [_mostVisitedView setDataSource:self]; | 555 [_mostVisitedView setDataSource:self]; |
555 [_mostVisitedView registerClass:[MostVisitedCell class] | 556 [_mostVisitedView registerClass:[MostVisitedCell class] |
556 forCellWithReuseIdentifier:@"classCell"]; | 557 forCellWithReuseIdentifier:@"classCell"]; |
557 [_mostVisitedView setBackgroundColor:[UIColor clearColor]]; | 558 [_mostVisitedView setBackgroundColor:[UIColor clearColor]]; |
558 [_mostVisitedView setBounces:YES]; | 559 [_mostVisitedView setBounces:YES]; |
559 [_mostVisitedView setShowsHorizontalScrollIndicator:NO]; | 560 [_mostVisitedView setShowsHorizontalScrollIndicator:NO]; |
560 [_mostVisitedView setShowsVerticalScrollIndicator:NO]; | 561 [_mostVisitedView setShowsVerticalScrollIndicator:NO]; |
(...skipping 13 matching lines...) Expand all Loading... |
574 @[ _hintLabelLeadingConstraint, _voiceTapTrailingConstraint ]; | 575 @[ _hintLabelLeadingConstraint, _voiceTapTrailingConstraint ]; |
575 [_headerView updateSearchField:_searchTapTarget | 576 [_headerView updateSearchField:_searchTapTarget |
576 withInitialFrame:content_suggestions::searchFieldFrame( | 577 withInitialFrame:content_suggestions::searchFieldFrame( |
577 [self viewWidth], self.logoIsShowing) | 578 [self viewWidth], self.logoIsShowing) |
578 subviewConstraints:constraints | 579 subviewConstraints:constraints |
579 forOffset:[_mostVisitedView contentOffset].y]; | 580 forOffset:[_mostVisitedView contentOffset].y]; |
580 } | 581 } |
581 | 582 |
582 - (void)addOverscrollActions { | 583 - (void)addOverscrollActions { |
583 if (!IsIPadIdiom()) { | 584 if (!IsIPadIdiom()) { |
584 _overscrollActionsController.reset([[OverscrollActionsController alloc] | 585 _overscrollActionsController = [[OverscrollActionsController alloc] |
585 initWithScrollView:_mostVisitedView]); | 586 initWithScrollView:_mostVisitedView]; |
586 [_overscrollActionsController setStyle:OverscrollStyle::NTP_NON_INCOGNITO]; | 587 [_overscrollActionsController setStyle:OverscrollStyle::NTP_NON_INCOGNITO]; |
587 [_overscrollActionsController setDelegate:self]; | 588 [_overscrollActionsController setDelegate:self]; |
588 } | 589 } |
589 } | 590 } |
590 | 591 |
591 // Check to see if the promo label should be hidden. | 592 // Check to see if the promo label should be hidden. |
592 - (void)hideWhatsNewIfNecessary { | 593 - (void)hideWhatsNewIfNecessary { |
593 if (![_promoHeaderView isHidden] && !self.promoCanShow) { | 594 if (![_promoHeaderView isHidden] && !self.promoCanShow) { |
594 [_promoHeaderView setHidden:YES]; | 595 [_promoHeaderView setHidden:YES]; |
595 [self.view setNeedsLayout]; | 596 [self.view setNeedsLayout]; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 - (void)collectionView:(UICollectionView*)collectionView | 775 - (void)collectionView:(UICollectionView*)collectionView |
775 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 776 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
776 MostVisitedCell* cell = | 777 MostVisitedCell* cell = |
777 (MostVisitedCell*)[collectionView cellForItemAtIndexPath:indexPath]; | 778 (MostVisitedCell*)[collectionView cellForItemAtIndexPath:indexPath]; |
778 | 779 |
779 // Keep the UICollectionView alive for one second while the screen | 780 // Keep the UICollectionView alive for one second while the screen |
780 // reader does its thing. | 781 // reader does its thing. |
781 // TODO(jif): This needs a radar, since it is almost certainly a | 782 // TODO(jif): This needs a radar, since it is almost certainly a |
782 // UIKit accessibility bug. crbug.com/529271 | 783 // UIKit accessibility bug. crbug.com/529271 |
783 if (UIAccessibilityIsVoiceOverRunning()) { | 784 if (UIAccessibilityIsVoiceOverRunning()) { |
784 UICollectionView* blockView = [_mostVisitedView retain]; | 785 __block UICollectionView* blockView = _mostVisitedView; |
785 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, | 786 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, |
786 static_cast<int64_t>(1 * NSEC_PER_SEC)), | 787 static_cast<int64_t>(1 * NSEC_PER_SEC)), |
787 dispatch_get_main_queue(), ^{ | 788 dispatch_get_main_queue(), ^{ |
788 [blockView release]; | 789 blockView = nil; |
789 }); | 790 }); |
790 } | 791 } |
791 | 792 |
792 const NSUInteger visitedIndex = indexPath.row; | 793 const NSUInteger visitedIndex = indexPath.row; |
793 [self blurOmnibox]; | 794 [self blurOmnibox]; |
794 DCHECK(visitedIndex < [self numberOfItems]); | 795 DCHECK(visitedIndex < [self numberOfItems]); |
795 [self.dataSource logMostVisitedClick:visitedIndex tileType:cell.tileType]; | 796 [self.dataSource logMostVisitedClick:visitedIndex tileType:cell.tileType]; |
796 [self.dispatcher loadURL:[self urlForIndex:visitedIndex] | 797 [self.dispatcher loadURL:[self urlForIndex:visitedIndex] |
797 referrer:web::Referrer() | 798 referrer:web::Referrer() |
798 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK | 799 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK |
799 rendererInitiated:NO]; | 800 rendererInitiated:NO]; |
800 } | 801 } |
801 | 802 |
802 #pragma mark - UICollectionViewDataSource | 803 #pragma mark - UICollectionViewDataSource |
803 | 804 |
804 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView | 805 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView |
805 viewForSupplementaryElementOfKind:(NSString*)kind | 806 viewForSupplementaryElementOfKind:(NSString*)kind |
806 atIndexPath:(NSIndexPath*)indexPath { | 807 atIndexPath:(NSIndexPath*)indexPath { |
807 DCHECK(kind == UICollectionElementKindSectionHeader); | 808 DCHECK(kind == UICollectionElementKindSectionHeader); |
808 | 809 |
809 if (!_supplementaryViews) | 810 if (!_supplementaryViews) |
810 _supplementaryViews.reset([[NSMutableArray alloc] init]); | 811 _supplementaryViews = [[NSMutableArray alloc] init]; |
811 | 812 |
812 if (indexPath.section == SectionWithOmnibox) { | 813 if (indexPath.section == SectionWithOmnibox) { |
813 if (!_headerView) { | 814 if (!_headerView) { |
814 _headerView.reset([[collectionView | 815 _headerView = |
815 dequeueReusableSupplementaryViewOfKind: | 816 [collectionView dequeueReusableSupplementaryViewOfKind: |
816 UICollectionElementKindSectionHeader | 817 UICollectionElementKindSectionHeader |
817 withReuseIdentifier:@"header" | 818 withReuseIdentifier:@"header" |
818 forIndexPath:indexPath] retain]); | 819 forIndexPath:indexPath]; |
819 [_headerView addSubview:[self.logoVendor view]]; | 820 [_headerView addSubview:[self.logoVendor view]]; |
820 [_headerView addSubview:_searchTapTarget]; | 821 [_headerView addSubview:_searchTapTarget]; |
821 [_headerView addViewsToSearchField:_searchTapTarget]; | 822 [_headerView addViewsToSearchField:_searchTapTarget]; |
822 | 823 |
823 if (!IsIPadIdiom()) { | 824 if (!IsIPadIdiom()) { |
824 // iPhone header also contains a toolbar since the normal toolbar is | 825 // iPhone header also contains a toolbar since the normal toolbar is |
825 // hidden. | 826 // hidden. |
826 [_headerView addToolbarWithDataSource:self.dataSource | 827 [_headerView addToolbarWithDataSource:self.dataSource |
827 dispatcher:self.dispatcher]; | 828 dispatcher:self.dispatcher]; |
828 [_headerView setToolbarTabCount:self.tabCount]; | 829 [_headerView setToolbarTabCount:self.tabCount]; |
829 [_headerView setCanGoForward:self.canGoForward]; | 830 [_headerView setCanGoForward:self.canGoForward]; |
830 [_headerView setCanGoBack:self.canGoBack]; | 831 [_headerView setCanGoBack:self.canGoBack]; |
831 } | 832 } |
832 [_supplementaryViews addObject:_headerView]; | 833 [_supplementaryViews addObject:_headerView]; |
833 } | 834 } |
834 return _headerView; | 835 return _headerView; |
835 } | 836 } |
836 | 837 |
837 if (indexPath.section == SectionWithMostVisited) { | 838 if (indexPath.section == SectionWithMostVisited) { |
838 if (!_promoHeaderView) { | 839 if (!_promoHeaderView) { |
839 _promoHeaderView.reset([[collectionView | 840 _promoHeaderView = |
840 dequeueReusableSupplementaryViewOfKind: | 841 [collectionView dequeueReusableSupplementaryViewOfKind: |
841 UICollectionElementKindSectionHeader | 842 UICollectionElementKindSectionHeader |
842 withReuseIdentifier:@"whatsNew" | 843 withReuseIdentifier:@"whatsNew" |
843 forIndexPath:indexPath] retain]); | 844 forIndexPath:indexPath]; |
844 [_promoHeaderView | 845 [_promoHeaderView |
845 setSideMargin:content_suggestions::centeredTilesMarginForWidth( | 846 setSideMargin:content_suggestions::centeredTilesMarginForWidth( |
846 [self viewWidth])]; | 847 [self viewWidth])]; |
847 [_promoHeaderView setDelegate:self]; | 848 [_promoHeaderView setDelegate:self]; |
848 if (self.promoCanShow) { | 849 if (self.promoCanShow) { |
849 [_promoHeaderView setText:self.promoText]; | 850 [_promoHeaderView setText:self.promoText]; |
850 [_promoHeaderView setIcon:self.promoIcon]; | 851 [_promoHeaderView setIcon:self.promoIcon]; |
851 [self.dataSource promoViewed]; | 852 [self.dataSource promoViewed]; |
852 } | 853 } |
853 [_supplementaryViews addObject:_promoHeaderView]; | 854 [_supplementaryViews addObject:_promoHeaderView]; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 } | 899 } |
899 return cell; | 900 return cell; |
900 } | 901 } |
901 | 902 |
902 const ntp_tiles::NTPTile& ntpTile = | 903 const ntp_tiles::NTPTile& ntpTile = |
903 [self.dataSource mostVisitedAtIndex:indexPath.row]; | 904 [self.dataSource mostVisitedAtIndex:indexPath.row]; |
904 NSString* title = base::SysUTF16ToNSString(ntpTile.title); | 905 NSString* title = base::SysUTF16ToNSString(ntpTile.title); |
905 | 906 |
906 [cell setupWithURL:ntpTile.url title:title dataSource:self.dataSource]; | 907 [cell setupWithURL:ntpTile.url title:title dataSource:self.dataSource]; |
907 | 908 |
908 base::scoped_nsobject<UILongPressGestureRecognizer> longPress( | 909 UILongPressGestureRecognizer* longPress = |
909 [[UILongPressGestureRecognizer alloc] | 910 [[UILongPressGestureRecognizer alloc] |
910 initWithTarget:self | 911 initWithTarget:self |
911 action:@selector(handleMostVisitedLongPress:)]); | 912 action:@selector(handleMostVisitedLongPress:)]; |
912 [cell addGestureRecognizer:longPress]; | 913 [cell addGestureRecognizer:longPress]; |
913 | 914 |
914 return cell; | 915 return cell; |
915 } | 916 } |
916 | 917 |
917 #pragma mark - Context Menu | 918 #pragma mark - Context Menu |
918 | 919 |
919 // Called when a user does a long press on a most visited item. | 920 // Called when a user does a long press on a most visited item. |
920 - (void)handleMostVisitedLongPress:(UILongPressGestureRecognizer*)sender { | 921 - (void)handleMostVisitedLongPress:(UILongPressGestureRecognizer*)sender { |
921 if (sender.state == UIGestureRecognizerStateBegan) { | 922 if (sender.state == UIGestureRecognizerStateBegan) { |
922 // Only one long press at a time. | 923 // Only one long press at a time. |
923 if ([_contextMenuCoordinator isVisible]) { | 924 if ([_contextMenuCoordinator isVisible]) { |
924 return; | 925 return; |
925 } | 926 } |
926 | 927 |
927 NSIndexPath* indexPath = [_mostVisitedView | 928 NSIndexPath* indexPath = [_mostVisitedView |
928 indexPathForCell:static_cast<UICollectionViewCell*>(sender.view)]; | 929 indexPathForCell:static_cast<UICollectionViewCell*>(sender.view)]; |
929 const NSUInteger index = indexPath.row; | 930 const NSUInteger index = indexPath.row; |
930 | 931 |
931 // A long press occured on one of the most visited button. Popup a context | 932 // A long press occured on one of the most visited button. Popup a context |
932 // menu. | 933 // menu. |
933 DCHECK(index < [self numberOfItems]); | 934 DCHECK(index < [self numberOfItems]); |
934 | 935 |
935 web::ContextMenuParams params; | 936 web::ContextMenuParams params; |
936 // Get view coordinates in local space. | 937 // Get view coordinates in local space. |
937 params.location = [sender locationInView:self.view]; | 938 params.location = [sender locationInView:self.view]; |
938 params.view.reset([self.view retain]); | 939 params.view.reset(self.view); |
939 | 940 |
940 // Present sheet/popover using controller that is added to view hierarchy. | 941 // Present sheet/popover using controller that is added to view hierarchy. |
941 UIViewController* topController = [params.view window].rootViewController; | 942 UIViewController* topController = [params.view window].rootViewController; |
942 while (topController.presentedViewController) | 943 while (topController.presentedViewController) |
943 topController = topController.presentedViewController; | 944 topController = topController.presentedViewController; |
944 | 945 |
945 _contextMenuCoordinator.reset([[ContextMenuCoordinator alloc] | 946 _contextMenuCoordinator = |
946 initWithBaseViewController:topController | 947 [[ContextMenuCoordinator alloc] initWithBaseViewController:topController |
947 params:params]); | 948 params:params]; |
948 | 949 |
949 ProceduralBlock action; | 950 ProceduralBlock action; |
950 | 951 |
951 // Open In New Tab. | 952 // Open In New Tab. |
952 GURL url = [self urlForIndex:index]; | 953 GURL url = [self urlForIndex:index]; |
953 base::WeakNSObject<GoogleLandingViewController> weakSelf(self); | 954 __weak GoogleLandingViewController* weakSelf = self; |
954 action = ^{ | 955 action = ^{ |
955 base::scoped_nsobject<GoogleLandingViewController> strongSelf( | 956 GoogleLandingViewController* strongSelf = weakSelf; |
956 [weakSelf retain]); | |
957 if (!strongSelf) | 957 if (!strongSelf) |
958 return; | 958 return; |
959 MostVisitedCell* cell = (MostVisitedCell*)sender.view; | 959 MostVisitedCell* cell = (MostVisitedCell*)sender.view; |
960 [[strongSelf dataSource] logMostVisitedClick:index | 960 [[strongSelf dataSource] logMostVisitedClick:index |
961 tileType:cell.tileType]; | 961 tileType:cell.tileType]; |
962 [[strongSelf dispatcher] webPageOrderedOpen:url | 962 [[strongSelf dispatcher] webPageOrderedOpen:url |
963 referrer:web::Referrer() | 963 referrer:web::Referrer() |
964 inBackground:YES | 964 inBackground:YES |
965 appendTo:kCurrentTab]; | 965 appendTo:kCurrentTab]; |
966 }; | 966 }; |
967 [_contextMenuCoordinator | 967 [_contextMenuCoordinator |
968 addItemWithTitle:l10n_util::GetNSStringWithFixup( | 968 addItemWithTitle:l10n_util::GetNSStringWithFixup( |
969 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) | 969 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) |
970 action:action]; | 970 action:action]; |
971 | 971 |
972 if (!self.isOffTheRecord) { | 972 if (!self.isOffTheRecord) { |
973 // Open in Incognito Tab. | 973 // Open in Incognito Tab. |
974 action = ^{ | 974 action = ^{ |
975 base::scoped_nsobject<GoogleLandingViewController> strongSelf( | 975 GoogleLandingViewController* strongSelf = weakSelf; |
976 [weakSelf retain]); | |
977 if (!strongSelf) | 976 if (!strongSelf) |
978 return; | 977 return; |
979 MostVisitedCell* cell = (MostVisitedCell*)sender.view; | 978 MostVisitedCell* cell = (MostVisitedCell*)sender.view; |
980 [[strongSelf dataSource] logMostVisitedClick:index | 979 [[strongSelf dataSource] logMostVisitedClick:index |
981 tileType:cell.tileType]; | 980 tileType:cell.tileType]; |
982 [[strongSelf dispatcher] webPageOrderedOpen:url | 981 [[strongSelf dispatcher] webPageOrderedOpen:url |
983 referrer:web::Referrer() | 982 referrer:web::Referrer() |
984 inIncognito:YES | 983 inIncognito:YES |
985 inBackground:NO | 984 inBackground:NO |
986 appendTo:kCurrentTab]; | 985 appendTo:kCurrentTab]; |
987 }; | 986 }; |
988 [_contextMenuCoordinator | 987 [_contextMenuCoordinator |
989 addItemWithTitle:l10n_util::GetNSStringWithFixup( | 988 addItemWithTitle:l10n_util::GetNSStringWithFixup( |
990 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) | 989 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) |
991 action:action]; | 990 action:action]; |
992 } | 991 } |
993 | 992 |
994 // Remove the most visited url. | 993 // Remove the most visited url. |
995 NSString* title = | 994 NSString* title = |
996 l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK); | 995 l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK); |
997 action = ^{ | 996 action = ^{ |
998 base::scoped_nsobject<GoogleLandingViewController> strongSelf( | 997 GoogleLandingViewController* strongSelf = weakSelf; |
999 [weakSelf retain]); | |
1000 // Early return if the controller has been deallocated. | 998 // Early return if the controller has been deallocated. |
1001 if (!strongSelf) | 999 if (!strongSelf) |
1002 return; | 1000 return; |
1003 base::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); | 1001 base::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); |
1004 [[strongSelf dataSource] addBlacklistedURL:url]; | 1002 [[strongSelf dataSource] addBlacklistedURL:url]; |
1005 [strongSelf showMostVisitedUndoForURL:net::NSURLWithGURL(url)]; | 1003 [strongSelf showMostVisitedUndoForURL:net::NSURLWithGURL(url)]; |
1006 }; | 1004 }; |
1007 [_contextMenuCoordinator addItemWithTitle:title action:action]; | 1005 [_contextMenuCoordinator addItemWithTitle:title action:action]; |
1008 | 1006 |
1009 [_contextMenuCoordinator start]; | 1007 [_contextMenuCoordinator start]; |
1010 | 1008 |
1011 if (IsIPadIdiom()) | 1009 if (IsIPadIdiom()) |
1012 [self blurOmnibox]; | 1010 [self blurOmnibox]; |
1013 } | 1011 } |
1014 } | 1012 } |
1015 | 1013 |
1016 - (void)showMostVisitedUndoForURL:(NSURL*)url { | 1014 - (void)showMostVisitedUndoForURL:(NSURL*)url { |
1017 _deletedUrl.reset([url retain]); | 1015 _deletedUrl = url; |
1018 | 1016 |
1019 MDCSnackbarMessageAction* action = | 1017 MDCSnackbarMessageAction* action = [[MDCSnackbarMessageAction alloc] init]; |
1020 [[[MDCSnackbarMessageAction alloc] init] autorelease]; | 1018 __weak GoogleLandingViewController* weakSelf = self; |
1021 base::WeakNSObject<GoogleLandingViewController> weakSelf(self); | |
1022 action.handler = ^{ | 1019 action.handler = ^{ |
1023 base::scoped_nsobject<GoogleLandingViewController> strongSelf( | 1020 GoogleLandingViewController* strongSelf = weakSelf; |
1024 [weakSelf retain]); | |
1025 if (!strongSelf) | 1021 if (!strongSelf) |
1026 return; | 1022 return; |
1027 [[strongSelf dataSource] | 1023 [[strongSelf dataSource] |
1028 removeBlacklistedURL:net::GURLWithNSURL(_deletedUrl)]; | 1024 removeBlacklistedURL:net::GURLWithNSURL(_deletedUrl)]; |
1029 }; | 1025 }; |
1030 action.title = l10n_util::GetNSString(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE); | 1026 action.title = l10n_util::GetNSString(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE); |
1031 action.accessibilityIdentifier = @"Undo"; | 1027 action.accessibilityIdentifier = @"Undo"; |
1032 | 1028 |
1033 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); | 1029 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
1034 MDCSnackbarMessage* message = [MDCSnackbarMessage | 1030 MDCSnackbarMessage* message = [MDCSnackbarMessage |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 - (BOOL)animateHeader { | 1231 - (BOOL)animateHeader { |
1236 return _animateHeader; | 1232 return _animateHeader; |
1237 } | 1233 } |
1238 | 1234 |
1239 #pragma mark - OverscrollActionsControllerDelegate | 1235 #pragma mark - OverscrollActionsControllerDelegate |
1240 | 1236 |
1241 - (void)overscrollActionsController:(OverscrollActionsController*)controller | 1237 - (void)overscrollActionsController:(OverscrollActionsController*)controller |
1242 didTriggerAction:(OverscrollAction)action { | 1238 didTriggerAction:(OverscrollAction)action { |
1243 switch (action) { | 1239 switch (action) { |
1244 case OverscrollAction::NEW_TAB: { | 1240 case OverscrollAction::NEW_TAB: { |
1245 base::scoped_nsobject<GenericChromeCommand> command( | 1241 GenericChromeCommand* command = |
1246 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_TAB]); | 1242 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_TAB]; |
1247 [[self view] chromeExecuteCommand:command]; | 1243 [[self view] chromeExecuteCommand:command]; |
1248 } break; | 1244 } break; |
1249 case OverscrollAction::CLOSE_TAB: { | 1245 case OverscrollAction::CLOSE_TAB: { |
1250 base::scoped_nsobject<GenericChromeCommand> command( | 1246 GenericChromeCommand* command = |
1251 [[GenericChromeCommand alloc] initWithTag:IDC_CLOSE_TAB]); | 1247 [[GenericChromeCommand alloc] initWithTag:IDC_CLOSE_TAB]; |
1252 [[self view] chromeExecuteCommand:command]; | 1248 [[self view] chromeExecuteCommand:command]; |
1253 } break; | 1249 } break; |
1254 case OverscrollAction::REFRESH: | 1250 case OverscrollAction::REFRESH: |
1255 [self reload]; | 1251 [self reload]; |
1256 break; | 1252 break; |
1257 case OverscrollAction::NONE: | 1253 case OverscrollAction::NONE: |
1258 NOTREACHED(); | 1254 NOTREACHED(); |
1259 break; | 1255 break; |
1260 } | 1256 } |
1261 } | 1257 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 - (void)setCanGoForward:(BOOL)canGoForward { | 1323 - (void)setCanGoForward:(BOOL)canGoForward { |
1328 _canGoForward = canGoForward; | 1324 _canGoForward = canGoForward; |
1329 [_headerView setCanGoForward:self.canGoForward]; | 1325 [_headerView setCanGoForward:self.canGoForward]; |
1330 } | 1326 } |
1331 | 1327 |
1332 - (void)setCanGoBack:(BOOL)canGoBack { | 1328 - (void)setCanGoBack:(BOOL)canGoBack { |
1333 _canGoBack = canGoBack; | 1329 _canGoBack = canGoBack; |
1334 [_headerView setCanGoBack:self.canGoBack]; | 1330 [_headerView setCanGoBack:self.canGoBack]; |
1335 } | 1331 } |
1336 @end | 1332 @end |
OLD | NEW |