Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When in mutiselect make sure that the treeview list supports selection pattern #210

Merged
merged 3 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions dev/TreeView/InteractionTests/TreeViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,41 @@ private void TreeViewItemUIATest(bool isContentMode = false)
}
}

[TestMethod]
[TestProperty("TreeViewTestSuite", "B")]
public void TreeViewListMultipleSelectionUIATest()
{
using (var setup = new TestSetupHelper("TreeView Tests"))
{
SetContentMode(false);

UIObject ItemRoot = LabelFirstItem();

InputHelper.Tap(ItemRoot);

ClickButton("LabelItems");
ClickButton("ToggleSelectionMode");

Log.Comment("Retrieve first item as generic UIElement");
UIObject Item1 = FindElement.ById("Root.1");
Verify.IsNotNull(Item1, "Verifying that we found a UIElement called Root.1");

Item1.SetFocus();
AutomationElement itemPeer = AutomationElement.FocusedElement;

var selectionItemPeer = (SelectionItemPattern)itemPeer.GetCurrentPattern(SelectionItemPattern.Pattern);
var treeViewListPeer = selectionItemPeer.Current.SelectionContainer;

var multipleSelectionPattern = (SelectionPattern)treeViewListPeer.GetCurrentPattern(SelectionPattern.Pattern);
Verify.IsNotNull(multipleSelectionPattern);
Verify.IsTrue(multipleSelectionPattern.Current.CanSelectMultiple);
Verify.IsFalse(multipleSelectionPattern.Current.IsSelectionRequired);
var elements = multipleSelectionPattern.Current.GetSelection();
Verify.IsNotNull(elements);
Verify.AreEqual(0, elements.Length);
}
}

[TestMethod]
[TestProperty("TreeViewTestSuite", "B")]
[TestProperty("Platform", "Desktop")]
Expand Down
33 changes: 27 additions & 6 deletions dev/TreeView/TreeViewItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,13 @@
</Style>
</Grid.Resources>

<CheckBox x:Name="MultiSelectCheckBox" Width="32" VerticalAlignment="Stretch" Style="{StaticResource TreeViewMultiSelectCheckBox}" Visibility="Collapsed" IsTabStop="False"/>
<CheckBox x:Name="MultiSelectCheckBox"
Width="32"
VerticalAlignment="Stretch"
Style="{StaticResource TreeViewMultiSelectCheckBox}"
Visibility="Collapsed"
IsTabStop="False"
AutomationProperties.AccessibilityView="Raw"/>
ranjeshj marked this conversation as resolved.
Show resolved Hide resolved
<Border x:Name="MultiArrangeOverlayTextBorder"
Opacity="0"
IsHitTestVisible="False"
Expand All @@ -362,11 +368,26 @@
</Border>
</Grid>

<Grid x:Name="ExpandCollapseChevron" Padding="12,0,12,0" Width="Auto" Opacity="{TemplateBinding GlyphOpacity}" Background="Transparent">
<TextBlock Foreground="{TemplateBinding GlyphBrush}" Width="12" Height="12" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.CollapsedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}" Text="{TemplateBinding CollapsedGlyph}" FontFamily="{StaticResource SymbolThemeFontFamily}" VerticalAlignment="Center"/>
<TextBlock Foreground="{TemplateBinding GlyphBrush}" Width="12" Height="12" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.ExpandedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}" Text="{TemplateBinding ExpandedGlyph}" FontFamily="{StaticResource SymbolThemeFontFamily}" VerticalAlignment="Center"/>
<Grid x:Name="ExpandCollapseChevron"
Padding="12,0,12,0"
Width="Auto"
Opacity="{TemplateBinding GlyphOpacity}"
Background="Transparent">
<TextBlock Foreground="{TemplateBinding GlyphBrush}"
Width="12" Height="12"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.CollapsedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}" Text="{TemplateBinding CollapsedGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"/>
<TextBlock Foreground="{TemplateBinding GlyphBrush}"
Width="12" Height="12"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.ExpandedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}"
Text="{TemplateBinding ExpandedGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"/>
</Grid>

<ContentPresenter x:Name="ContentPresenter"
Expand Down
54 changes: 36 additions & 18 deletions dev/TreeView/TreeViewItem_rs1.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,32 +252,50 @@
<StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.Indentation}">

<Grid>
<CheckBox x:Name="MultiSelectCheckBox" Width="32" VerticalAlignment="Stretch" Style="{StaticResource TreeViewMultiSelectCheckBox}" Visibility="Collapsed" IsTabStop="False"/>
<CheckBox x:Name="MultiSelectCheckBox"
Width="32"
VerticalAlignment="Stretch"
Style="{StaticResource TreeViewMultiSelectCheckBox}"
Visibility="Collapsed"
IsTabStop="False"
AutomationProperties.AccessibilityView="Raw" />
<Border x:Name="MultiArrangeOverlayTextBorder"
Opacity="0"
IsHitTestVisible="False"
MinWidth="20"
Height="20"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Background="{ThemeResource SystemControlBackgroundAccentBrush}"
BorderThickness="2"
BorderBrush="{ThemeResource SystemControlBackgroundChromeWhiteBrush}">
<TextBlock x:Name="MultiArrangeOverlayText"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.DragItemsCount}"
Style="{ThemeResource CaptionTextBlockStyle}"
Opacity="0"
IsHitTestVisible="False"
MinWidth="20"
Height="20"
VerticalAlignment="Center"
HorizontalAlignment="Center"
AutomationProperties.AccessibilityView="Raw" />
Background="{ThemeResource SystemControlBackgroundAccentBrush}"
BorderThickness="2"
BorderBrush="{ThemeResource SystemControlBackgroundChromeWhiteBrush}">
<TextBlock x:Name="MultiArrangeOverlayText"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.DragItemsCount}"
Style="{ThemeResource CaptionTextBlockStyle}"
IsHitTestVisible="False"
VerticalAlignment="Center"
HorizontalAlignment="Center"
AutomationProperties.AccessibilityView="Raw" />
</Border>
</Grid>

<Grid x:Name="ExpandCollapseChevron" Padding="12,0,12,0" Width="Auto" Opacity="{TemplateBinding GlyphOpacity}" Background="Transparent">
<TextBlock Foreground="{TemplateBinding GlyphBrush}" Width="12" Height="12" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.CollapsedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}" Text="{TemplateBinding CollapsedGlyph}" FontFamily="{StaticResource SymbolThemeFontFamily}" VerticalAlignment="Center"/>
<TextBlock Foreground="{TemplateBinding GlyphBrush}" Width="12" Height="12" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.ExpandedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}" Text="{TemplateBinding ExpandedGlyph}" FontFamily="{StaticResource SymbolThemeFontFamily}" VerticalAlignment="Center"/>
<TextBlock Foreground="{TemplateBinding GlyphBrush}"
Width="12" Height="12"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.CollapsedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}"
Text="{TemplateBinding CollapsedGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw" />
<TextBlock Foreground="{TemplateBinding GlyphBrush}"
Width="12" Height="12"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TreeViewItemTemplateSettings.ExpandedGlyphVisibility}"
FontSize="{TemplateBinding GlyphSize}"
Text="{TemplateBinding ExpandedGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw" />
</Grid>

<ContentPresenter x:Name="ContentPresenter"
Expand Down
27 changes: 25 additions & 2 deletions dev/TreeView/TreeViewListAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ winrt::com_array<winrt::hstring> TreeViewListAutomationPeer::DropEffects()

winrt::IInspectable TreeViewListAutomationPeer::GetPatternCore(winrt::PatternInterface const& patternInterface)
{
if (patternInterface == winrt::PatternInterface::DropTarget)
if (patternInterface == winrt::PatternInterface::DropTarget ||
(patternInterface == winrt::PatternInterface::Selection && IsMultiselect()))
ranjeshj marked this conversation as resolved.
Show resolved Hide resolved
{
return *this;
}
Expand All @@ -44,4 +45,26 @@ winrt::IInspectable TreeViewListAutomationPeer::GetPatternCore(winrt::PatternInt
winrt::AutomationControlType TreeViewListAutomationPeer::GetAutomationControlTypeCore()
{
return winrt::AutomationControlType::Tree;
}
}

// ISelectionProvider
bool TreeViewListAutomationPeer::CanSelectMultiple()
{
return IsMultiselect()? true: __super::CanSelectMultiple();
ranjeshj marked this conversation as resolved.
Show resolved Hide resolved
}

bool TreeViewListAutomationPeer::IsSelectionRequried()
{
return IsMultiselect()? false : __super::CanSelectMultiple();
}

winrt::com_array<winrt::Windows::UI::Xaml::Automation::Provider::IRawElementProviderSimple> TreeViewListAutomationPeer::GetSelection()
{
// The selected items might be collapsed, virtualized, so getting an accurate list of selected items is not possible.
return {};
}

bool TreeViewListAutomationPeer::IsMultiselect()
{
return winrt::get_self<TreeViewList>(Owner().as<winrt::TreeViewList>())->IsMultiselect();
}
13 changes: 11 additions & 2 deletions dev/TreeView/TreeViewListAutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class TreeViewListAutomationPeer :
public ReferenceTracker<
TreeViewListAutomationPeer,
winrt::implementation::TreeViewListAutomationPeerT,
winrt::IDropTargetProvider>
winrt::IDropTargetProvider,
winrt::ISelectionProvider>
{
public:
TreeViewListAutomationPeer(winrt::TreeViewList const& owner);
Expand All @@ -21,7 +22,15 @@ class TreeViewListAutomationPeer :
// IItemsControlAutomationPeerOverrides2
winrt::ItemAutomationPeer OnCreateItemAutomationPeer(winrt::IInspectable const& item);

//DropTargetProvider methods
// IDropTargetProvider
winrt::hstring DropEffect();
winrt::com_array<winrt::hstring> DropEffects();

// ISelectionProvider
bool CanSelectMultiple();
bool IsSelectionRequried();
winrt::com_array<winrt::Windows::UI::Xaml::Automation::Provider::IRawElementProviderSimple> GetSelection();

private:
bool IsMultiselect();
};