script: Add context-based context menu options (#40501)

Add context menu options for images, links, and editable text areas. In
addition add the ability to show menu options that are disabled. This
also improves the visual style of the context menu in egui as part of
supporting disabled options.

Testing: This has been manually tested, but we could we should be able
to
easily add unit tests when enriching the API with information about the
active element under context menus.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
This commit is contained in:
Martin Robinson
2025-11-11 12:03:41 +01:00
committed by GitHub
parent 9207c7d6b4
commit 1e4feeaa0d
10 changed files with 567 additions and 190 deletions

View File

@@ -24,7 +24,7 @@ use crate::dom::bindings::error::ErrorResult;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::clipboardevent::ClipboardEvent;
use crate::dom::clipboardevent::{ClipboardEvent, ClipboardEventType};
use crate::dom::compositionevent::CompositionEvent;
use crate::dom::document::Document;
use crate::dom::document_embedder_controls::ControlElement;
@@ -234,12 +234,21 @@ impl TextControlElement for HTMLTextAreaElement {
}
fn has_selectable_text(&self) -> bool {
true
!self.textinput.borrow().get_content().is_empty()
}
fn has_selection(&self) -> bool {
self.textinput.borrow().has_selection()
}
fn set_dirty_value_flag(&self, value: bool) {
self.value_dirty.set(value)
}
fn select_all(&self) {
self.textinput.borrow_mut().select_all();
self.upcast::<Node>().dirty(NodeDamage::Other);
}
}
impl HTMLTextAreaElementMethods<crate::DomTypeHolder> for HTMLTextAreaElement {
@@ -723,11 +732,14 @@ impl VirtualMethods for HTMLTextAreaElement {
.textinput
.borrow_mut()
.handle_clipboard_event(clipboard_event);
let flags = reaction.flags;
if flags.contains(ClipboardEventFlags::FireClipboardChangedEvent) {
self.owner_document()
.event_handler()
.fire_clipboardchange_event(can_gc);
self.owner_document().event_handler().fire_clipboard_event(
None,
ClipboardEventType::Change,
can_gc,
);
}
if flags.contains(ClipboardEventFlags::QueueInputEvent) {
self.textinput.borrow().queue_input_event(