mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Context Menu: UWP
This commit is contained in:
parent
ed46f5985c
commit
ed601bcbad
4 changed files with 46 additions and 7 deletions
|
@ -43,7 +43,7 @@ void on_ime_state_changed(bool aShow) {
|
|||
sServo->Delegate().OnServoIMEStateChanged(aShow);
|
||||
}
|
||||
|
||||
void set_clipboard_contents(const char *content) {
|
||||
void set_clipboard_contents(const char *) {
|
||||
// FIXME
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,14 @@ 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
void on_devtools_started(Servo::DevtoolsServerState result,
|
||||
const unsigned int port) {
|
||||
sServo->Delegate().OnServoDevtoolsStarted(
|
||||
|
@ -154,6 +162,7 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
|
|||
c.prompt_yes_no = &prompt_yes_no;
|
||||
c.prompt_input = &prompt_input;
|
||||
c.on_devtools_started = &on_devtools_started;
|
||||
c.show_context_menu = &show_context_menu;
|
||||
|
||||
capi::register_panic_handler(&on_panic);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
typedef capi::CMouseButton MouseButton;
|
||||
typedef capi::CPromptResult PromptResult;
|
||||
typedef capi::CContextMenuResult ContextMenuResult;
|
||||
typedef capi::CMediaSessionActionType MediaSessionActionType;
|
||||
typedef capi::CMediaSessionPlaybackState MediaSessionPlaybackState;
|
||||
typedef capi::CDevtoolsServerState DevtoolsServerState;
|
||||
|
@ -74,6 +75,9 @@ public:
|
|||
void SendMediaSessionAction(capi::CMediaSessionActionType action) {
|
||||
capi::media_session_action(action);
|
||||
}
|
||||
void ContextMenuClosed(capi::CContextMenuResult res, unsigned int idx) {
|
||||
capi::on_context_menu_closed(res, idx);
|
||||
}
|
||||
|
||||
private:
|
||||
ServoDelegate &mDelegate;
|
||||
|
@ -95,12 +99,13 @@ public:
|
|||
virtual bool OnServoAllowNavigation(hstring) = 0;
|
||||
virtual void OnServoAnimatingChanged(bool) = 0;
|
||||
virtual void OnServoIMEStateChanged(bool) = 0;
|
||||
virtual void OnServoDevtoolsStarted(bool, unsigned int) = 0;
|
||||
virtual void OnServoDevtoolsStarted(bool, const unsigned int) = 0;
|
||||
virtual void Flush() = 0;
|
||||
virtual void MakeCurrent() = 0;
|
||||
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 Servo::PromptResult OnServoPromptOkCancel(hstring, bool) = 0;
|
||||
virtual Servo::PromptResult OnServoPromptYesNo(hstring, bool) = 0;
|
||||
virtual std::optional<hstring> OnServoPromptInput(hstring, hstring, bool) = 0;
|
||||
|
|
|
@ -235,9 +235,9 @@ void ServoControl::OnSurfaceWheelChanged(
|
|||
void ServoControl::OnSurfaceResized(IInspectable const &,
|
||||
SizeChangedEventArgs const &e) {
|
||||
auto size = e.NewSize();
|
||||
auto w = size.Width * mDPI;
|
||||
auto h = size.Height * mDPI;
|
||||
RunOnGLThread([=] { mServo->SetSize(w, h); });
|
||||
auto w = (size.Width * mDPI);
|
||||
auto h = (size.Height * mDPI);
|
||||
RunOnGLThread([=] { mServo->SetSize((GLsizei)w, (GLsizei)h); });
|
||||
}
|
||||
|
||||
void ServoControl::GoBack() {
|
||||
|
@ -437,7 +437,7 @@ void ServoControl::OnServoAnimatingChanged(bool animating) {
|
|||
WakeConditionVariable(&mGLCondVar);
|
||||
}
|
||||
|
||||
void ServoControl::OnServoIMEStateChanged(bool aShow) {
|
||||
void ServoControl::OnServoIMEStateChanged(bool) {
|
||||
// FIXME:
|
||||
// https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-implementingtextandtextrange
|
||||
}
|
||||
|
@ -574,6 +574,30 @@ void ServoControl::OnServoDevtoolsStarted(bool success,
|
|||
ToastNotificationManager::CreateToastNotifier().Show(toast);
|
||||
}
|
||||
|
||||
void ServoControl::OnServoShowContextMenu(std::vector<winrt::hstring> items) {
|
||||
RunOnUIThread([=] {
|
||||
MessageDialog msg{L"Menu"};
|
||||
for (auto i = 0; i < items.size(); i++) {
|
||||
UICommand cmd{items[i], [=](auto) {
|
||||
RunOnGLThread([=] {
|
||||
mServo->ContextMenuClosed(
|
||||
Servo::ContextMenuResult::Selected, i);
|
||||
});
|
||||
}};
|
||||
msg.Commands().Append(cmd);
|
||||
}
|
||||
UICommand cancel{L"Cancel", [=](auto) {
|
||||
RunOnGLThread([=] {
|
||||
mServo->ContextMenuClosed(
|
||||
Servo::ContextMenuResult::Dismissed_, 0);
|
||||
});
|
||||
}};
|
||||
msg.Commands().Append(cancel);
|
||||
msg.CancelCommandIndex((uint32_t)items.size());
|
||||
msg.ShowAsync();
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Callable> void ServoControl::RunOnUIThread(Callable cb) {
|
||||
Dispatcher().RunAsync(CoreDispatcherPriority::High, cb);
|
||||
}
|
||||
|
|
|
@ -109,12 +109,13 @@ 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 servo::Servo::PromptResult OnServoPromptOkCancel(winrt::hstring,
|
||||
bool);
|
||||
virtual servo::Servo::PromptResult OnServoPromptYesNo(winrt::hstring, bool);
|
||||
virtual std::optional<hstring> OnServoPromptInput(winrt::hstring,
|
||||
winrt::hstring, bool);
|
||||
virtual void OnServoDevtoolsStarted(bool success, const unsigned int port);
|
||||
virtual void OnServoDevtoolsStarted(bool, const unsigned int);
|
||||
|
||||
private:
|
||||
winrt::event<Windows::Foundation::EventHandler<hstring>> mOnURLChangedEvent;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue