0

As the title says, I have a Cordova application which has the Cordova Crosswalk plugin installed and runs on Android and iOS.

Specifically on Android, and at least on versions Android 5.1.1 and 4.4.4 (and likely on all of them due to Crosswalk), whenever I long-press on an input field, my WebView shrinks in height and shows a weirdly-styled top bar with cut/copy/paste/clipboard buttons, and a "back" button which closes the top bar:

Android cut/copy/paste top bar

How do I prevent this long-click? I have tried adding an onLongClickListener and calling setLongClickable(false) on the WebView in my app's MainActivity.java, as follows:

public class MainActivity extends CordovaActivity {
    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);

        // disable the context menu and all long clicks
        super.getView().setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View v) {
            return true;
            }
        });
        super.appView.getView().setLongClickable(false);
        Log.i(TAG, "setLongClickable false");
    }
}

It doesn't seem to have any effect. I have also added the following CSS rules:

* {
    -webkit-text-size-adjust: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
  }

This also had no effect.

I have also tried the following Javascript, which runs before any view is rendered (using Backbone/Marionette/Handlebars) (#viewport is the first div element inside body):

  function stopEvent(e) {
    e.preventDefault();
    e.stopPropagation();
    return false;
  }

  window.oncontextmenu = function (e) {
    return stopEvent(e);
  };

  window.onselectstart = function(e) {
    return stopEvent(e);
  };
  window.ondragstart = function(e) {
    return stopEvent(e);
  };

  $('#viewport').on('taphold', function(e) {
    console.log("taphold");
    e.preventDefault();
    e.stopPropagation();

    return false;
  });

Again, no effect.

I'm almost certain it's due to the Cordova Crosswalk WebView, since after removing the plugin, the behaviour disappears: nothing happens on a long-press. Is the Crosswalk WebView perhaps ignoring the setLongClickable / setOnLongClickListener method calls? Perhaps there's another "hidden" WebView that I need to call these methods on?

How can I disable the top bar? I don't mind editing Cordova or Crosswalk Java sources. Thanks.

Edit: Perhaps this is related? https://crosswalk-project.org/jira/browse/XWALK-4786

2 Answers2

0

Looks like this is a bug in Crosswalk, and a PR which fixes it has been submitted:

https://github.com/crosswalk-project/crosswalk/pull/3193

0

in most scenarios to stop the text copy bar, you have to set the view's properties :

focusable = false
clickable = false

unless you need to click your view for some actions.

Boody
  • 144
  • 7
  • Can you elaborate on that please? What do you mean by "view's properties"? What are these properties exactly? And I do need normal touch input (but not "mouse click" input) since it's a mobile app. – Sandro Gržičić Aug 12 '15 at 10:45
  • in XML, you can set those properties for any view including the webview. – Boody Aug 12 '15 at 10:54
  • I don't think I have any XML files to set this in; I think the actual WebView is instantiated programatically. I presume the code equivalents are `setFocusable` and `setClickable`, however if I do that presumably the user won't be able to focus or touch any part of my view. Also, in any case I don't think it will take effect since I'm already doing `setLongClickable(false)` and adding my OnLongClickListener and that doesn't seem to take effect. The issue is likely that the XWalkWebView is not actually doing anything with these method calls, or maybe there's another "hidden" WebView. Thanks. – Sandro Gržičić Aug 12 '15 at 11:00