Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Do not trust StateSet cache for StateType.Enabled (bug 596801)
Browse files Browse the repository at this point in the history
Also fix NRE in GetText in the test app.

svn path=/trunk/at-spi-sharp/; revision=155839
  • Loading branch information
Mike Gorse committed Apr 20, 2010
1 parent 0d11a60 commit 4607cc9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions at-spi/Accessible.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ internal void Update (AccessibleProxy e)
foreach (string iface in e.interfaces)
AddInterface (iface);

stateSet = new StateSet (e.states);
stateSet = new StateSet (this, e.states);
// Using at-spi StateChanged events to broadcast
// changes for now; needed for gail Focused handling
UpdateChildren (e.children);
Expand Down Expand Up @@ -432,7 +432,7 @@ public StateSet StateSet {
stateSet.Add (StateType.Defunct);
return stateSet;
}
stateSet = new StateSet (states);
stateSet = new StateSet (this, states);
}
return stateSet;
}
Expand Down
5 changes: 5 additions & 0 deletions at-spi/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2010-04-20 Mike Gorse <mgorse@novell.com>

* Accessible.cs, StateSet.cs: Make StateSet cache its accessible and
do not trust cache for StateType.Enabled (bug 596801)

2010-03-17 Mike Gorse <mgorse@novell.com>

* Accessible.cs: Recognize Application interface, and warn rather
Expand Down
17 changes: 16 additions & 1 deletion at-spi/StateSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,42 @@ namespace Atspi
public class StateSet
{
private ulong states;
private Accessible accessible;

public StateSet ()
{
accessible = null;
states = 0;
}

public StateSet (uint [] states)
public StateSet (Accessible accessible, uint [] states)
{
this.accessible = accessible;
if (states.Length != 2)
throw new ArgumentException ("Expecting int [2]");
this.states = (ulong)(states [1] << (sizeof (int) * 8)) | (ulong)states [0];
}

public bool Contains (StateType state)
{
// Do not trust cache for Enabled; see BNC#596801
// TODO: Eventually remove this work-around
if (accessible != null && state == StateType.Enabled && (states & (ulong)StateType.Defunct) == 0) {
try {
uint [] data = accessible.proxy.GetState ();
states = (ulong)(data [1] << (sizeof (int) * 8)) | (ulong)data [0];
} catch (System.Exception) {
return false;
}
}
return (states & (ulong)state) != 0? true: false;
}

public void Add (StateType state)
{
states |= (ulong)state;
if (state == StateType.Defunct)
accessible = null;
}

public void Remove (StateType state)
Expand Down
6 changes: 6 additions & 0 deletions tests/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2010-04-20 Mike Gorse <mgorse@novell.com>

* apps/Document.cs: Fix NRE in GetText.

* at-spi-sharp/AccessibleTest.cs: Add test for bug 596801.

2010-03-01 Mike Gorse <mgorse@novell.com>

* at-spi-sharp/Base.cs: Allow a fixture to open multiple apps.
Expand Down
6 changes: 5 additions & 1 deletion tests/apps/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ public string GetText (int start_offset, int end_offset)
{
if (end_offset == -1)
end_offset = text.Length - start_offset;
return text.Substring (start_offset, end_offset);
if (end_offset > text.Length)
end_offset = text.Length;
if (end_offset < start_offset)
end_offset = start_offset;
return text.Substring (start_offset, end_offset - start_offset);
}

public string GetTextAfterOffset (int offset, Atk.TextBoundary boundary_type, out int start_offset, out int end_offset)
Expand Down
10 changes: 10 additions & 0 deletions tests/at-spi-sharp/AccessibleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public void States ()
);
}

[Test]
public void Bug596801 ()
{
EditableText et = documentFrame.QueryEditableText ();
Accessible child = documentFrame.Children [0].Children [0];
Assert.IsTrue (child.StateSet.Contains (StateType.Enabled), "Enabled");
et.SetTextContents ("StateChanged");
Assert.IsFalse (child.StateSet.Contains (StateType.Enabled), "Not enabled after disabling");
}

[Test]
public void Relations ()
{
Expand Down

0 comments on commit 4607cc9

Please sign in to comment.