Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57d2c3ad authored by Cary Clark's avatar Cary Clark
Browse files

extract selected text from the picture

This deletes the messages between WebView and WebViewCore
that pass a region and extracts the rendered text
and returns the selected text from WebView directly.

This requires companion changes in external/webkit,
which in turn is dependent on changes to external/skia.

Fixes http://b/2166748
parent 2f389aa3
Loading
Loading
Loading
Loading
+15 −20
Original line number Diff line number Diff line
@@ -486,7 +486,7 @@ public class WebView extends AbsoluteLayout
    static final int MOVE_OUT_OF_PLUGIN                 = 19;
    static final int CLEAR_TEXT_ENTRY                   = 20;
    static final int UPDATE_TEXT_SELECTION_MSG_ID       = 21;
    static final int UPDATE_CLIPBOARD                   = 22;

    static final int LONG_PRESS_CENTER                  = 23;
    static final int PREVENT_TOUCH_ID                   = 24;
    static final int WEBCORE_NEED_TOUCH_EVENTS          = 25;
@@ -522,7 +522,7 @@ public class WebView extends AbsoluteLayout
        "MOVE_OUT_OF_PLUGIN", //             = 19;
        "CLEAR_TEXT_ENTRY", //               = 20;
        "UPDATE_TEXT_SELECTION_MSG_ID", //   = 21;
        "UPDATE_CLIPBOARD", //               = 22;
        "22", //                             = 22;
        "LONG_PRESS_CENTER", //              = 23;
        "PREVENT_TOUCH_ID", //               = 24;
        "WEBCORE_NEED_TOUCH_EVENTS", //      = 25;
@@ -3661,14 +3661,22 @@ public class WebView extends AbsoluteLayout
    private boolean commitCopy() {
        boolean copiedSomething = false;
        if (mExtendSelection) {
            // copy region so core operates on copy without touching orig.
            Region selection = new Region(nativeGetSelection());
            if (selection.isEmpty() == false) {
            String selection = nativeGetSelection();
            if (selection != "") {
                if (DebugFlags.WEB_VIEW) {
                    Log.v(LOGTAG, "commitCopy \"" + selection + "\"");
                }
                Toast.makeText(mContext
                        , com.android.internal.R.string.text_copied
                        , Toast.LENGTH_SHORT).show();
                mWebViewCore.sendMessage(EventHub.GET_SELECTION, selection);
                copiedSomething = true;
                try {
                    IClipboard clip = IClipboard.Stub.asInterface(
                            ServiceManager.getService("clipboard"));
                            clip.setClipboardText(selection);
                } catch (android.os.RemoteException e) {
                    Log.e(LOGTAG, "Clipboard failed", e);
                }
            }
            mExtendSelection = false;
        }
@@ -5655,19 +5663,6 @@ public class WebView extends AbsoluteLayout
                        mWebTextView.setAdapterCustom(adapter);
                    }
                    break;
                case UPDATE_CLIPBOARD:
                    String str = (String) msg.obj;
                    if (DebugFlags.WEB_VIEW) {
                        Log.v(LOGTAG, "UPDATE_CLIPBOARD " + str);
                    }
                    try {
                        IClipboard clip = IClipboard.Stub.asInterface(
                                ServiceManager.getService("clipboard"));
                                clip.setClipboardText(str);
                    } catch (android.os.RemoteException e) {
                        Log.e(LOGTAG, "Clipboard failed", e);
                    }
                    break;
                case RESUME_WEBCORE_UPDATE:
                    WebViewCore.resumeUpdate(mWebViewCore);
                    break;
@@ -6369,7 +6364,7 @@ public class WebView extends AbsoluteLayout
    private native boolean  nativeFocusIsPlugin();
    /* package */ native int nativeFocusNodePointer();
    private native Rect     nativeGetCursorRingBounds();
    private native Region   nativeGetSelection();
    private native String   nativeGetSelection();
    private native boolean  nativeHasCursorNode();
    private native boolean  nativeHasFocusNode();
    private native void     nativeHideCursor();
+2 −11
Original line number Diff line number Diff line
@@ -547,8 +547,6 @@ final class WebViewCore {
     */
    private native void nativeSetSelection(int start, int end);

    private native String nativeGetSelection(Region sel);

    // Register a scheme to be treated as local scheme so that it can access
    // local asset files for resources
    private native void nativeRegisterURLSchemeAsLocal(String scheme);
@@ -777,7 +775,7 @@ final class WebViewCore {
            "SET_BACKGROUND_COLOR", // = 126;
            "SET_MOVE_FOCUS", // = 127
            "SAVE_DOCUMENT_STATE", // = 128;
            "GET_SELECTION", // = 129;
            "129", // = 129;
            "WEBKIT_DRAW", // = 130;
            "SYNC_SCROLL", // = 131;
            "POST_URL", // = 132;
@@ -829,7 +827,7 @@ final class WebViewCore {
        static final int SET_BACKGROUND_COLOR = 126;
        static final int SET_MOVE_FOCUS = 127;
        static final int SAVE_DOCUMENT_STATE = 128;
        static final int GET_SELECTION = 129;

        static final int WEBKIT_DRAW = 130;
        static final int SYNC_SCROLL = 131;
        static final int POST_URL = 132;
@@ -1253,13 +1251,6 @@ final class WebViewCore {
                            nativeSetBackgroundColor(msg.arg1);
                            break;

                        case GET_SELECTION:
                            String str = nativeGetSelection((Region) msg.obj);
                            Message.obtain(mWebView.mPrivateHandler
                                    , WebView.UPDATE_CLIPBOARD, str)
                                    .sendToTarget();
                            break;

                        case DUMP_DOMTREE:
                            nativeDumpDomTree(msg.arg1 == 1);
                            break;