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:
bors-servo 2020-06-11 02:12:00 -04:00 committed by GitHub
commit 10202c2ad2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 460 additions and 118 deletions

View file

@ -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 "BrowserPage.h"
#include "BrowserPage.g.cpp"
#include "DefaultUrl.h"
@ -19,6 +19,7 @@ using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::UI::ViewManagement;
using namespace winrt::Windows::ApplicationModel::Core;
using namespace winrt::Windows::ApplicationModel::Resources;
using namespace winrt::Windows::UI::Notifications;
using namespace winrt::Windows::Data::Xml::Dom;
@ -103,7 +104,7 @@ void BrowserPage::LoadServoURI(Uri uri) {
auto scheme = uri.SchemeName();
if (scheme != SERVO_SCHEME) {
log("Unexpected URL: ", uri.RawUri().c_str());
log(L"Unexpected URL: ", uri.RawUri().c_str());
return;
}
std::wstring raw{uri.RawUri()};
@ -181,6 +182,9 @@ void BrowserPage::BuildPrefList() {
// it's pretty difficiult to have different controls depending
// on the pref type.
prefList().Children().Clear();
auto resourceLoader = ResourceLoader::GetForCurrentView();
auto resetStr =
resourceLoader.GetString(L"devtoolsPreferenceResetButton/Content");
for (auto pref : ServoControl().Preferences()) {
auto value = pref.Value();
auto type = value.as<IPropertyValue>().Type();
@ -244,7 +248,7 @@ void BrowserPage::BuildPrefList() {
ctrl->Margin({4, 0, 40, 0});
stack.Children().Append(*ctrl);
auto reset = Controls::Button();
reset.Content(winrt::box_value(L"reset"));
reset.Content(winrt::box_value(resetStr));
reset.IsEnabled(!pref.IsDefault());
reset.Click([=](const auto &, auto const &) {
auto upref = ServoControl().ResetPref(pref.Key());
@ -284,18 +288,19 @@ void BrowserPage::OnDevtoolsButtonClicked(IInspectable const &,
BuildPrefList();
// FIXME: we could use template + binding for this.
auto ok = mDevtoolsStatus == DevtoolsStatus::Running ? Visibility::Visible
: Visibility::Collapsed;
auto ko = mDevtoolsStatus == DevtoolsStatus::Failed ? Visibility::Visible
: Visibility::Collapsed;
auto wip = mDevtoolsStatus == DevtoolsStatus::Stopped ? Visibility::Visible
: Visibility::Collapsed;
DevtoolsStatusOK().Visibility(ok);
DevtoolsStatusKO().Visibility(ko);
DevtoolsStatusWIP().Visibility(wip);
auto resourceLoader = ResourceLoader::GetForCurrentView();
if (mDevtoolsStatus == DevtoolsStatus::Running) {
DevtoolsPort().Text(std::to_wstring(mDevtoolsPort));
std::wstring message =
resourceLoader.GetString(L"devtoolsStatus/Running").c_str();
std::wstring formatted =
format(message, std::to_wstring(mDevtoolsPort).c_str());
DevtoolsStatusMessage().Text(formatted);
} else if (mDevtoolsStatus == DevtoolsStatus::Failed) {
DevtoolsStatusMessage().Text(
resourceLoader.GetString(L"devtoolsStatus/Failed"));
} else if (mDevtoolsStatus == DevtoolsStatus::Stopped) {
DevtoolsStatusMessage().Text(
resourceLoader.GetString(L"devtoolsStatus/Stopped"));
}
}

View file

@ -9,8 +9,6 @@
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">
<Page.Resources>
<Style x:Key="NavigationBarButton" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
@ -98,41 +96,41 @@
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Column="0">
<Button Style="{StaticResource NavigationBarButton}" x:Name="backButton" IsTabStop="true" IsEnabled="false" Click="OnBackButtonClicked" AutomationProperties.Name="Back" ToolTipService.ToolTip="Back">
<Button Style="{StaticResource NavigationBarButton}" x:Uid="backButton" x:Name="backButton" IsTabStop="true" IsEnabled="false" Click="OnBackButtonClicked">
<Image Source="Assets/UI/back.png" Height="18"></Image>
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="Left" Modifiers="Menu" />
</Button.KeyboardAccelerators>
</Button>
<Button Style="{StaticResource NavigationBarButton}" x:Name="forwardButton" IsTabStop="true" IsEnabled="false" Click="OnForwardButtonClicked" AutomationProperties.Name="Forward" ToolTipService.ToolTip="Forward">
<Button Style="{StaticResource NavigationBarButton}" x:Uid="forwardButton" x:Name="forwardButton" IsTabStop="true" IsEnabled="false" Click="OnForwardButtonClicked">
<Image Source="Assets/UI/forward.png" Height="18"></Image>
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="Right" Modifiers="Menu" />
</Button.KeyboardAccelerators>
</Button>
<Button Style="{StaticResource NavigationBarButton}" x:Name="reloadButton" IsTabStop="true" IsEnabled="false" Visibility="Visible" Click="OnReloadButtonClicked" AutomationProperties.Name="Reload" ToolTipService.ToolTip="Reload">
<Button Style="{StaticResource NavigationBarButton}" x:Name="reloadButton" x:Uid="reloadButton" IsTabStop="true" IsEnabled="false" Visibility="Visible" Click="OnReloadButtonClicked">
<Image Source="Assets/UI/reload.png" Height="18"></Image>
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="R" Modifiers="Control" />
</Button.KeyboardAccelerators>
</Button>
<Button Style="{StaticResource NavigationBarButton}" x:Name="stopButton" IsTabStop="true" IsEnabled="false" Visibility="Collapsed" Click="OnStopButtonClicked" AutomationProperties.Name="Stop" ToolTipService.ToolTip="Stop">
<Button Style="{StaticResource NavigationBarButton}" x:Name="stopButton" x:Uid="stopButton" IsTabStop="true" IsEnabled="false" Visibility="Collapsed" Click="OnStopButtonClicked">
<Image Source="Assets/UI/cross.png" Height="18"></Image>
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="Escape" Modifiers="None" />
</Button.KeyboardAccelerators>
</Button>
<Button Style="{StaticResource NavigationBarButton}" x:Name="homeButton" IsTabStop="true" Click="OnHomeButtonClicked" AutomationProperties.Name="Home" ToolTipService.ToolTip="Home">
<Button Style="{StaticResource NavigationBarButton}" x:Name="homeButton" x:Uid="homeButton" IsTabStop="true" Click="OnHomeButtonClicked">
<Image Source="Assets/UI/home.png" Height="18"></Image>
</Button>
</StackPanel>
<TextBox Text="" IsTabStop="true" InputScope="Url" PlaceholderText="Type a URL" x:Name="urlTextbox" VerticalAlignment="Center" Grid.Column="1" KeyUp="OnURLEdited" IsSpellCheckEnabled="False" Margin="3,0" KeyboardAcceleratorPlacementMode="Hidden">
<TextBox x:Uid="urlTextbox" Text="" IsTabStop="true" InputScope="Url" x:Name="urlTextbox" VerticalAlignment="Center" Grid.Column="1" KeyUp="OnURLEdited" IsSpellCheckEnabled="False" Margin="3,0" KeyboardAcceleratorPlacementMode="Hidden">
<TextBox.KeyboardAccelerators>
<KeyboardAccelerator Key="L" Modifiers="Control" Invoked="OnURLKeyboardAccelerator"/>
</TextBox.KeyboardAccelerators>
</TextBox>
<StackPanel Orientation="Horizontal" Grid.Column="2">
<Button Style="{StaticResource NavigationBarButton}" x:Name="devtoolsButton" IsTabStop="true" Click="OnDevtoolsButtonClicked" AutomationProperties.Name="Devtools" ToolTipService.ToolTip="Devtools">
<Button Style="{StaticResource NavigationBarButton}" x:Name="devtoolsButton" x:Uid="devtoolsButton" IsTabStop="true" Click="OnDevtoolsButtonClicked">
<Image Source="Assets/UI/devtools.png" Height="18"></Image>
</Button>
<ProgressRing x:Name="urlbarLoadingIndicator" Margin="10,0"/>
@ -151,28 +149,16 @@
</Button>
</Grid>
</muxc:TabView.TabStripFooter>
<muxc:TabViewItem Header="Devtools Server" IsClosable="False">
<StackPanel>
<TextBlock x:Name="DevtoolsStatusOK" Visibility="Collapsed" Margin="10">
<Run>Devtools server is listening on port </Run>
<Run FontWeight="Bold" x:Name="DevtoolsPort"></Run>
<Run>.</Run>
</TextBlock>
<TextBlock x:Name="DevtoolsStatusKO" Visibility="Collapsed">
<Run>Devtools server failed to start.</Run>
</TextBlock>
<TextBlock x:Name="DevtoolsStatusWIP" Visibility="Collapsed">
<Run>Devtools server is starting..</Run>
</TextBlock>
</StackPanel>
<muxc:TabViewItem x:Uid="devtoolsTabServer" IsClosable="False">
<TextBlock x:Name="DevtoolsStatusMessage" Margin="10"></TextBlock>
</muxc:TabViewItem>
<muxc:TabViewItem Header="Preferences" IsClosable="False">
<muxc:TabViewItem x:Uid="devtoolsTabPrefs" IsClosable="False">
<Grid VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="" IsTabStop="true" PlaceholderText="Search preferences" x:Name="preferenceSearchbox" VerticalAlignment="Center" KeyUp="OnPrefererenceSearchboxEdited" IsSpellCheckEnabled="False" Margin="3"/>
<TextBox Grid.Row="0" IsTabStop="true" x:Uid="preferenceSearchbox" x:Name="preferenceSearchbox" VerticalAlignment="Center" KeyUp="OnPrefererenceSearchboxEdited" IsSpellCheckEnabled="False" Margin="3"/>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="prefList"/>
</ScrollViewer>
@ -181,8 +167,8 @@
</muxc:TabView>
<ProgressBar x:Name="transientLoadingIndicator" Visibility="Collapsed" Grid.Row="3"/>
<CommandBar Grid.Row="4" x:Name="mediaControls" Visibility="Collapsed">
<AppBarButton Icon="Play" Label="Play" x:Name="playButton" Visibility="Collapsed" Click="OnMediaControlsPlayClicked"/>
<AppBarButton Icon="Pause" Label="Pause" x:Name="pauseButton" Click="OnMediaControlsPauseClicked"/>
<AppBarButton Icon="Play" x:Uid="playButton" x:Name="playButton" Visibility="Collapsed" Click="OnMediaControlsPlayClicked"/>
<AppBarButton Icon="Pause" x:Uid="pauseButton" x:Name="pauseButton" Click="OnMediaControlsPauseClicked"/>
</CommandBar>
</Grid>

View file

@ -16,7 +16,7 @@
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="ServoApp.App">
<uap:VisualElements DisplayName="Firefox Reality" Description="Firefox Reality brings the best and freshest content from the web that you know and love to Virtual Reality headsets. Our browser provides an open, accessible and secure way for everyone to explore the web. Experience sharp text, high quality videos, and a seamless transition from 2D to 3D immersive modes. Enjoy the best possible web browsing experience with Firefox Reality." Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" BackgroundColor="transparent">
<uap:VisualElements DisplayName="Firefox Reality" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" BackgroundColor="transparent" Description="ms-resource:appDescription">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" ShortName="Firefox Reality" Square310x310Logo="Assets\LargeTile.png" Square71x71Logo="Assets\SmallTile.png">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo" />

View file

@ -119,7 +119,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="logs.h" />
<ClInclude Include="strutils.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="App.h">
<DependentUpon>App.xaml</DependentUpon>
@ -923,7 +923,6 @@
<DependentUpon>BrowserPage.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="logs.cpp" />
<ClCompile Include="ServoControl\OpenGLES.cpp" />
<ClCompile Include="ServoControl\Servo.cpp" />
<ClCompile Include="ServoControl\ServoControl.cpp" />
@ -943,6 +942,10 @@
</None>
<None Include="PropertySheet.props" />
</ItemGroup>
<ItemGroup>
<PRIResource Include="Strings\en-US\Resources.resw" />
<PRIResource Include="Strings\fr-FR\Resources.resw" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets')" />

View file

@ -10,7 +10,6 @@
<ItemGroup>
<ClCompile Include="pch.cpp" />
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="logs.cpp" />
<ClCompile Include="BrowserPage.cpp" />
<ClCompile Include="App.cpp" />
<ClCompile Include="ServoControl\OpenGLES.cpp">
@ -25,7 +24,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="logs.h" />
<ClInclude Include="BrowserPage.h" />
<ClInclude Include="App.h" />
<ClInclude Include="ServoControl\OpenGLES.h">
@ -38,6 +36,7 @@
<Filter>ServoControl</Filter>
</ClInclude>
<ClInclude Include="DefaultUrl.h" />
<ClInclude Include="strutils.h" />
</ItemGroup>
<ItemGroup>
<Image Include="Assets\Wide310x150Logo.scale-200.png">
@ -888,6 +887,15 @@
<Filter Include="Assets\UI">
<UniqueIdentifier>{d49fe329-5e22-4470-8310-5b925419e6f8}</UniqueIdentifier>
</Filter>
<Filter Include="Strings">
<UniqueIdentifier>{49e23631-d899-4caf-bf7b-30776fee4d09}</UniqueIdentifier>
</Filter>
<Filter Include="Strings\en-US">
<UniqueIdentifier>{c12ff5d4-3730-4a0e-8b16-56ded3138875}</UniqueIdentifier>
</Filter>
<Filter Include="Strings\fr-FR">
<UniqueIdentifier>{b7d3273d-a27c-4176-87a1-3d5222b796b3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
@ -901,4 +909,12 @@
<ItemGroup>
<ApplicationDefinition Include="App.xaml" />
</ItemGroup>
<ItemGroup>
<PRIResource Include="Strings\en-US\Resources.resw">
<Filter>Strings\en-US</Filter>
</PRIResource>
<PRIResource Include="Strings\fr-FR\Resources.resw">
<Filter>Strings\fr-FR</Filter>
</PRIResource>
</ItemGroup>
</Project>

View file

@ -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();
}

View file

@ -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);

View file

@ -6,7 +6,7 @@
#include "pch.h"
#include <EGL/egl.h>
#include "logs.h"
#include "strutils.h"
#include <stdlib.h>
namespace winrt::servo {

View file

@ -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);

View file

@ -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

View file

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!-- A xx-XX/Resources.resw file doesn't need to 100% cover the en-US/Resources.resw counterpart.
The application falls back to the english resources if the string is not found -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="appDescription" xml:space="preserve">
<value>Firefox Reality brings the best and freshest content from the web that you know and love to Virtual Reality headsets. Our browser provides an open, accessible and secure way for everyone to explore the web. Experience sharp text, high quality videos, and a seamless transition from 2D to 3D immersive modes. Enjoy the best possible web browsing experience with Firefox Reality.</value>
</data>
<data name="backButton.AutomationProperties.Name" xml:space="preserve">
<value>Back</value>
<comment>Will be recognized by the speech recognition system</comment>
</data>
<data name="backButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Back</value>
</data>
<data name="devtoolsButton.AutomationProperties.Name" xml:space="preserve">
<value>Developer Tools</value>
<comment>Will be recognized by the speech recognition system</comment>
</data>
<data name="devtoolsButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Developer Tools</value>
</data>
<data name="forwardButton.AutomationProperties.Name" xml:space="preserve">
<value>Forward</value>
<comment>Will be recognized by the speech recognition system</comment>
</data>
<data name="forwardButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Forward</value>
</data>
<data name="homeButton.AutomationProperties.Name" xml:space="preserve">
<value>Home</value>
<comment>Will be recognized by the speech recognition system</comment>
</data>
<data name="homeButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Home</value>
</data>
<data name="reloadButton.AutomationProperties.Name" xml:space="preserve">
<value>Reload</value>
<comment>Will be recognized by the speech recognition system</comment>
</data>
<data name="reloadButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Reload</value>
</data>
<data name="stopButton.AutomationProperties.Name" xml:space="preserve">
<value>Stop</value>
<comment>Will be recognized by the speech recognition system</comment>
</data>
<data name="stopButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Stop</value>
</data>
<data name="urlTextbox.PlaceholderText" xml:space="preserve">
<value>Type a URL</value>
</data>
<data name="devtoolsTabServer.[using:Microsoft.UI.Xaml.Controls]TabViewItem.Header" xml:space="preserve">
<value>Devtools Server</value>
</data>
<data name="devtoolsTabPrefs.[using:Microsoft.UI.Xaml.Controls]TabViewItem.Header" xml:space="preserve">
<value>Preferences</value>
</data>
<data name="preferenceSearchbox.PlaceholderText" xml:space="preserve">
<value>Search Preferences</value>
</data>
<data name="playButton.Label" xml:space="preserve">
<value>Play</value>
</data>
<data name="pauseButton.Label" xml:space="preserve">
<value>Pause</value>
</data>
<data name="devtoolsStatus.Running" xml:space="preserve">
<value>Devtools server is listening on port %s.</value>
</data>
<data name="devtoolsStatus.Failed" xml:space="preserve">
<value>Devtools server failed to start.</value>
</data>
<data name="devtoolsStatus.Stopped" xml:space="preserve">
<value>Devtools server is starting.</value>
</data>
<data name="devtoolsPreferenceResetButton.Content" xml:space="preserve">
<value>reset</value>
</data>
<data name="URINotValid.Alert" xml:space="preserve">
<value>URI not valid</value>
</data>
<data name="JavascriptPrompt.ok" xml:space="preserve">
<value>ok</value>
</data>
<data name="JavascriptPrompt.cancel" xml:space="preserve">
<value>cancel</value>
</data>
<data name="JavascriptPrompt.yes" xml:space="preserve">
<value>yes</value>
</data>
<data name="JavascriptPrompt.no" xml:space="preserve">
<value>no</value>
</data>
<data name="JavascriptPrompt.title" xml:space="preserve">
<value>"%s" says:</value>
</data>
<data name="ContextMenu.title" xml:space="preserve">
<value>Menu</value>
</data>
</root>

View file

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="backButton.AutomationProperties.Name" xml:space="preserve">
<value>Retour</value>
<comment>Will be recognized by the speech recognition system</comment>
</data>
<data name="backButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Retour</value>
</data>
<data name="devtoolsButton.AutomationProperties.Name" xml:space="preserve">
<comment>Will be recognized by the speech recognition system</comment>
<value>Outils de développement</value>
</data>
<data name="devtoolsButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Outils de développement</value>
</data>
<data name="forwardButton.AutomationProperties.Name" xml:space="preserve">
<comment>Will be recognized by the speech recognition system</comment>
<value>Avancer</value>
</data>
<data name="forwardButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Avancer</value>
</data>
<data name="homeButton.AutomationProperties.Name" xml:space="preserve">
<comment>Will be recognized by the speech recognition system</comment>
<value>Accueil</value>
</data>
<data name="homeButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Accueil</value>
</data>
<data name="reloadButton.AutomationProperties.Name" xml:space="preserve">
<comment>Will be recognized by the speech recognition system</comment>
<value>Actualiser</value>
</data>
<data name="reloadButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Actualiser</value>
</data>
<data name="stopButton.AutomationProperties.Name" xml:space="preserve">
<comment>Will be recognized by the speech recognition system</comment>
<value>Arrêter</value>
</data>
<data name="stopButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Arrêter</value>
</data>
<data name="urlTextbox.PlaceholderText" xml:space="preserve">
<value>Saisir une adresse</value>
</data>
<data name="devtoolsTabServer.[using:Microsoft.UI.Xaml.Controls]TabViewItem.Header" xml:space="preserve">
<value>Serveur DevTools</value>
</data>
<data name="devtoolsTabPrefs.[using:Microsoft.UI.Xaml.Controls]TabViewItem.Header" xml:space="preserve">
<value>Préférences</value>
</data>
<data name="preferenceSearchbox.PlaceholderText" xml:space="preserve">
<value>Rechercher préférence</value>
</data>
<data name="playButton.Label" xml:space="preserve">
<value>Jouer</value>
</data>
<data name="pauseButton.Label" xml:space="preserve">
<value>Pause</value>
</data>
<data name="devtoolsStatus.Running" xml:space="preserve">
<value>Le serveur DevTools écoute sur le port %s.</value>
</data>
<data name="devtoolsStatus.Failed" xml:space="preserve">
<value>Le serveur DevTools n'a pas pu démarrer.</value>
</data>
<data name="devtoolsStatus.Stopped" xml:space="preserve">
<value>Le serveur DevTools démarre.</value>
</data>
<data name="devtoolsPreferenceResetButton.Content" xml:space="preserve">
<value>réinitialiser</value>
</data>
<data name="URINotValid.Alert" xml:space="preserve">
<value>URI invalide</value>
</data>
<data name="JavascriptPrompt.ok" xml:space="preserve">
<value>ok</value>
</data>
<data name="JavascriptPrompt.cancel" xml:space="preserve">
<value>annuler</value>
</data>
<data name="JavascriptPrompt.yes" xml:space="preserve">
<value>oui</value>
</data>
<data name="JavascriptPrompt.no" xml:space="preserve">
<value>non</value>
</data>
<data name="JavascriptPrompt.title" xml:space="preserve">
<value>"%s" dit:</value>
</data>
<data name="ContextMenu.title" xml:space="preserve">
<value>Menu</value>
</data>
</root>

View file

@ -1,27 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "pch.h"
void log(const char *format, ...) {
char buf[4096], *p = buf;
va_list args;
int n;
va_start(args, format);
n = vsnprintf(p, sizeof buf - 3, format, args);
va_end(args);
p += (n < 0) ? sizeof buf - 3 : n;
while (p > buf && isspace(p[-1])) {
*--p = '\0';
}
*p++ = '\r';
*p++ = '\n';
*p = '\0';
OutputDebugStringA(buf);
}

View file

@ -1,7 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#pragma once
void log(const char *format, ...);

View file

@ -29,6 +29,7 @@
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#include <winrt/Windows.ApplicationModel.Resources.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Metadata.h>

View file

@ -0,0 +1,22 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#pragma once
template <typename... Args>
std::wstring format(const std::wstring &txt, Args... args) {
size_t size = swprintf(nullptr, 0, txt.c_str(), args...) + 1;
if (size <= 0) {
throw std::runtime_error("Error during formatting.");
}
auto ptr = new wchar_t[size];
swprintf(ptr, size, txt.c_str(), args...);
auto wstr = std::wstring(ptr);
delete ptr;
return wstr;
}
template <typename... Args> void log(const std::wstring &txt, Args... args) {
OutputDebugString((format(txt, args...) + L"\r\n").c_str());
}