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