Skip to content

Commit

Permalink
Merge branch 'main' into init-script
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master authored Nov 22, 2024
2 parents 15d0643 + 448eb2f commit ad8c488
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 183 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ headers = "0.3"
versoview_messages = { path = "./versoview_messages" }

[target.'cfg(all(unix, not(apple), not(android)))'.dependencies]
serde_json = "1.0.132"
serde_json = "1.0"
serde = { workspace = true }

[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
Expand Down
21 changes: 1 addition & 20 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,7 @@ impl IOCompositor {
}
}

/// TODO: doc
pub fn hit_test_at_point(&self, point: DevicePoint) -> Option<CompositorHitTestResult> {
fn hit_test_at_point(&self, point: DevicePoint) -> Option<CompositorHitTestResult> {
return self
.hit_test_at_point_with_flags_and_pipeline(point, HitTestFlags::empty(), None)
.first()
Expand Down Expand Up @@ -2163,24 +2162,6 @@ impl IOCompositor {
self.webrender_api
.send_transaction(self.webrender_document, transaction);
}

/// Get webview id on the position
pub fn webview_id_on_position(
&self,
position: DevicePoint,
) -> Option<TopLevelBrowsingContextId> {
let hit_result: Option<CompositorHitTestResult> = self.hit_test_at_point(position);
if let Some(result) = hit_result {
let pipeline_id = result.pipeline_id;
for (w_id, p_id) in &self.webviews {
if *p_id == pipeline_id {
return Some(*w_id);
}
}
}

None
}
}

#[derive(Debug, PartialEq)]
Expand Down
41 changes: 22 additions & 19 deletions src/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,38 @@ use webrender_api::units::DeviceIntRect;
#[cfg(linux)]
use winit::dpi::PhysicalPosition;

/// Context Menu inner menu
/// Basic menu type building block
#[cfg(any(target_os = "macos", target_os = "windows"))]
pub struct Menu(pub MudaMenu);
/// Context Menu inner menu
/// Basic menu type building block
#[cfg(linux)]
#[derive(Debug, Clone)]
pub struct Menu(pub Vec<MenuItem>);

/// The Context Menu of the Window. It will be opened when users right click on any window's
/// webview.
///
/// **Platform Specific**
/// - macOS / Windows: This will be native context menu supported by each OS.
/// - Wayland: Winit doesn't support popup surface of Wayland at the moment. So we utilize a custom
/// webview implementation.
#[derive(Clone)]
pub struct ContextMenu {
#[cfg(any(target_os = "macos", target_os = "windows"))]
menu: MudaMenu,
#[cfg(linux)]
menu_items: Vec<MenuItem>,
/// The webview that the context menu is attached to
#[cfg(linux)]
webview: WebView,
}

impl ContextMenu {
/// Create context menu with custom items
///
/// **Platform Specific**
/// - macOS / Windows: Creates a context menu by muda crate with natvie OS support
/// - Linux: Creates a context menu with webview implementation
/// - Wayland: Creates a context menu with webview implementation
pub fn new_with_menu(menu: Menu) -> Self {
#[cfg(any(target_os = "macos", target_os = "windows"))]
{
Expand All @@ -56,12 +74,6 @@ impl ContextMenu {
}
}

/// Context Menu
#[cfg(any(target_os = "macos", target_os = "windows"))]
pub struct ContextMenu {
menu: MudaMenu,
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
impl ContextMenu {
/// Show the context menu on current cursor position
Expand Down Expand Up @@ -93,15 +105,6 @@ impl ContextMenu {
}
}

/// Context Menu
#[cfg(linux)]
#[derive(Debug, Clone)]
pub struct ContextMenu {
menu_items: Vec<MenuItem>,
/// The webview that the context menu is attached to
webview: WebView,
}

#[cfg(linux)]
impl ContextMenu {
/// Show the context menu to current cursor position
Expand Down Expand Up @@ -218,7 +221,7 @@ impl MenuItem {
/// Context Menu Click Result
#[cfg(linux)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextMenuClickResult {
pub struct ContextMenuResult {
/// The id of the menu ite /// Get the label of the menu item
pub id: String,
/// Close the context menu
Expand Down
10 changes: 6 additions & 4 deletions src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use webrender_api::units::DeviceIntRect;
use crate::{compositor::IOCompositor, verso::send_to_constellation, window::Window};

#[cfg(linux)]
use crate::context_menu::ContextMenuClickResult;
use crate::context_menu::ContextMenuResult;

/// A web view is an area to display web browsing context. It's what user will treat as a "web page".
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -77,6 +77,7 @@ impl Window {
log::trace!("Verso WebView {webview_id:?} ignores this message: {message:?}")
}
EmbedderMsg::WebViewFocused(w) => {
self.close_context_menu(sender);
log::debug!(
"Verso Window {:?}'s webview {} has loaded completely.",
self.id(),
Expand Down Expand Up @@ -176,6 +177,7 @@ impl Window {
log::trace!("Verso Panel ignores this message: {message:?}")
}
EmbedderMsg::WebViewFocused(w) => {
self.close_context_menu(sender);
log::debug!(
"Verso Window {:?}'s panel {} has loaded completely.",
self.id(),
Expand Down Expand Up @@ -318,15 +320,15 @@ impl Window {
if msg.starts_with("CONTEXT_MENU:") {
let json_str_msg = msg.strip_prefix("CONTEXT_MENU:").unwrap();
let result =
serde_json::from_str::<ContextMenuClickResult>(json_str_msg).unwrap();
serde_json::from_str::<ContextMenuResult>(json_str_msg).unwrap();

self.handle_context_menu_event(sender, result);
}
}
_ => log::trace!("Verso Panel isn't supporting this prompt yet"),
_ => log::trace!("Verso context menu isn't supporting this prompt yet"),
},
e => {
log::trace!("Verso Panel isn't supporting this message yet: {e:?}")
log::trace!("Verso context menu isn't supporting this message yet: {e:?}")
}
}
false
Expand Down
Loading

0 comments on commit ad8c488

Please sign in to comment.