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

Side by Side Diff: ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm

Issue 2941043002: [ObjC ARC] Converts ios/chrome/browser/ui/tools_menu:tools_menu to ARC. (Closed)
Patch Set: manual review. 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/tools_menu/tools_menu_view_controller.h" 5 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #import "base/ios/weak_nsobject.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/mac/objc_property_releaser.h"
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
15 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
16 #include "components/strings/grit/components_strings.h" 13 #include "components/strings/grit/components_strings.h"
17 #include "ios/chrome/browser/experimental_flags.h" 14 #include "ios/chrome/browser/experimental_flags.h"
18 #import "ios/chrome/browser/ui/animation_util.h" 15 #import "ios/chrome/browser/ui/animation_util.h"
19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 16 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 17 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
21 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_deleg ate.h" 18 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_deleg ate.h"
22 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h" 19 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h"
23 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h" 20 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h"
24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" 21 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h"
25 #import "ios/chrome/browser/ui/tools_menu/tools_menu_model.h" 22 #import "ios/chrome/browser/ui/tools_menu/tools_menu_model.h"
26 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" 23 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h"
27 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h"
28 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" 25 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h"
29 #include "ios/chrome/browser/ui/ui_util.h" 26 #include "ios/chrome/browser/ui/ui_util.h"
30 #import "ios/chrome/browser/ui/uikit_ui_util.h" 27 #import "ios/chrome/browser/ui/uikit_ui_util.h"
31 #import "ios/chrome/common/material_timing.h" 28 #import "ios/chrome/common/material_timing.h"
32 #include "ios/chrome/grit/ios_strings.h" 29 #include "ios/chrome/grit/ios_strings.h"
33 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 30 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
34 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider .h" 31 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider .h"
35 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" 32 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h"
36 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material Ink.h" 33 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material Ink.h"
37 #include "ios/web/public/user_agent.h" 34 #include "ios/web/public/user_agent.h"
38 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/l10n/l10n_util_mac.h" 36 #include "ui/base/l10n/l10n_util_mac.h"
37
38 #if !defined(__has_feature) || !__has_feature(objc_arc)
39 #error "This file requires ARC support."
40 #endif
41
40 using ios::material::TimingFunction; 42 using ios::material::TimingFunction;
41 43
42 namespace { 44 namespace {
43 45
44 // Time for ink to fade into view. 46 // Time for ink to fade into view.
45 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; 47 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15;
46 48
47 static const CGFloat kMenuItemHeight = 48; 49 static const CGFloat kMenuItemHeight = 48;
48 50
49 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; 51 static NSString* const kToolsItemCellID = @"ToolsItemCellID";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 _touchEndPoint = [[touches anyObject] locationInView:self]; 100 _touchEndPoint = [[touches anyObject] locationInView:self];
99 [super touchesEnded:touches withEvent:event]; 101 [super touchesEnded:touches withEvent:event];
100 } 102 }
101 103
102 @end 104 @end
103 105
104 // Class Extension for private methods. 106 // Class Extension for private methods.
105 @interface ToolsMenuViewController ()<UICollectionViewDelegateFlowLayout, 107 @interface ToolsMenuViewController ()<UICollectionViewDelegateFlowLayout,
106 UICollectionViewDataSource, 108 UICollectionViewDataSource,
107 ReadingListMenuNotificationDelegate> { 109 ReadingListMenuNotificationDelegate> {
108 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController;
109 BOOL _waitForInk; 110 BOOL _waitForInk;
110 // Weak pointer to ReadingListMenuNotifier, used to set the starting values 111 // Weak pointer to ReadingListMenuNotifier, used to set the starting values
111 // for the reading list badge. 112 // for the reading list badge.
112 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; 113 __weak ReadingListMenuNotifier* _readingListMenuNotifier;
113 } 114 }
114 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; 115 @property(nonatomic, strong) ToolsMenuCollectionView* menuView;
115 @property(nonatomic, retain) MDCInkView* touchFeedbackView; 116 @property(nonatomic, strong) MDCInkView* touchFeedbackView;
116 @property(nonatomic, assign) ToolbarType toolbarType; 117 @property(nonatomic, assign) ToolbarType toolbarType;
117 // Populated by the configuration object in |initializeMenuWithConfiguration:| 118 // Populated by the configuration object in |initializeMenuWithConfiguration:|
118 // stores the time this view controller was requested by the user for the 119 // stores the time this view controller was requested by the user for the
119 // reporting of metrics. 120 // reporting of metrics.
120 @property(nonatomic, assign) NSTimeInterval requestStartTime; 121 @property(nonatomic, assign) NSTimeInterval requestStartTime;
121 122
122 // Returns the reading list cell. 123 // Returns the reading list cell.
123 - (ReadingListMenuViewCell*)readingListCell; 124 - (ReadingListMenuViewCell*)readingListCell;
124 @end 125 @end
125 126
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 211
211 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; 212 ToolsMenuViewToolsCell* toolsCell = [self toolsCell];
212 [[toolsCell stopButton] setHidden:!isTabLoading]; 213 [[toolsCell stopButton] setHidden:!isTabLoading];
213 [[toolsCell reloadButton] setHidden:isTabLoading]; 214 [[toolsCell reloadButton] setHidden:isTabLoading];
214 } 215 }
215 216
216 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { 217 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration {
217 self.requestStartTime = configuration.requestStartTime; 218 self.requestStartTime = configuration.requestStartTime;
218 219
219 if (configuration.readingListMenuNotifier) { 220 if (configuration.readingListMenuNotifier) {
220 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); 221 _readingListMenuNotifier = configuration.readingListMenuNotifier;
221 [configuration.readingListMenuNotifier setDelegate:self]; 222 [configuration.readingListMenuNotifier setDelegate:self];
222 } 223 }
223 224
224 if (IsIPadIdiom()) { 225 if (IsIPadIdiom()) {
225 _toolbarType = 226 _toolbarType =
226 configuration.hasNoOpenedTabs 227 configuration.hasNoOpenedTabs
227 ? ToolbarTypeNoTabsiPad 228 ? ToolbarTypeNoTabsiPad
228 : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone); 229 : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone);
229 } else { 230 } else {
230 // kOptionInTabSwitcher option must be enabled on iPhone with 231 // kOptionInTabSwitcher option must be enabled on iPhone with
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 NSInteger item = [path item]; 325 NSInteger item = [path item];
325 326
326 if (_toolbarType == ToolbarTypeWebiPhone) 327 if (_toolbarType == ToolbarTypeWebiPhone)
327 --item; 328 --item;
328 329
329 return item; 330 return item;
330 } 331 }
331 332
332 #pragma mark - UIViewController Overrides 333 #pragma mark - UIViewController Overrides
333 334
334 - (instancetype)initWithNibName:(NSString*)nibNameOrNil
335 bundle:(NSBundle*)nibBundleOrNil {
336 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
337 if (self)
338 [self commonInitialization];
339
340 return self;
341 }
342
343 - (instancetype)initWithCoder:(NSCoder*)aDecoder {
344 self = [super initWithCoder:aDecoder];
345 if (self)
346 [self commonInitialization];
347
348 return self;
349 }
350
351 - (void)commonInitialization {
352 _propertyReleaser_ToolsMenuViewController.Init(
353 self, [ToolsMenuViewController class]);
354 _readingListMenuNotifier.reset();
355 }
356
357 - (void)loadView { 335 - (void)loadView {
358 [super loadView]; 336 [super loadView];
359 337
360 UIView* rootView = [self view]; 338 UIView* rootView = [self view];
361 [rootView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | 339 [rootView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
362 UIViewAutoresizingFlexibleWidth]; 340 UIViewAutoresizingFlexibleWidth];
363 [rootView setBackgroundColor:[UIColor whiteColor]]; 341 [rootView setBackgroundColor:[UIColor whiteColor]];
364 342
365 _touchFeedbackView = [[MDCInkView alloc] initWithFrame:CGRectZero]; 343 _touchFeedbackView = [[MDCInkView alloc] initWithFrame:CGRectZero];
366 344
367 base::scoped_nsobject<UICollectionViewFlowLayout> menuItemsLayout( 345 UICollectionViewFlowLayout* menuItemsLayout =
368 [[UICollectionViewFlowLayout alloc] init]); 346 [[UICollectionViewFlowLayout alloc] init];
369 347
370 _menuView = [[ToolsMenuCollectionView alloc] initWithFrame:[rootView bounds] 348 _menuView = [[ToolsMenuCollectionView alloc] initWithFrame:[rootView bounds]
371 collectionViewLayout:menuItemsLayout]; 349 collectionViewLayout:menuItemsLayout];
372 [_menuView setAccessibilityLabel:l10n_util::GetNSString(IDS_IOS_TOOLS_MENU)]; 350 [_menuView setAccessibilityLabel:l10n_util::GetNSString(IDS_IOS_TOOLS_MENU)];
373 [_menuView setAccessibilityIdentifier:kToolsMenuTableViewId]; 351 [_menuView setAccessibilityIdentifier:kToolsMenuTableViewId];
374 [_menuView setTranslatesAutoresizingMaskIntoConstraints:NO]; 352 [_menuView setTranslatesAutoresizingMaskIntoConstraints:NO];
375 [_menuView setBackgroundColor:[UIColor whiteColor]]; 353 [_menuView setBackgroundColor:[UIColor whiteColor]];
376 [_menuView setDataSource:self]; 354 [_menuView setDataSource:self];
377 [_menuView setDelegate:self]; 355 [_menuView setDelegate:self];
378 [_menuView setOpaque:YES]; 356 [_menuView setOpaque:YES];
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 // this once. 435 // this once.
458 self.requestStartTime = 0; 436 self.requestStartTime = 0;
459 } 437 }
460 438
461 }]; 439 }];
462 AnimateInViews([toolsCell allButtons], 10, 0); 440 AnimateInViews([toolsCell allButtons], 10, 0);
463 AnimateInViews(visibleCells, 0, -10); 441 AnimateInViews(visibleCells, 0, -10);
464 [CATransaction commit]; 442 [CATransaction commit];
465 443
466 [[self readingListCell] 444 [[self readingListCell]
467 updateBadgeCount:_readingListMenuNotifier.get().readingListUnreadCount 445 updateBadgeCount:_readingListMenuNotifier.readingListUnreadCount
468 animated:YES]; 446 animated:YES];
469 [[self readingListCell] 447 [[self readingListCell]
470 updateSeenState:_readingListMenuNotifier.get().readingListUnseenItemsExist 448 updateSeenState:_readingListMenuNotifier.readingListUnseenItemsExist
471 animated:YES]; 449 animated:YES];
472 } 450 }
473 451
474 - (void)hideContent { 452 - (void)hideContent {
475 _menuView.alpha = 0; 453 _menuView.alpha = 0;
476 454
477 // Remove the target/action for touching the buttons. VoiceOver may hold on 455 // Remove the target/action for touching the buttons. VoiceOver may hold on
478 // to these buttons after |self| has been released, causing a crash if a 456 // to these buttons after |self| has been released, causing a crash if a
479 // button is activated (see http://crbug.com/480974 ). 457 // button is activated (see http://crbug.com/480974 ).
480 UIButton* toolsButton = [[self toolsCell] toolsButton]; 458 UIButton* toolsButton = [[self toolsCell] toolsButton];
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 touchPoint = [view convertPoint:touchPoint toView:_touchFeedbackView]; 514 touchPoint = [view convertPoint:touchPoint toView:_touchFeedbackView];
537 [_touchFeedbackView startTouchBeganAnimationAtPoint:touchPoint 515 [_touchFeedbackView startTouchBeganAnimationAtPoint:touchPoint
538 completion:nil]; 516 completion:nil];
539 } 517 }
540 } 518 }
541 519
542 - (void)collectionView:(ToolsMenuCollectionView*)view 520 - (void)collectionView:(ToolsMenuCollectionView*)view
543 didUnhighlightItemAtIndexPath:(NSIndexPath*)path { 521 didUnhighlightItemAtIndexPath:(NSIndexPath*)path {
544 CGPoint touchPoint = [view touchEndPoint]; 522 CGPoint touchPoint = [view touchEndPoint];
545 touchPoint = [view convertPoint:touchPoint toView:_touchFeedbackView]; 523 touchPoint = [view convertPoint:touchPoint toView:_touchFeedbackView];
546 base::WeakNSObject<MDCInkView> inkView(_touchFeedbackView); 524 __weak MDCInkView* inkView = _touchFeedbackView;
547 _waitForInk = YES; 525 _waitForInk = YES;
548 [_touchFeedbackView startTouchEndedAnimationAtPoint:touchPoint 526 [_touchFeedbackView startTouchEndedAnimationAtPoint:touchPoint
549 completion:^{ 527 completion:^{
550 _waitForInk = NO; 528 _waitForInk = NO;
551 [inkView removeFromSuperview]; 529 [inkView removeFromSuperview];
552 }]; 530 }];
553 } 531 }
554 532
555 - (BOOL)collectionView:(UICollectionView*)view 533 - (BOOL)collectionView:(UICollectionView*)view
556 shouldSelectItemAtIndexPath:(NSIndexPath*)path { 534 shouldSelectItemAtIndexPath:(NSIndexPath*)path {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 612
635 - (void)unreadCountChanged:(NSInteger)unreadCount { 613 - (void)unreadCountChanged:(NSInteger)unreadCount {
636 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; 614 [[self readingListCell] updateBadgeCount:unreadCount animated:YES];
637 } 615 }
638 616
639 - (void)unseenStateChanged:(BOOL)unseenItemsExist { 617 - (void)unseenStateChanged:(BOOL)unseenItemsExist {
640 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; 618 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES];
641 } 619 }
642 620
643 @end 621 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698