-
Notifications
You must be signed in to change notification settings - Fork 1k
Improving accessible object for label edit in ListView #6309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RussKie
merged 2 commits into
dotnet:main
from
WPMGPRoSToTeMa:Issue_4810_Improving_ListView_LabelEdit_AccessibleObject
Aug 8, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.SetWinEventHook.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class User32 | ||
{ | ||
[DllImport(Libraries.User32, ExactSpelling = true, SetLastError = true)] | ||
private static extern nint SetWinEventHook(uint eventMin, uint eventMax, nint hmodWinEventProc, | ||
WINEVENTPROC pfnWinEventProc, uint idProcess, uint idThread, WINEVENT dwFlags); | ||
|
||
public static nint SetWinEventHook(uint eventId, WINEVENTPROC pfnWinEventProc) | ||
=> SetWinEventHook(eventId, eventId, Kernel32.GetModuleHandleW(null), pfnWinEventProc, | ||
(uint)Environment.ProcessId, Kernel32.GetCurrentThreadId(), WINEVENT.INCONTEXT); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.UnhookWinEvent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class User32 | ||
{ | ||
[DllImport(Libraries.User32, ExactSpelling = true, SetLastError = true)] | ||
public static extern BOOL UnhookWinEvent(nint hWinEventHook); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.WINEVENT.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class User32 | ||
{ | ||
public enum WINEVENT : uint | ||
{ | ||
OUTOFCONTEXT = 0, | ||
SKIPOWNTHREAD = 1, | ||
SKIPOWNPROCESS = 2, | ||
INCONTEXT = 4, | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.WINEVENTPROC.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class User32 | ||
{ | ||
public delegate void WINEVENTPROC(nint hWinEventHook, uint eventId, nint hwnd, int idObject, int idChild, uint idEventThread, uint dwmsEventTime); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/System.Windows.Forms/src/System/Windows/Forms/ListViewLabelEditAccessibleObject.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Drawing; | ||
using System.Runtime.InteropServices; | ||
using static Interop; | ||
|
||
namespace System.Windows.Forms | ||
{ | ||
internal class ListViewLabelEditAccessibleObject : AccessibleObject | ||
Tanya-Solyanik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private const string LIST_VIEW_LABEL_EDIT_AUTOMATION_ID = "1"; | ||
|
||
private readonly ListView _owningListView; | ||
private readonly IntPtr _handle; | ||
private readonly ListViewLabelEditUiaTextProvider _textProvider; | ||
private int[]? _runtimeId; | ||
|
||
public ListViewLabelEditAccessibleObject(ListView owningListView, IHandle handle) | ||
{ | ||
_owningListView = owningListView.OrThrowIfNull(); | ||
_handle = handle.Handle; | ||
UseStdAccessibleObjects(_handle); | ||
_textProvider = new ListViewLabelEditUiaTextProvider(owningListView, handle, this); | ||
} | ||
|
||
private protected override string AutomationId => LIST_VIEW_LABEL_EDIT_AUTOMATION_ID; | ||
|
||
internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction) | ||
{ | ||
AccessibleObject parent = _owningListView.AccessibilityObject; | ||
|
||
return direction switch | ||
{ | ||
UiaCore.NavigateDirection.Parent => parent, | ||
UiaCore.NavigateDirection.NextSibling => parent.GetChildIndex(this) is int childId and >= 0 ? parent.GetChild(childId + 1) : null, | ||
UiaCore.NavigateDirection.PreviousSibling => parent.GetChildIndex(this) is int childId and >= 0 ? parent.GetChild(childId - 1) : null, | ||
_ => base.FragmentNavigate(direction), | ||
}; | ||
} | ||
|
||
internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot => _owningListView.AccessibilityObject; | ||
|
||
internal override object? GetPropertyValue(UiaCore.UIA propertyID) | ||
Tanya-Solyanik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
=> propertyID switch | ||
{ | ||
UiaCore.UIA.ProcessIdPropertyId => Environment.ProcessId, | ||
UiaCore.UIA.ControlTypePropertyId => UiaCore.UIA.EditControlTypeId, | ||
UiaCore.UIA.AccessKeyPropertyId => string.Empty, | ||
UiaCore.UIA.HasKeyboardFocusPropertyId => true, | ||
Tanya-Solyanik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
UiaCore.UIA.IsKeyboardFocusablePropertyId => (State & AccessibleStates.Focusable) == AccessibleStates.Focusable, | ||
UiaCore.UIA.IsEnabledPropertyId => _owningListView.Enabled, | ||
UiaCore.UIA.IsContentElementPropertyId => true, | ||
UiaCore.UIA.NativeWindowHandlePropertyId => _handle, | ||
_ => base.GetPropertyValue(propertyID), | ||
}; | ||
|
||
internal override UiaCore.IRawElementProviderSimple? HostRawElementProvider | ||
{ | ||
get | ||
{ | ||
UiaCore.UiaHostProviderFromHwnd(new HandleRef(this, _handle), out UiaCore.IRawElementProviderSimple provider); | ||
return provider; | ||
} | ||
} | ||
|
||
internal override bool IsPatternSupported(UiaCore.UIA patternId) => patternId switch | ||
{ | ||
UiaCore.UIA.TextPatternId => true, | ||
UiaCore.UIA.TextPattern2Id => true, | ||
UiaCore.UIA.ValuePatternId => true, | ||
UiaCore.UIA.LegacyIAccessiblePatternId => true, | ||
_ => base.IsPatternSupported(patternId), | ||
}; | ||
|
||
public override string Name => User32.GetWindowText(_handle); | ||
|
||
internal override int[] RuntimeId => _runtimeId ??= new int[] { RuntimeIDFirstItem, PARAM.ToInt(_handle) }; | ||
|
||
internal override UiaCore.ITextRangeProvider DocumentRangeInternal | ||
=> _textProvider.DocumentRange; | ||
|
||
internal override UiaCore.ITextRangeProvider[]? GetTextSelection() | ||
=> _textProvider.GetSelection(); | ||
|
||
internal override UiaCore.ITextRangeProvider[]? GetTextVisibleRanges() | ||
=> _textProvider.GetVisibleRanges(); | ||
|
||
internal override UiaCore.ITextRangeProvider? GetTextRangeFromChild(UiaCore.IRawElementProviderSimple childElement) | ||
=> _textProvider.RangeFromChild(childElement); | ||
|
||
internal override UiaCore.ITextRangeProvider? GetTextRangeFromPoint(Point screenLocation) | ||
=> _textProvider.RangeFromPoint(screenLocation); | ||
|
||
internal override UiaCore.SupportedTextSelection SupportedTextSelectionInternal | ||
=> _textProvider.SupportedTextSelection; | ||
|
||
internal override UiaCore.ITextRangeProvider? GetTextCaretRange(out BOOL isActive) | ||
=> _textProvider.GetCaretRange(out isActive); | ||
|
||
internal override UiaCore.ITextRangeProvider GetRangeFromAnnotation(UiaCore.IRawElementProviderSimple annotationElement) | ||
=> _textProvider.RangeFromAnnotation(annotationElement); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.