forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement
ToggleButtonAutomationPeer
- Loading branch information
1 parent
b515ef6
commit ef52c88
Showing
2 changed files
with
74 additions
and
58 deletions.
There are no files selected for viewing
116 changes: 60 additions & 56 deletions
116
src/Uno.UI/UI/Xaml/Automation/Peers/ToggleButtonAutomationPeer.cs
This file contains 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 |
---|---|---|
@@ -1,81 +1,85 @@ | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
// MUX Reference ToggleButtonAutomationPeer_Partial.cpp, tag winui3/release/1.4.2 | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using static Microsoft/* UWP don't rename */.UI.Xaml.Controls._Tracing; | ||
|
||
namespace Microsoft.UI.Xaml.Automation.Peers | ||
namespace Microsoft.UI.Xaml.Automation.Peers; | ||
|
||
/// <summary> | ||
/// Exposes ToggleButton types to Microsoft UI Automation. | ||
/// </summary> | ||
public partial class ToggleButtonAutomationPeer : ButtonBaseAutomationPeer, Provider.IToggleProvider | ||
{ | ||
public partial class ToggleButtonAutomationPeer : ButtonBaseAutomationPeer, Provider.IToggleProvider | ||
public ToggleButtonAutomationPeer(ToggleButton owner) : base(owner) | ||
{ | ||
public ToggleButtonAutomationPeer(ToggleButton owner) : base(owner) | ||
{ | ||
} | ||
} | ||
|
||
protected override string GetClassNameCore() => "ToggleButton"; | ||
protected override string GetClassNameCore() => nameof(ToggleButton); | ||
|
||
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Button; | ||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
=> AutomationControlType.Button; | ||
|
||
public ToggleState ToggleState | ||
/// <summary> | ||
/// Gets the toggle state of the control. | ||
/// </summary> | ||
public ToggleState ToggleState | ||
=> ((ToggleButton)Owner).IsChecked switch | ||
{ | ||
get | ||
{ | ||
switch (((ToggleButton)Owner).IsChecked) | ||
{ | ||
case (true): | ||
return ToggleState.On; | ||
case (false): | ||
return ToggleState.Off; | ||
default: | ||
return ToggleState.Indeterminate; | ||
} | ||
} | ||
} | ||
(true) => ToggleState.On, | ||
(false) => ToggleState.Off, | ||
_ => ToggleState.Indeterminate, | ||
}; | ||
|
||
public void Toggle() | ||
/// <summary> | ||
/// Cycles through the toggle states of a control. | ||
/// </summary> | ||
public void Toggle() | ||
{ | ||
if (IsEnabled()) | ||
{ | ||
if (IsEnabled()) | ||
{ | ||
((ToggleButton)Owner).AutomationToggleButtonOnToggle(); | ||
} | ||
((ToggleButton)Owner).AutomationToggleButtonOnToggle(); | ||
} | ||
} | ||
|
||
internal void RaiseToggleStatePropertyChangedEvent(object pOldValue, object pNewValue) | ||
{ | ||
var oldValue = ConvertToToggleState(pOldValue); | ||
internal void RaiseToggleStatePropertyChangedEvent(object pOldValue, object pNewValue) | ||
{ | ||
var oldValue = ConvertToToggleState(pOldValue); | ||
|
||
var newValue = ConvertToToggleState(pNewValue); | ||
var newValue = ConvertToToggleState(pNewValue); | ||
|
||
MUX_ASSERT(oldValue != ToggleState.Indeterminate); | ||
MUX_ASSERT(newValue != ToggleState.Indeterminate); | ||
MUX_ASSERT(oldValue != ToggleState.Indeterminate); | ||
MUX_ASSERT(newValue != ToggleState.Indeterminate); | ||
|
||
if (oldValue != newValue) | ||
{ | ||
RaisePropertyChangedEvent(TogglePatternIdentifiers.ToggleStateProperty, oldValue, newValue); | ||
} | ||
if (oldValue != newValue) | ||
{ | ||
RaisePropertyChangedEvent(TogglePatternIdentifiers.ToggleStateProperty, oldValue, newValue); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Convert the Boolean in Inspectable to the ToggleState Enum, if the Inspectable is null | ||
/// that corresponds to Indeterminate state. | ||
/// </summary> | ||
internal static ToggleState ConvertToToggleState(object pValue) | ||
{ | ||
var pToggleState = ToggleState.Indeterminate; | ||
|
||
/// <summary> | ||
/// Convert the Boolean in Inspectable to the ToggleState Enum, if the Inspectable is null | ||
/// that corresponds to Indeterminate state. | ||
/// </summary> | ||
internal static ToggleState ConvertToToggleState(object pValue) | ||
if (pValue != null) | ||
{ | ||
var pToggleState = ToggleState.Indeterminate; | ||
var bValue = (bool)pValue; | ||
|
||
if (pValue != null) | ||
if (bValue) | ||
{ | ||
var bValue = (bool)pValue; | ||
|
||
if (bValue) | ||
{ | ||
pToggleState = ToggleState.On; | ||
} | ||
else | ||
{ | ||
|
||
pToggleState = ToggleState.Off; | ||
} | ||
pToggleState = ToggleState.On; | ||
} | ||
else | ||
{ | ||
|
||
return pToggleState; | ||
pToggleState = ToggleState.Off; | ||
} | ||
} | ||
|
||
return pToggleState; | ||
} | ||
} |
This file contains 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