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_configuration.h" | 49 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
52 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" | 50 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" |
53 #import "ios/chrome/browser/ui/ui_util.h" | 51 #import "ios/chrome/browser/ui/ui_util.h" |
54 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 52 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
55 #import "ios/chrome/common/material_timing.h" | 53 #import "ios/chrome/common/material_timing.h" |
56 #include "ios/chrome/grit/ios_strings.h" | 54 #include "ios/chrome/grit/ios_strings.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 CardSet* __weak _activeCardSet; // weak |
marq (ping after 24h)
2017/04/13 17:17:27
Please be consistent with the positioning of stora
stkhapugin
2017/04/14 09:44:29
Done.
Once a week, ARCMigrate decides to be nice
| |
453 id<TabSwitcherDelegate> _delegate; // weak | 455 id<TabSwitcherDelegate> __weak _delegate; // weak |
454 id<StackViewControllerTestDelegate> _testDelegate; // weak | 456 id<StackViewControllerTestDelegate> __weak _testDelegate; // weak |
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; // weak |
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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2054 inBackground:NO]; | 2043 inBackground:NO]; |
2055 [_activeCardSet.tabModel setCurrentTab:tab]; | 2044 [_activeCardSet.tabModel setCurrentTab:tab]; |
2056 | 2045 |
2057 [_delegate tabSwitcher:self | 2046 [_delegate tabSwitcher:self |
2058 dismissTransitionWillStartWithActiveModel:_activeCardSet.tabModel]; | 2047 dismissTransitionWillStartWithActiveModel:_activeCardSet.tabModel]; |
2059 | 2048 |
2060 CGFloat statusBarHeight = StatusBarHeight(); | 2049 CGFloat statusBarHeight = StatusBarHeight(); |
2061 CGRect viewBounds, remainder; | 2050 CGRect viewBounds, remainder; |
2062 CGRectDivide([self.view bounds], &remainder, &viewBounds, statusBarHeight, | 2051 CGRectDivide([self.view bounds], &remainder, &viewBounds, statusBarHeight, |
2063 CGRectMinYEdge); | 2052 CGRectMinYEdge); |
2064 UIImageView* newCard = | 2053 UIImageView* newCard = [[UIImageView alloc] initWithFrame:viewBounds]; |
2065 [[[UIImageView alloc] initWithFrame:viewBounds] autorelease]; | |
2066 // Temporarily resize the tab's view to ensure it matches the card while | 2054 // Temporarily resize the tab's view to ensure it matches the card while |
2067 // generating a snapshot, but then restore the original frame. | 2055 // generating a snapshot, but then restore the original frame. |
2068 CGRect originalTabFrame = [tab view].frame; | 2056 CGRect originalTabFrame = [tab view].frame; |
2069 [tab view].frame = viewBounds; | 2057 [tab view].frame = viewBounds; |
2070 newCard.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 2058 newCard.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
2071 [tab view].frame = originalTabFrame; | 2059 [tab view].frame = originalTabFrame; |
2072 newCard.center = | 2060 newCard.center = |
2073 CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds)); | 2061 CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds)); |
2074 [self.view addSubview:newCard]; | 2062 [self.view addSubview:newCard]; |
2075 | 2063 |
(...skipping 16 matching lines...) Expand all Loading... | |
2092 | 2080 |
2093 #pragma mark UIGestureRecognizerDelegate methods | 2081 #pragma mark UIGestureRecognizerDelegate methods |
2094 | 2082 |
2095 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)recognizer | 2083 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)recognizer |
2096 shouldReceiveTouch:(UITouch*)touch { | 2084 shouldReceiveTouch:(UITouch*)touch { |
2097 // Don't swallow any touches while the tools popup menu is open. | 2085 // Don't swallow any touches while the tools popup menu is open. |
2098 if ([_toolbarController toolsPopupController]) | 2086 if ([_toolbarController toolsPopupController]) |
2099 return NO; | 2087 return NO; |
2100 | 2088 |
2101 if ((recognizer == _pinchRecognizer) || | 2089 if ((recognizer == _pinchRecognizer) || |
2102 (recognizer == _swipeGestureRecognizer.get())) | 2090 (recognizer == _swipeGestureRecognizer)) |
2103 return YES; | 2091 return YES; |
2104 | 2092 |
2105 // Only the mode switch recognizer should be triggered in the inactive deck | 2093 // Only the mode switch recognizer should be triggered in the inactive deck |
2106 // region (and it should only be triggered there). | 2094 // region (and it should only be triggered there). |
2107 CGPoint touchLocation = [touch locationInView:_scrollView]; | 2095 CGPoint touchLocation = [touch locationInView:_scrollView]; |
2108 BOOL inInactiveDeckRegion = | 2096 BOOL inInactiveDeckRegion = |
2109 CGRectContainsPoint([self inactiveDeckRegion], touchLocation); | 2097 CGRectContainsPoint([self inactiveDeckRegion], touchLocation); |
2110 if (recognizer == _modeSwitchRecognizer.get()) | 2098 if (recognizer == _modeSwitchRecognizer) |
2111 return inInactiveDeckRegion; | 2099 return inInactiveDeckRegion; |
2112 else if (inInactiveDeckRegion) | 2100 else if (inInactiveDeckRegion) |
2113 return NO; | 2101 return NO; |
2114 | 2102 |
2115 // Extract the card on which the touch is occurring. | 2103 // Extract the card on which the touch is occurring. |
2116 CardView* cardView = nil; | 2104 CardView* cardView = nil; |
2117 StackCard* card = nil; | 2105 StackCard* card = nil; |
2118 if (recognizer == _swipeDismissesCardRecognizer.get()) { | 2106 if (recognizer == _swipeDismissesCardRecognizer) { |
2119 UIView* activeView = _activeCardSet.displayView; | 2107 UIView* activeView = _activeCardSet.displayView; |
2120 CGPoint locationInActiveView = [touch locationInView:activeView]; | 2108 CGPoint locationInActiveView = [touch locationInView:activeView]; |
2121 NSUInteger cardIndex = [self indexOfCardAtPoint:locationInActiveView]; | 2109 NSUInteger cardIndex = [self indexOfCardAtPoint:locationInActiveView]; |
2122 // |_swipeDismissesCardRecognizer| is interested only in touches that are | 2110 // |_swipeDismissesCardRecognizer| is interested only in touches that are |
2123 // on cards in the active set. | 2111 // on cards in the active set. |
2124 if (cardIndex == NSNotFound) | 2112 if (cardIndex == NSNotFound) |
2125 return NO; | 2113 return NO; |
2126 DCHECK(cardIndex < [[_activeCardSet cards] count]); | 2114 DCHECK(cardIndex < [[_activeCardSet cards] count]); |
2127 card = [[_activeCardSet cards] objectAtIndex:cardIndex]; | 2115 card = [[_activeCardSet cards] objectAtIndex:cardIndex]; |
2128 // This case seems like it should never happen, but it can be easily | 2116 // 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... | |
2160 otherGestureRecognizer == _scrollGestureRecognizer); | 2148 otherGestureRecognizer == _scrollGestureRecognizer); |
2161 if (pinchRecognizerInvolved && scrollRecognizerInvolved) | 2149 if (pinchRecognizerInvolved && scrollRecognizerInvolved) |
2162 return YES; | 2150 return YES; |
2163 | 2151 |
2164 // Swiping must be allowed to recognize simultaneously with the recognizer of | 2152 // Swiping must be allowed to recognize simultaneously with the recognizer of |
2165 // long presses that turn ambiguous swipes into card dismissals. | 2153 // long presses that turn ambiguous swipes into card dismissals. |
2166 BOOL swipeRecognizerInvolved = | 2154 BOOL swipeRecognizerInvolved = |
2167 (gestureRecognizer == _swipeGestureRecognizer || | 2155 (gestureRecognizer == _swipeGestureRecognizer || |
2168 otherGestureRecognizer == _swipeGestureRecognizer); | 2156 otherGestureRecognizer == _swipeGestureRecognizer); |
2169 BOOL swipeDismissesCardRecognizerInvolved = | 2157 BOOL swipeDismissesCardRecognizerInvolved = |
2170 (gestureRecognizer == _swipeDismissesCardRecognizer.get() || | 2158 (gestureRecognizer == _swipeDismissesCardRecognizer || |
2171 otherGestureRecognizer == _swipeDismissesCardRecognizer.get()); | 2159 otherGestureRecognizer == _swipeDismissesCardRecognizer); |
2172 if (swipeRecognizerInvolved && swipeDismissesCardRecognizerInvolved) | 2160 if (swipeRecognizerInvolved && swipeDismissesCardRecognizerInvolved) |
2173 return YES; | 2161 return YES; |
2174 | 2162 |
2175 // The swipe-triggers-card-dismissal long press recognizer must be allowed to | 2163 // The swipe-triggers-card-dismissal long press recognizer must be allowed to |
2176 // recognize simultaneously with the cards' long press recognizers that | 2164 // recognize simultaneously with the cards' long press recognizers that |
2177 // trigger show-more-of-card. | 2165 // trigger show-more-of-card. |
2178 BOOL longPressRecognizerInvolved = | 2166 BOOL longPressRecognizerInvolved = |
2179 ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || | 2167 ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || |
2180 [otherGestureRecognizer | 2168 [otherGestureRecognizer |
2181 isKindOfClass:[UILongPressGestureRecognizer class]]); | 2169 isKindOfClass:[UILongPressGestureRecognizer class]]); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2224 else | 2212 else |
2225 DLOG(ERROR) << "Closed card at an index out of range of the tab model"; | 2213 DLOG(ERROR) << "Closed card at an index out of range of the tab model"; |
2226 [_activeCardSet removeCardAtIndex:tabIndex]; | 2214 [_activeCardSet removeCardAtIndex:tabIndex]; |
2227 } | 2215 } |
2228 } | 2216 } |
2229 | 2217 |
2230 - (void)handleLongPressFrom:(UIGestureRecognizer*)recognizer { | 2218 - (void)handleLongPressFrom:(UIGestureRecognizer*)recognizer { |
2231 DCHECK(!_isBeingDismissed); | 2219 DCHECK(!_isBeingDismissed); |
2232 DCHECK(_isActive); | 2220 DCHECK(_isActive); |
2233 | 2221 |
2234 if (recognizer == _swipeDismissesCardRecognizer.get()) | 2222 if (recognizer == _swipeDismissesCardRecognizer) |
2235 return; | 2223 return; |
2236 | 2224 |
2237 UIGestureRecognizerState state = [recognizer state]; | 2225 UIGestureRecognizerState state = [recognizer state]; |
2238 if (state != UIGestureRecognizerStateBegan) | 2226 if (state != UIGestureRecognizerStateBegan) |
2239 return; | 2227 return; |
2240 if ([recognizer numberOfTouches] == 0) | 2228 if ([recognizer numberOfTouches] == 0) |
2241 return; | 2229 return; |
2242 | 2230 |
2243 // Don't take action on a card that is in the inactive stack, collapsed, or | 2231 // Don't take action on a card that is in the inactive stack, collapsed, or |
2244 // the last card. | 2232 // the last card. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2399 [_gestureStateTracker setPreviousFirstPinchOffset:firstOffset]; | 2387 [_gestureStateTracker setPreviousFirstPinchOffset:firstOffset]; |
2400 [_gestureStateTracker setPreviousSecondPinchOffset:secondOffset]; | 2388 [_gestureStateTracker setPreviousSecondPinchOffset:secondOffset]; |
2401 } | 2389 } |
2402 | 2390 |
2403 - (void)handleTapFrom:(UITapGestureRecognizer*)recognizer { | 2391 - (void)handleTapFrom:(UITapGestureRecognizer*)recognizer { |
2404 DCHECK(!_isBeingDismissed); | 2392 DCHECK(!_isBeingDismissed); |
2405 DCHECK(_isActive); | 2393 DCHECK(_isActive); |
2406 if (recognizer.state != UIGestureRecognizerStateEnded) | 2394 if (recognizer.state != UIGestureRecognizerStateEnded) |
2407 return; | 2395 return; |
2408 | 2396 |
2409 if (recognizer == _modeSwitchRecognizer.get()) { | 2397 if (recognizer == _modeSwitchRecognizer) { |
2410 DCHECK(CGRectContainsPoint([self inactiveDeckRegion], | 2398 DCHECK(CGRectContainsPoint([self inactiveDeckRegion], |
2411 [recognizer locationInView:_scrollView])); | 2399 [recognizer locationInView:_scrollView])); |
2412 [self setActiveCardSet:[self inactiveCardSet]]; | 2400 [self setActiveCardSet:[self inactiveCardSet]]; |
2413 return; | 2401 return; |
2414 } | 2402 } |
2415 | 2403 |
2416 CardView* cardView = (CardView*)recognizer.view; | 2404 CardView* cardView = (CardView*)recognizer.view; |
2417 UIView* activeView = _activeCardSet.displayView; | 2405 UIView* activeView = _activeCardSet.displayView; |
2418 if ([cardView superview] != activeView) | 2406 if ([cardView superview] != activeView) |
2419 return; | 2407 return; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2639 // Fade the card to become transparent at the conclusion of the animation, | 2627 // Fade the card to become transparent at the conclusion of the animation, |
2640 // and the card's tab to become transparent at the time that the card | 2628 // and the card's tab to become transparent at the time that the card |
2641 // reaches the threshold for being dismissed. | 2629 // reaches the threshold for being dismissed. |
2642 [card view].alpha = 1 - fractionOfAnimationBreadth; | 2630 [card view].alpha = 1 - fractionOfAnimationBreadth; |
2643 } else { | 2631 } else { |
2644 if (gesture.state == UIGestureRecognizerStateEnded && | 2632 if (gesture.state == UIGestureRecognizerStateEnded && |
2645 [self swipeShouldTriggerAction:position]) { | 2633 [self swipeShouldTriggerAction:position]) { |
2646 // Track card if animation should dismiss in reverse from the norm of | 2634 // Track card if animation should dismiss in reverse from the norm of |
2647 // clockwise in portrait, counter-clockwise in landscape. | 2635 // clockwise in portrait, counter-clockwise in landscape. |
2648 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) | 2636 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) |
2649 _reverseDismissCard.reset([card retain]); | 2637 _reverseDismissCard = card; |
2650 // This will trigger the completion of the close card animation. | 2638 // This will trigger the completion of the close card animation. |
2651 [self closeTab:card.view]; | 2639 [self closeTab:card.view]; |
2652 } else { | 2640 } else { |
2653 // Animate back to starting position. | 2641 // Animate back to starting position. |
2654 [UIView animateWithDuration:kDefaultAnimationDuration | 2642 [UIView animateWithDuration:kDefaultAnimationDuration |
2655 delay:0 | 2643 delay:0 |
2656 options:UIViewAnimationCurveEaseOut | 2644 options:UIViewAnimationCurveEaseOut |
2657 animations:^{ | 2645 animations:^{ |
2658 [card view].alpha = 1; | 2646 [card view].alpha = 1; |
2659 [[card view] setTabOpacity:1]; | 2647 [[card view] setTabOpacity:1]; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2709 case IDC_TOGGLE_TAB_SWITCHER: | 2697 case IDC_TOGGLE_TAB_SWITCHER: |
2710 [self dismissWithSelectedTabAnimation]; | 2698 [self dismissWithSelectedTabAnimation]; |
2711 break; | 2699 break; |
2712 default: | 2700 default: |
2713 [super chromeExecuteCommand:sender]; | 2701 [super chromeExecuteCommand:sender]; |
2714 break; | 2702 break; |
2715 } | 2703 } |
2716 } | 2704 } |
2717 | 2705 |
2718 - (void)showToolsMenuPopup { | 2706 - (void)showToolsMenuPopup { |
2719 base::scoped_nsobject<ToolsMenuConfiguration> configuration( | 2707 ToolsMenuConfiguration* configuration = |
2720 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]); | 2708 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; |
2721 [configuration setInTabSwitcher:YES]; | 2709 [configuration setInTabSwitcher:YES]; |
2722 // When checking for the existence of tabs, catch the case where the main set | 2710 // When checking for the existence of tabs, catch the case where the main set |
2723 // is both active and empty, but the incognito set has some cards. | 2711 // is both active and empty, but the incognito set has some cards. |
2724 if (([[_activeCardSet cards] count] == 0) && | 2712 if (([[_activeCardSet cards] count] == 0) && |
2725 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) | 2713 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) |
2726 [configuration setNoOpenedTabs:YES]; | 2714 [configuration setNoOpenedTabs:YES]; |
2727 if (_activeCardSet == _otrCardSet) | 2715 if (_activeCardSet == _otrCardSet) |
2728 [configuration setInIncognito:YES]; | 2716 [configuration setInIncognito:YES]; |
2729 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; | 2717 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
2730 } | 2718 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2899 BOOL isPortrait = | 2887 BOOL isPortrait = |
2900 UIInterfaceOrientationIsPortrait(_lastInterfaceOrientation); | 2888 UIInterfaceOrientationIsPortrait(_lastInterfaceOrientation); |
2901 BOOL clockwise = isPortrait ? _reverseDismissCard != removedCard | 2889 BOOL clockwise = isPortrait ? _reverseDismissCard != removedCard |
2902 : _reverseDismissCard == removedCard; | 2890 : _reverseDismissCard == removedCard; |
2903 [self animateOutCardView:removedCard.view | 2891 [self animateOutCardView:removedCard.view |
2904 delay:0 | 2892 delay:0 |
2905 clockwise:clockwise | 2893 clockwise:clockwise |
2906 completion:nil]; | 2894 completion:nil]; |
2907 // Reset |reverseDismissCard| if that card was the one dismissed. | 2895 // Reset |reverseDismissCard| if that card was the one dismissed. |
2908 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) | 2896 if ((isPortrait && !clockwise) || (!isPortrait && clockwise)) |
2909 _reverseDismissCard.reset(); | 2897 _reverseDismissCard = nil; |
2910 } | 2898 } |
2911 // Nil out the the closing card after all closing animations have finished. | 2899 // Nil out the the closing card after all closing animations have finished. |
2912 [CATransaction begin]; | 2900 [CATransaction begin]; |
2913 [CATransaction setCompletionBlock:^{ | 2901 [CATransaction setCompletionBlock:^{ |
2914 cardSet.closingCard = nil; | 2902 cardSet.closingCard = nil; |
2915 }]; | 2903 }]; |
2916 // If the last incognito card closes, switch back to just the main set. | 2904 // If the last incognito card closes, switch back to just the main set. |
2917 if ([cardSet.cards count] == 0 && cardSet == _otrCardSet.get()) { | 2905 if ([cardSet.cards count] == 0 && cardSet == _otrCardSet) { |
2918 [self displayMainCardSetOnly]; | 2906 [self displayMainCardSetOnly]; |
2919 } else { | 2907 } else { |
2920 NSUInteger numCards = [[cardSet cards] count]; | 2908 NSUInteger numCards = [[cardSet cards] count]; |
2921 if (numCards == 0) { | 2909 if (numCards == 0) { |
2922 // Commit the transaction before early return. | 2910 // Commit the transaction before early return. |
2923 [CATransaction commit]; | 2911 [CATransaction commit]; |
2924 return; | 2912 return; |
2925 } | 2913 } |
2926 if (index == numCards) { | 2914 if (index == numCards) { |
2927 // If the card that was closed was the last card and was in the start | 2915 // If the card that was closed was the last card and was in the start |
(...skipping 28 matching lines...) Expand all Loading... | |
2956 } | 2944 } |
2957 [CATransaction commit]; | 2945 [CATransaction commit]; |
2958 } | 2946 } |
2959 | 2947 |
2960 - (void)cardSet:(CardSet*)cardSet displayedCard:(StackCard*)card { | 2948 - (void)cardSet:(CardSet*)cardSet displayedCard:(StackCard*)card { |
2961 // Add gesture recognizers to the card. | 2949 // Add gesture recognizers to the card. |
2962 [card.view addCardCloseTarget:self action:@selector(closeTab:)]; | 2950 [card.view addCardCloseTarget:self action:@selector(closeTab:)]; |
2963 [card.view addAccessibilityTarget:self | 2951 [card.view addAccessibilityTarget:self |
2964 action:@selector(accessibilityFocusedOnElement:)]; | 2952 action:@selector(accessibilityFocusedOnElement:)]; |
2965 | 2953 |
2966 base::scoped_nsobject<UIGestureRecognizer> tapRecognizer([ | 2954 UIGestureRecognizer* tapRecognizer = |
2967 [UITapGestureRecognizer alloc] initWithTarget:self | 2955 [[UITapGestureRecognizer alloc] initWithTarget:self |
2968 action:@selector(handleTapFrom:)]); | 2956 action:@selector(handleTapFrom:)]; |
2969 tapRecognizer.get().delegate = self; | 2957 tapRecognizer.delegate = self; |
2970 [card.view addGestureRecognizer:tapRecognizer.get()]; | 2958 [card.view addGestureRecognizer:tapRecognizer]; |
2971 | 2959 |
2972 base::scoped_nsobject<UIGestureRecognizer> longPressRecognizer( | 2960 UIGestureRecognizer* longPressRecognizer = |
2973 [[UILongPressGestureRecognizer alloc] | 2961 [[UILongPressGestureRecognizer alloc] |
2974 initWithTarget:self | 2962 initWithTarget:self |
2975 action:@selector(handleLongPressFrom:)]); | 2963 action:@selector(handleLongPressFrom:)]; |
2976 longPressRecognizer.get().delegate = self; | 2964 longPressRecognizer.delegate = self; |
2977 [card.view addGestureRecognizer:longPressRecognizer.get()]; | 2965 [card.view addGestureRecognizer:longPressRecognizer]; |
2978 } | 2966 } |
2979 | 2967 |
2980 - (void)cardSetRecreatedCards:(CardSet*)cardSet { | 2968 - (void)cardSetRecreatedCards:(CardSet*)cardSet { |
2981 // Remove the old card views, if any, then start loading the new ones. | 2969 // Remove the old card views, if any, then start loading the new ones. |
2982 for (UIView* card in [cardSet.displayView subviews]) { | 2970 for (UIView* card in [cardSet.displayView subviews]) { |
2983 [card removeFromSuperview]; | 2971 [card removeFromSuperview]; |
2984 } | 2972 } |
2985 [self preloadCardViewsAsynchronously]; | 2973 [self preloadCardViewsAsynchronously]; |
2986 } | 2974 } |
2987 | 2975 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3453 // the cards out starting with that card. | 3441 // the cards out starting with that card. |
3454 [_activeCardSet fanOutCardsWithStartIndex:index]; | 3442 [_activeCardSet fanOutCardsWithStartIndex:index]; |
3455 [card.view postAccessibilityNotification]; | 3443 [card.view postAccessibilityNotification]; |
3456 [self postOpenTabsAccessibilityNotification]; | 3444 [self postOpenTabsAccessibilityNotification]; |
3457 } | 3445 } |
3458 } | 3446 } |
3459 | 3447 |
3460 #pragma mark - UIResponder | 3448 #pragma mark - UIResponder |
3461 | 3449 |
3462 - (NSArray*)keyCommands { | 3450 - (NSArray*)keyCommands { |
3463 base::WeakNSObject<StackViewController> weakSelf(self); | 3451 __weak StackViewController* weakSelf = self; |
3464 | 3452 |
3465 // Block to execute a command from the |tag|. | 3453 // Block to execute a command from the |tag|. |
3466 base::mac::ScopedBlock<void (^)(NSInteger)> execute( | 3454 void (^execute)(NSInteger) = ^(NSInteger tag) { |
3467 ^(NSInteger tag) { | 3455 [weakSelf chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]]; |
3468 [weakSelf | 3456 }; |
3469 chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]]; | |
3470 }, | |
3471 base::scoped_policy::RETAIN); | |
3472 | 3457 |
3473 return @[ | 3458 return @[ |
3474 [UIKeyCommand cr_keyCommandWithInput:@"t" | 3459 [UIKeyCommand cr_keyCommandWithInput:@"t" |
3475 modifierFlags:UIKeyModifierCommand | 3460 modifierFlags:UIKeyModifierCommand |
3476 title:l10n_util::GetNSStringWithFixup( | 3461 title:l10n_util::GetNSStringWithFixup( |
3477 IDS_IOS_TOOLS_MENU_NEW_TAB) | 3462 IDS_IOS_TOOLS_MENU_NEW_TAB) |
3478 action:^{ | 3463 action:^{ |
3479 if ([weakSelf isCurrentSetIncognito]) | 3464 if ([weakSelf isCurrentSetIncognito]) |
3480 execute.get()(IDC_NEW_INCOGNITO_TAB); | 3465 execute(IDC_NEW_INCOGNITO_TAB); |
3481 else | 3466 else |
3482 execute.get()(IDC_NEW_TAB); | 3467 execute(IDC_NEW_TAB); |
3483 }], | 3468 }], |
3484 [UIKeyCommand | 3469 [UIKeyCommand |
3485 cr_keyCommandWithInput:@"n" | 3470 cr_keyCommandWithInput:@"n" |
3486 modifierFlags:UIKeyModifierCommand | UIKeyModifierShift | 3471 modifierFlags:UIKeyModifierCommand | UIKeyModifierShift |
3487 title:l10n_util::GetNSStringWithFixup( | 3472 title:l10n_util::GetNSStringWithFixup( |
3488 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB) | 3473 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB) |
3489 action:^{ | 3474 action:^{ |
3490 execute.get()(IDC_NEW_INCOGNITO_TAB); | 3475 execute(IDC_NEW_INCOGNITO_TAB); |
3491 }], | 3476 }], |
3492 [UIKeyCommand cr_keyCommandWithInput:@"n" | 3477 [UIKeyCommand cr_keyCommandWithInput:@"n" |
3493 modifierFlags:UIKeyModifierCommand | 3478 modifierFlags:UIKeyModifierCommand |
3494 title:nil | 3479 title:nil |
3495 action:^{ | 3480 action:^{ |
3496 if ([weakSelf isCurrentSetIncognito]) | 3481 if ([weakSelf isCurrentSetIncognito]) |
3497 execute.get()(IDC_NEW_INCOGNITO_TAB); | 3482 execute(IDC_NEW_INCOGNITO_TAB); |
3498 else | 3483 else |
3499 execute.get()(IDC_NEW_TAB); | 3484 execute(IDC_NEW_TAB); |
3500 }], | 3485 }], |
3501 ]; | 3486 ]; |
3502 } | 3487 } |
3503 | 3488 |
3504 @end | 3489 @end |
3505 | 3490 |
3506 @implementation StackViewController (Testing) | 3491 @implementation StackViewController (Testing) |
3507 | 3492 |
3508 - (UIScrollView*)scrollView { | 3493 - (UIScrollView*)scrollView { |
3509 return _scrollView.get(); | 3494 return _scrollView; |
3510 } | 3495 } |
3511 | 3496 |
3512 @end | 3497 @end |
OLD | NEW |