Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / findinpage / FindInPageBridge.java
1 // Copyright 2014 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 package org.chromium.chrome.browser.findinpage;
6
7 import org.chromium.content_public.browser.WebContents;
8
9 /**
10  * Allows issuing find in page related requests for a given WebContents.
11  */
12 public class FindInPageBridge {
13     private final WebContents mWebContents;
14     private long mNativeFindInPageBridge;
15
16     public FindInPageBridge(WebContents webContents) {
17         assert webContents != null;
18         mWebContents = webContents;
19         mNativeFindInPageBridge = nativeInit(webContents);
20     }
21
22     /**
23      * Destroys this instance so no further calls can be executed.
24      */
25     public void destroy() {
26         nativeDestroy(mNativeFindInPageBridge);
27         mNativeFindInPageBridge = 0;
28     }
29
30     /**
31      * Starts the find operation by calling StartFinding on the ChromeTab.
32      * This function does not block while a search is in progress.
33      * Set a listener using setFindResultListener to receive the results.
34      */
35     public void startFinding(String searchString, boolean forwardDirection, boolean caseSensitive) {
36         assert mNativeFindInPageBridge != 0;
37         nativeStartFinding(mNativeFindInPageBridge, searchString, forwardDirection, caseSensitive);
38     }
39
40     /**
41      * When the user commits to a search query or jumps from one result
42      * to the next, move accessibility focus to the next find result.
43      */
44     public void activateFindInPageResultForAccessibility() {
45         assert mNativeFindInPageBridge != 0;
46         nativeActivateFindInPageResultForAccessibility(mNativeFindInPageBridge);
47     }
48
49     /** Stops the current find operation. */
50     public void stopFinding() {
51         assert mNativeFindInPageBridge != 0;
52         nativeStopFinding(mNativeFindInPageBridge);
53     }
54
55     /** Returns the most recent find text before the current one. */
56     public String getPreviousFindText() {
57         assert mNativeFindInPageBridge != 0;
58         return nativeGetPreviousFindText(mNativeFindInPageBridge);
59     }
60
61     /** Asks the renderer to send the bounding boxes of current find matches. */
62     public void requestFindMatchRects(int currentVersion) {
63         assert mNativeFindInPageBridge != 0;
64         nativeRequestFindMatchRects(mNativeFindInPageBridge, currentVersion);
65     }
66
67     /**
68      * Selects and zooms to the nearest find result to the point (x,y),
69      * where x and y are fractions of the content document's width and height.
70      */
71     public void activateNearestFindResult(float x, float y) {
72         assert mNativeFindInPageBridge != 0;
73         nativeActivateNearestFindResult(mNativeFindInPageBridge, x, y);
74     }
75
76     private native long nativeInit(WebContents webContents);
77
78     private native void nativeDestroy(long nativeFindInPageBridge);
79
80     private native void nativeStartFinding(long nativeFindInPageBridge, String searchString,
81             boolean forwardDirection, boolean caseSensitive);
82
83     private native void nativeStopFinding(long nativeFindInPageBridge);
84
85     private native String nativeGetPreviousFindText(long nativeFindInPageBridge);
86
87     private native void nativeRequestFindMatchRects(
88             long nativeFindInPageBridge, int currentVersion);
89
90     private native void nativeActivateNearestFindResult(
91             long nativeFindInPageBridge, float x, float y);
92
93     private native void nativeActivateFindInPageResultForAccessibility(
94             long nativeFindInPageBridge);
95 }