Skip to content
Permalink
Browse files

Switch to chromeless mode when app opens from a servo:// link

  • Loading branch information...
paulrouget committed Aug 29, 2019
1 parent 3ade7b6 commit 5fe9a6223d74bcf9849c1b8c39e8ea9f2100bc45
@@ -71,7 +71,8 @@ void App::OnActivated(IActivatedEventArgs const &args) {
Frame rootFrame{nullptr};

auto content = Window::Current().Content();
if (content == nullptr) {
bool isRunning = content != nullptr;
if (!isRunning) {
rootFrame = Frame();
rootFrame.Navigate(xaml_typename<ServoApp::BrowserPage>());
Window::Current().Content(rootFrame);
@@ -81,6 +82,9 @@ void App::OnActivated(IActivatedEventArgs const &args) {
}
auto page = rootFrame.Content().try_as<BrowserPage>();
page->LoadServoURI(protocolActivatedEventArgs.Uri());
// If Servo was opened as a result of clicking on a servo:// URL,
// we activate transient mode.
page->SetTransientMode(!isRunning);
}
}

@@ -55,6 +55,12 @@ void BrowserPage::LoadServoURI(Uri uri) {
servoControl().LoadURIOrSearch(raw2);
}

void BrowserPage::SetTransientMode(bool transient) {
servoControl().SetTransientMode(transient);
navigationBar().Visibility(transient ? Visibility::Collapsed
: Visibility::Visible);
}

void BrowserPage::Shutdown() { servoControl().Shutdown(); }

/**** USER INTERACTIONS WITH UI ****/
@@ -28,6 +28,7 @@ struct BrowserPage : BrowserPageT<BrowserPage> {
Windows::UI::Xaml::Input::KeyRoutedEventArgs const &);
void Shutdown();
void LoadServoURI(Windows::Foundation::Uri uri);
void SetTransientMode(bool);

private:
void BindServoEvents();
@@ -8,6 +8,7 @@ using namespace winrt::Windows::Graphics::Display;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::System;
using namespace concurrency;
using namespace winrt::servo;

@@ -270,7 +271,14 @@ void ServoControl::WakeUp() {
RunOnGLThread([=] {});
}

bool ServoControl::OnServoAllowNavigation(hstring) { return true; }
bool ServoControl::OnServoAllowNavigation(hstring uri) {
if (mTransient) {
RunOnUIThread([=] {
Launcher::LaunchUriAsync(Uri{uri});
});
}
return !mTransient;
}

void ServoControl::OnServoAnimatingChanged(bool animating) {
EnterCriticalSection(&mGLLock);
@@ -69,6 +69,8 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
mOnCaptureGesturesEndedEvent.remove(token);
}

void SetTransientMode(bool transient) { mTransient = transient; }

virtual void WakeUp();
virtual void OnServoLoadStarted();
virtual void OnServoLoadEnded();
@@ -94,6 +96,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {

float mDPI = 1;
hstring mInitialURL = L"https://servo.org";
bool mTransient = false;

Windows::UI::Xaml::Controls::SwapChainPanel ServoControl::Panel();
void CreateRenderSurface();
@@ -10,6 +10,7 @@ namespace ServoApp {
void Reload();
void Stop();
Windows.Foundation.Uri LoadURIOrSearch(String url);
void SetTransientMode(Boolean transient);
void Shutdown();
event EventDelegate OnLoadStarted;
event EventDelegate OnLoadEnded;
@@ -39,6 +39,7 @@
#include <winrt/Windows.Perception.Spatial.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>
#include <winrt/windows.system.h>
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.UI.Input.Spatial.h>
#include <winrt/Windows.UI.Popups.h>

0 comments on commit 5fe9a62

Please sign in to comment.
You can’t perform that action at this time.