blob: d46735eb70845fa7f20f125d107a2f7568a35d50 [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_CRW_WEB_VIEW_SCROLL_VIEW_PROXY_H_
#define IOS_WEB_PUBLIC_WEB_STATE_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(kkhorimoto): rename class to CRWContentViewScrollViewProxy.
@interface CRWWebViewScrollViewProxy : NSObject<UIScrollViewDelegate>
@property(nonatomic, assign) CGPoint contentOffset;
@property(nonatomic, assign) UIEdgeInsets contentInset;
@property(nonatomic, readonly) BOOL isZooming;
@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, readonly) UIPanGestureRecognizer* panGestureRecognizer;
// Returns the scrollview's gesture recognizers.
@property(nonatomic, readonly) NSArray* gestureRecognizers;
// Calls UIScrollView's implementation of setContentInset: directly. This
// bypasses a very slow update path in UIWebView.
- (void)setContentInsetFast:(UIEdgeInsets)contentInset;
- (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)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;
@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_CRW_WEB_VIEW_SCROLL_VIEW_PROXY_H_