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> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/metrics/user_metrics_action.h" | 22 #include "base/metrics/user_metrics_action.h" |
23 #include "base/strings/sys_string_conversions.h" | 23 #include "base/strings/sys_string_conversions.h" |
24 #include "ios/chrome/browser/chrome_url_constants.h" | 24 #include "ios/chrome/browser/chrome_url_constants.h" |
25 #include "ios/chrome/browser/experimental_flags.h" | 25 #include "ios/chrome/browser/experimental_flags.h" |
26 #import "ios/chrome/browser/tabs/tab.h" | 26 #import "ios/chrome/browser/tabs/tab.h" |
27 #import "ios/chrome/browser/tabs/tab_model.h" | 27 #import "ios/chrome/browser/tabs/tab_model.h" |
28 #import "ios/chrome/browser/tabs/tab_model_observer.h" | 28 #import "ios/chrome/browser/tabs/tab_model_observer.h" |
29 #import "ios/chrome/browser/ui/animation_util.h" | 29 #import "ios/chrome/browser/ui/animation_util.h" |
30 #import "ios/chrome/browser/ui/background_generator.h" | 30 #import "ios/chrome/browser/ui/background_generator.h" |
31 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 31 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 32 #import "ios/chrome/browser/ui/commands/browser_commands.h" |
32 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 33 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
33 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 34 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
34 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" | 35 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" |
35 #import "ios/chrome/browser/ui/ntp/new_tab_page_toolbar_controller.h" | 36 #import "ios/chrome/browser/ui/ntp/new_tab_page_toolbar_controller.h" |
36 #import "ios/chrome/browser/ui/reversed_animation.h" | 37 #import "ios/chrome/browser/ui/reversed_animation.h" |
37 #import "ios/chrome/browser/ui/rtl_geometry.h" | 38 #import "ios/chrome/browser/ui/rtl_geometry.h" |
38 #import "ios/chrome/browser/ui/stack_view/card_stack_layout_manager.h" | 39 #import "ios/chrome/browser/ui/stack_view/card_stack_layout_manager.h" |
39 #import "ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.h" | 40 #import "ios/chrome/browser/ui/stack_view/card_stack_pinch_gesture_recognizer.h" |
40 #import "ios/chrome/browser/ui/stack_view/card_view.h" | 41 #import "ios/chrome/browser/ui/stack_view/card_view.h" |
41 #import "ios/chrome/browser/ui/stack_view/close_button.h" | 42 #import "ios/chrome/browser/ui/stack_view/close_button.h" |
42 #import "ios/chrome/browser/ui/stack_view/page_animation_util.h" | 43 #import "ios/chrome/browser/ui/stack_view/page_animation_util.h" |
43 #import "ios/chrome/browser/ui/stack_view/stack_card.h" | 44 #import "ios/chrome/browser/ui/stack_view/stack_card.h" |
44 #import "ios/chrome/browser/ui/stack_view/stack_view_controller_private.h" | 45 #import "ios/chrome/browser/ui/stack_view/stack_view_controller_private.h" |
45 #import "ios/chrome/browser/ui/stack_view/stack_view_toolbar_controller.h" | 46 #import "ios/chrome/browser/ui/stack_view/stack_view_toolbar_controller.h" |
46 #import "ios/chrome/browser/ui/stack_view/title_label.h" | 47 #import "ios/chrome/browser/ui/stack_view/title_label.h" |
47 #import "ios/chrome/browser/ui/toolbar/new_tab_button.h" | 48 #import "ios/chrome/browser/ui/toolbar/new_tab_button.h" |
48 #import "ios/chrome/browser/ui/toolbar/toolbar_owner.h" | 49 #import "ios/chrome/browser/ui/toolbar/toolbar_owner.h" |
49 #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" |
50 #import "ios/chrome/browser/ui/ui_util.h" | 51 #import "ios/chrome/browser/ui/ui_util.h" |
51 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 52 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
52 #import "ios/chrome/common/material_timing.h" | 53 #import "ios/chrome/common/material_timing.h" |
53 #include "ios/chrome/grit/ios_strings.h" | 54 #include "ios/chrome/grit/ios_strings.h" |
| 55 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
54 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" | 56 #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
55 #include "ios/web/public/referrer.h" | 57 #include "ios/web/public/referrer.h" |
56 #import "net/base/mac/url_conversions.h" | 58 #import "net/base/mac/url_conversions.h" |
57 #include "ui/base/l10n/l10n_util.h" | 59 #include "ui/base/l10n/l10n_util.h" |
58 | 60 |
59 #if !defined(__has_feature) || !__has_feature(objc_arc) | 61 #if !defined(__has_feature) || !__has_feature(objc_arc) |
60 #error "This file requires ARC support." | 62 #error "This file requires ARC support." |
61 #endif | 63 #endif |
62 | 64 |
63 using base::UserMetricsAction; | 65 using base::UserMetricsAction; |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 StackCard* _reverseDismissCard; | 485 StackCard* _reverseDismissCard; |
484 // |YES| if the stack view is in the process of being dismissed. | 486 // |YES| if the stack view is in the process of being dismissed. |
485 BOOL _isBeingDismissed; | 487 BOOL _isBeingDismissed; |
486 // |YES| if the stack view is currently active. | 488 // |YES| if the stack view is currently active. |
487 BOOL _isActive; | 489 BOOL _isActive; |
488 // Records whether a memory warning occurred in the current session. | 490 // Records whether a memory warning occurred in the current session. |
489 BOOL _receivedMemoryWarningInSession; | 491 BOOL _receivedMemoryWarningInSession; |
490 // |YES| if there is card set animation being processed. For testing only. | 492 // |YES| if there is card set animation being processed. For testing only. |
491 // Save last touch point used by new tab animation. | 493 // Save last touch point used by new tab animation. |
492 CGPoint _lastTapPoint; | 494 CGPoint _lastTapPoint; |
| 495 // The dispacther instance used when this view controller is active. |
| 496 CommandDispatcher* _dispatcher; |
493 } | 497 } |
494 | 498 |
495 @synthesize activeCardSet = _activeCardSet; | 499 @synthesize activeCardSet = _activeCardSet; |
496 @synthesize delegate = _delegate; | 500 @synthesize delegate = _delegate; |
497 @synthesize dummyToolbarBackgroundView = _dummyToolbarBackgroundView; | 501 @synthesize dummyToolbarBackgroundView = _dummyToolbarBackgroundView; |
498 @synthesize inActiveDeckChangeAnimation = _inActiveDeckChangeAnimation; | 502 @synthesize inActiveDeckChangeAnimation = _inActiveDeckChangeAnimation; |
499 @synthesize testDelegate = _testDelegate; | 503 @synthesize testDelegate = _testDelegate; |
500 @synthesize transitionStyle = _transitionStyle; | 504 @synthesize transitionStyle = _transitionStyle; |
501 @synthesize transitionTappedCard = _transitionTappedCard; | 505 @synthesize transitionTappedCard = _transitionTappedCard; |
502 @synthesize transitionToolbarController = _transitionToolbarController; | 506 @synthesize transitionToolbarController = _transitionToolbarController; |
(...skipping 20 matching lines...) Expand all Loading... |
523 kPressDurationForAmbiguousSwipeToTriggerDismissal]; | 527 kPressDurationForAmbiguousSwipeToTriggerDismissal]; |
524 [_swipeDismissesCardRecognizer setDelegate:self]; | 528 [_swipeDismissesCardRecognizer setDelegate:self]; |
525 _pinchRecognizer = [[CardStackPinchGestureRecognizer alloc] | 529 _pinchRecognizer = [[CardStackPinchGestureRecognizer alloc] |
526 initWithTarget:self | 530 initWithTarget:self |
527 action:@selector(handlePinchFrom:)]; | 531 action:@selector(handlePinchFrom:)]; |
528 [_pinchRecognizer setDelegate:self]; | 532 [_pinchRecognizer setDelegate:self]; |
529 _modeSwitchRecognizer = [[UITapGestureRecognizer alloc] | 533 _modeSwitchRecognizer = [[UITapGestureRecognizer alloc] |
530 initWithTarget:self | 534 initWithTarget:self |
531 action:@selector(handleTapFrom:)]; | 535 action:@selector(handleTapFrom:)]; |
532 [_modeSwitchRecognizer setDelegate:self]; | 536 [_modeSwitchRecognizer setDelegate:self]; |
| 537 _dispatcher = [[CommandDispatcher alloc] init]; |
| 538 [_dispatcher startDispatchingToTarget:self |
| 539 forProtocol:@protocol(BrowserCommands)]; |
533 } | 540 } |
534 return self; | 541 return self; |
535 } | 542 } |
536 | 543 |
537 - (instancetype)initWithMainTabModel:(TabModel*)mainModel | 544 - (instancetype)initWithMainTabModel:(TabModel*)mainModel |
538 otrTabModel:(TabModel*)otrModel | 545 otrTabModel:(TabModel*)otrModel |
539 activeTabModel:(TabModel*)activeModel { | 546 activeTabModel:(TabModel*)activeModel { |
540 DCHECK(mainModel); | 547 DCHECK(mainModel); |
541 DCHECK(otrModel); | 548 DCHECK(otrModel); |
542 DCHECK(activeModel == otrModel || activeModel == mainModel); | 549 DCHECK(activeModel == otrModel || activeModel == mainModel); |
(...skipping 10 matching lines...) Expand all Loading... |
553 bundle:(NSBundle*)nibBundleOrNil { | 560 bundle:(NSBundle*)nibBundleOrNil { |
554 NOTREACHED(); | 561 NOTREACHED(); |
555 return nil; | 562 return nil; |
556 } | 563 } |
557 | 564 |
558 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 565 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
559 NOTREACHED(); | 566 NOTREACHED(); |
560 return nil; | 567 return nil; |
561 } | 568 } |
562 | 569 |
| 570 - (id<BrowserCommands>)browserCommandsDispatcher { |
| 571 return static_cast<id<BrowserCommands>>(_dispatcher); |
| 572 } |
| 573 |
563 - (void)setUpWithMainCardSet:(CardSet*)mainCardSet | 574 - (void)setUpWithMainCardSet:(CardSet*)mainCardSet |
564 otrCardSet:(CardSet*)otrCardSet | 575 otrCardSet:(CardSet*)otrCardSet |
565 activeCardSet:(CardSet*)activeCardSet { | 576 activeCardSet:(CardSet*)activeCardSet { |
566 _mainCardSet = mainCardSet; | 577 _mainCardSet = mainCardSet; |
567 _otrCardSet = otrCardSet; | 578 _otrCardSet = otrCardSet; |
568 if (experimental_flags::IsLRUSnapshotCacheEnabled()) { | 579 if (experimental_flags::IsLRUSnapshotCacheEnabled()) { |
569 [_mainCardSet setKeepOnlyVisibleCardViewsAlive:YES]; | 580 [_mainCardSet setKeepOnlyVisibleCardViewsAlive:YES]; |
570 [_otrCardSet setKeepOnlyVisibleCardViewsAlive:YES]; | 581 [_otrCardSet setKeepOnlyVisibleCardViewsAlive:YES]; |
571 } | 582 } |
572 _activeCardSet = (activeCardSet == mainCardSet) ? mainCardSet : otrCardSet; | 583 _activeCardSet = (activeCardSet == mainCardSet) ? mainCardSet : otrCardSet; |
(...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2676 // response to a user action it's not worth the bookkeeping of a reverse | 2687 // response to a user action it's not worth the bookkeeping of a reverse |
2677 // mapping to make it constant time. | 2688 // mapping to make it constant time. |
2678 for (StackCard* card in _activeCardSet.cards) { | 2689 for (StackCard* card in _activeCardSet.cards) { |
2679 if (card.viewIsLive && card.view == view) { | 2690 if (card.viewIsLive && card.view == view) { |
2680 return card; | 2691 return card; |
2681 } | 2692 } |
2682 } | 2693 } |
2683 return nil; | 2694 return nil; |
2684 } | 2695 } |
2685 | 2696 |
| 2697 #pragma mark - BrowserCommands |
| 2698 |
| 2699 - (void)showToolsMenu { |
| 2700 ToolsMenuConfiguration* configuration = |
| 2701 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; |
| 2702 [configuration setInTabSwitcher:YES]; |
| 2703 // When checking for the existence of tabs, catch the case where the main set |
| 2704 // is both active and empty, but the incognito set has some cards. |
| 2705 if (([[_activeCardSet cards] count] == 0) && |
| 2706 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) |
| 2707 [configuration setNoOpenedTabs:YES]; |
| 2708 if (_activeCardSet == _otrCardSet) |
| 2709 [configuration setInIncognito:YES]; |
| 2710 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
| 2711 } |
| 2712 |
2686 - (IBAction)chromeExecuteCommand:(id)sender { | 2713 - (IBAction)chromeExecuteCommand:(id)sender { |
2687 int command = [sender tag]; | 2714 int command = [sender tag]; |
2688 | 2715 |
2689 switch (command) { | 2716 switch (command) { |
2690 case IDC_SHOW_TOOLS_MENU: | |
2691 [self showToolsMenuPopup]; | |
2692 break; | |
2693 // Closing all while the main set is active closes everything, but closing | 2717 // Closing all while the main set is active closes everything, but closing |
2694 // all while incognito is active only closes incognito tabs. | 2718 // all while incognito is active only closes incognito tabs. |
2695 case IDC_CLOSE_ALL_TABS: | 2719 case IDC_CLOSE_ALL_TABS: |
2696 DCHECK(![self isCurrentSetIncognito]); | 2720 DCHECK(![self isCurrentSetIncognito]); |
2697 [self removeAllCardsFromSet:_mainCardSet]; | 2721 [self removeAllCardsFromSet:_mainCardSet]; |
2698 [self removeAllCardsFromSet:_otrCardSet]; | 2722 [self removeAllCardsFromSet:_otrCardSet]; |
2699 break; | 2723 break; |
2700 case IDC_CLOSE_ALL_INCOGNITO_TABS: | 2724 case IDC_CLOSE_ALL_INCOGNITO_TABS: |
2701 DCHECK([self isCurrentSetIncognito]); | 2725 DCHECK([self isCurrentSetIncognito]); |
2702 [self removeAllCardsFromSet:_activeCardSet]; | 2726 [self removeAllCardsFromSet:_activeCardSet]; |
(...skipping 10 matching lines...) Expand all Loading... |
2713 break; | 2737 break; |
2714 case IDC_TOGGLE_TAB_SWITCHER: | 2738 case IDC_TOGGLE_TAB_SWITCHER: |
2715 [self dismissWithSelectedTabAnimation]; | 2739 [self dismissWithSelectedTabAnimation]; |
2716 break; | 2740 break; |
2717 default: | 2741 default: |
2718 [super chromeExecuteCommand:sender]; | 2742 [super chromeExecuteCommand:sender]; |
2719 break; | 2743 break; |
2720 } | 2744 } |
2721 } | 2745 } |
2722 | 2746 |
2723 - (void)showToolsMenuPopup { | |
2724 ToolsMenuConfiguration* configuration = | |
2725 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; | |
2726 [configuration setInTabSwitcher:YES]; | |
2727 // When checking for the existence of tabs, catch the case where the main set | |
2728 // is both active and empty, but the incognito set has some cards. | |
2729 if (([[_activeCardSet cards] count] == 0) && | |
2730 (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) | |
2731 [configuration setNoOpenedTabs:YES]; | |
2732 if (_activeCardSet == _otrCardSet) | |
2733 [configuration setInIncognito:YES]; | |
2734 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; | |
2735 } | |
2736 | |
2737 #pragma mark Notification Handlers | 2747 #pragma mark Notification Handlers |
2738 | 2748 |
2739 - (void)allModelTabsHaveClosed:(NSNotification*)notify { | 2749 - (void)allModelTabsHaveClosed:(NSNotification*)notify { |
2740 // Early return if the stack view is not active. This can sometimes occur if | 2750 // Early return if the stack view is not active. This can sometimes occur if |
2741 // |clearInternalState| triggers the deletion of a tab model. | 2751 // |clearInternalState| triggers the deletion of a tab model. |
2742 if (!_isActive) | 2752 if (!_isActive) |
2743 return; | 2753 return; |
2744 | 2754 |
2745 CardSet* closedSet = | 2755 CardSet* closedSet = |
2746 (notify.object == [_mainCardSet tabModel]) ? _mainCardSet : _otrCardSet; | 2756 (notify.object == [_mainCardSet tabModel]) ? _mainCardSet : _otrCardSet; |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3505 | 3515 |
3506 @end | 3516 @end |
3507 | 3517 |
3508 @implementation StackViewController (Testing) | 3518 @implementation StackViewController (Testing) |
3509 | 3519 |
3510 - (UIScrollView*)scrollView { | 3520 - (UIScrollView*)scrollView { |
3511 return _scrollView; | 3521 return _scrollView; |
3512 } | 3522 } |
3513 | 3523 |
3514 @end | 3524 @end |
OLD | NEW |