mozilla
Your Search Results

    SelectionHandler

    The SelectionHandler object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

    The SelectionHandler object enables Firefox for Android add-ons to add things to the text selection ActionMode. These items will also be shown when just the Android cursor is shown (i.e. text is not necessarily selected). Use SelectionHandler.isSelectionActive(); in your selector you should ensure that your action only shows when appropriate.

    SelectionHandler is available as a property of the chrome window object. For example, if you use this template for initializing your extension, you can access it from the window argument passed into loadIntoWindow():

    function loadIntoWindow(window) {
      if (!window)
        return;
    
      window.SelectionHandler.addAction({
        label: "My action",
        icon: "chrome://myaddon/action.png",
        action: function() { alert("Foo"); },
        selector: {
          matches: function() { return true; }
        }
      });
    }
    

    addAction

    Add items to the text selection menu in Firefox for Android.

    SelectionHandler.addAction({
        label: "My action",
        icon: "chrome://myaddon/action.png",
        action: function() { alert("Foo"); },
        selector: {
            matches: function() { return true; }
        },
        showAsAction: true,
    });
    
    
    Parameters

    Options

    id
    An optional id for the item. If you don't pass one of these in, a guid will be generated and given to you.
    label
    An optional name for this item to be displayed as a hint when the action bar item is long-pressed.
    icon
    An optional icon for the item. If you don't specify an icon, the item will always show in the overflow menu.
    order
    An optional integer for determining order of the item in the action bar. Higher order values are listed first. If no order is specified, the item will be assigned an order of 0.
    action
    A function that will be called when the item is clicked. The currently focused element will be passed to it.
    selector
    An object with a matches function that's called whenever text selection action modes are shown/updated. This may be called if the android cursor is going to be shown as well (i.e. don't assume that something is selected!). Defaults to true.
    showAsAction
    Either a boolean or a function that returns true or false if the item CAN be shown as an action icon. Even if you request to be shown as an action, it may not be if the bar is already full. Defaults to true.
    Returns

    Returns this id of the added item. If you passed in an id, it will be returned. Otherwise, you'll get an autogenerated guid

    removeAction

    Remove items from the text selection menu in Firefox for Android.

    SelectionHandler.addAction(id);
    
    Options
    id
    The id of the item to remove

    isSelectionActive

    SelectionHandler.isSelectionActive();
    Returns

    Return true if something is selected.

    Document Tags and Contributors

    Contributors to this page: wesj, Liuche
    Last updated by: Liuche,