Commit cafca941 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Fix nits in AXPlatformNodeAuraLinux.

- Initialize members in the header.
- Move static members / functions into an anonymous namespace.
- Make a const char* array const.

Change-Id: Iba2de156748c7618908b08031dca10f5c8ab1fdc
Reviewed-on: https://chromium-review.googlesource.com/c/1294846
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601814}
parent a27462d7
......@@ -52,7 +52,7 @@ typedef struct _AXPlatformNodeAuraLinuxClass AXPlatformNodeAuraLinuxClass;
// TODO(aleventhal) Remove this and use atk_role_get_name() once the following
// GNOME bug is fixed: https://bugzilla.gnome.org/show_bug.cgi?id=795983
const char* role_names[] = {
const char* const kRoleNames[] = {
"invalid", // ATK_ROLE_INVALID.
"accelerator label",
"alert",
......@@ -1035,25 +1035,19 @@ G_END_DECLS
namespace {
// The root-level Application object that's the parent of all top-level windows.
AXPlatformNode* g_root_application = nullptr;
// The last AtkObject with keyboard focus. Tracking this is required to emit the
// ATK_STATE_FOCUSED change to false.
AtkObject* g_current_focused = nullptr;
// 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.
AXPlatformNodeAuraLinux* g_current_selected = nullptr;
} // namespace
void AXPlatformNodeAuraLinux::EnsureGTypeInit() {
#if !GLIB_CHECK_VERSION(2, 36, 0)
static bool first_time = true;
if (UNLIKELY(first_time)) {
g_type_init();
first_time = false;
}
#endif
}
const char* AXPlatformNodeAuraLinux::GetUniqueAccessibilityGTypeName(
int interface_mask) {
const char* GetUniqueAccessibilityGTypeName(int interface_mask) {
// 37 characters is enough for "AXPlatformNodeAuraLinux%x" with any integer
// value.
static char name[37];
......@@ -1061,12 +1055,24 @@ const char* AXPlatformNodeAuraLinux::GetUniqueAccessibilityGTypeName(
return name;
}
static bool IsRoleWithValueInterface(AtkRole role) {
bool IsRoleWithValueInterface(AtkRole role) {
return role == ATK_ROLE_SCROLL_BAR || role == ATK_ROLE_SLIDER ||
role == ATK_ROLE_PROGRESS_BAR || role == ATK_ROLE_SEPARATOR ||
role == ATK_ROLE_SPIN_BUTTON;
}
} // namespace
void AXPlatformNodeAuraLinux::EnsureGTypeInit() {
#if !GLIB_CHECK_VERSION(2, 36, 0)
static bool first_time = true;
if (UNLIKELY(first_time)) {
g_type_init();
first_time = false;
}
#endif
}
int AXPlatformNodeAuraLinux::GetGTypeInterfaceMask() {
int interface_mask = 0;
......@@ -1167,8 +1173,8 @@ void AXPlatformNodeAuraLinux::DestroyAtkObjects() {
atk_hyperlink_ = nullptr;
}
if (atk_object_) {
if (atk_object_ == current_focused_)
current_focused_ = nullptr;
if (atk_object_ == g_current_focused)
g_current_focused = nullptr;
AXPlatformNodeAuraLinuxDetach(AX_PLATFORM_NODE_AURALINUX(atk_object_));
g_object_unref(atk_object_);
atk_object_ = nullptr;
......@@ -1209,11 +1215,13 @@ AXPlatformNodeAuraLinux* AXPlatformNodeAuraLinux::GetFromUniqueId(
//
// static
AXPlatformNode* AXPlatformNodeAuraLinux::application_ = nullptr;
void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) {
g_root_application = application;
}
// static
void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) {
application_ = application;
AXPlatformNode* AXPlatformNodeAuraLinux::application() {
return g_root_application;
}
// static
......@@ -1693,11 +1701,7 @@ void AXPlatformNodeAuraLinux::GetAtkRelations(
AtkRelationSet* atk_relation_set) {
}
AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux()
: interface_mask_(0),
atk_object_(nullptr),
atk_hyperlink_(nullptr),
weak_factory_(this) {}
AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux() : weak_factory_(this) {}
AXPlatformNodeAuraLinux::~AXPlatformNodeAuraLinux() {
if (g_current_selected == this)
......@@ -1740,7 +1744,7 @@ void AXPlatformNodeAuraLinux::AddAccessibilityTreeProperties(
AtkRole role = GetAtkRole();
if (role != ATK_ROLE_UNKNOWN) {
int role_index = static_cast<int>(role);
dict->SetString("role", role_names[role_index]);
dict->SetString("role", kRoleNames[role_index]);
}
const gchar* name = atk_object_get_name(atk_object_);
if (name)
......@@ -1785,21 +1789,19 @@ void AXPlatformNodeAuraLinux::OnExpandedStateChanged(bool is_expanded) {
is_expanded);
}
AtkObject* AXPlatformNodeAuraLinux::current_focused_ = nullptr;
void AXPlatformNodeAuraLinux::OnFocused() {
DCHECK(atk_object_);
if (atk_object_ == current_focused_)
if (atk_object_ == g_current_focused)
return;
if (current_focused_) {
g_signal_emit_by_name(current_focused_, "focus-event", false);
atk_object_notify_state_change(ATK_OBJECT(current_focused_),
if (g_current_focused) {
g_signal_emit_by_name(g_current_focused, "focus-event", false);
atk_object_notify_state_change(ATK_OBJECT(g_current_focused),
ATK_STATE_FOCUSED, false);
}
current_focused_ = atk_object_;
g_current_focused = atk_object_;
g_signal_emit_by_name(atk_object_, "focus-event", true);
atk_object_notify_state_change(ATK_OBJECT(atk_object_), ATK_STATE_FOCUSED,
true);
......
......@@ -35,7 +35,7 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// Set or get the root-level Application object that's the parent of all
// top-level windows.
static void SetApplication(AXPlatformNode* application);
static AXPlatformNode* application() { return application_; }
static AXPlatformNode* application();
static void EnsureGTypeInit();
......@@ -120,7 +120,7 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
ATK_TEXT_INTERFACE,
ATK_VALUE_INTERFACE,
};
static const char* GetUniqueAccessibilityGTypeName(int interface_mask);
int GetGTypeInterfaceMask();
GType GetAccessibilityGType();
AtkObject* CreateAtkObject();
......@@ -131,19 +131,11 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// Keep information of latest AtkInterfaces mask to refresh atk object
// interfaces accordingly if needed.
int interface_mask_;
int interface_mask_ = 0;
// We own a reference to these ref-counted objects.
AtkObject* atk_object_;
AtkHyperlink* atk_hyperlink_;
// The root-level Application object that's the parent of all
// top-level windows.
static AXPlatformNode* application_;
// The last AtkObject with keyboard focus. Tracking this is required
// to emit the ATK_STATE_FOCUSED change to false.
static AtkObject* current_focused_;
AtkObject* atk_object_ = nullptr;
AtkHyperlink* atk_hyperlink_ = nullptr;
base::WeakPtrFactory<AXPlatformNodeAuraLinux> weak_factory_;
......
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