mirror of
https://github.com/servo/servo.git
synced 2025-08-14 18:05:36 +01:00
Auto merge of #26840 - paulrouget:l10n, r=Manishearth
UWP L10N Partially addresses #26665. This does not cover Rust strings and resources files.
This commit is contained in:
commit
10202c2ad2
16 changed files with 460 additions and 118 deletions
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "pch.h"
|
||||
#include "logs.h"
|
||||
#include "strutils.h"
|
||||
#include "OpenGLES.h"
|
||||
|
||||
using namespace winrt::Windows::UI::Xaml::Controls;
|
||||
|
@ -13,7 +13,7 @@ using namespace winrt::Windows::Foundation::Collections;
|
|||
OpenGLES::OpenGLES()
|
||||
: mEglConfig(nullptr), mEglDisplay(EGL_NO_DISPLAY),
|
||||
mEglContext(EGL_NO_CONTEXT) {
|
||||
log("OpenGLES::OpenGLES()");
|
||||
log(L"OpenGLES::OpenGLES()");
|
||||
Initialize();
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
|
|||
} else if (type == Windows::Foundation::PropertyType::Empty) {
|
||||
pref.pref_type = capi::CPrefType::Missing;
|
||||
} else {
|
||||
log("skipping pref %s. Unknown type", key);
|
||||
log(L"skipping pref %s. Unknown type", key);
|
||||
continue;
|
||||
}
|
||||
cprefs.push_back(pref);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "pch.h"
|
||||
#include <EGL/egl.h>
|
||||
#include "logs.h"
|
||||
#include "strutils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace winrt::servo {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#include "pch.h"
|
||||
#include "strutils.h"
|
||||
#include "ServoControl.h"
|
||||
#include "ServoControl.g.cpp"
|
||||
#include "Pref.g.cpp"
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std::placeholders;
|
||||
using namespace winrt::Windows::ApplicationModel::Resources;
|
||||
using namespace winrt::Windows::Graphics::Display;
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace winrt::Windows::UI::Popups;
|
||||
|
@ -21,6 +23,16 @@ ServoControl::ServoControl() {
|
|||
mDPI = (float)DisplayInformation::GetForCurrentView().ResolutionScale() / 100;
|
||||
DefaultStyleKey(winrt::box_value(L"ServoApp.ServoControl"));
|
||||
Loaded(std::bind(&ServoControl::OnLoaded, this, _1, _2));
|
||||
|
||||
auto r = ResourceLoader::GetForCurrentView();
|
||||
L10NStrings l10NStrings = {r.GetString(L"ContextMenu/title"),
|
||||
r.GetString(L"JavascriptPrompt/title"),
|
||||
r.GetString(L"JavascriptPrompt/ok"),
|
||||
r.GetString(L"JavascriptPrompt/cancel"),
|
||||
r.GetString(L"JavascriptPrompt/yes"),
|
||||
r.GetString(L"JavascriptPrompt/no"),
|
||||
r.GetString(L"URINotValid/Alert")};
|
||||
mL10NStrings = std::make_unique<L10NStrings>(l10NStrings);
|
||||
}
|
||||
|
||||
void ServoControl::Shutdown() {
|
||||
|
@ -82,8 +94,8 @@ Controls::SwapChainPanel ServoControl::Panel() {
|
|||
}
|
||||
|
||||
void ServoControl::CreateNativeWindow() {
|
||||
mPanelWidth = Panel().ActualWidth() * mDPI;
|
||||
mPanelHeight = Panel().ActualHeight() * mDPI;
|
||||
mPanelWidth = (int)(Panel().ActualWidth() * mDPI);
|
||||
mPanelHeight = (int)(Panel().ActualHeight() * mDPI);
|
||||
mNativeWindowProperties.Insert(EGLNativeWindowTypeProperty, Panel());
|
||||
// How to set size and or scale:
|
||||
// Insert(EGLRenderSurfaceSizeProperty),
|
||||
|
@ -280,13 +292,8 @@ hstring ServoControl::LoadURIOrSearch(hstring input) {
|
|||
std::wstring searchUri =
|
||||
unbox_value<hstring>(std::get<1>(Servo::GetPref(L"shell.searchpage")))
|
||||
.c_str();
|
||||
std::wstring keyword = L"%s";
|
||||
size_t start_pos = searchUri.find(keyword);
|
||||
if (start_pos == std::string::npos)
|
||||
searchUri = searchUri + escapedInput;
|
||||
else
|
||||
searchUri.replace(start_pos, keyword.length(), escapedInput);
|
||||
hstring finalUri{searchUri};
|
||||
std::wstring formatted = format(searchUri, escapedInput.c_str());
|
||||
hstring finalUri{formatted};
|
||||
TryLoadUri(finalUri);
|
||||
return finalUri;
|
||||
}
|
||||
|
@ -305,7 +312,7 @@ void ServoControl::TryLoadUri(hstring input) {
|
|||
RunOnGLThread([=] {
|
||||
if (!mServo->LoadUri(input)) {
|
||||
RunOnUIThread([=] {
|
||||
MessageDialog msg{L"URI not valid"};
|
||||
MessageDialog msg{mL10NStrings->URINotValid};
|
||||
msg.ShowAsync();
|
||||
});
|
||||
}
|
||||
|
@ -323,10 +330,10 @@ void ServoControl::RunOnGLThread(std::function<void()> task) {
|
|||
/**** GL THREAD LOOP ****/
|
||||
|
||||
void ServoControl::Loop() {
|
||||
log("BrowserPage::Loop(). GL thread: %i", GetCurrentThreadId());
|
||||
log(L"BrowserPage::Loop(). GL thread: %i", GetCurrentThreadId());
|
||||
|
||||
if (mServo == nullptr) {
|
||||
log("Entering loop");
|
||||
log(L"Entering loop");
|
||||
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
|
||||
EGLNativeWindowType win = GetNativeWindow();
|
||||
mServo = std::make_unique<Servo>(mInitialURL, mArgs, mPanelWidth,
|
||||
|
@ -367,7 +374,7 @@ void ServoControl::StartRenderLoop() {
|
|||
#endif
|
||||
}
|
||||
mLooping = true;
|
||||
log("BrowserPage::StartRenderLoop(). UI thread: %i", GetCurrentThreadId());
|
||||
log(L"BrowserPage::StartRenderLoop(). UI thread: %i", GetCurrentThreadId());
|
||||
auto task = Concurrency::create_task([=] { Loop(); });
|
||||
mLoopTask = std::make_unique<Concurrency::task<void>>(task);
|
||||
}
|
||||
|
@ -515,41 +522,52 @@ ServoControl::PromptSync(hstring title, hstring message, hstring primaryButton,
|
|||
}
|
||||
|
||||
void ServoControl::OnServoPromptAlert(winrt::hstring message, bool trusted) {
|
||||
auto title = trusted ? L"" : mCurrentUrl + L" says:";
|
||||
PromptSync(title, message, L"OK", {}, {});
|
||||
auto titlefmt =
|
||||
format(mL10NStrings->PromptTitle.c_str(), mCurrentUrl.c_str());
|
||||
hstring title{trusted ? L"" : titlefmt};
|
||||
PromptSync(title, message, mL10NStrings->PromptOk, {}, {});
|
||||
}
|
||||
|
||||
servo::Servo::PromptResult
|
||||
ServoControl::OnServoPromptOkCancel(winrt::hstring message, bool trusted) {
|
||||
auto title = trusted ? L"" : mCurrentUrl + L" says:";
|
||||
auto [button, string] = PromptSync(title, message, L"OK", L"Cancel", {});
|
||||
Servo::PromptResult ServoControl::OnServoPromptOkCancel(winrt::hstring message,
|
||||
bool trusted) {
|
||||
auto titlefmt =
|
||||
format(mL10NStrings->PromptTitle.c_str(), mCurrentUrl.c_str());
|
||||
hstring title{trusted ? L"" : titlefmt};
|
||||
auto [button, string] = PromptSync(title, message, mL10NStrings->PromptOk,
|
||||
mL10NStrings->PromptCancel, {});
|
||||
if (button == Controls::ContentDialogResult::Primary) {
|
||||
return servo::Servo::PromptResult::Primary;
|
||||
return Servo::PromptResult::Primary;
|
||||
} else if (button == Controls::ContentDialogResult::Secondary) {
|
||||
return servo::Servo::PromptResult::Secondary;
|
||||
return Servo::PromptResult::Secondary;
|
||||
} else {
|
||||
return servo::Servo::PromptResult::Dismissed;
|
||||
return Servo::PromptResult::Dismissed;
|
||||
}
|
||||
}
|
||||
|
||||
servo::Servo::PromptResult
|
||||
ServoControl::OnServoPromptYesNo(winrt::hstring message, bool trusted) {
|
||||
auto title = trusted ? L"" : mCurrentUrl + L" says:";
|
||||
auto [button, string] = PromptSync(title, message, L"Yes", L"No", {});
|
||||
Servo::PromptResult ServoControl::OnServoPromptYesNo(winrt::hstring message,
|
||||
bool trusted) {
|
||||
auto titlefmt =
|
||||
format(mL10NStrings->PromptTitle.c_str(), mCurrentUrl.c_str());
|
||||
hstring title{trusted ? L"" : titlefmt};
|
||||
auto [button, string] = PromptSync(title, message, mL10NStrings->PromptYes,
|
||||
mL10NStrings->PromptNo, {});
|
||||
if (button == Controls::ContentDialogResult::Primary) {
|
||||
return servo::Servo::PromptResult::Primary;
|
||||
return Servo::PromptResult::Primary;
|
||||
} else if (button == Controls::ContentDialogResult::Secondary) {
|
||||
return servo::Servo::PromptResult::Secondary;
|
||||
return Servo::PromptResult::Secondary;
|
||||
} else {
|
||||
return servo::Servo::PromptResult::Dismissed;
|
||||
return Servo::PromptResult::Dismissed;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<hstring> ServoControl::OnServoPromptInput(winrt::hstring message,
|
||||
winrt::hstring default,
|
||||
bool trusted) {
|
||||
auto title = trusted ? L"" : mCurrentUrl + L" says:";
|
||||
auto [button, string] = PromptSync(title, message, L"Ok", L"Cancel", default);
|
||||
auto titlefmt =
|
||||
format(mL10NStrings->PromptTitle.c_str(), mCurrentUrl.c_str());
|
||||
hstring title{trusted ? L"" : titlefmt};
|
||||
auto [button, string] = PromptSync(title, message, mL10NStrings->PromptOk,
|
||||
mL10NStrings->PromptCancel, default);
|
||||
return string;
|
||||
}
|
||||
|
||||
|
@ -564,7 +582,8 @@ void ServoControl::OnServoDevtoolsStarted(bool success,
|
|||
void ServoControl::OnServoShowContextMenu(std::optional<hstring> title,
|
||||
std::vector<winrt::hstring> items) {
|
||||
RunOnUIThread([=] {
|
||||
MessageDialog msg{title.value_or(L"Menu")};
|
||||
auto titlestr = mL10NStrings->ContextMenuTitle;
|
||||
MessageDialog msg{title.value_or(titlestr)};
|
||||
for (auto i = 0; i < items.size(); i++) {
|
||||
UICommand cmd{items[i], [=](auto) {
|
||||
RunOnGLThread([=] {
|
||||
|
@ -574,7 +593,7 @@ void ServoControl::OnServoShowContextMenu(std::optional<hstring> title,
|
|||
}};
|
||||
msg.Commands().Append(cmd);
|
||||
}
|
||||
UICommand cancel{L"Cancel", [=](auto) {
|
||||
UICommand cancel{mL10NStrings->PromptCancel, [=](auto) {
|
||||
RunOnGLThread([=] {
|
||||
mServo->ContextMenuClosed(
|
||||
Servo::ContextMenuResult::Dismissed_, 0);
|
||||
|
|
|
@ -26,6 +26,16 @@ private:
|
|||
bool mIsDefault;
|
||||
};
|
||||
|
||||
struct L10NStrings {
|
||||
hstring ContextMenuTitle;
|
||||
hstring PromptTitle;
|
||||
hstring PromptOk;
|
||||
hstring PromptCancel;
|
||||
hstring PromptYes;
|
||||
hstring PromptNo;
|
||||
hstring URINotValid;
|
||||
};
|
||||
|
||||
struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
|
||||
|
||||
ServoControl();
|
||||
|
@ -266,8 +276,8 @@ private:
|
|||
CONDITION_VARIABLE mGLCondVar;
|
||||
std::unique_ptr<Concurrency::task<void>> mLoopTask;
|
||||
hstring mArgs;
|
||||
|
||||
std::optional<servo::Servo::MouseButton> mPressedMouseButton = {};
|
||||
std::unique_ptr<L10NStrings> mL10NStrings = nullptr;
|
||||
};
|
||||
} // namespace winrt::ServoApp::implementation
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue