/// <inheritdoc/>
 public bool IsValid(FrameworkElement element, AutomationPeer peer)
 {
     if (peer?.GetAutomationControlType() == AutomationControlType.Button)
     {
         return(peer.GetPattern(PatternInterface.Invoke) != null ||
                peer.GetPattern(PatternInterface.Toggle) != null);
     }
     return(true);
 }
コード例 #2
0
        private void UpdateDOMEventHandlers(bool activate)
        {
            if (_activated != activate)
            {
                _activated = activate;
                if (activate)
                {
                    IScrollProvider scrollProvider = null;

                    AutomationPeer automationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(AssociatedObject);
                    if (automationPeer != null)
                    {
                        scrollProvider = (IScrollProvider)automationPeer.GetPattern(PatternInterface.Scroll);
                    }

                    if (scrollProvider == null)
                    {
                        ScrollViewer scrollViewer = GetChildScrollViewer(AssociatedObject);
                        if (scrollViewer != null)
                        {
                            automationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(scrollViewer);
                            if (automationPeer != null)
                            {
                                scrollProvider = (IScrollProvider)automationPeer.GetPattern(PatternInterface.Scroll);
                            }
                        }
                    }

                    if ((scrollProvider != null) && scrollProvider.VerticallyScrollable)
                    {
                        _scrollProvider = scrollProvider;

                        HtmlPage.Document.AttachEvent("DOMMouseScroll", OnBrowserDOMMouseScroll);
                        HtmlPage.Document.AttachEvent("onmousewheel", OnBrowserMouseWheel);
                    }
                }
                else
                {
                    if (_scrollProvider != null)
                    {
                        _scrollProvider = null;

                        HtmlPage.Document.DetachEvent("DOMMouseScroll", OnBrowserDOMMouseScroll);
                        HtmlPage.Document.DetachEvent("onmousewheel", OnBrowserMouseWheel);
                    }
                }
            }
        }
コード例 #3
0
        public override object GetPattern(PatternInterface patternInterface)
        {
            object peer = base.GetPattern(patternInterface);

            RibbonTab wrapperTab = GetWrapper() as RibbonTab;

            if (patternInterface == PatternInterface.ExpandCollapse &&
                wrapperTab != null &&
                wrapperTab.Ribbon != null &&
                wrapperTab.Ribbon.IsMinimized)
            {
                peer = this;
            }

            if (patternInterface == PatternInterface.ScrollItem)
            {
                peer = this;
            }

            if (peer == null)
            {
                AutomationPeer wrapperPeer = GetWrapperPeer();
                if (wrapperPeer != null)
                {
                    peer = wrapperPeer.GetPattern(patternInterface);
                }
            }
            return(peer);
        }
コード例 #4
0
        /// <summary>
        ///     Gets the control pattern for the AutoCompleteBox that is associated
        ///     with this AutoCompleteBoxAutomationPeer.
        /// </summary>
        /// <param name="patternInterface">The desired PatternInterface.</param>
        /// <returns>The desired AutomationPeer or null.</returns>
        public override object GetPattern(PatternInterface patternInterface)
        {
            object          iface = null;
            AutoCompleteBox owner = OwnerAutoCompleteBox;

            if (patternInterface == PatternInterface.Value)
            {
                iface = this;
            }
            else if (patternInterface == PatternInterface.ExpandCollapse)
            {
                iface = this;
            }
            else if (owner.SelectionAdapter != null)
            {
                AutomationPeer peer = owner.SelectionAdapter.CreateAutomationPeer();
                if (peer != null)
                {
                    iface = peer.GetPattern(patternInterface);
                }
            }

            if (iface == null)
            {
                iface = base.GetPattern(patternInterface);
            }

            return(iface);
        }
コード例 #5
0
        public void SelectionItemProvider_AddToSelection()
        {
            RadioButton radioButton = CreateConcreteFrameworkElement() as RadioButton;

            StackPanel stackPanel = new StackPanel();

            stackPanel.Children.Add(radioButton);
            TestPanel.Children.Add(stackPanel);

            Enqueue(() => {
                AutomationPeer peer
                    = FrameworkElementAutomationPeer.CreatePeerForElement(radioButton);

                ISelectionItemProvider selectionItem
                    = peer.GetPattern(PatternInterface.SelectionItem)
                      as ISelectionItemProvider;
                Assert.IsNotNull(selectionItem);

                radioButton.IsEnabled = false;
                try {
                    selectionItem.AddToSelection();
                    Assert.Fail("InvalidOperationException not raised when disabled");
                } catch (InvalidOperationException) { }

                radioButton.IsEnabled = true;
                try {
                    selectionItem.AddToSelection();
                    Assert.Fail("InvalidOperationException not raised when enabled");
                } catch (InvalidOperationException) { }
            });
            EnqueueTestComplete();
        }
コード例 #6
0
        private void InvokeScrollBar(int mouseDelta)
        {
            if (!Focused || mouseDelta == 0)
            {
                return;
            }

            short        mouseNum     = (short)(mouseDelta / 120);
            ScrollAmount scrollAmount = ScrollAmount.NoAmount;

            if (mouseNum < 0)
            {
                //向下滑动
                if (mouseNum >= -2)
                {
                    scrollAmount = ScrollAmount.SmallIncrement;
                }
                else
                {
                    scrollAmount = ScrollAmount.LargeIncrement;
                }
            }
            else if (mouseNum > 0)
            {
                //向上滑动
                if (mouseNum <= 2)
                {
                    scrollAmount = ScrollAmount.SmallDecrement;
                }
                else
                {
                    scrollAmount = ScrollAmount.LargeDecrement;
                }
            }

            if (scrollAmount == ScrollAmount.NoAmount)
            {
                return;
            }

            //修复滚轮滚动Bug

            //取得AutomationPeer
            AutomationPeer automationPeer = FrameworkElementAutomationPeer.FromElement(this);

            if (automationPeer == null)
            {
                automationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(this);
            }
            //得到scroll provider
            IScrollProvider scrollProvider = automationPeer.GetPattern(PatternInterface.Scroll) as IScrollProvider;

            if (scrollProvider != null)
            {
                if (scrollProvider.VerticallyScrollable)
                {
                    scrollProvider.Scroll(ScrollAmount.NoAmount, scrollAmount);
                }
            }
        }
コード例 #7
0
        void itemscontrol_Loaded(object sender, RoutedEventArgs e)
        {
            AutomationPeer             ap   = FrameworkElementAutomationPeer.CreatePeerForElement(this.AssociatedObject as UIElement);
            ScrollViewerAutomationPeer avap = (ScrollViewerAutomationPeer)ap.GetPattern(PatternInterface.Scroll);

            _scrollViewer = (ScrollViewer)avap.Owner;

            SetBinding(
                DataContextProperty,
                new Binding
            {
                Path   = new PropertyPath("DataContext"),
                Source = AssociatedObject,
                Mode   = BindingMode.TwoWay
            });

            _dt.Tick += (_, __) =>
            {
                _scrollViewer.ChangeView(_scrollViewer.HorizontalOffset + HorizontalSpeed,
                                         _scrollViewer.VerticalOffset + VerticalSpeed,
                                         null,
                                         true);
                _scrollViewer.UpdateLayout();
            };
        }
コード例 #8
0
        public void TestHasKeyboardFocusAfterPattern()
        {
            StackPanel panel = new StackPanel();
            ComboBox   fe    = CreateConcreteFrameworkElement() as ComboBox;

            fe.Items.Add("Item 0");
            fe.Items.Add("Item 1");

            Button button = new Button()
            {
                Content = "Button"
            };

            panel.Children.Add(fe);
            panel.Children.Add(button);

            AutomationPeer          buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(button);
            AutomationPeer          peer       = FrameworkElementAutomationPeer.CreatePeerForElement(fe);
            IExpandCollapseProvider provider   = null;

            CreateAsyncTest(panel,
                            () => {
                provider = (IExpandCollapseProvider)peer.GetPattern(PatternInterface.ExpandCollapse);
                Assert.IsNotNull(provider, "#1");
            },
                            () => provider.Expand(),
                            () => Assert.IsTrue(peer.HasKeyboardFocus(), "#2"),
                            () => button.Focus(),
                            () => Assert.IsTrue(buttonPeer.HasKeyboardFocus(), "#3"),
                            () => provider.Collapse(),
                            () => Assert.IsTrue(peer.HasKeyboardFocus(), "#4")
                            );
        }
コード例 #9
0
        public void InvokeProvider_Events()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            TestPanel.Children.Clear();
            datagrid = CreateDataGrid();
            IInvokeProvider      provider = null;
            AutomationEventTuple tuple    = null;
            AutomationPeer       peer     = null;

            CreateAsyncTest(datagrid,
                            () => {
                peer     = GetDataGridColumnHeader(datagrid);
                provider = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke);
                Assert.IsNotNull(provider, "GetPattern #0");
                EventsManager.Instance.Reset();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.InvokePatternOnInvoked);
                Assert.IsNull(tuple, "GetAutomationEventFrom #0");
                provider.Invoke();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.InvokePatternOnInvoked);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #1");
            });
        }
コード例 #10
0
        public override object GetPattern(PatternInterface patternInterface)
        {
            // In .net4 ItemAutomationPeer implements VirtualizedItemPattern, then we would need to call base.GetPattern here.
            object peer = null;

            if (patternInterface == PatternInterface.ScrollItem)
            {
                peer = this;
            }
            else if (patternInterface == PatternInterface.ExpandCollapse)
            {
                // only if RibbonGroup is Collapsed this Pattern applies.
                RibbonGroup wrapperGroup = GetWrapper() as RibbonGroup;
                if (wrapperGroup != null && wrapperGroup.IsCollapsed)
                {
                    peer = this;
                }
            }

            if (peer == null)
            {
                AutomationPeer wrapperPeer = GetWrapperPeer();
                if (wrapperPeer != null)
                {
                    peer = wrapperPeer.GetPattern(patternInterface);
                }
            }
            return(peer);
        }
コード例 #11
0
        public override object GetPattern(PatternInterface patternInterface)
        {
            object           result = null;
            FrameworkElement owner  = GetWrapper();

            if (owner != null)
            {
                RibbonMenuItem menuItemOwner = owner as RibbonMenuItem;
                if (menuItemOwner == null)
                {
                    AutomationPeer wrapperPeer = GetWrapperPeer();
                    if (wrapperPeer != null)
                    {
                        result = wrapperPeer.GetPattern(patternInterface);
                    }
                }
                else
                {
                    MenuItemRole role = menuItemOwner.Role;
                    if (patternInterface == PatternInterface.ExpandCollapse)
                    {
                        if ((role == MenuItemRole.TopLevelHeader || role == MenuItemRole.SubmenuHeader) &&
                            menuItemOwner.HasItems)
                        {
                            result = this;
                        }
                    }
                    else if (patternInterface == PatternInterface.Toggle)
                    {
                        result = this;
                    }
                    else if (patternInterface == PatternInterface.Invoke)
                    {
                        if ((role == MenuItemRole.TopLevelItem || role == MenuItemRole.SubmenuItem) &&
                            !menuItemOwner.HasItems)
                        {
                            result = this;
                        }
                    }
                    else if (patternInterface == PatternInterface.Transform)
                    {
                        if (menuItemOwner.IsSubmenuOpen && (menuItemOwner.CanUserResizeHorizontally || menuItemOwner.CanUserResizeVertically))
                        {
                            result = this;
                        }
                    }
                    else
                    {
                        AutomationPeer wrapperPeer = GetWrapperPeer();
                        if (wrapperPeer != null)
                        {
                            result = wrapperPeer.GetPattern(patternInterface);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #12
0
 /// <inheritdoc/>
 public bool IsValid(FrameworkElement element, AutomationPeer peer)
 {
     if (peer?.GetPattern(PatternInterface.Selection) is ISelectionProvider provider)
     {
         if (provider.IsSelectionRequired)
         {
             return(provider.GetSelection().Length > 0);
         }
     }
     return(true);
 }
コード例 #13
0
        public void IGridProvider_Methods()
        {
            Calendar                  calendar     = CreateConcreteFrameworkElement() as Calendar;
            AutomationPeer            peer         = FrameworkElementAutomationPeer.CreatePeerForElement(calendar);
            IGridProvider             gridProvider = null;
            IRawElementProviderSimple cell         = null;
            AutomationPeer            cellPeer     = null;

            CreateAsyncTest(calendar,
                            () => {
                Assert.IsNotNull(peer, "#0");
                gridProvider = peer.GetPattern(PatternInterface.Grid) as IGridProvider;
                Assert.IsNotNull(gridProvider, "#1");

                // IGridProvider.RowCount
                calendar.DisplayMode = CalendarMode.Month;
                Assert.AreEqual(6, gridProvider.RowCount, "RowCount #0");                  // First row displays day titles
                calendar.DisplayMode = CalendarMode.Decade;
                Assert.AreEqual(3, gridProvider.RowCount, "RowCount #1");
                calendar.DisplayMode = CalendarMode.Year;
                Assert.AreEqual(3, gridProvider.RowCount, "RowCount #2");
                // IGridProvider.ColumnCount
                calendar.DisplayMode = CalendarMode.Month;
                Assert.AreEqual(7, gridProvider.ColumnCount, "ColumnCount #0");
                calendar.DisplayMode = CalendarMode.Decade;
                Assert.AreEqual(4, gridProvider.ColumnCount, "ColumnCount #1");
                calendar.DisplayMode = CalendarMode.Year;
                Assert.AreEqual(4, gridProvider.ColumnCount, "ColumnCount #2");
                // IGridProvider.GetItem
                calendar.DisplayMode = CalendarMode.Month;

                cell = gridProvider.GetItem(0, 3);
                Assert.IsNotNull(cell, "GetItem #0");
                cellPeer = new PeerFromProvider().GetPeerFromProvider(cell);
                Assert.AreEqual(typeof(CalendarDayButton).Name, cellPeer.GetClassName(), "GetItem.ClassName #0");

                calendar.DisplayMode = CalendarMode.Year;

                cell = gridProvider.GetItem(2, 3);
                Assert.IsNotNull(cell, "GetItem #1");
                cellPeer = new PeerFromProvider().GetPeerFromProvider(cell);
                Assert.AreEqual(typeof(CalendarButton).Name, cellPeer.GetClassName(), "GetItem.ClassName #1");

                calendar.DisplayMode = CalendarMode.Decade;

                cell = gridProvider.GetItem(2, 3);
                Assert.IsNotNull(cell, "GetItem #2");
                cellPeer = new PeerFromProvider().GetPeerFromProvider(cell);
                Assert.AreEqual(typeof(CalendarButton).Name, cellPeer.GetClassName(), "GetItem.ClassName #2");

                cell = gridProvider.GetItem(10, 10);
                Assert.IsNull(cell, "GetItem #3");
            });
        }