Commit 4a17983f authored by Ojan Vafai's avatar Ojan Vafai Committed by Commit Bot

Revert "Emit state-changed:selected events for ATK on Aura Linux"

This reverts commit e966ecca.

Reason for revert: Broke two DumpAccessibilityEventsTest tests. See https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/linux-xenial-rel/3172 

Original change's description:
> Emit state-changed:selected events for ATK on Aura Linux
> 
> * Add an event notifier in AXPlatformNodeAuraLinux for browser chrome.
> * Check to see if focus should follow selection. If it should, also
>   emit state-changed:focused events.
> * Ensure that the correct states (focusable and selectable) wind up
>   in the state set of elements where focus should follow selection.
> * Forward events from Blink content to AXPlatformNodeAuraLinux.
> * Create an event listener so that DumpAccessibilityEventsTest tests
>   can be run. Add expectations for tests for which events are now
>   emitted. At the present time, that is only focus and selected.
> 
> R=​dmazzoni@google.com
> 
> Bug: 866340
> Change-Id: I0d3334c39b064afc75ac5e051969fb43a79a0d8a
> Reviewed-on: https://chromium-review.googlesource.com/1163724
> Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
> Reviewed-by: David Tseng <dtseng@chromium.org>
> Commit-Queue: Joanmarie Diggs <joanmarie.diggs@gmail.com>
> Cr-Commit-Position: refs/heads/master@{#589951}

TBR=dmazzoni@chromium.org,dtseng@chromium.org,aboxhall@chromium.org,nektar@chromium.org,aleventhal@chromium.org,joanmarie.diggs@gmail.com

Change-Id: If194799a765415ba34229b5315c54584021078e2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 866340
Reviewed-on: https://chromium-review.googlesource.com/1217069Reviewed-by: default avatarOjan Vafai <ojan@chromium.org>
Commit-Queue: Ojan Vafai <ojan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590002}
parent 7af1758a
......@@ -5,7 +5,6 @@
#include "content/browser/accessibility/accessibility_event_recorder.h"
#include "build/build_config.h"
#include "content/browser/accessibility/accessibility_buildflags.h"
#include "content/browser/accessibility/browser_accessibility_manager.h"
namespace content {
......@@ -17,7 +16,7 @@ AccessibilityEventRecorder::AccessibilityEventRecorder(
AccessibilityEventRecorder::~AccessibilityEventRecorder() = default;
#if !defined(OS_WIN) && !defined(OS_MACOSX) && !BUILDFLAG(USE_ATK)
#if !defined(OS_WIN) && !defined(OS_MACOSX)
// static
AccessibilityEventRecorder& AccessibilityEventRecorder::GetInstance(
BrowserAccessibilityManager* manager,
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/accessibility/accessibility_event_recorder.h"
#include <atk/atk.h>
#include <atk/atkutil.h>
#include "base/process/process_handle.h"
#include "base/strings/stringprintf.h"
#include "content/browser/accessibility/browser_accessibility_auralinux.h"
#include "content/browser/accessibility/browser_accessibility_manager.h"
namespace content {
class AccessibilityEventRecorderAuraLinux : public AccessibilityEventRecorder {
public:
explicit AccessibilityEventRecorderAuraLinux(
BrowserAccessibilityManager* manager,
base::ProcessId pid);
~AccessibilityEventRecorderAuraLinux() override;
void ProcessEvent(const char* event,
unsigned int n_params,
const GValue* params);
private:
void AddGlobalListeners();
void RemoveGlobalListeners();
std::vector<unsigned int> listener_ids_;
};
// static
gboolean OnEventReceived(GSignalInvocationHint* hint,
unsigned int n_params,
const GValue* params,
gpointer data) {
GSignalQuery query;
g_signal_query(hint->signal_id, &query);
static_cast<AccessibilityEventRecorderAuraLinux&>(
AccessibilityEventRecorder::GetInstance())
.ProcessEvent(query.signal_name, n_params, params);
return true;
}
// static
AccessibilityEventRecorder& AccessibilityEventRecorder::GetInstance(
BrowserAccessibilityManager* manager,
base::ProcessId pid) {
static base::NoDestructor<AccessibilityEventRecorderAuraLinux> instance(
manager, pid);
return *instance;
}
AccessibilityEventRecorderAuraLinux::AccessibilityEventRecorderAuraLinux(
BrowserAccessibilityManager* manager,
base::ProcessId pid)
: AccessibilityEventRecorder(manager, pid) {
AddGlobalListeners();
}
AccessibilityEventRecorderAuraLinux::~AccessibilityEventRecorderAuraLinux() {}
void AccessibilityEventRecorderAuraLinux::AddGlobalListeners() {
static constexpr size_t kArraySize = 2;
constexpr std::array<const char*, kArraySize> events{
{"ATK:AtkObject:state-change", "ATK:AtkObject:focus-event"}};
for (size_t i = 0; i < kArraySize; i++) {
unsigned int id = atk_add_global_event_listener(OnEventReceived, events[i]);
if (!id)
LOG(FATAL) << "atk_add_global_event_listener failed for " << events[i];
listener_ids_.push_back(id);
}
}
void AccessibilityEventRecorderAuraLinux::RemoveGlobalListeners() {
for (const auto& id : listener_ids_)
atk_remove_global_event_listener(id);
listener_ids_.clear();
}
void AccessibilityEventRecorderAuraLinux::ProcessEvent(const char* event,
unsigned int n_params,
const GValue* params) {
// If we don't have a root object, it means the tree is being destroyed.
if (!manager_->GetRoot()) {
RemoveGlobalListeners();
return;
}
std::string log = base::ToUpperASCII(event);
if (std::string(event).find("state-change") != std::string::npos) {
log += ":" + base::ToUpperASCII(g_value_get_string(&params[1]));
log += base::StringPrintf(":%s", g_strdup_value_contents(&params[2]));
}
AtkObject* obj = ATK_OBJECT(g_value_get_object(&params[0]));
std::string role = atk_role_get_name(atk_object_get_role(obj));
base::ReplaceChars(role, " ", "_", &role);
log += base::StringPrintf(" role=ROLE_%s", base::ToUpperASCII(role).c_str());
log += base::StringPrintf(" name='%s'", atk_object_get_name(obj));
std::string states = "";
AtkStateSet* state_set = atk_object_ref_state_set(obj);
for (int i = ATK_STATE_INVALID; i < ATK_STATE_LAST_DEFINED; i++) {
AtkStateType state_type = static_cast<AtkStateType>(i);
if (atk_state_set_contains_state(state_set, state_type)) {
states += " " + base::ToUpperASCII(atk_state_type_get_name(state_type));
}
}
states = base::CollapseWhitespaceASCII(states, false);
base::ReplaceChars(states, " ", ",", &states);
log += base::StringPrintf(" %s", states.c_str());
OnEvent(log);
}
} // namespace content
......@@ -60,23 +60,6 @@ void BrowserAccessibilityManagerAuraLinux::FireFocusEvent(
}
}
void BrowserAccessibilityManagerAuraLinux::FireSelectedEvent(
BrowserAccessibility* node) {
// Some browser UI widgets, such as the omnibox popup, only send notifications
// when they become selected. In contrast elements in a page, such as options
// in the select element, also send notifications when they become unselected.
// Since AXPlatformNodeAuraLinux must handle firing a platform event for the
// unselected case, we can safely ignore the unselected case for rendered
// elements.
if (!node->GetBoolAttribute(ax::mojom::BoolAttribute::kSelected))
return;
if (node->IsNative()) {
ToBrowserAccessibilityAuraLinux(node)->GetNode()->NotifyAccessibilityEvent(
ax::mojom::Event::kSelection);
}
}
void BrowserAccessibilityManagerAuraLinux::FireBlinkEvent(
ax::mojom::Event event_type,
BrowserAccessibility* node) {
......@@ -88,16 +71,7 @@ void BrowserAccessibilityManagerAuraLinux::FireGeneratedEvent(
AXEventGenerator::Event event_type,
BrowserAccessibility* node) {
BrowserAccessibilityManager::FireGeneratedEvent(event_type, node);
switch (event_type) {
case Event::MENU_ITEM_SELECTED:
case Event::SELECTED_CHANGED:
FireSelectedEvent(node);
break;
default:
// Need to implement.
break;
}
// Need to implement.
}
void BrowserAccessibilityManagerAuraLinux::OnAtomicUpdateFinished(
......
......@@ -34,8 +34,6 @@ class CONTENT_EXPORT BrowserAccessibilityManagerAuraLinux
void FireGeneratedEvent(AXEventGenerator::Event event_type,
BrowserAccessibility* node) override;
void FireSelectedEvent(BrowserAccessibility* node);
AtkObject* parent_object() { return parent_object_; }
protected:
......
......@@ -420,12 +420,6 @@ jumbo_static_library("test_support") {
]
}
if (use_atk) {
sources +=
[ "../browser/accessibility/accessibility_event_recorder_auralinux.cc" ]
configs += [ "//build/config/linux/atk" ]
}
if (use_glib) {
configs += [ "//build/config/linux:glib" ]
}
......
STATE-CHANGE:SELECTED:TRUE role=ROLE_LIST_ITEM name='Apple' ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE
FOCUS-EVENT role=ROLE_COMBO_BOX name='(null)' EDITABLE,ENABLED,EXPANDABLE,EXPANDED,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,SINGLE-LINE,VISIBLE,SUPPORTS-AUTOCOMPLETION,SELECTABLE-TEXT
FOCUS-EVENT role=ROLE_DOCUMENT_WEB name='(null)' ENABLED,FOCUSABLE,SENSITIVE,SHOWING,VISIBLE
STATE-CHANGE:FOCUSED:FALSE role=ROLE_DOCUMENT_WEB name='(null)' ENABLED,FOCUSABLE,SENSITIVE,SHOWING,VISIBLE
STATE-CHANGE:FOCUSED:TRUE role=ROLE_COMBO_BOX name='(null)' EDITABLE,ENABLED,EXPANDABLE,EXPANDED,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,SINGLE-LINE,VISIBLE,SUPPORTS-AUTOCOMPLETION,SELECTABLE-TEXT
STATE-CHANGE:SELECTED:TRUE role=ROLE_LIST_ITEM name='Banana' ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE
FOCUS-EVENT role=ROLE_DOCUMENT_WEB name='(null)' ENABLED,FOCUSABLE,SENSITIVE,SHOWING,VISIBLE
FOCUS-EVENT role=ROLE_LIST_BOX name='(null)' ENABLED,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,VERTICAL,VISIBLE
STATE-CHANGE:FOCUSED:FALSE role=ROLE_DOCUMENT_WEB name='(null)' ENABLED,FOCUSABLE,SENSITIVE,SHOWING,VISIBLE
STATE-CHANGE:FOCUSED:TRUE role=ROLE_LIST_BOX name='(null)' ENABLED,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,VERTICAL,VISIBLE
FOCUS-EVENT role=ROLE_LIST_BOX name='(null)' ENABLED,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,VERTICAL,VISIBLE
FOCUS-EVENT role=ROLE_LIST_ITEM name='Orange' ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE
STATE-CHANGE:FOCUSED:FALSE role=ROLE_LIST_BOX name='(null)' ENABLED,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,VERTICAL,VISIBLE
STATE-CHANGE:FOCUSED:TRUE role=ROLE_LIST_ITEM name='Orange' ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE
STATE-CHANGE:SELECTED:TRUE role=ROLE_LIST_ITEM name='Orange' ENABLED,FOCUSABLE,SELECTABLE,SELECTED,SENSITIVE,SHOWING,VISIBLE
FOCUS-EVENT role=ROLE_COMBO_BOX name='(null)' ENABLED,EXPANDABLE,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,VISIBLE
FOCUS-EVENT role=ROLE_DOCUMENT_WEB name='(null)' ENABLED,FOCUSABLE,SENSITIVE,SHOWING,VISIBLE
STATE-CHANGE:FOCUSED:FALSE role=ROLE_DOCUMENT_WEB name='(null)' ENABLED,FOCUSABLE,SENSITIVE,SHOWING,VISIBLE
STATE-CHANGE:FOCUSED:TRUE role=ROLE_COMBO_BOX name='(null)' ENABLED,EXPANDABLE,FOCUSABLE,FOCUSED,SENSITIVE,SHOWING,VISIBLE
......@@ -3,10 +3,10 @@
++++[list box] enabled
++++++[panel] name='Enabled' enabled xml-roles:group
++++++++[text] name='Enabled' enabled
++++++[list item] name='One' enabled selectable posinset:1 setsize:4
++++++[list item] name='Two' enabled selectable posinset:2 setsize:4
++++++[list item] name='Three' enabled selectable posinset:3 setsize:4
++++++[list item] name='Four' enabled selectable posinset:4 setsize:4
++++++[list item] name='One' enabled posinset:1 setsize:4
++++++[list item] name='Two' enabled posinset:2 setsize:4
++++++[list item] name='Three' enabled posinset:3 setsize:4
++++++[list item] name='Four' enabled posinset:4 setsize:4
++++++[panel] name='Disabled' enabled xml-roles:group
++++++++[text] name='Disabled' enabled
++++++[list item] name='One' posinset:1 setsize:4
......
......@@ -3,23 +3,23 @@
++++[combo box] expandable haspopup:menu
++++++[menu]
++++++++[menu item] name='Placeholder option' selectable selected posinset:1 setsize:3
++++++++[menu item] name='Option 1' selectable posinset:2 setsize:3
++++++++[menu item] name='Option 2' selectable posinset:3 setsize:3
++++++++[menu item] name='Option 1' posinset:2 setsize:3
++++++++[menu item] name='Option 2' posinset:3 setsize:3
++++[combo box] expandable haspopup:menu
++++++[menu]
++++++++[menu item] name='Option 1' selectable posinset:1 setsize:3
++++++++[menu item] name='Option 1' posinset:1 setsize:3
++++++++[menu item] name='Option 2' selectable selected posinset:2 setsize:3
++++++++[menu item] name='Option 3' selectable posinset:3 setsize:3
++++++++[menu item] name='Option 3' posinset:3 setsize:3
++++[combo box] expandable required haspopup:menu
++++++[menu]
++++++++[menu item] name='Option 1' selectable selected posinset:1 setsize:3
++++++++[menu item] name='Option 2' selectable posinset:2 setsize:3
++++++++[menu item] name='Option 3' selectable posinset:3 setsize:3
++++++++[menu item] name='Option 2' posinset:2 setsize:3
++++++++[menu item] name='Option 3' posinset:3 setsize:3
++++[list box] multiselectable
++++++[list item] name='Option 1' selectable posinset:1 setsize:3
++++++[list item] name='Option 2' selectable posinset:2 setsize:3
++++++[list item] name='Option 3' selectable posinset:3 setsize:3
++++++[list item] name='Option 1' posinset:1 setsize:3
++++++[list item] name='Option 2' posinset:2 setsize:3
++++++[list item] name='Option 3' posinset:3 setsize:3
++++[list box]
++++++[list item] name='Option 1' selectable posinset:1 setsize:3
++++++[list item] name='Option 2' selectable posinset:2 setsize:3
++++++[list item] name='Option 3' selectable posinset:3 setsize:3
++++++[list item] name='Option 1' posinset:1 setsize:3
++++++[list item] name='Option 2' posinset:2 setsize:3
++++++[list item] name='Option 3' posinset:3 setsize:3
......@@ -1434,8 +1434,7 @@ void AXPlatformNodeAuraLinux::GetAtkState(AtkStateSet* atk_state_set) {
atk_state_set_add_state(atk_state_set, ATK_STATE_EXPANDABLE);
atk_state_set_add_state(atk_state_set, ATK_STATE_EXPANDED);
}
if (data.HasState(ax::mojom::State::kFocusable) ||
SelectionAndFocusAreTheSame())
if (data.HasState(ax::mojom::State::kFocusable))
atk_state_set_add_state(atk_state_set, ATK_STATE_FOCUSABLE);
if (data.HasState(ax::mojom::State::kHorizontal))
atk_state_set_add_state(atk_state_set, ATK_STATE_HORIZONTAL);
......@@ -1466,11 +1465,10 @@ void AXPlatformNodeAuraLinux::GetAtkState(AtkStateSet* atk_state_set) {
atk_state_set_add_state(atk_state_set, ATK_STATE_BUSY);
if (data.GetBoolAttribute(ax::mojom::BoolAttribute::kModal))
atk_state_set_add_state(atk_state_set, ATK_STATE_MODAL);
if (data.HasBoolAttribute(ax::mojom::BoolAttribute::kSelected))
if (data.GetBoolAttribute(ax::mojom::BoolAttribute::kSelected)) {
atk_state_set_add_state(atk_state_set, ATK_STATE_SELECTABLE);
if (data.GetBoolAttribute(ax::mojom::BoolAttribute::kSelected))
atk_state_set_add_state(atk_state_set, ATK_STATE_SELECTED);
}
if (IsPlainTextField() || IsRichTextField()) {
atk_state_set_add_state(atk_state_set, ATK_STATE_SELECTABLE_TEXT);
if (data.HasState(ax::mojom::State::kMultiline))
......@@ -1525,10 +1523,7 @@ void AXPlatformNodeAuraLinux::GetAtkRelations(
}
AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux()
: interface_mask_(0),
atk_object_(nullptr),
atk_hyperlink_(nullptr),
weak_factory_(this) {}
: interface_mask_(0), atk_object_(nullptr), atk_hyperlink_(nullptr) {}
AXPlatformNodeAuraLinux::~AXPlatformNodeAuraLinux() {
DestroyAtkObjects();
......@@ -1615,52 +1610,6 @@ void AXPlatformNodeAuraLinux::OnFocused() {
true);
}
base::WeakPtr<AXPlatformNodeAuraLinux>
AXPlatformNodeAuraLinux::current_selected_ = nullptr;
void AXPlatformNodeAuraLinux::OnSelected() {
if (current_selected_ && !current_selected_->GetData().GetBoolAttribute(
ax::mojom::BoolAttribute::kSelected)) {
atk_object_notify_state_change(ATK_OBJECT(current_selected_->atk_object_),
ATK_STATE_SELECTED, false);
}
current_selected_ = weak_factory_.GetWeakPtr();
if (ATK_IS_OBJECT(atk_object_)) {
atk_object_notify_state_change(ATK_OBJECT(atk_object_), ATK_STATE_SELECTED,
true);
}
if (SelectionAndFocusAreTheSame())
OnFocused();
}
bool AXPlatformNodeAuraLinux::SelectionAndFocusAreTheSame() {
if (AXPlatformNodeBase* container = GetSelectionContainer()) {
ax::mojom::Role role = container->GetData().role;
if (role == ax::mojom::Role::kMenuBar || role == ax::mojom::Role::kMenu)
return true;
if (role == ax::mojom::Role::kListBox &&
!container->GetData().HasState(ax::mojom::State::kMultiselectable)) {
return container->GetDelegate()->GetFocus() ==
container->GetNativeViewAccessible();
}
}
// TODO(accessibility): GetSelectionContainer returns nullptr when the current
// object is a descendant of a select element with a size of 1. Intentional?
// For now, handle that scenario here.
//
// If the selection is changing on a collapsed select element, focus remains
// on the select element and not the newly-selected descendant.
if (AXPlatformNodeBase* parent = FromNativeViewAccessible(GetParent())) {
if (parent->GetData().role == ax::mojom::Role::kMenuListPopup)
return !parent->GetData().HasState(ax::mojom::State::kInvisible);
}
return false;
}
void AXPlatformNodeAuraLinux::NotifyAccessibilityEvent(
ax::mojom::Event event_type) {
switch (event_type) {
......@@ -1668,9 +1617,6 @@ void AXPlatformNodeAuraLinux::NotifyAccessibilityEvent(
case ax::mojom::Event::kFocusContext:
OnFocused();
break;
case ax::mojom::Event::kSelection:
OnSelected();
break;
default:
break;
}
......
......@@ -77,9 +77,6 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// Event helpers
void OnFocused();
void OnSelected();
bool SelectionAndFocusAreTheSame();
// AXPlatformNode overrides.
gfx::NativeViewAccessible GetNativeViewAccessible() override;
......@@ -136,13 +133,6 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// to emit the ATK_STATE_FOCUSED change to false.
static AtkObject* current_focused_;
// The last object which was selected. Tracking this is required because
// widgets in the browser UI only emit notifications upon becoming selected,
// but clients also expect notifications when items become unselected.
static base::WeakPtr<AXPlatformNodeAuraLinux> current_selected_;
base::WeakPtrFactory<AXPlatformNodeAuraLinux> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AXPlatformNodeAuraLinux);
};
......
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