blob: 63caa6e4d38663525ac1ead01ee38f7325aac40c [file] [log] [blame]
// Copyright 2015 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.
#ifndef UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_AURALINUX_H_
#define UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_AURALINUX_H_
#include <atk/atk.h>
#include <string>
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/utf_offset_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_export.h"
#include "ui/accessibility/platform/ax_platform_node_base.h"
// Some ATK interfaces require returning a (const gchar*), use
// this macro to make it safe to return a pointer to a temporary
// string.
#define ATK_AURALINUX_RETURN_STRING(str_expr) \
{ \
static std::string result; \
result = (str_expr); \
return result.c_str(); \
}
namespace ui {
// Implements accessibility on Aura Linux using ATK.
class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
public:
AXPlatformNodeAuraLinux();
~AXPlatformNodeAuraLinux() override;
// 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();
static void EnsureGTypeInit();
// Do asynchronous static initialization.
static void StaticInitialize();
void DataChanged();
void Destroy() override;
void AddAccessibilityTreeProperties(base::DictionaryValue* dict);
AtkRole GetAtkRole();
void GetAtkState(AtkStateSet* state_set);
AtkRelationSet* GetAtkRelations();
void GetExtents(gint* x, gint* y, gint* width, gint* height,
AtkCoordType coord_type);
void GetPosition(gint* x, gint* y, AtkCoordType coord_type);
void GetSize(gint* width, gint* height);
gfx::NativeViewAccessible HitTestSync(gint x,
gint y,
AtkCoordType coord_type);
bool GrabFocus();
bool DoDefaultAction();
const gchar* GetDefaultActionName();
AtkAttributeSet* GetAtkAttributes();
void SetExtentsRelativeToAtkCoordinateType(
gint* x, gint* y, gint* width, gint* height,
AtkCoordType coord_type);
// AtkDocument helpers
const gchar* GetDocumentAttributeValue(const gchar* attribute) const;
AtkAttributeSet* GetDocumentAttributes() const;
// AtkHyperlink helpers
AtkHyperlink* GetAtkHyperlink();
// Misc helpers
void GetFloatAttributeInGValue(ax::mojom::FloatAttribute attr, GValue* value);
// Event helpers
void OnCheckedStateChanged();
void OnExpandedStateChanged(bool is_expanded);
void OnFocused();
void OnWindowActivated();
void OnWindowDeactivated();
void OnMenuPopupStart();
void OnMenuPopupHide();
void OnMenuPopupEnd();
void OnSelected();
void OnSelectedChildrenChanged();
void OnValueChanged();
bool SupportsSelectionWithAtkSelection();
bool SelectionAndFocusAreTheSame();
// AXPlatformNode overrides.
gfx::NativeViewAccessible GetNativeViewAccessible() override;
void NotifyAccessibilityEvent(ax::mojom::Event event_type) override;
// AXPlatformNodeBase overrides.
void Init(AXPlatformNodeDelegate* delegate) override;
int GetIndexInParent() override;
base::string16 GetText() const override;
void UpdateHypertext();
const AXHypertext& GetHypertext();
const base::OffsetAdjuster::Adjustments& GetHypertextAdjustments();
size_t UTF16ToUnicodeOffsetInText(size_t utf16_offset);
size_t UnicodeToUTF16OffsetInText(size_t unicode_offset);
void SetEmbeddedDocument(AtkObject* new_document);
void SetEmbeddingWindow(AtkObject* new_embedding_window);
protected:
AXHypertext hypertext_;
// Offsets for the AtkText API are calculated in UTF-16 code point offsets,
// but the ATK APIs want all offsets to be in "characters," which we
// understand to be Unicode character offsets. We keep a lazily generated set
// of Adjustments to convert between UTF-16 and Unicode character offsets.
base::Optional<base::OffsetAdjuster::Adjustments> text_unicode_adjustments_ =
base::nullopt;
void AddAttributeToList(const char* name,
const char* value,
PlatformAttributeList* attributes) override;
private:
enum AtkInterfaces {
ATK_ACTION_INTERFACE,
ATK_COMPONENT_INTERFACE,
ATK_DOCUMENT_INTERFACE,
ATK_EDITABLE_TEXT_INTERFACE,
ATK_HYPERLINK_INTERFACE,
ATK_HYPERTEXT_INTERFACE,
ATK_IMAGE_INTERFACE,
ATK_SELECTION_INTERFACE,
ATK_TABLE_INTERFACE,
ATK_TEXT_INTERFACE,
ATK_VALUE_INTERFACE,
ATK_WINDOW_INTERFACE,
};
int GetGTypeInterfaceMask();
GType GetAccessibilityGType();
AtkObject* CreateAtkObject();
void DestroyAtkObjects();
void AddRelationToSet(AtkRelationSet*,
AtkRelationType,
AXPlatformNode* target);
// The AtkStateType for a checkable node can vary depending on the role.
AtkStateType GetAtkStateTypeForCheckableNode();
// Keep information of latest AtkInterfaces mask to refresh atk object
// interfaces accordingly if needed.
int interface_mask_ = 0;
// We own a reference to these ref-counted objects.
AtkObject* atk_object_ = nullptr;
AtkHyperlink* atk_hyperlink_ = nullptr;
// Some weak pointers which help us track ATK embeds / embedded by relations.
AtkObject* embedded_document_ = nullptr;
AtkObject* embedding_window_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(AXPlatformNodeAuraLinux);
};
} // namespace ui
#endif // UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_AURALINUX_H_