Commit d71ce763 authored by Suproteem Sarkar's avatar Suproteem Sarkar Committed by Commit Bot

Implemented popular control patterns for changing accessible object state in GetPatternProvider

R=nektar@chromium.org,dmazzoni@chromium.org

Bug: 852970
Change-Id: Id20d5bc038c36e9f339737aa18ccdc06d65ba9bb
Reviewed-on: https://chromium-review.googlesource.com/1102487
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569776}
parent 04171dee
......@@ -258,4 +258,28 @@ bool SupportsOrientation(ax::mojom::Role role) {
return false;
}
}
bool SupportsToggle(ax::mojom::Role role) {
switch (role) {
case ax::mojom::Role::kCheckBox:
case ax::mojom::Role::kMenuItemCheckBox:
case ax::mojom::Role::kSwitch:
case ax::mojom::Role::kToggleButton:
return true;
default:
return false;
}
}
bool SupportsExpandCollapse(ax::mojom::Role role) {
switch (role) {
case ax::mojom::Role::kComboBoxGrouping:
case ax::mojom::Role::kComboBoxMenuButton:
case ax::mojom::Role::kDisclosureTriangle:
case ax::mojom::Role::kTextFieldWithComboBox:
return true;
default:
return false;
}
}
} // namespace ui
......@@ -55,6 +55,12 @@ AX_EXPORT bool IsHeadingOrTableHeader(ax::mojom::Role role);
// Returns true if this node can have an orientation
AX_EXPORT bool SupportsOrientation(ax::mojom::Role role);
// Returns true if the provided role supports toggle
AX_EXPORT bool SupportsToggle(ax::mojom::Role role);
// Returns true if the provided role supports expand/collapse
AX_EXPORT bool SupportsExpandCollapse(ax::mojom::Role role);
} // namespace ui
#endif // UI_ACCESSIBILITY_AX_ROLE_PROPERTIES_H_
......@@ -1403,6 +1403,43 @@ STDMETHODIMP AXPlatformNodeWin::GetIAccessiblePair(IAccessible** accessible,
return S_OK;
}
//
// IExpandCollapseProvider implementation.
//
STDMETHODIMP AXPlatformNodeWin::Collapse() {
AXActionData action_data;
action_data.action = ax::mojom::Action::kDoDefault;
if (delegate_->AccessibilityPerformAction(action_data))
return S_OK;
return E_FAIL;
}
STDMETHODIMP AXPlatformNodeWin::Expand() {
AXActionData action_data;
action_data.action = ax::mojom::Action::kDoDefault;
if (delegate_->AccessibilityPerformAction(action_data))
return S_OK;
return E_FAIL;
}
STDMETHODIMP AXPlatformNodeWin::get_ExpandCollapseState(
ExpandCollapseState* result) {
COM_OBJECT_VALIDATE_1_ARG(result);
const AXNodeData& data = GetData();
if (data.HasState(ax::mojom::State::kExpanded)) {
*result = ExpandCollapseState_Expanded;
} else if (data.HasState(ax::mojom::State::kCollapsed)) {
*result = ExpandCollapseState_Collapsed;
} else {
NOTREACHED();
return E_FAIL;
}
return S_OK;
}
//
// IScrollItemProvider implementation.
//
......@@ -1423,6 +1460,32 @@ STDMETHODIMP AXPlatformNodeWin::ScrollIntoView() {
return E_FAIL;
}
//
// IToggleProvider implementation.
//
STDMETHODIMP AXPlatformNodeWin::Toggle() {
AXActionData action_data;
action_data.action = ax::mojom::Action::kDoDefault;
if (delegate_->AccessibilityPerformAction(action_data))
return S_OK;
return E_FAIL;
}
STDMETHODIMP AXPlatformNodeWin::get_ToggleState(ToggleState* result) {
COM_OBJECT_VALIDATE_1_ARG(result);
const auto checked_state = GetData().GetCheckedState();
if (checked_state == ax::mojom::CheckedState::kTrue) {
*result = ToggleState_On;
} else if (checked_state == ax::mojom::CheckedState::kMixed) {
*result = ToggleState_Indeterminate;
} else {
*result = ToggleState_Off;
}
return S_OK;
}
//
// IValueProvider implementation.
//
......@@ -2667,11 +2730,21 @@ STDMETHODIMP AXPlatformNodeWin::GetPatternProvider(PATTERNID pattern_id,
WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_PATTERN_PROVIDER);
COM_OBJECT_VALIDATE_1_ARG(result);
const AXNodeData& data = GetData();
switch (pattern_id) {
// Supported by IAccessibleEx.
// TODO(suproteem): Implementations where applicable.
case UIA_DockPatternId:
break;
case UIA_ExpandCollapsePatternId:
if (SupportsExpandCollapse(data.role)) {
AddRef();
*result = static_cast<IRawElementProviderSimple*>(this);
}
break;
case UIA_GridPatternId:
case UIA_GridItemPatternId:
case UIA_MultipleViewPatternId:
......@@ -2700,7 +2773,13 @@ STDMETHODIMP AXPlatformNodeWin::GetPatternProvider(PATTERNID pattern_id,
case UIA_InvokePatternId:
case UIA_SelectionItemPatternId:
case UIA_SelectionPatternId:
break;
case UIA_TogglePatternId:
if (SupportsToggle(data.role)) {
AddRef();
*result = static_cast<IRawElementProviderSimple*>(this);
}
break;
case UIA_ValuePatternId:
......@@ -2709,6 +2788,7 @@ STDMETHODIMP AXPlatformNodeWin::GetPatternProvider(PATTERNID pattern_id,
break;
case UIA_WindowPatternId:
break;
// Overlap with MSAA, not supported.
case UIA_AnnotationPatternId:
......
......@@ -241,10 +241,12 @@ class AX_EXPORT __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
public IAccessibleTable,
public IAccessibleTable2,
public IAccessibleTableCell,
public IExpandCollapseProvider,
public IRangeValueProvider,
public IRawElementProviderSimple,
public IScrollItemProvider,
public IServiceProvider,
public IToggleProvider,
public IValueProvider,
public AXPlatformNodeBase {
public:
......@@ -259,9 +261,11 @@ class AX_EXPORT __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
COM_INTERFACE_ENTRY(IAccessibleTable)
COM_INTERFACE_ENTRY(IAccessibleTable2)
COM_INTERFACE_ENTRY(IAccessibleTableCell)
COM_INTERFACE_ENTRY(IExpandCollapseProvider)
COM_INTERFACE_ENTRY(IRangeValueProvider)
COM_INTERFACE_ENTRY(IRawElementProviderSimple)
COM_INTERFACE_ENTRY(IScrollItemProvider)
COM_INTERFACE_ENTRY(IToggleProvider)
COM_INTERFACE_ENTRY(IValueProvider)
COM_INTERFACE_ENTRY(IServiceProvider)
END_COM_MAP()
......@@ -424,12 +428,30 @@ class AX_EXPORT __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
STDMETHODIMP GetIAccessiblePair(IAccessible** accessible,
LONG* child_id) override;
//
// IExpandCollapseProvider methods..
//
STDMETHODIMP Collapse() override;
STDMETHODIMP Expand() override;
STDMETHODIMP get_ExpandCollapseState(ExpandCollapseState* result) override;
//
// IScrollItemProvider methods.
//
STDMETHODIMP ScrollIntoView() override;
//
// IToggleProvider methods.
//
STDMETHODIMP Toggle() override;
STDMETHODIMP get_ToggleState(ToggleState* result) override;
//
// IValueProvider methods.
//
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment