Skip to content

Commit

Permalink
adding cfg target linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Tsai committed Nov 14, 2024
1 parent 0c63a6d commit d7d97e3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ Cargo.lock
.flatpak-builder/
libmozjs*
cargo-sources.json

resources/
!resources/panel.html
!resources/context-menu.html
9 changes: 6 additions & 3 deletions src/context_menu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use base::id::WebViewId;
use euclid::{Point2D, Size2D};

/* macOS, Windows Native Implementation */
#[cfg(any(target_os = "macos", target_os = "windows"))]
use muda::{ContextMenu as MudaContextMenu, Menu};
Expand All @@ -11,10 +8,14 @@ use raw_window_handle::{HasWindowHandle, RawWindowHandle};
#[cfg(linux)]
use crate::{verso::send_to_constellation, webview::WebView, window::Window};
#[cfg(linux)]
use base::id::WebViewId;
#[cfg(linux)]
use compositing_traits::ConstellationMsg;
#[cfg(linux)]
use crossbeam_channel::Sender;
#[cfg(linux)]
use euclid::{Point2D, Size2D};
#[cfg(linux)]
use serde::{Deserialize, Serialize};
#[cfg(linux)]
use servo_url::ServoUrl;
Expand Down Expand Up @@ -141,6 +142,7 @@ impl ContextMenu {
}

/// Menu Item
#[cfg(linux)]
#[derive(Debug, Clone, Serialize)]
pub struct MenuItem {
id: String,
Expand All @@ -150,6 +152,7 @@ pub struct MenuItem {
pub enabled: bool,
}

#[cfg(linux)]
impl MenuItem {
/// Create a new menu item
pub fn new(id: Option<&str>, label: &str, enabled: bool) -> Self {
Expand Down
9 changes: 5 additions & 4 deletions src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use servo_url::ServoUrl;
use url::Url;
use webrender_api::units::DeviceIntRect;

use crate::{
compositor::IOCompositor, context_menu::ContextMenuClickResult, verso::send_to_constellation,
window::Window,
};
use crate::{compositor::IOCompositor, verso::send_to_constellation, window::Window};

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

/// 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 @@ -295,6 +295,7 @@ impl Window {
}

/// Handle servo messages with main panel. Return true it requests a new window.
#[cfg(linux)]
pub fn handle_servo_messages_with_context_menu(
&mut self,
webview_id: WebViewId,
Expand Down
7 changes: 5 additions & 2 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use glutin_winit::DisplayBuilder;
use muda::{Menu, MenuEvent, MenuEventReceiver, MenuItem};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use raw_window_handle::HasWindowHandle;
// #[cfg(any(target_os = "macos", target_os = "windows"))]
use script_traits::TraversalDirection;
use script_traits::{TouchEventType, WheelDelta, WheelMode};
use servo_url::ServoUrl;
Expand Down Expand Up @@ -67,7 +66,8 @@ pub struct Window {
/// dialog webviews
dialog_webviews: Vec<WebView>,

/// context_menu
/// Linux context_menu
#[cfg(linux)]
pub(crate) context_menu: Option<ContextMenu>,

/// Global menu evnet receiver for muda crate
Expand Down Expand Up @@ -124,6 +124,7 @@ impl Window {
current_history_index: 0,
resizing: false,
dialog_webviews: vec![],
#[cfg(linux)]
context_menu: None,
#[cfg(any(target_os = "macos", target_os = "windows"))]
menu_event_receiver: MenuEvent::receiver().clone(),
Expand Down Expand Up @@ -167,6 +168,7 @@ impl Window {
current_history_index: 0,
resizing: false,
dialog_webviews: vec![],
#[cfg(linux)]
context_menu: None,
#[cfg(any(target_os = "macos", target_os = "windows"))]
menu_event_receiver: MenuEvent::receiver().clone(),
Expand Down Expand Up @@ -463,6 +465,7 @@ impl Window {
);
}
}
#[cfg(linux)]
if let Some(context_menu) = &self.context_menu {
if context_menu.webview().webview_id == webview_id {
self.handle_servo_messages_with_context_menu(
Expand Down

0 comments on commit d7d97e3

Please sign in to comment.