XAML key bindings

This commit is contained in:
Paul Rouget 2019-11-04 12:19:12 +01:00
parent 7fb12fcc43
commit 749f2217f9
3 changed files with 33 additions and 1 deletions

View file

@ -7,6 +7,7 @@
#include "BrowserPage.h"
#include "BrowserPage.g.cpp"
using namespace std::placeholders;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core;
@ -50,6 +51,17 @@ void BrowserPage::BindServoEvents() {
});
servoControl().OnCaptureGesturesEnded(
[=] { 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) {

View file

@ -26,6 +26,10 @@ public:
Windows::UI::Xaml::RoutedEventArgs const &);
void OnURLEdited(Windows::Foundation::IInspectable 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 LoadServoURI(Windows::Foundation::Uri uri);
void SetTransientMode(bool);

View file

@ -94,18 +94,34 @@
<StackPanel Orientation="Horizontal" Grid.Column="0">
<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>
<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">
<Image Source="Assets/UI/forward.png" Height="12"></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">
<Image Source="Assets/UI/reload.png" Height="12"></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">
<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 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"/>