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