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

Side by Side Diff: ios/chrome/browser/ui/ntp/new_tab_page_view.mm

Issue 2785893003: [ios clean] Add placeholder for NTP bookmarks, chrome home and open tabs. (Closed)
Patch Set: Comment nit Created 3 years, 8 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/new_tab_page_view.h" 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/objc_property_releaser.h" 8 #include "base/mac/objc_property_releaser.h"
9 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h" 9 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h"
10 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" 10 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 selectedItemXOffset = CGRectGetMinX(item.view.frame); 73 selectedItemXOffset = CGRectGetMinX(item.view.frame);
74 index++; 74 index++;
75 } 75 }
76 76
77 // Ensure the selected NTP panel is lined up correctly when the frame 77 // Ensure the selected NTP panel is lined up correctly when the frame
78 // changes. 78 // changes.
79 CGPoint point = CGPointMake(selectedItemXOffset, 0); 79 CGPoint point = CGPointMake(selectedItemXOffset, 0);
80 [self.scrollView setContentOffset:point animated:NO]; 80 [self.scrollView setContentOffset:point animated:NO];
81 } 81 }
82 82
83 // Trigger a layout. The |-layoutIfNeeded| call is required because sometimes 83 // This should never be needed in autolayout.
84 // |-layoutSubviews| is not successfully triggered when |-setNeedsLayout| is 84 if (self.translatesAutoresizingMaskIntoConstraints) {
85 // called after frame changes due to autoresizing masks. 85 // Trigger a layout. The |-layoutIfNeeded| call is required because
86 [self setNeedsLayout]; 86 // sometimes |-layoutSubviews| is not successfully triggered when
87 [self layoutIfNeeded]; 87 // |-setNeedsLayout| is called after frame changes due to autoresizing
88 // masks.
89 [self setNeedsLayout];
90 [self layoutIfNeeded];
91 }
88 } 92 }
89 93
90 - (void)layoutSubviews { 94 - (void)layoutSubviews {
91 [super layoutSubviews]; 95 [super layoutSubviews];
92 96
93 self.tabBar.hidden = !self.tabBar.items.count; 97 self.tabBar.hidden = !self.tabBar.items.count;
94 if (self.tabBar.hidden) { 98 if (self.tabBar.hidden) {
95 self.scrollView.frame = self.bounds; 99 self.scrollView.frame = self.bounds;
96 } else { 100 } else {
97 CGSize barSize = [self.tabBar sizeThatFits:self.bounds.size]; 101 CGSize barSize = [self.tabBar sizeThatFits:self.bounds.size];
98 self.tabBar.frame = CGRectMake(CGRectGetMinX(self.bounds), 102 self.tabBar.frame = CGRectMake(CGRectGetMinX(self.bounds),
99 CGRectGetMaxY(self.bounds) - barSize.height, 103 CGRectGetMaxY(self.bounds) - barSize.height,
100 barSize.width, barSize.height); 104 barSize.width, barSize.height);
101 self.scrollView.frame = CGRectMake( 105 self.scrollView.frame = CGRectMake(
102 CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds), 106 CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds),
103 CGRectGetWidth(self.bounds), CGRectGetMinY(self.tabBar.frame)); 107 CGRectGetWidth(self.bounds), CGRectGetMinY(self.tabBar.frame));
104 } 108 }
109
110 // When using a new_tab_page_view in autolayout -setFrame is never called,
111 // which means all the logic to keep the selected scroll index set is never
112 // called. Rather than refactor away all of this to support ios/clean, just
113 // make sure -setFrame is called when loaded in autolayout.
114 if (!self.translatesAutoresizingMaskIntoConstraints) {
115 [self setFrame:self.frame];
116 }
105 } 117 }
106 118
107 - (void)updateScrollViewContentSize { 119 - (void)updateScrollViewContentSize {
108 CGSize contentSize = self.scrollView.bounds.size; 120 CGSize contentSize = self.scrollView.bounds.size;
109 // On iPhone, NTP doesn't scroll horizontally, as alternate panels are shown 121 // On iPhone, NTP doesn't scroll horizontally, as alternate panels are shown
110 // modally. On iPad, panels are laid out side by side in the scroll view. 122 // modally. On iPad, panels are laid out side by side in the scroll view.
111 if (IsIPadIdiom()) { 123 if (IsIPadIdiom()) {
112 contentSize.width *= self.tabBar.items.count; 124 contentSize.width *= self.tabBar.items.count;
113 } 125 }
114 self.scrollView.contentSize = contentSize; 126 self.scrollView.contentSize = contentSize;
115 } 127 }
116 128
117 - (CGRect)panelFrameForItemAtIndex:(NSUInteger)index { 129 - (CGRect)panelFrameForItemAtIndex:(NSUInteger)index {
118 CGRect contentBounds = CGRectMake(0, 0, self.scrollView.contentSize.width, 130 CGRect contentBounds = CGRectMake(0, 0, self.scrollView.contentSize.width,
119 self.scrollView.contentSize.height); 131 self.scrollView.contentSize.height);
120 LayoutRect layout = 132 LayoutRect layout =
121 LayoutRectForRectInBoundingRect(self.scrollView.bounds, contentBounds); 133 LayoutRectForRectInBoundingRect(self.scrollView.bounds, contentBounds);
122 layout.position.leading = layout.size.width * index; 134 layout.position.leading = layout.size.width * index;
123 return LayoutRectGetRect(layout); 135 return LayoutRectGetRect(layout);
124 } 136 }
125 137
126 @end 138 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698