Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: ios/chrome/browser/ui/contextual_search/contextual_search_results_view.mm

Issue 2824493002: Reland of [ObjC ARC] Converts ios/chrome/browser/ui/contextual_search:contextual_search to ARC. (Closed)
Patch Set: fix test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/contextual_search/contextual_search_results_view .h" 5 #include "ios/chrome/browser/ui/contextual_search/contextual_search_results_view .h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #import "base/ios/weak_nsobject.h" 9 #import "base/ios/weak_nsobject.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
13 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" 13 #import "ios/chrome/browser/tabs/legacy_tab_helper.h"
14 #import "ios/chrome/browser/tabs/tab.h" 14 #import "ios/chrome/browser/tabs/tab.h"
15 #import "ios/chrome/browser/tabs/tab_helper_util.h" 15 #import "ios/chrome/browser/tabs/tab_helper_util.h"
16 #import "ios/chrome/browser/tabs/tab_private.h" 16 #import "ios/chrome/browser/tabs/tab_private.h"
17 #import "ios/chrome/browser/ui/contextual_search/contextual_search_metrics.h" 17 #import "ios/chrome/browser/ui/contextual_search/contextual_search_metrics.h"
18 #import "ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.h" 18 #import "ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.h"
19 #import "ios/chrome/browser/ui/contextual_search/contextual_search_web_state_obs erver.h" 19 #import "ios/chrome/browser/ui/contextual_search/contextual_search_web_state_obs erver.h"
20 #import "ios/chrome/browser/web_state_list/web_state_opener.h" 20 #import "ios/chrome/browser/web_state_list/web_state_opener.h"
21 #import "ios/chrome/common/material_timing.h" 21 #import "ios/chrome/common/material_timing.h"
22 #include "ios/web/public/load_committed_details.h" 22 #include "ios/web/public/load_committed_details.h"
23 #import "ios/web/public/serializable_user_data_manager.h" 23 #import "ios/web/public/serializable_user_data_manager.h"
24 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 24 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
25 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" 25 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
26 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h" 26 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h"
27 #import "ios/web/public/web_state/web_state.h" 27 #import "ios/web/public/web_state/web_state.h"
28 #import "ios/web/web_state/ui/crw_web_controller.h" 28 #import "ios/web/web_state/ui/crw_web_controller.h"
29 29
30 #if !defined(__has_feature) || !__has_feature(objc_arc)
31 #error "This file requires ARC support."
32 #endif
33
30 namespace { 34 namespace {
31 enum SearchResultsViewVisibility { OFFSCREEN, PRELOAD, VISIBLE }; 35 enum SearchResultsViewVisibility { OFFSCREEN, PRELOAD, VISIBLE };
32 } 36 }
33 37
34 @interface ContextualSearchResultsView ()<ContextualSearchWebStateDelegate, 38 @interface ContextualSearchResultsView ()<ContextualSearchWebStateDelegate,
35 CRWNativeContentProvider> 39 CRWNativeContentProvider>
36 40
37 // Can the search results be scrolled currently? 41 // Can the search results be scrolled currently?
38 @property(nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled; 42 @property(nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled;
39 @end 43 @end
40 44
41 @implementation ContextualSearchResultsView { 45 @implementation ContextualSearchResultsView {
42 base::WeakNSProtocol<id<ContextualSearchTabPromoter>> _promoter;
43 base::WeakNSProtocol<id<ContextualSearchPreloadChecker>> _preloadChecker;
44 std::unique_ptr<ContextualSearchWebStateObserver> _webStateObserver; 46 std::unique_ptr<ContextualSearchWebStateObserver> _webStateObserver;
45 47
46 // WebState that loads the search results. 48 // WebState that loads the search results.
47 std::unique_ptr<web::WebState> _webState; 49 std::unique_ptr<web::WebState> _webState;
48 std::unique_ptr<WebStateOpener> _webStateOpener; 50 std::unique_ptr<WebStateOpener> _webStateOpener;
49 51
50 // Access to the search tab's web view proxy. 52 // Access to the search tab's web view proxy.
51 base::scoped_nsprotocol<id<CRWWebViewProxy>> _webViewProxy; 53 id<CRWWebViewProxy> _webViewProxy;
52 54
53 BOOL _loaded; 55 BOOL _loaded;
54 BOOL _displayed; 56 BOOL _displayed;
55 BOOL _loadingError; 57 BOOL _loadingError;
56 BOOL _waitingForInitialSearchTabLoad; 58 BOOL _waitingForInitialSearchTabLoad;
57 BOOL _loadInProgress; 59 BOOL _loadInProgress;
58 BOOL _shouldScroll; 60 BOOL _shouldScroll;
59 61
60 BOOL _preloadEnabled; 62 BOOL _preloadEnabled;
61 63
62 SearchResultsViewVisibility _visibility; 64 SearchResultsViewVisibility _visibility;
63 65
64 // Time of starting a search results page load. 66 // Time of starting a search results page load.
65 base::Time _loadStartTime; 67 base::Time _loadStartTime;
66 } 68 }
67 69
68 @synthesize active = _active; 70 @synthesize active = _active;
69 @synthesize opener = _opener; 71 @synthesize opener = _opener;
72 @synthesize promoter = _promoter;
73 @synthesize preloadChecker = _preloadChecker;
70 74
71 - (instancetype)initWithFrame:(CGRect)frame { 75 - (instancetype)initWithFrame:(CGRect)frame {
72 if ((self = [super initWithFrame:frame])) { 76 if ((self = [super initWithFrame:frame])) {
73 self.translatesAutoresizingMaskIntoConstraints = NO; 77 self.translatesAutoresizingMaskIntoConstraints = NO;
74 self.backgroundColor = [UIColor whiteColor]; 78 self.backgroundColor = [UIColor whiteColor];
75 self.accessibilityIdentifier = @"contextualSearchResultsView"; 79 self.accessibilityIdentifier = @"contextualSearchResultsView";
76 self.clipsToBounds = YES; 80 self.clipsToBounds = YES;
77 _webStateObserver.reset(new ContextualSearchWebStateObserver(self)); 81 _webStateObserver.reset(new ContextualSearchWebStateObserver(self));
78 _visibility = OFFSCREEN; 82 _visibility = OFFSCREEN;
79 } 83 }
(...skipping 11 matching lines...) Expand all
91 [[_webViewProxy scrollViewProxy] setBounces:NO]; 95 [[_webViewProxy scrollViewProxy] setBounces:NO];
92 } 96 }
93 97
94 #pragma mark - public properties 98 #pragma mark - public properties
95 99
96 - (id<ContextualSearchTabPromoter>)promoter { 100 - (id<ContextualSearchTabPromoter>)promoter {
97 return _promoter; 101 return _promoter;
98 } 102 }
99 103
100 - (void)setPromoter:(id<ContextualSearchTabPromoter>)promoter { 104 - (void)setPromoter:(id<ContextualSearchTabPromoter>)promoter {
101 _promoter.reset(promoter); 105 _promoter = promoter;
102 } 106 }
103 107
104 - (id<ContextualSearchPreloadChecker>)preloadChecker { 108 - (id<ContextualSearchPreloadChecker>)preloadChecker {
105 return _preloadChecker; 109 return _preloadChecker;
106 } 110 }
107 111
108 - (void)setPreloadChecker:(id<ContextualSearchPreloadChecker>)preloadChecker { 112 - (void)setPreloadChecker:(id<ContextualSearchPreloadChecker>)preloadChecker {
109 _preloadChecker.reset(preloadChecker); 113 _preloadChecker = preloadChecker;
110 } 114 }
111 115
112 - (BOOL)contentVisible { 116 - (BOOL)contentVisible {
113 return _loaded && _visibility == VISIBLE; 117 return _loaded && _visibility == VISIBLE;
114 } 118 }
115 119
116 - (void)setActive:(BOOL)active { 120 - (void)setActive:(BOOL)active {
117 if (active) { 121 if (active) {
118 if (_webState) { 122 if (_webState) {
119 Tab* tab = LegacyTabHelper::GetTabForWebState(_webState.get()); 123 Tab* tab = LegacyTabHelper::GetTabForWebState(_webState.get());
120 // Start watching the embedded Tab's web activity. 124 // Start watching the embedded Tab's web activity.
121 _webStateObserver->ObserveWebState(_webState.get()); 125 _webStateObserver->ObserveWebState(_webState.get());
122 _webState->SetShouldSuppressDialogs(false); 126 _webState->SetShouldSuppressDialogs(false);
123 127
124 _webViewProxy.reset([[[tab webController] webViewProxy] retain]); 128 _webViewProxy = [[tab webController] webViewProxy];
125 [[_webViewProxy scrollViewProxy] setBounces:NO]; 129 [[_webViewProxy scrollViewProxy] setBounces:NO];
126 } 130 }
127 } else { 131 } else {
128 // Stop watching the embedded Tab's web activity. 132 // Stop watching the embedded Tab's web activity.
129 _webStateObserver->ObserveWebState(nullptr); 133 _webStateObserver->ObserveWebState(nullptr);
130 _webViewProxy.reset(nil); 134 _webViewProxy = nil;
131 } 135 }
132 136
133 _active = active; 137 _active = active;
134 } 138 }
135 139
136 #pragma mark - public methods 140 #pragma mark - public methods
137 141
138 - (void)scrollToTopAnimated:(BOOL)animated { 142 - (void)scrollToTopAnimated:(BOOL)animated {
139 [[_webViewProxy scrollViewProxy] setBounces:YES]; 143 [[_webViewProxy scrollViewProxy] setBounces:YES];
140 // Scroll the search tab's view to the top. 144 // Scroll the search tab's view to the top.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 195
192 #pragma mark - private methods 196 #pragma mark - private methods
193 197
194 - (void)disconnectTab { 198 - (void)disconnectTab {
195 if (_webState) { 199 if (_webState) {
196 Tab* tab = LegacyTabHelper::GetTabForWebState(_webState.get()); 200 Tab* tab = LegacyTabHelper::GetTabForWebState(_webState.get());
197 [[tab view] removeFromSuperview]; 201 [[tab view] removeFromSuperview];
198 [[tab webController] setNativeProvider:nil]; 202 [[tab webController] setNativeProvider:nil];
199 } 203 }
200 self.active = NO; 204 self.active = NO;
201 _webViewProxy.reset(); 205 _webViewProxy = nil;
202 } 206 }
203 207
204 - (void)cancelLoad { 208 - (void)cancelLoad {
205 [self disconnectTab]; 209 [self disconnectTab];
206 _loadInProgress = NO; 210 _loadInProgress = NO;
207 _loaded = NO; 211 _loaded = NO;
208 _webState.reset(); 212 _webState.reset();
209 } 213 }
210 214
211 - (void)loadPendingSearchIfPossible { 215 - (void)loadPendingSearchIfPossible {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 withError:error 385 withError:error
382 isPost:isPost]; 386 isPost:isPost];
383 387
384 if ([errorController respondsToSelector:@selector(setScrollEnabled:)]) { 388 if ([errorController respondsToSelector:@selector(setScrollEnabled:)]) {
385 [errorController setScrollEnabled:NO]; 389 [errorController setScrollEnabled:NO];
386 } 390 }
387 return errorController; 391 return errorController;
388 } 392 }
389 393
390 @end 394 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698