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; ...@@ -52,7 +52,7 @@ typedef struct _AXPlatformNodeAuraLinuxClass AXPlatformNodeAuraLinuxClass;
// TODO(aleventhal) Remove this and use atk_role_get_name() once the following // 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 // 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. "invalid", // ATK_ROLE_INVALID.
"accelerator label", "accelerator label",
"alert", "alert",
...@@ -1035,25 +1035,19 @@ G_END_DECLS ...@@ -1035,25 +1035,19 @@ G_END_DECLS
namespace { 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 // The last object which was selected. Tracking this is required because
// widgets in the browser UI only emit notifications upon becoming selected, // widgets in the browser UI only emit notifications upon becoming selected,
// but clients also expect notifications when items become unselected. // but clients also expect notifications when items become unselected.
AXPlatformNodeAuraLinux* g_current_selected = nullptr; AXPlatformNodeAuraLinux* g_current_selected = nullptr;
} // namespace const char* GetUniqueAccessibilityGTypeName(int interface_mask) {
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) {
// 37 characters is enough for "AXPlatformNodeAuraLinux%x" with any integer // 37 characters is enough for "AXPlatformNodeAuraLinux%x" with any integer
// value. // value.
static char name[37]; static char name[37];
...@@ -1061,12 +1055,24 @@ const char* AXPlatformNodeAuraLinux::GetUniqueAccessibilityGTypeName( ...@@ -1061,12 +1055,24 @@ const char* AXPlatformNodeAuraLinux::GetUniqueAccessibilityGTypeName(
return name; return name;
} }
static bool IsRoleWithValueInterface(AtkRole role) { bool IsRoleWithValueInterface(AtkRole role) {
return role == ATK_ROLE_SCROLL_BAR || role == ATK_ROLE_SLIDER || return role == ATK_ROLE_SCROLL_BAR || role == ATK_ROLE_SLIDER ||
role == ATK_ROLE_PROGRESS_BAR || role == ATK_ROLE_SEPARATOR || role == ATK_ROLE_PROGRESS_BAR || role == ATK_ROLE_SEPARATOR ||
role == ATK_ROLE_SPIN_BUTTON; 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 AXPlatformNodeAuraLinux::GetGTypeInterfaceMask() {
int interface_mask = 0; int interface_mask = 0;
...@@ -1167,8 +1173,8 @@ void AXPlatformNodeAuraLinux::DestroyAtkObjects() { ...@@ -1167,8 +1173,8 @@ void AXPlatformNodeAuraLinux::DestroyAtkObjects() {
atk_hyperlink_ = nullptr; atk_hyperlink_ = nullptr;
} }
if (atk_object_) { if (atk_object_) {
if (atk_object_ == current_focused_) if (atk_object_ == g_current_focused)
current_focused_ = nullptr; g_current_focused = nullptr;
AXPlatformNodeAuraLinuxDetach(AX_PLATFORM_NODE_AURALINUX(atk_object_)); AXPlatformNodeAuraLinuxDetach(AX_PLATFORM_NODE_AURALINUX(atk_object_));
g_object_unref(atk_object_); g_object_unref(atk_object_);
atk_object_ = nullptr; atk_object_ = nullptr;
...@@ -1209,11 +1215,13 @@ AXPlatformNodeAuraLinux* AXPlatformNodeAuraLinux::GetFromUniqueId( ...@@ -1209,11 +1215,13 @@ AXPlatformNodeAuraLinux* AXPlatformNodeAuraLinux::GetFromUniqueId(
// //
// static // static
AXPlatformNode* AXPlatformNodeAuraLinux::application_ = nullptr; void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) {
g_root_application = application;
}
// static // static
void AXPlatformNodeAuraLinux::SetApplication(AXPlatformNode* application) { AXPlatformNode* AXPlatformNodeAuraLinux::application() {
application_ = application; return g_root_application;
} }
// static // static
...@@ -1693,11 +1701,7 @@ void AXPlatformNodeAuraLinux::GetAtkRelations( ...@@ -1693,11 +1701,7 @@ void AXPlatformNodeAuraLinux::GetAtkRelations(
AtkRelationSet* atk_relation_set) { AtkRelationSet* atk_relation_set) {
} }
AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux() AXPlatformNodeAuraLinux::AXPlatformNodeAuraLinux() : weak_factory_(this) {}
: interface_mask_(0),
atk_object_(nullptr),
atk_hyperlink_(nullptr),
weak_factory_(this) {}
AXPlatformNodeAuraLinux::~AXPlatformNodeAuraLinux() { AXPlatformNodeAuraLinux::~AXPlatformNodeAuraLinux() {
if (g_current_selected == this) if (g_current_selected == this)
...@@ -1740,7 +1744,7 @@ void AXPlatformNodeAuraLinux::AddAccessibilityTreeProperties( ...@@ -1740,7 +1744,7 @@ void AXPlatformNodeAuraLinux::AddAccessibilityTreeProperties(
AtkRole role = GetAtkRole(); AtkRole role = GetAtkRole();
if (role != ATK_ROLE_UNKNOWN) { if (role != ATK_ROLE_UNKNOWN) {
int role_index = static_cast<int>(role); 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_); const gchar* name = atk_object_get_name(atk_object_);
if (name) if (name)
...@@ -1785,21 +1789,19 @@ void AXPlatformNodeAuraLinux::OnExpandedStateChanged(bool is_expanded) { ...@@ -1785,21 +1789,19 @@ void AXPlatformNodeAuraLinux::OnExpandedStateChanged(bool is_expanded) {
is_expanded); is_expanded);
} }
AtkObject* AXPlatformNodeAuraLinux::current_focused_ = nullptr;
void AXPlatformNodeAuraLinux::OnFocused() { void AXPlatformNodeAuraLinux::OnFocused() {
DCHECK(atk_object_); DCHECK(atk_object_);
if (atk_object_ == current_focused_) if (atk_object_ == g_current_focused)
return; return;
if (current_focused_) { if (g_current_focused) {
g_signal_emit_by_name(current_focused_, "focus-event", false); g_signal_emit_by_name(g_current_focused, "focus-event", false);
atk_object_notify_state_change(ATK_OBJECT(current_focused_), atk_object_notify_state_change(ATK_OBJECT(g_current_focused),
ATK_STATE_FOCUSED, false); ATK_STATE_FOCUSED, false);
} }
current_focused_ = atk_object_; g_current_focused = atk_object_;
g_signal_emit_by_name(atk_object_, "focus-event", true); g_signal_emit_by_name(atk_object_, "focus-event", true);
atk_object_notify_state_change(ATK_OBJECT(atk_object_), ATK_STATE_FOCUSED, atk_object_notify_state_change(ATK_OBJECT(atk_object_), ATK_STATE_FOCUSED,
true); true);
......
...@@ -35,7 +35,7 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase { ...@@ -35,7 +35,7 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// Set or get the root-level Application object that's the parent of all // Set or get the root-level Application object that's the parent of all
// top-level windows. // top-level windows.
static void SetApplication(AXPlatformNode* application); static void SetApplication(AXPlatformNode* application);
static AXPlatformNode* application() { return application_; } static AXPlatformNode* application();
static void EnsureGTypeInit(); static void EnsureGTypeInit();
...@@ -120,7 +120,7 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase { ...@@ -120,7 +120,7 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
ATK_TEXT_INTERFACE, ATK_TEXT_INTERFACE,
ATK_VALUE_INTERFACE, ATK_VALUE_INTERFACE,
}; };
static const char* GetUniqueAccessibilityGTypeName(int interface_mask);
int GetGTypeInterfaceMask(); int GetGTypeInterfaceMask();
GType GetAccessibilityGType(); GType GetAccessibilityGType();
AtkObject* CreateAtkObject(); AtkObject* CreateAtkObject();
...@@ -131,19 +131,11 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase { ...@@ -131,19 +131,11 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// Keep information of latest AtkInterfaces mask to refresh atk object // Keep information of latest AtkInterfaces mask to refresh atk object
// interfaces accordingly if needed. // interfaces accordingly if needed.
int interface_mask_; int interface_mask_ = 0;
// We own a reference to these ref-counted objects. // We own a reference to these ref-counted objects.
AtkObject* atk_object_; AtkObject* atk_object_ = nullptr;
AtkHyperlink* atk_hyperlink_; AtkHyperlink* atk_hyperlink_ = nullptr;
// 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_;
base::WeakPtrFactory<AXPlatformNodeAuraLinux> weak_factory_; 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