1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
22 #include "CyteKit/UCPlatform.h"
24 #include "CyteKit/dispatchEvent.h"
25 #include "CyteKit/WebView.h"
27 #include "Substrate.hpp"
29 #include "iPhonePrivate.h"
31 // CYWebPolicyDecision* {{{
32 @interface CYWebPolicyDecisionMediator : NSObject <
33 WebPolicyDecisionListener
35 id<WebPolicyDecisionListener> listener_;
36 CYWebPolicyDecision decision_;
39 - (id) initWithListener:(id<WebPolicyDecisionListener>)listener;
41 - (CYWebPolicyDecision) decision;
47 @implementation CYWebPolicyDecisionMediator
49 - (id) initWithListener:(id<WebPolicyDecisionListener>)listener {
50 if ((self = [super init]) != nil) {
55 - (CYWebPolicyDecision) decision {
60 return decision_ != CYWebPolicyDecisionUnknown;
65 case CYWebPolicyDecisionUnknown:
67 NSLog(@"CYWebPolicyDecisionUnknown");
70 case CYWebPolicyDecisionDownload: [listener_ download]; break;
71 case CYWebPolicyDecisionIgnore: [listener_ ignore]; break;
72 case CYWebPolicyDecisionUse: [listener_ use]; break;
79 decision_ = CYWebPolicyDecisionDownload;
83 decision_ = CYWebPolicyDecisionIgnore;
87 decision_ = CYWebPolicyDecisionUse;
93 @implementation CyteWebView : UIWebView {
97 #include "CyteKit/UCInternal.h"
100 - (id) initWithFrame:(CGRect)frame {
101 if ((self = [super initWithFrame:frame]) != nil) {
106 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
107 UIWebViewInternal *&_internal(MSHookIvar<UIWebViewInternal *>(self, "_internal"));
108 if (&_internal != NULL) {
109 UIWebViewWebViewDelegate *&webViewDelegate(MSHookIvar<UIWebViewWebViewDelegate *>(_internal, "webViewDelegate"));
110 if (&webViewDelegate != NULL)
111 [webViewDelegate _clearUIWebView];
118 - (NSString *) description {
119 return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[[self request] URL] absoluteString]];
122 - (id<CyteWebViewDelegate>) delegate {
123 return (id<CyteWebViewDelegate>) [super delegate];
126 - (void) setDelegate:(id<CyteWebViewDelegate>)delegate {
127 [super setDelegate:delegate];
130 /*- (WebView *) webView:(WebView *)view createWebViewWithRequest:(NSURLRequest *)request {
131 id<CyteWebViewDelegate> delegate([self delegate]);
132 WebView *created(nil);
133 if (created == nil && [delegate respondsToSelector:@selector(webView:createWebViewWithRequest:)])
134 created = [delegate webView:view createWebViewWithRequest:request];
135 if (created == nil && [UIWebView instancesRespondToSelector:@selector(webView:createWebViewWithRequest:)])
136 created = [super webView:view createWebViewWithRequest:request];
140 // webView:addMessageToConsole: (X.Xx) {{{
141 static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) {
142 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
143 if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)])
144 [uiWebView webView:view addMessageToConsole:message];
147 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
148 id<CyteWebViewDelegate> delegate([self delegate]);
149 if ([delegate respondsToSelector:@selector(webView:addMessageToConsole:)])
150 [delegate webView:view addMessageToConsole:message];
151 if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)])
152 [super webView:view addMessageToConsole:message];
155 // webView:decidePolicyForNavigationAction:request:frame:decisionListener: (2.0+) {{{
156 - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
157 id<CyteWebViewDelegate> delegate([self delegate]);
158 CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]);
159 if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)])
160 [delegate webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator];
161 if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)])
162 [super webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator];
163 if ([delegate respondsToSelector:@selector(webView:didDecidePolicy:forNavigationAction:request:frame:)])
164 [delegate webView:view didDecidePolicy:[mediator decision] forNavigationAction:action request:request frame:frame];
168 // webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: (3.0+) {{{
169 static void $UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *action, NSURLRequest *request, NSString *frame, id<WebPolicyDecisionListener> listener) {
170 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
171 if ([uiWebView respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
172 [uiWebView webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:listener];
175 - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
176 id<CyteWebViewDelegate> delegate([self delegate]);
177 CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]);
178 if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
179 [delegate webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator];
180 if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
181 [super webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator];
185 // webView:didClearWindowObject:forFrame: (3.2+) {{{
186 static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
187 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
188 if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
189 [uiWebView webView:view didClearWindowObject:window forFrame:frame];
192 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
193 id<CyteWebViewDelegate> delegate([self delegate]);
194 if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
195 [delegate webView:view didClearWindowObject:window forFrame:frame];
196 if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)])
197 [super webView:view didClearWindowObject:window forFrame:frame];
200 // webView:didCommitLoadForFrame: (3.0+) {{{
201 static void $UIWebViewWebViewDelegate$webView$didCommitLoadForFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebFrame *frame) {
202 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
203 if ([uiWebView respondsToSelector:@selector(webView:didCommitLoadForFrame:)])
204 [uiWebView webView:view didCommitLoadForFrame:frame];
207 - (void) webView:(WebView *)view didCommitLoadForFrame:(WebFrame *)frame {
208 id<CyteWebViewDelegate> delegate([self delegate]);
209 if ([delegate respondsToSelector:@selector(webView:didCommitLoadForFrame:)])
210 [delegate webView:view didCommitLoadForFrame:frame];
211 if ([UIWebView instancesRespondToSelector:@selector(webView:didCommitLoadForFrame:)])
212 [super webView:view didCommitLoadForFrame:frame];
215 // webView:didFailLoadWithError:forFrame: (2.0+) {{{
216 - (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
217 id<CyteWebViewDelegate> delegate([self delegate]);
218 if ([delegate respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
219 [delegate webView:view didFailLoadWithError:error forFrame:frame];
220 if ([UIWebView instancesRespondToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
221 [super webView:view didFailLoadWithError:error forFrame:frame];
224 // webView:didFailProvisionalLoadWithError:forFrame: (2.0+) {{{
225 - (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
226 id<CyteWebViewDelegate> delegate([self delegate]);
227 if ([delegate respondsToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)])
228 [delegate webView:view didFailProvisionalLoadWithError:error forFrame:frame];
229 if ([UIWebView instancesRespondToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)])
230 [super webView:view didFailProvisionalLoadWithError:error forFrame:frame];
233 // webView:didFinishLoadForFrame: (2.0+) {{{
234 - (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame {
235 id<CyteWebViewDelegate> delegate([self delegate]);
236 if ([delegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)])
237 [delegate webView:view didFinishLoadForFrame:frame];
238 if ([UIWebView instancesRespondToSelector:@selector(webView:didFinishLoadForFrame:)])
239 [super webView:view didFinishLoadForFrame:frame];
242 // webView:didReceiveTitle:forFrame: (3.2+) {{{
243 static void $UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSString *title, WebFrame *frame) {
244 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
245 if ([uiWebView respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)])
246 [uiWebView webView:view didReceiveTitle:title forFrame:frame];
249 - (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
250 id<CyteWebViewDelegate> delegate([self delegate]);
251 if ([delegate respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)])
252 [delegate webView:view didReceiveTitle:title forFrame:frame];
253 if ([UIWebView instancesRespondToSelector:@selector(webView:didReceiveTitle:forFrame:)])
254 [super webView:view didReceiveTitle:title forFrame:frame];
257 // webView:didStartProvisionalLoadForFrame: (2.0+) {{{
258 - (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame {
259 id<CyteWebViewDelegate> delegate([self delegate]);
260 if ([delegate respondsToSelector:@selector(webView:didStartProvisionalLoadForFrame:)])
261 [delegate webView:view didStartProvisionalLoadForFrame:frame];
262 if ([UIWebView instancesRespondToSelector:@selector(webView:didStartProvisionalLoadForFrame:)])
263 [super webView:view didStartProvisionalLoadForFrame:frame];
266 // webView:resource:didCancelAuthenticationChallenge:fromDataSource: {{{
267 - (void) webView:(WebView *)view resource:(id)identifier didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
268 id<CyteWebViewDelegate> delegate([self delegate]);
269 if ([UIWebView respondsToSelector:@selector(webView:resource:didCancelAuthenticationChallenge:fromDataSource:)])
270 [super webView:view resource:identifier didCancelAuthenticationChallenge:challenge fromDataSource:source];
271 if ([delegate respondsToSelector:@selector(webView:resource:didCancelAuthenticationChallenge:fromDataSource:)])
272 [delegate webView:view resource:identifier didCancelAuthenticationChallenge:challenge fromDataSource:source];
275 // webView:resource:didReceiveAuthenticationChallenge:fromDataSource: {{{
276 - (void) webView:(WebView *)view resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
277 id<CyteWebViewDelegate> delegate([self delegate]);
278 if ([UIWebView respondsToSelector:@selector(webView:resource:didReceiveAuthenticationChallenge:fromDataSource:)])
279 [super webView:view resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
280 if ([delegate respondsToSelector:@selector(webView:resource:didReceiveAuthenticationChallenge:fromDataSource:)])
281 [delegate webView:view resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
284 // webView:resource:willSendRequest:redirectResponse:fromDataSource: (3.2+) {{{
285 static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, id identifier, NSURLRequest *request, NSURLResponse *response, WebDataSource *source) {
286 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
287 if ([uiWebView respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
288 request = [uiWebView webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
292 - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
293 id<CyteWebViewDelegate> delegate([self delegate]);
294 if ([UIWebView instancesRespondToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
295 request = [super webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
296 if ([delegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
297 request = [delegate webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
301 // webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource: {{{
302 - (NSURLRequest *) webThreadWebView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
303 id<CyteWebViewDelegate> delegate([self delegate]);
304 if ([UIWebView instancesRespondToSelector:@selector(webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource:)])
305 request = [super webThreadWebView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
306 if ([delegate respondsToSelector:@selector(webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource:)])
307 request = [delegate webThreadWebView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
311 // webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.1+) {{{
312 - (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
313 [[self retain] autorelease];
314 id<CyteWebViewDelegate> delegate([self delegate]);
315 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)])
317 ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptAlertPanelWithMessage:initiatedByFrame:)] ||
318 [delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame]
320 [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame];
323 // webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.1+) {{{
324 - (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
325 [[self retain] autorelease];
326 id<CyteWebViewDelegate> delegate([self delegate]);
327 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)])
329 ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptConfirmPanelWithMessage:initiatedByFrame:)] ||
330 [delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame]
332 return [super webView:view runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame];
336 // webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.1+) {{{
337 - (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
338 [[self retain] autorelease];
339 id<CyteWebViewDelegate> delegate([self delegate]);
340 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)])
342 ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)] ||
343 [delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame]
345 return [super webView:view runJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame];
349 // webViewClose: (3.2+) {{{
350 static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view) {
351 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
352 if ([uiWebView respondsToSelector:@selector(webViewClose:)])
353 [uiWebView webViewClose:view];
356 - (void) webViewClose:(WebView *)view {
357 id<CyteWebViewDelegate> delegate([self delegate]);
358 if ([delegate respondsToSelector:@selector(webViewClose:)])
359 [delegate webViewClose:view];
360 if ([UIWebView instancesRespondToSelector:@selector(webViewClose:)])
361 [super webViewClose:view];
365 - (void) _updateViewSettings {
366 [super _updateViewSettings];
368 id<CyteWebViewDelegate> delegate([self delegate]);
369 if ([delegate respondsToSelector:@selector(webViewUpdateViewSettings:)])
370 [delegate webViewUpdateViewSettings:self];
373 - (void) dispatchEvent:(NSString *)event {
374 [[self _documentView] dispatchEvent:event];
377 - (void) reloadFromOrigin {
378 [[[self _documentView] webView] reloadFromOrigin:nil];
381 - (UIScrollView *) scrollView {
382 if ([self respondsToSelector:@selector(_scrollView)])
383 return [self _scrollView];
384 else if ([self respondsToSelector:@selector(_scroller)])
385 return (UIScrollView *) [self _scroller];
389 - (void) setNeedsLayout {
390 [super setNeedsLayout];
392 WebFrame *frame([[[self _documentView] webView] mainFrame]);
393 if ([frame respondsToSelector:@selector(setNeedsLayout)])
394 [frame setNeedsLayout];
397 - (NSURLRequest *) request {
398 WebFrame *frame([[[self _documentView] webView] mainFrame]);
399 return [([frame provisionalDataSource] ?: [frame dataSource]) request];
404 static void $UIWebViewWebViewDelegate$_clearUIWebView(UIWebViewWebViewDelegate *self, SEL sel) {
405 MSHookIvar<UIWebView *>(self, "uiWebView") = nil;
408 __attribute__((__constructor__)) static void $() {
409 if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
410 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12");
411 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24");
412 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16");
413 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didCommitLoadForFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didCommitLoadForFrame$, "v16@0:4@8@12");
414 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16");
415 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), (IMP) &$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$, "@28@0:4@8@12@16@20@24");
416 class_addMethod($UIWebViewWebViewDelegate, @selector(webViewClose:), (IMP) &$UIWebViewWebViewDelegate$webViewClose$, "v12@0:4@8");
417 class_addMethod($UIWebViewWebViewDelegate, @selector(_clearUIWebView), (IMP) &$UIWebViewWebViewDelegate$_clearUIWebView, "v8@0:4");
421 @implementation UIWebDocumentView (Cydia)
423 - (void) _setScrollerOffset:(CGPoint)offset {
424 UIScroller *scroller([self _scroller]);
426 CGSize size([scroller contentSize]);
427 CGSize bounds([scroller bounds].size);
430 max.x = size.width - bounds.width;
431 max.y = size.height - bounds.height;
439 offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
440 offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
442 [scroller setOffset:offset];