Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: ios/chrome/browser/ui/ntp/most_visited_layout.mm

Issue 2590473002: Upstream Chrome on iOS source code [5/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/ntp/most_visited_layout.h ('k') | ios/chrome/browser/ui/ntp/new_tab_page_bar.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/ntp/most_visited_layout.mm
diff --git a/ios/chrome/browser/ui/ntp/most_visited_layout.mm b/ios/chrome/browser/ui/ntp/most_visited_layout.mm
new file mode 100644
index 0000000000000000000000000000000000000000..bd0cdfcf3f3715f35c9a1b0bb6da14d578a79208
--- /dev/null
+++ b/ios/chrome/browser/ui/ntp/most_visited_layout.mm
@@ -0,0 +1,103 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/ntp/most_visited_layout.h"
+
+#import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h"
+#include "ios/chrome/browser/ui/ui_util.h"
+
+@implementation MostVisitedLayout
+
+- (NSArray*)layoutAttributesForElementsInRect:(CGRect)rect {
+ NSMutableArray* layoutAttributes = [
+ [[super layoutAttributesForElementsInRect:rect] mutableCopy] autorelease];
+ UICollectionViewLayoutAttributes* fixedHeaderAttributes = nil;
+ NSIndexPath* fixedHeaderIndexPath =
+ [NSIndexPath indexPathForItem:0 inSection:0];
+
+ for (UICollectionViewLayoutAttributes* attributes in layoutAttributes) {
+ if ([attributes.representedElementKind
+ isEqualToString:UICollectionElementKindSectionHeader] &&
+ attributes.indexPath.section == fixedHeaderIndexPath.section) {
+ fixedHeaderAttributes = [self
+ layoutAttributesForSupplementaryViewOfKind:
+ UICollectionElementKindSectionHeader
+ atIndexPath:fixedHeaderIndexPath];
+ attributes.zIndex = fixedHeaderAttributes.zIndex;
+ attributes.frame = fixedHeaderAttributes.frame;
+ }
+ }
+
+ // The fixed header's attributes are not updated if the header's default frame
+ // is far enough away from |rect|, which can occur when the NTP is scrolled
+ // up.
+ if (!fixedHeaderAttributes && !IsIPadIdiom()) {
+ UICollectionViewLayoutAttributes* fixedHeaderAttributes =
+ [self layoutAttributesForSupplementaryViewOfKind:
+ UICollectionElementKindSectionHeader
+ atIndexPath:fixedHeaderIndexPath];
+ [layoutAttributes addObject:fixedHeaderAttributes];
+ }
+
+ return layoutAttributes;
+}
+
+- (UICollectionViewLayoutAttributes*)
+layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
+ atIndexPath:(NSIndexPath*)indexPath {
+ UICollectionViewLayoutAttributes* attributes =
+ [super layoutAttributesForSupplementaryViewOfKind:kind
+ atIndexPath:indexPath];
+ if ([kind isEqualToString:UICollectionElementKindSectionHeader] &&
+ indexPath.section == 0) {
+ UICollectionView* collectionView = self.collectionView;
+ CGPoint contentOffset = collectionView.contentOffset;
+ CGFloat headerHeight = CGRectGetHeight(attributes.frame);
+ CGPoint origin = attributes.frame.origin;
+
+ // Keep the header in front of all other views.
+ attributes.zIndex = 1000;
+
+ // Prevent the fake omnibox from scrolling up off of the screen.
+ CGFloat minY = headerHeight - ntp_header::kMinHeaderHeight;
+ if (contentOffset.y > minY)
+ origin.y = contentOffset.y - minY;
+ attributes.frame = {origin, attributes.frame.size};
+ }
+ return attributes;
+}
+
+- (UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:
+ (NSIndexPath*)indexPath {
+ UICollectionViewLayoutAttributes* currentItemAttributes =
+ [super layoutAttributesForItemAtIndexPath:indexPath];
+
+ return currentItemAttributes;
+}
+
+- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBound {
+ return YES;
+}
+
+- (CGSize)collectionViewContentSize {
+ CGFloat collectionViewHeight = self.collectionView.bounds.size.height;
+ CGFloat headerHeight = [self headerReferenceSize].height;
+
+ // The minimum height for the collection view content should be the height of
+ // the header plus the height of the collection view minus the height of the
+ // NTP bottom bar. This allows the Most Visited cells to be scrolled up to the
+ // top of the screen.
+ CGFloat minimumHeight = collectionViewHeight + headerHeight -
+ ntp_header::kScrolledToTopOmniboxBottomMargin;
+ if (!IsIPadIdiom())
+ minimumHeight -= ntp_header::kToolbarHeight;
+
+ CGSize contentSize = [super collectionViewContentSize];
+ if (contentSize.height < minimumHeight) {
+ contentSize.height = minimumHeight;
+ }
+ return contentSize;
+}
+
+@end
« no previous file with comments | « ios/chrome/browser/ui/ntp/most_visited_layout.h ('k') | ios/chrome/browser/ui/ntp/new_tab_page_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698