Commit d9a155a6 authored by droger's avatar droger Committed by Commit bot

[iOS] Upstream ios/chrome/browser/find_in_page

BUG=452495, 452492

Review URL: https://codereview.chromium.org/1023813003

Cr-Commit-Position: refs/heads/master@{#322349}
parent bb148160
// Copyright 2012 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_CHROME_BROWSER_FIND_IN_PAGE_FIND_IN_PAGE_CONTROLLER_H_
#define IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_IN_PAGE_CONTROLLER_H_
#import <Foundation/Foundation.h>
#include "base/ios/block_types.h"
namespace web {
class WebState;
}
@class FindInPageModel;
extern NSString* const kFindBarTextFieldWillBecomeFirstResponderNotification;
extern NSString* const kFindBarTextFieldDidResignFirstResponderNotification;
@protocol FindInPageControllerDelegate<NSObject>
// Informs the delegate when the scroll position is about to be changed on the
// page.
- (void)willAdjustScrollPosition;
@end
@interface FindInPageController : NSObject
// Designated initializer.
- (id)initWithWebState:(web::WebState*)webState
delegate:(id<FindInPageControllerDelegate>)delegate;
// Inject the find in page scripts into the web state.
- (void)initFindInPage;
// Find In Page model. TODO(justincohen) consider using find_tab_helper.cc.
- (FindInPageModel*)findInPageModel;
// Is Find In Page available right now (given the state of the WebState)?
- (BOOL)canFindInPage;
// Find |query| in page, update model with results of find. Calls
// |completionHandler| after the find operation is complete. |completionHandler|
// can be nil.
- (void)findStringInPage:(NSString*)query
completionHandler:(ProceduralBlock)completionHandler;
// Move to the next find result based on |-findInPageModel|, and scroll to
// match. Calls |completionHandler| when the next string has been found.
// |completionHandler| can be nil.
- (void)findNextStringInPageWithCompletionHandler:
(ProceduralBlock)completionHandler;
// Move to the previous find result based on |-findInPageModel|. Calls
// |completionHandler| when the previous string has been found.
// |completionHandler| can be nil.
- (void)findPreviousStringInPageWithCompletionHandler:
(ProceduralBlock)completionHandler;
// Disable find in page script and model. Calls |completionHandler| once the
// model has been disabled and cleanup is complete. |completionHandler| can be
// nil.
- (void)disableFindInPageWithCompletionHandler:
(ProceduralBlock)completionHandler;
// Save search term to Paste UIPasteboard.
- (void)saveSearchTerm;
// Restore search term from Paste UIPasteboard, updating findInPageModel.
- (void)restoreSearchTerm;
// Instructs the controller to detach itself from the web state.
- (void)detachFromWebState;
@end
#endif // IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_IN_PAGE_CONTROLLER_H_
This diff is collapsed.
// Copyright 2011 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_CHROME_BROWSER_FIND_IN_PAGE_FIND_IN_PAGE_MODEL_H_
#define IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_IN_PAGE_MODEL_H_
#import <UIKit/UIKit.h>
#include "base/mac/scoped_nsobject.h"
// This is a simplified version of find_tab_helper.cc.
@interface FindInPageModel : NSObject {
@private
// Should find in page be displayed.
BOOL enabled_;
// The current search string.
base::scoped_nsobject<NSString> text_;
// The number of matches for |text_|
NSUInteger matches_;
// The currently higlighted index.
NSUInteger currentIndex_;
// The content offset needed to display the |currentIndex_| match.
CGPoint currentPoint_;
}
@property(nonatomic, readwrite, assign) BOOL enabled;
@property(nonatomic, readonly) NSString* text;
@property(nonatomic, readonly) NSUInteger matches;
@property(nonatomic, readonly) NSUInteger currentIndex;
@property(nonatomic, readonly) CGPoint currentPoint;
// Update the query string and the number of matches.
- (void)updateQuery:(NSString*)query matches:(NSUInteger)matches;
// Update the current match index and its found position.
- (void)updateIndex:(NSInteger)index atPoint:(CGPoint)point;
@end
#endif // IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_IN_PAGE_MODEL_H_
// Copyright 2012 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.
#import "ios/chrome/browser/find_in_page/find_in_page_model.h"
@implementation FindInPageModel
@synthesize enabled = enabled_;
@synthesize matches = matches_;
@synthesize currentIndex = currentIndex_;
@synthesize currentPoint = currentPoint_;
- (NSString*)text {
return text_;
}
- (void)setEnabled:(BOOL)enabled {
enabled_ = enabled;
matches_ = 0;
currentIndex_ = 0;
currentPoint_ = CGPointZero;
}
- (void)updateQuery:(NSString*)query matches:(NSUInteger)matches {
if (query)
text_.reset([query copy]);
matches_ = matches;
currentIndex_ = 0;
}
- (void)updateIndex:(NSInteger)index atPoint:(CGPoint)point {
currentIndex_ = index;
currentPoint_ = point;
}
@end
// Copyright 2012 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_CHROME_BROWSER_FIND_IN_PAGE_JS_FINDINPAGE_MANAGER_H_
#define IOS_CHROME_BROWSER_FIND_IN_PAGE_JS_FINDINPAGE_MANAGER_H_
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGGeometry.h>
#include "base/ios/block_types.h"
#import "base/mac/scoped_nsobject.h"
#import "ios/web/public/web_state/js/crw_js_injection_manager.h"
// Data from find in page.
typedef struct FindInPageEntry {
CGPoint point; // Scroll offset required to center the highlighted item.
NSInteger index; // Currently higlighted search term.
} FindInPageEntry;
// Constant for "not found".
extern FindInPageEntry FindInPageEntryZero;
@class CRWJSInjectionReceiver;
@class FindInPageModel;
// Manager for the injection of the Find In Page JavaScript.
@interface JsFindinpageManager : CRWJSInjectionManager {
@private
// Model for find in page.
base::scoped_nsobject<FindInPageModel> findInPageModel_;
}
// Find In Page model. TODO(justincohen) consider using find_tab_helper.cc.
@property(nonatomic, readonly) FindInPageModel* findInPageModel;
// Sets the width and height of the window.
- (void)setWidth:(CGFloat)width height:(CGFloat)height;
// Runs injected JavaScript to find |query| string. Calls |completionHandler|
// with YES if the find operation completed, it is called with NO otherwise.
// If the find operation was successfiul the first match to scroll to is
// also called with. If the |completionHandler| is called with NO, another
// call to |pumpWithCompletionHandler:| is required. |completionHandler| cannot
// be nil.
- (void)findString:(NSString*)query
completionHandler:(void (^)(BOOL, CGPoint))completionHandler;
// Searches for more matches. Calls |completionHandler| with a success BOOL and
// scroll position if pumping was successfull. If the pumping was unsuccessfull
// another pumping call maybe required. |completionHandler| cannot be nil.
// TODO(shreyasv): Consider folding the logic for re-pumping into this class
// instead of having clients having to do it.
- (void)pumpWithCompletionHandler:(void (^)(BOOL, CGPoint))completionHandler;
// Moves to the next matched location and executes the completion handler with
// the new scroll position passed in. The |completionHandler| can be nil.
- (void)nextMatchWithCompletionHandler:(void (^)(CGPoint))completionHandler;
// Moves to the previous matched location and executes the completion handle
// with the new scroll position passed in. The |completionHandler| can be nil.
- (void)previousMatchWithCompletionHandler:(void (^)(CGPoint))completionHandler;
// Stops find in page and calls |completionHandler| once find in page is
// stopped. |completionHandler| cannot be nil.
- (void)disableWithCompletionHandler:(ProceduralBlock)completionHandler;
@end
#endif // IOS_CHROME_BROWSER_FIND_IN_PAGE_JS_FINDINPAGE_MANAGER_H_
This diff is collapsed.
This diff is collapsed.
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
'../../url/url.gyp:url_lib', '../../url/url.gyp:url_lib',
'../provider/ios_provider_chrome.gyp:ios_provider_chrome_browser', '../provider/ios_provider_chrome.gyp:ios_provider_chrome_browser',
'../web/ios_web.gyp:ios_web', '../web/ios_web.gyp:ios_web',
'injected_js',
'ios_chrome_resources.gyp:ios_theme_resources_gen', 'ios_chrome_resources.gyp:ios_theme_resources_gen',
], ],
'link_settings': { 'link_settings': {
...@@ -82,6 +83,12 @@ ...@@ -82,6 +83,12 @@
'browser/dom_distiller/dom_distiller_service_factory.h', 'browser/dom_distiller/dom_distiller_service_factory.h',
'browser/experimental_flags.h', 'browser/experimental_flags.h',
'browser/experimental_flags.mm', 'browser/experimental_flags.mm',
'browser/find_in_page/find_in_page_controller.h',
'browser/find_in_page/find_in_page_controller.mm',
'browser/find_in_page/find_in_page_model.h',
'browser/find_in_page/find_in_page_model.mm',
'browser/find_in_page/js_findinpage_manager.h',
'browser/find_in_page/js_findinpage_manager.mm',
'browser/infobars/confirm_infobar_controller.h', 'browser/infobars/confirm_infobar_controller.h',
'browser/infobars/confirm_infobar_controller.mm', 'browser/infobars/confirm_infobar_controller.mm',
'browser/infobars/infobar.h', 'browser/infobars/infobar.h',
...@@ -161,5 +168,20 @@ ...@@ -161,5 +168,20 @@
'browser/web_resource/ios_web_resource_service.h', 'browser/web_resource/ios_web_resource_service.h',
], ],
}, },
{
'target_name': 'injected_js',
'type': 'none',
'sources': [
'browser/find_in_page/resources/find_in_page.js',
],
'includes': [
'../../ios/web/js_compile.gypi',
],
'link_settings': {
'mac_bundle_resources': [
'<(SHARED_INTERMEDIATE_DIR)/find_in_page.js',
],
},
},
], ],
} }
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
'public/web_state/crw_web_delegate.h', 'public/web_state/crw_web_delegate.h',
'public/web_state/crw_web_user_interface_delegate.h' 'public/web_state/crw_web_user_interface_delegate.h'
'public/web_state/crw_web_view_proxy.h' 'public/web_state/crw_web_view_proxy.h'
'public/web_state/crw_web_view_scroll_view_proxy.h'
'public/web_state/js/crw_js_base_manager.h', 'public/web_state/js/crw_js_base_manager.h',
'public/web_state/js/crw_js_early_script_manager.h', 'public/web_state/js/crw_js_early_script_manager.h',
'public/web_state/js/crw_js_injection_evaluator.h', 'public/web_state/js/crw_js_injection_evaluator.h',
......
// 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.
@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;
// Copies all display properties that can be set on a CRWWebViewScrollViewProxy
// from the underlying UIScrollView into |scrollView|.
- (void)copyPropertiesToScrollView:(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;
@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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment