mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-02-17 06:56:24 +00:00
support accessibility one
Signed-off-by: dujingcheng <dujingcheng@huawei.com>
This commit is contained in:
parent
72b868b234
commit
3d1e7e2226
61
frameworks/core/accessibility/accessibility_provider.h
Normal file
61
frameworks/core/accessibility/accessibility_provider.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_ACCESSIBILITY_PROVIDER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_ACCESSIBILITY_PROVIDER_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "core/accessibility/native_interface_accessibility_impl.h"
|
||||
#include "core/accessibility/third_accessibility_manager.h"
|
||||
|
||||
namespace OHOS::Accessibility {
|
||||
class AccessibilityElementInfo;
|
||||
class AccessibilityEventInfo;
|
||||
} // namespace OHOS::Accessibility
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class AccessibilityProvider : public AceType {
|
||||
DECLARE_ACE_TYPE(AccessibilityProvider, AceType);
|
||||
public:
|
||||
virtual int32_t FindAccessibilityNodeInfosById(
|
||||
const int64_t elementId, const int32_t mode, const int32_t requestId,
|
||||
std::vector<ArkUI_AccessibilityElementInfo>& infos) = 0;
|
||||
virtual int32_t FindAccessibilityNodeInfosByText(
|
||||
const int64_t elementId, std::string text, const int32_t requestId,
|
||||
std::vector<ArkUI_AccessibilityElementInfo>& infos) = 0;
|
||||
virtual int32_t FindFocusedAccessibilityNode(
|
||||
const int64_t elementId, int32_t focusType, const int32_t requestId,
|
||||
ArkUI_AccessibilityElementInfo& elementInfo) = 0;
|
||||
virtual int32_t FindNextFocusAccessibilityNode(
|
||||
const int64_t elementId, int32_t direction, const int32_t requestId,
|
||||
ArkUI_AccessibilityElementInfo& elementInfo) = 0;
|
||||
virtual int32_t ExecuteAccessibilityAction(
|
||||
const int64_t elementId, int32_t action, const int32_t requestId,
|
||||
const std::map<std::string, std::string>& actionArguments) = 0;
|
||||
virtual int32_t ClearFocusedAccessibilityNode() = 0;
|
||||
virtual int32_t GetAccessibilityNodeCursorPosition(
|
||||
const int64_t elementId, const int32_t requestId, int32_t &cursorPosition) = 0;
|
||||
virtual int32_t SendAccessibilityAsyncEvent(
|
||||
const ArkUI_AccessibilityEventInfo& accessibilityEvent,
|
||||
void (*callback)(int32_t errorCode)) = 0;
|
||||
virtual void SendThirdAccessibilityProvider(
|
||||
const std::weak_ptr<ThirdAccessibilityManager>& thirdAccessibilityManager) {};
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_ACCESSIBILITY_PROVIDER_H
|
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "core/accessibility/native_interface_accessibility_impl.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "base/log/log.h"
|
||||
|
||||
ArkUI_AccessibilityElementInfo::ArkUI_AccessibilityElementInfo()
|
||||
{
|
||||
screenRect.leftTopX = 0;
|
||||
screenRect.leftTopY = 0;
|
||||
screenRect.rightBottomX = 0;
|
||||
screenRect.rightBottomY = 0;
|
||||
|
||||
rangeInfo.current = 0;
|
||||
rangeInfo.max = 0;
|
||||
rangeInfo.min = 0;
|
||||
|
||||
grid.columnCount = 0;
|
||||
grid.rowCount = 0;
|
||||
grid.selectionMode = 0;
|
||||
|
||||
gridItem.columnIndex = 0;
|
||||
gridItem.rowIndex = 0;
|
||||
gridItem.columnSpan = 0;
|
||||
gridItem.rowSpan = 0;
|
||||
gridItem.heading = false;
|
||||
gridItem.selected = false;
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::SetRect(const ArkUI_AccessibleRect& rect)
|
||||
{
|
||||
this->screenRect = rect;
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::SetRangeInfo(const ArkUI_AccessibleRangeInfo& rangeInfo)
|
||||
{
|
||||
this->rangeInfo = rangeInfo;
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::SetGridInfo(const ArkUI_AccessibleGridInfo& gridInfo)
|
||||
{
|
||||
this->grid = gridInfo;
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::SetGridItemInfo(const ArkUI_AccessibleGridItemInfo& gridItemInfo)
|
||||
{
|
||||
this->gridItem = gridItemInfo;
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::ClearChildNodeIds()
|
||||
{
|
||||
childNodeIds.clear();
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::AddChildNodeId(int64_t childNodeId)
|
||||
{
|
||||
childNodeIds.push_back(childNodeId);
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::ClearOperationActions()
|
||||
{
|
||||
operationActions.clear();
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityElementInfo::AddOperationAction(const ArkUI_AccessibleAction& action)
|
||||
{
|
||||
operationActions.push_back(action);
|
||||
}
|
||||
|
||||
ArkUI_AccessibilityElementInfo* ArkUI_AccessibilityElementInfoList::AddAndGetElementInfo()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
elementInfos_.push_back(ArkUI_AccessibilityElementInfo());
|
||||
return &elementInfos_.back();
|
||||
}
|
||||
|
||||
bool ArkUI_AccessibilityElementInfoList::CopyAccessibilityElementInfo(
|
||||
std::vector<ArkUI_AccessibilityElementInfo>& infos)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (elementInfos_.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::copy(elementInfos_.begin(), elementInfos_.end(), std::back_inserter(infos));
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* ArkUI_AccessibilityActionArguments::FindValueByKey(const char* key)
|
||||
{
|
||||
auto iter = actionArguments_.find(key);
|
||||
if (iter == actionArguments_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return iter->second.c_str();
|
||||
}
|
@ -0,0 +1,588 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_NATIVE_INTERFACE_ACCESSIBILITY_IMPL_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_NATIVE_INTERFACE_ACCESSIBILITY_IMPL_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "interfaces/native/native_interface_accessibility.h"
|
||||
|
||||
#include "base/utils/singleton.h"
|
||||
|
||||
struct ArkUI_AccessibilityElementInfo {
|
||||
explicit ArkUI_AccessibilityElementInfo();
|
||||
void SetPageId(int32_t pageId)
|
||||
{
|
||||
this->pageId = pageId;
|
||||
}
|
||||
|
||||
int32_t GetPageId() const
|
||||
{
|
||||
return pageId;
|
||||
}
|
||||
|
||||
void SetParentId(int64_t parentId)
|
||||
{
|
||||
this->parentId = parentId;
|
||||
}
|
||||
|
||||
int64_t GetParentId() const
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
|
||||
int32_t GetElementId() const
|
||||
{
|
||||
return elementId;
|
||||
}
|
||||
|
||||
void SetElementId(int64_t elementId)
|
||||
{
|
||||
this->elementId = elementId;
|
||||
}
|
||||
|
||||
void SetComponentId(int64_t componentId)
|
||||
{
|
||||
this->componentId = componentId;
|
||||
}
|
||||
|
||||
int64_t GetComponentId() const
|
||||
{
|
||||
return componentId;
|
||||
}
|
||||
|
||||
void SetTextBeginSelected(int32_t textBeginSelected)
|
||||
{
|
||||
this->textBeginSelected = textBeginSelected;
|
||||
}
|
||||
|
||||
int32_t GetTextBeginSelected() const
|
||||
{
|
||||
return textBeginSelected;
|
||||
}
|
||||
|
||||
void SetTextEndSelected(int32_t textEndSelected)
|
||||
{
|
||||
this->textEndSelected = textEndSelected;
|
||||
}
|
||||
|
||||
int32_t GetTextEndSelected() const
|
||||
{
|
||||
return textEndSelected;
|
||||
}
|
||||
|
||||
void SetCurrentIndex(int32_t currentIndex)
|
||||
{
|
||||
this->currentIndex = currentIndex;
|
||||
}
|
||||
|
||||
int32_t GetCurrentIndex() const
|
||||
{
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
void SetBeginIndex(int32_t beginIndex)
|
||||
{
|
||||
this->beginIndex = beginIndex;
|
||||
}
|
||||
|
||||
int32_t GetBeginIndex() const
|
||||
{
|
||||
return beginIndex;
|
||||
}
|
||||
|
||||
void SetEndIndex(int32_t endIndex)
|
||||
{
|
||||
this->endIndex = endIndex;
|
||||
}
|
||||
|
||||
int32_t GetEndIndex() const
|
||||
{
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
void SetItemCount(int32_t itemCount)
|
||||
{
|
||||
this->itemCount = itemCount;
|
||||
}
|
||||
|
||||
int32_t GetItemCount() const
|
||||
{
|
||||
return itemCount;
|
||||
}
|
||||
|
||||
void SetOffset(int32_t offset)
|
||||
{
|
||||
this->offset = offset;
|
||||
}
|
||||
|
||||
int32_t GetOffset() const
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
void SetZIndex(int32_t zIndex)
|
||||
{
|
||||
this->zIndex = zIndex;
|
||||
}
|
||||
|
||||
int32_t GetZIndex() const
|
||||
{
|
||||
return zIndex;
|
||||
}
|
||||
|
||||
void SetOpacity(float opacity)
|
||||
{
|
||||
this->opacity = opacity;
|
||||
}
|
||||
|
||||
float GetOpacity() const
|
||||
{
|
||||
return opacity;
|
||||
}
|
||||
|
||||
void SetCheckable(bool checkable)
|
||||
{
|
||||
this->checkable = checkable;
|
||||
}
|
||||
|
||||
bool IsCheckable() const
|
||||
{
|
||||
return checkable;
|
||||
}
|
||||
|
||||
void SetChecked(bool checked)
|
||||
{
|
||||
this->checked = checked;
|
||||
}
|
||||
|
||||
bool IsChecked() const
|
||||
{
|
||||
return checked;
|
||||
}
|
||||
|
||||
void SetFocusable(bool focusable)
|
||||
{
|
||||
this->focusable = focusable;
|
||||
}
|
||||
|
||||
bool IsFocusable() const
|
||||
{
|
||||
return focusable;
|
||||
}
|
||||
|
||||
void SetFocused(bool focused)
|
||||
{
|
||||
this->focused = focused;
|
||||
}
|
||||
|
||||
bool IsFocused() const
|
||||
{
|
||||
return focused;
|
||||
}
|
||||
|
||||
void SetVisible(bool visible)
|
||||
{
|
||||
this->visible = visible;
|
||||
}
|
||||
|
||||
bool IsVisible() const
|
||||
{
|
||||
return visible;
|
||||
}
|
||||
|
||||
void SetAccessibilityFocused(bool accessibilityFocused)
|
||||
{
|
||||
this->accessibilityFocused = accessibilityFocused;
|
||||
}
|
||||
|
||||
bool IsAccessibilityFocused() const
|
||||
{
|
||||
return accessibilityFocused;
|
||||
}
|
||||
|
||||
void SetSelected(bool selected)
|
||||
{
|
||||
this->selected = selected;
|
||||
}
|
||||
|
||||
bool IsSelected() const
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
void SetClickable(bool clickable)
|
||||
{
|
||||
this->clickable = clickable;
|
||||
}
|
||||
|
||||
bool IsClickable() const
|
||||
{
|
||||
return clickable;
|
||||
}
|
||||
|
||||
void SetLongClickable(bool longClickable)
|
||||
{
|
||||
this->longClickable = longClickable;
|
||||
}
|
||||
|
||||
bool IsLongClickable() const
|
||||
{
|
||||
return longClickable;
|
||||
}
|
||||
|
||||
void SetEnabled(bool enabled)
|
||||
{
|
||||
this->enabled = enabled;
|
||||
}
|
||||
|
||||
bool IsEnabled() const
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void SetPassword(bool isPassword)
|
||||
{
|
||||
this->password = isPassword;
|
||||
}
|
||||
|
||||
bool IsPassword() const
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
void SetScrollable(bool scrollable)
|
||||
{
|
||||
this->scrollable = scrollable;
|
||||
}
|
||||
|
||||
bool IsScrollable() const
|
||||
{
|
||||
return scrollable;
|
||||
}
|
||||
|
||||
void SetEditable(bool editable)
|
||||
{
|
||||
this->editable = editable;
|
||||
}
|
||||
|
||||
bool IsEditable() const
|
||||
{
|
||||
return editable;
|
||||
}
|
||||
|
||||
void SetHint(bool hint)
|
||||
{
|
||||
this->hint = hint;
|
||||
}
|
||||
|
||||
bool IsHint() const
|
||||
{
|
||||
return hint;
|
||||
}
|
||||
|
||||
void SetAccessibilityGroup(bool accessibilityGroup)
|
||||
{
|
||||
this->accessibilityGroup = accessibilityGroup;
|
||||
}
|
||||
|
||||
bool GetAccessibilityGroup() const
|
||||
{
|
||||
return accessibilityGroup;
|
||||
}
|
||||
|
||||
void SetRect(const ArkUI_AccessibleRect& rect);
|
||||
ArkUI_AccessibleRect GetScreenRect() const
|
||||
{
|
||||
return screenRect;
|
||||
}
|
||||
|
||||
void SetRangeInfo(const ArkUI_AccessibleRangeInfo& rangeInfo);
|
||||
ArkUI_AccessibleRangeInfo GetRangeInfo() const
|
||||
{
|
||||
return rangeInfo;
|
||||
}
|
||||
|
||||
void SetGridInfo(const ArkUI_AccessibleGridInfo& gridInfo);
|
||||
ArkUI_AccessibleGridInfo GetGridInfo() const
|
||||
{
|
||||
return grid;
|
||||
}
|
||||
|
||||
void SetGridItemInfo(const ArkUI_AccessibleGridItemInfo& gridItemInfo);
|
||||
ArkUI_AccessibleGridItemInfo GetGridItemInfo() const
|
||||
{
|
||||
return gridItem;
|
||||
}
|
||||
|
||||
void ClearChildNodeIds();
|
||||
void AddChildNodeId(int64_t childNodeId);
|
||||
const std::vector<int64_t>& GetChildNodeIds() const
|
||||
{
|
||||
return childNodeIds;
|
||||
}
|
||||
|
||||
void ClearOperationActions();
|
||||
void AddOperationAction(const ArkUI_AccessibleAction& action);
|
||||
const std::vector<ArkUI_AccessibleAction>& GetOperationActions() const
|
||||
{
|
||||
return operationActions;
|
||||
}
|
||||
|
||||
void SetComponentType(const std::string& componentType)
|
||||
{
|
||||
this->componentType = componentType;
|
||||
}
|
||||
|
||||
std::string GetComponentType() const
|
||||
{
|
||||
return componentType;
|
||||
}
|
||||
|
||||
void SetContents(const std::string& contents)
|
||||
{
|
||||
this->contents = contents;
|
||||
}
|
||||
|
||||
std::string GetContents() const
|
||||
{
|
||||
return contents;
|
||||
}
|
||||
|
||||
void SetHintText(const std::string& hintText)
|
||||
{
|
||||
this->hintText = hintText;
|
||||
}
|
||||
|
||||
std::string GetHintText() const
|
||||
{
|
||||
return hintText;
|
||||
}
|
||||
|
||||
void SetAccessibilityText(const std::string& accessibilityText)
|
||||
{
|
||||
this->accessibilityText = accessibilityText;
|
||||
}
|
||||
|
||||
std::string GetAccessibilityText() const
|
||||
{
|
||||
return accessibilityText;
|
||||
}
|
||||
|
||||
void SetAccessibilityDescription(const std::string& accessibilityDescription)
|
||||
{
|
||||
this->accessibilityDescription = accessibilityDescription;
|
||||
}
|
||||
|
||||
std::string GetAccessibilityDescription() const
|
||||
{
|
||||
return accessibilityDescription;
|
||||
}
|
||||
|
||||
void SetAccessibilityLevel(const std::string& accessibilityLevel)
|
||||
{
|
||||
this->accessibilityLevel = accessibilityLevel;
|
||||
}
|
||||
|
||||
std::string GetAccessibilityLevel() const
|
||||
{
|
||||
return accessibilityLevel;
|
||||
}
|
||||
|
||||
void SetBackgroundColor(const std::string& backgroundColor)
|
||||
{
|
||||
this->backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
std::string GetBackgroundColor() const
|
||||
{
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
void SetBackgroundImage(const std::string& backgroundImage)
|
||||
{
|
||||
this->backgroundImage = backgroundImage;
|
||||
}
|
||||
|
||||
std::string GetBackgroundImage() const
|
||||
{
|
||||
return backgroundImage;
|
||||
}
|
||||
|
||||
void SetBlur(const std::string& blur)
|
||||
{
|
||||
this->blur = blur;
|
||||
}
|
||||
|
||||
std::string GetBlur() const
|
||||
{
|
||||
return blur;
|
||||
}
|
||||
|
||||
void SetHitTestBehavior(const std::string& hitTestBehavior)
|
||||
{
|
||||
this->hitTestBehavior = hitTestBehavior;
|
||||
}
|
||||
|
||||
std::string GetHitTestBehavior() const
|
||||
{
|
||||
return hitTestBehavior;
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t pageId = 0;
|
||||
int32_t textBeginSelected = 0;
|
||||
int32_t textEndSelected = 0;
|
||||
int32_t currentIndex = 0;
|
||||
int32_t beginIndex = 0;
|
||||
int32_t endIndex = 0;
|
||||
int32_t itemCount = 0;
|
||||
int32_t offset = 0;
|
||||
int32_t zIndex = 0;
|
||||
float opacity = 0.0f;
|
||||
|
||||
int64_t componentId = 0;
|
||||
int64_t parentId = 0;
|
||||
int32_t elementId = 0;
|
||||
|
||||
bool checkable = false;
|
||||
bool checked = false;
|
||||
bool focusable = false;
|
||||
bool focused = false;
|
||||
bool visible = false;
|
||||
bool accessibilityFocused = false;
|
||||
bool selected = false;
|
||||
bool clickable = false;
|
||||
bool longClickable = false;
|
||||
bool enabled = false;
|
||||
bool password = false;
|
||||
bool scrollable = false;
|
||||
bool editable = false;
|
||||
bool hint = false;
|
||||
bool accessibilityGroup = false;
|
||||
|
||||
ArkUI_AccessibleRect screenRect;
|
||||
ArkUI_AccessibleRangeInfo rangeInfo;
|
||||
ArkUI_AccessibleGridInfo grid;
|
||||
ArkUI_AccessibleGridItemInfo gridItem;
|
||||
|
||||
std::vector<int64_t> childNodeIds;
|
||||
std::vector<ArkUI_AccessibleAction> operationActions;
|
||||
|
||||
std::string componentType;
|
||||
std::string contents;
|
||||
std::string hintText;
|
||||
std::string accessibilityText;
|
||||
std::string accessibilityDescription;
|
||||
|
||||
std::string accessibilityLevel;
|
||||
std::string backgroundColor;
|
||||
std::string backgroundImage;
|
||||
std::string blur;
|
||||
std::string hitTestBehavior;
|
||||
};
|
||||
|
||||
struct ArkUI_AccessibilityEventInfo {
|
||||
public:
|
||||
ArkUI_AccessibilityEventInfo() = default;
|
||||
|
||||
ArkUI_AccessibilityEventType GetEventType() const
|
||||
{
|
||||
return eventType;
|
||||
}
|
||||
|
||||
void SetEventType(ArkUI_AccessibilityEventType eventType_)
|
||||
{
|
||||
eventType = eventType_;
|
||||
}
|
||||
|
||||
int32_t GetPageId() const
|
||||
{
|
||||
return pageId;
|
||||
}
|
||||
|
||||
void SetPageId(int32_t pageId)
|
||||
{
|
||||
this->pageId = pageId;
|
||||
}
|
||||
|
||||
int32_t GetRequestFocusId() const
|
||||
{
|
||||
return requestFocusId;
|
||||
}
|
||||
|
||||
void SetRequestFocusId(int32_t requestFocusId)
|
||||
{
|
||||
this->requestFocusId = requestFocusId;
|
||||
}
|
||||
|
||||
ArkUI_AccessibilityElementInfo* GetElementInfo() const
|
||||
{
|
||||
return elementInfo;
|
||||
}
|
||||
|
||||
void SetElementInfo(ArkUI_AccessibilityElementInfo* elementInfo)
|
||||
{
|
||||
this->elementInfo = elementInfo;
|
||||
}
|
||||
|
||||
std::string GetTextAnnouncedForAccessibility() const
|
||||
{
|
||||
return textAnnouncedForAccessibility;
|
||||
}
|
||||
|
||||
void SetTextAnnouncedForAccessibility(const std::string& textAnnouncedForAccessibility)
|
||||
{
|
||||
this->textAnnouncedForAccessibility = textAnnouncedForAccessibility;
|
||||
}
|
||||
|
||||
private:
|
||||
ArkUI_AccessibilityEventType eventType = ARKUI_NATIVE_ACCESSIBILITY_TYPE_VIEW_INVALID;
|
||||
int32_t pageId = 0;
|
||||
int32_t requestFocusId = 0;
|
||||
ArkUI_AccessibilityElementInfo* elementInfo = nullptr;
|
||||
std::string textAnnouncedForAccessibility;
|
||||
};
|
||||
|
||||
// suport multithreads
|
||||
struct ArkUI_AccessibilityElementInfoList {
|
||||
public:
|
||||
ArkUI_AccessibilityElementInfoList() = default;
|
||||
ArkUI_AccessibilityElementInfo* AddAndGetElementInfo();
|
||||
bool CopyAccessibilityElementInfo(std::vector<ArkUI_AccessibilityElementInfo>& infos);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::vector<ArkUI_AccessibilityElementInfo> elementInfos_;
|
||||
};
|
||||
|
||||
struct ArkUI_AccessibilityActionArguments {
|
||||
public:
|
||||
ArkUI_AccessibilityActionArguments(std::map<std::string, std::string> actionArguments)
|
||||
{
|
||||
actionArguments_.swap(actionArguments);
|
||||
}
|
||||
const char* FindValueByKey(const char* key);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> actionArguments_;
|
||||
};
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_NATIVE_INTERFACE_ACCESSIBILITY_IMPL_H
|
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "core/accessibility/native_interface_accessibility_provider.h"
|
||||
|
||||
using namespace OHOS::Ace;
|
||||
namespace {
|
||||
constexpr int32_t NOT_REGISTERED = -1;
|
||||
constexpr int32_t COPY_FAILED = -2;
|
||||
}
|
||||
int32_t ArkUI_AccessibilityProvider::AccessibilityProviderRegisterCallback(
|
||||
ArkUI_AccessibilityProviderCallbacks* callbacks)
|
||||
{
|
||||
if (callbacks == nullptr) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "callbacks is null");
|
||||
if (registerCallback_) {
|
||||
registerCallback_(false);
|
||||
}
|
||||
return OH_ARKUI_ACCESSIBILITY_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
accessibilityProviderCallbacks_ = callbacks;
|
||||
if (registerCallback_) {
|
||||
registerCallback_(true);
|
||||
}
|
||||
TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "AccessibilityProviderRegisterCallback success");
|
||||
return OH_ARKUI_ACCESSIBILITY_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::FindAccessibilityNodeInfosById(
|
||||
const int64_t elementId, const int32_t mode, const int32_t requestId,
|
||||
std::vector<ArkUI_AccessibilityElementInfo>& infos)
|
||||
{
|
||||
if (!accessibilityProviderCallbacks_ ||
|
||||
!accessibilityProviderCallbacks_->FindAccessibilityNodeInfosById) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "FindAccessibilityNodeInfosById is null");
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
ArkUI_AccessibilityElementInfoList* accessibilityElementInfoList
|
||||
= new (std::nothrow) ArkUI_AccessibilityElementInfoList();
|
||||
int32_t ret = accessibilityProviderCallbacks_->FindAccessibilityNodeInfosById(
|
||||
elementId, static_cast<ArkUI_AccessibilitySearchMode>(mode),
|
||||
requestId, accessibilityElementInfoList);
|
||||
if (!accessibilityElementInfoList->CopyAccessibilityElementInfo(infos)) {
|
||||
ret = COPY_FAILED;
|
||||
}
|
||||
|
||||
delete accessibilityElementInfoList;
|
||||
accessibilityElementInfoList = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::FindAccessibilityNodeInfosByText(
|
||||
const int64_t elementId, std::string text, const int32_t requestId,
|
||||
std::vector<ArkUI_AccessibilityElementInfo>& infos)
|
||||
{
|
||||
if (!accessibilityProviderCallbacks_ ||
|
||||
!accessibilityProviderCallbacks_->FindAccessibilityNodeInfosByText) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "FindAccessibilityNodeInfosByText is null");
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
ArkUI_AccessibilityElementInfoList* accessibilityElementInfoList
|
||||
= new (std::nothrow) ArkUI_AccessibilityElementInfoList();
|
||||
int32_t ret = accessibilityProviderCallbacks_->FindAccessibilityNodeInfosByText(
|
||||
elementId, text.c_str(), requestId, accessibilityElementInfoList);
|
||||
if (!accessibilityElementInfoList->CopyAccessibilityElementInfo(infos)) {
|
||||
ret = COPY_FAILED;
|
||||
}
|
||||
|
||||
delete accessibilityElementInfoList;
|
||||
accessibilityElementInfoList = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::FindFocusedAccessibilityNode(
|
||||
const int64_t elementId, int32_t focusType, const int32_t requestId,
|
||||
ArkUI_AccessibilityElementInfo& elementInfo)
|
||||
{
|
||||
if (!accessibilityProviderCallbacks_ ||
|
||||
!accessibilityProviderCallbacks_->FindFocusedAccessibilityNode) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "FindFocusedAccessibilityNode is null");
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
return accessibilityProviderCallbacks_->FindFocusedAccessibilityNode(elementId,
|
||||
static_cast<ArkUI_AccessibilityFocusType>(focusType), requestId, &elementInfo);
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::FindNextFocusAccessibilityNode(
|
||||
const int64_t elementId, int32_t direction, const int32_t requestId,
|
||||
ArkUI_AccessibilityElementInfo& elementInfo)
|
||||
{
|
||||
if (!accessibilityProviderCallbacks_ ||
|
||||
!accessibilityProviderCallbacks_->FindNextFocusAccessibilityNode) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "FindNextFocusAccessibilityNode is null");
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
return accessibilityProviderCallbacks_->FindNextFocusAccessibilityNode(elementId,
|
||||
static_cast<ArkUI_AccessibilityFocusMoveDirection>(direction), requestId, &elementInfo);
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::ExecuteAccessibilityAction(
|
||||
const int64_t elementId, int32_t action, const int32_t requestId,
|
||||
const std::map<std::string, std::string>& actionArguments)
|
||||
{
|
||||
if (!accessibilityProviderCallbacks_ ||
|
||||
!accessibilityProviderCallbacks_->ExecuteAccessibilityAction) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "ExecuteAccessibilityAction is null");
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
return accessibilityProviderCallbacks_->ExecuteAccessibilityAction(
|
||||
elementId,
|
||||
static_cast<ArkUI_Accessibility_ActionType>(action),
|
||||
new ArkUI_AccessibilityActionArguments(actionArguments),
|
||||
requestId);
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::ClearFocusedAccessibilityNode()
|
||||
{
|
||||
if (!accessibilityProviderCallbacks_ ||
|
||||
!accessibilityProviderCallbacks_->ClearFocusedFocusAccessibilityNode) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "ClearFocusedAccessibilityNode is null");
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
return accessibilityProviderCallbacks_->ClearFocusedFocusAccessibilityNode();
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::GetAccessibilityNodeCursorPosition(
|
||||
const int64_t elementId, const int32_t requestId, int32_t &cursorPosition)
|
||||
{
|
||||
if (!accessibilityProviderCallbacks_ ||
|
||||
!accessibilityProviderCallbacks_->GetAccessibilityNodeCursorPosition) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "GetAccessibilityNodeCursorPosition is null");
|
||||
return NOT_REGISTERED;
|
||||
}
|
||||
|
||||
return accessibilityProviderCallbacks_->GetAccessibilityNodeCursorPosition(
|
||||
elementId, requestId, &cursorPosition);
|
||||
}
|
||||
|
||||
int32_t ArkUI_AccessibilityProvider::SendAccessibilityAsyncEvent(
|
||||
ArkUI_AccessibilityEventInfo* accessibilityEvent,
|
||||
void (*callback)(int32_t errorCode))
|
||||
{
|
||||
if (accessibilityEvent == nullptr) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "accessibilityEvent is null");
|
||||
if (callback) {
|
||||
callback(-1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto accessibilityProvider = accessibilityProvider_.Upgrade();
|
||||
if (accessibilityProvider == nullptr) {
|
||||
TAG_LOGW(AceLogTag::ACE_ACCESSIBILITY, "accessibilityProvider is null");
|
||||
if (callback) {
|
||||
callback(-1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
accessibilityProvider->SendAccessibilityAsyncEvent(*accessibilityEvent, callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityProvider::SetInnerAccessibilityProvider(
|
||||
const OHOS::Ace::WeakPtr<OHOS::Ace::AccessibilityProvider>& accessibilityProvider)
|
||||
{
|
||||
accessibilityProvider_ = accessibilityProvider;
|
||||
}
|
||||
|
||||
bool ArkUI_AccessibilityProvider::IsRegister()
|
||||
{
|
||||
return accessibilityProviderCallbacks_ != nullptr;
|
||||
}
|
||||
|
||||
void ArkUI_AccessibilityProvider::SetRegisterCallback(RegisterCallback callback)
|
||||
{
|
||||
registerCallback_ = callback;
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_NATIVE_INTERFACE_ACCESSIBILITY_HANDLE_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_NATIVE_INTERFACE_ACCESSIBILITY_HANDLE_H
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "core/accessibility/accessibility_provider.h"
|
||||
|
||||
struct ArkUI_AccessibilityProvider {
|
||||
public:
|
||||
ArkUI_AccessibilityProvider() = default;
|
||||
virtual ~ArkUI_AccessibilityProvider() {}
|
||||
using RegisterCallback = std::function<void(bool)>;
|
||||
|
||||
int32_t FindAccessibilityNodeInfosById(
|
||||
const int64_t elementId, const int32_t mode, const int32_t requestId,
|
||||
std::vector<ArkUI_AccessibilityElementInfo>& infos);
|
||||
int32_t FindAccessibilityNodeInfosByText(
|
||||
const int64_t elementId, std::string text, const int32_t requestId,
|
||||
std::vector<ArkUI_AccessibilityElementInfo>& infos);
|
||||
int32_t FindFocusedAccessibilityNode(
|
||||
const int64_t elementId, int32_t focusType, const int32_t requestId,
|
||||
ArkUI_AccessibilityElementInfo& elementInfo);
|
||||
int32_t FindNextFocusAccessibilityNode(
|
||||
const int64_t elementId, int32_t direction, const int32_t requestId,
|
||||
ArkUI_AccessibilityElementInfo& elementInfo);
|
||||
int32_t ExecuteAccessibilityAction(
|
||||
const int64_t elementId, int32_t action, const int32_t requestId,
|
||||
const std::map<std::string, std::string>& actionArguments);
|
||||
int32_t ClearFocusedAccessibilityNode();
|
||||
int32_t GetAccessibilityNodeCursorPosition(
|
||||
const int64_t elementId, const int32_t requestId, int32_t &cursorPosition);
|
||||
int32_t SendAccessibilityAsyncEvent(
|
||||
ArkUI_AccessibilityEventInfo* accessibilityEvent,
|
||||
void (*callback)(int32_t errorCode));
|
||||
int32_t AccessibilityProviderRegisterCallback(
|
||||
ArkUI_AccessibilityProviderCallbacks* callbacks);
|
||||
void SetInnerAccessibilityProvider(
|
||||
const OHOS::Ace::WeakPtr<OHOS::Ace::AccessibilityProvider>& accessibilityProvider);
|
||||
bool IsRegister();
|
||||
void SetRegisterCallback(RegisterCallback callback);
|
||||
|
||||
private:
|
||||
ArkUI_AccessibilityProviderCallbacks* accessibilityProviderCallbacks_ = nullptr;
|
||||
OHOS::Ace::WeakPtr<OHOS::Ace::AccessibilityProvider> accessibilityProvider_;
|
||||
RegisterCallback registerCallback_;
|
||||
};
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_NATIVE_INTERFACE_ACCESSIBILITY_HANDLE_H
|
35
frameworks/core/accessibility/third_accessibility_manager.h
Normal file
35
frameworks/core/accessibility/third_accessibility_manager.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_THIRD_ACCESSIBILITY_PROVIDER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_THIRD_ACCESSIBILITY_PROVIDER_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "core/accessibility/native_interface_accessibility_impl.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class ThirdAccessibilityManager : public AceType {
|
||||
DECLARE_ACE_TYPE(ThirdAccessibilityManager, AceType);
|
||||
public:
|
||||
virtual int32_t SendAccessibilityAsyncEvent(
|
||||
const ArkUI_AccessibilityEventInfo& accessibilityEvent,
|
||||
void (*callback)(int32_t errorCode)) { return 0; };
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_THIRD_ACCESSIBILITY_PROVIDER_H
|
Loading…
x
Reference in New Issue
Block a user