mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Make it possible to add a title to context menu
This commit is contained in:
parent
687156ac90
commit
0b489a0135
9 changed files with 33 additions and 18 deletions
|
@ -521,7 +521,7 @@ where
|
|||
Err(()) => error!("Error running devtools server"),
|
||||
}
|
||||
},
|
||||
EmbedderMsg::ShowContextMenu(sender, _) => {
|
||||
EmbedderMsg::ShowContextMenu(sender, ..) => {
|
||||
let _ = sender.send(ContextMenuResult::Ignored);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ pub trait HostTrait {
|
|||
/// Ask for string
|
||||
fn prompt_input(&self, msg: String, default: String, trusted: bool) -> Option<String>;
|
||||
/// Show context menu
|
||||
fn show_context_menu(&self, items: Vec<String>);
|
||||
fn show_context_menu(&self, title: Option<String>, items: Vec<String>);
|
||||
/// Page starts loading.
|
||||
/// "Reload button" should be disabled.
|
||||
/// "Stop button" should be enabled.
|
||||
|
@ -579,7 +579,7 @@ impl ServoGlue {
|
|||
EmbedderMsg::AllowUnload(sender) => {
|
||||
let _ = sender.send(true);
|
||||
},
|
||||
EmbedderMsg::ShowContextMenu(sender, items) => {
|
||||
EmbedderMsg::ShowContextMenu(sender, title, items) => {
|
||||
if self.context_menu_sender.is_some() {
|
||||
warn!(
|
||||
"Trying to show a context menu when a context menu is already active"
|
||||
|
@ -587,7 +587,9 @@ impl ServoGlue {
|
|||
let _ = sender.send(ContextMenuResult::Ignored);
|
||||
} else {
|
||||
self.context_menu_sender = Some(sender);
|
||||
self.callbacks.host_callbacks.show_context_menu(items);
|
||||
self.callbacks
|
||||
.host_callbacks
|
||||
.show_context_menu(title, items);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::Prompt(definition, origin) => {
|
||||
|
|
|
@ -230,7 +230,8 @@ pub struct CHostCallbacks {
|
|||
trusted: bool,
|
||||
) -> *const c_char,
|
||||
pub on_devtools_started: extern "C" fn(result: CDevtoolsServerState, port: c_uint),
|
||||
pub show_context_menu: extern "C" fn(items_list: *const *const c_char, items_size: u32),
|
||||
pub show_context_menu:
|
||||
extern "C" fn(title: *const c_char, items_list: *const *const c_char, items_size: u32),
|
||||
}
|
||||
|
||||
/// Servo options
|
||||
|
@ -903,15 +904,19 @@ impl HostTrait for HostCallbacks {
|
|||
}
|
||||
}
|
||||
|
||||
fn show_context_menu(&self, items: Vec<String>) {
|
||||
fn show_context_menu(&self, title: Option<String>, items: Vec<String>) {
|
||||
debug!("show_context_menu");
|
||||
let size = items.len() as u32;
|
||||
let items_size = items.len() as u32;
|
||||
let cstrs: Vec<CString> = items
|
||||
.into_iter()
|
||||
.map(|i| CString::new(i).expect("Can't create string"))
|
||||
.collect();
|
||||
let ptrs: Vec<*const c_char> = cstrs.iter().map(|cstr| cstr.as_ptr()).collect();
|
||||
(self.0.show_context_menu)(ptrs.as_ptr(), size);
|
||||
// let _ = cstrs; // Don't drop these too early
|
||||
let items: Vec<*const c_char> = cstrs.iter().map(|cstr| cstr.as_ptr()).collect();
|
||||
let title = title.map(|s| CString::new(s).expect("Can't create string"));
|
||||
let title_ptr = title
|
||||
.as_ref()
|
||||
.map(|cstr| cstr.as_ptr())
|
||||
.unwrap_or(std::ptr::null());
|
||||
(self.0.show_context_menu)(title_ptr, items.as_ptr(), items_size);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue