web_extensions_sys/
context_menus.rs

1use js_sys::{Function, Object};
2use wasm_bindgen::JsValue;
3use wasm_bindgen::prelude::wasm_bindgen;
4use crate::EventTarget;
5
6// https://developer.chrome.com/docs/extensions/reference/api/contextMenus
7#[wasm_bindgen]
8extern "C" {
9    pub type ContextMenus;
10
11    #[wasm_bindgen(method)]
12    pub fn create(
13        this: &ContextMenus,
14        create_properties: &Object,
15        callback: Option<&Function>,
16    ) -> JsValue;
17
18    #[wasm_bindgen(method)]
19    pub fn remove(
20        this: &ContextMenus,
21        menu_item_id: &JsValue,
22        callback: Option<&Function>
23    );
24
25    #[wasm_bindgen(method, js_name=removeAll)]
26    pub fn remove_all(
27        this: &ContextMenus,
28        callback: Option<&Function>
29    );
30
31    #[wasm_bindgen(method)]
32    pub fn update(
33        this: &ContextMenus,
34        id: &JsValue,
35        update_properties: &Object,
36        callback: Option<&Function>
37    );
38
39    #[wasm_bindgen(method, getter, js_name = onClicked)]
40    pub fn on_clicked(this: &ContextMenus) -> EventTarget;
41}
42
43#[wasm_bindgen]
44extern "C" {
45    // https://developer.chrome.com/docs/extensions/reference/api/contextMenus#type-OnClickData
46    #[derive(Debug)]
47    pub type OnClickData;
48
49    // A flag indicating the state of a checkbox or radio item after it is clicked.
50    #[wasm_bindgen(method, getter)]
51    pub fn checked(this: &OnClickData) -> Option<bool>;
52
53    // A flag indicating whether the element is editable (text input, textarea, etc.).
54    #[wasm_bindgen(method, getter)]
55    pub fn editable(this: &OnClickData) -> bool;
56
57    // The ID of the frame of the element where the context menu was clicked, if it was in a frame.
58    #[wasm_bindgen(method, getter, js_name = frameId)]
59    pub fn frame_id(this: &OnClickData) -> Option<u32>;
60
61    // The URL of the frame of the element where the context menu was clicked, if it was in a frame.
62    #[wasm_bindgen(method, getter, js_name = frameUrl)]
63    pub fn frame_url(this: &OnClickData) -> Option<String>;
64
65    // If the element is a link, the URL it points to.
66    #[wasm_bindgen(method, getter, js_name = linkUrl)]
67    pub fn link_url(this: &OnClickData) -> Option<String>;
68
69    // One of 'image', 'video', or 'audio' if the context menu was activated on one of these types of elements.
70    #[wasm_bindgen(method, getter, js_name = mediaType)]
71    pub fn media_type(this: &OnClickData) -> Option<String>;
72
73    // The ID of the menu item that was clicked.
74    #[wasm_bindgen(method, getter, js_name = menuItemId)]
75    pub fn menu_item_id(this: &OnClickData) -> Option<String>;
76
77    // The URL of the page where the menu item was clicked. This property is not set if the click occured in a context where there is no current page, such as in a launcher context menu.
78    #[wasm_bindgen(method, getter, js_name = pageUrl)]
79    pub fn page_url(this: &OnClickData) -> Option<String>;
80
81    // The parent ID, if any, for the item clicked.
82    #[wasm_bindgen(method, getter, js_name = parentMenuItemId)]
83    pub fn parent_menu_item_id(this: &OnClickData) -> Option<String>;
84
85    // The text for the context selection, if any.
86    #[wasm_bindgen(method, getter, js_name = selectionText)]
87    pub fn selection_text(this: &OnClickData) -> Option<String>;
88
89    // Will be present for elements with a 'src' URL.
90    #[wasm_bindgen(method, getter, js_name = srcUrl)]
91    pub fn src_url(this: &OnClickData) -> Option<String>;
92
93    // A flag indicating the state of a checkbox or radio item before it was clicked.
94    #[wasm_bindgen(method, getter, js_name = wasChecked)]
95    pub fn was_checked(this: &OnClickData) -> Option<bool>;
96}