Auto merge of #26043 - paulrouget:IMMenu, r=jdm

Context menu API

This adds an API for Servo internals to request a context menu to the embedder, along an implement for the UWP port.
This commit is contained in:
bors-servo 2020-03-30 03:08:08 -04:00 committed by GitHub
commit c3ecf2ecef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 132 additions and 10 deletions

View file

@ -233,9 +233,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() {
@ -435,7 +435,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
}
@ -564,6 +564,30 @@ void ServoControl::OnServoDevtoolsStarted(bool success,
});
}
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);
}