OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/web_view/public/cwv_scroll_view.h" |
| 6 |
| 7 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h" |
| 8 #import "ios/web_view/internal/cwv_scroll_view_internal.h" |
| 9 #import "ios/web_view/public/cwv_scroll_view_delegate.h" |
| 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
| 15 @interface CWVScrollView ()<CRWWebViewScrollViewProxyObserver> |
| 16 |
| 17 // For KVO compliance, redefines the property as readwrite and calls its setter |
| 18 // when the value changes, instead of defining a getter which directly calls |
| 19 // _proxy.contentSize. |
| 20 @property(nonatomic, readwrite) CGSize contentSize; |
| 21 |
| 22 @end |
| 23 |
| 24 @implementation CWVScrollView |
| 25 |
| 26 @synthesize contentSize = _contentSize; |
| 27 @synthesize delegate = _delegate; |
| 28 @synthesize proxy = _proxy; |
| 29 |
| 30 - (void)setProxy:(nullable CRWWebViewScrollViewProxy*)proxy { |
| 31 [_proxy removeObserver:self]; |
| 32 _proxy = proxy; |
| 33 self.contentSize = _proxy.contentSize; |
| 34 [_proxy addObserver:self]; |
| 35 } |
| 36 |
| 37 - (CGPoint)contentOffset { |
| 38 return _proxy.contentOffset; |
| 39 } |
| 40 |
| 41 - (void)setContentOffset:(CGPoint)contentOffset { |
| 42 _proxy.contentOffset = contentOffset; |
| 43 } |
| 44 |
| 45 - (CGRect)bounds { |
| 46 return {_proxy.contentOffset, _proxy.frame.size}; |
| 47 } |
| 48 |
| 49 - (BOOL)isDragging { |
| 50 return _proxy.dragging; |
| 51 } |
| 52 |
| 53 - (UIEdgeInsets)contentInset { |
| 54 return _proxy.contentInset; |
| 55 } |
| 56 |
| 57 - (void)setContentInset:(UIEdgeInsets)contentInset { |
| 58 _proxy.contentInset = contentInset; |
| 59 } |
| 60 |
| 61 - (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer { |
| 62 [_proxy addGestureRecognizer:gestureRecognizer]; |
| 63 } |
| 64 |
| 65 #pragma mark - CRWWebViewScrollViewObserver |
| 66 |
| 67 - (void)webViewScrollViewWillBeginDragging: |
| 68 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| 69 SEL selector = @selector(webViewScrollViewWillBeginDragging:); |
| 70 if ([_delegate respondsToSelector:selector]) { |
| 71 [_delegate scrollViewWillBeginDragging:self]; |
| 72 } |
| 73 } |
| 74 - (void)webViewScrollViewWillEndDragging: |
| 75 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy |
| 76 withVelocity:(CGPoint)velocity |
| 77 targetContentOffset:(inout CGPoint*)targetContentOffset { |
| 78 SEL selector = @selector |
| 79 (webViewScrollViewWillEndDragging:withVelocity:targetContentOffset:); |
| 80 if ([_delegate respondsToSelector:selector]) { |
| 81 [_delegate scrollViewWillEndDragging:self |
| 82 withVelocity:velocity |
| 83 targetContentOffset:targetContentOffset]; |
| 84 } |
| 85 } |
| 86 |
| 87 - (void)webViewScrollViewDidScroll: |
| 88 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| 89 SEL selector = @selector(scrollViewDidScroll:); |
| 90 if ([_delegate respondsToSelector:selector]) { |
| 91 [_delegate scrollViewDidScroll:self]; |
| 92 } |
| 93 } |
| 94 |
| 95 - (void)webViewScrollViewDidEndDecelerating: |
| 96 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| 97 SEL selector = @selector(webViewScrollViewDidEndDecelerating:); |
| 98 if ([_delegate respondsToSelector:selector]) { |
| 99 [_delegate scrollViewDidEndDecelerating:self]; |
| 100 } |
| 101 } |
| 102 |
| 103 - (void)webViewScrollViewDidResetContentSize: |
| 104 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| 105 self.contentSize = _proxy.contentSize; |
| 106 } |
| 107 |
| 108 @end |
OLD | NEW |