OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_transition_context.h" |
| 6 |
| 7 #include "base/mac/objc_property_releaser.h" |
| 8 #import "ios/chrome/browser/tabs/tab.h" |
| 9 #import "ios/chrome/browser/ui/browser_view_controller.h" |
| 10 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_transition_context.h" |
| 11 #import "ios/chrome/browser/ui/tabs/tab_strip_controller+tab_switcher_animation.
h" |
| 12 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h" |
| 13 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 14 |
| 15 @class BrowserViewController; |
| 16 |
| 17 @interface TabSwitcherTransitionContextContent () { |
| 18 base::scoped_nsobject<TabSwitcherTabStripPlaceholderView> |
| 19 _tabStripPlaceholderView; |
| 20 base::WeakNSObject<BrowserViewController> _bvc; |
| 21 } |
| 22 |
| 23 @end |
| 24 |
| 25 @implementation TabSwitcherTransitionContextContent { |
| 26 base::mac::ObjCPropertyReleaser |
| 27 _propertyReleaser_tabSwitcherTransitionContextContent; |
| 28 } |
| 29 |
| 30 + (instancetype)tabSwitcherTransitionContextContentFromBVC: |
| 31 (BrowserViewController*)bvc { |
| 32 TabSwitcherTransitionContextContent* transitionContextContent = |
| 33 [[[TabSwitcherTransitionContextContent alloc] init] autorelease]; |
| 34 |
| 35 Tab* currentTab = [[bvc tabModel] currentTab]; |
| 36 transitionContextContent.initialSelectedTabIndex = |
| 37 [[bvc tabModel] indexOfTab:currentTab]; |
| 38 |
| 39 if (![bvc isViewLoaded]) { |
| 40 [bvc ensureViewCreated]; |
| 41 [bvc.view setFrame:[[UIScreen mainScreen] bounds]]; |
| 42 } |
| 43 |
| 44 UIView* toolbarView = [[bvc toolbarController] view]; |
| 45 base::scoped_nsobject<UIView> toolbarSnapshotView; |
| 46 if ([toolbarView window]) { |
| 47 toolbarSnapshotView.reset( |
| 48 [[toolbarView snapshotViewAfterScreenUpdates:NO] retain]); |
| 49 } else { |
| 50 toolbarSnapshotView.reset([[UIView alloc] initWithFrame:toolbarView.frame]); |
| 51 [toolbarSnapshotView layer].contents = static_cast<id>( |
| 52 CaptureViewWithOption(toolbarView, 1, kClientSideRendering).CGImage); |
| 53 } |
| 54 transitionContextContent.toolbarSnapshotView = toolbarSnapshotView; |
| 55 transitionContextContent->_bvc.reset(bvc); |
| 56 return transitionContextContent; |
| 57 } |
| 58 |
| 59 - (TabSwitcherTabStripPlaceholderView*)generateTabStripPlaceholderView { |
| 60 TabStripController* tsc = [_bvc tabStripController]; |
| 61 return [tsc placeholderView]; |
| 62 } |
| 63 |
| 64 @synthesize toolbarSnapshotView = _toolbarSnapshotView; |
| 65 @synthesize initialSelectedTabIndex = _initialSelectedTabIndex; |
| 66 |
| 67 - (instancetype)init { |
| 68 self = [super init]; |
| 69 if (self) { |
| 70 _propertyReleaser_tabSwitcherTransitionContextContent.Init( |
| 71 self, [TabSwitcherTransitionContextContent class]); |
| 72 } |
| 73 return self; |
| 74 } |
| 75 |
| 76 @end |
| 77 |
| 78 @implementation TabSwitcherTransitionContext { |
| 79 base::mac::ObjCPropertyReleaser |
| 80 _propertyReleaser_tabSwitcherTransitionContext; |
| 81 } |
| 82 |
| 83 + (instancetype) |
| 84 tabSwitcherTransitionContextWithCurrent:(BrowserViewController*)currentBVC |
| 85 mainBVC:(BrowserViewController*)mainBVC |
| 86 otrBVC:(BrowserViewController*)otrBVC { |
| 87 TabSwitcherTransitionContext* transitionContext = |
| 88 [[[TabSwitcherTransitionContext alloc] init] autorelease]; |
| 89 Tab* currentTab = [[currentBVC tabModel] currentTab]; |
| 90 UIImage* tabSnapshotImage = |
| 91 [currentTab generateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| 92 [transitionContext setTabSnapshotImage:tabSnapshotImage]; |
| 93 [transitionContext |
| 94 setIncognitoContent: |
| 95 [TabSwitcherTransitionContextContent |
| 96 tabSwitcherTransitionContextContentFromBVC:otrBVC]]; |
| 97 [transitionContext |
| 98 setRegularContent: |
| 99 [TabSwitcherTransitionContextContent |
| 100 tabSwitcherTransitionContextContentFromBVC:mainBVC]]; |
| 101 [transitionContext setInitialTabModel:currentBVC.tabModel]; |
| 102 return transitionContext; |
| 103 } |
| 104 |
| 105 @synthesize tabSnapshotImage = _tabSnapshotImage; |
| 106 @synthesize incognitoContent = _incognitoContent; |
| 107 @synthesize regularContent = _regularContent; |
| 108 @synthesize initialTabModel = _initialTabModel; |
| 109 |
| 110 - (instancetype)init { |
| 111 self = [super init]; |
| 112 if (self) { |
| 113 _propertyReleaser_tabSwitcherTransitionContext.Init( |
| 114 self, [TabSwitcherTransitionContext class]); |
| 115 } |
| 116 return self; |
| 117 } |
| 118 |
| 119 @end |
OLD | NEW |