| 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" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
| 13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 14 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 14 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_utils.h" |
| 16 #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h" | 17 #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h" |
| 17 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" | 18 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" |
| 18 #import "ios/chrome/browser/ui/ntp/most_visited_cell.h" | 19 #import "ios/chrome/browser/ui/ntp/most_visited_cell.h" |
| 19 #import "ios/chrome/browser/ui/ntp/most_visited_layout.h" | 20 #import "ios/chrome/browser/ui/ntp/most_visited_layout.h" |
| 20 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h" | 21 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h" |
| 21 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_view.h" | 22 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_view.h" |
| 22 #import "ios/chrome/browser/ui/ntp/whats_new_header_view.h" | 23 #import "ios/chrome/browser/ui/ntp/whats_new_header_view.h" |
| 23 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" | 24 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" |
| 24 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 25 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
| 25 #include "ios/chrome/browser/ui/ui_util.h" | 26 #include "ios/chrome/browser/ui/ui_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 using base::UserMetricsAction; | 38 using base::UserMetricsAction; |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 enum { | 42 enum { |
| 42 SectionWithOmnibox, | 43 SectionWithOmnibox, |
| 43 SectionWithMostVisited, | 44 SectionWithMostVisited, |
| 44 NumberOfCollectionViewSections, | 45 NumberOfCollectionViewSections, |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 enum InterfaceOrientation { | |
| 48 ALL, | |
| 49 IPHONE_LANDSCAPE, | |
| 50 }; | |
| 51 | |
| 52 const CGFloat kVoiceSearchButtonWidth = 48; | 48 const CGFloat kVoiceSearchButtonWidth = 48; |
| 53 const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3}; | 49 const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3}; |
| 54 | 50 |
| 55 // Height for the doodle frame when Google is not the default search engine. | |
| 56 const CGFloat kNonGoogleSearchDoodleHeight = 60; | |
| 57 // Height for the header view on tablet when Google is not the default search | |
| 58 // engine. | |
| 59 const CGFloat kNonGoogleSearchHeaderHeightIPad = 10; | |
| 60 | |
| 61 const CGFloat kHintLabelSidePadding = 12; | 51 const CGFloat kHintLabelSidePadding = 12; |
| 62 const CGFloat kNTPSearchFieldBottomPadding = 16; | |
| 63 const CGFloat kWhatsNewHeaderHiddenHeight = 8; | 52 const CGFloat kWhatsNewHeaderHiddenHeight = 8; |
| 64 const CGFloat kDoodleTopMarginIPadPortrait = 82; | |
| 65 const CGFloat kDoodleTopMarginIPadLandscape = 82; | |
| 66 const NSInteger kMaxNumMostVisitedFaviconRows = 2; | 53 const NSInteger kMaxNumMostVisitedFaviconRows = 2; |
| 67 const CGFloat kMaxSearchFieldFrameMargin = 200; | |
| 68 const CGFloat kShiftTilesDownAnimationDuration = 0.2; | 54 const CGFloat kShiftTilesDownAnimationDuration = 0.2; |
| 69 | 55 |
| 70 const CGFloat kMostVisitedPaddingIPhone = 16; | |
| 71 const CGFloat kMostVisitedPaddingIPadFavicon = 24; | |
| 72 | |
| 73 } // namespace | 56 } // namespace |
| 74 | 57 |
| 75 @interface GoogleLandingViewController (UsedByGoogleLandingView) | 58 @interface GoogleLandingViewController (UsedByGoogleLandingView) |
| 76 // Update frames for subviews depending on the interface orientation. | 59 // Update frames for subviews depending on the interface orientation. |
| 77 - (void)updateSubviewFrames; | 60 - (void)updateSubviewFrames; |
| 78 // Resets the collection view's inset to 0. | 61 // Resets the collection view's inset to 0. |
| 79 - (void)resetSectionInset; | 62 - (void)resetSectionInset; |
| 80 - (void)reloadData; | 63 - (void)reloadData; |
| 81 @end | 64 @end |
| 82 | 65 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 @property(nonatomic, assign) int tabCount; | 180 @property(nonatomic, assign) int tabCount; |
| 198 | 181 |
| 199 // |YES| if the google landing toolbar can show the forward arrow, cached and | 182 // |YES| if the google landing toolbar can show the forward arrow, cached and |
| 200 // pushed into the header view. | 183 // pushed into the header view. |
| 201 @property(nonatomic, assign) BOOL canGoForward; | 184 @property(nonatomic, assign) BOOL canGoForward; |
| 202 | 185 |
| 203 // |YES| if the google landing toolbar can show the back arrow, cached and | 186 // |YES| if the google landing toolbar can show the back arrow, cached and |
| 204 // pushed into the header view. | 187 // pushed into the header view. |
| 205 @property(nonatomic, assign) BOOL canGoBack; | 188 @property(nonatomic, assign) BOOL canGoBack; |
| 206 | 189 |
| 207 // iPhone landscape uses a slightly different layout for the doodle and search | |
| 208 // field frame. Returns the proper frame from |frames| based on orientation, | |
| 209 // centered in the view. | |
| 210 - (CGRect)getOrientationFrame:(const CGRect[])frames; | |
| 211 // Returns the proper frame for the doodle. | |
| 212 - (CGRect)doodleFrame; | |
| 213 // Returns the proper frame for the search field. | |
| 214 - (CGRect)searchFieldFrame; | |
| 215 // Returns the height to use for the What's New promo view. | 190 // Returns the height to use for the What's New promo view. |
| 216 - (CGFloat)promoHeaderHeight; | 191 - (CGFloat)promoHeaderHeight; |
| 217 // Add fake search field and voice search microphone. | 192 // Add fake search field and voice search microphone. |
| 218 - (void)addSearchField; | 193 - (void)addSearchField; |
| 219 // Add most visited collection view. | 194 // Add most visited collection view. |
| 220 - (void)addMostVisited; | 195 - (void)addMostVisited; |
| 221 // Update the iPhone fakebox's frame based on the current scroll view offset. | 196 // Update the iPhone fakebox's frame based on the current scroll view offset. |
| 222 - (void)updateSearchField; | 197 - (void)updateSearchField; |
| 223 // Scrolls most visited to the top of the view when the omnibox is focused. | 198 // Scrolls most visited to the top of the view when the omnibox is focused. |
| 224 - (void)locationBarBecomesFirstResponder; | 199 - (void)locationBarBecomesFirstResponder; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 239 // Helper method to set UICollectionViewFlowLayout insets for most visited. | 214 // Helper method to set UICollectionViewFlowLayout insets for most visited. |
| 240 - (void)setFlowLayoutInset:(UICollectionViewFlowLayout*)layout; | 215 - (void)setFlowLayoutInset:(UICollectionViewFlowLayout*)layout; |
| 241 // Instructs the UICollectionView and UIView to reload it's data and layout. | 216 // Instructs the UICollectionView and UIView to reload it's data and layout. |
| 242 - (void)reloadData; | 217 - (void)reloadData; |
| 243 // Returns the size of |self.mostVisitedData|. | 218 // Returns the size of |self.mostVisitedData|. |
| 244 - (NSUInteger)numberOfItems; | 219 - (NSUInteger)numberOfItems; |
| 245 // Returns the number of non empty tiles (as opposed to the placeholder tiles). | 220 // Returns the number of non empty tiles (as opposed to the placeholder tiles). |
| 246 - (NSInteger)numberOfNonEmptyTilesShown; | 221 - (NSInteger)numberOfNonEmptyTilesShown; |
| 247 // Returns the URL for the mosted visited item in |self.mostVisitedData|. | 222 // Returns the URL for the mosted visited item in |self.mostVisitedData|. |
| 248 - (GURL)urlForIndex:(NSUInteger)index; | 223 - (GURL)urlForIndex:(NSUInteger)index; |
| 249 // Returns the expected height of the NewTabPageHeaderView. | |
| 250 - (CGFloat)heightForSectionWithOmnibox; | |
| 251 // Returns the nearest ancestor view that is kind of |aClass|. | 224 // Returns the nearest ancestor view that is kind of |aClass|. |
| 252 - (UIView*)nearestAncestorOfView:(UIView*)view withClass:(Class)aClass; | 225 - (UIView*)nearestAncestorOfView:(UIView*)view withClass:(Class)aClass; |
| 253 // Updates the collection view's scroll view offset for the next frame of the | 226 // Updates the collection view's scroll view offset for the next frame of the |
| 254 // shiftTilesDown animation. | 227 // shiftTilesDown animation. |
| 255 - (void)shiftTilesDownAnimationDidFire:(CADisplayLink*)link; | 228 - (void)shiftTilesDownAnimationDidFire:(CADisplayLink*)link; |
| 256 // Returns the size to use for Most Visited cells in the NTP. | 229 // Returns the size to use for Most Visited cells in the NTP. |
| 257 - (CGSize)mostVisitedCellSize; | 230 - (CGSize)mostVisitedCellSize; |
| 258 // Returns the padding for use between Most Visited cells. | |
| 259 - (CGFloat)mostVisitedCellPadding; | |
| 260 | 231 |
| 261 @end | 232 @end |
| 262 | 233 |
| 263 @implementation GoogleLandingViewController | 234 @implementation GoogleLandingViewController |
| 264 | 235 |
| 265 @dynamic view; | 236 @dynamic view; |
| 266 @synthesize logoVendor = _logoVendor; | 237 @synthesize logoVendor = _logoVendor; |
| 267 @synthesize dataSource = _dataSource; | 238 @synthesize dataSource = _dataSource; |
| 268 // Property declared in NewTabPagePanelProtocol. | 239 // Property declared in NewTabPagePanelProtocol. |
| 269 @synthesize delegate = _delegate; | 240 @synthesize delegate = _delegate; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 #pragma mark - Private | 326 #pragma mark - Private |
| 356 | 327 |
| 357 - (CGSize)mostVisitedCellSize { | 328 - (CGSize)mostVisitedCellSize { |
| 358 if (IsIPadIdiom()) { | 329 if (IsIPadIdiom()) { |
| 359 // On iPads, split-screen and slide-over may require showing smaller cells. | 330 // On iPads, split-screen and slide-over may require showing smaller cells. |
| 360 CGSize maximumCellSize = [MostVisitedCell maximumSize]; | 331 CGSize maximumCellSize = [MostVisitedCell maximumSize]; |
| 361 CGSize viewSize = self.view.bounds.size; | 332 CGSize viewSize = self.view.bounds.size; |
| 362 CGFloat smallestDimension = | 333 CGFloat smallestDimension = |
| 363 viewSize.height > viewSize.width ? viewSize.width : viewSize.height; | 334 viewSize.height > viewSize.width ? viewSize.width : viewSize.height; |
| 364 CGFloat cellWidth = AlignValueToPixel( | 335 CGFloat cellWidth = AlignValueToPixel( |
| 365 (smallestDimension - 3 * [self mostVisitedCellPadding]) / 2); | 336 (smallestDimension - 3 * content_suggestions::spacingBetweenTiles()) / |
| 337 2); |
| 366 if (cellWidth < maximumCellSize.width) { | 338 if (cellWidth < maximumCellSize.width) { |
| 367 return CGSizeMake(cellWidth, cellWidth); | 339 return CGSizeMake(cellWidth, cellWidth); |
| 368 } else { | 340 } else { |
| 369 return maximumCellSize; | 341 return maximumCellSize; |
| 370 } | 342 } |
| 371 } else { | 343 } else { |
| 372 return [MostVisitedCell maximumSize]; | 344 return [MostVisitedCell maximumSize]; |
| 373 } | 345 } |
| 374 } | 346 } |
| 375 | 347 |
| 376 - (CGFloat)mostVisitedCellPadding { | |
| 377 return IsIPadIdiom() ? kMostVisitedPaddingIPadFavicon | |
| 378 : kMostVisitedPaddingIPhone; | |
| 379 } | |
| 380 | |
| 381 - (CGFloat)viewWidth { | 348 - (CGFloat)viewWidth { |
| 382 return [self.view frame].size.width; | 349 return [self.view frame].size.width; |
| 383 } | 350 } |
| 384 | 351 |
| 385 - (int)numberOfColumns { | 352 - (int)numberOfColumns { |
| 386 CGFloat width = [self viewWidth]; | 353 CGFloat width = [self viewWidth]; |
| 387 CGFloat padding = [self mostVisitedCellPadding]; | |
| 388 // Try to fit 4 columns. | |
| 389 if (width >= 5 * padding + _mostVisitedCellSize.width * 4) | |
| 390 return 4; | |
| 391 // Try to fit 3 columns. | |
| 392 if (width >= 4 * padding + _mostVisitedCellSize.width * 3) | |
| 393 return 3; | |
| 394 // Try to fit 2 columns. | |
| 395 if (width >= 3 * padding + _mostVisitedCellSize.width * 2) | |
| 396 return 2; | |
| 397 // We never want to have a layout with only one column, however: At launch, | |
| 398 // the view's size is initialized to the width of 320, which can only fit | |
| 399 // one column on iPhone 6 and 6+. TODO(crbug.com/506183): Get rid of the | |
| 400 // unecessary resize, and add a NOTREACHED() here. | |
| 401 return 1; | |
| 402 } | |
| 403 | 354 |
| 404 - (CGFloat)leftMargin { | 355 NSUInteger columns = content_suggestions::numberOfTilesForWidth( |
| 405 int columns = [self numberOfColumns]; | 356 width - 2 * content_suggestions::spacingBetweenTiles()); |
| 406 CGFloat whitespace = [self viewWidth] - columns * _mostVisitedCellSize.width - | 357 DCHECK(columns > 1); |
| 407 (columns - 1) * [self mostVisitedCellPadding]; | 358 return columns; |
| 408 CGFloat margin = AlignValueToPixel(whitespace / 2); | |
| 409 DCHECK(margin >= [self mostVisitedCellPadding]); | |
| 410 return margin; | |
| 411 } | |
| 412 | |
| 413 - (CGRect)doodleFrame { | |
| 414 const CGRect kDoodleFrame[2] = { | |
| 415 {{0, 66}, {0, 120}}, {{0, 56}, {0, 120}}, | |
| 416 }; | |
| 417 CGRect doodleFrame = [self getOrientationFrame:kDoodleFrame]; | |
| 418 if (!IsIPadIdiom() && !self.logoIsShowing) | |
| 419 doodleFrame.size.height = kNonGoogleSearchDoodleHeight; | |
| 420 if (IsIPadIdiom()) { | |
| 421 doodleFrame.origin.y = IsPortrait() ? kDoodleTopMarginIPadPortrait | |
| 422 : kDoodleTopMarginIPadLandscape; | |
| 423 } | |
| 424 return doodleFrame; | |
| 425 } | |
| 426 | |
| 427 - (CGRect)searchFieldFrame { | |
| 428 CGFloat y = CGRectGetMaxY([self doodleFrame]); | |
| 429 CGFloat leftMargin = [self leftMargin]; | |
| 430 if (leftMargin > kMaxSearchFieldFrameMargin) | |
| 431 leftMargin = kMaxSearchFieldFrameMargin; | |
| 432 const CGRect kSearchFieldFrame[2] = { | |
| 433 {{leftMargin, y + 32}, {0, 50}}, {{leftMargin, y + 16}, {0, 50}}, | |
| 434 }; | |
| 435 CGRect searchFieldFrame = [self getOrientationFrame:kSearchFieldFrame]; | |
| 436 if (IsIPadIdiom()) { | |
| 437 CGFloat iPadTopMargin = IsPortrait() ? kDoodleTopMarginIPadPortrait | |
| 438 : kDoodleTopMarginIPadLandscape; | |
| 439 searchFieldFrame.origin.y += iPadTopMargin - 32; | |
| 440 } | |
| 441 return searchFieldFrame; | |
| 442 } | |
| 443 | |
| 444 - (CGRect)getOrientationFrame:(const CGRect[])frames { | |
| 445 UIInterfaceOrientation orient = | |
| 446 [[UIApplication sharedApplication] statusBarOrientation]; | |
| 447 InterfaceOrientation inter_orient = | |
| 448 (IsIPadIdiom() || UIInterfaceOrientationIsPortrait(orient)) | |
| 449 ? ALL | |
| 450 : IPHONE_LANDSCAPE; | |
| 451 | |
| 452 // Calculate width based on screen width and origin x. | |
| 453 CGRect frame = frames[inter_orient]; | |
| 454 frame.size.width = fmax(self.view.bounds.size.width - 2 * frame.origin.x, 50); | |
| 455 return frame; | |
| 456 } | 359 } |
| 457 | 360 |
| 458 - (CGFloat)promoHeaderHeight { | 361 - (CGFloat)promoHeaderHeight { |
| 459 CGFloat promoMaxWidth = [self viewWidth] - 2 * [self leftMargin]; | 362 CGFloat promoMaxWidth = |
| 363 [self viewWidth] - |
| 364 2 * content_suggestions::centeredTilesMarginForWidth([self viewWidth]); |
| 460 NSString* text = self.promoText; | 365 NSString* text = self.promoText; |
| 461 return [WhatsNewHeaderView heightToFitText:text inWidth:promoMaxWidth]; | 366 return [WhatsNewHeaderView heightToFitText:text inWidth:promoMaxWidth]; |
| 462 } | 367 } |
| 463 | 368 |
| 464 - (void)updateLogoAndFakeboxDisplay { | 369 - (void)updateLogoAndFakeboxDisplay { |
| 465 if (self.logoVendor.showingLogo != self.logoIsShowing) { | 370 if (self.logoVendor.showingLogo != self.logoIsShowing) { |
| 466 self.logoVendor.showingLogo = self.logoIsShowing; | 371 self.logoVendor.showingLogo = self.logoIsShowing; |
| 467 if (_viewLoaded) { | 372 if (_viewLoaded) { |
| 468 [self updateSubviewFrames]; | 373 [self updateSubviewFrames]; |
| 469 | 374 |
| 470 // Adjust the height of |_headerView| to fit its content which may have | 375 // Adjust the height of |_headerView| to fit its content which may have |
| 471 // been shifted due to the visibility of the doodle. | 376 // been shifted due to the visibility of the doodle. |
| 472 CGRect headerFrame = [_headerView frame]; | 377 CGRect headerFrame = [_headerView frame]; |
| 473 headerFrame.size.height = [self heightForSectionWithOmnibox]; | 378 headerFrame.size.height = content_suggestions::heightForLogoHeader( |
| 379 [self viewWidth], self.logoIsShowing, self.promoCanShow); |
| 474 [_headerView setFrame:headerFrame]; | 380 [_headerView setFrame:headerFrame]; |
| 475 | 381 |
| 476 // Adjust vertical positioning of |_promoHeaderView|. | 382 // Adjust vertical positioning of |_promoHeaderView|. |
| 477 CGFloat omniboxHeaderHeight = | 383 CGFloat omniboxHeaderHeight = |
| 478 [self collectionView:_mostVisitedView | 384 [self collectionView:_mostVisitedView |
| 479 layout:[_mostVisitedView | 385 layout:[_mostVisitedView |
| 480 collectionViewLayout] | 386 collectionViewLayout] |
| 481 referenceSizeForHeaderInSection:0] | 387 referenceSizeForHeaderInSection:0] |
| 482 .height; | 388 .height; |
| 483 CGRect whatsNewFrame = [_promoHeaderView frame]; | 389 CGRect whatsNewFrame = [_promoHeaderView frame]; |
| 484 whatsNewFrame.origin.y = omniboxHeaderHeight; | 390 whatsNewFrame.origin.y = omniboxHeaderHeight; |
| 485 [_promoHeaderView setFrame:whatsNewFrame]; | 391 [_promoHeaderView setFrame:whatsNewFrame]; |
| 486 } | 392 } |
| 487 if (IsIPadIdiom()) | 393 if (IsIPadIdiom()) |
| 488 [_searchTapTarget setHidden:!self.logoIsShowing]; | 394 [_searchTapTarget setHidden:!self.logoIsShowing]; |
| 489 } | 395 } |
| 490 } | 396 } |
| 491 | 397 |
| 492 // Initialize and add a search field tap target and a voice search button. | 398 // Initialize and add a search field tap target and a voice search button. |
| 493 - (void)addSearchField { | 399 - (void)addSearchField { |
| 494 CGRect searchFieldFrame = [self searchFieldFrame]; | 400 CGRect searchFieldFrame = content_suggestions::searchFieldFrame( |
| 401 [self viewWidth], self.logoIsShowing); |
| 495 _searchTapTarget.reset([[UIButton alloc] initWithFrame:searchFieldFrame]); | 402 _searchTapTarget.reset([[UIButton alloc] initWithFrame:searchFieldFrame]); |
| 496 if (IsIPadIdiom()) { | 403 if (IsIPadIdiom()) { |
| 497 UIImage* searchBoxImage = [[UIImage imageNamed:@"ntp_google_search_box"] | 404 UIImage* searchBoxImage = [[UIImage imageNamed:@"ntp_google_search_box"] |
| 498 resizableImageWithCapInsets:kSearchBoxStretchInsets]; | 405 resizableImageWithCapInsets:kSearchBoxStretchInsets]; |
| 499 [_searchTapTarget setBackgroundImage:searchBoxImage | 406 [_searchTapTarget setBackgroundImage:searchBoxImage |
| 500 forState:UIControlStateNormal]; | 407 forState:UIControlStateNormal]; |
| 501 } | 408 } |
| 502 [_searchTapTarget setAdjustsImageWhenHighlighted:NO]; | 409 [_searchTapTarget setAdjustsImageWhenHighlighted:NO]; |
| 503 [_searchTapTarget addTarget:self | 410 [_searchTapTarget addTarget:self |
| 504 action:@selector(searchFieldTapped:) | 411 action:@selector(searchFieldTapped:) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 forControlEvents:UIControlEventTouchDown]; | 499 forControlEvents:UIControlEventTouchDown]; |
| 593 | 500 |
| 594 // Use a GenericChromeCommand because |sender| already has a tag set for a | 501 // Use a GenericChromeCommand because |sender| already has a tag set for a |
| 595 // different command. | 502 // different command. |
| 596 base::scoped_nsobject<GenericChromeCommand> command( | 503 base::scoped_nsobject<GenericChromeCommand> command( |
| 597 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]); | 504 [[GenericChromeCommand alloc] initWithTag:IDC_PRELOAD_VOICE_SEARCH]); |
| 598 [sender chromeExecuteCommand:command]; | 505 [sender chromeExecuteCommand:command]; |
| 599 } | 506 } |
| 600 | 507 |
| 601 - (void)setFlowLayoutInset:(UICollectionViewFlowLayout*)layout { | 508 - (void)setFlowLayoutInset:(UICollectionViewFlowLayout*)layout { |
| 602 CGFloat leftMargin = [self leftMargin]; | 509 CGFloat leftMargin = |
| 510 content_suggestions::centeredTilesMarginForWidth([self viewWidth]); |
| 603 [layout setSectionInset:UIEdgeInsetsMake(0, leftMargin, 0, leftMargin)]; | 511 [layout setSectionInset:UIEdgeInsetsMake(0, leftMargin, 0, leftMargin)]; |
| 604 } | 512 } |
| 605 | 513 |
| 606 - (void)resetSectionInset { | 514 - (void)resetSectionInset { |
| 607 UICollectionViewFlowLayout* flowLayout = | 515 UICollectionViewFlowLayout* flowLayout = |
| 608 (UICollectionViewFlowLayout*)[_mostVisitedView collectionViewLayout]; | 516 (UICollectionViewFlowLayout*)[_mostVisitedView collectionViewLayout]; |
| 609 [flowLayout setSectionInset:UIEdgeInsetsZero]; | 517 [flowLayout setSectionInset:UIEdgeInsetsZero]; |
| 610 } | 518 } |
| 611 | 519 |
| 612 - (void)updateSubviewFrames { | 520 - (void)updateSubviewFrames { |
| 613 _mostVisitedCellSize = [self mostVisitedCellSize]; | 521 _mostVisitedCellSize = [self mostVisitedCellSize]; |
| 614 UICollectionViewFlowLayout* flowLayout = | 522 UICollectionViewFlowLayout* flowLayout = |
| 615 base::mac::ObjCCastStrict<UICollectionViewFlowLayout>( | 523 base::mac::ObjCCastStrict<UICollectionViewFlowLayout>( |
| 616 [_mostVisitedView collectionViewLayout]); | 524 [_mostVisitedView collectionViewLayout]); |
| 617 [flowLayout setItemSize:_mostVisitedCellSize]; | 525 [flowLayout setItemSize:_mostVisitedCellSize]; |
| 618 self.logoVendor.view.frame = [self doodleFrame]; | 526 self.logoVendor.view.frame = |
| 527 content_suggestions::doodleFrame([self viewWidth], self.logoIsShowing); |
| 619 | 528 |
| 620 [self setFlowLayoutInset:flowLayout]; | 529 [self setFlowLayoutInset:flowLayout]; |
| 621 [flowLayout invalidateLayout]; | 530 [flowLayout invalidateLayout]; |
| 622 [_promoHeaderView setSideMargin:[self leftMargin]]; | 531 [_promoHeaderView |
| 532 setSideMargin:content_suggestions::centeredTilesMarginForWidth( |
| 533 [self viewWidth])]; |
| 623 | 534 |
| 624 // On the iPhone 6 Plus, if the app is started in landscape after a fresh | 535 // On the iPhone 6 Plus, if the app is started in landscape after a fresh |
| 625 // install, the UICollectionViewLayout incorrectly sizes the widths of the | 536 // install, the UICollectionViewLayout incorrectly sizes the widths of the |
| 626 // supplementary views to the portrait width. Correct that here to ensure | 537 // supplementary views to the portrait width. Correct that here to ensure |
| 627 // that the header is property laid out to the UICollectionView's width. | 538 // that the header is property laid out to the UICollectionView's width. |
| 628 // crbug.com/491131 | 539 // crbug.com/491131 |
| 629 CGFloat collectionViewWidth = CGRectGetWidth([_mostVisitedView bounds]); | 540 CGFloat collectionViewWidth = CGRectGetWidth([_mostVisitedView bounds]); |
| 630 CGFloat collectionViewMinX = CGRectGetMinX([_mostVisitedView bounds]); | 541 CGFloat collectionViewMinX = CGRectGetMinX([_mostVisitedView bounds]); |
| 631 for (UIView* supplementaryView in _supplementaryViews.get()) { | 542 for (UIView* supplementaryView in _supplementaryViews.get()) { |
| 632 CGRect supplementaryViewFrame = supplementaryView.frame; | 543 CGRect supplementaryViewFrame = supplementaryView.frame; |
| 633 supplementaryViewFrame.origin.x = collectionViewMinX; | 544 supplementaryViewFrame.origin.x = collectionViewMinX; |
| 634 supplementaryViewFrame.size.width = collectionViewWidth; | 545 supplementaryViewFrame.size.width = collectionViewWidth; |
| 635 supplementaryView.frame = supplementaryViewFrame; | 546 supplementaryView.frame = supplementaryViewFrame; |
| 636 } | 547 } |
| 637 | 548 |
| 638 BOOL isScrollableNTP = !IsIPadIdiom() || IsCompactTablet(); | 549 BOOL isScrollableNTP = !IsIPadIdiom() || IsCompactTablet(); |
| 639 if (isScrollableNTP && _scrolledToTop) { | 550 if (isScrollableNTP && _scrolledToTop) { |
| 640 // Set the scroll view's offset to the pinned offset to keep the omnibox | 551 // Set the scroll view's offset to the pinned offset to keep the omnibox |
| 641 // at the top of the screen if it isn't already. | 552 // at the top of the screen if it isn't already. |
| 642 CGFloat pinnedOffsetY = [self pinnedOffsetY]; | 553 CGFloat pinnedOffsetY = [self pinnedOffsetY]; |
| 643 if ([_mostVisitedView contentOffset].y < pinnedOffsetY) { | 554 if ([_mostVisitedView contentOffset].y < pinnedOffsetY) { |
| 644 [_mostVisitedView setContentOffset:CGPointMake(0, pinnedOffsetY)]; | 555 [_mostVisitedView setContentOffset:CGPointMake(0, pinnedOffsetY)]; |
| 645 } else { | 556 } else { |
| 646 [self updateSearchField]; | 557 [self updateSearchField]; |
| 647 } | 558 } |
| 648 } else { | 559 } else { |
| 649 [_searchTapTarget setFrame:[self searchFieldFrame]]; | 560 [_searchTapTarget setFrame:content_suggestions::searchFieldFrame( |
| 561 [self viewWidth], self.logoIsShowing)]; |
| 650 } | 562 } |
| 651 | 563 |
| 652 if (!_viewLoaded) { | 564 if (!_viewLoaded) { |
| 653 _viewLoaded = YES; | 565 _viewLoaded = YES; |
| 654 [self.logoVendor fetchDoodle]; | 566 [self.logoVendor fetchDoodle]; |
| 655 } | 567 } |
| 656 [self.delegate updateNtpBarShadowForPanelController:self]; | 568 [self.delegate updateNtpBarShadowForPanelController:self]; |
| 657 } | 569 } |
| 658 | 570 |
| 659 // Initialize and add a panel with most visited sites. | 571 // Initialize and add a panel with most visited sites. |
| 660 - (void)addMostVisited { | 572 - (void)addMostVisited { |
| 661 CGRect mostVisitedFrame = [self.view bounds]; | 573 CGRect mostVisitedFrame = [self.view bounds]; |
| 662 base::scoped_nsobject<UICollectionViewFlowLayout> flowLayout; | 574 base::scoped_nsobject<UICollectionViewFlowLayout> flowLayout; |
| 663 if (IsIPadIdiom()) | 575 if (IsIPadIdiom()) |
| 664 flowLayout.reset([[UICollectionViewFlowLayout alloc] init]); | 576 flowLayout.reset([[UICollectionViewFlowLayout alloc] init]); |
| 665 else | 577 else |
| 666 flowLayout.reset([[MostVisitedLayout alloc] init]); | 578 flowLayout.reset([[MostVisitedLayout alloc] init]); |
| 667 | 579 |
| 668 [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; | 580 [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; |
| 669 [flowLayout setItemSize:_mostVisitedCellSize]; | 581 [flowLayout setItemSize:_mostVisitedCellSize]; |
| 670 [flowLayout setMinimumInteritemSpacing:8]; | 582 [flowLayout setMinimumInteritemSpacing:8]; |
| 671 [flowLayout setMinimumLineSpacing:[self mostVisitedCellPadding]]; | 583 [flowLayout setMinimumLineSpacing:content_suggestions::spacingBetweenTiles()]; |
| 672 DCHECK(!_mostVisitedView); | 584 DCHECK(!_mostVisitedView); |
| 673 _mostVisitedView.reset([[UICollectionView alloc] | 585 _mostVisitedView.reset([[UICollectionView alloc] |
| 674 initWithFrame:mostVisitedFrame | 586 initWithFrame:mostVisitedFrame |
| 675 collectionViewLayout:flowLayout]); | 587 collectionViewLayout:flowLayout]); |
| 676 [_mostVisitedView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | 588 [_mostVisitedView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
| 677 UIViewAutoresizingFlexibleWidth]; | 589 UIViewAutoresizingFlexibleWidth]; |
| 678 [_mostVisitedView setDelegate:self]; | 590 [_mostVisitedView setDelegate:self]; |
| 679 [_mostVisitedView setDataSource:self]; | 591 [_mostVisitedView setDataSource:self]; |
| 680 [_mostVisitedView registerClass:[MostVisitedCell class] | 592 [_mostVisitedView registerClass:[MostVisitedCell class] |
| 681 forCellWithReuseIdentifier:@"classCell"]; | 593 forCellWithReuseIdentifier:@"classCell"]; |
| 682 [_mostVisitedView setBackgroundColor:[UIColor clearColor]]; | 594 [_mostVisitedView setBackgroundColor:[UIColor clearColor]]; |
| 683 [_mostVisitedView setBounces:YES]; | 595 [_mostVisitedView setBounces:YES]; |
| 684 [_mostVisitedView setShowsHorizontalScrollIndicator:NO]; | 596 [_mostVisitedView setShowsHorizontalScrollIndicator:NO]; |
| 685 [_mostVisitedView setShowsVerticalScrollIndicator:NO]; | 597 [_mostVisitedView setShowsVerticalScrollIndicator:NO]; |
| 686 [_mostVisitedView registerClass:[WhatsNewHeaderView class] | 598 [_mostVisitedView registerClass:[WhatsNewHeaderView class] |
| 687 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 599 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 688 withReuseIdentifier:@"whatsNew"]; | 600 withReuseIdentifier:@"whatsNew"]; |
| 689 [_mostVisitedView registerClass:[NewTabPageHeaderView class] | 601 [_mostVisitedView registerClass:[NewTabPageHeaderView class] |
| 690 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 602 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 691 withReuseIdentifier:@"header"]; | 603 withReuseIdentifier:@"header"]; |
| 692 [_mostVisitedView setAccessibilityIdentifier:@"Google Landing"]; | 604 [_mostVisitedView setAccessibilityIdentifier:@"Google Landing"]; |
| 693 | 605 |
| 694 [self.view addSubview:_mostVisitedView]; | 606 [self.view addSubview:_mostVisitedView]; |
| 695 } | 607 } |
| 696 | 608 |
| 697 - (void)updateSearchField { | 609 - (void)updateSearchField { |
| 698 NSArray* constraints = | 610 NSArray* constraints = |
| 699 @[ _hintLabelLeadingConstraint, _voiceTapTrailingConstraint ]; | 611 @[ _hintLabelLeadingConstraint, _voiceTapTrailingConstraint ]; |
| 700 [_headerView updateSearchField:_searchTapTarget | 612 [_headerView updateSearchField:_searchTapTarget |
| 701 withInitialFrame:[self searchFieldFrame] | 613 withInitialFrame:content_suggestions::searchFieldFrame( |
| 614 [self viewWidth], self.logoIsShowing) |
| 702 subviewConstraints:constraints | 615 subviewConstraints:constraints |
| 703 forOffset:[_mostVisitedView contentOffset].y]; | 616 forOffset:[_mostVisitedView contentOffset].y]; |
| 704 } | 617 } |
| 705 | 618 |
| 706 - (void)addOverscrollActions { | 619 - (void)addOverscrollActions { |
| 707 if (!IsIPadIdiom()) { | 620 if (!IsIPadIdiom()) { |
| 708 _overscrollActionsController.reset([[OverscrollActionsController alloc] | 621 _overscrollActionsController.reset([[OverscrollActionsController alloc] |
| 709 initWithScrollView:_mostVisitedView]); | 622 initWithScrollView:_mostVisitedView]); |
| 710 [_overscrollActionsController setStyle:OverscrollStyle::NTP_NON_INCOGNITO]; | 623 [_overscrollActionsController setStyle:OverscrollStyle::NTP_NON_INCOGNITO]; |
| 711 [_overscrollActionsController setDelegate:self]; | 624 [_overscrollActionsController setDelegate:self]; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 // -invalidateLayout is necessary because sometimes the flowLayout has the | 762 // -invalidateLayout is necessary because sometimes the flowLayout has the |
| 850 // wrong cached size and will throw an internal exception if the | 763 // wrong cached size and will throw an internal exception if the |
| 851 // -numberOfItems shrinks. -setNeedsLayout is needed in case | 764 // -numberOfItems shrinks. -setNeedsLayout is needed in case |
| 852 // -numberOfItems increases enough to add a new row and change the height | 765 // -numberOfItems increases enough to add a new row and change the height |
| 853 // of _mostVisitedView. | 766 // of _mostVisitedView. |
| 854 [_mostVisitedView reloadData]; | 767 [_mostVisitedView reloadData]; |
| 855 [[_mostVisitedView collectionViewLayout] invalidateLayout]; | 768 [[_mostVisitedView collectionViewLayout] invalidateLayout]; |
| 856 [self.view setNeedsLayout]; | 769 [self.view setNeedsLayout]; |
| 857 } | 770 } |
| 858 | 771 |
| 859 - (CGFloat)heightForSectionWithOmnibox { | |
| 860 CGFloat headerHeight = | |
| 861 CGRectGetMaxY([self searchFieldFrame]) + kNTPSearchFieldBottomPadding; | |
| 862 if (IsIPadIdiom()) { | |
| 863 if (self.logoIsShowing) { | |
| 864 if (!self.promoCanShow) { | |
| 865 UIInterfaceOrientation orient = | |
| 866 [[UIApplication sharedApplication] statusBarOrientation]; | |
| 867 const CGFloat kTopSpacingMaterialPortrait = 56; | |
| 868 const CGFloat kTopSpacingMaterialLandscape = 32; | |
| 869 headerHeight += UIInterfaceOrientationIsPortrait(orient) | |
| 870 ? kTopSpacingMaterialPortrait | |
| 871 : kTopSpacingMaterialLandscape; | |
| 872 } | |
| 873 } else { | |
| 874 headerHeight = kNonGoogleSearchHeaderHeightIPad; | |
| 875 } | |
| 876 } | |
| 877 return headerHeight; | |
| 878 } | |
| 879 | |
| 880 #pragma mark - ToolbarOwner | 772 #pragma mark - ToolbarOwner |
| 881 | 773 |
| 882 - (ToolbarController*)relinquishedToolbarController { | 774 - (ToolbarController*)relinquishedToolbarController { |
| 883 return [_headerView relinquishedToolbarController]; | 775 return [_headerView relinquishedToolbarController]; |
| 884 } | 776 } |
| 885 | 777 |
| 886 - (void)reparentToolbarController { | 778 - (void)reparentToolbarController { |
| 887 [_headerView reparentToolbarController]; | 779 [_headerView reparentToolbarController]; |
| 888 } | 780 } |
| 889 | 781 |
| 890 #pragma mark - UICollectionView Methods. | 782 #pragma mark - UICollectionView Methods. |
| 891 | 783 |
| 892 - (CGSize)collectionView:(UICollectionView*)collectionView | 784 - (CGSize)collectionView:(UICollectionView*)collectionView |
| 893 layout: | 785 layout: |
| 894 (UICollectionViewLayout*)collectionViewLayout | 786 (UICollectionViewLayout*)collectionViewLayout |
| 895 referenceSizeForHeaderInSection:(NSInteger)section { | 787 referenceSizeForHeaderInSection:(NSInteger)section { |
| 896 CGFloat headerHeight = 0; | 788 CGFloat headerHeight = 0; |
| 897 if (section == SectionWithOmnibox) { | 789 if (section == SectionWithOmnibox) { |
| 898 headerHeight = [self heightForSectionWithOmnibox]; | 790 headerHeight = content_suggestions::heightForLogoHeader( |
| 791 [self viewWidth], self.logoIsShowing, self.promoCanShow); |
| 899 ((UICollectionViewFlowLayout*)collectionViewLayout).headerReferenceSize = | 792 ((UICollectionViewFlowLayout*)collectionViewLayout).headerReferenceSize = |
| 900 CGSizeMake(0, headerHeight); | 793 CGSizeMake(0, headerHeight); |
| 901 } else if (section == SectionWithMostVisited) { | 794 } else if (section == SectionWithMostVisited) { |
| 902 if (self.promoCanShow) { | 795 if (self.promoCanShow) { |
| 903 headerHeight = [self promoHeaderHeight]; | 796 headerHeight = [self promoHeaderHeight]; |
| 904 } else { | 797 } else { |
| 905 headerHeight = kWhatsNewHeaderHiddenHeight; | 798 headerHeight = kWhatsNewHeaderHiddenHeight; |
| 906 } | 799 } |
| 907 } | 800 } |
| 908 return CGSizeMake(0, headerHeight); | 801 return CGSizeMake(0, headerHeight); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 return _headerView; | 871 return _headerView; |
| 979 } | 872 } |
| 980 | 873 |
| 981 if (indexPath.section == SectionWithMostVisited) { | 874 if (indexPath.section == SectionWithMostVisited) { |
| 982 if (!_promoHeaderView) { | 875 if (!_promoHeaderView) { |
| 983 _promoHeaderView.reset([[collectionView | 876 _promoHeaderView.reset([[collectionView |
| 984 dequeueReusableSupplementaryViewOfKind: | 877 dequeueReusableSupplementaryViewOfKind: |
| 985 UICollectionElementKindSectionHeader | 878 UICollectionElementKindSectionHeader |
| 986 withReuseIdentifier:@"whatsNew" | 879 withReuseIdentifier:@"whatsNew" |
| 987 forIndexPath:indexPath] retain]); | 880 forIndexPath:indexPath] retain]); |
| 988 [_promoHeaderView setSideMargin:[self leftMargin]]; | 881 [_promoHeaderView |
| 882 setSideMargin:content_suggestions::centeredTilesMarginForWidth( |
| 883 [self viewWidth])]; |
| 989 [_promoHeaderView setDelegate:self]; | 884 [_promoHeaderView setDelegate:self]; |
| 990 if (self.promoCanShow) { | 885 if (self.promoCanShow) { |
| 991 [_promoHeaderView setText:self.promoText]; | 886 [_promoHeaderView setText:self.promoText]; |
| 992 [_promoHeaderView setIcon:self.promoIcon]; | 887 [_promoHeaderView setIcon:self.promoIcon]; |
| 993 [self.dataSource promoViewed]; | 888 [self.dataSource promoViewed]; |
| 994 } | 889 } |
| 995 [_supplementaryViews addObject:_promoHeaderView]; | 890 [_supplementaryViews addObject:_promoHeaderView]; |
| 996 } | 891 } |
| 997 return _promoHeaderView; | 892 return _promoHeaderView; |
| 998 } | 893 } |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 - (void)setCanGoForward:(BOOL)canGoForward { | 1364 - (void)setCanGoForward:(BOOL)canGoForward { |
| 1470 _canGoForward = canGoForward; | 1365 _canGoForward = canGoForward; |
| 1471 [_headerView setCanGoForward:self.canGoForward]; | 1366 [_headerView setCanGoForward:self.canGoForward]; |
| 1472 } | 1367 } |
| 1473 | 1368 |
| 1474 - (void)setCanGoBack:(BOOL)canGoBack { | 1369 - (void)setCanGoBack:(BOOL)canGoBack { |
| 1475 _canGoBack = canGoBack; | 1370 _canGoBack = canGoBack; |
| 1476 [_headerView setCanGoBack:self.canGoBack]; | 1371 [_headerView setCanGoBack:self.canGoBack]; |
| 1477 } | 1372 } |
| 1478 @end | 1373 @end |
| OLD | NEW |