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

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

Issue 2891563003: [ObjC ARC] Converts ios/chrome/browser/ui/ntp:ntp_header to ARC. (Closed)
Patch Set: comments Created 3 years, 6 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"
9 #import "ios/chrome/browser/tabs/tab_model.h" 8 #import "ios/chrome/browser/tabs/tab_model.h"
10 #import "ios/chrome/browser/tabs/tab_model_observer.h" 9 #import "ios/chrome/browser/tabs/tab_model_observer.h"
11 #import "ios/chrome/browser/ui/image_util.h" 10 #import "ios/chrome/browser/ui/image_util.h"
12 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" 11 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h"
13 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h" 12 #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" 13 #import "ios/chrome/browser/ui/ntp/new_tab_page_toolbar_controller.h"
15 #import "ios/chrome/browser/ui/uikit_ui_util.h" 14 #import "ios/chrome/browser/ui/uikit_ui_util.h"
16 #import "ios/chrome/common/material_timing.h" 15 #import "ios/chrome/common/material_timing.h"
17 #include "ios/chrome/grit/ios_theme_resources.h" 16 #include "ios/chrome/grit/ios_theme_resources.h"
18 #import "ui/gfx/ios/uikit_util.h" 17 #import "ui/gfx/ios/uikit_util.h"
19 18
19 #if !defined(__has_feature) || !__has_feature(objc_arc)
20 #error "This file requires ARC support."
21 #endif
22
20 namespace { 23 namespace {
21 24
22 const CGFloat kOmniboxImageBottomInset = 1; 25 const CGFloat kOmniboxImageBottomInset = 1;
23 const CGFloat kHintLabelSidePadding = 12; 26 const CGFloat kHintLabelSidePadding = 12;
24 const CGFloat kMaxConstraintConstantDiff = 5; 27 const CGFloat kMaxConstraintConstantDiff = 5;
25 28
26 } // namespace 29 } // namespace
27 30
28 @interface NewTabPageHeaderView () { 31 @interface NewTabPageHeaderView () {
29 base::scoped_nsobject<NewTabPageToolbarController> _toolbarController; 32 NewTabPageToolbarController* _toolbarController;
30 base::scoped_nsobject<UIImageView> _searchBoxBorder; 33 UIImageView* _searchBoxBorder;
31 base::scoped_nsobject<UIImageView> _shadow; 34 UIImageView* _shadow;
32 } 35 }
33 36
34 @end 37 @end
35 38
36 @implementation NewTabPageHeaderView 39 @implementation NewTabPageHeaderView
37 40
38 - (instancetype)initWithFrame:(CGRect)frame { 41 - (instancetype)initWithFrame:(CGRect)frame {
39 self = [super initWithFrame:frame]; 42 self = [super initWithFrame:frame];
40 if (self) { 43 if (self) {
41 self.clipsToBounds = YES; 44 self.clipsToBounds = YES;
42 } 45 }
43 return self; 46 return self;
44 } 47 }
45 48
46 - (void)dealloc {
47 [super dealloc];
48 }
49 49
50 - (UIView*)toolBarView { 50 - (UIView*)toolBarView {
51 return [_toolbarController view]; 51 return [_toolbarController view];
52 } 52 }
53 53
54 - (ToolbarController*)relinquishedToolbarController { 54 - (ToolbarController*)relinquishedToolbarController {
55 ToolbarController* relinquishedToolbarController = nil; 55 ToolbarController* relinquishedToolbarController = nil;
56 if ([[_toolbarController view] isDescendantOfView:self]) { 56 if ([[_toolbarController view] isDescendantOfView:self]) {
57 // Only relinquish the toolbar controller if it's in the hierarchy. 57 // Only relinquish the toolbar controller if it's in the hierarchy.
58 relinquishedToolbarController = _toolbarController.get(); 58 relinquishedToolbarController = _toolbarController;
59 } 59 }
60 return relinquishedToolbarController; 60 return relinquishedToolbarController;
61 } 61 }
62 62
63 - (void)reparentToolbarController { 63 - (void)reparentToolbarController {
64 [self addSubview:[_toolbarController view]]; 64 [self addSubview:[_toolbarController view]];
65 } 65 }
66 66
67 - (void)addToolbarWithDataSource:(id<GoogleLandingDataSource>)dataSource 67 - (void)addToolbarWithDataSource:(id<GoogleLandingDataSource>)dataSource
68 dispatcher:(id)dispatcher { 68 dispatcher:(id)dispatcher {
69 DCHECK(!_toolbarController); 69 DCHECK(!_toolbarController);
70 DCHECK(dataSource); 70 DCHECK(dataSource);
71 71
72 _toolbarController.reset([[NewTabPageToolbarController alloc] init]); 72 _toolbarController = [[NewTabPageToolbarController alloc] init];
73 [_toolbarController setDispatcher:dispatcher]; 73 [_toolbarController setDispatcher:dispatcher];
74 _toolbarController.get().readingListModel = [dataSource readingListModel]; 74 _toolbarController.readingListModel = [dataSource readingListModel];
75 75
76 UIView* toolbarView = [_toolbarController view]; 76 UIView* toolbarView = [_toolbarController view];
77 CGRect toolbarFrame = self.bounds; 77 CGRect toolbarFrame = self.bounds;
78 toolbarFrame.size.height = ntp_header::kToolbarHeight; 78 toolbarFrame.size.height = ntp_header::kToolbarHeight;
79 toolbarView.frame = toolbarFrame; 79 toolbarView.frame = toolbarFrame;
80 [toolbarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 80 [toolbarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
81 81
82 [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 82 [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
83 [self addSubview:[_toolbarController view]]; 83 [self addSubview:[_toolbarController view]];
84 } 84 }
(...skipping 13 matching lines...) Expand all
98 }; 98 };
99 99
100 - (void)setToolbarTabCount:(int)tabCount { 100 - (void)setToolbarTabCount:(int)tabCount {
101 [_toolbarController setTabCount:tabCount]; 101 [_toolbarController setTabCount:tabCount];
102 } 102 }
103 103
104 - (void)addViewsToSearchField:(UIView*)searchField { 104 - (void)addViewsToSearchField:(UIView*)searchField {
105 [searchField setBackgroundColor:[UIColor whiteColor]]; 105 [searchField setBackgroundColor:[UIColor whiteColor]];
106 UIImage* searchBorderImage = 106 UIImage* searchBorderImage =
107 StretchableImageNamed(@"ntp_google_search_box", 12, 12); 107 StretchableImageNamed(@"ntp_google_search_box", 12, 12);
108 _searchBoxBorder.reset([[UIImageView alloc] initWithImage:searchBorderImage]); 108 _searchBoxBorder = [[UIImageView alloc] initWithImage:searchBorderImage];
109 [_searchBoxBorder setFrame:[searchField bounds]]; 109 [_searchBoxBorder setFrame:[searchField bounds]];
110 [_searchBoxBorder setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 110 [_searchBoxBorder setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
111 UIViewAutoresizingFlexibleHeight]; 111 UIViewAutoresizingFlexibleHeight];
112 [searchField insertSubview:_searchBoxBorder atIndex:0]; 112 [searchField insertSubview:_searchBoxBorder atIndex:0];
113 113
114 UIImage* fullBleedShadow = NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED); 114 UIImage* fullBleedShadow = NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED);
115 _shadow.reset([[UIImageView alloc] initWithImage:fullBleedShadow]); 115 _shadow = [[UIImageView alloc] initWithImage:fullBleedShadow];
116 CGRect shadowFrame = [searchField bounds]; 116 CGRect shadowFrame = [searchField bounds];
117 shadowFrame.origin.y = 117 shadowFrame.origin.y =
118 searchField.bounds.size.height - kOmniboxImageBottomInset; 118 searchField.bounds.size.height - kOmniboxImageBottomInset;
119 shadowFrame.size.height = fullBleedShadow.size.height; 119 shadowFrame.size.height = fullBleedShadow.size.height;
120 [_shadow setFrame:shadowFrame]; 120 [_shadow setFrame:shadowFrame];
121 [_shadow setUserInteractionEnabled:NO]; 121 [_shadow setUserInteractionEnabled:NO];
122 [_shadow setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 122 [_shadow setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
123 UIViewAutoresizingFlexibleTopMargin]; 123 UIViewAutoresizingFlexibleTopMargin];
124 [searchField addSubview:_shadow]; 124 [searchField addSubview:_shadow];
125 [_shadow setAlpha:0]; 125 [_shadow setAlpha:0];
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 168
169 - (void)fadeOutShadow { 169 - (void)fadeOutShadow {
170 [UIView animateWithDuration:ios::material::kDuration1 170 [UIView animateWithDuration:ios::material::kDuration1
171 animations:^{ 171 animations:^{
172 [_shadow setAlpha:0]; 172 [_shadow setAlpha:0];
173 }]; 173 }];
174 } 174 }
175 175
176 @end 176 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698