public void ComboBoxItemAccessibleObject_Bounds_ReturnsCorrect_ForDifferentHeightItems(ComboBoxStyle comboBoxStyle, int itemIndex, Rectangle expectedRect) { using DifferentHeightComboBox comboBox = new DifferentHeightComboBox(); comboBox.DropDownStyle = comboBoxStyle; comboBox.Items.AddRange(new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }); comboBox.CreateControl(); if (comboBoxStyle == ComboBoxStyle.Simple) { comboBox.Size = new Size(100, 400); } else { comboBox.Size = new Size(100, comboBox.Size.Height); comboBox.DropDownHeight = 400; comboBox.DroppedDown = true; } ComboBoxAccessibleObject comboBoxAccessibleObject = (ComboBoxAccessibleObject)comboBox.AccessibilityObject; ComboBoxItemAccessibleObjectCollection itemsCollection = comboBoxAccessibleObject.ItemAccessibleObjects; Entry itemEntry = comboBox.Items.InnerList[itemIndex]; ComboBoxItemAccessibleObject itemAccessibleObject = itemsCollection.GetComboBoxItemAccessibleObject(itemEntry); Rectangle actual = itemAccessibleObject.Bounds; Rectangle dropdownRect = comboBox.ChildListAccessibleObject.Bounds; Assert.Equal(expectedRect, actual); }
public void ComboBoxItemAccessibleObject_Bounds_ReturnsCorrect_IfComboBoxIsScrollable(ComboBoxStyle comboBoxStyle, int itemIndex, Point expectedPosition) { using ComboBox comboBox = new ComboBox(); comboBox.IntegralHeight = false; comboBox.DropDownStyle = comboBoxStyle; comboBox.Items.AddRange(new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }); comboBox.CreateControl(); if (comboBoxStyle == ComboBoxStyle.Simple) { comboBox.Size = new Size(100, 132); } else { comboBox.Size = new Size(100, comboBox.Size.Height); comboBox.DropDownHeight = 105; comboBox.DroppedDown = true; } ComboBoxAccessibleObject comboBoxAccessibleObject = (ComboBoxAccessibleObject)comboBox.AccessibilityObject; ComboBoxItemAccessibleObjectCollection itemsCollection = comboBoxAccessibleObject.ItemAccessibleObjects; Entry itemEntry = comboBox.Items.InnerList[itemIndex]; ComboBoxItemAccessibleObject itemAccessibleObject = itemsCollection.GetComboBoxItemAccessibleObject(itemEntry); Rectangle actual = itemAccessibleObject.Bounds; Rectangle dropdownRect = comboBox.ChildListAccessibleObject.Bounds; // We get items rectangles from Windows // It returns to us different expected widths values depending on a combobox drop-down style int itemWidth = comboBoxStyle == ComboBoxStyle.Simple ? 79 : 81; Assert.Equal(expectedPosition.X, actual.X); Assert.Equal(expectedPosition.Y, actual.Y); Assert.Equal(itemWidth, actual.Width); // All items are the same width Assert.Equal(15, actual.Height); // All items are the same height }
public void ComboBoxItemAccessibleObject_ScrollIntoView_DoNothing_IfControlIsNotEnabled(ComboBoxStyle comboBoxStyle) { using ComboBox comboBox = new ComboBox(); comboBox.IntegralHeight = false; comboBox.DropDownStyle = comboBoxStyle; comboBox.Enabled = false; comboBox.Items.AddRange(new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }); comboBox.CreateControl(); if (comboBoxStyle == ComboBoxStyle.Simple) { comboBox.Size = new Size(100, 132); } else { comboBox.DropDownHeight = 107; comboBox.DroppedDown = true; } ComboBoxAccessibleObject comboBoxAccessibleObject = (ComboBoxAccessibleObject)comboBox.AccessibilityObject; ComboBoxItemAccessibleObjectCollection itemsCollection = comboBoxAccessibleObject.ItemAccessibleObjects; Entry itemEntry = comboBox.Items.InnerList[10]; ComboBoxItemAccessibleObject itemAccessibleObject = itemsCollection.GetComboBoxItemAccessibleObject(itemEntry); itemAccessibleObject.ScrollIntoView(); int actual = unchecked ((int)(long)User32.SendMessageW(comboBox, (User32.WM)User32.CB.GETTOPINDEX)); Assert.Equal(0, actual); // ScrollIntoView didn't scroll to the tested item because the combobox is disabled }
public ObjectCollection(ComboBox owner) { _owner = owner; if (_owner.AccessibilityObject is null) { throw new ArgumentException(nameof(owner)); } _ownerComboBoxAccessibleObject = (ComboBoxAccessibleObject)_owner.AccessibilityObject; }
public void ComboBoxItemAccessibleObject_GetPropertyValue_ScrollItemPattern_IsAvailable() { using ComboBox comboBox = new ComboBox(); comboBox.Items.AddRange(new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }); comboBox.CreateControl(); ComboBoxAccessibleObject comboBoxAccessibleObject = (ComboBoxAccessibleObject)comboBox.AccessibilityObject; ComboBoxItemAccessibleObjectCollection itemsCollection = comboBoxAccessibleObject.ItemAccessibleObjects; // Check that all items support ScrollItemPattern foreach (Entry itemEntry in comboBox.Items.InnerList) { ComboBoxItemAccessibleObject itemAccessibleObject = itemsCollection.GetComboBoxItemAccessibleObject(itemEntry); Assert.True((bool)itemAccessibleObject.GetPropertyValue(UiaCore.UIA.IsScrollItemPatternAvailablePropertyId)); } }
public void ComboBoxItemAccessibleObject_IsPatternSupported_ReturnsTrue_ForScrollItemPattern() { using ComboBox comboBox = new ComboBox(); comboBox.Items.AddRange(new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }); comboBox.CreateControl(); ComboBoxAccessibleObject comboBoxAccessibleObject = (ComboBoxAccessibleObject)comboBox.AccessibilityObject; ComboBoxItemAccessibleObjectCollection itemsCollection = comboBoxAccessibleObject.ItemAccessibleObjects; // Check that all items support ScrollItemPattern foreach (Entry itemEntry in comboBox.Items.InnerList) { ComboBoxItemAccessibleObject itemAccessibleObject = itemsCollection.GetComboBoxItemAccessibleObject(itemEntry); Assert.True(itemAccessibleObject.IsPatternSupported(UiaCore.UIA.ScrollItemPatternId)); } }
public void ComboBoxItemAccessibleObject_ScrollIntoView_EnsureVisible(ComboBoxStyle comboBoxStyle, bool scrollingDown, int itemIndex, int itemsCount) { using ComboBox comboBox = new ComboBox(); comboBox.IntegralHeight = false; comboBox.DropDownStyle = comboBoxStyle; comboBox.CreateControl(); for (int i = 0; i < itemsCount; i++) { comboBox.Items.Add(i); } if (comboBoxStyle == ComboBoxStyle.Simple) { comboBox.Size = new Size(100, 132); } else { comboBox.DropDownHeight = 107; comboBox.DroppedDown = true; } ComboBoxAccessibleObject comboBoxAccessibleObject = (ComboBoxAccessibleObject)comboBox.AccessibilityObject; ComboBoxItemAccessibleObjectCollection itemsCollection = comboBoxAccessibleObject.ItemAccessibleObjects; Entry itemEntry = comboBox.Items.InnerList[itemIndex]; ComboBoxItemAccessibleObject itemAccessibleObject = itemsCollection.GetComboBoxItemAccessibleObject(itemEntry); int expected; Rectangle dropDownRect = comboBox.ChildListAccessibleObject.Bounds; int visibleItemsCount = (int)Math.Ceiling((double)dropDownRect.Height / comboBox.ItemHeight); // Get an index of the first item that is visible if dropdown is scrolled to the bottom int lastFirstVisible = itemsCount - visibleItemsCount; if (scrollingDown) { if (dropDownRect.IntersectsWith(itemAccessibleObject.Bounds)) { // ScrollIntoView method shouldn't scroll to the item because it is already visible expected = 0; } else { // ScrollIntoView method should scroll to the item or // the first item that is visible if dropdown is scrolled to the bottom expected = itemIndex > lastFirstVisible ? lastFirstVisible : itemIndex; } } else { // Scroll to the bottom and test the method when scrolling up User32.SendMessageW(comboBox, (User32.WM)User32.CB.SETTOPINDEX, (IntPtr)(itemsCount - 1)); if (dropDownRect.IntersectsWith(itemAccessibleObject.Bounds)) { // ScrollIntoView method shouldn't scroll to the item because it is already visible expected = lastFirstVisible; } else { // ScrollIntoView method should scroll to the item expected = itemIndex; } } itemAccessibleObject.ScrollIntoView(); int actual = unchecked ((int)(long)User32.SendMessageW(comboBox, (User32.WM)User32.CB.GETTOPINDEX)); Assert.Equal(expected, actual); }