Auto merge of #24639 - paulrouget:xaml-keybindings, r=jdm

Xaml keybindings

Some keybindings for the Windows UWP app.
This commit is contained in:
bors-servo 2019-11-04 14:40:31 -05:00 committed by GitHub
commit 1d450ba1f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 102 deletions

View file

@ -7,6 +7,7 @@
#include "BrowserPage.h" #include "BrowserPage.h"
#include "BrowserPage.g.cpp" #include "BrowserPage.g.cpp"
using namespace std::placeholders;
using namespace winrt::Windows::Foundation; using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core; using namespace winrt::Windows::UI::Core;
@ -50,6 +51,17 @@ void BrowserPage::BindServoEvents() {
}); });
servoControl().OnCaptureGesturesEnded( servoControl().OnCaptureGesturesEnded(
[=] { navigationBar().IsHitTestVisible(true); }); [=] { navigationBar().IsHitTestVisible(true); });
urlTextbox().GotFocus(std::bind(&BrowserPage::OnURLFocused, this, _1));
}
void BrowserPage::OnURLFocused(Windows::Foundation::IInspectable const &) {
urlTextbox().SelectAll();
}
void BrowserPage::OnURLKeyboardAccelerator(
Windows::Foundation::IInspectable const &,
Windows::UI::Xaml::Input::KeyboardAcceleratorInvokedEventArgs const &) {
urlTextbox().Focus(FocusState::Programmatic);
} }
void BrowserPage::LoadServoURI(Uri uri) { void BrowserPage::LoadServoURI(Uri uri) {

View file

@ -26,6 +26,10 @@ public:
Windows::UI::Xaml::RoutedEventArgs const &); Windows::UI::Xaml::RoutedEventArgs const &);
void OnURLEdited(Windows::Foundation::IInspectable const &, void OnURLEdited(Windows::Foundation::IInspectable const &,
Windows::UI::Xaml::Input::KeyRoutedEventArgs const &); Windows::UI::Xaml::Input::KeyRoutedEventArgs const &);
void OnURLFocused(Windows::Foundation::IInspectable const &);
void OnURLKeyboardAccelerator(
Windows::Foundation::IInspectable const &,
Windows::UI::Xaml::Input::KeyboardAcceleratorInvokedEventArgs const &);
void Shutdown(); void Shutdown();
void LoadServoURI(Windows::Foundation::Uri uri); void LoadServoURI(Windows::Foundation::Uri uri);
void SetTransientMode(bool); void SetTransientMode(bool);

View file

@ -7,108 +7,124 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<Style x:Key="NavigationBarButton" TargetType="Button"> <Style x:Key="NavigationBarButton" TargetType="Button">
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{ThemeResource ButtonForeground}"/> <Setter Property="Foreground" Value="{ThemeResource ButtonForeground}"/>
<Setter Property="BorderBrush" Value="{ThemeResource ButtonBorderBrush}"/> <Setter Property="BorderBrush" Value="{ThemeResource ButtonBorderBrush}"/>
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}"/> <Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}"/>
<Setter Property="Padding" Value="0"/> <Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="10,2"/> <Setter Property="Margin" Value="10,2"/>
<Setter Property="MinWidth" Value="30"/> <Setter Property="MinWidth" Value="30"/>
<Setter Property="MinHeight" Value="30"/> <Setter Property="MinHeight" Value="30"/>
<Setter Property="HorizontalAlignment" Value="Center"/> <Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontWeight" Value="Normal"/> <Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/> <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}"/> <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}"/>
<Setter Property="FocusVisualMargin" Value="-3"/> <Setter Property="FocusVisualMargin" Value="-3"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="Button"> <ControlTemplate TargetType="Button">
<ContentPresenter x:Name="ContentPresenter" AutomationProperties.AccessibilityView="Raw" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" CornerRadius="{TemplateBinding CornerRadius}" ContentTransitions="{TemplateBinding ContentTransitions}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"> <ContentPresenter x:Name="ContentPresenter" AutomationProperties.AccessibilityView="Raw" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" CornerRadius="{TemplateBinding CornerRadius}" ContentTransitions="{TemplateBinding ContentTransitions}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
<VisualStateManager.VisualStateGroups> <VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates"> <VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"> <VisualState x:Name="Normal">
<Storyboard> <Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter"/> <PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter"/>
</Storyboard> </Storyboard>
</VisualState> </VisualState>
<VisualState x:Name="PointerOver"> <VisualState x:Name="PointerOver">
<Storyboard> <Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBackgroundPointerOver}"/> <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBackgroundPointerOver}"/>
</ObjectAnimationUsingKeyFrames> </ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPointerOver}"/> <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPointerOver}"/>
</ObjectAnimationUsingKeyFrames> </ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPointerOver}"/> <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPointerOver}"/>
</ObjectAnimationUsingKeyFrames> </ObjectAnimationUsingKeyFrames>
<PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter"/> <PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter"/>
</Storyboard> </Storyboard>
</VisualState> </VisualState>
<VisualState x:Name="Pressed"> <VisualState x:Name="Pressed">
<Storyboard> <Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBackgroundPressed}"/> <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBackgroundPressed}"/>
</ObjectAnimationUsingKeyFrames> </ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPressed}"/> <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPressed}"/>
</ObjectAnimationUsingKeyFrames> </ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPressed}"/> <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPressed}"/>
</ObjectAnimationUsingKeyFrames> </ObjectAnimationUsingKeyFrames>
<PointerDownThemeAnimation Storyboard.TargetName="ContentPresenter"/> <PointerDownThemeAnimation Storyboard.TargetName="ContentPresenter"/>
</Storyboard> </Storyboard>
</VisualState> </VisualState>
<VisualState x:Name="Disabled"> <VisualState x:Name="Disabled">
<Storyboard> <Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Opacity"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Opacity">
<DiscreteObjectKeyFrame KeyTime="0" Value="0.2"/> <DiscreteObjectKeyFrame KeyTime="0" Value="0.2"/>
</ObjectAnimationUsingKeyFrames> </ObjectAnimationUsingKeyFrames>
</Storyboard> </Storyboard>
</VisualState> </VisualState>
</VisualStateGroup> </VisualStateGroup>
</VisualStateManager.VisualStateGroups> </VisualStateManager.VisualStateGroups>
</ContentPresenter> </ContentPresenter>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
</Page.Resources> </Page.Resources>
<Grid VerticalAlignment="Stretch"> <Grid VerticalAlignment="Stretch">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="0" x:Name="navigationBar" Background="{ThemeResource InkToolbarButtonBackgroundThemeBrush}"> <Grid Grid.Row="0" x:Name="navigationBar" Background="{ThemeResource InkToolbarButtonBackgroundThemeBrush}">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/> <ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/> <ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Column="0"> <StackPanel Orientation="Horizontal" Grid.Column="0">
<Button Style="{StaticResource NavigationBarButton}" x:Name="backButton" IsTabStop="true" IsEnabled="false" Click="OnBackButtonClicked" AutomationProperties.Name="Back"> <Button Style="{StaticResource NavigationBarButton}" x:Name="backButton" IsTabStop="true" IsEnabled="false" Click="OnBackButtonClicked" AutomationProperties.Name="Back">
<Image Source="Assets/UI/back.png" Height="12"></Image> <Image Source="Assets/UI/back.png" Height="12"></Image>
</Button> <Button.KeyboardAccelerators>
<Button Style="{StaticResource NavigationBarButton}" x:Name="forwardButton" IsTabStop="true" IsEnabled="false" Click="OnForwardButtonClicked" AutomationProperties.Name="Forward"> <KeyboardAccelerator Key="Left" Modifiers="Menu" />
<Image Source="Assets/UI/forward.png" Height="12"></Image> </Button.KeyboardAccelerators>
</Button> </Button>
<Button Style="{StaticResource NavigationBarButton}" x:Name="reloadButton" IsTabStop="true" IsEnabled="false" Visibility="Visible" Click="OnReloadButtonClicked" AutomationProperties.Name="Reload"> <Button Style="{StaticResource NavigationBarButton}" x:Name="forwardButton" IsTabStop="true" IsEnabled="false" Click="OnForwardButtonClicked" AutomationProperties.Name="Forward">
<Image Source="Assets/UI/reload.png" Height="12"></Image> <Image Source="Assets/UI/forward.png" Height="12"></Image>
</Button> <Button.KeyboardAccelerators>
<Button Style="{StaticResource NavigationBarButton}" x:Name="stopButton" IsTabStop="true" IsEnabled="false" Visibility="Collapsed" Click="OnStopButtonClicked" AutomationProperties.Name="Stop"> <KeyboardAccelerator Key="Right" Modifiers="Menu" />
<Image Source="Assets/UI/stop.png" Height="12"></Image> </Button.KeyboardAccelerators>
</Button> </Button>
</StackPanel> <Button Style="{StaticResource NavigationBarButton}" x:Name="reloadButton" IsTabStop="true" IsEnabled="false" Visibility="Visible" Click="OnReloadButtonClicked" AutomationProperties.Name="Reload">
<TextBox Text="" IsTabStop="true" InputScope="Url" PlaceholderText="Type a URL" x:Name="urlTextbox" Grid.Column="1" KeyUp="OnURLEdited" IsSpellCheckEnabled="False" Margin="3,0"/> <Image Source="Assets/UI/reload.png" Height="12"></Image>
<ProgressRing x:Name="urlbarLoadingIndicator" Grid.Column="2" Margin="10,0"/> <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">
<Image Source="Assets/UI/stop.png" Height="12"></Image>
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="Escape" Modifiers="None" />
</Button.KeyboardAccelerators>
</Button>
</StackPanel>
<TextBox Text="" IsTabStop="true" InputScope="Url" PlaceholderText="Type a URL" x:Name="urlTextbox" Grid.Column="1" KeyUp="OnURLEdited" IsSpellCheckEnabled="False" Margin="3,0">
<TextBox.KeyboardAccelerators>
<KeyboardAccelerator Key="L" Modifiers="Control" Invoked="OnURLKeyboardAccelerator"/>
</TextBox.KeyboardAccelerators>
</TextBox>
<ProgressRing x:Name="urlbarLoadingIndicator" Grid.Column="2" Margin="10,0"/>
</Grid>
<local:ServoControl TabIndex="0" x:Name="servoControl" Grid.Row="1"/>
<ProgressBar x:Name="transientLoadingIndicator" Visibility="Collapsed" Grid.Row="2"/>
</Grid> </Grid>
<local:ServoControl TabIndex="0" x:Name="servoControl" Grid.Row="1"/>
<ProgressBar x:Name="transientLoadingIndicator" Visibility="Collapsed" Grid.Row="2"/>
</Grid>
</Page> </Page>