Skip to content

Commit

Permalink
TabView: Fixed ctrl-click to deselect and tab min/max width. (#1393)
Browse files Browse the repository at this point in the history
* TabView: Fixed ctrl-click to deselect and tab min/max width.

* CR updates

* Added to test.
  • Loading branch information
teaP authored and msft-github-bot committed Oct 3, 2019
1 parent 44575e6 commit 0053f1e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
27 changes: 27 additions & 0 deletions dev/TabView/InteractionTests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Microsoft.Windows.Apps.Test.Foundation.Patterns;
using Microsoft.Windows.Apps.Test.Foundation.Waiters;
using Windows.UI.Xaml.Media;
using Windows.Devices.Input;

namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests
{
Expand Down Expand Up @@ -71,6 +72,21 @@ public void SelectionTest()
Button selectIndexButton = FindElement.ByName<Button>("SelectIndexButton");
selectIndexButton.InvokeAndWait();
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "2");

Log.Comment("Verify that ctrl-click on tab selects it.");
UIObject firstTab = FindElement.ByName("FirstTab");
KeyboardHelper.PressDownModifierKey(ModifierKey.Control);
firstTab.Click();
KeyboardHelper.ReleaseModifierKey(ModifierKey.Control);
Wait.ForIdle();
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "0");

Log.Comment("Verify that ctrl-click on tab does not deselect.");
KeyboardHelper.PressDownModifierKey(ModifierKey.Control);
firstTab.Click();
KeyboardHelper.ReleaseModifierKey(ModifierKey.Control);
Wait.ForIdle();
Verify.AreEqual(selectedIndexTextBlock.DocumentText, "0");
}
}

Expand Down Expand Up @@ -121,6 +137,17 @@ public void TabSizeAndScrollButtonsTest()
Log.Comment("Tab with larger content should be wider.");
Verify.IsGreaterThan(largerTab.BoundingRectangle.Width, smallerTab.BoundingRectangle.Width);

Log.Comment("Changing tab header to short/long.");
Button shortLongButton = FindElement.ByName<Button>("ShortLongTextButton");
shortLongButton.InvokeAndWait();
ElementCache.Refresh();

diff = Math.Abs(smallerTab.BoundingRectangle.Width - 100);
Verify.IsLessThanOrEqual(diff, 1, "Smaller text should have min width of 100");

diff = Math.Abs(largerTab.BoundingRectangle.Width - 240);
Verify.IsLessThanOrEqual(diff, 1, "Smaller text should have max width of 240");

// With largerTab now rendering wider, the scroll buttons should appear:
Verify.IsTrue(AreScrollButtonsVisible(), "Scroll buttons should appear");

Expand Down
9 changes: 5 additions & 4 deletions dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ void TabView::UpdateTabWidths()
{
double tabWidth = std::numeric_limits<double>::quiet_NaN();

double minTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMinWidthName, winrt::Application::Current().Resources(), box_value(c_tabMinimumWidth)));
double maxTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMaxWidthName, winrt::Application::Current().Resources(), box_value(c_tabMaximumWidth)));

if (auto tabGrid = m_tabContainerGrid.get())
{
// Add up width taken by custom content and + button
Expand Down Expand Up @@ -555,10 +558,6 @@ void TabView::UpdateTabWidths()
}
else if (TabWidthMode() == winrt::TabViewWidthMode::Equal)
{
// Tabs should all be the same size, proportional to the amount of space.
double minTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMinWidthName, winrt::Application::Current().Resources(), box_value(c_tabMinimumWidth)));
double maxTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMaxWidthName, winrt::Application::Current().Resources(), box_value(c_tabMaximumWidth)));

// Calculate the proportional width of each tab given the width of the ScrollViewer.
auto padding = Padding();
double tabWidthForScroller = (availableWidth - (padding.Left + padding.Right)) / (double)(TabItems().Size());
Expand Down Expand Up @@ -601,6 +600,8 @@ void TabView::UpdateTabWidths()
if (tvi)
{
tvi.Width(tabWidth);
tvi.MaxWidth(maxTabWidth);
tvi.MinWidth(minTabWidth);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions dev/TabView/TabViewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ void TabViewItem::OnHeaderPropertyChanged(const winrt::DependencyPropertyChanged

void TabViewItem::OnPointerPressed(winrt::PointerRoutedEventArgs const& args)
{
if (IsSelected() && args.Pointer().PointerDeviceType() == winrt::PointerDeviceType::Mouse)
{
auto pointerPoint = args.GetCurrentPoint(*this);
if (pointerPoint.Properties().IsLeftButtonPressed())
{
auto isCtrlDown = (winrt::Window::Current().CoreWindow().GetKeyState(winrt::VirtualKey::Control) & winrt::CoreVirtualKeyStates::Down) == winrt::CoreVirtualKeyStates::Down;
if (isCtrlDown)
{
// Return here so the base class will not pick it up, but let it remain unhandled so someone else could handle it.
return;
}
}
}

__super::OnPointerPressed(args);

if (args.GetCurrentPoint(nullptr).Properties().PointerUpdateKind() == winrt::PointerUpdateKind::MiddleButtonPressed)
Expand Down
4 changes: 3 additions & 1 deletion dev/TabView/TestUI/TabViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<Button x:Name="CustomTooltipButton" AutomationProperties.Name="CustomTooltipButton" Content="Custom Tooltip" Margin="0,0,0,8" Click="CustomTooltipButton_Click"/>
<Button x:Name="SetTabViewWidth" AutomationProperties.Name="SetTabViewWidth" Content="Set Width" Margin="0,0,0,8" Click="SetTabViewWidth_Click" />

<Button x:Name="ShortLongTextButton" AutomationProperties.Name="ShortLongTextButton" Content="Short/Long Text" Margin="0,0,0,8" Click="ShortLongTextButton_Click" />

<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
<TextBlock Text="Scroll buttons visible: " />
<TextBlock x:Name="ScrollButtonsVisible" AutomationProperties.Name="ScrollButtonsVisible" Text="False" />
Expand Down Expand Up @@ -109,7 +111,7 @@

<StackPanel x:Name="FirstTabContent" AutomationProperties.Name="FirstTabContent">
<Button x:Name="FirstTabButton" AutomationProperties.Name="FirstTabButton" Margin="8" FontSize="20">Home Button</Button>
<Button x:Name="TabViewSizingPageButtton" AutomationProperties.Name="TabViewSizingPageButtton" Margin="8" FontSize="20" Click="TabViewSizingPageButtton_Click" >TabView Sizing Page</Button>
<Button x:Name="TabViewSizingPageButton" AutomationProperties.Name="TabViewSizingPageButton" Margin="8" Click="TabViewSizingPageButton_Click" FontSize="20">TabView Sizing Page</Button>
</StackPanel>
</controls:TabViewItem>

Expand Down
8 changes: 7 additions & 1 deletion dev/TabView/TestUI/TabViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,15 @@ public void GetScrollButtonsVisible_Click(object sender, RoutedEventArgs e)
}
}

private void TabViewSizingPageButtton_Click(object sender, RoutedEventArgs e)
private void TabViewSizingPageButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(TabViewSizingPage));
}

private void ShortLongTextButton_Click(object sender, RoutedEventArgs e)
{
FirstTab.Header = "s";
LongHeaderTab.Header = "long long long long long long long long";
}
}
}

0 comments on commit 0053f1e

Please sign in to comment.