script: Allow opening links in a new WebView (#35017)

This changes starts tracking the keyboard modifier state in the
`Constellation` and forwards it with every input event. The state
is used to modify the target of link click so when the
platform-dependent alternate action key is enabled, the target is
overriden to "_blank".

In addition, specification step numbers and text is updated.

Signed-off-by: webbeef <me@webbeef.org>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
webbeef 2025-03-23 03:59:19 -07:00 committed by GitHub
parent 8b8b447ef0
commit 90161c1c91
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 114 additions and 25 deletions

View file

@ -36,7 +36,7 @@ use html5ever::{LocalName, Namespace, QualName, local_name, namespace_url, ns};
use hyper_serde::Serde;
use ipc_channel::ipc;
use js::rust::{HandleObject, HandleValue};
use keyboard_types::{Code, Key, KeyState};
use keyboard_types::{Code, Key, KeyState, Modifiers};
use metrics::{InteractiveFlag, InteractiveWindow, ProgressiveWebMetrics};
use mime::{self, Mime};
use net_traits::CookieSource::NonHTTP;
@ -531,6 +531,9 @@ pub(crate) struct Document {
/// The lifetime of an intersection observer is specified at
/// <https://github.com/w3c/IntersectionObserver/issues/525>.
intersection_observers: DomRefCell<Vec<Dom<IntersectionObserver>>>,
/// The active keyboard modifiers for the WebView. This is updated when receiving any input event.
#[no_trace]
active_keyboard_modifiers: Cell<Modifiers>,
}
#[allow(non_snake_case)]
@ -3868,6 +3871,7 @@ impl Document {
inherited_insecure_requests_policy: Cell::new(inherited_insecure_requests_policy),
intersection_observer_task_queued: Cell::new(false),
intersection_observers: Default::default(),
active_keyboard_modifiers: Cell::new(Modifiers::empty()),
}
}
@ -3888,6 +3892,26 @@ impl Document {
.unwrap_or(InsecureRequestsPolicy::DoNotUpgrade)
}
/// Update the active keyboard modifiers for this [`Document`] while handling events.
pub(crate) fn update_active_keyboard_modifiers(&self, modifiers: Modifiers) {
self.active_keyboard_modifiers.set(modifiers);
}
pub(crate) fn alternate_action_keyboard_modifier_active(&self) -> bool {
#[cfg(target_os = "macos")]
{
self.active_keyboard_modifiers
.get()
.contains(Modifiers::META)
}
#[cfg(not(target_os = "macos"))]
{
self.active_keyboard_modifiers
.get()
.contains(Modifiers::CONTROL)
}
}
/// Note a pending compositor event, to be processed at the next `update_the_rendering` task.
pub(crate) fn note_pending_input_event(&self, event: ConstellationInputEvent) {
let mut pending_compositor_events = self.pending_input_events.borrow_mut();