OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/tab_switcher/tab_switcher_view.h" | 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #include "base/mac/scoped_nsobject.h" | |
10 #include "base/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
11 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 10 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
12 #include "ios/chrome/browser/ui/rtl_geometry.h" | 11 #include "ios/chrome/browser/ui/rtl_geometry.h" |
13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_header_view.h" | 12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_header_view.h" |
14 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_controller.h" | 13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_controller.h" |
15 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" | 14 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" |
16 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h" | 15 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h" |
17 #include "ios/chrome/grit/ios_strings.h" | 16 #include "ios/chrome/grit/ios_strings.h" |
18 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 17 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
19 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 18 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
21 | 20 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." |
| 23 #endif |
| 24 |
22 namespace { | 25 namespace { |
23 const CGFloat kHeaderHeight = 95; | 26 const CGFloat kHeaderHeight = 95; |
24 const CGFloat kNewTabButtonMarginFromEdges = 48; | 27 const CGFloat kNewTabButtonMarginFromEdges = 48; |
25 const CGFloat kNewTabButtonWidth = 48; | 28 const CGFloat kNewTabButtonWidth = 48; |
26 } | 29 } |
27 | 30 |
28 @interface TabSwitcherView ()<UIScrollViewDelegate> { | 31 @interface TabSwitcherView ()<UIScrollViewDelegate> { |
29 base::scoped_nsobject<TabSwitcherHeaderView> _headerView; | 32 TabSwitcherHeaderView* _headerView; |
30 base::scoped_nsobject<UIScrollView> _scrollView; | 33 UIScrollView* _scrollView; |
31 base::scoped_nsobject<MDCButton> _openNewTabButton; | 34 MDCButton* _openNewTabButton; |
32 base::scoped_nsobject<NSMutableArray> _panels; | 35 NSMutableArray* _panels; |
33 ios_internal::NewTabButtonStyle _openNewTabButtonStyle; | 36 ios_internal::NewTabButtonStyle _openNewTabButtonStyle; |
34 NSInteger _previousPanelIndex; | 37 NSInteger _previousPanelIndex; |
35 } | 38 } |
36 | 39 |
37 // Returns the header view frame. | 40 // Returns the header view frame. |
38 - (CGRect)headerViewFrame; | 41 - (CGRect)headerViewFrame; |
39 // Returns the scrollview frame. | 42 // Returns the scrollview frame. |
40 - (CGRect)scrollViewFrame; | 43 - (CGRect)scrollViewFrame; |
41 // Returns the new tab button frame. | 44 // Returns the new tab button frame. |
42 - (CGRect)openNewTabButtonFrame; | 45 - (CGRect)openNewTabButtonFrame; |
(...skipping 11 matching lines...) Expand all Loading... |
54 | 57 |
55 @implementation TabSwitcherView | 58 @implementation TabSwitcherView |
56 | 59 |
57 @synthesize delegate = delegate_; | 60 @synthesize delegate = delegate_; |
58 | 61 |
59 - (instancetype)initWithFrame:(CGRect)frame { | 62 - (instancetype)initWithFrame:(CGRect)frame { |
60 self = [super initWithFrame:frame]; | 63 self = [super initWithFrame:frame]; |
61 if (self) { | 64 if (self) { |
62 _openNewTabButtonStyle = ios_internal::NewTabButtonStyle::UNINITIALIZED; | 65 _openNewTabButtonStyle = ios_internal::NewTabButtonStyle::UNINITIALIZED; |
63 [self loadSubviews]; | 66 [self loadSubviews]; |
64 _panels.reset([[NSMutableArray alloc] init]); | 67 _panels = [[NSMutableArray alloc] init]; |
65 _previousPanelIndex = -1; | 68 _previousPanelIndex = -1; |
66 } | 69 } |
67 return self; | 70 return self; |
68 } | 71 } |
69 | 72 |
70 - (TabSwitcherHeaderView*)headerView { | 73 - (TabSwitcherHeaderView*)headerView { |
71 return _headerView; | 74 return _headerView; |
72 } | 75 } |
73 | 76 |
74 - (UIScrollView*)scrollView { | 77 - (UIScrollView*)scrollView { |
(...skipping 22 matching lines...) Expand all Loading... |
97 [_scrollView addSubview:view]; | 100 [_scrollView addSubview:view]; |
98 [_panels insertObject:view atIndex:index]; | 101 [_panels insertObject:view atIndex:index]; |
99 [self updateScrollViewContent]; | 102 [self updateScrollViewContent]; |
100 } | 103 } |
101 | 104 |
102 - (void)removePanelViewAtIndex:(NSUInteger)index { | 105 - (void)removePanelViewAtIndex:(NSUInteger)index { |
103 [self removePanelViewAtIndex:index updateScrollView:YES]; | 106 [self removePanelViewAtIndex:index updateScrollView:YES]; |
104 } | 107 } |
105 | 108 |
106 - (void)removePanelViewAtIndex:(NSUInteger)index updateScrollView:(BOOL)update { | 109 - (void)removePanelViewAtIndex:(NSUInteger)index updateScrollView:(BOOL)update { |
107 DCHECK_EQ([[_panels objectAtIndex:index] superview], _scrollView.get()); | 110 DCHECK_EQ([[_panels objectAtIndex:index] superview], _scrollView); |
108 [[_panels objectAtIndex:index] removeFromSuperview]; | 111 [[_panels objectAtIndex:index] removeFromSuperview]; |
109 [_panels removeObjectAtIndex:index]; | 112 [_panels removeObjectAtIndex:index]; |
110 if (update) | 113 if (update) |
111 [self updateScrollViewContent]; | 114 [self updateScrollViewContent]; |
112 } | 115 } |
113 | 116 |
114 - (NSInteger)currentPanelIndex { | 117 - (NSInteger)currentPanelIndex { |
115 return [self currentPageIndex]; | 118 return [self currentPageIndex]; |
116 } | 119 } |
117 | 120 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 currentContentSize.width = [_panels count] * panelSize.width; | 167 currentContentSize.width = [_panels count] * panelSize.width; |
165 [_scrollView setContentSize:currentContentSize]; | 168 [_scrollView setContentSize:currentContentSize]; |
166 for (NSUInteger i = 0; i < [_panels count]; i++) { | 169 for (NSUInteger i = 0; i < [_panels count]; i++) { |
167 id panelView = [_panels objectAtIndex:i]; | 170 id panelView = [_panels objectAtIndex:i]; |
168 [panelView setFrame:[self frameForPanelAtIndex:i]]; | 171 [panelView setFrame:[self frameForPanelAtIndex:i]]; |
169 } | 172 } |
170 } | 173 } |
171 | 174 |
172 - (void)loadSubviews { | 175 - (void)loadSubviews { |
173 // Creates and add the header view showing the list of panels. | 176 // Creates and add the header view showing the list of panels. |
174 base::scoped_nsobject<TabSwitcherHeaderView> headerView( | 177 TabSwitcherHeaderView* headerView = |
175 [[TabSwitcherHeaderView alloc] initWithFrame:[self headerViewFrame]]); | 178 [[TabSwitcherHeaderView alloc] initWithFrame:[self headerViewFrame]]; |
176 [self addSubview:headerView]; | 179 [self addSubview:headerView]; |
177 _headerView = headerView; | 180 _headerView = headerView; |
178 | 181 |
179 // Creates and add the scrollview containing the panels. | 182 // Creates and add the scrollview containing the panels. |
180 base::scoped_nsobject<UIScrollView> scrollView( | 183 UIScrollView* scrollView = |
181 [[UIScrollView alloc] initWithFrame:[self scrollViewFrame]]); | 184 [[UIScrollView alloc] initWithFrame:[self scrollViewFrame]]; |
182 [scrollView setBackgroundColor:[[MDCPalette greyPalette] tint900]]; | 185 [scrollView setBackgroundColor:[[MDCPalette greyPalette] tint900]]; |
183 [scrollView setAlwaysBounceHorizontal:YES]; | 186 [scrollView setAlwaysBounceHorizontal:YES]; |
184 [scrollView setDelegate:self]; | 187 [scrollView setDelegate:self]; |
185 [scrollView setPagingEnabled:YES]; | 188 [scrollView setPagingEnabled:YES]; |
186 [scrollView setDelegate:self]; | 189 [scrollView setDelegate:self]; |
187 if (UseRTLLayout()) | 190 if (UseRTLLayout()) |
188 [scrollView setTransform:CGAffineTransformMakeScale(-1, 1)]; | 191 [scrollView setTransform:CGAffineTransformMakeScale(-1, 1)]; |
189 [self addSubview:scrollView]; | 192 [self addSubview:scrollView]; |
190 _scrollView = scrollView; | 193 _scrollView = scrollView; |
191 | 194 |
192 // Creates and add the floating new tab button. | 195 // Creates and add the floating new tab button. |
193 _openNewTabButton.reset([[MDCFloatingButton alloc] init]); | 196 _openNewTabButton = [[MDCFloatingButton alloc] init]; |
194 UIImage* openNewTabButtonImage = | 197 UIImage* openNewTabButtonImage = |
195 [[UIImage imageNamed:@"tabswitcher_new_tab_fab"] | 198 [[UIImage imageNamed:@"tabswitcher_new_tab_fab"] |
196 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; | 199 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
197 [_openNewTabButton setImage:openNewTabButtonImage | 200 [_openNewTabButton setImage:openNewTabButtonImage |
198 forState:UIControlStateNormal]; | 201 forState:UIControlStateNormal]; |
199 [[_openNewTabButton imageView] setTintColor:[UIColor whiteColor]]; | 202 [[_openNewTabButton imageView] setTintColor:[UIColor whiteColor]]; |
200 [_openNewTabButton setFrame:[self openNewTabButtonFrame]]; | 203 [_openNewTabButton setFrame:[self openNewTabButtonFrame]]; |
201 // When the button is positioned with autolayout, the animation of the | 204 // When the button is positioned with autolayout, the animation of the |
202 // button's position conflicts with other animations. | 205 // button's position conflicts with other animations. |
203 [_openNewTabButton | 206 [_openNewTabButton |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 case ios_internal::GRAY: | 362 case ios_internal::GRAY: |
360 [self.delegate openNewTabInPanelAtIndex:panelIndex]; | 363 [self.delegate openNewTabInPanelAtIndex:panelIndex]; |
361 return YES; | 364 return YES; |
362 case ios_internal::UNINITIALIZED: | 365 case ios_internal::UNINITIALIZED: |
363 case ios_internal::HIDDEN: | 366 case ios_internal::HIDDEN: |
364 return NO; | 367 return NO; |
365 } | 368 } |
366 } | 369 } |
367 | 370 |
368 @end | 371 @end |
OLD | NEW |