Chromium Code Reviews| 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/find_in_page/find_in_page_controller.h" | 5 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h" |
| 6 | 6 |
| 7 #import <cmath> | |
| 7 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 8 | 9 |
| 9 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 12 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 13 #import "ios/chrome/browser/find_in_page/find_in_page_model.h" | 14 #import "ios/chrome/browser/find_in_page/find_in_page_model.h" |
| 14 #import "ios/chrome/browser/find_in_page/js_findinpage_manager.h" | 15 #import "ios/chrome/browser/find_in_page/js_findinpage_manager.h" |
| 15 #import "ios/chrome/browser/web/dom_altering_lock.h" | 16 #import "ios/chrome/browser/web/dom_altering_lock.h" |
| 16 #import "ios/web/public/web_state/crw_web_view_proxy.h" | 17 #import "ios/web/public/web_state/crw_web_view_proxy.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // Gives find in page more time to complete. Calls |completionHandler| with | 52 // Gives find in page more time to complete. Calls |completionHandler| with |
| 52 // a BOOL indicating if the find operation was successfull. |completionHandler| | 53 // a BOOL indicating if the find operation was successfull. |completionHandler| |
| 53 // can be nil. | 54 // can be nil. |
| 54 - (void)pumpFindStringInPageWithCompletionHandler: | 55 - (void)pumpFindStringInPageWithCompletionHandler: |
| 55 (void (^)(BOOL))completionHandler; | 56 (void (^)(BOOL))completionHandler; |
| 56 // Processes the result of a single find in page pump. Calls |completionHandler| | 57 // Processes the result of a single find in page pump. Calls |completionHandler| |
| 57 // if pumping is done. Re-pumps if necessary. | 58 // if pumping is done. Re-pumps if necessary. |
| 58 - (void)processPumpResult:(BOOL)finished | 59 - (void)processPumpResult:(BOOL)finished |
| 59 scrollPoint:(CGPoint)scrollPoint | 60 scrollPoint:(CGPoint)scrollPoint |
| 60 completionHandler:(ProceduralBlock)completionHandler; | 61 completionHandler:(ProceduralBlock)completionHandler; |
| 62 // Prevent overscroll. | |
| 63 - (CGPoint)limitOverscroll:(CRWWebViewScrollViewProxy*)scrollViewProxy | |
| 64 atPoint:(CGPpoint)point; | |
| 61 // Returns the associated web state. May be null. | 65 // Returns the associated web state. May be null. |
| 62 - (web::WebState*)webState; | 66 - (web::WebState*)webState; |
| 63 @end | 67 @end |
| 64 | 68 |
| 65 @implementation FindInPageController { | 69 @implementation FindInPageController { |
| 66 @private | 70 @private |
| 67 // Object that manages find_in_page.js injection into the web view. | 71 // Object that manages find_in_page.js injection into the web view. |
| 68 JsFindinpageManager* _findInPageJsManager; | 72 JsFindinpageManager* _findInPageJsManager; |
| 69 id<FindInPageControllerDelegate> _delegate; | 73 id<FindInPageControllerDelegate> _delegate; |
| 70 | 74 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 130 |
| 127 // Initialize the module with our frame size. | 131 // Initialize the module with our frame size. |
| 128 CGRect frame = [_webViewProxy bounds]; | 132 CGRect frame = [_webViewProxy bounds]; |
| 129 [_findInPageJsManager setWidth:frame.size.width height:frame.size.height]; | 133 [_findInPageJsManager setWidth:frame.size.width height:frame.size.height]; |
| 130 } | 134 } |
| 131 | 135 |
| 132 - (CRWWebViewScrollViewProxy*)webViewScrollView { | 136 - (CRWWebViewScrollViewProxy*)webViewScrollView { |
| 133 return [_webViewProxy scrollViewProxy]; | 137 return [_webViewProxy scrollViewProxy]; |
| 134 } | 138 } |
| 135 | 139 |
| 140 - (CGPoint)limitoverscroll:(CRWWebViewScrollViewProxy*)scrollViewProxy | |
|
shreyasv1
2015/04/08 20:55:58
Declaration does not match definition.
| |
| 141 atPoint:(CGPpoint)point { | |
| 142 CGFloat contentHeight = scrollViewProxy.contentSize.height; | |
| 143 CGFloat frameHeight = scrollViewProxy.frame.size.height; | |
| 144 CGFloat maxScroll = std::max((CGFloat)0, contentHeight - frameHeight); | |
| 145 if (point.y > maxScroll) { | |
| 146 point.y = maxScroll; | |
| 147 } | |
| 148 return point; | |
| 149 } | |
| 150 | |
| 136 - (void)processPumpResult:(BOOL)finished | 151 - (void)processPumpResult:(BOOL)finished |
| 137 scrollPoint:(CGPoint)scrollPoint | 152 scrollPoint:(CGPoint)scrollPoint |
| 138 completionHandler:(ProceduralBlock)completionHandler { | 153 completionHandler:(ProceduralBlock)completionHandler { |
| 139 if (finished) { | 154 if (finished) { |
| 140 [_delegate willAdjustScrollPosition]; | 155 [_delegate willAdjustScrollPosition]; |
| 156 scrollPoint = [self limitOverscroll:[_webViewProxy scrollViewProxy] | |
| 157 atPoint:scrollPoint]; | |
| 141 [[_webViewProxy scrollViewProxy] setContentOffset:scrollPoint animated:YES]; | 158 [[_webViewProxy scrollViewProxy] setContentOffset:scrollPoint animated:YES]; |
| 142 if (completionHandler) | 159 if (completionHandler) |
| 143 completionHandler(); | 160 completionHandler(); |
| 144 } else { | 161 } else { |
| 145 [self performSelector:@selector(startPumpingWithCompletionHandler:) | 162 [self performSelector:@selector(startPumpingWithCompletionHandler:) |
| 146 withObject:completionHandler | 163 withObject:completionHandler |
| 147 afterDelay:kRecurringPumpDelay]; | 164 afterDelay:kRecurringPumpDelay]; |
| 148 } | 165 } |
| 149 } | 166 } |
| 150 | 167 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } | 209 } |
| 193 | 210 |
| 194 - (void)pumpFindStringInPageWithCompletionHandler: | 211 - (void)pumpFindStringInPageWithCompletionHandler: |
| 195 (void (^)(BOOL))completionHandler { | 212 (void (^)(BOOL))completionHandler { |
| 196 base::WeakNSObject<FindInPageController> weakSelf(self); | 213 base::WeakNSObject<FindInPageController> weakSelf(self); |
| 197 [_findInPageJsManager pumpWithCompletionHandler:^(BOOL finished, | 214 [_findInPageJsManager pumpWithCompletionHandler:^(BOOL finished, |
| 198 CGPoint point) { | 215 CGPoint point) { |
| 199 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); | 216 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); |
| 200 if (finished) { | 217 if (finished) { |
| 201 [[strongSelf delegate] willAdjustScrollPosition]; | 218 [[strongSelf delegate] willAdjustScrollPosition]; |
| 219 point = [strongSelf limitOverscroll:[strongSelf webViewScrollView] | |
| 220 atPoint:point]; | |
| 202 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; | 221 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; |
| 203 } | 222 } |
| 204 completionHandler(finished); | 223 completionHandler(finished); |
| 205 }]; | 224 }]; |
| 206 } | 225 } |
| 207 | 226 |
| 208 - (void)findNextStringInPageWithCompletionHandler: | 227 - (void)findNextStringInPageWithCompletionHandler: |
| 209 (ProceduralBlock)completionHandler { | 228 (ProceduralBlock)completionHandler { |
| 210 [self initFindInPage]; | 229 [self initFindInPage]; |
| 211 base::WeakNSObject<FindInPageController> weakSelf(self); | 230 base::WeakNSObject<FindInPageController> weakSelf(self); |
| 212 [_findInPageJsManager nextMatchWithCompletionHandler:^(CGPoint point) { | 231 [_findInPageJsManager nextMatchWithCompletionHandler:^(CGPoint point) { |
| 213 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); | 232 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); |
| 214 [[strongSelf delegate] willAdjustScrollPosition]; | 233 [[strongSelf delegate] willAdjustScrollPosition]; |
| 215 CGFloat contentHeight = [strongSelf webViewScrollView].contentSize.height; | 234 point = [strongSelf limitOverscroll:[strongSelf webViewScrollView] |
| 216 CGFloat frameHeight = [strongSelf webViewScrollView].frame.size.height; | 235 atPoint:point]; |
| 217 CGFloat maxScroll = fmax(0, contentHeight - frameHeight); | |
| 218 if (point.y > maxScroll) { | |
| 219 point.y = maxScroll; | |
| 220 } | |
| 221 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; | 236 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; |
| 222 if (completionHandler) | 237 if (completionHandler) |
| 223 completionHandler(); | 238 completionHandler(); |
| 224 }]; | 239 }]; |
| 225 } | 240 } |
| 226 | 241 |
| 227 // Highlight the previous search match, update model and scroll to match. | 242 // Highlight the previous search match, update model and scroll to match. |
| 228 - (void)findPreviousStringInPageWithCompletionHandler: | 243 - (void)findPreviousStringInPageWithCompletionHandler: |
| 229 (ProceduralBlock)completionHandler { | 244 (ProceduralBlock)completionHandler { |
| 230 [self initFindInPage]; | 245 [self initFindInPage]; |
| 231 base::WeakNSObject<FindInPageController> weakSelf(self); | 246 base::WeakNSObject<FindInPageController> weakSelf(self); |
| 232 [_findInPageJsManager previousMatchWithCompletionHandler:^(CGPoint point) { | 247 [_findInPageJsManager previousMatchWithCompletionHandler:^(CGPoint point) { |
| 233 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); | 248 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); |
| 234 [[strongSelf delegate] willAdjustScrollPosition]; | 249 [[strongSelf delegate] willAdjustScrollPosition]; |
| 250 point = [strongSelf limitOverscroll:[strongSelf webViewScrollView] | |
| 251 atPoint:point]; | |
| 235 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; | 252 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; |
| 236 if (completionHandler) | 253 if (completionHandler) |
| 237 completionHandler(); | 254 completionHandler(); |
| 238 }]; | 255 }]; |
| 239 } | 256 } |
| 240 | 257 |
| 241 // Remove highlights from the page and disable the model. | 258 // Remove highlights from the page and disable the model. |
| 242 - (void)disableFindInPageWithCompletionHandler: | 259 - (void)disableFindInPageWithCompletionHandler: |
| 243 (ProceduralBlock)completionHandler { | 260 (ProceduralBlock)completionHandler { |
| 244 if (![self canFindInPage]) | 261 if (![self canFindInPage]) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 | 365 |
| 349 - (BOOL)canReleaseDOMLock { | 366 - (BOOL)canReleaseDOMLock { |
| 350 return NO; | 367 return NO; |
| 351 } | 368 } |
| 352 | 369 |
| 353 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler { | 370 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler { |
| 354 NOTREACHED(); | 371 NOTREACHED(); |
| 355 } | 372 } |
| 356 | 373 |
| 357 @end | 374 @end |
| OLD | NEW |