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

Side by Side Diff: ios/chrome/browser/ui/tabs/tab_strip_controller.mm

Issue 2942913002: [ObjC ARC] Converts ios/chrome/browser/ui/tabs:tabs to ARC. (Closed)
Patch Set: fix_error 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
« no previous file with comments | « ios/chrome/browser/ui/tabs/BUILD.gn ('k') | ios/chrome/browser/ui/tabs/tab_strip_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tabs/tab_strip_controller.h" 5 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h"
6 #import "ios/chrome/browser/ui/tabs/tab_strip_controller_private.h" 6 #import "ios/chrome/browser/ui/tabs/tab_strip_controller_private.h"
7 7
8 #include <cmath> 8 #include <cmath>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #import "base/ios/weak_nsobject.h"
13 #include "base/mac/bundle_locations.h" 12 #include "base/mac/bundle_locations.h"
14 #include "base/mac/foundation_util.h" 13 #include "base/mac/foundation_util.h"
15 #include "base/mac/objc_property_releaser.h" 14
16 #include "base/mac/scoped_nsobject.h"
17 #include "base/metrics/user_metrics.h" 15 #include "base/metrics/user_metrics.h"
18 #include "base/metrics/user_metrics_action.h" 16 #include "base/metrics/user_metrics_action.h"
19 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 18 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
21 #include "ios/chrome/browser/experimental_flags.h" 19 #include "ios/chrome/browser/experimental_flags.h"
22 #import "ios/chrome/browser/tabs/tab.h" 20 #import "ios/chrome/browser/tabs/tab.h"
23 #import "ios/chrome/browser/tabs/tab_model.h" 21 #import "ios/chrome/browser/tabs/tab_model.h"
24 #import "ios/chrome/browser/tabs/tab_model_observer.h" 22 #import "ios/chrome/browser/tabs/tab_model_observer.h"
25 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 23 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
26 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 24 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
27 #import "ios/chrome/browser/ui/fullscreen_controller.h" 25 #import "ios/chrome/browser/ui/fullscreen_controller.h"
28 #include "ios/chrome/browser/ui/rtl_geometry.h" 26 #include "ios/chrome/browser/ui/rtl_geometry.h"
29 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_tab_strip_placeholder_ view.h" 27 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_tab_strip_placeholder_ view.h"
30 #import "ios/chrome/browser/ui/tabs/tab_strip_controller+tab_switcher_animation. h" 28 #import "ios/chrome/browser/ui/tabs/tab_strip_controller+tab_switcher_animation. h"
31 #import "ios/chrome/browser/ui/tabs/tab_strip_view.h" 29 #import "ios/chrome/browser/ui/tabs/tab_strip_view.h"
32 #import "ios/chrome/browser/ui/tabs/tab_view.h" 30 #import "ios/chrome/browser/ui/tabs/tab_view.h"
33 #include "ios/chrome/browser/ui/tabs/target_frame_cache.h" 31 #include "ios/chrome/browser/ui/tabs/target_frame_cache.h"
34 #include "ios/chrome/browser/ui/ui_util.h" 32 #include "ios/chrome/browser/ui/ui_util.h"
35 #import "ios/chrome/browser/ui/uikit_ui_util.h" 33 #import "ios/chrome/browser/ui/uikit_ui_util.h"
36 #import "ios/chrome/browser/ui/util/snapshot_util.h" 34 #import "ios/chrome/browser/ui/util/snapshot_util.h"
37 #include "ios/chrome/grit/ios_strings.h" 35 #include "ios/chrome/grit/ios_strings.h"
38 #import "ios/web/public/web_state/web_state.h" 36 #import "ios/web/public/web_state/web_state.h"
39 #include "third_party/google_toolbox_for_mac/src/iPhone/GTMFadeTruncatingLabel.h " 37 #include "third_party/google_toolbox_for_mac/src/iPhone/GTMFadeTruncatingLabel.h "
40 #include "ui/gfx/image/image.h" 38 #include "ui/gfx/image/image.h"
41 39
40 #if !defined(__has_feature) || !__has_feature(objc_arc)
41 #error "This file requires ARC support."
42 #endif
43
42 using base::UserMetricsAction; 44 using base::UserMetricsAction;
43 45
44 NSString* const kWillStartTabStripTabAnimation = 46 NSString* const kWillStartTabStripTabAnimation =
45 @"kWillStartTabStripTabAnimation"; 47 @"kWillStartTabStripTabAnimation";
46 NSString* const kTabStripDragStarted = @"kTabStripDragStarted"; 48 NSString* const kTabStripDragStarted = @"kTabStripDragStarted";
47 NSString* const kTabStripDragEnded = @"kTabStripDragEnded"; 49 NSString* const kTabStripDragEnded = @"kTabStripDragEnded";
48 50
49 namespace TabStrip { 51 namespace TabStrip {
50 UIColor* BackgroundColor() { 52 UIColor* BackgroundColor() {
51 DCHECK(IsIPadIdiom()); 53 DCHECK(IsIPadIdiom());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 113
112 // Offsets needed to keep the UI properly centered on high-res screens, in 114 // Offsets needed to keep the UI properly centered on high-res screens, in
113 // points. 115 // points.
114 const CGFloat kNewTabButtonBottomOffsetHighRes = 2.0; 116 const CGFloat kNewTabButtonBottomOffsetHighRes = 2.0;
115 } 117 }
116 118
117 @interface TabStripController ()<TabModelObserver, 119 @interface TabStripController ()<TabModelObserver,
118 TabStripViewLayoutDelegate, 120 TabStripViewLayoutDelegate,
119 UIGestureRecognizerDelegate, 121 UIGestureRecognizerDelegate,
120 UIScrollViewDelegate> { 122 UIScrollViewDelegate> {
121 base::scoped_nsobject<TabModel> _tabModel; 123 TabModel* _tabModel;
122 UIView* _view; 124 UIView* _view;
123 TabStripView* _tabStripView; 125 TabStripView* _tabStripView;
124 UIButton* _buttonNewTab; 126 UIButton* _buttonNewTab;
125 base::scoped_nsobject<UIButton> _tabSwitcherButton; 127 UIButton* _tabSwitcherButton;
126 128
127 // Background view of the tab switcher button. Only visible while in compact 129 // Background view of the tab switcher button. Only visible while in compact
128 // layout. 130 // layout.
129 base::scoped_nsobject<UIImageView> _tabSwitcherButtonBackgroundView; 131 UIImageView* _tabSwitcherButtonBackgroundView;
130 132
131 TabStrip::Style _style; 133 TabStrip::Style _style;
132 base::WeakNSProtocol<id<FullScreenControllerDelegate>> _fullscreenDelegate; 134 __weak id<FullScreenControllerDelegate> _fullscreenDelegate;
133 135
134 // Array of TabViews. There is a one-to-one correspondence between this array 136 // Array of TabViews. There is a one-to-one correspondence between this array
135 // and the set of Tabs in the TabModel. 137 // and the set of Tabs in the TabModel.
136 base::scoped_nsobject<NSMutableArray> _tabArray; 138 NSMutableArray* _tabArray;
137 139
138 // Set of TabViews that are currently closing. These TabViews are also in 140 // Set of TabViews that are currently closing. These TabViews are also in
139 // |_tabArray|. Used to translate between |_tabArray| indexes and TabModel 141 // |_tabArray|. Used to translate between |_tabArray| indexes and TabModel
140 // indexes. 142 // indexes.
141 base::scoped_nsobject<NSMutableSet> _closingTabs; 143 NSMutableSet* _closingTabs;
142 144
143 // Tracks target frames for TabViews. 145 // Tracks target frames for TabViews.
144 // TODO(rohitrao): This is unnecessary, as UIKit updates view frames 146 // TODO(rohitrao): This is unnecessary, as UIKit updates view frames
145 // immediately, so [view frame] will always return the end state of the 147 // immediately, so [view frame] will always return the end state of the
146 // current animation. We can remove this cache entirely. b/5516053 148 // current animation. We can remove this cache entirely. b/5516053
147 TargetFrameCache _targetFrames; 149 TargetFrameCache _targetFrames;
148 150
149 // Animate when doing layout. This flag is set by setNeedsLayoutWithAnimation 151 // Animate when doing layout. This flag is set by setNeedsLayoutWithAnimation
150 // and cleared in layoutSubviews. 152 // and cleared in layoutSubviews.
151 BOOL _animateLayout; 153 BOOL _animateLayout;
152 154
153 // The current tab width. Recomputed whenever a tab is added or removed. 155 // The current tab width. Recomputed whenever a tab is added or removed.
154 CGFloat _currentTabWidth; 156 CGFloat _currentTabWidth;
155 157
156 // View used to dim unselected tabs when in reordering mode. Nil when not 158 // View used to dim unselected tabs when in reordering mode. Nil when not
157 // reordering tabs. 159 // reordering tabs.
158 base::scoped_nsobject<UIView> _dimmingView; 160 UIView* _dimmingView;
159 161
160 // Is the selected tab highlighted, used when dragging or swiping tabs. 162 // Is the selected tab highlighted, used when dragging or swiping tabs.
161 BOOL _highlightsSelectedTab; 163 BOOL _highlightsSelectedTab;
162 164
163 // YES when in reordering mode. 165 // YES when in reordering mode.
164 // TODO(rohitrao): This is redundant with |_draggedTab|. Remove it. 166 // TODO(rohitrao): This is redundant with |_draggedTab|. Remove it.
165 BOOL _isReordering; 167 BOOL _isReordering;
166 168
167 // The tab that is currently being dragged. nil when not in reordering mode. 169 // The tab that is currently being dragged. nil when not in reordering mode.
168 base::scoped_nsobject<TabView> _draggedTab; 170 TabView* _draggedTab;
169 171
170 // The last known location of the touch that is dragging the tab. This 172 // The last known location of the touch that is dragging the tab. This
171 // location is in the coordinate system of |[_tabStripView superview]| because 173 // location is in the coordinate system of |[_tabStripView superview]| because
172 // that coordinate system does not change as the scroll view scrolls. 174 // that coordinate system does not change as the scroll view scrolls.
173 CGPoint _lastDragLocation; 175 CGPoint _lastDragLocation;
174 176
175 // Timer used to autoscroll when in reordering mode. Is nil when not active. 177 // Timer used to autoscroll when in reordering mode. Is nil when not active.
176 // Owned by its runloop. 178 // Owned by its runloop.
177 NSTimer* _autoscrollTimer; // weak 179 NSTimer* _autoscrollTimer; // weak
178 180
179 // The distance to scroll for each autoscroll timer tick. If negative, the 181 // The distance to scroll for each autoscroll timer tick. If negative, the
180 // tabstrip will scroll to the left; if positive, to the right. 182 // tabstrip will scroll to the left; if positive, to the right.
181 CGFloat _autoscrollDistance; 183 CGFloat _autoscrollDistance;
182 184
183 // The model index of the placeholder gap, if one exists. This value is used 185 // The model index of the placeholder gap, if one exists. This value is used
184 // as the new model index of the dragged tab when it is dropped. 186 // as the new model index of the dragged tab when it is dropped.
185 NSUInteger _placeholderGapModelIndex; 187 NSUInteger _placeholderGapModelIndex;
186
187 base::mac::ObjCPropertyReleaser _propertyReleaser_TabStripController;
188 } 188 }
189 189
190 @property(nonatomic, readonly, retain) TabStripView* tabStripView; 190 @property(nonatomic, readonly, retain) TabStripView* tabStripView;
191 @property(nonatomic, readonly, retain) UIButton* buttonNewTab; 191 @property(nonatomic, readonly, retain) UIButton* buttonNewTab;
192 192
193 // Initializes the tab array based on the the entries in the TabModel. Creates 193 // Initializes the tab array based on the the entries in the TabModel. Creates
194 // one TabView per Tab and adds it to the tabstrip. A later call to 194 // one TabView per Tab and adds it to the tabstrip. A later call to
195 // |-layoutTabs| is needed to properly place the tabs in the correct positions. 195 // |-layoutTabs| is needed to properly place the tabs in the correct positions.
196 - (void)initializeTabArrayFromTabModel; 196 - (void)initializeTabArrayFromTabModel;
197 197
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 @implementation TabStripController 319 @implementation TabStripController
320 320
321 @synthesize buttonNewTab = _buttonNewTab; 321 @synthesize buttonNewTab = _buttonNewTab;
322 @synthesize highlightsSelectedTab = _highlightsSelectedTab; 322 @synthesize highlightsSelectedTab = _highlightsSelectedTab;
323 @synthesize tabStripView = _tabStripView; 323 @synthesize tabStripView = _tabStripView;
324 @synthesize view = _view; 324 @synthesize view = _view;
325 325
326 - (instancetype)initWithTabModel:(TabModel*)tabModel 326 - (instancetype)initWithTabModel:(TabModel*)tabModel
327 style:(TabStrip::Style)style { 327 style:(TabStrip::Style)style {
328 if ((self = [super init])) { 328 if ((self = [super init])) {
329 _propertyReleaser_TabStripController.Init(self, [TabStripController class]); 329 _tabArray = [[NSMutableArray alloc] initWithCapacity:10];
330 _tabArray.reset([[NSMutableArray alloc] initWithCapacity:10]); 330 _closingTabs = [[NSMutableSet alloc] initWithCapacity:5];
331 _closingTabs.reset([[NSMutableSet alloc] initWithCapacity:5]);
332 331
333 _tabModel.reset([tabModel retain]); 332 _tabModel = tabModel;
334 [_tabModel addObserver:self]; 333 [_tabModel addObserver:self];
335 _style = style; 334 _style = style;
336 335
337 // |self.view| setup. 336 // |self.view| setup.
338 CGRect tabStripFrame = [UIApplication sharedApplication].keyWindow.bounds; 337 CGRect tabStripFrame = [UIApplication sharedApplication].keyWindow.bounds;
339 tabStripFrame.size.height = kTabStripHeight; 338 tabStripFrame.size.height = kTabStripHeight;
340 _view = [[UIView alloc] initWithFrame:tabStripFrame]; 339 _view = [[UIView alloc] initWithFrame:tabStripFrame];
341 _view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | 340 _view.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
342 UIViewAutoresizingFlexibleBottomMargin); 341 UIViewAutoresizingFlexibleBottomMargin);
343 _view.backgroundColor = TabStrip::BackgroundColor(); 342 _view.backgroundColor = TabStrip::BackgroundColor();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 424
426 - (instancetype)init { 425 - (instancetype)init {
427 NOTREACHED(); 426 NOTREACHED();
428 return nil; 427 return nil;
429 } 428 }
430 429
431 - (void)dealloc { 430 - (void)dealloc {
432 [_tabStripView setDelegate:nil]; 431 [_tabStripView setDelegate:nil];
433 [_tabStripView setLayoutDelegate:nil]; 432 [_tabStripView setLayoutDelegate:nil];
434 [_tabModel removeObserver:self]; 433 [_tabModel removeObserver:self];
435 [super dealloc]; 434 ;
marq (ping after 24h) 2017/06/19 11:03:49 Remove bare ;
stkhapugin 2017/06/20 14:38:57 Done.
436 } 435 }
437 436
438 - (id<FullScreenControllerDelegate>)fullscreenDelegate { 437 - (id<FullScreenControllerDelegate>)fullscreenDelegate {
439 return _fullscreenDelegate; 438 return _fullscreenDelegate;
440 } 439 }
441 440
442 - (void)setFullscreenDelegate: 441 - (void)setFullscreenDelegate:
443 (id<FullScreenControllerDelegate>)fullscreenDelegate { 442 (id<FullScreenControllerDelegate>)fullscreenDelegate {
444 _fullscreenDelegate.reset(fullscreenDelegate); 443 _fullscreenDelegate = fullscreenDelegate;
445 } 444 }
446 445
447 - (void)initializeTabArrayFromTabModel { 446 - (void)initializeTabArrayFromTabModel {
448 DCHECK(_tabModel); 447 DCHECK(_tabModel);
449 for (Tab* tab in _tabModel.get()) { 448 for (Tab* tab in _tabModel) {
450 BOOL isSelectedTab = [_tabModel currentTab] == tab; 449 BOOL isSelectedTab = [_tabModel currentTab] == tab;
451 TabView* view = [self tabViewForTab:tab isSelected:isSelectedTab]; 450 TabView* view = [self tabViewForTab:tab isSelected:isSelectedTab];
452 [_tabArray addObject:view]; 451 [_tabArray addObject:view];
453 [_tabStripView addSubview:view]; 452 [_tabStripView addSubview:view];
454 } 453 }
455 } 454 }
456 455
457 - (void)initializeTabArrayWithNoModel { 456 - (void)initializeTabArrayWithNoModel {
458 DCHECK(!_tabModel); 457 DCHECK(!_tabModel);
459 TabView* view = [self emptyTabView]; 458 TabView* view = [self emptyTabView];
460 [_tabArray addObject:view]; 459 [_tabArray addObject:view];
461 [_tabStripView addSubview:view]; 460 [_tabStripView addSubview:view];
462 [view setSelected:YES]; 461 [view setSelected:YES];
463 return; 462 return;
464 } 463 }
465 464
466 - (TabView*)emptyTabView { 465 - (TabView*)emptyTabView {
467 TabView* view = 466 TabView* view = [[TabView alloc] initWithEmptyView:YES selected:YES];
468 [[[TabView alloc] initWithEmptyView:YES selected:YES] autorelease];
469 [view setIncognitoStyle:(_style == TabStrip::kStyleIncognito)]; 467 [view setIncognitoStyle:(_style == TabStrip::kStyleIncognito)];
470 [view setContentMode:UIViewContentModeRedraw]; 468 [view setContentMode:UIViewContentModeRedraw];
471 469
472 // Setting the tab to be hidden marks it as a new tab. The layout code will 470 // Setting the tab to be hidden marks it as a new tab. The layout code will
473 // make the tab visible and set up the appropriate animations. 471 // make the tab visible and set up the appropriate animations.
474 [view setHidden:YES]; 472 [view setHidden:YES];
475 473
476 return view; 474 return view;
477 } 475 }
478 476
479 - (TabView*)tabViewForTab:(Tab*)tab isSelected:(BOOL)isSelected { 477 - (TabView*)tabViewForTab:(Tab*)tab isSelected:(BOOL)isSelected {
480 TabView* view = 478 TabView* view = [[TabView alloc] initWithEmptyView:NO selected:isSelected];
481 [[[TabView alloc] initWithEmptyView:NO selected:isSelected] autorelease];
482 if (UseRTLLayout()) 479 if (UseRTLLayout())
483 [view setTransform:CGAffineTransformMakeScale(-1, 1)]; 480 [view setTransform:CGAffineTransformMakeScale(-1, 1)];
484 [view setIncognitoStyle:(_style == TabStrip::kStyleIncognito)]; 481 [view setIncognitoStyle:(_style == TabStrip::kStyleIncognito)];
485 [view setContentMode:UIViewContentModeRedraw]; 482 [view setContentMode:UIViewContentModeRedraw];
486 [[view titleLabel] setText:[tab title]]; 483 [[view titleLabel] setText:[tab title]];
487 [view setFavicon:[tab favicon]]; 484 [view setFavicon:[tab favicon]];
488 485
489 // Set the tab buttons' action messages. 486 // Set the tab buttons' action messages.
490 [view addTarget:self 487 [view addTarget:self
491 action:@selector(tabTapped:) 488 action:@selector(tabTapped:)
492 forControlEvents:UIControlEventTouchUpInside]; 489 forControlEvents:UIControlEventTouchUpInside];
493 [[view closeButton] addTarget:self 490 [[view closeButton] addTarget:self
494 action:@selector(closeTab:) 491 action:@selector(closeTab:)
495 forControlEvents:UIControlEventTouchUpInside]; 492 forControlEvents:UIControlEventTouchUpInside];
496 493
497 // Install a long press gesture recognizer to handle drag and drop. 494 // Install a long press gesture recognizer to handle drag and drop.
498 base::scoped_nsobject<UILongPressGestureRecognizer> longPress( 495 UILongPressGestureRecognizer* longPress =
499 [[UILongPressGestureRecognizer alloc] 496 [[UILongPressGestureRecognizer alloc]
500 initWithTarget:self 497 initWithTarget:self
501 action:@selector(handleLongPress:)]); 498 action:@selector(handleLongPress:)];
502 [longPress setMinimumPressDuration:kDragAndDropLongPressDuration]; 499 [longPress setMinimumPressDuration:kDragAndDropLongPressDuration];
503 [longPress setDelegate:self]; 500 [longPress setDelegate:self];
504 [view addGestureRecognizer:longPress]; 501 [view addGestureRecognizer:longPress];
505 502
506 // Giving the tab view exclusive touch prevents other views from receiving 503 // Giving the tab view exclusive touch prevents other views from receiving
507 // touches while a TabView is handling a touch. 504 // touches while a TabView is handling a touch.
508 [view setExclusiveTouch:YES]; 505 [view setExclusiveTouch:YES];
509 506
510 // Setting the tab to be hidden marks it as a new tab. The layout code will 507 // Setting the tab to be hidden marks it as a new tab. The layout code will
511 // make the tab visible and set up the appropriate animations. 508 // make the tab visible and set up the appropriate animations.
(...skipping 14 matching lines...) Expand all
526 - (void)installDimmingViewWithAnimation:(BOOL)animate { 523 - (void)installDimmingViewWithAnimation:(BOOL)animate {
527 // The dimming view should not cover the bottom 2px of the tab strip, as those 524 // The dimming view should not cover the bottom 2px of the tab strip, as those
528 // pixels are visually part of the top border of the toolbar. The bottom 525 // pixels are visually part of the top border of the toolbar. The bottom
529 // inset constants take into account the conversion from pixels to points. 526 // inset constants take into account the conversion from pixels to points.
530 CGRect frame = [_tabStripView bounds]; 527 CGRect frame = [_tabStripView bounds];
531 frame.size.height -= (IsHighResScreen() ? kDimmingViewBottomInsetHighRes 528 frame.size.height -= (IsHighResScreen() ? kDimmingViewBottomInsetHighRes
532 : kDimmingViewBottomInset); 529 : kDimmingViewBottomInset);
533 530
534 // Create the dimming view if it doesn't exist. In all cases, make sure it's 531 // Create the dimming view if it doesn't exist. In all cases, make sure it's
535 // set up correctly. 532 // set up correctly.
536 if (_dimmingView.get()) 533 if (_dimmingView)
537 [_dimmingView setFrame:frame]; 534 [_dimmingView setFrame:frame];
538 else 535 else
539 _dimmingView.reset([[UIView alloc] initWithFrame:frame]); 536 _dimmingView = [[UIView alloc] initWithFrame:frame];
540 537
541 // Enable user interaction in order to eat touches from views behind it. 538 // Enable user interaction in order to eat touches from views behind it.
542 [_dimmingView setUserInteractionEnabled:YES]; 539 [_dimmingView setUserInteractionEnabled:YES];
543 [_dimmingView setBackgroundColor:[TabStrip::BackgroundColor() 540 [_dimmingView setBackgroundColor:[TabStrip::BackgroundColor()
544 colorWithAlphaComponent:0]]; 541 colorWithAlphaComponent:0]];
545 [_dimmingView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | 542 [_dimmingView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
546 UIViewAutoresizingFlexibleHeight)]; 543 UIViewAutoresizingFlexibleHeight)];
547 [_tabStripView addSubview:_dimmingView]; 544 [_tabStripView addSubview:_dimmingView];
548 545
549 CGFloat duration = animate ? kTabStripFadeAnimationDuration : 0; 546 CGFloat duration = animate ? kTabStripFadeAnimationDuration : 0;
(...skipping 10 matching lines...) Expand all
560 CGFloat duration = animate ? kTabStripFadeAnimationDuration : 0; 557 CGFloat duration = animate ? kTabStripFadeAnimationDuration : 0;
561 [UIView animateWithDuration:duration 558 [UIView animateWithDuration:duration
562 animations:^{ 559 animations:^{
563 [_dimmingView setBackgroundColor:[TabStrip::BackgroundColor() 560 [_dimmingView setBackgroundColor:[TabStrip::BackgroundColor()
564 colorWithAlphaComponent:0]]; 561 colorWithAlphaComponent:0]];
565 } 562 }
566 completion:^(BOOL finished) { 563 completion:^(BOOL finished) {
567 // Do not remove the dimming view if the animation was aborted. 564 // Do not remove the dimming view if the animation was aborted.
568 if (finished) { 565 if (finished) {
569 [_dimmingView removeFromSuperview]; 566 [_dimmingView removeFromSuperview];
570 _dimmingView.reset(); 567 _dimmingView = nil;
571 } 568 }
572 }]; 569 }];
573 } 570 }
574 } 571 }
575 572
576 - (void)recordUserMetrics:(id)sender { 573 - (void)recordUserMetrics:(id)sender {
577 if (sender == _buttonNewTab) 574 if (sender == _buttonNewTab)
578 base::RecordAction(UserMetricsAction("MobileTabStripNewTab")); 575 base::RecordAction(UserMetricsAction("MobileTabStripNewTab"));
579 else if (sender == _tabSwitcherButton.get()) 576 else if (sender == _tabSwitcherButton)
580 base::RecordAction(UserMetricsAction("MobileTabSwitcherOpen")); 577 base::RecordAction(UserMetricsAction("MobileTabSwitcherOpen"));
581 else 578 else
582 LOG(WARNING) << "Trying to record metrics for unknown sender " 579 LOG(WARNING) << "Trying to record metrics for unknown sender "
583 << base::SysNSStringToUTF8([sender description]); 580 << base::SysNSStringToUTF8([sender description]);
584 } 581 }
585 582
586 - (void)tabTapped:(id)sender { 583 - (void)tabTapped:(id)sender {
587 DCHECK([sender isKindOfClass:[TabView class]]); 584 DCHECK([sender isKindOfClass:[TabView class]]);
588 585
589 // Ignore taps while in reordering mode. 586 // Ignore taps while in reordering mode.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 object:nil]; 640 object:nil];
644 break; 641 break;
645 default: 642 default:
646 NOTREACHED(); 643 NOTREACHED();
647 } 644 }
648 } 645 }
649 646
650 - (NSUInteger)indexForModelIndex:(NSUInteger)modelIndex { 647 - (NSUInteger)indexForModelIndex:(NSUInteger)modelIndex {
651 NSUInteger index = modelIndex; 648 NSUInteger index = modelIndex;
652 NSUInteger i = 0; 649 NSUInteger i = 0;
653 for (TabView* tab in _tabArray.get()) { 650 for (TabView* tab in _tabArray) {
654 if ([_closingTabs containsObject:tab]) 651 if ([_closingTabs containsObject:tab])
655 ++index; 652 ++index;
656 653
657 if (i == index) 654 if (i == index)
658 break; 655 break;
659 656
660 ++i; 657 ++i;
661 } 658 }
662 659
663 DCHECK_GE(index, modelIndex); 660 DCHECK_GE(index, modelIndex);
664 return index; 661 return index;
665 } 662 }
666 663
667 - (NSUInteger)modelIndexForIndex:(NSUInteger)index { 664 - (NSUInteger)modelIndexForIndex:(NSUInteger)index {
668 NSUInteger modelIndex = 0; 665 NSUInteger modelIndex = 0;
669 NSUInteger arrayIndex = 0; 666 NSUInteger arrayIndex = 0;
670 for (TabView* tab in _tabArray.get()) { 667 for (TabView* tab in _tabArray) {
671 if (arrayIndex == index) { 668 if (arrayIndex == index) {
672 if ([_closingTabs containsObject:tab]) 669 if ([_closingTabs containsObject:tab])
673 return NSNotFound; 670 return NSNotFound;
674 return modelIndex; 671 return modelIndex;
675 } 672 }
676 673
677 if (![_closingTabs containsObject:tab]) 674 if (![_closingTabs containsObject:tab])
678 ++modelIndex; 675 ++modelIndex;
679 676
680 ++arrayIndex; 677 ++arrayIndex;
(...skipping 22 matching lines...) Expand all
703 // Install the dimming view, hide the new tab button, and select the tab so it 700 // Install the dimming view, hide the new tab button, and select the tab so it
704 // appears highlighted. 701 // appears highlighted.
705 Tab* tab = [_tabModel tabAtIndex:index]; 702 Tab* tab = [_tabModel tabAtIndex:index];
706 self.highlightsSelectedTab = YES; 703 self.highlightsSelectedTab = YES;
707 _buttonNewTab.hidden = YES; 704 _buttonNewTab.hidden = YES;
708 [_tabModel setCurrentTab:tab]; 705 [_tabModel setCurrentTab:tab];
709 706
710 // Set up initial drag state. 707 // Set up initial drag state.
711 _lastDragLocation = [gesture locationInView:[_tabStripView superview]]; 708 _lastDragLocation = [gesture locationInView:[_tabStripView superview]];
712 _isReordering = YES; 709 _isReordering = YES;
713 _draggedTab.reset([view retain]); 710 _draggedTab = nil;
marq (ping after 24h) 2017/06/19 11:03:49 _draggedTab = view, I think.
stkhapugin 2017/06/20 14:38:56 Done.
714 _placeholderGapModelIndex = [self modelIndexForTabView:_draggedTab]; 711 _placeholderGapModelIndex = [self modelIndexForTabView:_draggedTab];
715 712
716 // Update the autoscroll distance and timer. 713 // Update the autoscroll distance and timer.
717 [self computeAutoscrollDistanceForTabView:_draggedTab]; 714 [self computeAutoscrollDistanceForTabView:_draggedTab];
718 if (_autoscrollDistance != 0) 715 if (_autoscrollDistance != 0)
719 [self installAutoscrollTimerIfNeeded]; 716 [self installAutoscrollTimerIfNeeded];
720 else 717 else
721 [self removeAutoscrollTimer]; 718 [self removeAutoscrollTimer];
722 } 719 }
723 720
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 [self setNeedsLayoutWithAnimation]; 775 [self setNeedsLayoutWithAnimation];
779 } 776 }
780 777
781 - (void)resetDragState { 778 - (void)resetDragState {
782 self.highlightsSelectedTab = NO; 779 self.highlightsSelectedTab = NO;
783 _buttonNewTab.hidden = NO; 780 _buttonNewTab.hidden = NO;
784 [self removeAutoscrollTimer]; 781 [self removeAutoscrollTimer];
785 782
786 _isReordering = NO; 783 _isReordering = NO;
787 _placeholderGapModelIndex = NSNotFound; 784 _placeholderGapModelIndex = NSNotFound;
788 _draggedTab.reset(); 785 _draggedTab = nil;
789 } 786 }
790 787
791 - (BOOL)isReorderingTabs { 788 - (BOOL)isReorderingTabs {
792 return _isReordering; 789 return _isReordering;
793 } 790 }
794 791
795 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)recognizer { 792 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)recognizer {
796 DCHECK([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]); 793 DCHECK([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]);
797 794
798 // If a drag is already in progress, do not allow another to start. 795 // If a drag is already in progress, do not allow another to start.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 943
947 // Observer method. 944 // Observer method.
948 - (void)tabModel:(TabModel*)model 945 - (void)tabModel:(TabModel*)model
949 didMoveTab:(Tab*)tab 946 didMoveTab:(Tab*)tab
950 fromIndex:(NSUInteger)fromIndex 947 fromIndex:(NSUInteger)fromIndex
951 toIndex:(NSUInteger)toIndex { 948 toIndex:(NSUInteger)toIndex {
952 DCHECK(!_isReordering); 949 DCHECK(!_isReordering);
953 950
954 // Reorder the objects in _tabArray to keep in sync with the model ordering. 951 // Reorder the objects in _tabArray to keep in sync with the model ordering.
955 NSUInteger arrayIndex = [self indexForModelIndex:fromIndex]; 952 NSUInteger arrayIndex = [self indexForModelIndex:fromIndex];
956 base::scoped_nsobject<TabView> view( 953 TabView* view = [_tabArray objectAtIndex:arrayIndex];
957 [[_tabArray objectAtIndex:arrayIndex] retain]);
958 [_tabArray removeObject:view]; 954 [_tabArray removeObject:view];
959 [_tabArray insertObject:view atIndex:toIndex]; 955 [_tabArray insertObject:view atIndex:toIndex];
960 [self setNeedsLayoutWithAnimation]; 956 [self setNeedsLayoutWithAnimation];
961 } 957 }
962 958
963 // Observer method. 959 // Observer method.
964 - (void)tabModel:(TabModel*)model 960 - (void)tabModel:(TabModel*)model
965 didChangeActiveTab:(Tab*)newTab 961 didChangeActiveTab:(Tab*)newTab
966 previousTab:(Tab*)previousTab 962 previousTab:(Tab*)previousTab
967 atIndex:(NSUInteger)modelIndex { 963 atIndex:(NSUInteger)modelIndex {
968 for (TabView* view in _tabArray.get()) { 964 for (TabView* view in _tabArray) {
969 [view setSelected:NO]; 965 [view setSelected:NO];
970 } 966 }
971 967
972 NSUInteger index = [self indexForModelIndex:modelIndex]; 968 NSUInteger index = [self indexForModelIndex:modelIndex];
973 TabView* activeView = [_tabArray objectAtIndex:index]; 969 TabView* activeView = [_tabArray objectAtIndex:index];
974 [activeView setSelected:YES]; 970 [activeView setSelected:YES];
975 971
976 // No need to animate this change, as selecting a new tab simply changes the 972 // No need to animate this change, as selecting a new tab simply changes the
977 // z-ordering of the TabViews. If a new tab was selected as a result of a tab 973 // z-ordering of the TabViews. If a new tab was selected as a result of a tab
978 // closure, then the animated layout has already been scheduled. 974 // closure, then the animated layout has already been scheduled.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 [UIImage imageNamed:@"tabswitcher_tab_switcher_button"]; 1021 [UIImage imageNamed:@"tabswitcher_tab_switcher_button"];
1026 tabSwitcherButtonIcon = [tabSwitcherButtonIcon 1022 tabSwitcherButtonIcon = [tabSwitcherButtonIcon
1027 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 1023 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
1028 int tabSwitcherButtonIdsAccessibilityLabel = 1024 int tabSwitcherButtonIdsAccessibilityLabel =
1029 IDS_IOS_TAB_STRIP_ENTER_TAB_SWITCHER; 1025 IDS_IOS_TAB_STRIP_ENTER_TAB_SWITCHER;
1030 NSString* tabSwitcherButtonEnglishUiAutomationName = @"Enter Tab Switcher"; 1026 NSString* tabSwitcherButtonEnglishUiAutomationName = @"Enter Tab Switcher";
1031 const CGFloat tabStripHeight = _view.frame.size.height; 1027 const CGFloat tabStripHeight = _view.frame.size.height;
1032 CGRect buttonFrame = 1028 CGRect buttonFrame =
1033 CGRectMake(CGRectGetMaxX(_view.frame) - kTabSwitcherButtonWidth, 0.0, 1029 CGRectMake(CGRectGetMaxX(_view.frame) - kTabSwitcherButtonWidth, 0.0,
1034 kTabSwitcherButtonWidth, tabStripHeight); 1030 kTabSwitcherButtonWidth, tabStripHeight);
1035 _tabSwitcherButton.reset( 1031 _tabSwitcherButton = [UIButton buttonWithType:UIButtonTypeCustom];
1036 [[UIButton buttonWithType:UIButtonTypeCustom] retain]);
1037 [_tabSwitcherButton setTintColor:[UIColor whiteColor]]; 1032 [_tabSwitcherButton setTintColor:[UIColor whiteColor]];
1038 [_tabSwitcherButton setFrame:buttonFrame]; 1033 [_tabSwitcherButton setFrame:buttonFrame];
1039 [_tabSwitcherButton setContentMode:UIViewContentModeCenter]; 1034 [_tabSwitcherButton setContentMode:UIViewContentModeCenter];
1040 [_tabSwitcherButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; 1035 [_tabSwitcherButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
1041 [_tabSwitcherButton setBackgroundColor:[UIColor clearColor]]; 1036 [_tabSwitcherButton setBackgroundColor:[UIColor clearColor]];
1042 [_tabSwitcherButton setExclusiveTouch:YES]; 1037 [_tabSwitcherButton setExclusiveTouch:YES];
1043 [_tabSwitcherButton setImage:tabSwitcherButtonIcon 1038 [_tabSwitcherButton setImage:tabSwitcherButtonIcon
1044 forState:UIControlStateNormal]; 1039 forState:UIControlStateNormal];
1045 // Set target/action to bubble up with command id as tag. 1040 // Set target/action to bubble up with command id as tag.
1046 [_tabSwitcherButton addTarget:nil 1041 [_tabSwitcherButton addTarget:nil
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 } 1162 }
1168 1163
1169 // To handle content offset change without making views appear to jump, 1164 // To handle content offset change without making views appear to jump,
1170 // shift all of the subviews by an amount equal to the size change. 1165 // shift all of the subviews by an amount equal to the size change.
1171 [self shiftTabStripSubviews:oldOffset]; 1166 [self shiftTabStripSubviews:oldOffset];
1172 return; 1167 return;
1173 } 1168 }
1174 1169
1175 NSUInteger numNonClosingTabsToLeft = 0; 1170 NSUInteger numNonClosingTabsToLeft = 0;
1176 NSUInteger i = 0; 1171 NSUInteger i = 0;
1177 for (TabView* tab in _tabArray.get()) { 1172 for (TabView* tab in _tabArray) {
1178 if ([_closingTabs containsObject:tab]) 1173 if ([_closingTabs containsObject:tab])
1179 ++i; 1174 ++i;
1180 1175
1181 if (i == tabIndex) 1176 if (i == tabIndex)
1182 break; 1177 break;
1183 1178
1184 ++numNonClosingTabsToLeft; 1179 ++numNonClosingTabsToLeft;
1185 ++i; 1180 ++i;
1186 } 1181 }
1187 1182
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 1219
1225 - (void)updateScrollViewFrameForTabSwitcherButton { 1220 - (void)updateScrollViewFrameForTabSwitcherButton {
1226 CGRect tabFrame = _tabStripView.frame; 1221 CGRect tabFrame = _tabStripView.frame;
1227 tabFrame.size.width = _view.bounds.size.width; 1222 tabFrame.size.width = _view.bounds.size.width;
1228 if (!IsCompactTablet()) { 1223 if (!IsCompactTablet()) {
1229 tabFrame.size.width -= kTabSwitcherButtonWidth; 1224 tabFrame.size.width -= kTabSwitcherButtonWidth;
1230 _tabStripView.contentInset = UIEdgeInsetsZero; 1225 _tabStripView.contentInset = UIEdgeInsetsZero;
1231 [_tabSwitcherButtonBackgroundView setHidden:YES]; 1226 [_tabSwitcherButtonBackgroundView setHidden:YES];
1232 } else { 1227 } else {
1233 if (!_tabSwitcherButtonBackgroundView) { 1228 if (!_tabSwitcherButtonBackgroundView) {
1234 _tabSwitcherButtonBackgroundView.reset([[UIImageView alloc] init]); 1229 _tabSwitcherButtonBackgroundView = [[UIImageView alloc] init];
1235 const CGFloat tabStripHeight = _view.frame.size.height; 1230 const CGFloat tabStripHeight = _view.frame.size.height;
1236 const CGRect backgroundViewFrame = CGRectMake( 1231 const CGRect backgroundViewFrame = CGRectMake(
1237 CGRectGetMaxX(_view.frame) - kTabSwitcherButtonBackgroundWidth, 0.0, 1232 CGRectGetMaxX(_view.frame) - kTabSwitcherButtonBackgroundWidth, 0.0,
1238 kTabSwitcherButtonBackgroundWidth, tabStripHeight); 1233 kTabSwitcherButtonBackgroundWidth, tabStripHeight);
1239 [_tabSwitcherButtonBackgroundView setFrame:backgroundViewFrame]; 1234 [_tabSwitcherButtonBackgroundView setFrame:backgroundViewFrame];
1240 [_tabSwitcherButtonBackgroundView 1235 [_tabSwitcherButtonBackgroundView
1241 setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; 1236 setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
1242 UIImage* backgroundTabSwitcherImage = 1237 UIImage* backgroundTabSwitcherImage =
1243 [UIImage imageNamed:@"tabstrip_toggle_button_gradient"]; 1238 [UIImage imageNamed:@"tabstrip_toggle_button_gradient"];
1244 [_tabSwitcherButtonBackgroundView setImage:backgroundTabSwitcherImage]; 1239 [_tabSwitcherButtonBackgroundView setImage:backgroundTabSwitcherImage];
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 } 1543 }
1549 1544
1550 @end 1545 @end
1551 1546
1552 #pragma mark - TabSwitcherAnimation 1547 #pragma mark - TabSwitcherAnimation
1553 1548
1554 @implementation TabStripController (TabSwitcherAnimation) 1549 @implementation TabStripController (TabSwitcherAnimation)
1555 1550
1556 - (TabSwitcherTabStripPlaceholderView*)placeholderView { 1551 - (TabSwitcherTabStripPlaceholderView*)placeholderView {
1557 TabSwitcherTabStripPlaceholderView* placeholderView = 1552 TabSwitcherTabStripPlaceholderView* placeholderView =
1558 [[[TabSwitcherTabStripPlaceholderView alloc] 1553 [[TabSwitcherTabStripPlaceholderView alloc]
1559 initWithFrame:self.view.bounds] autorelease]; 1554 initWithFrame:self.view.bounds];
1560 CGFloat xOffset = [_tabStripView contentOffset].x; 1555 CGFloat xOffset = [_tabStripView contentOffset].x;
1561 UIView* previousView = nil; 1556 UIView* previousView = nil;
1562 const NSUInteger selectedModelIndex = 1557 const NSUInteger selectedModelIndex =
1563 [_tabModel indexOfTab:[_tabModel currentTab]]; 1558 [_tabModel indexOfTab:[_tabModel currentTab]];
1564 const NSUInteger selectedArrayIndex = 1559 const NSUInteger selectedArrayIndex =
1565 [self indexForModelIndex:selectedModelIndex]; 1560 [self indexForModelIndex:selectedModelIndex];
1566 [self updateContentSizeAndRepositionViews]; 1561 [self updateContentSizeAndRepositionViews];
1567 [self layoutTabStripSubviews]; 1562 [self layoutTabStripSubviews];
1568 for (NSUInteger tabArrayIndex = 0; tabArrayIndex < [_tabArray count]; 1563 for (NSUInteger tabArrayIndex = 0; tabArrayIndex < [_tabArray count];
1569 ++tabArrayIndex) { 1564 ++tabArrayIndex) {
(...skipping 22 matching lines...) Expand all
1592 1587
1593 @implementation TabStripController (Testing) 1588 @implementation TabStripController (Testing)
1594 1589
1595 - (TabView*)existingTabViewForTab:(Tab*)tab { 1590 - (TabView*)existingTabViewForTab:(Tab*)tab {
1596 NSUInteger tabIndex = [_tabModel indexOfTab:tab]; 1591 NSUInteger tabIndex = [_tabModel indexOfTab:tab];
1597 NSUInteger tabViewIndex = [self indexForModelIndex:tabIndex]; 1592 NSUInteger tabViewIndex = [self indexForModelIndex:tabIndex];
1598 return [_tabArray objectAtIndex:tabViewIndex]; 1593 return [_tabArray objectAtIndex:tabViewIndex];
1599 } 1594 }
1600 1595
1601 @end 1596 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/tabs/BUILD.gn ('k') | ios/chrome/browser/ui/tabs/tab_strip_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698