OLD | NEW |
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/stack_view/stack_view_controller.h" | 5 #import "ios/chrome/browser/ui/stack_view/stack_view_controller.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
11 #include <limits> | 11 #include <limits> |
12 | 12 |
13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
14 #import "base/ios/block_types.h" | 14 #import "base/ios/block_types.h" |
| 15 #import "base/ios/weak_nsobject.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #import "base/mac/bundle_locations.h" | 17 #import "base/mac/bundle_locations.h" |
17 #import "base/mac/foundation_util.h" | 18 #import "base/mac/foundation_util.h" |
18 | 19 #import "base/mac/objc_property_releaser.h" |
19 #include "base/mac/scoped_block.h" | 20 #include "base/mac/scoped_block.h" |
| 21 #import "base/mac/scoped_nsobject.h" |
20 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
21 #include "base/metrics/user_metrics.h" | 23 #include "base/metrics/user_metrics.h" |
22 #include "base/metrics/user_metrics_action.h" | 24 #include "base/metrics/user_metrics_action.h" |
23 #include "base/strings/sys_string_conversions.h" | 25 #include "base/strings/sys_string_conversions.h" |
24 #include "ios/chrome/browser/chrome_url_constants.h" | 26 #include "ios/chrome/browser/chrome_url_constants.h" |
25 #include "ios/chrome/browser/experimental_flags.h" | 27 #include "ios/chrome/browser/experimental_flags.h" |
26 #import "ios/chrome/browser/tabs/tab.h" | 28 #import "ios/chrome/browser/tabs/tab.h" |
27 #import "ios/chrome/browser/tabs/tab_model.h" | 29 #import "ios/chrome/browser/tabs/tab_model.h" |
28 #import "ios/chrome/browser/tabs/tab_model_observer.h" | 30 #import "ios/chrome/browser/tabs/tab_model_observer.h" |
29 #import "ios/chrome/browser/ui/animation_util.h" | 31 #import "ios/chrome/browser/ui/animation_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
49 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" | 51 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
50 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" | 52 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" |
51 #import "ios/chrome/browser/ui/ui_util.h" | 53 #import "ios/chrome/browser/ui/ui_util.h" |
52 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 54 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
53 #import "ios/chrome/common/material_timing.h" | 55 #import "ios/chrome/common/material_timing.h" |
54 #include "ios/chrome/grit/ios_strings.h" | 56 #include "ios/chrome/grit/ios_strings.h" |
55 #include "ios/web/public/referrer.h" | 57 #include "ios/web/public/referrer.h" |
56 #import "net/base/mac/url_conversions.h" | 58 #import "net/base/mac/url_conversions.h" |
57 #include "ui/base/l10n/l10n_util.h" | 59 #include "ui/base/l10n/l10n_util.h" |
58 | 60 |
59 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
60 #error "This file requires ARC support." | |
61 #endif | |
62 | |
63 using base::UserMetricsAction; | 61 using base::UserMetricsAction; |
64 | 62 |
65 // To obtain scroll behavior, places the card stacks' display views within a | 63 // To obtain scroll behavior, places the card stacks' display views within a |
66 // UIScrollView container. The container is used only as a driver of scroll | 64 // UIScrollView container. The container is used only as a driver of scroll |
67 // events. To avoid the finite size of the container from impacting scrolling, | 65 // events. To avoid the finite size of the container from impacting scrolling, |
68 // (1) the container is made large enough that it cannot be scrolled to a | 66 // (1) the container is made large enough that it cannot be scrolled to a |
69 // boundary point without the user having first fully scrolled the card stack | 67 // boundary point without the user having first fully scrolled the card stack |
70 // in that direction, and (2) after scroll events, the container's scroll | 68 // in that direction, and (2) after scroll events, the container's scroll |
71 // offset is recentered if necessary. | 69 // offset is recentered if necessary. |
72 | 70 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // the end stack as appropriate. If the element is in the middle of a stack, fan | 434 // the end stack as appropriate. If the element is in the middle of a stack, fan |
437 // outcards from its card's index. | 435 // outcards from its card's index. |
438 - (void)accessibilityFocusedOnElement:(id)element; | 436 - (void)accessibilityFocusedOnElement:(id)element; |
439 | 437 |
440 // Determine the center of |sender| if it's a view or a toolbar item and store. | 438 // Determine the center of |sender| if it's a view or a toolbar item and store. |
441 - (void)setLastTapPoint:(id)sender; | 439 - (void)setLastTapPoint:(id)sender; |
442 | 440 |
443 @end | 441 @end |
444 | 442 |
445 @implementation StackViewController { | 443 @implementation StackViewController { |
446 UIScrollView* _scrollView; | 444 base::scoped_nsobject<UIScrollView> _scrollView; |
447 // The view containing the stack view's background. | 445 // The view containing the stack view's background. |
448 UIView* _backgroundView; | 446 base::scoped_nsobject<UIView> _backgroundView; |
449 // The main card set. | 447 // The main card set. |
450 CardSet* _mainCardSet; | 448 base::scoped_nsobject<CardSet> _mainCardSet; |
451 // The off-the-record card set. | 449 // The off-the-record card set. |
452 CardSet* _otrCardSet; | 450 base::scoped_nsobject<CardSet> _otrCardSet; |
453 // The currently active card set; one of _mainCardSet or _otrCardSet. | 451 // The currently active card set; one of _mainCardSet or _otrCardSet. |
454 __weak CardSet* _activeCardSet; | 452 CardSet* _activeCardSet; // weak |
455 __weak id<TabSwitcherDelegate> _delegate; | 453 id<TabSwitcherDelegate> _delegate; // weak |
456 __weak id<StackViewControllerTestDelegate> _testDelegate; | 454 id<StackViewControllerTestDelegate> _testDelegate; // weak |
457 // Controller for the stack view toolbar. | 455 // Controller for the stack view toolbar. |
458 StackViewToolbarController* _toolbarController; | 456 base::scoped_nsobject<StackViewToolbarController> _toolbarController; |
459 // The size of a card at the time the stack was first shown. | 457 // The size of a card at the time the stack was first shown. |
460 CGSize _initialCardSize; | 458 CGSize _initialCardSize; |
461 // The previous orientation of the interface. | 459 // The previous orientation of the interface. |
462 UIInterfaceOrientation _lastInterfaceOrientation; | 460 UIInterfaceOrientation _lastInterfaceOrientation; |
463 // Gesture recognizer to catch taps on the inactive stack. | 461 // Gesture recognizer to catch taps on the inactive stack. |
464 UITapGestureRecognizer* _modeSwitchRecognizer; | 462 base::scoped_nsobject<UITapGestureRecognizer> _modeSwitchRecognizer; |
465 // Gesture recognizer to catch pinches in the active scroll view. | 463 // Gesture recognizer to catch pinches in the active scroll view. |
466 UIGestureRecognizer* _pinchRecognizer; | 464 base::scoped_nsobject<UIGestureRecognizer> _pinchRecognizer; |
467 // Gesture recognizer to catch swipes to switch decks/dismiss cards. | 465 // Gesture recognizer to catch swipes to switch decks/dismiss cards. |
468 UIGestureRecognizer* _swipeGestureRecognizer; | 466 base::scoped_nsobject<UIGestureRecognizer> _swipeGestureRecognizer; |
469 // Gesture recognizer that determines whether an ambiguous swipe action | 467 // Gesture recognizer that determines whether an ambiguous swipe action |
470 // (i.e., a swipe on an active card in the direction that would cause a deck | 468 // (i.e., a swipe on an active card in the direction that would cause a deck |
471 // change) should trigger a change of decks or a card dismissal. | 469 // change) should trigger a change of decks or a card dismissal. |
472 UILongPressGestureRecognizer* _swipeDismissesCardRecognizer; | 470 base::scoped_nsobject<UILongPressGestureRecognizer> |
| 471 _swipeDismissesCardRecognizer; |
473 // Tracks the parameters of gesture-related events. | 472 // Tracks the parameters of gesture-related events. |
474 GestureStateTracker* _gestureStateTracker; | 473 base::scoped_nsobject<GestureStateTracker> _gestureStateTracker; |
475 // If |YES|, callbacks to |scrollViewDidScroll:| do not trigger scrolling. | 474 // If |YES|, callbacks to |scrollViewDidScroll:| do not trigger scrolling. |
476 // Default is |NO|. | 475 // Default is |NO|. |
477 BOOL _ignoreScrollCallbacks; | 476 BOOL _ignoreScrollCallbacks; |
478 // The scroll view's pan gesture recognizer. | 477 // The scroll view's pan gesture recognizer. |
479 __weak UIPanGestureRecognizer* _scrollGestureRecognizer; | 478 UIPanGestureRecognizer* _scrollGestureRecognizer; // weak |
480 // Because the removal of the StackCard during a swipe happens in a callback, | 479 // Because the removal of the StackCard during a swipe happens in a callback, |
481 // track which direction the animation should dismiss with. | 480 // track which direction the animation should dismiss with. |
482 // |_reverseDismissCard| is only set when the dismissal happens in reverse. | 481 // |_reverseDismissCard| is only set when the dismissal happens in reverse. |
483 StackCard* _reverseDismissCard; | 482 base::scoped_nsobject<StackCard> _reverseDismissCard; |
484 // |YES| if the stack view is in the process of being dismissed. | 483 // |YES| if the stack view is in the process of being dismissed. |
485 BOOL _isBeingDismissed; | 484 BOOL _isBeingDismissed; |
486 // |YES| if the stack view is currently active. | 485 // |YES| if the stack view is currently active. |
487 BOOL _isActive; | 486 BOOL _isActive; |
488 // Records whether a memory warning occurred in the current session. | 487 // Records whether a memory warning occurred in the current session. |
489 BOOL _receivedMemoryWarningInSession; | 488 BOOL _receivedMemoryWarningInSession; |
490 // |YES| if there is card set animation being processed. For testing only. | 489 // |YES| if there is card set animation being processed. For testing only. |
491 // Save last touch point used by new tab animation. | 490 // Save last touch point used by new tab animation. |
492 CGPoint _lastTapPoint; | 491 CGPoint _lastTapPoint; |
| 492 |
| 493 base::mac::ObjCPropertyReleaser _propertyReleaserStackViewController; |
493 } | 494 } |
494 | 495 |
495 @synthesize activeCardSet = _activeCardSet; | 496 @synthesize activeCardSet = _activeCardSet; |
496 @synthesize delegate = _delegate; | 497 @synthesize delegate = _delegate; |
497 @synthesize dummyToolbarBackgroundView = _dummyToolbarBackgroundView; | 498 @synthesize dummyToolbarBackgroundView = _dummyToolbarBackgroundView; |
498 @synthesize inActiveDeckChangeAnimation = _inActiveDeckChangeAnimation; | 499 @synthesize inActiveDeckChangeAnimation = _inActiveDeckChangeAnimation; |
499 @synthesize testDelegate = _testDelegate; | 500 @synthesize testDelegate = _testDelegate; |
500 @synthesize transitionStyle = _transitionStyle; | 501 @synthesize transitionStyle = _transitionStyle; |
501 @synthesize transitionTappedCard = _transitionTappedCard; | 502 @synthesize transitionTappedCard = _transitionTappedCard; |
502 @synthesize transitionToolbarController = _transitionToolbarController; | 503 @synthesize transitionToolbarController = _transitionToolbarController; |
503 @synthesize transitionToolbarFrame = _transitionToolbarFrame; | 504 @synthesize transitionToolbarFrame = _transitionToolbarFrame; |
504 @synthesize transitionToolbarOwner = _transitionToolbarOwner; | 505 @synthesize transitionToolbarOwner = _transitionToolbarOwner; |
505 @synthesize transitionWasCancelled = _transitionWasCancelled; | 506 @synthesize transitionWasCancelled = _transitionWasCancelled; |
506 | 507 |
507 - (instancetype)initWithMainCardSet:(CardSet*)mainCardSet | 508 - (instancetype)initWithMainCardSet:(CardSet*)mainCardSet |
508 otrCardSet:(CardSet*)otrCardSet | 509 otrCardSet:(CardSet*)otrCardSet |
509 activeCardSet:(CardSet*)activeCardSet { | 510 activeCardSet:(CardSet*)activeCardSet { |
510 DCHECK(mainCardSet); | 511 DCHECK(mainCardSet); |
511 DCHECK(otrCardSet); | 512 DCHECK(otrCardSet); |
512 DCHECK(activeCardSet == otrCardSet || activeCardSet == mainCardSet); | 513 DCHECK(activeCardSet == otrCardSet || activeCardSet == mainCardSet); |
513 self = [super initWithNibName:nil bundle:nil]; | 514 self = [super initWithNibName:nil bundle:nil]; |
514 if (self) { | 515 if (self) { |
| 516 _propertyReleaserStackViewController.Init(self, |
| 517 [StackViewController class]); |
515 [self setUpWithMainCardSet:mainCardSet | 518 [self setUpWithMainCardSet:mainCardSet |
516 otrCardSet:otrCardSet | 519 otrCardSet:otrCardSet |
517 activeCardSet:activeCardSet]; | 520 activeCardSet:activeCardSet]; |
518 _swipeDismissesCardRecognizer = [[UILongPressGestureRecognizer alloc] | 521 _swipeDismissesCardRecognizer.reset([[UILongPressGestureRecognizer alloc] |
519 initWithTarget:self | 522 initWithTarget:self |
520 action:@selector(handleLongPressFrom:)]; | 523 action:@selector(handleLongPressFrom:)]); |
521 [_swipeDismissesCardRecognizer | 524 [_swipeDismissesCardRecognizer |
522 setMinimumPressDuration: | 525 setMinimumPressDuration: |
523 kPressDurationForAmbiguousSwipeToTriggerDismissal]; | 526 kPressDurationForAmbiguousSwipeToTriggerDismissal]; |
524 [_swipeDismissesCardRecognizer setDelegate:self]; | 527 [_swipeDismissesCardRecognizer setDelegate:self]; |
525 _pinchRecognizer = [[CardStackPinchGestureRecognizer alloc] | 528 _pinchRecognizer.reset([[CardStackPinchGestureRecognizer alloc] |
526 initWithTarget:self | 529 initWithTarget:self |
527 action:@selector(handlePinchFrom:)]; | 530 action:@selector(handlePinchFrom:)]); |
528 [_pinchRecognizer setDelegate:self]; | 531 [_pinchRecognizer setDelegate:self]; |
529 _modeSwitchRecognizer = [[UITapGestureRecognizer alloc] | 532 _modeSwitchRecognizer.reset([[UITapGestureRecognizer alloc] |
530 initWithTarget:self | 533 initWithTarget:self |
531 action:@selector(handleTapFrom:)]; | 534 action:@selector(handleTapFrom:)]); |
532 [_modeSwitchRecognizer setDelegate:self]; | 535 [_modeSwitchRecognizer setDelegate:self]; |
533 } | 536 } |
534 return self; | 537 return self; |
535 } | 538 } |
536 | 539 |
537 - (instancetype)initWithMainTabModel:(TabModel*)mainModel | 540 - (instancetype)initWithMainTabModel:(TabModel*)mainModel |
538 otrTabModel:(TabModel*)otrModel | 541 otrTabModel:(TabModel*)otrModel |
539 activeTabModel:(TabModel*)activeModel { | 542 activeTabModel:(TabModel*)activeModel { |
540 DCHECK(mainModel); | 543 DCHECK(mainModel); |
541 DCHECK(otrModel); | 544 DCHECK(otrModel); |
542 DCHECK(activeModel == otrModel || activeModel == mainModel); | 545 DCHECK(activeModel == otrModel || activeModel == mainModel); |
543 CardSet* mainCardSet = [[CardSet alloc] initWithModel:mainModel]; | 546 base::scoped_nsobject<CardSet> mainCardSet( |
544 CardSet* otrCardSet = [[CardSet alloc] initWithModel:otrModel]; | 547 [[CardSet alloc] initWithModel:mainModel]); |
| 548 base::scoped_nsobject<CardSet> otrCardSet( |
| 549 [[CardSet alloc] initWithModel:otrModel]); |
545 CardSet* activeCardSet = | 550 CardSet* activeCardSet = |
546 (activeModel == mainModel) ? mainCardSet : otrCardSet; | 551 (activeModel == mainModel) ? mainCardSet.get() : otrCardSet.get(); |
547 return [self initWithMainCardSet:mainCardSet | 552 return [self initWithMainCardSet:mainCardSet |
548 otrCardSet:otrCardSet | 553 otrCardSet:otrCardSet |
549 activeCardSet:activeCardSet]; | 554 activeCardSet:activeCardSet]; |
550 } | 555 } |
551 | 556 |
552 - (instancetype)initWithNibName:(NSString*)nibNameOrNil | 557 - (instancetype)initWithNibName:(NSString*)nibNameOrNil |
553 bundle:(NSBundle*)nibBundleOrNil { | 558 bundle:(NSBundle*)nibBundleOrNil { |
554 NOTREACHED(); | 559 NOTREACHED(); |
555 return nil; | 560 return nil; |
556 } | 561 } |
557 | 562 |
558 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 563 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
559 NOTREACHED(); | 564 NOTREACHED(); |
560 return nil; | 565 return nil; |
561 } | 566 } |
562 | 567 |
563 - (void)setUpWithMainCardSet:(CardSet*)mainCardSet | 568 - (void)setUpWithMainCardSet:(CardSet*)mainCardSet |
564 otrCardSet:(CardSet*)otrCardSet | 569 otrCardSet:(CardSet*)otrCardSet |
565 activeCardSet:(CardSet*)activeCardSet { | 570 activeCardSet:(CardSet*)activeCardSet { |
566 _mainCardSet = mainCardSet; | 571 _mainCardSet.reset([mainCardSet retain]); |
567 _otrCardSet = otrCardSet; | 572 _otrCardSet.reset([otrCardSet retain]); |
568 if (experimental_flags::IsLRUSnapshotCacheEnabled()) { | 573 if (experimental_flags::IsLRUSnapshotCacheEnabled()) { |
569 [_mainCardSet setKeepOnlyVisibleCardViewsAlive:YES]; | 574 [_mainCardSet setKeepOnlyVisibleCardViewsAlive:YES]; |
570 [_otrCardSet setKeepOnlyVisibleCardViewsAlive:YES]; | 575 [_otrCardSet setKeepOnlyVisibleCardViewsAlive:YES]; |
571 } | 576 } |
572 _activeCardSet = (activeCardSet == mainCardSet) ? mainCardSet : otrCardSet; | 577 _activeCardSet = (activeCardSet == mainCardSet) ? mainCardSet : otrCardSet; |
573 _gestureStateTracker = [[GestureStateTracker alloc] init]; | 578 _gestureStateTracker.reset([[GestureStateTracker alloc] init]); |
574 _pinchRecognizer = [[CardStackPinchGestureRecognizer alloc] | 579 _pinchRecognizer.reset([[CardStackPinchGestureRecognizer alloc] |
575 initWithTarget:self | 580 initWithTarget:self |
576 action:@selector(handlePinchFrom:)]; | 581 action:@selector(handlePinchFrom:)]); |
577 [_pinchRecognizer setDelegate:self]; | 582 [_pinchRecognizer setDelegate:self]; |
578 _modeSwitchRecognizer = | 583 _modeSwitchRecognizer.reset([[UITapGestureRecognizer alloc] |
579 [[UITapGestureRecognizer alloc] initWithTarget:self | 584 initWithTarget:self |
580 action:@selector(handleTapFrom:)]; | 585 action:@selector(handleTapFrom:)]); |
581 [_modeSwitchRecognizer setDelegate:self]; | 586 [_modeSwitchRecognizer setDelegate:self]; |
582 } | 587 } |
583 | 588 |
584 - (void)restoreInternalStateWithMainTabModel:(TabModel*)mainModel | 589 - (void)restoreInternalStateWithMainTabModel:(TabModel*)mainModel |
585 otrTabModel:(TabModel*)otrModel | 590 otrTabModel:(TabModel*)otrModel |
586 activeTabModel:(TabModel*)activeModel { | 591 activeTabModel:(TabModel*)activeModel { |
587 DCHECK(mainModel); | 592 DCHECK(mainModel); |
588 DCHECK(otrModel); | 593 DCHECK(otrModel); |
589 DCHECK(activeModel == otrModel || activeModel == mainModel); | 594 DCHECK(activeModel == otrModel || activeModel == mainModel); |
590 DCHECK(!_isActive); | 595 DCHECK(!_isActive); |
591 CardSet* mainCardSet = [[CardSet alloc] initWithModel:mainModel]; | 596 base::scoped_nsobject<CardSet> mainCardSet( |
592 CardSet* otrCardSet = [[CardSet alloc] initWithModel:otrModel]; | 597 [[CardSet alloc] initWithModel:mainModel]); |
| 598 base::scoped_nsobject<CardSet> otrCardSet( |
| 599 [[CardSet alloc] initWithModel:otrModel]); |
593 CardSet* activeCardSet = | 600 CardSet* activeCardSet = |
594 (activeModel == mainModel) ? mainCardSet : otrCardSet; | 601 (activeModel == mainModel) ? mainCardSet.get() : otrCardSet.get(); |
595 [self setUpWithMainCardSet:mainCardSet | 602 [self setUpWithMainCardSet:mainCardSet |
596 otrCardSet:otrCardSet | 603 otrCardSet:otrCardSet |
597 activeCardSet:activeCardSet]; | 604 activeCardSet:activeCardSet]; |
598 | 605 |
599 // If the view is not currently loaded, do not adjust its size or add | 606 // If the view is not currently loaded, do not adjust its size or add |
600 // gesture recognizers. That work will be done in |viewDidLoad|. | 607 // gesture recognizers. That work will be done in |viewDidLoad|. |
601 if ([self isViewLoaded]) { | 608 if ([self isViewLoaded]) { |
602 [self prepareForDisplay]; | 609 [self prepareForDisplay]; |
603 // The delegate is set to nil when the stack view is dismissed. | 610 // The delegate is set to nil when the stack view is dismissed. |
604 [_scrollView setDelegate:self]; | 611 [_scrollView setDelegate:self]; |
(...skipping 11 matching lines...) Expand all Loading... |
616 - (void)clearInternalState { | 623 - (void)clearInternalState { |
617 DCHECK(!_isActive); | 624 DCHECK(!_isActive); |
618 [[_mainCardSet displayView] removeFromSuperview]; | 625 [[_mainCardSet displayView] removeFromSuperview]; |
619 [[_otrCardSet displayView] removeFromSuperview]; | 626 [[_otrCardSet displayView] removeFromSuperview]; |
620 | 627 |
621 // Only deregister from the specific notifications for which this class | 628 // Only deregister from the specific notifications for which this class |
622 // registered. Do not use the blanket |removeObserver|, otherwise the low | 629 // registered. Do not use the blanket |removeObserver|, otherwise the low |
623 // memory notification is not received and the view is never unloaded. | 630 // memory notification is not received and the view is never unloaded. |
624 [self deregisterForNotifications]; | 631 [self deregisterForNotifications]; |
625 | 632 |
626 _mainCardSet = nil; | 633 _mainCardSet.reset(); |
627 _otrCardSet = nil; | 634 _otrCardSet.reset(); |
628 _activeCardSet = nil; | 635 _activeCardSet = nil; |
629 | 636 |
630 // Remove gesture recognizers and notifications. | 637 // Remove gesture recognizers and notifications. |
631 [self prepareForDismissal]; | 638 [self prepareForDismissal]; |
632 _gestureStateTracker = nil; | 639 _gestureStateTracker.reset(); |
633 _pinchRecognizer = nil; | 640 _pinchRecognizer.reset(); |
634 _modeSwitchRecognizer = nil; | 641 _modeSwitchRecognizer.reset(); |
635 _swipeGestureRecognizer = nil; | 642 _swipeGestureRecognizer.reset(); |
636 | 643 |
637 // The cards need to recompute their sizes the next time they are shown. | 644 // The cards need to recompute their sizes the next time they are shown. |
638 _initialCardSize.height = _initialCardSize.width = 0.0f; | 645 _initialCardSize.height = _initialCardSize.width = 0.0f; |
639 // The scroll view will need to recenter itself relative to its viewport. | 646 // The scroll view will need to recenter itself relative to its viewport. |
640 [_scrollView setContentOffset:CGPointZero]; | 647 [_scrollView setContentOffset:CGPointZero]; |
641 _isBeingDismissed = NO; | 648 _isBeingDismissed = NO; |
642 } | 649 } |
643 | 650 |
644 - (void)viewportSizeWasChanged { | 651 - (void)viewportSizeWasChanged { |
645 [self updateScrollViewContentSize]; | 652 [self updateScrollViewContentSize]; |
(...skipping 16 matching lines...) Expand all Loading... |
662 _ignoreScrollCallbacks = YES; | 669 _ignoreScrollCallbacks = YES; |
663 [_scrollView setContentSize:[self sizeForScrollLength:scrollLength | 670 [_scrollView setContentSize:[self sizeForScrollLength:scrollLength |
664 breadth:scrollBreadth]]; | 671 breadth:scrollBreadth]]; |
665 _ignoreScrollCallbacks = NO; | 672 _ignoreScrollCallbacks = NO; |
666 [self recenterScrollViewIfNecessary]; | 673 [self recenterScrollViewIfNecessary]; |
667 } | 674 } |
668 | 675 |
669 - (void)setUpDisplayViews { | 676 - (void)setUpDisplayViews { |
670 CGRect displayViewFrame = CGRectMake(0, 0, [_scrollView frame].size.width, | 677 CGRect displayViewFrame = CGRectMake(0, 0, [_scrollView frame].size.width, |
671 [_scrollView frame].size.height); | 678 [_scrollView frame].size.height); |
672 UIView* mainDisplayView = [[UIView alloc] initWithFrame:displayViewFrame]; | 679 base::scoped_nsobject<UIView> mainDisplayView( |
| 680 [[UIView alloc] initWithFrame:displayViewFrame]); |
673 [mainDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 681 [mainDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
674 UIViewAutoresizingFlexibleHeight]; | 682 UIViewAutoresizingFlexibleHeight]; |
675 UIView* otrDisplayView = [[UIView alloc] initWithFrame:displayViewFrame]; | 683 base::scoped_nsobject<UIView> otrDisplayView( |
| 684 [[UIView alloc] initWithFrame:displayViewFrame]); |
676 [otrDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 685 [otrDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
677 UIViewAutoresizingFlexibleHeight]; | 686 UIViewAutoresizingFlexibleHeight]; |
678 | 687 |
679 [_scrollView addSubview:mainDisplayView]; | 688 [_scrollView addSubview:mainDisplayView]; |
680 [_scrollView addSubview:otrDisplayView]; | 689 [_scrollView addSubview:otrDisplayView]; |
681 [_mainCardSet setDisplayView:mainDisplayView]; | 690 [_mainCardSet setDisplayView:mainDisplayView]; |
682 [_otrCardSet setDisplayView:otrDisplayView]; | 691 [_otrCardSet setDisplayView:otrDisplayView]; |
683 } | 692 } |
684 | 693 |
685 - (void)prepareForDisplay { | 694 - (void)prepareForDisplay { |
(...skipping 12 matching lines...) Expand all Loading... |
698 : UIInterfaceOrientationLandscapeRight; | 707 : UIInterfaceOrientationLandscapeRight; |
699 } | 708 } |
700 [self registerForNotifications]; | 709 [self registerForNotifications]; |
701 | 710 |
702 // TODO(blundell): Why isn't this recognizer initialized with the | 711 // TODO(blundell): Why isn't this recognizer initialized with the |
703 // pinch and mode switch recognizers? | 712 // pinch and mode switch recognizers? |
704 UIPanGestureRecognizer* panGestureRecognizer = | 713 UIPanGestureRecognizer* panGestureRecognizer = |
705 [[UIPanGestureRecognizer alloc] initWithTarget:self | 714 [[UIPanGestureRecognizer alloc] initWithTarget:self |
706 action:@selector(handlePanFrom:)]; | 715 action:@selector(handlePanFrom:)]; |
707 [panGestureRecognizer setMaximumNumberOfTouches:1]; | 716 [panGestureRecognizer setMaximumNumberOfTouches:1]; |
708 _swipeGestureRecognizer = panGestureRecognizer; | 717 _swipeGestureRecognizer.reset(panGestureRecognizer); |
709 [[self view] addGestureRecognizer:_swipeGestureRecognizer]; | 718 [[self view] addGestureRecognizer:_swipeGestureRecognizer]; |
710 [_swipeGestureRecognizer setDelegate:self]; | 719 [_swipeGestureRecognizer setDelegate:self]; |
711 } | 720 } |
712 | 721 |
713 - (void)loadView { | 722 - (void)loadView { |
714 [super loadView]; | 723 [super loadView]; |
715 | 724 |
716 _backgroundView = [[UIView alloc] initWithFrame:self.view.bounds]; | 725 _backgroundView.reset([[UIView alloc] initWithFrame:self.view.bounds]); |
717 [_backgroundView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | | 726 [_backgroundView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | |
718 UIViewAutoresizingFlexibleWidth)]; | 727 UIViewAutoresizingFlexibleWidth)]; |
719 [self.view addSubview:_backgroundView]; | 728 [self.view addSubview:_backgroundView]; |
720 | 729 |
721 _toolbarController = | 730 _toolbarController.reset( |
722 [[StackViewToolbarController alloc] initWithStackViewToolbar]; | 731 [[StackViewToolbarController alloc] initWithStackViewToolbar]); |
723 CGRect toolbarFrame = [self.view bounds]; | 732 CGRect toolbarFrame = [self.view bounds]; |
724 toolbarFrame.origin.y = CGRectGetMinY([[_toolbarController view] frame]); | 733 toolbarFrame.origin.y = CGRectGetMinY([[_toolbarController view] frame]); |
725 toolbarFrame.size.height = CGRectGetHeight([[_toolbarController view] frame]); | 734 toolbarFrame.size.height = CGRectGetHeight([[_toolbarController view] frame]); |
726 [[_toolbarController view] setFrame:toolbarFrame]; | 735 [[_toolbarController view] setFrame:toolbarFrame]; |
727 [self.view addSubview:[_toolbarController view]]; | 736 [self.view addSubview:[_toolbarController view]]; |
728 [self updateToolbarAppearanceWithAnimation:NO]; | 737 [self updateToolbarAppearanceWithAnimation:NO]; |
729 | 738 |
730 InstallBackgroundInView(_backgroundView); | 739 InstallBackgroundInView(_backgroundView); |
731 | 740 |
732 UIEdgeInsets contentInsets = UIEdgeInsetsMake( | 741 UIEdgeInsets contentInsets = UIEdgeInsetsMake( |
733 toolbarFrame.size.height - kVerticalToolbarOverlap, 0.0, 0.0, 0.0); | 742 toolbarFrame.size.height - kVerticalToolbarOverlap, 0.0, 0.0, 0.0); |
734 CGRect scrollViewFrame = | 743 CGRect scrollViewFrame = |
735 UIEdgeInsetsInsetRect(self.view.bounds, contentInsets); | 744 UIEdgeInsetsInsetRect(self.view.bounds, contentInsets); |
736 _scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame]; | 745 _scrollView.reset([[UIScrollView alloc] initWithFrame:scrollViewFrame]); |
737 [self.view addSubview:_scrollView]; | 746 [self.view addSubview:_scrollView]; |
738 [_scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | | 747 [_scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | |
739 UIViewAutoresizingFlexibleWidth)]; | 748 UIViewAutoresizingFlexibleWidth)]; |
740 [_scrollView setBounces:NO]; | 749 [_scrollView setBounces:NO]; |
741 [_scrollView setScrollsToTop:NO]; | 750 [_scrollView setScrollsToTop:NO]; |
742 [_scrollView setClipsToBounds:NO]; | 751 [_scrollView setClipsToBounds:NO]; |
743 [_scrollView setShowsVerticalScrollIndicator:NO]; | 752 [_scrollView setShowsVerticalScrollIndicator:NO]; |
744 [_scrollView setShowsHorizontalScrollIndicator:NO]; | 753 [_scrollView setShowsHorizontalScrollIndicator:NO]; |
745 [_scrollView setDelegate:self]; | 754 [_scrollView setDelegate:self]; |
746 | 755 |
(...skipping 20 matching lines...) Expand all Loading... |
767 [self setInitialCardSizing]; | 776 [self setInitialCardSizing]; |
768 [self viewportSizeWasChanged]; | 777 [self viewportSizeWasChanged]; |
769 } else { | 778 } else { |
770 [self refreshCardDisplayWithAnimation:NO]; | 779 [self refreshCardDisplayWithAnimation:NO]; |
771 [self updateToolbarAppearanceWithAnimation:NO]; | 780 [self updateToolbarAppearanceWithAnimation:NO]; |
772 } | 781 } |
773 [self preloadCardViewsAsynchronously]; | 782 [self preloadCardViewsAsynchronously]; |
774 | 783 |
775 // Reset the gesture state tracker to clear gesture-related information from | 784 // Reset the gesture state tracker to clear gesture-related information from |
776 // the last time the stack view was shown. | 785 // the last time the stack view was shown. |
777 _gestureStateTracker = [[GestureStateTracker alloc] init]; | 786 _gestureStateTracker.reset([[GestureStateTracker alloc] init]); |
778 | 787 |
779 [super viewWillAppear:animated]; | 788 [super viewWillAppear:animated]; |
780 } | 789 } |
781 | 790 |
782 - (void)refreshCardDisplayWithAnimation:(BOOL)animates { | 791 - (void)refreshCardDisplayWithAnimation:(BOOL)animates { |
783 _lastInterfaceOrientation = GetInterfaceOrientation(); | 792 _lastInterfaceOrientation = GetInterfaceOrientation(); |
784 [self updateDeckOrientationWithAnimation:animates]; | 793 [self updateDeckOrientationWithAnimation:animates]; |
785 [self viewportSizeWasChanged]; | 794 [self viewportSizeWasChanged]; |
786 [_mainCardSet updateCardVisibilities]; | 795 [_mainCardSet updateCardVisibilities]; |
787 [_otrCardSet updateCardVisibilities]; | 796 [_otrCardSet updateCardVisibilities]; |
(...skipping 12 matching lines...) Expand all Loading... |
800 } | 809 } |
801 | 810 |
802 - (void)dealloc { | 811 - (void)dealloc { |
803 [_mainCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; | 812 [_mainCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; |
804 [_otrCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; | 813 [_otrCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; |
805 // Card sets shouldn't have any other references, but nil the observer just | 814 // Card sets shouldn't have any other references, but nil the observer just |
806 // in case one somehow does end up with another ref. | 815 // in case one somehow does end up with another ref. |
807 [_mainCardSet setObserver:nil]; | 816 [_mainCardSet setObserver:nil]; |
808 [_otrCardSet setObserver:nil]; | 817 [_otrCardSet setObserver:nil]; |
809 [self cleanUpViewsAndNotifications]; | 818 [self cleanUpViewsAndNotifications]; |
| 819 [super dealloc]; |
810 } | 820 } |
811 | 821 |
812 // Overridden to always return NO, ensuring that the status bar shows in | 822 // Overridden to always return NO, ensuring that the status bar shows in |
813 // landscape on iOS8. | 823 // landscape on iOS8. |
814 - (BOOL)prefersStatusBarHidden { | 824 - (BOOL)prefersStatusBarHidden { |
815 return NO; | 825 return NO; |
816 } | 826 } |
817 | 827 |
818 // Called when in the foreground and the OS needs more memory. Release as much | 828 // Called when in the foreground and the OS needs more memory. Release as much |
819 // as possible. | 829 // as possible. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 UMA_HISTOGRAM_BOOLEAN("MemoryWarning.OccurredDuringCardStackSession", | 953 UMA_HISTOGRAM_BOOLEAN("MemoryWarning.OccurredDuringCardStackSession", |
944 _receivedMemoryWarningInSession); | 954 _receivedMemoryWarningInSession); |
945 } | 955 } |
946 | 956 |
947 - (void)cleanUpViewsAndNotifications { | 957 - (void)cleanUpViewsAndNotifications { |
948 [_mainCardSet setDisplayView:nil]; | 958 [_mainCardSet setDisplayView:nil]; |
949 [_otrCardSet setDisplayView:nil]; | 959 [_otrCardSet setDisplayView:nil]; |
950 // Stop pre-loading cards. | 960 // Stop pre-loading cards. |
951 [NSObject cancelPreviousPerformRequestsWithTarget:self]; | 961 [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
952 [_scrollView setDelegate:nil]; | 962 [_scrollView setDelegate:nil]; |
953 _scrollView = nil; | 963 _scrollView.reset(); |
954 _backgroundView = nil; | 964 _backgroundView.reset(); |
955 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 965 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
956 } | 966 } |
957 | 967 |
958 - (UIStatusBarStyle)preferredStatusBarStyle { | 968 - (UIStatusBarStyle)preferredStatusBarStyle { |
959 // When dismissing the stack view, the status bar's style is updated when this | 969 // When dismissing the stack view, the status bar's style is updated when this |
960 // view controller is still responsible. If the stack view is dismissing into | 970 // view controller is still responsible. If the stack view is dismissing into |
961 // a non-incognito BVC, the status bar needs to use the default style. | 971 // a non-incognito BVC, the status bar needs to use the default style. |
962 BOOL useDefaultStyle = _isBeingDismissed && ![self isCurrentSetIncognito]; | 972 BOOL useDefaultStyle = _isBeingDismissed && ![self isCurrentSetIncognito]; |
963 return useDefaultStyle ? UIStatusBarStyleDefault | 973 return useDefaultStyle ? UIStatusBarStyleDefault |
964 : UIStatusBarStyleLightContent; | 974 : UIStatusBarStyleLightContent; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 delay += kCascadingCardCloseDelay; | 1070 delay += kCascadingCardCloseDelay; |
1061 } | 1071 } |
1062 } | 1072 } |
1063 | 1073 |
1064 - (void)disableGestureHandlers { | 1074 - (void)disableGestureHandlers { |
1065 // Disable gesture handlers before modifying the stack. Don't call this too | 1075 // Disable gesture handlers before modifying the stack. Don't call this too |
1066 // late or a gesture callback could occur while still in the old state of the | 1076 // late or a gesture callback could occur while still in the old state of the |
1067 // world. | 1077 // world. |
1068 // (see the comment in -cardSet:willRemoveCard:atIndex for details). | 1078 // (see the comment in -cardSet:willRemoveCard:atIndex for details). |
1069 [_scrollView setScrollEnabled:NO]; | 1079 [_scrollView setScrollEnabled:NO]; |
1070 _pinchRecognizer.enabled = NO; | 1080 _pinchRecognizer.get().enabled = NO; |
1071 _swipeGestureRecognizer.enabled = NO; | 1081 _swipeGestureRecognizer.get().enabled = NO; |
1072 } | 1082 } |
1073 | 1083 |
1074 - (void)enableGestureHandlers { | 1084 - (void)enableGestureHandlers { |
1075 // Reenable gesture handlers after modifying the stack. Don't call this too | 1085 // Reenable gesture handlers after modifying the stack. Don't call this too |
1076 // early or a gesture callback could occur while still in the old state of the | 1086 // early or a gesture callback could occur while still in the old state of the |
1077 // world. | 1087 // world. |
1078 // (see the comment in -cardSet:willRemoveCard:atIndex for details). | 1088 // (see the comment in -cardSet:willRemoveCard:atIndex for details). |
1079 [_scrollView setScrollEnabled:YES]; | 1089 [_scrollView setScrollEnabled:YES]; |
1080 _pinchRecognizer.enabled = YES; | 1090 _pinchRecognizer.get().enabled = YES; |
1081 _swipeGestureRecognizer.enabled = YES; | 1091 _swipeGestureRecognizer.get().enabled = YES; |
1082 } | 1092 } |
1083 | 1093 |
1084 - (void)activeCardCountChanged { | 1094 - (void)activeCardCountChanged { |
1085 // Cancel any outstanding gestures (see the comment in | 1095 // Cancel any outstanding gestures (see the comment in |
1086 // -cardSet:willRemoveCard:atIndex). | 1096 // -cardSet:willRemoveCard:atIndex). |
1087 [self disableGestureHandlers]; | 1097 [self disableGestureHandlers]; |
1088 [self enableGestureHandlers]; | 1098 [self enableGestureHandlers]; |
1089 } | 1099 } |
1090 | 1100 |
1091 - (void)setInitialCardSizing { | 1101 - (void)setInitialCardSizing { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 } | 1210 } |
1201 | 1211 |
1202 - (BOOL)bothDecksShouldBeDisplayed { | 1212 - (BOOL)bothDecksShouldBeDisplayed { |
1203 return [[_otrCardSet cards] count] > 0; | 1213 return [[_otrCardSet cards] count] > 0; |
1204 } | 1214 } |
1205 | 1215 |
1206 #pragma mark - | 1216 #pragma mark - |
1207 #pragma mark Current Set Handling | 1217 #pragma mark Current Set Handling |
1208 | 1218 |
1209 - (BOOL)isCurrentSetIncognito { | 1219 - (BOOL)isCurrentSetIncognito { |
1210 return _activeCardSet == _otrCardSet; | 1220 return _activeCardSet == _otrCardSet.get(); |
1211 } | 1221 } |
1212 | 1222 |
1213 - (CardSet*)inactiveCardSet { | 1223 - (CardSet*)inactiveCardSet { |
1214 return [self isCurrentSetIncognito] ? _mainCardSet : _otrCardSet; | 1224 return [self isCurrentSetIncognito] ? _mainCardSet.get() : _otrCardSet.get(); |
1215 } | 1225 } |
1216 | 1226 |
1217 - (void)setActiveCardSet:(CardSet*)cardSet { | 1227 - (void)setActiveCardSet:(CardSet*)cardSet { |
1218 DCHECK(cardSet); | 1228 DCHECK(cardSet); |
1219 if (cardSet == _activeCardSet) | 1229 if (cardSet == _activeCardSet) |
1220 return; | 1230 return; |
1221 [self activeCardCountChanged]; | 1231 [self activeCardCountChanged]; |
1222 _activeCardSet = cardSet; | 1232 _activeCardSet = cardSet; |
1223 | 1233 |
1224 [self displayActiveCardSet]; | 1234 [self displayActiveCardSet]; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 [_activeCardSet.currentCard setIsActiveTab:YES]; | 1467 [_activeCardSet.currentCard setIsActiveTab:YES]; |
1458 | 1468 |
1459 // When in accessbility mode, fan out cards from the start, announce open tabs | 1469 // When in accessbility mode, fan out cards from the start, announce open tabs |
1460 // and move the VoiceOver cursor to the New Tab button. Fanning out the cards | 1470 // and move the VoiceOver cursor to the New Tab button. Fanning out the cards |
1461 // from the start eliminates the screen change that would otherwise occur when | 1471 // from the start eliminates the screen change that would otherwise occur when |
1462 // moving the VoiceOver cursor from the Show Tabs button to the card stack. | 1472 // moving the VoiceOver cursor from the Show Tabs button to the card stack. |
1463 if (UIAccessibilityIsVoiceOverRunning()) { | 1473 if (UIAccessibilityIsVoiceOverRunning()) { |
1464 [_activeCardSet fanOutCardsWithStartIndex:0]; | 1474 [_activeCardSet fanOutCardsWithStartIndex:0]; |
1465 [self postOpenTabsAccessibilityNotification]; | 1475 [self postOpenTabsAccessibilityNotification]; |
1466 UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, | 1476 UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, |
1467 _toolbarController.view); | 1477 _toolbarController.get().view); |
1468 } | 1478 } |
1469 } | 1479 } |
1470 | 1480 |
1471 - (void)cancelTransitionAnimation { | 1481 - (void)cancelTransitionAnimation { |
1472 // Set up transaction. | 1482 // Set up transaction. |
1473 [CATransaction begin]; | 1483 [CATransaction begin]; |
1474 [CATransaction setCompletionBlock:^{ | 1484 [CATransaction setCompletionBlock:^{ |
1475 [self finishTransitionAnimation]; | 1485 [self finishTransitionAnimation]; |
1476 }]; | 1486 }]; |
1477 self.transitionWasCancelled = YES; | 1487 self.transitionWasCancelled = YES; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 BOOL isPresenting = self.transitionStyle == STACK_TRANSITION_STYLE_PRESENTING; | 1578 BOOL isPresenting = self.transitionStyle == STACK_TRANSITION_STYLE_PRESENTING; |
1569 | 1579 |
1570 // Get reference to toolbar for transition. | 1580 // Get reference to toolbar for transition. |
1571 self.transitionToolbarOwner = [_delegate tabSwitcherTransitionToolbarOwner]; | 1581 self.transitionToolbarOwner = [_delegate tabSwitcherTransitionToolbarOwner]; |
1572 self.transitionToolbarController = | 1582 self.transitionToolbarController = |
1573 [self.transitionToolbarOwner relinquishedToolbarController]; | 1583 [self.transitionToolbarOwner relinquishedToolbarController]; |
1574 self.transitionToolbarController.view.animatingTransition = YES; | 1584 self.transitionToolbarController.view.animatingTransition = YES; |
1575 self.transitionToolbarFrame = self.transitionToolbarController.view.frame; | 1585 self.transitionToolbarFrame = self.transitionToolbarController.view.frame; |
1576 | 1586 |
1577 // Create dummy toolbar background view. | 1587 // Create dummy toolbar background view. |
1578 self.dummyToolbarBackgroundView = [[UIView alloc] initWithFrame:CGRectZero]; | 1588 self.dummyToolbarBackgroundView = |
| 1589 [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; |
1579 [self.dummyToolbarBackgroundView setClipsToBounds:YES]; | 1590 [self.dummyToolbarBackgroundView setClipsToBounds:YES]; |
1580 | 1591 |
1581 // Set the transition completion block. | 1592 // Set the transition completion block. |
1582 [CATransaction begin]; | 1593 [CATransaction begin]; |
1583 [CATransaction setCompletionBlock:^{ | 1594 [CATransaction setCompletionBlock:^{ |
1584 [self finishTransitionAnimation]; | 1595 [self finishTransitionAnimation]; |
1585 }]; | 1596 }]; |
1586 | 1597 |
1587 // Slide in/out the inactive card set. | 1598 // Slide in/out the inactive card set. |
1588 [self animateInactiveSetTransition]; | 1599 [self animateInactiveSetTransition]; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 inBackground:NO]; | 2054 inBackground:NO]; |
2044 [_activeCardSet.tabModel setCurrentTab:tab]; | 2055 [_activeCardSet.tabModel setCurrentTab:tab]; |
2045 | 2056 |
2046 [_delegate tabSwitcher:self | 2057 [_delegate tabSwitcher:self |
2047 dismissTransitionWillStartWithActiveModel:_activeCardSet.tabModel]; | 2058 dismissTransitionWillStartWithActiveModel:_activeCardSet.tabModel]; |
2048 | 2059 |
2049 CGFloat statusBarHeight = StatusBarHeight(); | 2060 CGFloat statusBarHeight = StatusBarHeight(); |
2050 CGRect viewBounds, remainder; | 2061 CGRect viewBounds, remainder; |
2051 CGRectDivide([self.view bounds], &remainder, &viewBounds, statusBarHeight, | 2062 CGRectDivide([self.view bounds], &remainder, &viewBounds, statusBarHeight, |
2052 CGRectMinYEdge); | 2063 CGRectMinYEdge); |
2053 UIImageView* newCard = [[UIImageView alloc] initWithFrame:viewBounds]; | 2064 UIImageView* newCard = |
| 2065 [[[UIImageView alloc] initWithFrame:viewBounds] autorelease]; |
2054 // Temporarily resize the tab's view to ensure it matches the card while | 2066 // Temporarily resize the tab's view to ensure it matches the card while |
2055 // generating a snapshot, but then restore the original frame. | 2067 // generating a snapshot, but then restore the original frame. |
2056 CGRect originalTabFrame = [tab view].frame; | 2068 CGRect originalTabFrame = [tab view].frame; |
2057 [tab view].frame = viewBounds; | 2069 [tab view].frame = viewBounds; |
2058 newCard.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 2070 newCard.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
2059 [tab view].frame = originalTabFrame; | 2071 [tab view].frame = originalTabFrame; |
2060 newCard.center = | 2072 newCard.center = |
2061 CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds)); | 2073 CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds)); |
2062 [self.view addSubview:newCard]; | 2074 [self.view addSubview:newCard]; |
2063 | 2075 |
(...skipping 16 matching lines...) Expand all Loading... |
2080 | 2092 |
2081 #pragma mark UIGestureRecognizerDelegate methods | 2093 #pragma mark UIGestureRecognizerDelegate methods |
2082 | 2094 |
2083 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)recognizer | 2095 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)recognizer |
2084 shouldReceiveTouch:(UITouch*)touch { | 2096 shouldReceiveTouch:(UITouch*)touch { |
2085 // Don't swallow any touches while the tools popup menu is open. | 2097 // Don't swallow any touches while the tools popup menu is open. |
2086 if ([_toolbarController toolsPopupController]) | 2098 if ([_toolbarController toolsPopupController]) |
2087 return NO; | 2099 return NO; |
2088 | 2100 |
2089 if ((recognizer == _pinchRecognizer) || | 2101 if ((recognizer == _pinchRecognizer) || |
2090 (recognizer == _swipeGestureRecognizer)) | 2102 (recognizer == _swipeGestureRecognizer.get())) |
2091 return YES; | 2103 return YES; |
2092 | 2104 |
2093 // Only the mode switch recognizer should be triggered in the inactive deck | 2105 // Only the mode switch recognizer should be triggered in the inactive deck |
2094 // region (and it should only be triggered there). | 2106 // region (and it should only be triggered there). |
2095 CGPoint touchLocation = [touch locationInView:_scrollView]; | 2107 CGPoint touchLocation = [touch locationInView:_scrollView]; |
2096 BOOL inInactiveDeckRegion = | 2108 BOOL inInactiveDeckRegion = |
2097 CGRectContainsPoint([self inactiveDeckRegion], touchLocation); | 2109 CGRectContainsPoint([self inactiveDeckRegion], touchLocation); |
2098 if (recognizer == _modeSwitchRecognizer) | 2110 if (recognizer == _modeSwitchRecognizer.get()) |
2099 return inInactiveDeckRegion; | 2111 return inInactiveDeckRegion; |
2100 else if (inInactiveDeckRegion) | 2112 else if (inInactiveDeckRegion) |
2101 return NO; | 2113 return NO; |
2102 | 2114 |
2103 // Extract the card on which the touch is occurring. | 2115 // Extract the card on which the touch is occurring. |
2104 CardView* cardView = nil; | 2116 CardView* cardView = nil; |
2105 StackCard* card = nil; | 2117 StackCard* card = nil; |
2106 if (recognizer == _swipeDismissesCardRecognizer) { | 2118 if (recognizer == _swipeDismissesCardRecognizer.get()) { |
2107 UIView* activeView = _activeCardSet.displayView; | 2119 UIView* activeView = _activeCardSet.displayView; |
2108 CGPoint locationInActiveView = [touch locationInView:activeView]; | 2120 CGPoint locationInActiveView = [touch locationInView:activeView]; |
2109 NSUInteger cardIndex = [self indexOfCardAtPoint:locationInActiveView]; | 2121 NSUInteger cardIndex = [self indexOfCardAtPoint:locationInActiveView]; |
2110 // |_swipeDismissesCardRecognizer| is interested only in touches that are | 2122 // |_swipeDismissesCardRecognizer| is interested only in touches that are |
2111 // on cards in the active set. | 2123 // on cards in the active set. |
2112 if (cardIndex == NSNotFound) | 2124 if (cardIndex == NSNotFound) |
2113 return NO; | 2125 return NO; |
2114 DCHECK(cardIndex < [[_activeCardSet cards] count]); | 2126 DCHECK(cardIndex < [[_activeCardSet cards] count]); |
2115 card = [[_activeCardSet cards] objectAtIndex:cardIndex]; | 2127 card = [[_activeCardSet cards] objectAtIndex:cardIndex]; |
2116 // This case seems like it should never happen, but it can be easily | 2128 // This case seems like it should never happen, but it can be easily |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 otherGestureRecognizer == _scrollGestureRecognizer); | 2160 otherGestureRecognizer == _scrollGestureRecognizer); |
2149 if (pinchRecognizerInvolved && scrollRecognizerInvolved) | 2161 if (pinchRecognizerInvolved && scrollRecognizerInvolved) |
2150 return YES; | 2162 return YES; |
2151 | 2163 |
2152 // Swiping must be allowed to recognize simultaneously with the recognizer of | 2164 // Swiping must be allowed to recognize simultaneously with the recognizer of |
2153 // long presses that turn ambiguous swipes into card dismissals. | 2165 // long presses that turn ambiguous swipes into card dismissals. |
2154 BOOL swipeRecognizerInvolved = | 2166 BOOL swipeRecognizerInvolved = |
2155 (gestureRecognizer == _swipeGestureRecognizer || | 2167 (gestureRecognizer == _swipeGestureRecognizer || |
2156 otherGestureRecognizer == _swipeGestureRecognizer); | 2168 otherGestureRecognizer == _swipeGestureRecognizer); |
2157 BOOL swipeDismissesCardRecognizerInvolved = | 2169 BOOL swipeDismissesCardRecognizerInvolved = |
2158 (gestureRecognizer == _swipeDismissesCardRecognizer || | 2170 (gestureRecognizer == _swipeDismissesCardRecognizer.get() || |
2159 otherGestureRecognizer == _swipeDismissesCardRecognizer); | 2171 otherGestureRecognizer == _swipeDismissesCardRecognizer.get()); |
2160 if (swipeRecognizerInvolved && swipeDismissesCardRecognizerInvolved) | 2172 if (swipeRecognizerInvolved && swipeDismissesCardRecognizerInvolved) |
2161 return YES; | 2173 return YES; |
2162 | 2174 |
2163 // The swipe-triggers-card-dismissal long press recognizer must be allowed to | 2175 // The swipe-triggers-card-dismissal long press recognizer must be allowed to |
2164 // recognize simultaneously with the cards' long press recognizers that | 2176 // recognize simultaneously with the cards' long press recognizers that |
2165 // trigger show-more-of-card. | 2177 // trigger show-more-of-card. |
2166 BOOL longPressRecognizerInvolved = | 2178 BOOL longPressRecognizerInvolved = |
2167 ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || | 2179 ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || |
2168 [otherGestureRecognizer | 2180 [otherGestureRecognizer |
2169 isKindOfClass:[UILongPressGestureRecognizer class]]); | 2181 isKindOfClass:[UILongPressGestureRecognizer class]]); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2212 else | 2224 else |
2213 DLOG(ERROR) << "Closed card at an index out of range of the tab model"; | 2225 DLOG(ERROR) << "Closed card at an index out of range of the tab model"; |
2214 [_activeCardSet removeCardAtIndex:tabIndex]; | 2226 [_activeCardSet removeCardAtIndex:tabIndex]; |
2215 } | 2227 } |
2216 } | 2228 } |
2217 | 2229 |
2218 - (void)handleLongPressFrom:(UIGestureRecognizer*)recognizer { | 2230 - (void)handleLongPressFrom:(UIGestureRecognizer*)recognizer { |
2219 DCHECK(!_isBeingDismissed); | 2231 DCHECK(!_isBeingDismissed); |
2220 DCHECK(_isActive); | 2232 DCHECK(_isActive); |
2221 | 2233 |
2222 if (recognizer == _swipeDismissesCardRecognizer) | 2234 if (recognizer == _swipeDismissesCardRecognizer.get()) |
2223 return; | 2235 return; |
2224 | 2236 |
2225 UIGestureRecognizerState state = [recognizer state]; | 2237 UIGestureRecognizerState state = [recognizer state]; |
2226 if (state != UIGestureRecognizerStateBegan) | 2238 if (state != UIGestureRecognizerStateBegan) |
2227 return; | 2239 return; |
2228 if ([recognizer numberOfTouches] == 0) | 2240 if ([recognizer numberOfTouches] == 0) |
2229 return; | 2241 return; |
2230 | 2242 |
2231 // Don't take action on a card that is in the inactive stack, collapsed, or | 2243 // Don't take action on a card that is in the inactive stack, collapsed, or |
2232 // the last card. | 2244 // the last card. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2387 [_gestureStateTracker setPreviousFirstPinchOffset:firstOffset]; | 2399 [_gestureStateTracker setPreviousFirstPinchOffset:firstOffset]; |
2388 [_gestureStateTracker setPreviousSecondPinchOffset:secondOffset]; | 2400 [_gestureStateTracker setPreviousSecondPinchOffset:secondOffset]; |
2389 } | 2401 } |
2390 | 2402 |
2391 - (void)handleTapFrom:(UITapGestureRecognizer*)recognizer { | 2403 - (void)handleTapFrom:(UITapGestureRecognizer*)recognizer { |
2392 DCHECK(!_isBeingDismissed); | 2404 DCHECK(!_isBeingDismissed); |
2393 DCHECK(_isActive); | 2405 DCHECK(_isActive); |
2394 if (recognizer.state != UIGestureRecognizerStateEnded) | 2406 if (recognizer.state != UIGestureRecognizerStateEnded) |
2395 return; | 2407 return; |
2396 | 2408 |
2397 if (recognizer == _modeSwitchRecognizer) { | 2409 if (recognizer == _modeSwitchRecognizer.get()) { |
2398 DCHECK(CGRectContainsPoint([self inactiveDeckRegion], | 2410 DCHECK(CGRectContainsPoint([self inactiveDeckRegion], |
2399 [recognizer locationInView:_scrollView])); | 2411 [recognizer locationInView:_scrollView])); |
2400 [self setActiveCardSet:[self inactiveCardSet]]; | 2412 [self setActiveCardSet:[self inactiveCardSet]]; |
2401 return; | 2413 return; |
2402 } | 2414 } |
2403 | 2415 |
2404 CardView* cardView = (CardView*)recognizer.view; | 2416 CardView* cardView = (CardView*)recognizer.view; |
2405 UIView* activeView = _activeCardSet.displayView; | 2417 UIView* activeView = _activeCardSet.displayView; |
2406 if ([cardView superview] != activeView) | 2418 if ([cardView superview] != activeView) |
2407 return; | 2419 return; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2627 // Fade the card to become transparent at the conclusion of the animation, | 2639 // Fade the card to become transparent at the conclusion of the animation, |
2628 // and the card's tab to become transparent at the time that the card | 2640 // and the card's tab to become transparent at the time that the card |
2629 // reaches the threshold for being dismissed. | 2641 // reaches the threshold for being dismissed. |
2630 [card view].alpha = 1 - fractionOfAnimationBreadth; | 2642 [card view].alpha = 1 - fractionOfAnimationBreadth; |
2631 } else { | 2643 } else { |
2632 if (gesture.state == UIGestureRecognizerStateEnded && | 2644 if (gesture.state == UIGestureRecognizerStateEnded && |
2633 [self swipeShouldTriggerAction:position]) { | 2645 [self swipeShouldTriggerAction:position]) { |
2634 // Track card if animation should dismiss in reverse from the norm of | 2646 // Track card if animation should dismiss in reverse from the norm of |
2635 // clockwise in portrait, counter-clockwise in landscape. | 2647 // clockwise in portrait, counter-clockwise in landscape. |
2636 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) | 2648 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) |
2637 _reverseDismissCard = card; | 2649 _reverseDismissCard.reset([card retain]); |
2638 // This will trigger the completion of the close card animation. | 2650 // This will trigger the completion of the close card animation. |
2639 [self closeTab:card.view]; | 2651 [self closeTab:card.view]; |
2640 } else { | 2652 } else { |
2641 // Animate back to starting position. | 2653 // Animate back to starting position. |
2642 [UIView animateWithDuration:kDefaultAnimationDuration | 2654 [UIView animateWithDuration:kDefaultAnimationDuration |
2643 delay:0 | 2655 delay:0 |
2644 options:UIViewAnimationCurveEaseOut | 2656 options:UIViewAnimationCurveEaseOut |
2645 animations:^{ | 2657 animations:^{ |
2646 [card view].alpha = 1; | 2658 [card view].alpha = 1; |
2647 [[card view] setTabOpacity:1]; | 2659 [[card view] setTabOpacity:1]; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2697 case IDC_TOGGLE_TAB_SWITCHER: | 2709 case IDC_TOGGLE_TAB_SWITCHER: |
2698 [self dismissWithSelectedTabAnimation]; | 2710 [self dismissWithSelectedTabAnimation]; |
2699 break; | 2711 break; |
2700 default: | 2712 default: |
2701 [super chromeExecuteCommand:sender]; | 2713 [super chromeExecuteCommand:sender]; |
2702 break; | 2714 break; |
2703 } | 2715 } |
2704 } | 2716 } |
2705 | 2717 |
2706 - (void)showToolsMenuPopup { | 2718 - (void)showToolsMenuPopup { |
2707 ToolsMenuConfiguration* configuration = | 2719 base::scoped_nsobject<ToolsMenuConfiguration> configuration( |
2708 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; | 2720 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]); |
2709 [configuration setInTabSwitcher:YES]; | 2721 [configuration setInTabSwitcher:YES]; |
2710 // When checking for the existence of tabs, catch the case where the main set | 2722 // When checking for the existence of tabs, catch the case where the main set |
2711 // is both active and empty, but the incognito set has some cards. | 2723 // is both active and empty, but the incognito set has some cards. |
2712 if (([[_activeCardSet cards] count] == 0) && | 2724 if (([[_activeCardSet cards] count] == 0) && |
2713 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) | 2725 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) |
2714 [configuration setNoOpenedTabs:YES]; | 2726 [configuration setNoOpenedTabs:YES]; |
2715 if (_activeCardSet == _otrCardSet) | 2727 if (_activeCardSet == _otrCardSet) |
2716 [configuration setInIncognito:YES]; | 2728 [configuration setInIncognito:YES]; |
2717 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; | 2729 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
2718 } | 2730 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2887 BOOL isPortrait = | 2899 BOOL isPortrait = |
2888 UIInterfaceOrientationIsPortrait(_lastInterfaceOrientation); | 2900 UIInterfaceOrientationIsPortrait(_lastInterfaceOrientation); |
2889 BOOL clockwise = isPortrait ? _reverseDismissCard != removedCard | 2901 BOOL clockwise = isPortrait ? _reverseDismissCard != removedCard |
2890 : _reverseDismissCard == removedCard; | 2902 : _reverseDismissCard == removedCard; |
2891 [self animateOutCardView:removedCard.view | 2903 [self animateOutCardView:removedCard.view |
2892 delay:0 | 2904 delay:0 |
2893 clockwise:clockwise | 2905 clockwise:clockwise |
2894 completion:nil]; | 2906 completion:nil]; |
2895 // Reset |reverseDismissCard| if that card was the one dismissed. | 2907 // Reset |reverseDismissCard| if that card was the one dismissed. |
2896 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) | 2908 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) |
2897 _reverseDismissCard = nil; | 2909 _reverseDismissCard.reset(); |
2898 } | 2910 } |
2899 // Nil out the the closing card after all closing animations have finished. | 2911 // Nil out the the closing card after all closing animations have finished. |
2900 [CATransaction begin]; | 2912 [CATransaction begin]; |
2901 [CATransaction setCompletionBlock:^{ | 2913 [CATransaction setCompletionBlock:^{ |
2902 cardSet.closingCard = nil; | 2914 cardSet.closingCard = nil; |
2903 }]; | 2915 }]; |
2904 // If the last incognito card closes, switch back to just the main set. | 2916 // If the last incognito card closes, switch back to just the main set. |
2905 if ([cardSet.cards count] == 0 && cardSet == _otrCardSet) { | 2917 if ([cardSet.cards count] == 0 && cardSet == _otrCardSet.get()) { |
2906 [self displayMainCardSetOnly]; | 2918 [self displayMainCardSetOnly]; |
2907 } else { | 2919 } else { |
2908 NSUInteger numCards = [[cardSet cards] count]; | 2920 NSUInteger numCards = [[cardSet cards] count]; |
2909 if (numCards == 0) { | 2921 if (numCards == 0) { |
2910 // Commit the transaction before early return. | 2922 // Commit the transaction before early return. |
2911 [CATransaction commit]; | 2923 [CATransaction commit]; |
2912 return; | 2924 return; |
2913 } | 2925 } |
2914 if (index == numCards) { | 2926 if (index == numCards) { |
2915 // If the card that was closed was the last card and was in the start | 2927 // If the card that was closed was the last card and was in the start |
(...skipping 28 matching lines...) Expand all Loading... |
2944 } | 2956 } |
2945 [CATransaction commit]; | 2957 [CATransaction commit]; |
2946 } | 2958 } |
2947 | 2959 |
2948 - (void)cardSet:(CardSet*)cardSet displayedCard:(StackCard*)card { | 2960 - (void)cardSet:(CardSet*)cardSet displayedCard:(StackCard*)card { |
2949 // Add gesture recognizers to the card. | 2961 // Add gesture recognizers to the card. |
2950 [card.view addCardCloseTarget:self action:@selector(closeTab:)]; | 2962 [card.view addCardCloseTarget:self action:@selector(closeTab:)]; |
2951 [card.view addAccessibilityTarget:self | 2963 [card.view addAccessibilityTarget:self |
2952 action:@selector(accessibilityFocusedOnElement:)]; | 2964 action:@selector(accessibilityFocusedOnElement:)]; |
2953 | 2965 |
2954 UIGestureRecognizer* tapRecognizer = | 2966 base::scoped_nsobject<UIGestureRecognizer> tapRecognizer([ |
2955 [[UITapGestureRecognizer alloc] initWithTarget:self | 2967 [UITapGestureRecognizer alloc] initWithTarget:self |
2956 action:@selector(handleTapFrom:)]; | 2968 action:@selector(handleTapFrom:)]); |
2957 tapRecognizer.delegate = self; | 2969 tapRecognizer.get().delegate = self; |
2958 [card.view addGestureRecognizer:tapRecognizer]; | 2970 [card.view addGestureRecognizer:tapRecognizer.get()]; |
2959 | 2971 |
2960 UIGestureRecognizer* longPressRecognizer = | 2972 base::scoped_nsobject<UIGestureRecognizer> longPressRecognizer( |
2961 [[UILongPressGestureRecognizer alloc] | 2973 [[UILongPressGestureRecognizer alloc] |
2962 initWithTarget:self | 2974 initWithTarget:self |
2963 action:@selector(handleLongPressFrom:)]; | 2975 action:@selector(handleLongPressFrom:)]); |
2964 longPressRecognizer.delegate = self; | 2976 longPressRecognizer.get().delegate = self; |
2965 [card.view addGestureRecognizer:longPressRecognizer]; | 2977 [card.view addGestureRecognizer:longPressRecognizer.get()]; |
2966 } | 2978 } |
2967 | 2979 |
2968 - (void)cardSetRecreatedCards:(CardSet*)cardSet { | 2980 - (void)cardSetRecreatedCards:(CardSet*)cardSet { |
2969 // Remove the old card views, if any, then start loading the new ones. | 2981 // Remove the old card views, if any, then start loading the new ones. |
2970 for (UIView* card in [cardSet.displayView subviews]) { | 2982 for (UIView* card in [cardSet.displayView subviews]) { |
2971 [card removeFromSuperview]; | 2983 [card removeFromSuperview]; |
2972 } | 2984 } |
2973 [self preloadCardViewsAsynchronously]; | 2985 [self preloadCardViewsAsynchronously]; |
2974 } | 2986 } |
2975 | 2987 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3441 // the cards out starting with that card. | 3453 // the cards out starting with that card. |
3442 [_activeCardSet fanOutCardsWithStartIndex:index]; | 3454 [_activeCardSet fanOutCardsWithStartIndex:index]; |
3443 [card.view postAccessibilityNotification]; | 3455 [card.view postAccessibilityNotification]; |
3444 [self postOpenTabsAccessibilityNotification]; | 3456 [self postOpenTabsAccessibilityNotification]; |
3445 } | 3457 } |
3446 } | 3458 } |
3447 | 3459 |
3448 #pragma mark - UIResponder | 3460 #pragma mark - UIResponder |
3449 | 3461 |
3450 - (NSArray*)keyCommands { | 3462 - (NSArray*)keyCommands { |
3451 __weak StackViewController* weakSelf = self; | 3463 base::WeakNSObject<StackViewController> weakSelf(self); |
3452 | 3464 |
3453 // Block to execute a command from the |tag|. | 3465 // Block to execute a command from the |tag|. |
3454 void (^execute)(NSInteger) = ^(NSInteger tag) { | 3466 base::mac::ScopedBlock<void (^)(NSInteger)> execute( |
3455 [weakSelf chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]]; | 3467 ^(NSInteger tag) { |
3456 }; | 3468 [weakSelf |
| 3469 chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]]; |
| 3470 }, |
| 3471 base::scoped_policy::RETAIN); |
3457 | 3472 |
3458 return @[ | 3473 return @[ |
3459 [UIKeyCommand cr_keyCommandWithInput:@"t" | 3474 [UIKeyCommand cr_keyCommandWithInput:@"t" |
3460 modifierFlags:UIKeyModifierCommand | 3475 modifierFlags:UIKeyModifierCommand |
3461 title:l10n_util::GetNSStringWithFixup( | 3476 title:l10n_util::GetNSStringWithFixup( |
3462 IDS_IOS_TOOLS_MENU_NEW_TAB) | 3477 IDS_IOS_TOOLS_MENU_NEW_TAB) |
3463 action:^{ | 3478 action:^{ |
3464 if ([weakSelf isCurrentSetIncognito]) | 3479 if ([weakSelf isCurrentSetIncognito]) |
3465 execute(IDC_NEW_INCOGNITO_TAB); | 3480 execute.get()(IDC_NEW_INCOGNITO_TAB); |
3466 else | 3481 else |
3467 execute(IDC_NEW_TAB); | 3482 execute.get()(IDC_NEW_TAB); |
3468 }], | 3483 }], |
3469 [UIKeyCommand | 3484 [UIKeyCommand |
3470 cr_keyCommandWithInput:@"n" | 3485 cr_keyCommandWithInput:@"n" |
3471 modifierFlags:UIKeyModifierCommand | UIKeyModifierShift | 3486 modifierFlags:UIKeyModifierCommand | UIKeyModifierShift |
3472 title:l10n_util::GetNSStringWithFixup( | 3487 title:l10n_util::GetNSStringWithFixup( |
3473 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB) | 3488 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB) |
3474 action:^{ | 3489 action:^{ |
3475 execute(IDC_NEW_INCOGNITO_TAB); | 3490 execute.get()(IDC_NEW_INCOGNITO_TAB); |
3476 }], | 3491 }], |
3477 [UIKeyCommand cr_keyCommandWithInput:@"n" | 3492 [UIKeyCommand cr_keyCommandWithInput:@"n" |
3478 modifierFlags:UIKeyModifierCommand | 3493 modifierFlags:UIKeyModifierCommand |
3479 title:nil | 3494 title:nil |
3480 action:^{ | 3495 action:^{ |
3481 if ([weakSelf isCurrentSetIncognito]) | 3496 if ([weakSelf isCurrentSetIncognito]) |
3482 execute(IDC_NEW_INCOGNITO_TAB); | 3497 execute.get()(IDC_NEW_INCOGNITO_TAB); |
3483 else | 3498 else |
3484 execute(IDC_NEW_TAB); | 3499 execute.get()(IDC_NEW_TAB); |
3485 }], | 3500 }], |
3486 ]; | 3501 ]; |
3487 } | 3502 } |
3488 | 3503 |
3489 @end | 3504 @end |
3490 | 3505 |
3491 @implementation StackViewController (Testing) | 3506 @implementation StackViewController (Testing) |
3492 | 3507 |
3493 - (UIScrollView*)scrollView { | 3508 - (UIScrollView*)scrollView { |
3494 return _scrollView; | 3509 return _scrollView.get(); |
3495 } | 3510 } |
3496 | 3511 |
3497 @end | 3512 @end |
OLD | NEW |