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

Side by Side Diff: ios/chrome/browser/find_in_page/find_in_page_controller.mm

Issue 1071723002: [Find in Page] Prevent scrolling past the page edge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Gives find in page more time to complete. Calls |completionHandler| with 51 // Gives find in page more time to complete. Calls |completionHandler| with
52 // a BOOL indicating if the find operation was successfull. |completionHandler| 52 // a BOOL indicating if the find operation was successfull. |completionHandler|
53 // can be nil. 53 // can be nil.
54 - (void)pumpFindStringInPageWithCompletionHandler: 54 - (void)pumpFindStringInPageWithCompletionHandler:
55 (void (^)(BOOL))completionHandler; 55 (void (^)(BOOL))completionHandler;
56 // Processes the result of a single find in page pump. Calls |completionHandler| 56 // Processes the result of a single find in page pump. Calls |completionHandler|
57 // if pumping is done. Re-pumps if necessary. 57 // if pumping is done. Re-pumps if necessary.
58 - (void)processPumpResult:(BOOL)finished 58 - (void)processPumpResult:(BOOL)finished
59 scrollPoint:(CGPoint)scrollPoint 59 scrollPoint:(CGPoint)scrollPoint
60 completionHandler:(ProceduralBlock)completionHandler; 60 completionHandler:(ProceduralBlock)completionHandler;
61 // Prevent overscroll.
sdefresne 2015/04/08 20:02:19 API recommendation: since each invocation follow t
justincohen 2015/04/08 20:25:51 messaged offline about this.
62 - (CGPoint)limitOverscroll:(CRWWebViewScrollViewProxy*)scrollViewProxy
63 atPoint:(CGPpoint)point;
61 // Returns the associated web state. May be null. 64 // Returns the associated web state. May be null.
62 - (web::WebState*)webState; 65 - (web::WebState*)webState;
63 @end 66 @end
64 67
65 @implementation FindInPageController { 68 @implementation FindInPageController {
66 @private 69 @private
67 // Object that manages find_in_page.js injection into the web view. 70 // Object that manages find_in_page.js injection into the web view.
68 JsFindinpageManager* _findInPageJsManager; 71 JsFindinpageManager* _findInPageJsManager;
69 id<FindInPageControllerDelegate> _delegate; 72 id<FindInPageControllerDelegate> _delegate;
70 73
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 129
127 // Initialize the module with our frame size. 130 // Initialize the module with our frame size.
128 CGRect frame = [_webViewProxy bounds]; 131 CGRect frame = [_webViewProxy bounds];
129 [_findInPageJsManager setWidth:frame.size.width height:frame.size.height]; 132 [_findInPageJsManager setWidth:frame.size.width height:frame.size.height];
130 } 133 }
131 134
132 - (CRWWebViewScrollViewProxy*)webViewScrollView { 135 - (CRWWebViewScrollViewProxy*)webViewScrollView {
133 return [_webViewProxy scrollViewProxy]; 136 return [_webViewProxy scrollViewProxy];
134 } 137 }
135 138
139 - (CGPoint)limitoverscroll:(CRWWebViewScrollViewProxy*)scrollViewProxy
140 atPoint:(CGPpoint)point {
141 CGFloat contentHeight = scrollViewProxy.contentSize.height;
142 CGFloat frameHeight = scrollViewProxy.frame.size.height;
143 CGFloat maxScroll = fmax(0, contentHeight - frameHeight);
sdefresne 2015/04/08 20:02:19 nit: please use std::max() from <cmath>
justincohen 2015/04/08 20:25:51 Done.
144 if (point.y > maxScroll) {
145 point.y = maxScroll;
146 }
147 return point;
148 }
149
136 - (void)processPumpResult:(BOOL)finished 150 - (void)processPumpResult:(BOOL)finished
137 scrollPoint:(CGPoint)scrollPoint 151 scrollPoint:(CGPoint)scrollPoint
138 completionHandler:(ProceduralBlock)completionHandler { 152 completionHandler:(ProceduralBlock)completionHandler {
139 if (finished) { 153 if (finished) {
140 [_delegate willAdjustScrollPosition]; 154 [_delegate willAdjustScrollPosition];
155 scrollPoint = [self limitOverscroll:[_webViewProxy scrollViewProxy]
156 atPoint:scrollPoint];
141 [[_webViewProxy scrollViewProxy] setContentOffset:scrollPoint animated:YES]; 157 [[_webViewProxy scrollViewProxy] setContentOffset:scrollPoint animated:YES];
142 if (completionHandler) 158 if (completionHandler)
143 completionHandler(); 159 completionHandler();
144 } else { 160 } else {
145 [self performSelector:@selector(startPumpingWithCompletionHandler:) 161 [self performSelector:@selector(startPumpingWithCompletionHandler:)
146 withObject:completionHandler 162 withObject:completionHandler
147 afterDelay:kRecurringPumpDelay]; 163 afterDelay:kRecurringPumpDelay];
148 } 164 }
149 } 165 }
150 166
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 208 }
193 209
194 - (void)pumpFindStringInPageWithCompletionHandler: 210 - (void)pumpFindStringInPageWithCompletionHandler:
195 (void (^)(BOOL))completionHandler { 211 (void (^)(BOOL))completionHandler {
196 base::WeakNSObject<FindInPageController> weakSelf(self); 212 base::WeakNSObject<FindInPageController> weakSelf(self);
197 [_findInPageJsManager pumpWithCompletionHandler:^(BOOL finished, 213 [_findInPageJsManager pumpWithCompletionHandler:^(BOOL finished,
198 CGPoint point) { 214 CGPoint point) {
199 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); 215 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]);
200 if (finished) { 216 if (finished) {
201 [[strongSelf delegate] willAdjustScrollPosition]; 217 [[strongSelf delegate] willAdjustScrollPosition];
218 point =
219 [self limitOverscroll:[strongSelf webViewScrollView] atPoint:point];
sdefresne 2015/04/08 20:02:18 point = [strongSelf limitOverscroll:[strongSelf we
justincohen 2015/04/08 20:25:51 Done.
202 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; 220 [[strongSelf webViewScrollView] setContentOffset:point animated:YES];
203 } 221 }
204 completionHandler(finished); 222 completionHandler(finished);
205 }]; 223 }];
206 } 224 }
207 225
208 - (void)findNextStringInPageWithCompletionHandler: 226 - (void)findNextStringInPageWithCompletionHandler:
209 (ProceduralBlock)completionHandler { 227 (ProceduralBlock)completionHandler {
210 [self initFindInPage]; 228 [self initFindInPage];
211 base::WeakNSObject<FindInPageController> weakSelf(self); 229 base::WeakNSObject<FindInPageController> weakSelf(self);
212 [_findInPageJsManager nextMatchWithCompletionHandler:^(CGPoint point) { 230 [_findInPageJsManager nextMatchWithCompletionHandler:^(CGPoint point) {
213 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); 231 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]);
214 [[strongSelf delegate] willAdjustScrollPosition]; 232 [[strongSelf delegate] willAdjustScrollPosition];
215 CGFloat contentHeight = [strongSelf webViewScrollView].contentSize.height; 233 point = [self limitOverscroll:[strongSelf webViewScrollView] atPoint:point];
sdefresne 2015/04/08 20:02:18 point = [strongSelf limitOverscroll:[strongSelf we
justincohen 2015/04/08 20:25:51 Done.
216 CGFloat frameHeight = [strongSelf webViewScrollView].frame.size.height;
217 CGFloat maxScroll = fmax(0, contentHeight - frameHeight);
218 if (point.y > maxScroll) {
219 point.y = maxScroll;
220 }
221 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; 234 [[strongSelf webViewScrollView] setContentOffset:point animated:YES];
222 if (completionHandler) 235 if (completionHandler)
223 completionHandler(); 236 completionHandler();
224 }]; 237 }];
225 } 238 }
226 239
227 // Highlight the previous search match, update model and scroll to match. 240 // Highlight the previous search match, update model and scroll to match.
228 - (void)findPreviousStringInPageWithCompletionHandler: 241 - (void)findPreviousStringInPageWithCompletionHandler:
229 (ProceduralBlock)completionHandler { 242 (ProceduralBlock)completionHandler {
230 [self initFindInPage]; 243 [self initFindInPage];
231 base::WeakNSObject<FindInPageController> weakSelf(self); 244 base::WeakNSObject<FindInPageController> weakSelf(self);
232 [_findInPageJsManager previousMatchWithCompletionHandler:^(CGPoint point) { 245 [_findInPageJsManager previousMatchWithCompletionHandler:^(CGPoint point) {
233 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]); 246 base::scoped_nsobject<FindInPageController> strongSelf([weakSelf retain]);
234 [[strongSelf delegate] willAdjustScrollPosition]; 247 [[strongSelf delegate] willAdjustScrollPosition];
248 point = [self limitOverscroll:[strongSelf webViewScrollView] atPoint:point];
sdefresne 2015/04/08 20:02:18 point = [strongSelf limitOverscroll:[strongSelf we
justincohen 2015/04/08 20:25:51 Done.
235 [[strongSelf webViewScrollView] setContentOffset:point animated:YES]; 249 [[strongSelf webViewScrollView] setContentOffset:point animated:YES];
236 if (completionHandler) 250 if (completionHandler)
237 completionHandler(); 251 completionHandler();
238 }]; 252 }];
239 } 253 }
240 254
241 // Remove highlights from the page and disable the model. 255 // Remove highlights from the page and disable the model.
242 - (void)disableFindInPageWithCompletionHandler: 256 - (void)disableFindInPageWithCompletionHandler:
243 (ProceduralBlock)completionHandler { 257 (ProceduralBlock)completionHandler {
244 if (![self canFindInPage]) 258 if (![self canFindInPage])
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 362
349 - (BOOL)canReleaseDOMLock { 363 - (BOOL)canReleaseDOMLock {
350 return NO; 364 return NO;
351 } 365 }
352 366
353 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler { 367 - (void)releaseDOMLockWithCompletionHandler:(ProceduralBlock)completionHandler {
354 NOTREACHED(); 368 NOTREACHED();
355 } 369 }
356 370
357 @end 371 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698