| 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 disconnect]; |
| 634 _otrCardSet.reset(); | 627 _mainCardSet = nil; |
| 628 |
| 629 [_otrCardSet disconnect]; |
| 630 _otrCardSet = nil; |
| 631 |
| 635 _activeCardSet = nil; | 632 _activeCardSet = nil; |
| 636 | 633 |
| 637 // Remove gesture recognizers and notifications. | 634 // Remove gesture recognizers and notifications. |
| 638 [self prepareForDismissal]; | 635 [self prepareForDismissal]; |
| 639 _gestureStateTracker.reset(); | 636 _gestureStateTracker = nil; |
| 640 _pinchRecognizer.reset(); | 637 _pinchRecognizer = nil; |
| 641 _modeSwitchRecognizer.reset(); | 638 _modeSwitchRecognizer = nil; |
| 642 _swipeGestureRecognizer.reset(); | 639 _swipeGestureRecognizer = nil; |
| 643 | 640 |
| 644 // The cards need to recompute their sizes the next time they are shown. | 641 // The cards need to recompute their sizes the next time they are shown. |
| 645 _initialCardSize.height = _initialCardSize.width = 0.0f; | 642 _initialCardSize.height = _initialCardSize.width = 0.0f; |
| 646 // The scroll view will need to recenter itself relative to its viewport. | 643 // The scroll view will need to recenter itself relative to its viewport. |
| 647 [_scrollView setContentOffset:CGPointZero]; | 644 [_scrollView setContentOffset:CGPointZero]; |
| 648 _isBeingDismissed = NO; | 645 _isBeingDismissed = NO; |
| 649 } | 646 } |
| 650 | 647 |
| 651 - (void)viewportSizeWasChanged { | 648 - (void)viewportSizeWasChanged { |
| 652 [self updateScrollViewContentSize]; | 649 [self updateScrollViewContentSize]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 669 _ignoreScrollCallbacks = YES; | 666 _ignoreScrollCallbacks = YES; |
| 670 [_scrollView setContentSize:[self sizeForScrollLength:scrollLength | 667 [_scrollView setContentSize:[self sizeForScrollLength:scrollLength |
| 671 breadth:scrollBreadth]]; | 668 breadth:scrollBreadth]]; |
| 672 _ignoreScrollCallbacks = NO; | 669 _ignoreScrollCallbacks = NO; |
| 673 [self recenterScrollViewIfNecessary]; | 670 [self recenterScrollViewIfNecessary]; |
| 674 } | 671 } |
| 675 | 672 |
| 676 - (void)setUpDisplayViews { | 673 - (void)setUpDisplayViews { |
| 677 CGRect displayViewFrame = CGRectMake(0, 0, [_scrollView frame].size.width, | 674 CGRect displayViewFrame = CGRectMake(0, 0, [_scrollView frame].size.width, |
| 678 [_scrollView frame].size.height); | 675 [_scrollView frame].size.height); |
| 679 base::scoped_nsobject<UIView> mainDisplayView( | 676 UIView* mainDisplayView = [[UIView alloc] initWithFrame:displayViewFrame]; |
| 680 [[UIView alloc] initWithFrame:displayViewFrame]); | |
| 681 [mainDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 677 [mainDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| 682 UIViewAutoresizingFlexibleHeight]; | 678 UIViewAutoresizingFlexibleHeight]; |
| 683 base::scoped_nsobject<UIView> otrDisplayView( | 679 UIView* otrDisplayView = [[UIView alloc] initWithFrame:displayViewFrame]; |
| 684 [[UIView alloc] initWithFrame:displayViewFrame]); | |
| 685 [otrDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 680 [otrDisplayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| 686 UIViewAutoresizingFlexibleHeight]; | 681 UIViewAutoresizingFlexibleHeight]; |
| 687 | 682 |
| 688 [_scrollView addSubview:mainDisplayView]; | 683 [_scrollView addSubview:mainDisplayView]; |
| 689 [_scrollView addSubview:otrDisplayView]; | 684 [_scrollView addSubview:otrDisplayView]; |
| 690 [_mainCardSet setDisplayView:mainDisplayView]; | 685 [_mainCardSet setDisplayView:mainDisplayView]; |
| 691 [_otrCardSet setDisplayView:otrDisplayView]; | 686 [_otrCardSet setDisplayView:otrDisplayView]; |
| 692 } | 687 } |
| 693 | 688 |
| 694 - (void)prepareForDisplay { | 689 - (void)prepareForDisplay { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 707 : UIInterfaceOrientationLandscapeRight; | 702 : UIInterfaceOrientationLandscapeRight; |
| 708 } | 703 } |
| 709 [self registerForNotifications]; | 704 [self registerForNotifications]; |
| 710 | 705 |
| 711 // TODO(blundell): Why isn't this recognizer initialized with the | 706 // TODO(blundell): Why isn't this recognizer initialized with the |
| 712 // pinch and mode switch recognizers? | 707 // pinch and mode switch recognizers? |
| 713 UIPanGestureRecognizer* panGestureRecognizer = | 708 UIPanGestureRecognizer* panGestureRecognizer = |
| 714 [[UIPanGestureRecognizer alloc] initWithTarget:self | 709 [[UIPanGestureRecognizer alloc] initWithTarget:self |
| 715 action:@selector(handlePanFrom:)]; | 710 action:@selector(handlePanFrom:)]; |
| 716 [panGestureRecognizer setMaximumNumberOfTouches:1]; | 711 [panGestureRecognizer setMaximumNumberOfTouches:1]; |
| 717 _swipeGestureRecognizer.reset(panGestureRecognizer); | 712 _swipeGestureRecognizer = panGestureRecognizer; |
| 718 [[self view] addGestureRecognizer:_swipeGestureRecognizer]; | 713 [[self view] addGestureRecognizer:_swipeGestureRecognizer]; |
| 719 [_swipeGestureRecognizer setDelegate:self]; | 714 [_swipeGestureRecognizer setDelegate:self]; |
| 720 } | 715 } |
| 721 | 716 |
| 722 - (void)loadView { | 717 - (void)loadView { |
| 723 [super loadView]; | 718 [super loadView]; |
| 724 | 719 |
| 725 _backgroundView.reset([[UIView alloc] initWithFrame:self.view.bounds]); | 720 _backgroundView = [[UIView alloc] initWithFrame:self.view.bounds]; |
| 726 [_backgroundView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | | 721 [_backgroundView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | |
| 727 UIViewAutoresizingFlexibleWidth)]; | 722 UIViewAutoresizingFlexibleWidth)]; |
| 728 [self.view addSubview:_backgroundView]; | 723 [self.view addSubview:_backgroundView]; |
| 729 | 724 |
| 730 _toolbarController.reset( | 725 _toolbarController = |
| 731 [[StackViewToolbarController alloc] initWithStackViewToolbar]); | 726 [[StackViewToolbarController alloc] initWithStackViewToolbar]; |
| 732 CGRect toolbarFrame = [self.view bounds]; | 727 CGRect toolbarFrame = [self.view bounds]; |
| 733 toolbarFrame.origin.y = CGRectGetMinY([[_toolbarController view] frame]); | 728 toolbarFrame.origin.y = CGRectGetMinY([[_toolbarController view] frame]); |
| 734 toolbarFrame.size.height = CGRectGetHeight([[_toolbarController view] frame]); | 729 toolbarFrame.size.height = CGRectGetHeight([[_toolbarController view] frame]); |
| 735 [[_toolbarController view] setFrame:toolbarFrame]; | 730 [[_toolbarController view] setFrame:toolbarFrame]; |
| 736 [self.view addSubview:[_toolbarController view]]; | 731 [self.view addSubview:[_toolbarController view]]; |
| 737 [self updateToolbarAppearanceWithAnimation:NO]; | 732 [self updateToolbarAppearanceWithAnimation:NO]; |
| 738 | 733 |
| 739 InstallBackgroundInView(_backgroundView); | 734 InstallBackgroundInView(_backgroundView); |
| 740 | 735 |
| 741 UIEdgeInsets contentInsets = UIEdgeInsetsMake( | 736 UIEdgeInsets contentInsets = UIEdgeInsetsMake( |
| 742 toolbarFrame.size.height - kVerticalToolbarOverlap, 0.0, 0.0, 0.0); | 737 toolbarFrame.size.height - kVerticalToolbarOverlap, 0.0, 0.0, 0.0); |
| 743 CGRect scrollViewFrame = | 738 CGRect scrollViewFrame = |
| 744 UIEdgeInsetsInsetRect(self.view.bounds, contentInsets); | 739 UIEdgeInsetsInsetRect(self.view.bounds, contentInsets); |
| 745 _scrollView.reset([[UIScrollView alloc] initWithFrame:scrollViewFrame]); | 740 _scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame]; |
| 746 [self.view addSubview:_scrollView]; | 741 [self.view addSubview:_scrollView]; |
| 747 [_scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | | 742 [_scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | |
| 748 UIViewAutoresizingFlexibleWidth)]; | 743 UIViewAutoresizingFlexibleWidth)]; |
| 749 [_scrollView setBounces:NO]; | 744 [_scrollView setBounces:NO]; |
| 750 [_scrollView setScrollsToTop:NO]; | 745 [_scrollView setScrollsToTop:NO]; |
| 751 [_scrollView setClipsToBounds:NO]; | 746 [_scrollView setClipsToBounds:NO]; |
| 752 [_scrollView setShowsVerticalScrollIndicator:NO]; | 747 [_scrollView setShowsVerticalScrollIndicator:NO]; |
| 753 [_scrollView setShowsHorizontalScrollIndicator:NO]; | 748 [_scrollView setShowsHorizontalScrollIndicator:NO]; |
| 754 [_scrollView setDelegate:self]; | 749 [_scrollView setDelegate:self]; |
| 755 | 750 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 776 [self setInitialCardSizing]; | 771 [self setInitialCardSizing]; |
| 777 [self viewportSizeWasChanged]; | 772 [self viewportSizeWasChanged]; |
| 778 } else { | 773 } else { |
| 779 [self refreshCardDisplayWithAnimation:NO]; | 774 [self refreshCardDisplayWithAnimation:NO]; |
| 780 [self updateToolbarAppearanceWithAnimation:NO]; | 775 [self updateToolbarAppearanceWithAnimation:NO]; |
| 781 } | 776 } |
| 782 [self preloadCardViewsAsynchronously]; | 777 [self preloadCardViewsAsynchronously]; |
| 783 | 778 |
| 784 // Reset the gesture state tracker to clear gesture-related information from | 779 // Reset the gesture state tracker to clear gesture-related information from |
| 785 // the last time the stack view was shown. | 780 // the last time the stack view was shown. |
| 786 _gestureStateTracker.reset([[GestureStateTracker alloc] init]); | 781 _gestureStateTracker = [[GestureStateTracker alloc] init]; |
| 787 | 782 |
| 788 [super viewWillAppear:animated]; | 783 [super viewWillAppear:animated]; |
| 789 } | 784 } |
| 790 | 785 |
| 791 - (void)refreshCardDisplayWithAnimation:(BOOL)animates { | 786 - (void)refreshCardDisplayWithAnimation:(BOOL)animates { |
| 792 _lastInterfaceOrientation = GetInterfaceOrientation(); | 787 _lastInterfaceOrientation = GetInterfaceOrientation(); |
| 793 [self updateDeckOrientationWithAnimation:animates]; | 788 [self updateDeckOrientationWithAnimation:animates]; |
| 794 [self viewportSizeWasChanged]; | 789 [self viewportSizeWasChanged]; |
| 795 [_mainCardSet updateCardVisibilities]; | 790 [_mainCardSet updateCardVisibilities]; |
| 796 [_otrCardSet updateCardVisibilities]; | 791 [_otrCardSet updateCardVisibilities]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 809 } | 804 } |
| 810 | 805 |
| 811 - (void)dealloc { | 806 - (void)dealloc { |
| 812 [_mainCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; | 807 [_mainCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; |
| 813 [_otrCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; | 808 [_otrCardSet clearGestureRecognizerTargetAndDelegateFromCards:self]; |
| 814 // Card sets shouldn't have any other references, but nil the observer just | 809 // Card sets shouldn't have any other references, but nil the observer just |
| 815 // in case one somehow does end up with another ref. | 810 // in case one somehow does end up with another ref. |
| 816 [_mainCardSet setObserver:nil]; | 811 [_mainCardSet setObserver:nil]; |
| 817 [_otrCardSet setObserver:nil]; | 812 [_otrCardSet setObserver:nil]; |
| 818 [self cleanUpViewsAndNotifications]; | 813 [self cleanUpViewsAndNotifications]; |
| 819 [super dealloc]; | |
| 820 } | 814 } |
| 821 | 815 |
| 822 // Overridden to always return NO, ensuring that the status bar shows in | 816 // Overridden to always return NO, ensuring that the status bar shows in |
| 823 // landscape on iOS8. | 817 // landscape on iOS8. |
| 824 - (BOOL)prefersStatusBarHidden { | 818 - (BOOL)prefersStatusBarHidden { |
| 825 return NO; | 819 return NO; |
| 826 } | 820 } |
| 827 | 821 |
| 828 // Called when in the foreground and the OS needs more memory. Release as much | 822 // Called when in the foreground and the OS needs more memory. Release as much |
| 829 // as possible. | 823 // as possible. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 UMA_HISTOGRAM_BOOLEAN("MemoryWarning.OccurredDuringCardStackSession", | 947 UMA_HISTOGRAM_BOOLEAN("MemoryWarning.OccurredDuringCardStackSession", |
| 954 _receivedMemoryWarningInSession); | 948 _receivedMemoryWarningInSession); |
| 955 } | 949 } |
| 956 | 950 |
| 957 - (void)cleanUpViewsAndNotifications { | 951 - (void)cleanUpViewsAndNotifications { |
| 958 [_mainCardSet setDisplayView:nil]; | 952 [_mainCardSet setDisplayView:nil]; |
| 959 [_otrCardSet setDisplayView:nil]; | 953 [_otrCardSet setDisplayView:nil]; |
| 960 // Stop pre-loading cards. | 954 // Stop pre-loading cards. |
| 961 [NSObject cancelPreviousPerformRequestsWithTarget:self]; | 955 [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
| 962 [_scrollView setDelegate:nil]; | 956 [_scrollView setDelegate:nil]; |
| 963 _scrollView.reset(); | 957 _scrollView = nil; |
| 964 _backgroundView.reset(); | 958 _backgroundView = nil; |
| 965 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 959 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 966 } | 960 } |
| 967 | 961 |
| 968 - (UIStatusBarStyle)preferredStatusBarStyle { | 962 - (UIStatusBarStyle)preferredStatusBarStyle { |
| 969 // When dismissing the stack view, the status bar's style is updated when this | 963 // 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 | 964 // 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. | 965 // a non-incognito BVC, the status bar needs to use the default style. |
| 972 BOOL useDefaultStyle = _isBeingDismissed && ![self isCurrentSetIncognito]; | 966 BOOL useDefaultStyle = _isBeingDismissed && ![self isCurrentSetIncognito]; |
| 973 return useDefaultStyle ? UIStatusBarStyleDefault | 967 return useDefaultStyle ? UIStatusBarStyleDefault |
| 974 : UIStatusBarStyleLightContent; | 968 : UIStatusBarStyleLightContent; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 delay += kCascadingCardCloseDelay; | 1064 delay += kCascadingCardCloseDelay; |
| 1071 } | 1065 } |
| 1072 } | 1066 } |
| 1073 | 1067 |
| 1074 - (void)disableGestureHandlers { | 1068 - (void)disableGestureHandlers { |
| 1075 // Disable gesture handlers before modifying the stack. Don't call this too | 1069 // 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 | 1070 // late or a gesture callback could occur while still in the old state of the |
| 1077 // world. | 1071 // world. |
| 1078 // (see the comment in -cardSet:willRemoveCard:atIndex for details). | 1072 // (see the comment in -cardSet:willRemoveCard:atIndex for details). |
| 1079 [_scrollView setScrollEnabled:NO]; | 1073 [_scrollView setScrollEnabled:NO]; |
| 1080 _pinchRecognizer.get().enabled = NO; | 1074 _pinchRecognizer.enabled = NO; |
| 1081 _swipeGestureRecognizer.get().enabled = NO; | 1075 _swipeGestureRecognizer.enabled = NO; |
| 1082 } | 1076 } |
| 1083 | 1077 |
| 1084 - (void)enableGestureHandlers { | 1078 - (void)enableGestureHandlers { |
| 1085 // Reenable gesture handlers after modifying the stack. Don't call this too | 1079 // 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 | 1080 // early or a gesture callback could occur while still in the old state of the |
| 1087 // world. | 1081 // world. |
| 1088 // (see the comment in -cardSet:willRemoveCard:atIndex for details). | 1082 // (see the comment in -cardSet:willRemoveCard:atIndex for details). |
| 1089 [_scrollView setScrollEnabled:YES]; | 1083 [_scrollView setScrollEnabled:YES]; |
| 1090 _pinchRecognizer.get().enabled = YES; | 1084 _pinchRecognizer.enabled = YES; |
| 1091 _swipeGestureRecognizer.get().enabled = YES; | 1085 _swipeGestureRecognizer.enabled = YES; |
| 1092 } | 1086 } |
| 1093 | 1087 |
| 1094 - (void)activeCardCountChanged { | 1088 - (void)activeCardCountChanged { |
| 1095 // Cancel any outstanding gestures (see the comment in | 1089 // Cancel any outstanding gestures (see the comment in |
| 1096 // -cardSet:willRemoveCard:atIndex). | 1090 // -cardSet:willRemoveCard:atIndex). |
| 1097 [self disableGestureHandlers]; | 1091 [self disableGestureHandlers]; |
| 1098 [self enableGestureHandlers]; | 1092 [self enableGestureHandlers]; |
| 1099 } | 1093 } |
| 1100 | 1094 |
| 1101 - (void)setInitialCardSizing { | 1095 - (void)setInitialCardSizing { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 } | 1204 } |
| 1211 | 1205 |
| 1212 - (BOOL)bothDecksShouldBeDisplayed { | 1206 - (BOOL)bothDecksShouldBeDisplayed { |
| 1213 return [[_otrCardSet cards] count] > 0; | 1207 return [[_otrCardSet cards] count] > 0; |
| 1214 } | 1208 } |
| 1215 | 1209 |
| 1216 #pragma mark - | 1210 #pragma mark - |
| 1217 #pragma mark Current Set Handling | 1211 #pragma mark Current Set Handling |
| 1218 | 1212 |
| 1219 - (BOOL)isCurrentSetIncognito { | 1213 - (BOOL)isCurrentSetIncognito { |
| 1220 return _activeCardSet == _otrCardSet.get(); | 1214 return _activeCardSet == _otrCardSet; |
| 1221 } | 1215 } |
| 1222 | 1216 |
| 1223 - (CardSet*)inactiveCardSet { | 1217 - (CardSet*)inactiveCardSet { |
| 1224 return [self isCurrentSetIncognito] ? _mainCardSet.get() : _otrCardSet.get(); | 1218 return [self isCurrentSetIncognito] ? _mainCardSet : _otrCardSet; |
| 1225 } | 1219 } |
| 1226 | 1220 |
| 1227 - (void)setActiveCardSet:(CardSet*)cardSet { | 1221 - (void)setActiveCardSet:(CardSet*)cardSet { |
| 1228 DCHECK(cardSet); | 1222 DCHECK(cardSet); |
| 1229 if (cardSet == _activeCardSet) | 1223 if (cardSet == _activeCardSet) |
| 1230 return; | 1224 return; |
| 1231 [self activeCardCountChanged]; | 1225 [self activeCardCountChanged]; |
| 1232 _activeCardSet = cardSet; | 1226 _activeCardSet = cardSet; |
| 1233 | 1227 |
| 1234 [self displayActiveCardSet]; | 1228 [self displayActiveCardSet]; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 [_activeCardSet.currentCard setIsActiveTab:YES]; | 1461 [_activeCardSet.currentCard setIsActiveTab:YES]; |
| 1468 | 1462 |
| 1469 // When in accessbility mode, fan out cards from the start, announce open tabs | 1463 // 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 | 1464 // 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 | 1465 // 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. | 1466 // moving the VoiceOver cursor from the Show Tabs button to the card stack. |
| 1473 if (UIAccessibilityIsVoiceOverRunning()) { | 1467 if (UIAccessibilityIsVoiceOverRunning()) { |
| 1474 [_activeCardSet fanOutCardsWithStartIndex:0]; | 1468 [_activeCardSet fanOutCardsWithStartIndex:0]; |
| 1475 [self postOpenTabsAccessibilityNotification]; | 1469 [self postOpenTabsAccessibilityNotification]; |
| 1476 UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, | 1470 UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, |
| 1477 _toolbarController.get().view); | 1471 _toolbarController.view); |
| 1478 } | 1472 } |
| 1479 } | 1473 } |
| 1480 | 1474 |
| 1481 - (void)cancelTransitionAnimation { | 1475 - (void)cancelTransitionAnimation { |
| 1482 // Set up transaction. | 1476 // Set up transaction. |
| 1483 [CATransaction begin]; | 1477 [CATransaction begin]; |
| 1484 [CATransaction setCompletionBlock:^{ | 1478 [CATransaction setCompletionBlock:^{ |
| 1485 [self finishTransitionAnimation]; | 1479 [self finishTransitionAnimation]; |
| 1486 }]; | 1480 }]; |
| 1487 self.transitionWasCancelled = YES; | 1481 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; | 1572 BOOL isPresenting = self.transitionStyle == STACK_TRANSITION_STYLE_PRESENTING; |
| 1579 | 1573 |
| 1580 // Get reference to toolbar for transition. | 1574 // Get reference to toolbar for transition. |
| 1581 self.transitionToolbarOwner = [_delegate tabSwitcherTransitionToolbarOwner]; | 1575 self.transitionToolbarOwner = [_delegate tabSwitcherTransitionToolbarOwner]; |
| 1582 self.transitionToolbarController = | 1576 self.transitionToolbarController = |
| 1583 [self.transitionToolbarOwner relinquishedToolbarController]; | 1577 [self.transitionToolbarOwner relinquishedToolbarController]; |
| 1584 self.transitionToolbarController.view.animatingTransition = YES; | 1578 self.transitionToolbarController.view.animatingTransition = YES; |
| 1585 self.transitionToolbarFrame = self.transitionToolbarController.view.frame; | 1579 self.transitionToolbarFrame = self.transitionToolbarController.view.frame; |
| 1586 | 1580 |
| 1587 // Create dummy toolbar background view. | 1581 // Create dummy toolbar background view. |
| 1588 self.dummyToolbarBackgroundView = | 1582 self.dummyToolbarBackgroundView = [[UIView alloc] initWithFrame:CGRectZero]; |
| 1589 [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; | |
| 1590 [self.dummyToolbarBackgroundView setClipsToBounds:YES]; | 1583 [self.dummyToolbarBackgroundView setClipsToBounds:YES]; |
| 1591 | 1584 |
| 1592 // Set the transition completion block. | 1585 // Set the transition completion block. |
| 1593 [CATransaction begin]; | 1586 [CATransaction begin]; |
| 1594 [CATransaction setCompletionBlock:^{ | 1587 [CATransaction setCompletionBlock:^{ |
| 1595 [self finishTransitionAnimation]; | 1588 [self finishTransitionAnimation]; |
| 1596 }]; | 1589 }]; |
| 1597 | 1590 |
| 1598 // Slide in/out the inactive card set. | 1591 // Slide in/out the inactive card set. |
| 1599 [self animateInactiveSetTransition]; | 1592 [self animateInactiveSetTransition]; |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2058 inBackground:NO]; | 2051 inBackground:NO]; |
| 2059 [_activeCardSet.tabModel setCurrentTab:tab]; | 2052 [_activeCardSet.tabModel setCurrentTab:tab]; |
| 2060 | 2053 |
| 2061 [_delegate tabSwitcher:self | 2054 [_delegate tabSwitcher:self |
| 2062 dismissTransitionWillStartWithActiveModel:_activeCardSet.tabModel]; | 2055 dismissTransitionWillStartWithActiveModel:_activeCardSet.tabModel]; |
| 2063 | 2056 |
| 2064 CGFloat statusBarHeight = StatusBarHeight(); | 2057 CGFloat statusBarHeight = StatusBarHeight(); |
| 2065 CGRect viewBounds, remainder; | 2058 CGRect viewBounds, remainder; |
| 2066 CGRectDivide([self.view bounds], &remainder, &viewBounds, statusBarHeight, | 2059 CGRectDivide([self.view bounds], &remainder, &viewBounds, statusBarHeight, |
| 2067 CGRectMinYEdge); | 2060 CGRectMinYEdge); |
| 2068 UIImageView* newCard = | 2061 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 | 2062 // Temporarily resize the tab's view to ensure it matches the card while |
| 2071 // generating a snapshot, but then restore the original frame. | 2063 // generating a snapshot, but then restore the original frame. |
| 2072 CGRect originalTabFrame = [tab view].frame; | 2064 CGRect originalTabFrame = [tab view].frame; |
| 2073 [tab view].frame = viewBounds; | 2065 [tab view].frame = viewBounds; |
| 2074 newCard.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 2066 newCard.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| 2075 [tab view].frame = originalTabFrame; | 2067 [tab view].frame = originalTabFrame; |
| 2076 newCard.center = | 2068 newCard.center = |
| 2077 CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds)); | 2069 CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds)); |
| 2078 [self.view addSubview:newCard]; | 2070 [self.view addSubview:newCard]; |
| 2079 | 2071 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2105 | 2097 |
| 2106 #pragma mark UIGestureRecognizerDelegate methods | 2098 #pragma mark UIGestureRecognizerDelegate methods |
| 2107 | 2099 |
| 2108 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)recognizer | 2100 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)recognizer |
| 2109 shouldReceiveTouch:(UITouch*)touch { | 2101 shouldReceiveTouch:(UITouch*)touch { |
| 2110 // Don't swallow any touches while the tools popup menu is open. | 2102 // Don't swallow any touches while the tools popup menu is open. |
| 2111 if ([_toolbarController toolsPopupController]) | 2103 if ([_toolbarController toolsPopupController]) |
| 2112 return NO; | 2104 return NO; |
| 2113 | 2105 |
| 2114 if ((recognizer == _pinchRecognizer) || | 2106 if ((recognizer == _pinchRecognizer) || |
| 2115 (recognizer == _swipeGestureRecognizer.get())) | 2107 (recognizer == _swipeGestureRecognizer)) |
| 2116 return YES; | 2108 return YES; |
| 2117 | 2109 |
| 2118 // Only the mode switch recognizer should be triggered in the inactive deck | 2110 // Only the mode switch recognizer should be triggered in the inactive deck |
| 2119 // region (and it should only be triggered there). | 2111 // region (and it should only be triggered there). |
| 2120 CGPoint touchLocation = [touch locationInView:_scrollView]; | 2112 CGPoint touchLocation = [touch locationInView:_scrollView]; |
| 2121 BOOL inInactiveDeckRegion = | 2113 BOOL inInactiveDeckRegion = |
| 2122 CGRectContainsPoint([self inactiveDeckRegion], touchLocation); | 2114 CGRectContainsPoint([self inactiveDeckRegion], touchLocation); |
| 2123 if (recognizer == _modeSwitchRecognizer.get()) | 2115 if (recognizer == _modeSwitchRecognizer) |
| 2124 return inInactiveDeckRegion; | 2116 return inInactiveDeckRegion; |
| 2125 else if (inInactiveDeckRegion) | 2117 else if (inInactiveDeckRegion) |
| 2126 return NO; | 2118 return NO; |
| 2127 | 2119 |
| 2128 // Extract the card on which the touch is occurring. | 2120 // Extract the card on which the touch is occurring. |
| 2129 CardView* cardView = nil; | 2121 CardView* cardView = nil; |
| 2130 StackCard* card = nil; | 2122 StackCard* card = nil; |
| 2131 if (recognizer == _swipeDismissesCardRecognizer.get()) { | 2123 if (recognizer == _swipeDismissesCardRecognizer) { |
| 2132 UIView* activeView = _activeCardSet.displayView; | 2124 UIView* activeView = _activeCardSet.displayView; |
| 2133 CGPoint locationInActiveView = [touch locationInView:activeView]; | 2125 CGPoint locationInActiveView = [touch locationInView:activeView]; |
| 2134 NSUInteger cardIndex = [self indexOfCardAtPoint:locationInActiveView]; | 2126 NSUInteger cardIndex = [self indexOfCardAtPoint:locationInActiveView]; |
| 2135 // |_swipeDismissesCardRecognizer| is interested only in touches that are | 2127 // |_swipeDismissesCardRecognizer| is interested only in touches that are |
| 2136 // on cards in the active set. | 2128 // on cards in the active set. |
| 2137 if (cardIndex == NSNotFound) | 2129 if (cardIndex == NSNotFound) |
| 2138 return NO; | 2130 return NO; |
| 2139 DCHECK(cardIndex < [[_activeCardSet cards] count]); | 2131 DCHECK(cardIndex < [[_activeCardSet cards] count]); |
| 2140 card = [[_activeCardSet cards] objectAtIndex:cardIndex]; | 2132 card = [[_activeCardSet cards] objectAtIndex:cardIndex]; |
| 2141 // This case seems like it should never happen, but it can be easily | 2133 // 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); | 2165 otherGestureRecognizer == _scrollGestureRecognizer); |
| 2174 if (pinchRecognizerInvolved && scrollRecognizerInvolved) | 2166 if (pinchRecognizerInvolved && scrollRecognizerInvolved) |
| 2175 return YES; | 2167 return YES; |
| 2176 | 2168 |
| 2177 // Swiping must be allowed to recognize simultaneously with the recognizer of | 2169 // Swiping must be allowed to recognize simultaneously with the recognizer of |
| 2178 // long presses that turn ambiguous swipes into card dismissals. | 2170 // long presses that turn ambiguous swipes into card dismissals. |
| 2179 BOOL swipeRecognizerInvolved = | 2171 BOOL swipeRecognizerInvolved = |
| 2180 (gestureRecognizer == _swipeGestureRecognizer || | 2172 (gestureRecognizer == _swipeGestureRecognizer || |
| 2181 otherGestureRecognizer == _swipeGestureRecognizer); | 2173 otherGestureRecognizer == _swipeGestureRecognizer); |
| 2182 BOOL swipeDismissesCardRecognizerInvolved = | 2174 BOOL swipeDismissesCardRecognizerInvolved = |
| 2183 (gestureRecognizer == _swipeDismissesCardRecognizer.get() || | 2175 (gestureRecognizer == _swipeDismissesCardRecognizer || |
| 2184 otherGestureRecognizer == _swipeDismissesCardRecognizer.get()); | 2176 otherGestureRecognizer == _swipeDismissesCardRecognizer); |
| 2185 if (swipeRecognizerInvolved && swipeDismissesCardRecognizerInvolved) | 2177 if (swipeRecognizerInvolved && swipeDismissesCardRecognizerInvolved) |
| 2186 return YES; | 2178 return YES; |
| 2187 | 2179 |
| 2188 // The swipe-triggers-card-dismissal long press recognizer must be allowed to | 2180 // The swipe-triggers-card-dismissal long press recognizer must be allowed to |
| 2189 // recognize simultaneously with the cards' long press recognizers that | 2181 // recognize simultaneously with the cards' long press recognizers that |
| 2190 // trigger show-more-of-card. | 2182 // trigger show-more-of-card. |
| 2191 BOOL longPressRecognizerInvolved = | 2183 BOOL longPressRecognizerInvolved = |
| 2192 ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || | 2184 ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || |
| 2193 [otherGestureRecognizer | 2185 [otherGestureRecognizer |
| 2194 isKindOfClass:[UILongPressGestureRecognizer class]]); | 2186 isKindOfClass:[UILongPressGestureRecognizer class]]); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2237 else | 2229 else |
| 2238 DLOG(ERROR) << "Closed card at an index out of range of the tab model"; | 2230 DLOG(ERROR) << "Closed card at an index out of range of the tab model"; |
| 2239 [_activeCardSet removeCardAtIndex:tabIndex]; | 2231 [_activeCardSet removeCardAtIndex:tabIndex]; |
| 2240 } | 2232 } |
| 2241 } | 2233 } |
| 2242 | 2234 |
| 2243 - (void)handleLongPressFrom:(UIGestureRecognizer*)recognizer { | 2235 - (void)handleLongPressFrom:(UIGestureRecognizer*)recognizer { |
| 2244 DCHECK(!_isBeingDismissed); | 2236 DCHECK(!_isBeingDismissed); |
| 2245 DCHECK(_isActive); | 2237 DCHECK(_isActive); |
| 2246 | 2238 |
| 2247 if (recognizer == _swipeDismissesCardRecognizer.get()) | 2239 if (recognizer == _swipeDismissesCardRecognizer) |
| 2248 return; | 2240 return; |
| 2249 | 2241 |
| 2250 UIGestureRecognizerState state = [recognizer state]; | 2242 UIGestureRecognizerState state = [recognizer state]; |
| 2251 if (state != UIGestureRecognizerStateBegan) | 2243 if (state != UIGestureRecognizerStateBegan) |
| 2252 return; | 2244 return; |
| 2253 if ([recognizer numberOfTouches] == 0) | 2245 if ([recognizer numberOfTouches] == 0) |
| 2254 return; | 2246 return; |
| 2255 | 2247 |
| 2256 // Don't take action on a card that is in the inactive stack, collapsed, or | 2248 // Don't take action on a card that is in the inactive stack, collapsed, or |
| 2257 // the last card. | 2249 // the last card. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2412 [_gestureStateTracker setPreviousFirstPinchOffset:firstOffset]; | 2404 [_gestureStateTracker setPreviousFirstPinchOffset:firstOffset]; |
| 2413 [_gestureStateTracker setPreviousSecondPinchOffset:secondOffset]; | 2405 [_gestureStateTracker setPreviousSecondPinchOffset:secondOffset]; |
| 2414 } | 2406 } |
| 2415 | 2407 |
| 2416 - (void)handleTapFrom:(UITapGestureRecognizer*)recognizer { | 2408 - (void)handleTapFrom:(UITapGestureRecognizer*)recognizer { |
| 2417 DCHECK(!_isBeingDismissed); | 2409 DCHECK(!_isBeingDismissed); |
| 2418 DCHECK(_isActive); | 2410 DCHECK(_isActive); |
| 2419 if (recognizer.state != UIGestureRecognizerStateEnded) | 2411 if (recognizer.state != UIGestureRecognizerStateEnded) |
| 2420 return; | 2412 return; |
| 2421 | 2413 |
| 2422 if (recognizer == _modeSwitchRecognizer.get()) { | 2414 if (recognizer == _modeSwitchRecognizer) { |
| 2423 DCHECK(CGRectContainsPoint([self inactiveDeckRegion], | 2415 DCHECK(CGRectContainsPoint([self inactiveDeckRegion], |
| 2424 [recognizer locationInView:_scrollView])); | 2416 [recognizer locationInView:_scrollView])); |
| 2425 [self setActiveCardSet:[self inactiveCardSet]]; | 2417 [self setActiveCardSet:[self inactiveCardSet]]; |
| 2426 return; | 2418 return; |
| 2427 } | 2419 } |
| 2428 | 2420 |
| 2429 CardView* cardView = (CardView*)recognizer.view; | 2421 CardView* cardView = (CardView*)recognizer.view; |
| 2430 UIView* activeView = _activeCardSet.displayView; | 2422 UIView* activeView = _activeCardSet.displayView; |
| 2431 if ([cardView superview] != activeView) | 2423 if ([cardView superview] != activeView) |
| 2432 return; | 2424 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, | 2644 // 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 | 2645 // and the card's tab to become transparent at the time that the card |
| 2654 // reaches the threshold for being dismissed. | 2646 // reaches the threshold for being dismissed. |
| 2655 [card view].alpha = 1 - fractionOfAnimationBreadth; | 2647 [card view].alpha = 1 - fractionOfAnimationBreadth; |
| 2656 } else { | 2648 } else { |
| 2657 if (gesture.state == UIGestureRecognizerStateEnded && | 2649 if (gesture.state == UIGestureRecognizerStateEnded && |
| 2658 [self swipeShouldTriggerAction:position]) { | 2650 [self swipeShouldTriggerAction:position]) { |
| 2659 // Track card if animation should dismiss in reverse from the norm of | 2651 // Track card if animation should dismiss in reverse from the norm of |
| 2660 // clockwise in portrait, counter-clockwise in landscape. | 2652 // clockwise in portrait, counter-clockwise in landscape. |
| 2661 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) | 2653 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) |
| 2662 _reverseDismissCard.reset([card retain]); | 2654 _reverseDismissCard = card; |
| 2663 // This will trigger the completion of the close card animation. | 2655 // This will trigger the completion of the close card animation. |
| 2664 [self closeTab:card.view]; | 2656 [self closeTab:card.view]; |
| 2665 } else { | 2657 } else { |
| 2666 // Animate back to starting position. | 2658 // Animate back to starting position. |
| 2667 [UIView animateWithDuration:kDefaultAnimationDuration | 2659 [UIView animateWithDuration:kDefaultAnimationDuration |
| 2668 delay:0 | 2660 delay:0 |
| 2669 options:UIViewAnimationCurveEaseOut | 2661 options:UIViewAnimationCurveEaseOut |
| 2670 animations:^{ | 2662 animations:^{ |
| 2671 [card view].alpha = 1; | 2663 [card view].alpha = 1; |
| 2672 [[card view] setTabOpacity:1]; | 2664 [[card view] setTabOpacity:1]; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2722 case IDC_TOGGLE_TAB_SWITCHER: | 2714 case IDC_TOGGLE_TAB_SWITCHER: |
| 2723 [self dismissWithSelectedTabAnimation]; | 2715 [self dismissWithSelectedTabAnimation]; |
| 2724 break; | 2716 break; |
| 2725 default: | 2717 default: |
| 2726 [super chromeExecuteCommand:sender]; | 2718 [super chromeExecuteCommand:sender]; |
| 2727 break; | 2719 break; |
| 2728 } | 2720 } |
| 2729 } | 2721 } |
| 2730 | 2722 |
| 2731 - (void)showToolsMenuPopup { | 2723 - (void)showToolsMenuPopup { |
| 2732 base::scoped_nsobject<ToolsMenuConfiguration> configuration( | 2724 ToolsMenuConfiguration* configuration = |
| 2733 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]); | 2725 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; |
| 2734 [configuration setInTabSwitcher:YES]; | 2726 [configuration setInTabSwitcher:YES]; |
| 2735 // When checking for the existence of tabs, catch the case where the main set | 2727 // 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. | 2728 // is both active and empty, but the incognito set has some cards. |
| 2737 if (([[_activeCardSet cards] count] == 0) && | 2729 if (([[_activeCardSet cards] count] == 0) && |
| 2738 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) | 2730 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) |
| 2739 [configuration setNoOpenedTabs:YES]; | 2731 [configuration setNoOpenedTabs:YES]; |
| 2740 if (_activeCardSet == _otrCardSet) | 2732 if (_activeCardSet == _otrCardSet) |
| 2741 [configuration setInIncognito:YES]; | 2733 [configuration setInIncognito:YES]; |
| 2742 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; | 2734 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
| 2743 } | 2735 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2912 BOOL isPortrait = | 2904 BOOL isPortrait = |
| 2913 UIInterfaceOrientationIsPortrait(_lastInterfaceOrientation); | 2905 UIInterfaceOrientationIsPortrait(_lastInterfaceOrientation); |
| 2914 BOOL clockwise = isPortrait ? _reverseDismissCard != removedCard | 2906 BOOL clockwise = isPortrait ? _reverseDismissCard != removedCard |
| 2915 : _reverseDismissCard == removedCard; | 2907 : _reverseDismissCard == removedCard; |
| 2916 [self animateOutCardView:removedCard.view | 2908 [self animateOutCardView:removedCard.view |
| 2917 delay:0 | 2909 delay:0 |
| 2918 clockwise:clockwise | 2910 clockwise:clockwise |
| 2919 completion:nil]; | 2911 completion:nil]; |
| 2920 // Reset |reverseDismissCard| if that card was the one dismissed. | 2912 // Reset |reverseDismissCard| if that card was the one dismissed. |
| 2921 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) | 2913 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) |
| 2922 _reverseDismissCard.reset(); | 2914 _reverseDismissCard = nil; |
| 2923 } | 2915 } |
| 2924 // Nil out the the closing card after all closing animations have finished. | 2916 // Nil out the the closing card after all closing animations have finished. |
| 2925 [CATransaction begin]; | 2917 [CATransaction begin]; |
| 2926 [CATransaction setCompletionBlock:^{ | 2918 [CATransaction setCompletionBlock:^{ |
| 2927 cardSet.closingCard = nil; | 2919 cardSet.closingCard = nil; |
| 2928 }]; | 2920 }]; |
| 2929 // If the last incognito card closes, switch back to just the main set. | 2921 // If the last incognito card closes, switch back to just the main set. |
| 2930 if ([cardSet.cards count] == 0 && cardSet == _otrCardSet.get()) { | 2922 if ([cardSet.cards count] == 0 && cardSet == _otrCardSet) { |
| 2931 [self displayMainCardSetOnly]; | 2923 [self displayMainCardSetOnly]; |
| 2932 } else { | 2924 } else { |
| 2933 NSUInteger numCards = [[cardSet cards] count]; | 2925 NSUInteger numCards = [[cardSet cards] count]; |
| 2934 if (numCards == 0) { | 2926 if (numCards == 0) { |
| 2935 // Commit the transaction before early return. | 2927 // Commit the transaction before early return. |
| 2936 [CATransaction commit]; | 2928 [CATransaction commit]; |
| 2937 return; | 2929 return; |
| 2938 } | 2930 } |
| 2939 if (index == numCards) { | 2931 if (index == numCards) { |
| 2940 // If the card that was closed was the last card and was in the start | 2932 // If the card that was closed was the last card and was in the start |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2969 } | 2961 } |
| 2970 [CATransaction commit]; | 2962 [CATransaction commit]; |
| 2971 } | 2963 } |
| 2972 | 2964 |
| 2973 - (void)cardSet:(CardSet*)cardSet displayedCard:(StackCard*)card { | 2965 - (void)cardSet:(CardSet*)cardSet displayedCard:(StackCard*)card { |
| 2974 // Add gesture recognizers to the card. | 2966 // Add gesture recognizers to the card. |
| 2975 [card.view addCardCloseTarget:self action:@selector(closeTab:)]; | 2967 [card.view addCardCloseTarget:self action:@selector(closeTab:)]; |
| 2976 [card.view addAccessibilityTarget:self | 2968 [card.view addAccessibilityTarget:self |
| 2977 action:@selector(accessibilityFocusedOnElement:)]; | 2969 action:@selector(accessibilityFocusedOnElement:)]; |
| 2978 | 2970 |
| 2979 base::scoped_nsobject<UIGestureRecognizer> tapRecognizer([ | 2971 UIGestureRecognizer* tapRecognizer = |
| 2980 [UITapGestureRecognizer alloc] initWithTarget:self | 2972 [[UITapGestureRecognizer alloc] initWithTarget:self |
| 2981 action:@selector(handleTapFrom:)]); | 2973 action:@selector(handleTapFrom:)]; |
| 2982 tapRecognizer.get().delegate = self; | 2974 tapRecognizer.delegate = self; |
| 2983 [card.view addGestureRecognizer:tapRecognizer.get()]; | 2975 [card.view addGestureRecognizer:tapRecognizer]; |
| 2984 | 2976 |
| 2985 base::scoped_nsobject<UIGestureRecognizer> longPressRecognizer( | 2977 UIGestureRecognizer* longPressRecognizer = |
| 2986 [[UILongPressGestureRecognizer alloc] | 2978 [[UILongPressGestureRecognizer alloc] |
| 2987 initWithTarget:self | 2979 initWithTarget:self |
| 2988 action:@selector(handleLongPressFrom:)]); | 2980 action:@selector(handleLongPressFrom:)]; |
| 2989 longPressRecognizer.get().delegate = self; | 2981 longPressRecognizer.delegate = self; |
| 2990 [card.view addGestureRecognizer:longPressRecognizer.get()]; | 2982 [card.view addGestureRecognizer:longPressRecognizer]; |
| 2991 } | 2983 } |
| 2992 | 2984 |
| 2993 - (void)cardSetRecreatedCards:(CardSet*)cardSet { | 2985 - (void)cardSetRecreatedCards:(CardSet*)cardSet { |
| 2994 // Remove the old card views, if any, then start loading the new ones. | 2986 // Remove the old card views, if any, then start loading the new ones. |
| 2995 for (UIView* card in [cardSet.displayView subviews]) { | 2987 for (UIView* card in [cardSet.displayView subviews]) { |
| 2996 [card removeFromSuperview]; | 2988 [card removeFromSuperview]; |
| 2997 } | 2989 } |
| 2998 [self preloadCardViewsAsynchronously]; | 2990 [self preloadCardViewsAsynchronously]; |
| 2999 } | 2991 } |
| 3000 | 2992 |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3466 // the cards out starting with that card. | 3458 // the cards out starting with that card. |
| 3467 [_activeCardSet fanOutCardsWithStartIndex:index]; | 3459 [_activeCardSet fanOutCardsWithStartIndex:index]; |
| 3468 [card.view postAccessibilityNotification]; | 3460 [card.view postAccessibilityNotification]; |
| 3469 [self postOpenTabsAccessibilityNotification]; | 3461 [self postOpenTabsAccessibilityNotification]; |
| 3470 } | 3462 } |
| 3471 } | 3463 } |
| 3472 | 3464 |
| 3473 #pragma mark - UIResponder | 3465 #pragma mark - UIResponder |
| 3474 | 3466 |
| 3475 - (NSArray*)keyCommands { | 3467 - (NSArray*)keyCommands { |
| 3476 base::WeakNSObject<StackViewController> weakSelf(self); | 3468 __weak StackViewController* weakSelf = self; |
| 3477 | 3469 |
| 3478 // Block to execute a command from the |tag|. | 3470 // Block to execute a command from the |tag|. |
| 3479 base::mac::ScopedBlock<void (^)(NSInteger)> execute( | 3471 void (^execute)(NSInteger) = ^(NSInteger tag) { |
| 3480 ^(NSInteger tag) { | 3472 [weakSelf chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]]; |
| 3481 [weakSelf | 3473 }; |
| 3482 chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]]; | |
| 3483 }, | |
| 3484 base::scoped_policy::RETAIN); | |
| 3485 | 3474 |
| 3486 return @[ | 3475 return @[ |
| 3487 [UIKeyCommand cr_keyCommandWithInput:@"t" | 3476 [UIKeyCommand cr_keyCommandWithInput:@"t" |
| 3488 modifierFlags:UIKeyModifierCommand | 3477 modifierFlags:UIKeyModifierCommand |
| 3489 title:l10n_util::GetNSStringWithFixup( | 3478 title:l10n_util::GetNSStringWithFixup( |
| 3490 IDS_IOS_TOOLS_MENU_NEW_TAB) | 3479 IDS_IOS_TOOLS_MENU_NEW_TAB) |
| 3491 action:^{ | 3480 action:^{ |
| 3492 if ([weakSelf isCurrentSetIncognito]) | 3481 if ([weakSelf isCurrentSetIncognito]) |
| 3493 execute.get()(IDC_NEW_INCOGNITO_TAB); | 3482 execute(IDC_NEW_INCOGNITO_TAB); |
| 3494 else | 3483 else |
| 3495 execute.get()(IDC_NEW_TAB); | 3484 execute(IDC_NEW_TAB); |
| 3496 }], | 3485 }], |
| 3497 [UIKeyCommand | 3486 [UIKeyCommand |
| 3498 cr_keyCommandWithInput:@"n" | 3487 cr_keyCommandWithInput:@"n" |
| 3499 modifierFlags:UIKeyModifierCommand | UIKeyModifierShift | 3488 modifierFlags:UIKeyModifierCommand | UIKeyModifierShift |
| 3500 title:l10n_util::GetNSStringWithFixup( | 3489 title:l10n_util::GetNSStringWithFixup( |
| 3501 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB) | 3490 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB) |
| 3502 action:^{ | 3491 action:^{ |
| 3503 execute.get()(IDC_NEW_INCOGNITO_TAB); | 3492 execute(IDC_NEW_INCOGNITO_TAB); |
| 3504 }], | 3493 }], |
| 3505 [UIKeyCommand cr_keyCommandWithInput:@"n" | 3494 [UIKeyCommand cr_keyCommandWithInput:@"n" |
| 3506 modifierFlags:UIKeyModifierCommand | 3495 modifierFlags:UIKeyModifierCommand |
| 3507 title:nil | 3496 title:nil |
| 3508 action:^{ | 3497 action:^{ |
| 3509 if ([weakSelf isCurrentSetIncognito]) | 3498 if ([weakSelf isCurrentSetIncognito]) |
| 3510 execute.get()(IDC_NEW_INCOGNITO_TAB); | 3499 execute(IDC_NEW_INCOGNITO_TAB); |
| 3511 else | 3500 else |
| 3512 execute.get()(IDC_NEW_TAB); | 3501 execute(IDC_NEW_TAB); |
| 3513 }], | 3502 }], |
| 3514 ]; | 3503 ]; |
| 3515 } | 3504 } |
| 3516 | 3505 |
| 3517 @end | 3506 @end |
| 3518 | 3507 |
| 3519 @implementation StackViewController (Testing) | 3508 @implementation StackViewController (Testing) |
| 3520 | 3509 |
| 3521 - (UIScrollView*)scrollView { | 3510 - (UIScrollView*)scrollView { |
| 3522 return _scrollView.get(); | 3511 return _scrollView; |
| 3523 } | 3512 } |
| 3524 | 3513 |
| 3525 @end | 3514 @end |
| OLD | NEW |