View | Details | Raw Unified | Return to bug 468271
Collapse All | Expand All

(-)UIAutomationWinforms/Mono.UIAutomation.Winforms/ListViewProvider.cs (-4 / +15 lines)
Lines 1163-1168 Link Here
1163
				// Automation Events
1163
				// Automation Events
1164
				SetEvent (ProviderEventType.AutomationElementIsOffscreenProperty,
1164
				SetEvent (ProviderEventType.AutomationElementIsOffscreenProperty,
1165
				          new ListItemEditAutomationIsOffscreenPropertyEvent (this));
1165
				          new ListItemEditAutomationIsOffscreenPropertyEvent (this));
1166
				SetEvent (ProviderEventType.AutomationElementHasKeyboardFocusProperty,
1167
				          new ListItemEditAutomationHasKeyboardFocusPropertyEvent (this));
1166
			}
1168
			}
1167
1169
1168
			protected override object GetProviderPropertyValue (int propertyId)
1170
			protected override object GetProviderPropertyValue (int propertyId)
Lines 1175-1184 Link Here
1175
					IValueProvider valueProvider = (IValueProvider) GetBehavior (ValuePatternIdentifiers.Pattern);
1177
					IValueProvider valueProvider = (IValueProvider) GetBehavior (ValuePatternIdentifiers.Pattern);
1176
					return valueProvider.Value;
1178
					return valueProvider.Value;
1177
				} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
1179
				} else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
1178
					return false;
1180
					return IsFirstColumn || itemProvider.ListView.FullRowSelect;
1179
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
1181
				else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id) {
1180
					return false;
1182
					if (IsFirstColumn)
1181
				else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
1183
						return itemProvider.GetPropertyValue (propertyId);
1184
					else
1185
						return false;
1186
				} else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
1182
					return true;
1187
					return true;
1183
				else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
1188
				else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
1184
					return null;
1189
					return null;
Lines 1210-1215 Link Here
1210
					return base.GetProviderPropertyValue (propertyId);
1215
					return base.GetProviderPropertyValue (propertyId);
1211
			}
1216
			}
1212
1217
1218
			bool IsFirstColumn {
1219
				get {
1220
					return header.Index == 0;
1221
					//return itemProvider.ListView.Columns.IndexOf (header) == 0;
1222
				}
1223
			}
1213
			private ListViewListItemProvider itemProvider;
1224
			private ListViewListItemProvider itemProvider;
1214
			private SWF.ColumnHeader header;
1225
			private SWF.ColumnHeader header;
1215
		} //ListViewListItemEditProvider
1226
		} //ListViewListItemEditProvider
(-)UIAutomationWinforms/Mono.UIAutomation.Winforms.mdp (-1 / +2 lines)
Lines 1-4 Link Here
1
<Project name="Mono.UIAutomation.Winforms" fileversion="2.0" language="C#" DefaultNamespace="Mono.UIAutomation.Winforms" UseParentDirectoryAsNamespace="True" clr-version="Net_2_0" targetFramework="3.5" ctype="DotNetProject">
1
<Project name="Mono.UIAutomation.Winforms" fileversion="2.0" language="C#" UseParentDirectoryAsNamespace="True" DefaultNamespace="Mono.UIAutomation.Winforms" clr-version="Net_2_0" targetFramework="3.5" ctype="DotNetProject">
2
  <Configurations active="Debug">
2
  <Configurations active="Debug">
3
    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
3
    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
4
      <Output directory="bin/Debug" signAssembly="True" assemblyKeyFile="../mono-uia.snk" assembly="UIAutomationWinforms" />
4
      <Output directory="bin/Debug" signAssembly="True" assemblyKeyFile="../mono-uia.snk" assembly="UIAutomationWinforms" />
Lines 542-547 Link Here
542
    <File name="Mono.UIAutomation.Winforms.Events/PropertyGrid/SelectionPatternSelectionEvent.cs" subtype="Code" buildaction="Compile" />
542
    <File name="Mono.UIAutomation.Winforms.Events/PropertyGrid/SelectionPatternSelectionEvent.cs" subtype="Code" buildaction="Compile" />
543
    <File name="Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonToggleProviderBehavior.cs" subtype="Code" buildaction="Compile" />
543
    <File name="Mono.UIAutomation.Winforms.Behaviors/ToolBar/ToolBarButtonToggleProviderBehavior.cs" subtype="Code" buildaction="Compile" />
544
    <File name="Mono.UIAutomation.Winforms.Events/ToolBar/ToolBarButtonTogglePatternToggleStateEvent.cs" subtype="Code" buildaction="Compile" />
544
    <File name="Mono.UIAutomation.Winforms.Events/ToolBar/ToolBarButtonTogglePatternToggleStateEvent.cs" subtype="Code" buildaction="Compile" />
545
    <File name="Mono.UIAutomation.Winforms.Events/ListView/ListItemEditAutomationHasKeyboardFocusPropertyEvent.cs" subtype="Code" buildaction="Compile" />
545
  </Contents>
546
  </Contents>
546
  <References>
547
  <References>
547
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
548
    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
(-)UIAutomationWinforms/Makefile.am (+1 lines)
Lines 341-346 Link Here
341
	Mono.UIAutomation.Winforms.Events/ListView/ListItemAutomationIsOffscreenPropertyEvent.cs \
341
	Mono.UIAutomation.Winforms.Events/ListView/ListItemAutomationIsOffscreenPropertyEvent.cs \
342
	Mono.UIAutomation.Winforms.Events/ListView/ListItemCheckBoxAutomationIsOffscreenPropertyEvent.cs \
342
	Mono.UIAutomation.Winforms.Events/ListView/ListItemCheckBoxAutomationIsOffscreenPropertyEvent.cs \
343
	Mono.UIAutomation.Winforms.Events/ListView/ListItemCheckBoxTogglePatternToggleStateEvent.cs \
343
	Mono.UIAutomation.Winforms.Events/ListView/ListItemCheckBoxTogglePatternToggleStateEvent.cs \
344
	Mono.UIAutomation.Winforms.Events/ListView/ListItemEditAutomationHasKeyboardFocusPropertyEvent.cs \
344
	Mono.UIAutomation.Winforms.Events/ListView/ListItemEditAutomationIsOffscreenPropertyEvent.cs \
345
	Mono.UIAutomation.Winforms.Events/ListView/ListItemEditAutomationIsOffscreenPropertyEvent.cs \
345
	Mono.UIAutomation.Winforms.Events/ListView/ListItemEditGridItemColumnEvent.cs \
346
	Mono.UIAutomation.Winforms.Events/ListView/ListItemEditGridItemColumnEvent.cs \
346
	Mono.UIAutomation.Winforms.Events/ListView/ListItemEditGridItemRowEvent.cs \
347
	Mono.UIAutomation.Winforms.Events/ListView/ListItemEditGridItemRowEvent.cs \
(-)UIAutomationWinforms/Mono.UIAutomation.Winforms.Events/ListView/ListItemEditAutomationHasKeyboardFocusPropertyEvent.cs (+77 lines)
Line 0 Link Here
1
// Permission is hereby granted, free of charge, to any person obtaining 
2
// a copy of this software and associated documentation files (the 
3
// "Software"), to deal in the Software without restriction, including 
4
// without limitation the rights to use, copy, modify, merge, publish, 
5
// distribute, sublicense, and/or sell copies of the Software, and to 
6
// permit persons to whom the Software is furnished to do so, subject to 
7
// the following conditions: 
8
//  
9
// The above copyright notice and this permission notice shall be 
10
// included in all copies or substantial portions of the Software. 
11
//  
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
13
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
14
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
16
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
19
// 
20
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com) 
21
// 
22
// Authors: 
23
//	Mario Carrion <mcarrion@novell.com>
24
// 
25
26
using System;
27
using System.ComponentModel;
28
using System.Windows.Automation;
29
using System.Windows.Automation.Provider;
30
using SWF = System.Windows.Forms;
31
using Mono.UIAutomation.Winforms.Events;
32
33
namespace Mono.UIAutomation.Winforms.Events.ListView
34
{
35
36
	internal class ListItemEditAutomationHasKeyboardFocusPropertyEvent
37
		: AutomationHasKeyboardFocusPropertyEvent
38
	{
39
		
40
		#region Constructors
41
42
		public ListItemEditAutomationHasKeyboardFocusPropertyEvent (ListViewProvider.ListViewListItemEditProvider editProvider)
43
			: base (editProvider)
44
		{
45
			this.editProvider = editProvider;
46
		}
47
		
48
		#endregion
49
		
50
		#region IConnectable Overrides
51
	
52
		public override void Connect ()
53
		{
54
			editProvider.ItemProvider.ListView.UIAFocusedItemChanged 
55
				+= OnUIAFocusedItemChanged;
56
		}
57
58
		public override void Disconnect ()
59
		{
60
			editProvider.ItemProvider.ListView.UIAFocusedItemChanged 
61
				-= OnUIAFocusedItemChanged;
62
		}
63
		
64
		#endregion
65
		
66
		#region Private Fields
67
		
68
		private void OnUIAFocusedItemChanged (object sender, EventArgs args)
69
		{
70
			RaiseAutomationPropertyChangedEvent ();
71
		}
72
73
		private ListViewProvider.ListViewListItemEditProvider editProvider;
74
		
75
		#endregion
76
	}
77
}
(-)UIAutomationWinformsTests/ListViewProviderTest.cs (+153 lines)
Lines 2285-2290 Link Here
2285
			}
2285
			}
2286
		}
2286
		}
2287
2287
2288
		[Test]
2289
		public void Bug468271Test ()
2290
		{
2291
			// NOTE: This test only exposes bug in Provider side.
2292
			// ListView_details: "table cell" isn't accessible without "focused"
2293
			ListView listview = new ListView ();
2294
			listview.View = View.Details;
2295
			listview.CheckBoxes = true;
2296
			listview.GridLines = true;
2297
			listview.Sorting = SortOrder.Ascending;
2298
			listview.Dock = DockStyle.Top;
2299
			listview.Width = 350;
2300
			listview.Height = 260;
2301
2302
			listview.Columns.Add ("Column1", 200, HorizontalAlignment.Left);
2303
			listview.Columns.Add ("Column2", 200, HorizontalAlignment.Left);
2304
			listview.Columns.Add ("Column3", 200, HorizontalAlignment.Left);
2305
2306
			for (int index = 0; index < 3; index++) {
2307
				ListViewItem item = new ListViewItem (string.Format ("Item:{0}", index));
2308
				item.SubItems.Add (index.ToString ());
2309
				item.SubItems.Add ((index+10).ToString ());
2310
				listview.Items.Add (item);
2311
			}
2312
2313
			// We have the following table:
2314
			// "Column1"         | "Column2" | "Column3"
2315
			// ------------------|-----------|----------
2316
			// checkbox, "Item0" | "0"       | "10"
2317
			// checkbox, "Item1" | "1"       | "11"
2318
			// checkbox, "Item2" | "2"       | "12"
2319
2320
			// ListViewUIATree:
2321
			// - Header
2322
			//   - HeaderItem "Column1"
2323
			//   - HeaderItem "Column2"
2324
			//   - HeaderItem "Column3"
2325
			// - DataItem "Item0"
2326
			//   - CheckBox
2327
			//   - "Item0"
2328
			//   - "0"
2329
			//   - "10"
2330
			// - DataItem "Item1"
2331
			//   - CheckBox
2332
			//   - "Item1"
2333
			//   - "1"
2334
			//   - "11"
2335
			// - DataItem "Item2"
2336
			//   - CheckBox
2337
			//   - "Item2"
2338
			//   - "2"
2339
			//   - "12"
2340
			IRawElementProviderFragmentRoot root
2341
				= (IRawElementProviderFragmentRoot) GetProviderFromControl (listview);
2342
			Assert.IsNotNull (root, "Missing ListViewProvider");
2343
			IRawElementProviderFragmentRoot []dataItems = new IRawElementProviderFragmentRoot [3];
2344
			IRawElementProviderFragment child = root.Navigate (NavigateDirection.FirstChild);
2345
			Assert.IsNotNull (child, "Missing child");
2346
			
2347
			int dataItem = 0;
2348
			while (child != null) {				
2349
				if ((int) child.GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id)
2350
				    == ControlType.DataItem.Id) {
2351
					dataItems [dataItem] = (IRawElementProviderFragmentRoot) child;
2352
					dataItem++;
2353
				}
2354
				child = child.Navigate (NavigateDirection.NextSibling);
2355
			}
2356
			Assert.AreEqual (dataItems.Length, dataItem, "Count != DataItems");
2357
2358
			// You *can* only focus 1 item, so, focusing a different item
2359
			// will unfocus previous item and focus new item.
2360
2361
			// listview.FullRowSelect = false: first subitem will is selected.
2362
			bridge.ResetEventLists ();
2363
			listview.Focus ();
2364
			listview.Items [0].Focused = true;
2365
			TestFocusInDataItemChildren (listview, 0, dataItems [0], true);
2366
2367
			bridge.ResetEventLists ();
2368
			listview.Items [1].Focused = true;
2369
			TestFocusInDataItemChildren (listview, 1, dataItems [1], true);
2370
			TestFocusInDataItemChildren (listview, 0, dataItems [0], false);
2371
2372
			bridge.ResetEventLists ();
2373
			listview.Items [2].Focused = true;
2374
			TestFocusInDataItemChildren (listview, 2, dataItems [2], true);			
2375
			TestFocusInDataItemChildren (listview, 1, dataItems [1], false);
2376
		}
2377
2378
		private int GetIndexFromName (ListViewItem item, string name)
2379
		{
2380
			int index = 0;
2381
2382
			foreach (ListViewItem.ListViewSubItem subItem in item.SubItems) {
2383
				if (subItem.Text == name)
2384
					break;
2385
				index++;
2386
			}
2387
2388
			return index;
2389
		}
2390
2391
		private void TestFocusInDataItemChildren (ListView listview, 
2392
		                                          int index, 
2393
		                                          IRawElementProviderFragmentRoot dataItemRoot,
2394
		                                          bool focused)
2395
		{
2396
			AutomationPropertyChangedEventTuple tuple 
2397
				= bridge.GetAutomationPropertyEventFrom (dataItemRoot, 
2398
				                                         AutomationElementIdentifiers.HasKeyboardFocusProperty.Id);
2399
			Assert.AreEqual (focused, 
2400
			                 (bool) tuple.e.NewValue,
2401
			                 "DataItem Focused value.");
2402
2403
			IRawElementProviderFragment child = dataItemRoot.Navigate (NavigateDirection.FirstChild);
2404
			Assert.IsNotNull (child, "Child should not be null");
2405
			int subItem = 0;
2406
			while (child != null) {
2407
				bool hasfocus 
2408
					= (bool) child.GetPropertyValue (AutomationElementIdentifiers.HasKeyboardFocusProperty.Id);
2409
				if ((int) child.GetPropertyValue (AutomationElementIdentifiers.ControlTypeProperty.Id)
2410
				    == ControlType.Edit.Id) {
2411
					string name
2412
						= (string) child.GetPropertyValue (AutomationElementIdentifiers.NameProperty.Id);
2413
					if (!focused)
2414
						Assert.IsFalse (hasfocus,
2415
						                string.Format ("{0}.{1} Name: '{0}'",
2416
						                               index, subItem, name));
2417
					else {
2418
						if (listview.FullRowSelect
2419
						    || GetIndexFromName (listview.Items [index], name) == 0)
2420
							Assert.AreEqual (focused,
2421
							                 hasfocus,
2422
							                 string.Format ("{0}.{1} Name: '{0}'",
2423
							                                index, subItem, name));
2424
						else
2425
							Assert.AreNotEqual (focused,
2426
							                    hasfocus,
2427
							                    string.Format ("{0}.{1} Name: '{0}'",
2428
							                                   index, subItem, name));
2429
					}
2430
					subItem++;
2431
				} else 
2432
					// CheckBox only selected when is fullrow and is focused
2433
					// is expected
2434
					Assert.AreEqual (listview.FullRowSelect && focused, 
2435
					                 hasfocus,
2436
					                 string.Format ("{0}.CheckBox Focus should NOT be set", index));
2437
				child = child.Navigate (NavigateDirection.NextSibling);
2438
			}
2439
		}
2440
2288
		#region BaseProviderTest Overrides
2441
		#region BaseProviderTest Overrides
2289
2442
2290
		protected override Control GetControlInstance ()
2443
		protected override Control GetControlInstance ()

Return to bug 468271