aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-03-31 08:33:14 -0400
committerGitHub <noreply@github.com>2020-03-31 08:33:14 -0400
commit234c8557ed1fbdd57115c2dab4f2587fd257ee2b (patch)
treedb8f04f468b4e7cd7412e39ab84c9ad26cbfc65c
parent5f71be281d42f33750f6255296d078721ec0c4c7 (diff)
parent0b489a0135034bca275c065647b1198846bb425c (diff)
downloadservo-234c8557ed1fbdd57115c2dab4f2587fd257ee2b.tar.gz
servo-234c8557ed1fbdd57115c2dab4f2587fd257ee2b.zip
Auto merge of #26067 - paulrouget:contextTitle, r=jdm
Make it possible to add a title to context menu Fixes #26061
-rw-r--r--.gitignore2
-rw-r--r--components/embedder_traits/lib.rs2
-rw-r--r--ports/glutin/browser.rs2
-rw-r--r--ports/libsimpleservo/api/src/lib.rs8
-rw-r--r--ports/libsimpleservo/capi/src/lib.rs17
-rw-r--r--support/hololens/ServoApp/ServoControl/Servo.cpp9
-rw-r--r--support/hololens/ServoApp/ServoControl/Servo.h3
-rw-r--r--support/hololens/ServoApp/ServoControl/ServoControl.cpp5
-rw-r--r--support/hololens/ServoApp/ServoControl/ServoControl.h3
9 files changed, 33 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
index 60d0f3dd203..25a90bcb750 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,7 +53,7 @@ support/hololens/ARM64/
support/hololens/ServoApp/x64/
support/hololens/ServoApp/ARM/
support/hololens/ServoApp/ARM64/
-support/hololens/ServoApp/Generated\ Files
+support/hololens/ServoApp/Generated Files/
support/hololens/ServoApp/BundleArtifacts/
support/hololens/ServoApp/support/
support/hololens/ServoApp/Debug/
diff --git a/components/embedder_traits/lib.rs b/components/embedder_traits/lib.rs
index 961cd5e53a4..7e76a3f2446 100644
--- a/components/embedder_traits/lib.rs
+++ b/components/embedder_traits/lib.rs
@@ -157,7 +157,7 @@ pub enum EmbedderMsg {
/// Show dialog to user
Prompt(PromptDefinition, PromptOrigin),
/// Show a context menu to the user
- ShowContextMenu(IpcSender<ContextMenuResult>, Vec<String>),
+ ShowContextMenu(IpcSender<ContextMenuResult>, Option<String>, Vec<String>),
/// Whether or not to allow a pipeline to load a url.
AllowNavigationRequest(PipelineId, ServoUrl),
/// Whether or not to allow script to open a new tab/browser
diff --git a/ports/glutin/browser.rs b/ports/glutin/browser.rs
index d92eb1bde9b..c97a1fa504a 100644
--- a/ports/glutin/browser.rs
+++ b/ports/glutin/browser.rs
@@ -521,7 +521,7 @@ where
Err(()) => error!("Error running devtools server"),
}
},
- EmbedderMsg::ShowContextMenu(sender, _) => {
+ EmbedderMsg::ShowContextMenu(sender, ..) => {
let _ = sender.send(ContextMenuResult::Ignored);
}
}
diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs
index c876ffb9fc0..0c14dbf3851 100644
--- a/ports/libsimpleservo/api/src/lib.rs
+++ b/ports/libsimpleservo/api/src/lib.rs
@@ -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) => {
diff --git a/ports/libsimpleservo/capi/src/lib.rs b/ports/libsimpleservo/capi/src/lib.rs
index d55d9f41175..323f60575df 100644
--- a/ports/libsimpleservo/capi/src/lib.rs
+++ b/ports/libsimpleservo/capi/src/lib.rs
@@ -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);
}
}
diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp
index 96438300ac4..4d82649596c 100644
--- a/support/hololens/ServoApp/ServoControl/Servo.cpp
+++ b/support/hololens/ServoApp/ServoControl/Servo.cpp
@@ -67,12 +67,17 @@ void prompt_alert(const char *message, bool trusted) {
sServo->Delegate().OnServoPromptAlert(char2hstring(message), trusted);
}
-void show_context_menu(const char *const *items_list, uint32_t items_size) {
+void show_context_menu(const char *title, const char *const *items_list,
+ uint32_t items_size) {
+ std::optional<hstring> opt_title = {};
+ if (title != nullptr) {
+ opt_title = char2hstring(title);
+ }
std::vector<winrt::hstring> items;
for (uint32_t i = 0; i < items_size; i++) {
items.push_back(char2hstring(items_list[i]));
}
- sServo->Delegate().OnServoShowContextMenu(items);
+ sServo->Delegate().OnServoShowContextMenu(opt_title, items);
}
void on_devtools_started(Servo::DevtoolsServerState result,
diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h
index 2b396f6d09d..7b3b3b00ed3 100644
--- a/support/hololens/ServoApp/ServoControl/Servo.h
+++ b/support/hololens/ServoApp/ServoControl/Servo.h
@@ -105,7 +105,8 @@ public:
virtual void OnServoMediaSessionMetadata(hstring, hstring, hstring) = 0;
virtual void OnServoMediaSessionPlaybackStateChange(int) = 0;
virtual void OnServoPromptAlert(hstring, bool) = 0;
- virtual void OnServoShowContextMenu(std::vector<hstring>) = 0;
+ virtual void OnServoShowContextMenu(std::optional<hstring>,
+ std::vector<hstring>) = 0;
virtual Servo::PromptResult OnServoPromptOkCancel(hstring, bool) = 0;
virtual Servo::PromptResult OnServoPromptYesNo(hstring, bool) = 0;
virtual std::optional<hstring> OnServoPromptInput(hstring, hstring, bool) = 0;
diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp
index 810efed02e1..4d1349ee370 100644
--- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp
+++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp
@@ -564,9 +564,10 @@ void ServoControl::OnServoDevtoolsStarted(bool success,
});
}
-void ServoControl::OnServoShowContextMenu(std::vector<winrt::hstring> items) {
+void ServoControl::OnServoShowContextMenu(std::optional<hstring> title,
+ std::vector<winrt::hstring> items) {
RunOnUIThread([=] {
- MessageDialog msg{L"Menu"};
+ MessageDialog msg{title.value_or(L"Menu")};
for (auto i = 0; i < items.size(); i++) {
UICommand cmd{items[i], [=](auto) {
RunOnGLThread([=] {
diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h
index 889c3510bfb..6eaf4459f4b 100644
--- a/support/hololens/ServoApp/ServoControl/ServoControl.h
+++ b/support/hololens/ServoApp/ServoControl/ServoControl.h
@@ -117,7 +117,8 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
winrt::hstring);
virtual void OnServoMediaSessionPlaybackStateChange(int);
virtual void OnServoPromptAlert(winrt::hstring, bool);
- virtual void OnServoShowContextMenu(std::vector<winrt::hstring>);
+ virtual void OnServoShowContextMenu(std::optional<winrt::hstring>,
+ std::vector<winrt::hstring>);
virtual servo::Servo::PromptResult OnServoPromptOkCancel(winrt::hstring,
bool);
virtual servo::Servo::PromptResult OnServoPromptYesNo(winrt::hstring, bool);