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

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

Issue 2833513002: Replace TabModel with WebStateList in GoogleLandingController. (Closed)
Patch Set: Fix gn 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_header_view.h" 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #import "ios/chrome/browser/tabs/tab_model.h" 9 #import "ios/chrome/browser/tabs/tab_model.h"
10 #import "ios/chrome/browser/tabs/tab_model_observer.h" 10 #import "ios/chrome/browser/tabs/tab_model_observer.h"
11 #import "ios/chrome/browser/ui/image_util.h" 11 #import "ios/chrome/browser/ui/image_util.h"
12 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" 12 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h"
13 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h" 13 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h"
14 #import "ios/chrome/browser/ui/ntp/new_tab_page_toolbar_controller.h" 14 #import "ios/chrome/browser/ui/ntp/new_tab_page_toolbar_controller.h"
15 #import "ios/chrome/browser/ui/uikit_ui_util.h" 15 #import "ios/chrome/browser/ui/uikit_ui_util.h"
16 #import "ios/chrome/common/material_timing.h" 16 #import "ios/chrome/common/material_timing.h"
17 #include "ios/chrome/grit/ios_theme_resources.h" 17 #include "ios/chrome/grit/ios_theme_resources.h"
18 #import "ui/gfx/ios/uikit_util.h" 18 #import "ui/gfx/ios/uikit_util.h"
19 19
20 namespace { 20 namespace {
21 21
22 const CGFloat kOmniboxImageBottomInset = 1; 22 const CGFloat kOmniboxImageBottomInset = 1;
23 const CGFloat kHintLabelSidePadding = 12; 23 const CGFloat kHintLabelSidePadding = 12;
24 const CGFloat kMaxConstraintConstantDiff = 5; 24 const CGFloat kMaxConstraintConstantDiff = 5;
25 25
26 } // namespace 26 } // namespace
27 27
28 @interface NewTabPageHeaderView ()<TabModelObserver> { 28 @interface NewTabPageHeaderView () {
29 base::scoped_nsobject<NewTabPageToolbarController> _toolbarController; 29 base::scoped_nsobject<NewTabPageToolbarController> _toolbarController;
30 base::scoped_nsobject<TabModel> _tabModel;
31 base::scoped_nsobject<UIImageView> _searchBoxBorder; 30 base::scoped_nsobject<UIImageView> _searchBoxBorder;
32 base::scoped_nsobject<UIImageView> _shadow; 31 base::scoped_nsobject<UIImageView> _shadow;
33 } 32 }
34 33
35 @end 34 @end
36 35
37 @implementation NewTabPageHeaderView 36 @implementation NewTabPageHeaderView
38 37
39 - (instancetype)initWithFrame:(CGRect)frame { 38 - (instancetype)initWithFrame:(CGRect)frame {
40 self = [super initWithFrame:frame]; 39 self = [super initWithFrame:frame];
41 if (self) { 40 if (self) {
42 self.clipsToBounds = YES; 41 self.clipsToBounds = YES;
43 } 42 }
44 return self; 43 return self;
45 } 44 }
46 45
47 - (void)dealloc { 46 - (void)dealloc {
48 [_tabModel removeObserver:self];
49 [super dealloc]; 47 [super dealloc];
50 } 48 }
51 49
52 - (UIView*)toolBarView { 50 - (UIView*)toolBarView {
53 return [_toolbarController view]; 51 return [_toolbarController view];
54 } 52 }
55 53
56 - (ToolbarController*)relinquishedToolbarController { 54 - (ToolbarController*)relinquishedToolbarController {
57 ToolbarController* relinquishedToolbarController = nil; 55 ToolbarController* relinquishedToolbarController = nil;
58 if ([[_toolbarController view] isDescendantOfView:self]) { 56 if ([[_toolbarController view] isDescendantOfView:self]) {
59 // Only relinquish the toolbar controller if it's in the hierarchy. 57 // Only relinquish the toolbar controller if it's in the hierarchy.
60 relinquishedToolbarController = _toolbarController.get(); 58 relinquishedToolbarController = _toolbarController.get();
61 } 59 }
62 return relinquishedToolbarController; 60 return relinquishedToolbarController;
63 } 61 }
64 62
65 - (void)reparentToolbarController { 63 - (void)reparentToolbarController {
66 [self addSubview:[_toolbarController view]]; 64 [self addSubview:[_toolbarController view]];
67 } 65 }
68 66
69 - (void)addToolbarWithDataSource:(id<GoogleLandingDataSource>)dataSource { 67 - (void)addToolbarWithDataSource:(id<GoogleLandingDataSource>)dataSource {
70 DCHECK(!_toolbarController); 68 DCHECK(!_toolbarController);
71 DCHECK(dataSource); 69 DCHECK(dataSource);
72 70
73 _toolbarController.reset([[NewTabPageToolbarController alloc] 71 _toolbarController.reset([[NewTabPageToolbarController alloc]
74 initWithToolbarDelegate:[dataSource toolbarDelegate] 72 initWithToolbarDelegate:[dataSource toolbarDelegate]
75 focuser:dataSource]); 73 focuser:dataSource]);
76 _toolbarController.get().readingListModel = [dataSource readingListModel]; 74 _toolbarController.get().readingListModel = [dataSource readingListModel];
77 [_tabModel removeObserver:self];
78 _tabModel.reset([[dataSource tabModel] retain]);
79 [self addTabModelObserver];
80 75
81 UIView* toolbarView = [_toolbarController view]; 76 UIView* toolbarView = [_toolbarController view];
82 CGRect toolbarFrame = self.bounds; 77 CGRect toolbarFrame = self.bounds;
83 toolbarFrame.size.height = ntp_header::kToolbarHeight; 78 toolbarFrame.size.height = ntp_header::kToolbarHeight;
84 toolbarView.frame = toolbarFrame; 79 toolbarView.frame = toolbarFrame;
85 [toolbarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 80 [toolbarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
86 [self hideToolbarViewsForNewTabPage]; 81 [self hideToolbarViewsForNewTabPage];
87 82
88 [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 83 [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
89 [self addSubview:[_toolbarController view]]; 84 [self addSubview:[_toolbarController view]];
90 } 85 }
91 86
92 - (void)hideToolbarViewsForNewTabPage { 87 - (void)hideToolbarViewsForNewTabPage {
93 [_toolbarController hideViewsForNewTabPage:YES]; 88 [_toolbarController hideViewsForNewTabPage:YES];
94 }; 89 };
95 90
96 - (void)addTabModelObserver { 91 - (void)setToolbarTabCount:(int)tabCount {
97 [_tabModel addObserver:self]; 92 [_toolbarController setTabCount:tabCount];
98 [_toolbarController setTabCount:[_tabModel count]];
99 } 93 }
100 94
101 - (void)addViewsToSearchField:(UIView*)searchField { 95 - (void)addViewsToSearchField:(UIView*)searchField {
102 [searchField setBackgroundColor:[UIColor whiteColor]]; 96 [searchField setBackgroundColor:[UIColor whiteColor]];
103 UIImage* searchBorderImage = 97 UIImage* searchBorderImage =
104 StretchableImageNamed(@"ntp_google_search_box", 12, 12); 98 StretchableImageNamed(@"ntp_google_search_box", 12, 12);
105 _searchBoxBorder.reset([[UIImageView alloc] initWithImage:searchBorderImage]); 99 _searchBoxBorder.reset([[UIImageView alloc] initWithImage:searchBorderImage]);
106 [_searchBoxBorder setFrame:[searchField bounds]]; 100 [_searchBoxBorder setFrame:[searchField bounds]];
107 [_searchBoxBorder setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 101 [_searchBoxBorder setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
108 UIViewAutoresizingFlexibleHeight]; 102 UIViewAutoresizingFlexibleHeight];
109 [searchField insertSubview:_searchBoxBorder atIndex:0]; 103 [searchField insertSubview:_searchBoxBorder atIndex:0];
110 104
111 UIImage* fullBleedShadow = NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED); 105 UIImage* fullBleedShadow = NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED);
112 _shadow.reset([[UIImageView alloc] initWithImage:fullBleedShadow]); 106 _shadow.reset([[UIImageView alloc] initWithImage:fullBleedShadow]);
113 CGRect shadowFrame = [searchField bounds]; 107 CGRect shadowFrame = [searchField bounds];
114 shadowFrame.origin.y = 108 shadowFrame.origin.y =
115 searchField.bounds.size.height - kOmniboxImageBottomInset; 109 searchField.bounds.size.height - kOmniboxImageBottomInset;
116 shadowFrame.size.height = fullBleedShadow.size.height; 110 shadowFrame.size.height = fullBleedShadow.size.height;
117 [_shadow setFrame:shadowFrame]; 111 [_shadow setFrame:shadowFrame];
118 [_shadow setUserInteractionEnabled:NO]; 112 [_shadow setUserInteractionEnabled:NO];
119 [_shadow setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 113 [_shadow setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
120 UIViewAutoresizingFlexibleTopMargin]; 114 UIViewAutoresizingFlexibleTopMargin];
121 [searchField addSubview:_shadow]; 115 [searchField addSubview:_shadow];
122 [_shadow setAlpha:0]; 116 [_shadow setAlpha:0];
123 } 117 }
124 118
125 - (void)tabModelDidChangeTabCount:(TabModel*)model {
126 DCHECK(model == _tabModel);
127 [_toolbarController setTabCount:[_tabModel count]];
128 }
129
130 - (void)updateSearchField:(UIView*)searchField 119 - (void)updateSearchField:(UIView*)searchField
131 withInitialFrame:(CGRect)initialFrame 120 withInitialFrame:(CGRect)initialFrame
132 subviewConstraints:(NSArray*)constraints 121 subviewConstraints:(NSArray*)constraints
133 forOffset:(CGFloat)offset { 122 forOffset:(CGFloat)offset {
134 // The scroll offset at which point |searchField|'s frame should stop growing. 123 // The scroll offset at which point |searchField|'s frame should stop growing.
135 CGFloat maxScaleOffset = 124 CGFloat maxScaleOffset =
136 self.frame.size.height - ntp_header::kMinHeaderHeight; 125 self.frame.size.height - ntp_header::kMinHeaderHeight;
137 // The scroll offset at which point |searchField|'s frame should start 126 // The scroll offset at which point |searchField|'s frame should start
138 // growing. 127 // growing.
139 CGFloat startScaleOffset = maxScaleOffset - ntp_header::kAnimationDistance; 128 CGFloat startScaleOffset = maxScaleOffset - ntp_header::kAnimationDistance;
(...skipping 29 matching lines...) Expand all
169 } 158 }
170 159
171 - (void)fadeOutShadow { 160 - (void)fadeOutShadow {
172 [UIView animateWithDuration:ios::material::kDuration1 161 [UIView animateWithDuration:ios::material::kDuration1
173 animations:^{ 162 animations:^{
174 [_shadow setAlpha:0]; 163 [_shadow setAlpha:0];
175 }]; 164 }];
176 } 165 }
177 166
178 @end 167 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/ntp/new_tab_page_header_view.h ('k') | ios/clean/chrome/browser/ui/ntp/ntp_home_coordinator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698