Chromium Code Reviews| 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 delegate = _delegate; | |
| 27 @synthesize proxy = _proxy; | |
| 28 @synthesize contentSize = _contentSize; | |
|
michaeldo
2017/05/01 18:49:53
nit: Please sort alphabetically.
Hiroshi Ichikawa
2017/05/08 06:52:41
Done.
| |
| 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)frame { | |
| 46 return _proxy.frame; | |
| 47 } | |
| 48 | |
| 49 - (CGRect)bounds { | |
| 50 return {_proxy.contentOffset, _proxy.frame.size}; | |
| 51 } | |
| 52 | |
| 53 - (BOOL)isDragging { | |
| 54 return _proxy.dragging; | |
| 55 } | |
| 56 | |
| 57 - (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer { | |
| 58 [_proxy addGestureRecognizer:gestureRecognizer]; | |
| 59 } | |
| 60 | |
| 61 - (UIEdgeInsets)contentInset { | |
| 62 return _proxy.contentInset; | |
| 63 } | |
| 64 | |
| 65 - (void)setContentInset:(UIEdgeInsets)contentInset { | |
| 66 _proxy.contentInset = contentInset; | |
| 67 } | |
| 68 | |
| 69 #pragma mark - CRWWebViewScrollViewObserver | |
| 70 | |
| 71 - (void)webViewScrollViewWillBeginDragging: | |
| 72 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | |
| 73 SEL selector = @selector(webViewScrollViewWillBeginDragging:); | |
| 74 if ([_delegate respondsToSelector:selector]) { | |
| 75 [_delegate scrollViewWillBeginDragging:self]; | |
| 76 } | |
| 77 } | |
| 78 - (void)webViewScrollViewWillEndDragging: | |
| 79 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy | |
| 80 withVelocity:(CGPoint)velocity | |
| 81 targetContentOffset:(inout CGPoint*)targetContentOffset { | |
| 82 SEL selector = @selector | |
| 83 (webViewScrollViewWillEndDragging:withVelocity:targetContentOffset:); | |
| 84 if ([_delegate respondsToSelector:selector]) { | |
| 85 [_delegate scrollViewWillEndDragging:self | |
| 86 withVelocity:velocity | |
| 87 targetContentOffset:targetContentOffset]; | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 - (void)webViewScrollViewDidScroll: | |
| 92 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | |
| 93 SEL selector = @selector(scrollViewDidScroll:); | |
| 94 if ([_delegate respondsToSelector:selector]) { | |
| 95 [_delegate scrollViewDidScroll:self]; | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 - (void)webViewScrollViewDidEndDecelerating: | |
| 100 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | |
| 101 SEL selector = @selector(webViewScrollViewDidEndDecelerating:); | |
| 102 if ([_delegate respondsToSelector:selector]) { | |
| 103 [_delegate scrollViewDidEndDecelerating:self]; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 - (void)webViewScrollViewDidResetContentSize: | |
| 108 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { | |
| 109 self.contentSize = _proxy.contentSize; | |
| 110 } | |
| 111 | |
| 112 @end | |
| OLD | NEW |