Skip to content

Commit

Permalink
refactor: Cleanup in Xaml.Hosting namespace, focus event args
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jun 2, 2022
1 parent 9b7d5fc commit 2a5740e
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 250 deletions.
87 changes: 1 addition & 86 deletions src/SamplesApp/UnoIslands.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,93 +35,8 @@ public App()
InitializeLogging();

this.InitializeComponent();

#if HAS_UNO || NETFX_CORE
this.Suspending += OnSuspending;
#endif
}

// /// <summary>
// /// Invoked when the application is launched normally by the end user. Other entry points
// /// will be used such as when the application is launched to open a specific file.
// /// </summary>
// /// <param name="args">Details about the launch request and process.</param>
// protected override void OnLaunched(LaunchActivatedEventArgs args)
// {
//#if DEBUG
// if (System.Diagnostics.Debugger.IsAttached)
// {
// // this.DebugSettings.EnableFrameRateCounter = true;
// }
//#endif

//#if NET5_0 && WINDOWS
// _window = new Window();
// _window.Activate();
//#else
// _window = Windows.UI.Xaml.Window.Current;
//#endif

// var rootFrame = _window.Content as Frame;

// // Do not repeat app initialization when the Window already has content,
// // just ensure that the window is active
// if (rootFrame == null)
// {
// // Create a Frame to act as the navigation context and navigate to the first page
// rootFrame = new Frame();

// rootFrame.NavigationFailed += OnNavigationFailed;

// if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
// {
// // TODO: Load state from previously suspended application
// }

// // Place the frame in the current Window
// _window.Content = rootFrame;
// }

//#if !(NET5_0 && WINDOWS)
// if (args.PrelaunchActivated == false)
//#endif
// {
// if (rootFrame.Content == null)
// {
// // When the navigation stack isn't restored navigate to the first page,
// // configuring the new page by passing required information as a navigation
// // parameter
// rootFrame.Navigate(typeof(MainPage), args.Arguments);
// }
// // Ensure the current window is active
// _window.Activate();
// }
// }

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new InvalidOperationException($"Failed to load {e.SourcePageType.FullName}: {e.Exception}");
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
// TODO: Save application state and stop any background activity
deferral.Complete();
}


/// <summary>
/// Configures global Uno Platform logging
/// </summary>
Expand Down
7 changes: 3 additions & 4 deletions src/SamplesApp/UnoIslands.WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UnoIslands.WPF"
xmlns:xamlHost="clr-namespace:Uno.UI.XamlHost.Skia.Wpf;assembly=Uno.UI.Runtime.Skia.Wpf"
mc:Ignorable="d"
Title="Uno with Skia# Backend" Height="450" Width="800">
xmlns:xamlHost="clr-namespace:Uno.UI.XamlHost.Skia.Wpf;assembly=Uno.UI.Runtime.Skia.Wpf"
mc:Ignorable="d"
Title="Uno Islands Sample" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Hosting
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class DesktopWindowXamlSourceGotFocusEventArgs
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationRequest Request
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Hosting
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class DesktopWindowXamlSourceTakeFocusRequestedEventArgs
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationRequest Request
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Windows.UI.Xaml.Hosting;

/// <summary>
/// Provides event data for the GotFocus event.
/// </summary>
public partial class DesktopWindowXamlSourceGotFocusEventArgs
{
internal DesktopWindowXamlSourceGotFocusEventArgs(XamlSourceFocusNavigationRequest request)
{
Request = request;
}

/// <summary>
/// Gets a XamlSourceFocusNavigationRequest object that specifies the reason and other info for the focus navigation.
/// </summary>
public XamlSourceFocusNavigationRequest Request { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Windows.UI.Xaml.Hosting;

/// <summary>
/// Provides event data for the TakeFocusRequested event.
/// </summary>
public partial class DesktopWindowXamlSourceTakeFocusRequestedEventArgs
{
internal DesktopWindowXamlSourceTakeFocusRequestedEventArgs(XamlSourceFocusNavigationRequest request)
{
Request = request;
}

/// <summary>
/// Gets a XamlSourceFocusNavigationRequest object that specifies the reason and other info for the focus navigation.
/// </summary>
public XamlSourceFocusNavigationRequest Request { get; }
}
62 changes: 37 additions & 25 deletions src/Uno.UI/UI/Xaml/Hosting/ElementCompositionPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,61 @@
using System.Linq;
using Windows.UI.Composition;

namespace Windows.UI.Xaml.Hosting
namespace Windows.UI.Xaml.Hosting;

/// <summary>
/// Enables access to composition visual objects that back XAML elements in the XAML composition tree.
/// </summary>
public partial class ElementCompositionPreview
{
public partial class ElementCompositionPreview
{
private const string ChildVisualName = "childVisual";
private const string ChildVisualName = "childVisual";

#if !__SKIA__
static readonly Compositor _compositor = new Compositor();
static readonly Compositor _compositor = new Compositor();
#endif

public static Visual GetElementVisual(UIElement element)
{
/// <summary>
/// Retrieves the Windows.UI.Composition.Visual object that backs a XAML element in the XAML composition tree.
/// </summary>
/// <param name="element">The element for which to retrieve the Visual.</param>
/// <returns>The Windows.UI.Composition.Visual object that backs the XAML element.</returns>
public static Visual GetElementVisual(UIElement element)
{
#if __SKIA__
return element.Visual;
return element.Visual;
#else
return new Composition.Visual(_compositor) { NativeOwner = element };
return new Composition.Visual(_compositor) { NativeOwner = element };
#endif
}
}

public static void SetElementChildVisual(UIElement element, Visual visual)
{
/// <summary>
/// Sets a custom Windows.UI.Composition.Visual as the last child of the element’s visual tree.
/// </summary>
/// <param name="element">The element to add the child Visual to.</param>
/// <param name="visual">The Visual to add to the element's visual tree.</param>
public static void SetElementChildVisual(UIElement element, Visual visual)
{
#if __IOS__
element.Layer.AddSublayer(visual.NativeLayer);
visual.NativeOwner = element;
element.ClipsToBounds = false;

if (element is FrameworkElement fe)
{
fe.SizeChanged +=
(s, e) => visual.NativeLayer.Frame = new CoreGraphics.CGRect(0, 0, element.Frame.Width, element.Frame.Height);
}
if (element is FrameworkElement fe)
{
fe.SizeChanged +=
(s, e) => visual.NativeLayer.Frame = new CoreGraphics.CGRect(0, 0, element.Frame.Width, element.Frame.Height);
}
#elif __SKIA__

var container = new Composition.ContainerVisual(element.Visual.Compositor) { Comment = ChildVisualName };
container.Children.InsertAtTop(visual);
var container = new Composition.ContainerVisual(element.Visual.Compositor) { Comment = ChildVisualName };
container.Children.InsertAtTop(visual);

if (element.Visual.Children.FirstOrDefault(v => v.Comment == ChildVisualName) is Composition.ContainerVisual cv)
{
element.Visual.Children.Remove(cv);
}
if (element.Visual.Children.FirstOrDefault(v => v.Comment == ChildVisualName) is Composition.ContainerVisual cv)
{
element.Visual.Children.Remove(cv);
}

element.Visual.Children.InsertAtTop(container);
element.Visual.Children.InsertAtTop(container);
#endif
}
}
}
105 changes: 52 additions & 53 deletions src/Uno.UI/UI/Xaml/Hosting/XamlSourceFocusNavigationReason.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
namespace Windows.UI.Xaml.Hosting
namespace Windows.UI.Xaml.Hosting;

/// <summary>
/// Defines values that represent the reasons that the Windows.UI.Xaml.UIElement got focus
/// in a desktop application that uses a DesktopWindowXamlSource object to host XAML-based UI.
/// The XamlSourceFocusNavigationRequest.Reason property returns one of these values.
/// </summary>
public enum XamlSourceFocusNavigationReason
{
/// <summary>
/// Defines values that represent the reasons that the Windows.UI.Xaml.UIElement got focus
/// in a desktop application that uses a DesktopWindowXamlSource object to host XAML-based UI.
/// The XamlSourceFocusNavigationRequest.Reason property returns one of these values.
/// </summary>
public enum XamlSourceFocusNavigationReason
{
/// <summary>
/// The focus was set programmatically.
/// </summary>
Programmatic = 0,

/// <summary>
/// The focus was restored after a task switch, such as pressing Alt + Tab.
/// </summary>
Restore = 1,

/// <summary>
/// The focus was set in response to the user navigating to the next element
/// by using a bidirectional navigation experience (for example, by pressing Tab).
/// </summary>
First = 3,

/// <summary>
/// The focus was set in response to the user navigating to the previous element
/// by using a bidirectional navigation experience (for example, by pressing Shift-Tab).
/// </summary>
Last = 4,

/// <summary>
/// The focus was set in response to the user navigating left by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Left = 7,

/// <summary>
/// The focus was set in response to the user navigating up by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Up = 8,

/// <summary>
/// The focus was set in response to the user navigating right by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Right = 9,

/// <summary>
/// The focus was set in response to the user navigating down by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Down = 10,
}
/// The focus was set programmatically.
/// </summary>
Programmatic = 0,

/// <summary>
/// The focus was restored after a task switch, such as pressing Alt + Tab.
/// </summary>
Restore = 1,

/// <summary>
/// The focus was set in response to the user navigating to the next element
/// by using a bidirectional navigation experience (for example, by pressing Tab).
/// </summary>
First = 3,

/// <summary>
/// The focus was set in response to the user navigating to the previous element
/// by using a bidirectional navigation experience (for example, by pressing Shift-Tab).
/// </summary>
Last = 4,

/// <summary>
/// The focus was set in response to the user navigating left by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Left = 7,

/// <summary>
/// The focus was set in response to the user navigating up by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Up = 8,

/// <summary>
/// The focus was set in response to the user navigating right by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Right = 9,

/// <summary>
/// The focus was set in response to the user navigating down by using
/// a 4-direction navigation experience (for example, by using keyboard arrow keys).
/// </summary>
Down = 10,
}
Loading

0 comments on commit 2a5740e

Please sign in to comment.