Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
| 87 [self layoutIfNeeded]; | 87 // |-layoutSubviews| is not successfully triggered when |-setNeedsLayout| is |
|
lpromero
2017/04/06 13:01:04
Reflow the comment.
justincohen
2017/04/06 18:25:09
Done.
| |
| 88 // called after frame changes due to autoresizing 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 |
| OLD | NEW |