예제 #1
0
        private void RaiseVisibilityEvents(bool isOffscreen)
        {
            IAutomationCacheProperty cachedProperty
                = GetCachedProperty(AutomationElementIdentifiers.BoundingRectangleProperty);
            Rect newValue = GetBoundingRectangle();

            RaisePropertyChangedEvent(AutomationElementIdentifiers.BoundingRectangleProperty,
                                      cachedProperty.OldValue,
                                      newValue);

            RaisePropertyChangedEvent(AutomationElementIdentifiers.IsOffscreenProperty,
                                      !isOffscreen,
                                      isOffscreen);
        }
예제 #2
0
        // Raises UIA Event (NameProperty) and internal event (NameChanged)
        // NOTE: This method MUST BE called by AutomationPeers overriding GetNameCore().
        internal override void RaiseNameChanged()
        {
            IAutomationCacheProperty cachedProperty
                = GetCachedProperty(AutomationElementIdentifiers.NameProperty);
            string newValue = GetName();

            if (!object.Equals(newValue, cachedProperty.OldValue))
            {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.NameProperty,
                                          cachedProperty.OldValue,
                                          newValue);
                if (NameChanged != null)
                {
                    NameChanged(this, EventArgs.Empty);
                }
            }
        }
예제 #3
0
        public void RaisePropertyChangedEvent(AutomationPeer peer,
                                              AutomationProperty property,
                                              object oldValue,
                                              object newValue)
        {
            if (!AccessibilityEnabled || peer == null)
            {
                return;
            }

            if (object.Equals(newValue, oldValue))
            {
                return;
            }

            // We are going to raise changes only when the value ACTUALLY CHANGES
            IAutomationCacheProperty cachedProperty = peer.GetCachedProperty(property);

            if (cachedProperty != null)
            {
                if (object.Equals(newValue, cachedProperty.OldValue))
                {
                    return;
                }
                cachedProperty.OldValue = newValue;
            }

            if (AutomationPropertyChanged != null)
            {
                AutomationPropertyChanged(this,
                                          new AutomationPropertyChangedEventArgs(peer,
                                                                                 property,
                                                                                 oldValue,
                                                                                 newValue));
            }
        }
예제 #4
0
파일: AutomationPeer.cs 프로젝트: dfr0/moon
		// Method used to cache main properties to RaisePropertyChanged when calling 
		// InvalidatePeer. This method is also called by FrameworkElementAutomationPeer.CreatePeerForElement
		internal void CacheMainProperties ()
		{
			// We are keeping a list of cached properties to raise events depending on the 
			// accessibility status, because the bridge is loaded by request, ie,
			// when an AT requests a11y information is loaded

			if (cacheProperties == null) {
				// Main properties defined in AutomationElementIdentifiers static fields
				cacheProperties = new IAutomationCacheProperty[] {
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.AcceleratorKeyProperty, 
					                                         OldValue = GetAcceleratorKey (), 
									         Delegate =  GetAcceleratorKey },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.AccessKeyProperty, 
					                                         OldValue = GetAccessKey (), 
									         Delegate = GetAccessKey },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.AutomationIdProperty, 
					                                         OldValue = GetAutomationId (), 
									         Delegate = GetAutomationId },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.ClassNameProperty, 
					                                         OldValue = GetClassName (), 
									         Delegate = GetClassName },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.HelpTextProperty, 
					                                         OldValue = GetHelpText (), 
									         Delegate = GetHelpText },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.ItemStatusProperty, 
					                                         OldValue = GetItemStatus (), 
									         Delegate = GetItemStatus },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.ItemTypeProperty,
					                                         OldValue = GetItemType (), 
									         Delegate = GetItemType },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.NameProperty,
					                                         OldValue = GetName (), 
									         Delegate = GetName },
					new AutomationCacheProperty<string> () { Property = AutomationElementIdentifiers.LocalizedControlTypeProperty,
					                                         OldValue = GetLocalizedControlType (), 
									         Delegate = GetLocalizedControlType },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.HasKeyboardFocusProperty,
					                                       OldValue = HasKeyboardFocus (), 
									       Delegate = HasKeyboardFocus },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.IsOffscreenProperty,
					                                       OldValue = IsOffscreen (), 
									       Delegate = IsOffscreen },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.IsContentElementProperty,
					                                       OldValue = IsContentElement (), 
									       Delegate = IsContentElement },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.IsControlElementProperty,
					                                       OldValue = IsControlElement (), 
									       Delegate = IsControlElement },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.IsEnabledProperty,
					                                       OldValue = IsEnabled (), 
									       Delegate = IsEnabled },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.IsPasswordProperty,
					                                       OldValue = IsPassword (), 
									       Delegate = IsPassword },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.IsRequiredForFormProperty,
					                                       OldValue = IsRequiredForForm (), 
									       Delegate = IsRequiredForForm },
					new AutomationCacheProperty<bool> () { Property = AutomationElementIdentifiers.IsKeyboardFocusableProperty,
					                                       OldValue = IsKeyboardFocusable (), 
									       Delegate = IsKeyboardFocusable },
					new AutomationCacheProperty<Rect> () { Property = AutomationElementIdentifiers.BoundingRectangleProperty,
					                                       OldValue = GetBoundingRectangle (), 
									       Delegate = GetBoundingRectangle },
					new AutomationCacheProperty<Point> () { Property = AutomationElementIdentifiers.ClickablePointProperty,
					                                        OldValue = GetClickablePoint (), 
									        Delegate = GetClickablePoint },
					new AutomationCachePeerProperty () { Property = AutomationElementIdentifiers.LabeledByProperty,
					                                     OldValue = GetLabeledBy (), 
									     Delegate = GetLabeledBy },
					new AutomationCacheProperty<AutomationOrientation> () { Property = AutomationElementIdentifiers.OrientationProperty,
					                                                        OldValue = GetOrientation (), 
										                Delegate = GetOrientation },
					new AutomationCacheProperty<AutomationControlType> () { Property = AutomationElementIdentifiers.ControlTypeProperty,
					                                                        OldValue = GetAutomationControlType (), 
										                Delegate = GetAutomationControlType }
				};
			}
		}
예제 #5
0
        // Method used to cache main properties to RaisePropertyChanged when calling
        // InvalidatePeer. This method is also called by FrameworkElementAutomationPeer.CreatePeerForElement
        internal void CacheMainProperties()
        {
            // We are keeping a list of cached properties to raise events depending on the
            // accessibility status, because the bridge is loaded by request, ie,
            // when an AT requests a11y information is loaded

            if (cacheProperties == null)
            {
                // Main properties defined in AutomationElementIdentifiers static fields
                cacheProperties = new IAutomationCacheProperty[] {
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.AcceleratorKeyProperty,
                        OldValue = GetAcceleratorKey(),
                        Delegate = GetAcceleratorKey
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.AccessKeyProperty,
                        OldValue = GetAccessKey(),
                        Delegate = GetAccessKey
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.AutomationIdProperty,
                        OldValue = GetAutomationId(),
                        Delegate = GetAutomationId
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.ClassNameProperty,
                        OldValue = GetClassName(),
                        Delegate = GetClassName
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.HelpTextProperty,
                        OldValue = GetHelpText(),
                        Delegate = GetHelpText
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.ItemStatusProperty,
                        OldValue = GetItemStatus(),
                        Delegate = GetItemStatus
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.ItemTypeProperty,
                        OldValue = GetItemType(),
                        Delegate = GetItemType
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.NameProperty,
                        OldValue = GetName(),
                        Delegate = GetName
                    },
                    new AutomationCacheProperty <string> ()
                    {
                        Property = AutomationElementIdentifiers.LocalizedControlTypeProperty,
                        OldValue = GetLocalizedControlType(),
                        Delegate = GetLocalizedControlType
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.HasKeyboardFocusProperty,
                        OldValue = HasKeyboardFocus(),
                        Delegate = HasKeyboardFocus
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.IsOffscreenProperty,
                        OldValue = IsOffscreen(),
                        Delegate = IsOffscreen
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.IsContentElementProperty,
                        OldValue = IsContentElement(),
                        Delegate = IsContentElement
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.IsControlElementProperty,
                        OldValue = IsControlElement(),
                        Delegate = IsControlElement
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.IsEnabledProperty,
                        OldValue = IsEnabled(),
                        Delegate = IsEnabled
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.IsPasswordProperty,
                        OldValue = IsPassword(),
                        Delegate = IsPassword
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.IsRequiredForFormProperty,
                        OldValue = IsRequiredForForm(),
                        Delegate = IsRequiredForForm
                    },
                    new AutomationCacheProperty <bool> ()
                    {
                        Property = AutomationElementIdentifiers.IsKeyboardFocusableProperty,
                        OldValue = IsKeyboardFocusable(),
                        Delegate = IsKeyboardFocusable
                    },
                    new AutomationCacheProperty <Rect> ()
                    {
                        Property = AutomationElementIdentifiers.BoundingRectangleProperty,
                        OldValue = GetBoundingRectangle(),
                        Delegate = GetBoundingRectangle
                    },
                    new AutomationCacheProperty <Point> ()
                    {
                        Property = AutomationElementIdentifiers.ClickablePointProperty,
                        OldValue = GetClickablePoint(),
                        Delegate = GetClickablePoint
                    },
                    new AutomationCachePeerProperty()
                    {
                        Property = AutomationElementIdentifiers.LabeledByProperty,
                        OldValue = GetLabeledBy(),
                        Delegate = GetLabeledBy
                    },
                    new AutomationCacheProperty <AutomationOrientation> ()
                    {
                        Property = AutomationElementIdentifiers.OrientationProperty,
                        OldValue = GetOrientation(),
                        Delegate = GetOrientation
                    },
                    new AutomationCacheProperty <AutomationControlType> ()
                    {
                        Property = AutomationElementIdentifiers.ControlTypeProperty,
                        OldValue = GetAutomationControlType(),
                        Delegate = GetAutomationControlType
                    }
                };
            }
        }
예제 #6
0
        public FrameworkElementAutomationPeer(FrameworkElement owner)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            this.owner          = owner;
            isKeyboardFocusable = null;

            // Default Automation events
            owner.SizeChanged += (o, s) => {
                Point location = GetLocation(owner);
                RaisePropertyChangedEvent(AutomationElementIdentifiers.BoundingRectangleProperty,
                                          new Rect(0, 0, s.PreviousSize.Width, s.PreviousSize.Height),
                                          new Rect(location.X, location.Y, s.NewSize.Width, s.NewSize.Height));
            };
            owner.UIAVisibilityChanged += (o, e) => {
                IAutomationCacheProperty cachedProperty
                    = GetCachedProperty(AutomationElementIdentifiers.BoundingRectangleProperty);
                Rect newValue = GetBoundingRectangle();
                RaisePropertyChangedEvent(AutomationElementIdentifiers.BoundingRectangleProperty,
                                          cachedProperty.OldValue,
                                          newValue);

                RaiseIsKeyboardFocusableEvent();

                bool isOffscreen = IsOffscreen();
                RaisePropertyChangedEvent(AutomationElementIdentifiers.IsOffscreenProperty,
                                          !isOffscreen,
                                          isOffscreen);
            };

            Control control = owner as Control;

            if (control != null)
            {
                control.IsEnabledChanged += (o, e) => {
                    RaisePropertyChangedEvent(AutomationElementIdentifiers.IsEnabledProperty,
                                              e.OldValue,
                                              e.NewValue);

                    RaiseIsKeyboardFocusableEvent();
                };
                control.UIAIsTabStopChanged += (o, e) => {
                    RaiseIsKeyboardFocusableEvent();
                };

                // StructureChanged
                ContentControl contentControl = control as ContentControl;
                if (contentControl != null)
                {
                    contentControl.UIAContentChanged += OnContentChanged;
                    AddItemsChangedToPanel(contentControl.Content);
                }
            }

            // SWA.AutomationProperties events
            owner.AcceleratorKeyChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.AcceleratorKeyProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.AccessKeyChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.AccessKeyProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.AutomationIdChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.AutomationIdProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.HelpTextChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.HelpTextProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.IsRequiredForFormChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.IsRequiredForFormProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.ItemStatusChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemStatusProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            owner.ItemTypeChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemTypeProperty,
                                          e.OldValue,
                                          e.NewValue);
            };
            // LabeledBy and Name properties are "special" because they somehow depend on each other.
            owner.LabeledByChanged += (o, e) => {
                RaisePropertyChangedEvent(AutomationElementIdentifiers.LabeledByProperty,
                                          e.OldValue,
                                          e.NewValue);
                // Name property
                UIElement labeledByOld = e.OldValue as UIElement;
                if (labeledByOld != null)
                {
                    FrameworkElementAutomationPeer peer
                        = FrameworkElementAutomationPeer.CreatePeerForElement(labeledByOld) as FrameworkElementAutomationPeer;
                    if (peer != null)
                    {
                        peer.NameChanged -= LabeledBy_NameChanged;
                    }
                }
                UIElement labeledByNew = e.NewValue as UIElement;
                if (labeledByNew != null)
                {
                    FrameworkElementAutomationPeer peer
                        = FrameworkElementAutomationPeer.CreatePeerForElement(labeledByNew) as FrameworkElementAutomationPeer;
                    if (peer != null)
                    {
                        peer.NameChanged += LabeledBy_NameChanged;
                    }
                }
                RaiseNameChanged();
            };
            owner.NameChanged += (o, e) => RaiseNameChanged();
        }