| 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_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/google_landing_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 @end | 185 @end |
| 186 | 186 |
| 187 @interface GoogleLandingController ()<MostVisitedSitesObserving, | 187 @interface GoogleLandingController ()<MostVisitedSitesObserving, |
| 188 OverscrollActionsControllerDelegate, | 188 OverscrollActionsControllerDelegate, |
| 189 UICollectionViewDataSource, | 189 UICollectionViewDataSource, |
| 190 UICollectionViewDelegate, | 190 UICollectionViewDelegate, |
| 191 UICollectionViewDelegateFlowLayout, | 191 UICollectionViewDelegateFlowLayout, |
| 192 UIGestureRecognizerDelegate, | 192 UIGestureRecognizerDelegate, |
| 193 WhatsNewHeaderViewDelegate> { | 193 WhatsNewHeaderViewDelegate> { |
| 194 // The main view. | |
| 195 base::scoped_nsobject<GoogleLandingView> _view; | |
| 196 | |
| 197 // Fake omnibox. | 194 // Fake omnibox. |
| 198 base::scoped_nsobject<UIButton> _searchTapTarget; | 195 base::scoped_nsobject<UIButton> _searchTapTarget; |
| 199 | 196 |
| 200 // Controller to fetch and show doodles or a default Google logo. | 197 // Controller to fetch and show doodles or a default Google logo. |
| 201 base::scoped_nsprotocol<id<LogoVendor>> _doodleController; | 198 base::scoped_nsprotocol<id<LogoVendor>> _doodleController; |
| 202 | 199 |
| 203 // Most visited data from the MostVisitedSites service (copied upon receiving | 200 // Most visited data from the MostVisitedSites service (copied upon receiving |
| 204 // the callback). | 201 // the callback). |
| 205 ntp_tiles::NTPTilesVector _mostVisitedData; | 202 ntp_tiles::NTPTilesVector _mostVisitedData; |
| 206 | 203 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 base::scoped_nsobject<WhatsNewHeaderView> _promoHeaderView; | 264 base::scoped_nsobject<WhatsNewHeaderView> _promoHeaderView; |
| 268 base::WeakNSProtocol<id<WebToolbarDelegate>> _webToolbarDelegate; | 265 base::WeakNSProtocol<id<WebToolbarDelegate>> _webToolbarDelegate; |
| 269 base::scoped_nsobject<TabModel> _tabModel; | 266 base::scoped_nsobject<TabModel> _tabModel; |
| 270 } | 267 } |
| 271 | 268 |
| 272 // Whether the Google logo or doodle is being shown. | 269 // Whether the Google logo or doodle is being shown. |
| 273 @property(nonatomic, readonly, getter=isShowingLogo) BOOL showingLogo; | 270 @property(nonatomic, readonly, getter=isShowingLogo) BOOL showingLogo; |
| 274 | 271 |
| 275 @property(nonatomic) id<UrlLoader> loader; | 272 @property(nonatomic) id<UrlLoader> loader; |
| 276 | 273 |
| 274 // Redeclare the |view| property to be the GoogleLandingView subclass instead of |
| 275 // a generic UIView. |
| 276 @property(nonatomic, readwrite, strong) GoogleLandingView* view; |
| 277 |
| 277 // iPhone landscape uses a slightly different layout for the doodle and search | 278 // iPhone landscape uses a slightly different layout for the doodle and search |
| 278 // field frame. Returns the proper frame from |frames| based on orientation, | 279 // field frame. Returns the proper frame from |frames| based on orientation, |
| 279 // centered in the view. | 280 // centered in the view. |
| 280 - (CGRect)getOrientationFrame:(const CGRect[])frames; | 281 - (CGRect)getOrientationFrame:(const CGRect[])frames; |
| 281 // Returns the proper frame for the doodle. | 282 // Returns the proper frame for the doodle. |
| 282 - (CGRect)doodleFrame; | 283 - (CGRect)doodleFrame; |
| 283 // Returns the proper frame for the search field. | 284 // Returns the proper frame for the search field. |
| 284 - (CGRect)searchFieldFrame; | 285 - (CGRect)searchFieldFrame; |
| 285 // Returns the height to use for the What's New promo view. | 286 // Returns the height to use for the What's New promo view. |
| 286 - (CGFloat)promoHeaderHeight; | 287 - (CGFloat)promoHeaderHeight; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // Returns the size to use for Most Visited cells in the NTP contained in | 336 // Returns the size to use for Most Visited cells in the NTP contained in |
| 336 // |view|. | 337 // |view|. |
| 337 + (CGSize)mostVisitedCellSizeForView:(UIView*)view; | 338 + (CGSize)mostVisitedCellSizeForView:(UIView*)view; |
| 338 // Returns the padding for use between Most Visited cells. | 339 // Returns the padding for use between Most Visited cells. |
| 339 + (CGFloat)mostVisitedCellPadding; | 340 + (CGFloat)mostVisitedCellPadding; |
| 340 | 341 |
| 341 @end | 342 @end |
| 342 | 343 |
| 343 @implementation GoogleLandingController | 344 @implementation GoogleLandingController |
| 344 | 345 |
| 346 @dynamic view; |
| 345 @synthesize loader = _loader; | 347 @synthesize loader = _loader; |
| 346 // Property declared in NewTabPagePanelProtocol. | 348 // Property declared in NewTabPagePanelProtocol. |
| 347 @synthesize delegate = _delegate; | 349 @synthesize delegate = _delegate; |
| 348 | 350 |
| 349 + (NSUInteger)maxSitesShown { | 351 + (NSUInteger)maxSitesShown { |
| 350 return kMaxNumMostVisitedFavicons; | 352 return kMaxNumMostVisitedFavicons; |
| 351 } | 353 } |
| 352 | 354 |
| 353 - (id)initWithLoader:(id<UrlLoader>)loader | 355 - (id)initWithLoader:(id<UrlLoader>)loader |
| 354 browserState:(ios::ChromeBrowserState*)browserState | 356 browserState:(ios::ChromeBrowserState*)browserState |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 _tapGestureRecognizer.reset([[UITapGestureRecognizer alloc] | 388 _tapGestureRecognizer.reset([[UITapGestureRecognizer alloc] |
| 387 initWithTarget:self | 389 initWithTarget:self |
| 388 action:@selector(blurOmnibox)]); | 390 action:@selector(blurOmnibox)]); |
| 389 [_tapGestureRecognizer setDelegate:self]; | 391 [_tapGestureRecognizer setDelegate:self]; |
| 390 _swipeGestureRecognizer.reset([[UISwipeGestureRecognizer alloc] | 392 _swipeGestureRecognizer.reset([[UISwipeGestureRecognizer alloc] |
| 391 initWithTarget:self | 393 initWithTarget:self |
| 392 action:@selector(blurOmnibox)]); | 394 action:@selector(blurOmnibox)]); |
| 393 [_swipeGestureRecognizer | 395 [_swipeGestureRecognizer |
| 394 setDirection:UISwipeGestureRecognizerDirectionDown]; | 396 setDirection:UISwipeGestureRecognizerDirectionDown]; |
| 395 | 397 |
| 396 _view.reset( | |
| 397 [[GoogleLandingView alloc] initWithFrame:[UIScreen mainScreen].bounds]); | |
| 398 [_view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | |
| 399 UIViewAutoresizingFlexibleWidth]; | |
| 400 [_view setFrameDelegate:self]; | |
| 401 | |
| 402 _focuser.reset(focuser); | 398 _focuser.reset(focuser); |
| 403 _webToolbarDelegate.reset(webToolbarDelegate); | 399 _webToolbarDelegate.reset(webToolbarDelegate); |
| 404 _tabModel.reset([tabModel retain]); | 400 _tabModel.reset([tabModel retain]); |
| 405 | 401 |
| 406 _scrolledToTop = NO; | 402 _scrolledToTop = NO; |
| 407 _animateHeader = YES; | 403 _animateHeader = YES; |
| 408 // Initialise |shiftTilesDownStartTime| to a sentinel value to indicate that | |
| 409 // the animation has not yet started. | |
| 410 _shiftTilesDownStartTime = -1; | |
| 411 _mostVisitedCellSize = | |
| 412 [GoogleLandingController mostVisitedCellSizeForView:_view]; | |
| 413 [self addDoodle]; | |
| 414 [self addSearchField]; | |
| 415 [self addMostVisited]; | |
| 416 [self addOverscrollActions]; | |
| 417 [self reload]; | |
| 418 } | 404 } |
| 419 return self; | 405 return self; |
| 420 } | 406 } |
| 421 | 407 |
| 408 - (void)loadView { |
| 409 self.view = |
| 410 [[GoogleLandingView alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 411 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
| 412 UIViewAutoresizingFlexibleWidth]; |
| 413 [self.view setFrameDelegate:self]; |
| 414 // Initialise |shiftTilesDownStartTime| to a sentinel value to indicate that |
| 415 // the animation has not yet started. |
| 416 _shiftTilesDownStartTime = -1; |
| 417 _mostVisitedCellSize = |
| 418 [GoogleLandingController mostVisitedCellSizeForView:self.view]; |
| 419 [self addDoodle]; |
| 420 [self addSearchField]; |
| 421 [self addMostVisited]; |
| 422 [self addOverscrollActions]; |
| 423 [self reload]; |
| 424 } |
| 425 |
| 422 + (CGSize)mostVisitedCellSizeForView:(UIView*)view { | 426 + (CGSize)mostVisitedCellSizeForView:(UIView*)view { |
| 423 if (IsIPadIdiom()) { | 427 if (IsIPadIdiom()) { |
| 424 // On iPads, split-screen and slide-over may require showing smaller cells. | 428 // On iPads, split-screen and slide-over may require showing smaller cells. |
| 425 CGSize maximumCellSize = [MostVisitedCell maximumSize]; | 429 CGSize maximumCellSize = [MostVisitedCell maximumSize]; |
| 426 CGSize viewSize = view.bounds.size; | 430 CGSize viewSize = view.bounds.size; |
| 427 CGFloat smallestDimension = | 431 CGFloat smallestDimension = |
| 428 viewSize.height > viewSize.width ? viewSize.width : viewSize.height; | 432 viewSize.height > viewSize.width ? viewSize.width : viewSize.height; |
| 429 CGFloat cellWidth = AlignValueToPixel( | 433 CGFloat cellWidth = AlignValueToPixel( |
| 430 (smallestDimension - 3 * [self.class mostVisitedCellPadding]) / 2); | 434 (smallestDimension - 3 * [self.class mostVisitedCellPadding]) / 2); |
| 431 if (cellWidth < maximumCellSize.width) { | 435 if (cellWidth < maximumCellSize.width) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 // Call -scrollViewDidScroll: so that the omnibox's frame is adjusted for | 481 // Call -scrollViewDidScroll: so that the omnibox's frame is adjusted for |
| 478 // the scroll view's offset. | 482 // the scroll view's offset. |
| 479 [self scrollViewDidScroll:_mostVisitedView]; | 483 [self scrollViewDidScroll:_mostVisitedView]; |
| 480 }; | 484 }; |
| 481 | 485 |
| 482 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0), dispatch_get_main_queue(), | 486 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0), dispatch_get_main_queue(), |
| 483 layoutBlock); | 487 layoutBlock); |
| 484 } | 488 } |
| 485 | 489 |
| 486 - (CGFloat)viewWidth { | 490 - (CGFloat)viewWidth { |
| 487 return [_view frame].size.width; | 491 return [self.view frame].size.width; |
| 488 } | 492 } |
| 489 | 493 |
| 490 - (int)numberOfColumns { | 494 - (int)numberOfColumns { |
| 491 CGFloat width = [self viewWidth]; | 495 CGFloat width = [self viewWidth]; |
| 492 CGFloat padding = [self.class mostVisitedCellPadding]; | 496 CGFloat padding = [self.class mostVisitedCellPadding]; |
| 493 // Try to fit 4 columns. | 497 // Try to fit 4 columns. |
| 494 if (width >= 5 * padding + _mostVisitedCellSize.width * 4) | 498 if (width >= 5 * padding + _mostVisitedCellSize.width * 4) |
| 495 return 4; | 499 return 4; |
| 496 // Try to fit 3 columns. | 500 // Try to fit 3 columns. |
| 497 if (width >= 4 * padding + _mostVisitedCellSize.width * 3) | 501 if (width >= 4 * padding + _mostVisitedCellSize.width * 3) |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 } | 807 } |
| 804 | 808 |
| 805 - (void)resetSectionInset { | 809 - (void)resetSectionInset { |
| 806 UICollectionViewFlowLayout* flowLayout = | 810 UICollectionViewFlowLayout* flowLayout = |
| 807 (UICollectionViewFlowLayout*)[_mostVisitedView collectionViewLayout]; | 811 (UICollectionViewFlowLayout*)[_mostVisitedView collectionViewLayout]; |
| 808 [flowLayout setSectionInset:UIEdgeInsetsZero]; | 812 [flowLayout setSectionInset:UIEdgeInsetsZero]; |
| 809 } | 813 } |
| 810 | 814 |
| 811 - (void)updateSubviewFrames { | 815 - (void)updateSubviewFrames { |
| 812 _mostVisitedCellSize = | 816 _mostVisitedCellSize = |
| 813 [GoogleLandingController mostVisitedCellSizeForView:_view]; | 817 [GoogleLandingController mostVisitedCellSizeForView:self.view]; |
| 814 UICollectionViewFlowLayout* flowLayout = | 818 UICollectionViewFlowLayout* flowLayout = |
| 815 base::mac::ObjCCastStrict<UICollectionViewFlowLayout>( | 819 base::mac::ObjCCastStrict<UICollectionViewFlowLayout>( |
| 816 [_mostVisitedView collectionViewLayout]); | 820 [_mostVisitedView collectionViewLayout]); |
| 817 [flowLayout setItemSize:_mostVisitedCellSize]; | 821 [flowLayout setItemSize:_mostVisitedCellSize]; |
| 818 [[_doodleController view] setFrame:[self doodleFrame]]; | 822 [[_doodleController view] setFrame:[self doodleFrame]]; |
| 819 | 823 |
| 820 [self setFlowLayoutInset:flowLayout]; | 824 [self setFlowLayoutInset:flowLayout]; |
| 821 [flowLayout invalidateLayout]; | 825 [flowLayout invalidateLayout]; |
| 822 [_promoHeaderView setSideMargin:[self leftMargin]]; | 826 [_promoHeaderView setSideMargin:[self leftMargin]]; |
| 823 | 827 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 851 | 855 |
| 852 if (!_viewLoaded) { | 856 if (!_viewLoaded) { |
| 853 _viewLoaded = YES; | 857 _viewLoaded = YES; |
| 854 [_doodleController fetchDoodle]; | 858 [_doodleController fetchDoodle]; |
| 855 } | 859 } |
| 856 [self.delegate updateNtpBarShadowForPanelController:self]; | 860 [self.delegate updateNtpBarShadowForPanelController:self]; |
| 857 } | 861 } |
| 858 | 862 |
| 859 // Initialize and add a panel with most visited sites. | 863 // Initialize and add a panel with most visited sites. |
| 860 - (void)addMostVisited { | 864 - (void)addMostVisited { |
| 861 CGRect mostVisitedFrame = [_view bounds]; | 865 CGRect mostVisitedFrame = [self.view bounds]; |
| 862 base::scoped_nsobject<UICollectionViewFlowLayout> flowLayout; | 866 base::scoped_nsobject<UICollectionViewFlowLayout> flowLayout; |
| 863 if (IsIPadIdiom()) | 867 if (IsIPadIdiom()) |
| 864 flowLayout.reset([[UICollectionViewFlowLayout alloc] init]); | 868 flowLayout.reset([[UICollectionViewFlowLayout alloc] init]); |
| 865 else | 869 else |
| 866 flowLayout.reset([[MostVisitedLayout alloc] init]); | 870 flowLayout.reset([[MostVisitedLayout alloc] init]); |
| 867 | 871 |
| 868 [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; | 872 [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; |
| 869 [flowLayout setItemSize:_mostVisitedCellSize]; | 873 [flowLayout setItemSize:_mostVisitedCellSize]; |
| 870 [flowLayout setMinimumInteritemSpacing:8]; | 874 [flowLayout setMinimumInteritemSpacing:8]; |
| 871 [flowLayout setMinimumLineSpacing:[self.class mostVisitedCellPadding]]; | 875 [flowLayout setMinimumLineSpacing:[self.class mostVisitedCellPadding]]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 884 [_mostVisitedView setShowsHorizontalScrollIndicator:NO]; | 888 [_mostVisitedView setShowsHorizontalScrollIndicator:NO]; |
| 885 [_mostVisitedView setShowsVerticalScrollIndicator:NO]; | 889 [_mostVisitedView setShowsVerticalScrollIndicator:NO]; |
| 886 [_mostVisitedView registerClass:[WhatsNewHeaderView class] | 890 [_mostVisitedView registerClass:[WhatsNewHeaderView class] |
| 887 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 891 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 888 withReuseIdentifier:@"whatsNew"]; | 892 withReuseIdentifier:@"whatsNew"]; |
| 889 [_mostVisitedView registerClass:[NewTabPageHeaderView class] | 893 [_mostVisitedView registerClass:[NewTabPageHeaderView class] |
| 890 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 894 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 891 withReuseIdentifier:@"header"]; | 895 withReuseIdentifier:@"header"]; |
| 892 [_mostVisitedView setAccessibilityIdentifier:@"Google Landing"]; | 896 [_mostVisitedView setAccessibilityIdentifier:@"Google Landing"]; |
| 893 | 897 |
| 894 [_view addSubview:_mostVisitedView]; | 898 [self.view addSubview:_mostVisitedView]; |
| 895 _most_visited_sites = | 899 _most_visited_sites = |
| 896 IOSMostVisitedSitesFactory::NewForBrowserState(_browserState); | 900 IOSMostVisitedSitesFactory::NewForBrowserState(_browserState); |
| 897 _most_visited_observer_bridge.reset( | 901 _most_visited_observer_bridge.reset( |
| 898 new ntp_tiles::MostVisitedSitesObserverBridge(self)); | 902 new ntp_tiles::MostVisitedSitesObserverBridge(self)); |
| 899 _most_visited_sites->SetMostVisitedURLsObserver( | 903 _most_visited_sites->SetMostVisitedURLsObserver( |
| 900 _most_visited_observer_bridge.get(), kMaxNumMostVisitedFavicons); | 904 _most_visited_observer_bridge.get(), kMaxNumMostVisitedFavicons); |
| 901 } | 905 } |
| 902 | 906 |
| 903 - (void)updateSearchField { | 907 - (void)updateSearchField { |
| 904 NSArray* constraints = | 908 NSArray* constraints = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 931 - (void)locationBarBecomesFirstResponder { | 935 - (void)locationBarBecomesFirstResponder { |
| 932 if (!_isShowing) | 936 if (!_isShowing) |
| 933 return; | 937 return; |
| 934 | 938 |
| 935 _omniboxFocused = YES; | 939 _omniboxFocused = YES; |
| 936 [self shiftTilesUp]; | 940 [self shiftTilesUp]; |
| 937 } | 941 } |
| 938 | 942 |
| 939 - (void)shiftTilesUp { | 943 - (void)shiftTilesUp { |
| 940 _scrolledToTop = YES; | 944 _scrolledToTop = YES; |
| 941 // Add gesture recognizer to background |_view| when omnibox is focused. | 945 // Add gesture recognizer to background |self.view| when omnibox is focused. |
| 942 [_view addGestureRecognizer:_tapGestureRecognizer]; | 946 [self.view addGestureRecognizer:_tapGestureRecognizer]; |
| 943 [_view addGestureRecognizer:_swipeGestureRecognizer]; | 947 [self.view addGestureRecognizer:_swipeGestureRecognizer]; |
| 944 | 948 |
| 945 CGFloat pinnedOffsetY = [self pinnedOffsetY]; | 949 CGFloat pinnedOffsetY = [self pinnedOffsetY]; |
| 946 _animateHeader = !IsIPadIdiom(); | 950 _animateHeader = !IsIPadIdiom(); |
| 947 | 951 |
| 948 [UIView animateWithDuration:0.25 | 952 [UIView animateWithDuration:0.25 |
| 949 animations:^{ | 953 animations:^{ |
| 950 if ([_mostVisitedView contentOffset].y < pinnedOffsetY) { | 954 if ([_mostVisitedView contentOffset].y < pinnedOffsetY) { |
| 951 [_mostVisitedView setContentOffset:CGPointMake(0, pinnedOffsetY)]; | 955 [_mostVisitedView setContentOffset:CGPointMake(0, pinnedOffsetY)]; |
| 952 [[_mostVisitedView collectionViewLayout] invalidateLayout]; | 956 [[_mostVisitedView collectionViewLayout] invalidateLayout]; |
| 953 } | 957 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 [_searchTapTarget setHidden:NO]; | 1002 [_searchTapTarget setHidden:NO]; |
| 999 [_focuser onFakeboxBlur]; | 1003 [_focuser onFakeboxBlur]; |
| 1000 } | 1004 } |
| 1001 | 1005 |
| 1002 // Reload most visited sites in case the number of placeholder cells needs to | 1006 // Reload most visited sites in case the number of placeholder cells needs to |
| 1003 // be updated after an orientation change. | 1007 // be updated after an orientation change. |
| 1004 [_mostVisitedView reloadData]; | 1008 [_mostVisitedView reloadData]; |
| 1005 | 1009 |
| 1006 // Reshow views that are within range of the most visited collection view | 1010 // Reshow views that are within range of the most visited collection view |
| 1007 // (if necessary). | 1011 // (if necessary). |
| 1008 [_view removeGestureRecognizer:_tapGestureRecognizer]; | 1012 [self.view removeGestureRecognizer:_tapGestureRecognizer]; |
| 1009 [_view removeGestureRecognizer:_swipeGestureRecognizer]; | 1013 [self.view removeGestureRecognizer:_swipeGestureRecognizer]; |
| 1010 | 1014 |
| 1011 // CADisplayLink is used for this animation instead of the standard UIView | 1015 // CADisplayLink is used for this animation instead of the standard UIView |
| 1012 // animation because the standard animation did not properly convert the | 1016 // animation because the standard animation did not properly convert the |
| 1013 // fakebox from its scrolled up mode to its scrolled down mode. Specifically, | 1017 // fakebox from its scrolled up mode to its scrolled down mode. Specifically, |
| 1014 // calling |UICollectionView reloadData| adjacent to the standard animation | 1018 // calling |UICollectionView reloadData| adjacent to the standard animation |
| 1015 // caused the fakebox's views to jump incorrectly. CADisplayLink avoids this | 1019 // caused the fakebox's views to jump incorrectly. CADisplayLink avoids this |
| 1016 // problem because it allows |shiftTilesDownAnimationDidFire| to directly | 1020 // problem because it allows |shiftTilesDownAnimationDidFire| to directly |
| 1017 // control each frame. | 1021 // control each frame. |
| 1018 CADisplayLink* link = [CADisplayLink | 1022 CADisplayLink* link = [CADisplayLink |
| 1019 displayLinkWithTarget:self | 1023 displayLinkWithTarget:self |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 [_contextMenuCoordinator stop]; | 1487 [_contextMenuCoordinator stop]; |
| 1484 } | 1488 } |
| 1485 | 1489 |
| 1486 - (void)dismissKeyboard { | 1490 - (void)dismissKeyboard { |
| 1487 } | 1491 } |
| 1488 | 1492 |
| 1489 - (void)setScrollsToTop:(BOOL)enable { | 1493 - (void)setScrollsToTop:(BOOL)enable { |
| 1490 } | 1494 } |
| 1491 | 1495 |
| 1492 - (CGFloat)alphaForBottomShadow { | 1496 - (CGFloat)alphaForBottomShadow { |
| 1493 // Get the frame of the bottommost cell in |_view|'s coordinate system. | 1497 // Get the frame of the bottommost cell in |self.view|'s coordinate system. |
| 1494 NSInteger section = SectionWithMostVisited; | 1498 NSInteger section = SectionWithMostVisited; |
| 1495 // Account for the fact that the tableview may not yet contain | 1499 // Account for the fact that the tableview may not yet contain |
| 1496 // |numberOfNonEmptyTilesShown| tiles because it hasn't been updated yet. | 1500 // |numberOfNonEmptyTilesShown| tiles because it hasn't been updated yet. |
| 1497 NSUInteger lastItemIndex = | 1501 NSUInteger lastItemIndex = |
| 1498 std::min([_mostVisitedView numberOfItemsInSection:SectionWithMostVisited], | 1502 std::min([_mostVisitedView numberOfItemsInSection:SectionWithMostVisited], |
| 1499 [self numberOfNonEmptyTilesShown]) - | 1503 [self numberOfNonEmptyTilesShown]) - |
| 1500 1; | 1504 1; |
| 1501 DCHECK(lastItemIndex >= 0); | 1505 DCHECK(lastItemIndex >= 0); |
| 1502 NSIndexPath* lastCellIndexPath = | 1506 NSIndexPath* lastCellIndexPath = |
| 1503 [NSIndexPath indexPathForItem:lastItemIndex inSection:section]; | 1507 [NSIndexPath indexPathForItem:lastItemIndex inSection:section]; |
| 1504 UICollectionViewLayoutAttributes* attributes = | 1508 UICollectionViewLayoutAttributes* attributes = |
| 1505 [_mostVisitedView layoutAttributesForItemAtIndexPath:lastCellIndexPath]; | 1509 [_mostVisitedView layoutAttributesForItemAtIndexPath:lastCellIndexPath]; |
| 1506 CGRect lastCellFrame = attributes.frame; | 1510 CGRect lastCellFrame = attributes.frame; |
| 1507 CGRect cellFrameInSuperview = | 1511 CGRect cellFrameInSuperview = |
| 1508 [_mostVisitedView convertRect:lastCellFrame toView:self.view]; | 1512 [_mostVisitedView convertRect:lastCellFrame toView:self.view]; |
| 1509 | 1513 |
| 1510 // Calculate when the bottom of the cell passes through the bottom of |_view|. | 1514 // Calculate when the bottom of the cell passes through the bottom of |
| 1515 // |self.view|. |
| 1511 CGFloat maxY = CGRectGetMaxY(cellFrameInSuperview); | 1516 CGFloat maxY = CGRectGetMaxY(cellFrameInSuperview); |
| 1512 CGFloat viewHeight = CGRectGetHeight(self.view.frame); | 1517 CGFloat viewHeight = CGRectGetHeight(self.view.frame); |
| 1513 | 1518 |
| 1514 CGFloat pixelsBelowFrame = maxY - viewHeight; | 1519 CGFloat pixelsBelowFrame = maxY - viewHeight; |
| 1515 CGFloat alpha = pixelsBelowFrame / kNewTabPageDistanceToFadeShadow; | 1520 CGFloat alpha = pixelsBelowFrame / kNewTabPageDistanceToFadeShadow; |
| 1516 alpha = MIN(MAX(alpha, 0), 1); | 1521 alpha = MIN(MAX(alpha, 0), 1); |
| 1517 return alpha; | 1522 return alpha; |
| 1518 } | 1523 } |
| 1519 | 1524 |
| 1520 - (UIView*)view { | |
| 1521 return _view; | |
| 1522 } | |
| 1523 | |
| 1524 #pragma mark - LogoAnimationControllerOwnerOwner | 1525 #pragma mark - LogoAnimationControllerOwnerOwner |
| 1525 | 1526 |
| 1526 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { | 1527 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { |
| 1527 return [_doodleController logoAnimationControllerOwner]; | 1528 return [_doodleController logoAnimationControllerOwner]; |
| 1528 } | 1529 } |
| 1529 | 1530 |
| 1530 #pragma mark - UIScrollViewDelegate Methods. | 1531 #pragma mark - UIScrollViewDelegate Methods. |
| 1531 | 1532 |
| 1532 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { | 1533 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { |
| 1533 [self.delegate updateNtpBarShadowForPanelController:self]; | 1534 [self.delegate updateNtpBarShadowForPanelController:self]; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 if (!view) { | 1706 if (!view) { |
| 1706 return nil; | 1707 return nil; |
| 1707 } | 1708 } |
| 1708 if ([view isKindOfClass:aClass]) { | 1709 if ([view isKindOfClass:aClass]) { |
| 1709 return view; | 1710 return view; |
| 1710 } | 1711 } |
| 1711 return [self nearestAncestorOfView:[view superview] withClass:aClass]; | 1712 return [self nearestAncestorOfView:[view superview] withClass:aClass]; |
| 1712 } | 1713 } |
| 1713 | 1714 |
| 1714 @end | 1715 @end |
| OLD | NEW |