Class ContextMenu

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public final class ContextMenu extends GObject

Represents the context menu in a WebKitWebView.

WebKitContextMenu represents a context menu containing WebKitContextMenuItems in a WebKitWebView.

When a WebKitWebView is about to display the context menu, it emits the WebKitWebView::context-menu signal, which has the WebKitContextMenu as an argument. You can modify it, adding new submenus that you can create with webkit_context_menu_new(), adding new WebKitContextMenuItems with webkit_context_menu_prepend(), webkit_context_menu_append() or webkit_context_menu_insert(), maybe after having removed the existing ones with webkit_context_menu_remove_all().

  • Constructor Details

    • ContextMenu

      public ContextMenu(MemorySegment address)
      Create a ContextMenu instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • ContextMenu

      public ContextMenu()
      Create a new ContextMenu.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the ContextMenu class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected ContextMenu asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • withItems

      public static ContextMenu withItems(List<ContextMenuItem> items)

      Creates a new WebKitContextMenu object with the given items.

      Creates a new WebKitContextMenu object to be used as a submenu of an existing WebKitContextMenu with the given initial items. See also webkit_context_menu_new()

      Parameters:
      items - a GList of WebKitContextMenuItem
      Returns:
      The newly created WebKitContextMenu object
    • append

      public void append(ContextMenuItem item)
      Adds item at the end of the menu.
      Parameters:
      item - the WebKitContextMenuItem to add
    • first

      public ContextMenuItem first()
      Gets the first item in the menu.
      Returns:
      the first WebKitContextMenuItem of menu, or null if the WebKitContextMenu is empty.
    • getEvent

      public Event getEvent()

      Gets the GdkEvent that triggered the context menu. This function only returns a valid GdkEvent when called for a WebKitContextMenu passed to WebKitWebView::context-menu signal; in all other cases, null is returned.

      The returned GdkEvent is expected to be one of the following types: a GdkEventButton of type EventType.BUTTON_PRESS when the context menu was triggered with mouse. a GdkEventKey of type EventType.KEY_PRESS if the keyboard was used to show the menu. a generic GdkEvent of type GDK_NOTHING when the GtkWidget::popup-menu signal was used to show the context menu.

      Returns:
      the menu event or null.
      Since:
      2.40
    • getItemAtPosition

      public ContextMenuItem getItemAtPosition(int position)
      Gets the item at the given position in the menu.
      Parameters:
      position - the position of the item, counting from 0
      Returns:
      the WebKitContextMenuItem at position position in menu, or null if the position is off the end of the menu.
    • getItems

      public List<ContextMenuItem> getItems()
      Returns the item list of menu.
      Returns:
      a GList of WebKitContextMenuItems
    • getNItems

      public int getNItems()
      Gets the length of the menu.
      Returns:
      the number of WebKitContextMenuItems in this ContextMenu
    • getPosition

      public boolean getPosition(@Nullable Out<Integer> x, @Nullable Out<Integer> y)

      Gets the position in view coordinates where the context menu was triggered.

      This function only returns valid coordinates when called for a WebKitContextMenu passed to WebKitWebView::context-menu signal.

      Parameters:
      x - return location for the x coordinate
      y - return location for the y coordinate
      Returns:
      true if valid position coordinates are available, false otherwise
      Since:
      2.52
    • getUserData

      public Variant getUserData()

      Gets the user data of menu.

      This function can be used from the UI Process to get user data previously set from the Web Process with webkit_context_menu_set_user_data().

      Returns:
      the user data of menu, or null if this ContextMenu doesn't have user data
      Since:
      2.8
    • insert

      public void insert(ContextMenuItem item, int position)

      Inserts item into the this ContextMenu at the given position.

      If position is negative, or is larger than the number of items in the WebKitContextMenu, the item is added on to the end of the menu. The first position is 0.

      Parameters:
      item - the WebKitContextMenuItem to add
      position - the position to insert the item
    • last

      public ContextMenuItem last()
      Gets the last item in the menu.
      Returns:
      the last WebKitContextMenuItem of menu, or null if the WebKitContextMenu is empty.
    • moveItem

      public void moveItem(ContextMenuItem item, int position)

      Moves item to the given position in the menu.

      If position is negative, or is larger than the number of items in the WebKitContextMenu, the item is added on to the end of the menu. The first position is 0.

      Parameters:
      item - the WebKitContextMenuItem to add
      position - the new position to move the item
    • prepend

      public void prepend(ContextMenuItem item)
      Adds item at the beginning of the menu.
      Parameters:
      item - the WebKitContextMenuItem to add
    • remove

      public void remove(ContextMenuItem item)

      Removes item from the menu.

      See also webkit_context_menu_remove_all() to remove all items.

      Parameters:
      item - the WebKitContextMenuItem to remove
    • removeAll

      public void removeAll()
      Removes all items of the menu.
    • setUserData

      public void setUserData(Variant userData)

      Sets user data to menu.

      This function can be used from a Web Process extension to set user data that can be retrieved from the UI Process using webkit_context_menu_get_user_data(). If the userData GVariant is floating, it is consumed.

      Parameters:
      userData - a GVariant
      Since:
      2.8
    • builder

      public static ContextMenu.Builder<? extends ContextMenu.Builder> builder()
      A ContextMenu.Builder object constructs a ContextMenu with the specified properties. Use the various set...() methods to set properties, and finish construction with ContextMenu.Builder.build().
      Returns:
      the builder object