2 // System.Windows.Automation.Peers.AutomationPeer
5 // Moonlight List (moonlight-list@lists.ximian.com)
7 // Copyright (C) 2008,2009 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.Collections
.Generic
;
32 using System
.Windows
.Automation
.Provider
;
34 namespace System
.Windows
.Automation
.Peers
{
36 public abstract class AutomationPeer
: DependencyObject
{
38 protected AutomationPeer ()
42 public AutomationPeer EventsSource
{
47 public void RaiseAutomationEvent (AutomationEvents events
)
49 AutomationSingleton
.Instance
.RaiseAutomationEvent (this, events
);
52 public static bool ListenerExists (AutomationEvents events
)
54 return AutomationSingleton
.Instance
.ListenerExists (events
);
57 protected IRawElementProviderSimple
ProviderFromPeer (AutomationPeer peer
)
61 return new IRawElementProviderSimple (peer
);
64 public AutomationPeer
GetLabeledBy ()
66 return GetLabeledByCore ();
69 public string GetName ()
71 AutomationPeer labeledByPeer
= GetLabeledBy ();
72 if (labeledByPeer
!= null)
73 return labeledByPeer
.GetName () ?? string.Empty
;
75 return GetNameCore ();
78 public string GetItemType ()
80 return GetItemTypeCore ();
83 public List
<AutomationPeer
> GetChildren ()
85 return GetChildrenCore ();
88 protected abstract AutomationPeer
GetLabeledByCore ();
89 protected abstract string GetNameCore ();
90 protected abstract string GetItemTypeCore ();
91 protected abstract List
<AutomationPeer
> GetChildrenCore ();
92 protected abstract string GetAcceleratorKeyCore ();
93 protected abstract string GetAccessKeyCore ();
94 protected abstract AutomationControlType
GetAutomationControlTypeCore ();
95 protected abstract string GetAutomationIdCore ();
96 protected abstract Rect
GetBoundingRectangleCore ();
97 protected abstract string GetClassNameCore ();
98 protected abstract bool IsOffscreenCore ();
99 protected abstract bool IsPasswordCore ();
100 protected abstract Point
GetClickablePointCore ();
101 protected abstract string GetItemStatusCore ();
102 protected abstract string GetHelpTextCore ();
103 protected abstract AutomationOrientation
GetOrientationCore ();
104 protected abstract bool HasKeyboardFocusCore ();
105 protected abstract bool IsContentElementCore ();
106 protected abstract bool IsControlElementCore ();
107 protected abstract bool IsEnabledCore ();
108 protected abstract bool IsKeyboardFocusableCore ();
109 protected abstract bool IsRequiredForFormCore ();
110 protected abstract string GetLocalizedControlTypeCore ();
111 protected abstract void SetFocusCore ();
113 public abstract object GetPattern (PatternInterface patternInterface
);
115 public string GetAcceleratorKey ()
117 return GetAcceleratorKeyCore ();
120 public string GetAccessKey ()
122 return GetAccessKeyCore ();
125 public AutomationControlType
GetAutomationControlType ()
127 return GetAutomationControlTypeCore ();
130 public string GetAutomationId ()
132 return GetAutomationIdCore ();
135 public Rect
GetBoundingRectangle ()
137 return GetBoundingRectangleCore ();
140 public string GetClassName ()
142 return GetClassNameCore ();
145 public Point
GetClickablePoint ()
147 return GetClickablePointCore ();
150 public string GetHelpText ()
152 return GetHelpTextCore ();
155 public string GetItemStatus ()
157 return GetItemStatusCore ();
160 public string GetLocalizedControlType ()
162 return GetLocalizedControlTypeCore ();
165 public AutomationOrientation
GetOrientation ()
167 return GetOrientationCore ();
170 public AutomationPeer
GetParent ()
172 return GetParentCore ();
175 public bool HasKeyboardFocus ()
177 return HasKeyboardFocusCore ();
180 public void InvalidatePeer ()
182 AutomationSingleton
.Instance
.InvalidatePeer (this);
185 public bool IsContentElement ()
187 return IsContentElementCore ();
190 public bool IsControlElement ()
192 return IsControlElementCore ();
195 public bool IsEnabled ()
197 return IsEnabledCore ();
200 public bool IsKeyboardFocusable ()
202 return IsKeyboardFocusableCore ();
205 public bool IsOffscreen ()
207 return IsOffscreenCore ();
210 public bool IsPassword ()
212 return IsPasswordCore ();
215 public bool IsRequiredForForm ()
217 return IsRequiredForFormCore ();
220 protected AutomationPeer
PeerFromProvider (IRawElementProviderSimple provider
)
222 // SL2 will NRE too if 'provider' is null
223 return provider
.AutomationPeer
;
226 public void RaisePropertyChangedEvent (AutomationProperty property
, object oldValue
, object newValue
)
228 AutomationSingleton
.Instance
.RaisePropertyChangedEvent (this, property
, oldValue
, newValue
);
231 public void SetFocus ()
236 // Overriden by FrameworkElementAutomationPeer to return Parent peer using recursion
237 internal virtual AutomationPeer
GetParentCore ()
242 // Method used to cache main properties to RaisePropertyChanged when calling
243 // InvalidatePeer. This method is also called by FrameworkElementAutomationPeer.CreatePeerForElement
244 internal void CacheMainProperties ()
246 // We are keeping a list of cached properties to raise events depending on the
247 // accessibility status, because the bridge is loaded by request, ie,
248 // when an AT requests a11y information is loaded
250 if (cacheProperties
== null) {
251 // Main properties defined in AutomationElementIdentifiers static fields
252 cacheProperties
= new IAutomationCacheProperty
[] {
253 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.AcceleratorKeyProperty
,
254 OldValue
= GetAcceleratorKey (),
255 Delegate
= GetAcceleratorKey
},
256 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.AccessKeyProperty
,
257 OldValue
= GetAccessKey (),
258 Delegate
= GetAccessKey
},
259 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.AutomationIdProperty
,
260 OldValue
= GetAutomationId (),
261 Delegate
= GetAutomationId
},
262 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.ClassNameProperty
,
263 OldValue
= GetClassName (),
264 Delegate
= GetClassName
},
265 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.HelpTextProperty
,
266 OldValue
= GetHelpText (),
267 Delegate
= GetHelpText
},
268 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.ItemStatusProperty
,
269 OldValue
= GetItemStatus (),
270 Delegate
= GetItemStatus
},
271 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.ItemTypeProperty
,
272 OldValue
= GetItemType (),
273 Delegate
= GetItemType
},
274 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.NameProperty
,
275 OldValue
= GetName (),
276 Delegate
= GetName
},
277 new AutomationCacheProperty
<string> () { Property
= AutomationElementIdentifiers
.LocalizedControlTypeProperty
,
278 OldValue
= GetLocalizedControlType (),
279 Delegate
= GetLocalizedControlType
},
280 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.HasKeyboardFocusProperty
,
281 OldValue
= HasKeyboardFocus (),
282 Delegate
= HasKeyboardFocus
},
283 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.IsOffscreenProperty
,
284 OldValue
= IsOffscreen (),
285 Delegate
= IsOffscreen
},
286 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.IsContentElementProperty
,
287 OldValue
= IsContentElement (),
288 Delegate
= IsContentElement
},
289 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.IsControlElementProperty
,
290 OldValue
= IsControlElement (),
291 Delegate
= IsControlElement
},
292 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.IsEnabledProperty
,
293 OldValue
= IsEnabled (),
294 Delegate
= IsEnabled
},
295 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.IsPasswordProperty
,
296 OldValue
= IsPassword (),
297 Delegate
= IsPassword
},
298 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.IsRequiredForFormProperty
,
299 OldValue
= IsRequiredForForm (),
300 Delegate
= IsRequiredForForm
},
301 new AutomationCacheProperty
<bool> () { Property
= AutomationElementIdentifiers
.IsKeyboardFocusableProperty
,
302 OldValue
= IsKeyboardFocusable (),
303 Delegate
= IsKeyboardFocusable
},
304 new AutomationCacheProperty
<Rect
> () { Property
= AutomationElementIdentifiers
.BoundingRectangleProperty
,
305 OldValue
= GetBoundingRectangle (),
306 Delegate
= GetBoundingRectangle
},
307 new AutomationCacheProperty
<Point
> () { Property
= AutomationElementIdentifiers
.ClickablePointProperty
,
308 OldValue
= GetClickablePoint (),
309 Delegate
= GetClickablePoint
},
310 new AutomationCachePeerProperty () { Property
= AutomationElementIdentifiers
.LabeledByProperty
,
311 OldValue
= GetLabeledBy (),
312 Delegate
= GetLabeledBy
},
313 new AutomationCacheProperty
<AutomationOrientation
> () { Property
= AutomationElementIdentifiers
.OrientationProperty
,
314 OldValue
= GetOrientation (),
315 Delegate
= GetOrientation
},
316 new AutomationCacheProperty
<AutomationControlType
> () { Property
= AutomationElementIdentifiers
.ControlTypeProperty
,
317 OldValue
= GetAutomationControlType (),
318 Delegate
= GetAutomationControlType
}
323 internal IAutomationCacheProperty
GetCachedProperty (AutomationProperty property
)
325 CacheMainProperties ();
327 return (from p
in cacheProperties where p
.Property
== property
select p
).FirstOrDefault();
330 internal IEnumerable
<IAutomationCacheProperty
> CacheProperties
{
331 get { return cacheProperties; }
334 internal virtual void RaiseNameChanged ()
338 private IAutomationCacheProperty
[]cacheProperties
;