예제 #1
0
 /// <inheritdoc/>
 public bool IsValid(FrameworkElement element, AutomationPeer peer)
 {
     if (peer?.GetAutomationControlType() == AutomationControlType.ScrollBar ||
         peer?.GetAutomationControlType() == AutomationControlType.Tab)
     {
         return(peer?.GetOrientation() != AutomationOrientation.None);
     }
     return(true);
 }
 /// <inheritdoc/>
 public bool IsValid(FrameworkElement element, AutomationPeer peer)
 {
     if (peer != null)
     {
         if (peer.GetAutomationControlType() == AutomationControlType.Text ||
             peer.GetAutomationControlType() == AutomationControlType.Image ||
             peer.IsKeyboardFocusable())
         {
             return(!string.IsNullOrWhiteSpace(peer.GetName()));
         }
     }
     return(true);
 }
예제 #3
0
        public override void GetAutomationControlType()
        {
            TabItem        tabItem = CreateConcreteFrameworkElement() as TabItem;
            AutomationPeer peer    = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem) as AutomationPeer;

            Assert.AreEqual(AutomationControlType.TabItem, peer.GetAutomationControlType(), "#0");
        }
        /// <inheritdoc/>
        public bool IsValid(FrameworkElement element, AutomationPeer peer)
        {
            var type = peer?.GetAutomationControlType();

            // These types are ignored
            if (type == AutomationControlType.AppBar ||
                type == AutomationControlType.Custom ||
                type == AutomationControlType.DataItem ||
                type == AutomationControlType.Group ||
                type == AutomationControlType.Image ||
                type == AutomationControlType.Header ||
                type == AutomationControlType.List ||
                type == AutomationControlType.MenuBar ||
                type == AutomationControlType.Pane ||
                type == AutomationControlType.ScrollBar ||
                type == AutomationControlType.SemanticZoom ||
                type == AutomationControlType.Separator ||
                type == AutomationControlType.StatusBar ||
                type == AutomationControlType.TitleBar ||
                type == AutomationControlType.Thumb ||
                type == AutomationControlType.Text ||
                type == AutomationControlType.ToolBar ||
                type == AutomationControlType.ToolTip ||
                type == AutomationControlType.Window)
            {
                return(true);
            }

            return(!peer.IsEnabled() || peer.IsKeyboardFocusable());
        }
 /// <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);
 }
예제 #6
0
        public void AllTests()
        {
            AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(CreateConcreteFrameworkElement());

            // GetAutomationControlType
            Assert.AreEqual(AutomationControlType.DataItem, peer.GetAutomationControlType(), "GetAutomationControlType");

            // GetClassName
            Assert.AreEqual("DataGridRow", peer.GetClassName(), "GetClassNameCore");
        }
예제 #7
0
        Dictionary <string, string> CollectCommonProperties(FrameworkElement source, EventArgs e)
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties["Name"]      = source.Name;
            properties["ClassName"] = source.GetType().ToString();

            if (previousArgs == null)
            {
                previousArgs = new PreviousArgs()
                {
                    EventArgs = e, Id = (currentId++).ToString("X")
                };
            }
            else
            {
                if (e == null || !Object.ReferenceEquals(previousArgs.EventArgs, e))
                {
                    previousArgs = new PreviousArgs()
                    {
                        EventArgs = e, Id = (currentId++).ToString("X")
                    };
                }
            }
            properties["#e"] = previousArgs.Id;

            AutomationPeer automation = GetAutomationPeer(source);

            if (automation == null)
            {
                return(properties);
            }

            properties["Name"] = string.IsNullOrEmpty(source.Name) ? automation.GetName() : source.Name;

            string itemType = automation.GetItemType();

            if (!string.IsNullOrEmpty(itemType))
            {
                properties["ItemType"] = itemType;
            }

            var automationId = automation.GetAutomationId();

            if (!string.IsNullOrEmpty(automationId))
            {
                properties["AutomationID"] = automationId;
            }

            properties["ControlType"]   = automation.GetAutomationControlType().ToString();
            properties["windowCaption"] = properties["Name"];

            CollectValue(properties, automation);
            return(properties);
        }
        protected override AutomationControlType GetAutomationControlTypeCore()
        {
            AutomationPeer wrapperPeer = GetWrapperPeer();

            if (wrapperPeer != null)
            {
                return(wrapperPeer.GetAutomationControlType());
            }

            return(AutomationControlType.MenuItem);
        }
예제 #9
0
        /// <inheritdoc/>
        public bool IsValid(FrameworkElement element, AutomationPeer peer)
        {
            var type = peer?.GetAutomationControlType();

            if (type == AutomationControlType.Header ||
                type == AutomationControlType.SemanticZoom ||
                type == AutomationControlType.ScrollBar)
            {
                return(!peer.IsKeyboardFocusable());
            }
            return(true);
        }
        /// <inheritdoc/>
        public bool IsValid(FrameworkElement element, AutomationPeer peer)
        {
            var name = peer?.GetName();

            // Null or empty string is not handled by this rule, so it complies.
            if (string.IsNullOrEmpty(name))
            {
                return(true);
            }

            var automationType = peer?.GetAutomationControlType();

            // These control types are hard to name without their type and custom types are hard to justify.
            // Also descriptions that are fairly long are usually descriptive enough.
            if (automationType == AutomationControlType.AppBar ||
                automationType == AutomationControlType.Custom ||
                automationType == AutomationControlType.Header ||
                automationType == AutomationControlType.MenuBar ||
                automationType == AutomationControlType.SemanticZoom ||
                automationType == AutomationControlType.StatusBar ||
                automationType == AutomationControlType.ToolBar ||
                automationType == AutomationControlType.Text ||
                name.Length > 40)
            {
                return(true);
            }

            // Check if control or automation control type is included.
            if (name.Contains(element?.GetType().ToString(), StringComparison.OrdinalIgnoreCase) ||
                name.Contains(peer?.GetAutomationControlType().ToString(), StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Check if the name is the datacontext name.
            return(!name.Equals(element?.DataContext?.GetType().ToString(), StringComparison.OrdinalIgnoreCase));
        }
예제 #11
0
        public void AllTests()
        {
            AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(CreateConcreteFrameworkElement());

            // GetAutomationControlType
            Assert.AreEqual(AutomationControlType.HeaderItem, peer.GetAutomationControlType(), "GetAutomationControlType");

            // ContentTest
            Assert.IsNull(peer.GetChildren(), "#0");

            // GetClassName
            Assert.AreEqual("DataGridRowHeader", peer.GetClassName(), "GetClassNameCore");

            // IsContentElement
            Assert.IsFalse(peer.IsContentElement(), "IsContentElement");
        }
예제 #12
0
        public void AllTests()
        {
            DataGridColumnHeader fe   = CreateConcreteFrameworkElement() as DataGridColumnHeader;
            AutomationPeer       peer = FrameworkElementAutomationPeer.CreatePeerForElement(fe);

            // GetAutomationControlType
            Assert.AreEqual(AutomationControlType.HeaderItem, peer.GetAutomationControlType(), "GetAutomationControlType");

            // GetBoundingRectangle
            Rect boundingRectangle = peer.GetBoundingRectangle();

            Assert.AreNotEqual(0, boundingRectangle.X, "GetBoundingRectangle X");
            Assert.AreNotEqual(0, boundingRectangle.Y, "GetBoundingRectangle Y");
            Assert.AreNotEqual(0, boundingRectangle.Width, "GetBoundingRectangle Width");
            Assert.AreNotEqual(0, boundingRectangle.Height, "GetBoundingRectangle Height");

            // GetChildren
            List <AutomationPeer> children = peer.GetChildren();

            Assert.IsNotNull(children, "#0");
            Assert.AreEqual(1, children.Count, "#1");

            // IsKeyboardFocusable
            Assert.IsFalse(peer.IsKeyboardFocusable(), "IsKeyboardFocusable");

            // GetClassName
            Assert.AreEqual("DataGridColumnHeader", peer.GetClassName(), "#0");

            // IsContentElement
            Assert.IsFalse(peer.IsContentElement(), "#0");

            // GetName
            Assert.AreEqual(fe.Content, peer.GetName(), "GetName");

            // GetClickablePoint
            Point p = peer.GetClickablePoint();

            Assert.IsFalse(double.IsNaN(p.X), "#0");
            Assert.IsFalse(double.IsNaN(p.Y), "#1");

            // GetParent
            Assert.IsNotNull(peer.GetParent(), "GetParent");

            // IsOffscreen
            Assert.IsFalse(peer.IsOffscreen(), "IsOffScreen");
        }
        /// <inheritdoc/>
        public bool IsValid(FrameworkElement element, AutomationPeer peer)
        {
            if (peer?.GetAutomationControlType() != AutomationControlType.ListItem ||
                VisualTreeHelper.GetChildrenCount(element) == 0)
            {
                return(true);
            }

            if (element is ListViewItem)
            {
                var child = VisualTreeHelper.GetChild(element, 0) as FrameworkElement;

                if (child?.DataContext == null)
                {
                    child = VisualTreeHelper.GetChild(child, 0) as FrameworkElement;
                }
                if (child.DataContext == null)
                {
                    return(true);
                }
                return(!peer.GetName().Contains(child?.DataContext?.GetType().ToString(), StringComparison.InvariantCultureIgnoreCase));
            }
            else if (element is GridViewItem)
            {
                var child = VisualTreeHelper.GetChild(element, 0) as FrameworkElement;

                if (child?.DataContext == null)
                {
                    child = VisualTreeHelper.GetChild(child, 0) as FrameworkElement;
                }
                if (child.DataContext == null)
                {
                    return(true);
                }
                return(!peer.GetName().Contains(child?.DataContext?.GetType().ToString(), StringComparison.InvariantCultureIgnoreCase));
            }
            else
            {
                return(true);
            }
        }
예제 #14
0
        public Adapter GetAdapter(AutomationPeer peer, bool create)
        {
            if (peer == null)
            {
                return(null);
            }

            // We ignore all requests until the application is
            // completely loaded.
            if (RootVisualAdapter == null)
            {
                return(null);
            }

            // Do we already have a running Adapter instance for
            // this peer?
            if (activeAdapters.ContainsKey(peer))
            {
                return(activeAdapters [peer]);
            }

            if (!create)
            {
                return(null);
            }

            // Create a list of all potential implementors that
            // will later be merged to have a list of implementors
            // with unique Atk interfaces.
            List <Type> implementors = new List <Type> ();

            List <PatternInterface> implementorBlacklist = new List <PatternInterface> ();

            // Do we have any explict implementors for this type?
            Type explicitImpl;

            if (explicitImplementors.TryGetValue(peer.GetType().ToString(),
                                                 out explicitImpl))
            {
                if (blacklist.ContainsKey(explicitImpl))
                {
                    implementorBlacklist.Add(blacklist [explicitImpl]);
                }
                implementors.Add(explicitImpl);
            }

            // Do we have any implementors for this control type?
            List <Type> controlTypeImpls;

            if (controlTypeImplementors.TryGetValue(peer.GetAutomationControlType(),
                                                    out controlTypeImpls))
            {
                if (controlTypeImpls != null)
                {
                    foreach (Type t in controlTypeImpls)
                    {
                        if (blacklist.ContainsKey(t))
                        {
                            implementorBlacklist.Add(blacklist [t]);
                        }
                    }

                    implementors.AddRange(controlTypeImpls);
                }
            }

            // Find implementors for the patterns that the peer
            // implements
            List <Type> potentialImpls = new List <Type> ();

            potentialImpls.AddRange(
                GetImplementorsForPeer(peer, implementorBlacklist));

            // Create a reverse mapping between Atk interface and
            // implementor to ensure uniqueness.
            //
            // If there are collisions, favor the one with the most
            // Atk interfaces.
            Dictionary <Type, Type> atkInterfaces
                = new Dictionary <Type, Type> ();

            foreach (Type impl in potentialImpls)
            {
                Type [] ifaces = impl.GetInterfaces();

                // If the implementor doesn't implement any Atk
                // interfaces, go ahead and add it to our list
                // of implementors.
                if (ifaces.Length == 0)
                {
                    implementors.Add(impl);
                    continue;
                }

                foreach (Type i in ifaces)
                {
                    if (i.Namespace == "Atk" &&
                        atkInterfaces.ContainsKey(i) &&
                        (ifaces.Length <= atkInterfaces [i].GetInterfaces().Length))
                    {
                        atkInterfaces.Remove(i);
                    }
                    else
                    {
                        atkInterfaces [i] = impl;
                    }
                }
            }

            // Add the distinct implementors
            implementors.AddRange(atkInterfaces.Select(x => x.Value).Distinct());
            implementors.Sort((a, b) => a.Name.CompareTo(b.Name));

            // Concat the type names together
            string typeName = implementors.Aggregate(String.Empty, (s, t) => s + t.Name)
                              + "Adapter";

            // If we're not implementing anything, just
            // short-circuit the process
            Adapter adapter = null;

            if (implementors.Count() == 0)
            {
                adapter = new Adapter(peer);
                activeAdapters.Add(peer, adapter);
                return(adapter);
            }

            // See if we've created the type already
            Type adapterType;

            if (!adapterTypes.TryGetValue(typeName,
                                          out adapterType))
            {
                Assembly asm = Assembly.GetCallingAssembly();
                adapterType = asm.GetType(
                    String.Format("Moonlight.AtkBridge.Adapters.{0}",
                                  typeName),
                    false
                    );

                if (adapterType != null)
                {
                    adapterTypes [typeName] = adapterType;
                }
            }

            if (adapterType == null)
            {
                Log.Warn("Control should have a {0}, but no adapter of that type could be found.", typeName);

                // Fall back to a basic adapter
                adapter = new Adapter(peer);
                activeAdapters.Add(peer, adapter);
                return(adapter);
            }

            Log.Debug("Creating new instance of {0} for {1}",
                      adapterType, peer.GetType());

            adapter = (Adapter)Activator.CreateInstance(
                adapterType, new object [] { peer }
                );

            activeAdapters.Add(peer, adapter);
            return(adapter);
        }
예제 #15
0
        public override void GetAutomationControlType()
        {
            AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(CreateConcreteFrameworkElement());

            Assert.AreEqual(AutomationControlType.Window, peer.GetAutomationControlType(), "GetAutomationControlType");
        }
예제 #16
0
        private static ControlType GetControlType(AutomationPeer itemPeer)
        {
            switch (itemPeer.GetAutomationControlType())
            {
            case AutomationControlType.Button:
                return(ControlType.Button);

            case AutomationControlType.Calendar:
                return(ControlType.Calendar);

            case AutomationControlType.CheckBox:
                return(ControlType.CheckBox);

            case AutomationControlType.ComboBox:
                return(ControlType.ComboBox);

            case AutomationControlType.Edit:
                return(ControlType.Edit);

            case AutomationControlType.Hyperlink:
                return(ControlType.Hyperlink);

            case AutomationControlType.Image:
                return(ControlType.Image);

            case AutomationControlType.ListItem:
                return(ControlType.ListItem);

            case AutomationControlType.List:
                return(ControlType.List);

            case AutomationControlType.Menu:
                return(ControlType.Menu);

            case AutomationControlType.MenuBar:
                return(ControlType.MenuBar);

            case AutomationControlType.MenuItem:
                return(ControlType.MenuItem);

            case AutomationControlType.ProgressBar:
                return(ControlType.ProgressBar);

            case AutomationControlType.RadioButton:
                return(ControlType.RadioButton);

            case AutomationControlType.ScrollBar:
                return(ControlType.ScrollBar);

            case AutomationControlType.Slider:
                return(ControlType.Slider);

            case AutomationControlType.Spinner:
                return(ControlType.Spinner);

            case AutomationControlType.StatusBar:
                return(ControlType.StatusBar);

            case AutomationControlType.Tab:
                return(ControlType.Tab);

            case AutomationControlType.TabItem:
                return(ControlType.TabItem);

            case AutomationControlType.Text:
                return(ControlType.Text);

            case AutomationControlType.ToolBar:
                return(ControlType.ToolBar);

            case AutomationControlType.ToolTip:
                return(ControlType.ToolTip);

            case AutomationControlType.Tree:
                return(ControlType.Tree);

            case AutomationControlType.TreeItem:
                return(ControlType.TreeItem);

            case AutomationControlType.Custom:
                return(ControlType.Custom);

            case AutomationControlType.Group:
                return(ControlType.Group);

            case AutomationControlType.Thumb:
                return(ControlType.Thumb);

            case AutomationControlType.DataGrid:
                return(ControlType.DataGrid);

            case AutomationControlType.DataItem:
                return(ControlType.DataItem);

            case AutomationControlType.Document:
                return(ControlType.Document);

            case AutomationControlType.SplitButton:
                return(ControlType.SplitButton);

            case AutomationControlType.Window:
                return(ControlType.Window);

            case AutomationControlType.Pane:
                return(ControlType.Pane);

            case AutomationControlType.Header:
                return(ControlType.Header);

            case AutomationControlType.HeaderItem:
                return(ControlType.HeaderItem);

            case AutomationControlType.Table:
                return(ControlType.Table);

            case AutomationControlType.TitleBar:
                return(ControlType.TitleBar);

            case AutomationControlType.Separator:
                return(ControlType.Separator);
            }

            return(null);
        }