blob: 54cbbea01b9cf1c57cfddecff5836686b65d1530 [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_WEB_STATE_UI_CRW_WEB_VIEW_SCROLL_VIEW_PROXY_H_
#define IOS_WEB_PUBLIC_WEB_STATE_UI_CRW_WEB_VIEW_SCROLL_VIEW_PROXY_H_
#import <UIKit/UIKit.h>
@protocol CRWWebViewScrollViewProxyObserver;
// Provides an interface for web state observers to access the WebState's
// UIScrollView in a limited and controlled manner.
// This class is designed to limit lifetime of the UIScrollView such that it is
// not retained beyond WebState. It is also a way to tunnel UIScrollViewDelegate
// callbacks.
// NOTE: The API exposed by the proxy class isn't intended to be restrictive.
// The features needing to access other UIScrollView properties and methods
// needed to drive the UIScrollView are free to extend the proxy class as
// needed.
// The class forwards some of the methods onto the UIScrollView. For more
// information look at the UIScrollView documentation.
// TODO(crbug.com/546152): rename class to CRWContentViewScrollViewProxy.
@interface CRWWebViewScrollViewProxy : NSObject<UIScrollViewDelegate>
@property(nonatomic, assign) CGPoint contentOffset;
@property(nonatomic, assign) UIEdgeInsets contentInset;
@property(nonatomic, readonly, getter=isDecelerating) BOOL decelerating;
@property(nonatomic, readonly, getter=isDragging) BOOL dragging;
@property(nonatomic, readonly, getter=isTracking) BOOL tracking;
@property(nonatomic, readonly) BOOL isZooming;
@property(nonatomic, readonly) CGFloat zoomScale;
@property(nonatomic, assign) UIEdgeInsets scrollIndicatorInsets;
@property(nonatomic, assign) CGSize contentSize;
@property(nonatomic, readonly) CGRect frame;
@property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
@property(nonatomic, assign) BOOL bounces;
@property(nonatomic, assign) BOOL scrollsToTop;
@property(nonatomic, assign)
UIScrollViewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior
API_AVAILABLE(ios(11.0));
@property(weak, nonatomic, readonly)
UIPanGestureRecognizer* panGestureRecognizer;
// Returns the scrollview's gesture recognizers.
@property(weak, nonatomic, readonly) NSArray* gestureRecognizers;
@property(nonatomic, readonly, copy) NSArray<__kindof UIView*>* subviews;
- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer;
- (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer;
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;
// Used by the CRWWebViewProxy to set the UIScrollView to be managed.
- (void)setScrollView:(UIScrollView*)scrollView;
// Adds |observer| to subscribe to change notifications.
- (void)addObserver:(id<CRWWebViewScrollViewProxyObserver>)observer;
// Removes |observer| as a subscriber for change notifications.
- (void)removeObserver:(id<CRWWebViewScrollViewProxyObserver>)observer;
@end
// A protocol to be implemented by objects to listen for changes to the
// UIScrollView.
// This is an exact mirror of the UIScrollViewDelegate callbacks. For more
// information look at the UIScrollViewDelegate documentation.
@protocol CRWWebViewScrollViewObserver<NSObject>
@optional
- (void)webViewScrollViewFrameDidChange:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewDidScroll:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewWillBeginDragging:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewWillEndDragging:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint*)targetContentOffset;
- (void)webViewScrollViewDidEndDragging:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy
willDecelerate:(BOOL)decelerate;
- (void)webViewScrollViewDidEndScrollingAnimation:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewDidEndDecelerating:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (BOOL)webViewScrollViewShouldScrollToTop:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewDidZoom:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewDidResetContentSize:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewDidResetContentInset:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
// The equivalent in UIScrollViewDelegate also takes a parameter (UIView*)view,
// but CRWWebViewScrollViewObserver doesn't expose it for flexibility of future
// implementation.
- (void)webViewScrollViewWillBeginZooming:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
- (void)webViewScrollViewDidEndZooming:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy
atScale:(CGFloat)scale;
@end
// A protocol to be implemented by objects to listen for changes to the
// CRWWebViewScrollViewProxyObserver.
// It inherit from CRWWebViewScrollViewScrollViewObserver which only implements
// methods for listening to scrollview changes.
@protocol CRWWebViewScrollViewProxyObserver<CRWWebViewScrollViewObserver>
@optional
// Called when the underlying scrollview of the proxy is set.
- (void)webViewScrollViewProxyDidSetScrollView:
(CRWWebViewScrollViewProxy*)webViewScrollViewProxy;
@end
#endif // IOS_WEB_PUBLIC_WEB_STATE_UI_CRW_WEB_VIEW_SCROLL_VIEW_PROXY_H_