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

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: Comments 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 if (self.translatesAutoresizingMaskIntoConstraints) {
marq (ping after 24h) 2017/04/05 12:22:47 It's not clear to my why this is conditional here.
justincohen 2017/04/05 19:28:23 Added a comment explaining why.
84 // |-layoutSubviews| is not successfully triggered when |-setNeedsLayout| is 84 // Trigger a layout. The |-layoutIfNeeded| call is required because
85 // called after frame changes due to autoresizing masks. 85 // sometimes
86 [self setNeedsLayout]; 86 // |-layoutSubviews| is not successfully triggered when |-setNeedsLayout| is
87 [self layoutIfNeeded]; 87 // called after frame changes due to autoresizing masks.
88 [self setNeedsLayout];
89 [self layoutIfNeeded];
90 }
88 } 91 }
89 92
90 - (void)layoutSubviews { 93 - (void)layoutSubviews {
91 [super layoutSubviews]; 94 [super layoutSubviews];
92 95
93 self.tabBar.hidden = !self.tabBar.items.count; 96 self.tabBar.hidden = !self.tabBar.items.count;
94 if (self.tabBar.hidden) { 97 if (self.tabBar.hidden) {
95 self.scrollView.frame = self.bounds; 98 self.scrollView.frame = self.bounds;
96 } else { 99 } else {
97 CGSize barSize = [self.tabBar sizeThatFits:self.bounds.size]; 100 CGSize barSize = [self.tabBar sizeThatFits:self.bounds.size];
98 self.tabBar.frame = CGRectMake(CGRectGetMinX(self.bounds), 101 self.tabBar.frame = CGRectMake(CGRectGetMinX(self.bounds),
99 CGRectGetMaxY(self.bounds) - barSize.height, 102 CGRectGetMaxY(self.bounds) - barSize.height,
100 barSize.width, barSize.height); 103 barSize.width, barSize.height);
101 self.scrollView.frame = CGRectMake( 104 self.scrollView.frame = CGRectMake(
102 CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds), 105 CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds),
103 CGRectGetWidth(self.bounds), CGRectGetMinY(self.tabBar.frame)); 106 CGRectGetWidth(self.bounds), CGRectGetMinY(self.tabBar.frame));
104 } 107 }
108
109 if (!self.translatesAutoresizingMaskIntoConstraints) {
110 [self setFrame:self.frame];
marq (ping after 24h) 2017/04/05 12:22:47 This feels deeply wrong. Why is it needed?
justincohen 2017/04/05 19:28:23 Added a comment explaining why.
111 }
105 } 112 }
106 113
107 - (void)updateScrollViewContentSize { 114 - (void)updateScrollViewContentSize {
108 CGSize contentSize = self.scrollView.bounds.size; 115 CGSize contentSize = self.scrollView.bounds.size;
109 // On iPhone, NTP doesn't scroll horizontally, as alternate panels are shown 116 // 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. 117 // modally. On iPad, panels are laid out side by side in the scroll view.
111 if (IsIPadIdiom()) { 118 if (IsIPadIdiom()) {
112 contentSize.width *= self.tabBar.items.count; 119 contentSize.width *= self.tabBar.items.count;
113 } 120 }
114 self.scrollView.contentSize = contentSize; 121 self.scrollView.contentSize = contentSize;
115 } 122 }
116 123
117 - (CGRect)panelFrameForItemAtIndex:(NSUInteger)index { 124 - (CGRect)panelFrameForItemAtIndex:(NSUInteger)index {
118 CGRect contentBounds = CGRectMake(0, 0, self.scrollView.contentSize.width, 125 CGRect contentBounds = CGRectMake(0, 0, self.scrollView.contentSize.width,
119 self.scrollView.contentSize.height); 126 self.scrollView.contentSize.height);
120 LayoutRect layout = 127 LayoutRect layout =
121 LayoutRectForRectInBoundingRect(self.scrollView.bounds, contentBounds); 128 LayoutRectForRectInBoundingRect(self.scrollView.bounds, contentBounds);
122 layout.position.leading = layout.size.width * index; 129 layout.position.leading = layout.size.width * index;
123 return LayoutRectGetRect(layout); 130 return LayoutRectGetRect(layout);
124 } 131 }
125 132
126 @end 133 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698