1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "core/accessibility/accessibility_node.h"
17
18 #include "core/common/container.h"
19 #include "core/event/ace_event_helper.h"
20
21 namespace OHOS::Ace {
22 using ChartValue = std::unordered_map<std::string, std::vector<std::pair<std::string, double>>>;
23 namespace {
24
25 const char ACCESSIBILITY_VALUE[] = "value";
26 const char ACCESSIBILITY_TYPE[] = "type";
27 const char ACCESSIBILITY_DISABLED[] = "disabled";
28 const char ACCESSIBILITY_GROUP[] = "accessibilitygroup";
29 const char ACCESSIBILITY_TEXT[] = "accessibilitytext";
30 const char ACCESSIBILITY_DESCRIPTION[] = "accessibilitydescription";
31 const char ACCESSIBILITY_IMPORTANCE[] = "accessibilityimportance";
32 const char ACCESSIBILITY_SHOW[] = "show";
33 const char ID[] = "id";
34
35 const char INPUT_TYPE_CHECKBOX[] = "checkbox";
36 const char INPUT_TYPE_RADIO[] = "radio";
37 const char INPUT_TYPE_PASSWORD[] = "password";
38
39 // common event definition
40 const char ACCESSIBILITY_EVENT[] = "accessibility";
41 const char CLICK[] = "click";
42 const char LONG_PRESS[] = "longpress";
43 const char FOCUS[] = "focus";
44 const char BLUR[] = "blur";
45
StringToBool(const std::string & value)46 inline bool StringToBool(const std::string& value)
47 {
48 return value == "true";
49 }
50
MergeItems(const std::vector<std::pair<std::string,std::string>> & newItems,std::vector<std::pair<std::string,std::string>> & items)51 void MergeItems(const std::vector<std::pair<std::string, std::string>>& newItems,
52 std::vector<std::pair<std::string, std::string>>& items)
53 {
54 if (items.empty()) {
55 items = newItems;
56 } else {
57 std::unordered_map<std::string, std::string> originItems;
58 std::vector<std::pair<std::string, std::string>> sameVec;
59 std::vector<std::pair<std::string, std::string>> diffVec;
60 for (const auto& item: items) {
61 originItems[item.first] = item.second;
62 }
63
64 for (const auto& item: newItems) {
65 originItems[item.first] = item.second;
66 }
67
68 // find same element
69 for (auto item = items.begin(); item != items.end(); item++) {
70 const auto iter = originItems.find(item->first);
71 if (iter != originItems.end()) {
72 sameVec.emplace_back(iter->first, iter->second);
73 }
74 }
75
76 // find different element
77 for (auto newItem = newItems.begin(); newItem != newItems.end(); newItem++) {
78 size_t diffFlagCount = 0;
79 for (auto item = items.begin(); item != items.end(); item++) {
80 if (newItem->first != item->first) {
81 diffFlagCount++;
82 }
83 }
84 if (diffFlagCount == items.size()) {
85 diffVec.emplace_back(newItem->first, newItem->second);
86 }
87 }
88 sameVec.insert(sameVec.end(), diffVec.begin(), diffVec.end());
89 items.clear();
90 items = sameVec;
91 }
92 }
93
94 } // namespace
95
AccessibilityNode(NodeId nodeId,const std::string & nodeName)96 AccessibilityNode::AccessibilityNode(NodeId nodeId, const std::string& nodeName) : nodeId_(nodeId), tag_(nodeName)
97 {
98 // Initialize member variable in bitfield
99 isEnabled_ = true;
100 visible_ = true;
101 shown_ = true;
102 }
103
SetActionClickImpl(const ActionClickImpl & actionClickImpl)104 void AccessibilityNode::SetActionClickImpl(const ActionClickImpl& actionClickImpl)
105 {
106 actionClickImpl_ = actionClickImpl;
107 }
108
ActionClick()109 bool AccessibilityNode::ActionClick()
110 {
111 if (actionClickImpl_) {
112 actionClickImpl_();
113 return true;
114 }
115 return false;
116 }
117
SetActionLongClickImpl(const ActionLongClickImpl & actionLongClickImpl)118 void AccessibilityNode::SetActionLongClickImpl(const ActionLongClickImpl& actionLongClickImpl)
119 {
120 actionLongClickImpl_ = actionLongClickImpl;
121 }
122
ActionLongClick()123 bool AccessibilityNode::ActionLongClick()
124 {
125 if (actionLongClickImpl_) {
126 actionLongClickImpl_();
127 return true;
128 }
129 return false;
130 }
131
SetActionSetTextImpl(const ActionSetTextImpl & actionSetTextImpl)132 void AccessibilityNode::SetActionSetTextImpl(const ActionSetTextImpl& actionSetTextImpl)
133 {
134 actionSetTextImpl_ = actionSetTextImpl;
135 }
136
ActionSetText(const std::string & text)137 bool AccessibilityNode::ActionSetText(const std::string& text)
138 {
139 if (actionSetTextImpl_) {
140 actionSetTextImpl_(text);
141 return true;
142 }
143 return false;
144 }
145
SetActionScrollForward(const ActionScrollForwardImpl & actionScrollForwardImpl)146 void AccessibilityNode::SetActionScrollForward(const ActionScrollForwardImpl& actionScrollForwardImpl)
147 {
148 actionScrollForwardImpl_ = actionScrollForwardImpl;
149 }
150
ActionScrollForward()151 bool AccessibilityNode::ActionScrollForward()
152 {
153 if (actionScrollForwardImpl_) {
154 return actionScrollForwardImpl_();
155 }
156 return false;
157 }
158
SetActionScrollBackward(const ActionScrollBackwardImpl & actionScrollBackwardImpl)159 void AccessibilityNode::SetActionScrollBackward(const ActionScrollBackwardImpl& actionScrollBackwardImpl)
160 {
161 actionScrollBackwardImpl_ = actionScrollBackwardImpl;
162 }
163
ActionScrollBackward()164 bool AccessibilityNode::ActionScrollBackward()
165 {
166 if (actionScrollBackwardImpl_) {
167 return actionScrollBackwardImpl_();
168 }
169 return false;
170 }
171
SetActionAccessibilityFocusImpl(const ActionAccessibilityFocusImpl & actionAccessibilityFocusImpl)172 void AccessibilityNode::SetActionAccessibilityFocusImpl(
173 const ActionAccessibilityFocusImpl& actionAccessibilityFocusImpl)
174 {
175 actionAccessibilityFocusIdsImpl_ = actionAccessibilityFocusImpl;
176 }
177
ActionAccessibilityFocus(bool isFocus)178 bool AccessibilityNode::ActionAccessibilityFocus(bool isFocus)
179 {
180 if (actionAccessibilityFocusIdsImpl_) {
181 actionAccessibilityFocusIdsImpl_(isFocus);
182 return true;
183 }
184 return false;
185 }
186
SetActionFocusImpl(const ActionFocusImpl & actionFocusImpl)187 void AccessibilityNode::SetActionFocusImpl(const ActionFocusImpl& actionFocusImpl)
188 {
189 actionFocusImpl_ = actionFocusImpl;
190 }
191
ActionFocus()192 bool AccessibilityNode::ActionFocus()
193 {
194 if (actionFocusImpl_) {
195 actionFocusImpl_();
196 return true;
197 }
198 return false;
199 }
200
SetActionUpdateIdsImpl(const ActionUpdateIdsImpl & actionUpdateIdsImpl)201 void AccessibilityNode::SetActionUpdateIdsImpl(const ActionUpdateIdsImpl& actionUpdateIdsImpl)
202 {
203 actionUpdateIdsImpl_ = actionUpdateIdsImpl;
204 }
205
ActionUpdateIds()206 void AccessibilityNode::ActionUpdateIds()
207 {
208 if (actionUpdateIdsImpl_) {
209 actionUpdateIdsImpl_();
210 }
211 }
212
SetParentNode(const RefPtr<AccessibilityNode> & parentNode)213 void AccessibilityNode::SetParentNode(const RefPtr<AccessibilityNode>& parentNode)
214 {
215 parentNode_ = parentNode;
216 }
217
SetPositionInfo(const PositionInfo & positionInfo)218 void AccessibilityNode::SetPositionInfo(const PositionInfo& positionInfo)
219 {
220 rect_.SetRect(positionInfo.left, positionInfo.top, positionInfo.width, positionInfo.height);
221 }
222
SetAttr(const std::vector<std::pair<std::string,std::string>> & attrs)223 void AccessibilityNode::SetAttr(const std::vector<std::pair<std::string, std::string>>& attrs)
224 {
225 MergeItems(attrs, attrs_);
226
227 for (const auto& attr : attrs) {
228 if (attr.first == ACCESSIBILITY_VALUE) {
229 text_ = attr.second;
230 if (tag_ == ACCESSIBILITY_TAG_TEXT && parentNode_.Upgrade() &&
231 parentNode_.Upgrade()->GetTag() == ACCESSIBILITY_TAG_POPUP) {
232 auto spParent = parentNode_.Upgrade();
233 auto parentText = spParent->GetText() + text_;
234 spParent->SetText(parentText);
235 }
236 } else if (attr.first == ACCESSIBILITY_DISABLED) {
237 isEnabled_ = !StringToBool(attr.second);
238 } else if (attr.first == ACCESSIBILITY_TYPE) {
239 inputType_ = attr.second;
240 } else if (attr.first == ACCESSIBILITY_GROUP) {
241 accessible_ = StringToBool(attr.second);
242 } else if (attr.first == ACCESSIBILITY_TEXT) {
243 accessibilityLabel_ = attr.second;
244 } else if (attr.first == ACCESSIBILITY_DESCRIPTION) {
245 accessibilityHint_ = attr.second;
246 } else if (attr.first == ACCESSIBILITY_IMPORTANCE) {
247 importantForAccessibility_ = attr.second;
248 } else if (attr.first == ID) {
249 jsComponentId_ = attr.second;
250 } else if (attr.first == ACCESSIBILITY_SHOW) {
251 shown_ = attr.second == "true";
252 }
253 }
254 SetOperableInfo();
255 }
256
SetStyle(const std::vector<std::pair<std::string,std::string>> & styles)257 void AccessibilityNode::SetStyle(const std::vector<std::pair<std::string, std::string>>& styles)
258 {
259 MergeItems(styles, styles_);
260 }
261
AddEvent(int32_t pageId,const std::vector<std::string> & events)262 void AccessibilityNode::AddEvent(int32_t pageId, const std::vector<std::string>& events)
263 {
264 for (const auto& event : events) {
265 if (event == ACCESSIBILITY_EVENT) {
266 onAccessibilityEventId_ = EventMarker(std::to_string(nodeId_), event, pageId);
267 } else if (event == CLICK) {
268 onClickId_ = EventMarker(std::to_string(nodeId_), event, pageId);
269 SetClickableState(true);
270 } else if (event == LONG_PRESS) {
271 onLongPressId_ = EventMarker(std::to_string(nodeId_), event, pageId);
272 SetLongClickableState(true);
273 } else if (event == FOCUS) {
274 onFocusId_ = EventMarker(std::to_string(nodeId_), event, pageId);
275 } else if (event == BLUR) {
276 onBlurId_ = EventMarker(std::to_string(nodeId_), event, pageId);
277 }
278 }
279 AddSupportAction(AceAction::CUSTOM_ACTION);
280 AddSupportAction(AceAction::GLOBAL_ACTION_BACK);
281 }
282
AddNode(const RefPtr<AccessibilityNode> & node,int32_t slot)283 void AccessibilityNode::AddNode(const RefPtr<AccessibilityNode>& node, int32_t slot)
284 {
285 CHECK_NULL_VOID(node);
286 auto isExist = std::find_if(children_.begin(), children_.end(),
287 [node](const RefPtr<AccessibilityNode>& child) { return child->GetNodeId() == node->GetNodeId(); });
288 if (isExist != children_.end()) {
289 return;
290 }
291 auto pos = children_.begin();
292 std::advance(pos, slot);
293 children_.insert(pos, node);
294 }
295
RemoveNode(const RefPtr<AccessibilityNode> & node)296 void AccessibilityNode::RemoveNode(const RefPtr<AccessibilityNode>& node)
297 {
298 CHECK_NULL_VOID(node);
299 children_.remove_if(
300 [node](const RefPtr<AccessibilityNode>& child) { return node->GetNodeId() == child->GetNodeId(); });
301 }
302
Mount(int32_t slot)303 void AccessibilityNode::Mount(int32_t slot)
304 {
305 auto parentNode = parentNode_.Upgrade();
306 CHECK_NULL_VOID(parentNode);
307 parentNode->AddNode(AceType::Claim(this), slot);
308 }
309
AddOffsetForChildren(const Offset & offset)310 void AccessibilityNode::AddOffsetForChildren(const Offset& offset)
311 {
312 SetLeft(GetLeft() + offset.GetX());
313 SetTop(GetTop() + offset.GetY());
314 for (const auto& child : GetChildList()) {
315 child->AddOffsetForChildren(offset);
316 }
317 }
318
SetOperableInfo()319 void AccessibilityNode::SetOperableInfo()
320 {
321 static const LinearMapNode<OperableInfo> nodeOperatorMap[] = {
322 { ACCESSIBILITY_TAG_BUTTON,
323 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
324 { ACCESSIBILITY_TAG_CALENDAR,
325 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
326 { ACCESSIBILITY_TAG_CANVAS,
327 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
328 { ACCESSIBILITY_TAG_CHART,
329 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
330 { ACCESSIBILITY_TAG_CLOCK,
331 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
332 { ACCESSIBILITY_TAG_DIALOG,
333 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
334 { ACCESSIBILITY_TAG_DIV,
335 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
336 { ACCESSIBILITY_TAG_DIVIDER,
337 { .checkable = false, .clickable = false, .scrollable = false,
338 .longClickable = false, .focusable = false } },
339 { ACCESSIBILITY_TAG_IMAGE,
340 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
341 { ACCESSIBILITY_TAG_INPUT,
342 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
343 { ACCESSIBILITY_TAG_LABEL,
344 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
345 { ACCESSIBILITY_TAG_LIST,
346 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
347 { ACCESSIBILITY_TAG_LIST_ITEM,
348 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
349 { ACCESSIBILITY_TAG_LIST_ITEM_GROUP,
350 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
351 { ACCESSIBILITY_TAG_MARQUEE,
352 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
353 { ACCESSIBILITY_TAG_NAVIGATION_BAR,
354 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
355 { ACCESSIBILITY_TAG_OPTION,
356 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
357 { ACCESSIBILITY_TAG_POPUP,
358 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
359 { ACCESSIBILITY_TAG_PROGRESS,
360 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
361 { ACCESSIBILITY_TAG_RATING,
362 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
363 { ACCESSIBILITY_TAG_REFRESH,
364 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
365 { ACCESSIBILITY_TAG_SELECT,
366 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
367 { ACCESSIBILITY_TAG_SLIDER,
368 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
369 { ACCESSIBILITY_TAG_SPAN,
370 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
371 { ACCESSIBILITY_TAG_STACK,
372 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
373 { ACCESSIBILITY_TAG_SWIPER,
374 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
375 { ACCESSIBILITY_TAG_SWITCH,
376 { .checkable = true, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
377 { ACCESSIBILITY_TAG_TAB_BAR,
378 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
379 { ACCESSIBILITY_TAG_TAB_CONTENT,
380 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
381 { ACCESSIBILITY_TAG_TABS,
382 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
383 { ACCESSIBILITY_TAG_TEXT,
384 { .checkable = false, .clickable = true, .scrollable = true, .longClickable = true, .focusable = true } },
385 { ACCESSIBILITY_TAG_TEXTAREA,
386 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
387 { ACCESSIBILITY_TAG_VIDEO,
388 { .checkable = false, .clickable = true, .scrollable = false, .longClickable = true, .focusable = true } },
389 };
390
391 // set node operable info
392 int64_t operateIter = BinarySearchFindIndex(nodeOperatorMap, ArraySize(nodeOperatorMap), tag_.c_str());
393 if (operateIter != -1) {
394 isCheckable_ = nodeOperatorMap[operateIter].value.checkable;
395 isScrollable_ = nodeOperatorMap[operateIter].value.scrollable;
396 isFocusable_ = nodeOperatorMap[operateIter].value.focusable;
397 if (isFocusable_) {
398 AddSupportAction(AceAction::ACTION_FOCUS);
399 }
400 } else {
401 isCheckable_ = false;
402 isClickable_ = false;
403 isScrollable_ = false;
404 isLongClickable_ = false;
405 isFocusable_ = false;
406 }
407
408 if (tag_ == ACCESSIBILITY_TAG_INPUT) {
409 if (inputType_ == INPUT_TYPE_CHECKBOX || inputType_ == INPUT_TYPE_RADIO) {
410 isCheckable_ = true;
411 } else if (inputType_ == INPUT_TYPE_PASSWORD) {
412 isPassword_ = true;
413 }
414 }
415 }
416
GetSupportAction(uint64_t enableActions) const417 std::unordered_set<AceAction> AccessibilityNode::GetSupportAction(uint64_t enableActions) const
418 {
419 static const AceAction allActions[] = {
420 AceAction::ACTION_NONE, AceAction::GLOBAL_ACTION_BACK, AceAction::CUSTOM_ACTION, AceAction::ACTION_CLICK,
421 AceAction::ACTION_LONG_CLICK, AceAction::ACTION_SCROLL_FORWARD, AceAction::ACTION_SCROLL_BACKWARD,
422 AceAction::ACTION_FOCUS, AceAction::ACTION_ACCESSIBILITY_FOCUS, AceAction::ACTION_CLEAR_ACCESSIBILITY_FOCUS,
423 AceAction::ACTION_NEXT_AT_MOVEMENT_GRANULARITY, AceAction::ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
424 AceAction::ACTION_SET_TEXT,
425 };
426
427 std::unordered_set<AceAction> supportActions;
428 if (supportActions_ == 0) {
429 return supportActions;
430 }
431
432 auto finalSupportActions = supportActions_ & enableActions;
433 for (auto action : allActions) {
434 if ((finalSupportActions & (1UL << static_cast<uint32_t>(action))) != 0) {
435 supportActions.emplace(action);
436 }
437 }
438 return supportActions;
439 }
440
SetFocusChangeEventMarker(const EventMarker & eventId)441 void AccessibilityNode::SetFocusChangeEventMarker(const EventMarker& eventId)
442 {
443 if (eventId.IsEmpty()) {
444 return;
445 }
446
447 auto container = Container::Current();
448 CHECK_NULL_VOID(container);
449 #ifndef NG_BUILD
450 auto pipelineContext = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
451 CHECK_NULL_VOID(pipelineContext);
452 focusChangeEventId_ =
453 AceAsyncEvent<void(const std::string&)>::Create(eventId, pipelineContext);
454 #endif
455 }
456
OnFocusChange(bool isFocus)457 void AccessibilityNode::OnFocusChange(bool isFocus)
458 {
459 CHECK_NULL_VOID(focusChangeEventId_);
460 auto json = JsonUtil::Create(true);
461 json->Put("eventType", isFocused_ ? "1" : "2");
462 focusChangeEventId_(json->ToString());
463 }
464
SetWindowId(uint32_t windowId)465 void AccessibilityNode::SetWindowId(uint32_t windowId)
466 {
467 windowId_ = windowId;
468 }
469
GetWindowId() const470 uint32_t AccessibilityNode::GetWindowId() const
471 {
472 return windowId_;
473 }
474
SetIsRootNode(bool isRootNode)475 void AccessibilityNode::SetIsRootNode(bool isRootNode)
476 {
477 isRootNode_ = isRootNode;
478 }
479
IsRootNode() const480 bool AccessibilityNode::IsRootNode() const
481 {
482 return isRootNode_;
483 }
484
ResetChildList(std::list<RefPtr<AccessibilityNode>> & children)485 void AccessibilityNode::ResetChildList(std::list<RefPtr<AccessibilityNode>>& children)
486 {
487 children_.clear();
488 children_.swap(children);
489 }
490
GetChildList() const491 const std::list<RefPtr<AccessibilityNode>> AccessibilityNode::GetChildList() const
492 {
493 return children_;
494 }
495
GetParentId() const496 NodeId AccessibilityNode::GetParentId() const
497 {
498 auto parentNode = parentNode_.Upgrade();
499 return parentNode ? parentNode->GetNodeId() : -1;
500 }
501
GetParentNode() const502 RefPtr<AccessibilityNode> AccessibilityNode::GetParentNode() const
503 {
504 return parentNode_.Upgrade();
505 }
506
GetTag() const507 const std::string& AccessibilityNode::GetTag() const
508 {
509 return tag_;
510 }
511
SetTag(const std::string & tag)512 void AccessibilityNode::SetTag(const std::string& tag)
513 {
514 tag_ = tag;
515 }
516
GetPageId() const517 int32_t AccessibilityNode::GetPageId() const
518 {
519 return pageId_;
520 }
521
SetPageId(int32_t pageId)522 void AccessibilityNode::SetPageId(int32_t pageId)
523 {
524 pageId_ = pageId;
525 }
526
GetAccessibilityEventMarker() const527 const EventMarker& AccessibilityNode::GetAccessibilityEventMarker() const
528 {
529 return onAccessibilityEventId_;
530 }
531
GetClickEventMarker() const532 const EventMarker& AccessibilityNode::GetClickEventMarker() const
533 {
534 return onClickId_;
535 }
536
GetLongPressEventMarker() const537 const EventMarker& AccessibilityNode::GetLongPressEventMarker() const
538 {
539 return onLongPressId_;
540 }
541
GetSetTextEventMarker() const542 const EventMarker& AccessibilityNode::GetSetTextEventMarker() const
543 {
544 return onSetTextId_;
545 }
546
GetFocusEventMarker() const547 const EventMarker& AccessibilityNode::GetFocusEventMarker() const
548 {
549 return onFocusId_;
550 }
551
GetBlurEventMarker() const552 const EventMarker& AccessibilityNode::GetBlurEventMarker() const
553 {
554 return onBlurId_;
555 }
556
GetNodeId() const557 NodeId AccessibilityNode::GetNodeId() const
558 {
559 return nodeId_;
560 }
561
GetText() const562 const std::string& AccessibilityNode::GetText() const
563 {
564 return text_;
565 }
566
SetText(const std::string & text)567 void AccessibilityNode::SetText(const std::string& text)
568 {
569 text_ = text;
570 }
571
GetHintText() const572 const std::string& AccessibilityNode::GetHintText() const
573 {
574 return hintText_;
575 }
576
SetHintText(const std::string & hintText)577 void AccessibilityNode::SetHintText(const std::string& hintText)
578 {
579 hintText_ = hintText;
580 }
581
GetChildIds() const582 const std::vector<int32_t>& AccessibilityNode::GetChildIds() const
583 {
584 return childIds_;
585 }
586
SetChildIds(const std::vector<int32_t> & ids)587 void AccessibilityNode::SetChildIds(const std::vector<int32_t>& ids)
588 {
589 childIds_ = ids;
590 }
591
GetWidth() const592 double AccessibilityNode::GetWidth() const
593 {
594 return rect_.Width();
595 }
596
SetWidth(double width)597 void AccessibilityNode::SetWidth(double width)
598 {
599 rect_.SetWidth(width);
600 }
601
GetHeight() const602 double AccessibilityNode::GetHeight() const
603 {
604 return rect_.Height();
605 }
606
SetHeight(double height)607 void AccessibilityNode::SetHeight(double height)
608 {
609 rect_.SetHeight(height);
610 }
611
GetLeft() const612 double AccessibilityNode::GetLeft() const
613 {
614 return rect_.Left();
615 }
616
SetLeft(double left)617 void AccessibilityNode::SetLeft(double left)
618 {
619 return rect_.SetLeft(left);
620 }
621
GetTop() const622 double AccessibilityNode::GetTop() const
623 {
624 return rect_.Top();
625 }
626
SetTop(double top)627 void AccessibilityNode::SetTop(double top)
628 {
629 return rect_.SetTop(top);
630 }
631
GetCheckedState() const632 bool AccessibilityNode::GetCheckedState() const
633 {
634 return isChecked_;
635 }
636
SetCheckedState(bool state)637 void AccessibilityNode::SetCheckedState(bool state)
638 {
639 isChecked_ = state;
640 }
641
GetEnabledState() const642 bool AccessibilityNode::GetEnabledState() const
643 {
644 return isEnabled_;
645 }
646
SetEnabledState(bool state)647 void AccessibilityNode::SetEnabledState(bool state)
648 {
649 isEnabled_ = state;
650 }
651
GetEditable() const652 bool AccessibilityNode::GetEditable() const
653 {
654 return isEditable_;
655 }
656
SetEditable(bool editable)657 void AccessibilityNode::SetEditable(bool editable)
658 {
659 isEditable_ = editable;
660 }
661
GetFocusedState() const662 bool AccessibilityNode::GetFocusedState() const
663 {
664 return isFocused_;
665 }
666
SetFocusedState(bool state)667 void AccessibilityNode::SetFocusedState(bool state)
668 {
669 isFocused_ = state;
670 OnFocusChange(isFocused_);
671 }
672
GetAccessibilityFocusedState() const673 bool AccessibilityNode::GetAccessibilityFocusedState() const
674 {
675 return isAccessibilityFocused_;
676 }
677
SetAccessibilityFocusedState(bool state)678 void AccessibilityNode::SetAccessibilityFocusedState(bool state)
679 {
680 isAccessibilityFocused_ = state;
681 }
682
GetSelectedState() const683 bool AccessibilityNode::GetSelectedState() const
684 {
685 return isSelected_;
686 }
687
SetSelectedState(bool state)688 void AccessibilityNode::SetSelectedState(bool state)
689 {
690 isSelected_ = state;
691 }
692
GetCheckableState() const693 bool AccessibilityNode::GetCheckableState() const
694 {
695 return isCheckable_;
696 }
697
SetCheckableState(bool state)698 void AccessibilityNode::SetCheckableState(bool state)
699 {
700 isCheckable_ = state;
701 }
702
GetClickableState() const703 bool AccessibilityNode::GetClickableState() const
704 {
705 return isClickable_;
706 }
707
SetClickableState(bool state)708 void AccessibilityNode::SetClickableState(bool state)
709 {
710 isClickable_ = state;
711 SetSupportAction(AceAction::ACTION_CLICK, state);
712 }
713
GetFocusableState() const714 bool AccessibilityNode::GetFocusableState() const
715 {
716 return isFocusable_;
717 }
718
SetFocusableState(bool state)719 void AccessibilityNode::SetFocusableState(bool state)
720 {
721 isFocusable_ = state;
722 }
723
GetScrollableState() const724 bool AccessibilityNode::GetScrollableState() const
725 {
726 return isScrollable_;
727 }
728
SetScrollableState(bool state)729 void AccessibilityNode::SetScrollableState(bool state)
730 {
731 isScrollable_ = state;
732 }
733
GetLongClickableState() const734 bool AccessibilityNode::GetLongClickableState() const
735 {
736 return isLongClickable_;
737 }
738
SetLongClickableState(bool state)739 void AccessibilityNode::SetLongClickableState(bool state)
740 {
741 isLongClickable_ = state;
742 SetSupportAction(AceAction::ACTION_LONG_CLICK, state);
743 }
744
GetIsMultiLine() const745 bool AccessibilityNode::GetIsMultiLine() const
746 {
747 return isMultiLine_;
748 }
749
SetIsMultiLine(bool multiLine)750 void AccessibilityNode::SetIsMultiLine(bool multiLine)
751 {
752 isMultiLine_ = multiLine;
753 }
754
GetIsPassword() const755 bool AccessibilityNode::GetIsPassword() const
756 {
757 return isPassword_;
758 }
759
SetIsPassword(bool isPassword)760 void AccessibilityNode::SetIsPassword(bool isPassword)
761 {
762 isPassword_ = isPassword;
763 }
764
AddSupportAction(AceAction action)765 void AccessibilityNode::AddSupportAction(AceAction action)
766 {
767 supportActions_ |= (1UL << static_cast<uint32_t>(action));
768 }
769
SetSupportAction(AceAction action,bool isEnable)770 void AccessibilityNode::SetSupportAction(AceAction action, bool isEnable)
771 {
772 isEnable ? supportActions_ |= (1UL << static_cast<uint32_t>(action))
773 : supportActions_ &= (~(0UL)) ^ (1UL << static_cast<uint32_t>(action));
774 }
775
GetAccessibilityLabel() const776 const std::string& AccessibilityNode::GetAccessibilityLabel() const
777 {
778 return accessibilityLabel_;
779 }
780
SetAccessibilityLabel(const std::string & label)781 void AccessibilityNode::SetAccessibilityLabel(const std::string& label)
782 {
783 accessibilityLabel_ = label;
784 }
785
GetAccessibilityHint() const786 const std::string& AccessibilityNode::GetAccessibilityHint() const
787 {
788 return accessibilityHint_;
789 }
790
SetAccessibilityHint(const std::string & hint)791 void AccessibilityNode::SetAccessibilityHint(const std::string& hint)
792 {
793 accessibilityHint_ = hint;
794 }
795
GetImportantForAccessibility() const796 const std::string& AccessibilityNode::GetImportantForAccessibility() const
797 {
798 return importantForAccessibility_;
799 }
800
SetImportantForAccessibility(const std::string & importance)801 void AccessibilityNode::SetImportantForAccessibility(const std::string& importance)
802 {
803 importantForAccessibility_ = importance;
804 }
805
GetMaxTextLength() const806 size_t AccessibilityNode::GetMaxTextLength() const
807 {
808 return maxTextLength_;
809 }
810
SetMaxTextLength(size_t length)811 void AccessibilityNode::SetMaxTextLength(size_t length)
812 {
813 maxTextLength_ = length;
814 }
815
GetTextSelectionStart() const816 int32_t AccessibilityNode::GetTextSelectionStart() const
817 {
818 return textSelectionStart_;
819 }
820
SetTextSelectionStart(int32_t start)821 void AccessibilityNode::SetTextSelectionStart(int32_t start)
822 {
823 textSelectionStart_ = start;
824 }
825
GetTextSelectionEnd() const826 int32_t AccessibilityNode::GetTextSelectionEnd() const
827 {
828 return textSelectionEnd_;
829 }
830
SetTextSelectionEnd(int32_t end)831 void AccessibilityNode::SetTextSelectionEnd(int32_t end)
832 {
833 textSelectionEnd_ = end;
834 }
835
GetErrorText() const836 const std::string& AccessibilityNode::GetErrorText() const
837 {
838 return errorText_;
839 }
840
SetErrorText(const std::string & errorText)841 void AccessibilityNode::SetErrorText(const std::string& errorText)
842 {
843 errorText_ = errorText;
844 }
845
GetJsComponentId() const846 const std::string& AccessibilityNode::GetJsComponentId() const
847 {
848 return jsComponentId_;
849 }
850
SetJsComponentId(const std::string & jsComponentId)851 void AccessibilityNode::SetJsComponentId(const std::string& jsComponentId)
852 {
853 jsComponentId_ = jsComponentId;
854 }
855
GetAccessible() const856 bool AccessibilityNode::GetAccessible() const
857 {
858 return accessible_;
859 }
860
SetAccessible(bool accessible)861 void AccessibilityNode::SetAccessible(bool accessible)
862 {
863 accessible_ = accessible;
864 }
865
GetAccessibilityValue() const866 AccessibilityValue AccessibilityNode::GetAccessibilityValue() const
867 {
868 return accessibilityValue_;
869 }
870
SetAccessibilityValue(double cur,double min,double max)871 void AccessibilityNode::SetAccessibilityValue(double cur, double min, double max)
872 {
873 accessibilityValue_.current = cur;
874 accessibilityValue_.min = min;
875 accessibilityValue_.max = max;
876 }
877
GetChartValue() const878 const std::unique_ptr<ChartValue>& AccessibilityNode::GetChartValue() const
879 {
880 return chartValue_;
881 }
882
PutChartValue(const std::string & groupName,const std::vector<std::pair<std::string,double>> & values)883 void AccessibilityNode::PutChartValue(
884 const std::string& groupName, const std::vector<std::pair<std::string, double>>& values)
885 {
886 if (!chartValue_) {
887 chartValue_ = std::make_unique<ChartValue>();
888 }
889
890 auto result = chartValue_->try_emplace(groupName, values);
891 if (!result.second) {
892 result.first->second = values;
893 }
894 }
895
GetInputType() const896 std::string AccessibilityNode::GetInputType() const
897 {
898 return inputType_;
899 }
900
GetTextInputType() const901 AceTextCategory AccessibilityNode::GetTextInputType() const
902 {
903 return textInputType_;
904 }
905
SetTextInputType(AceTextCategory type)906 void AccessibilityNode::SetTextInputType(AceTextCategory type)
907 {
908 textInputType_ = type;
909 }
910
GetCollectionInfo() const911 const AceCollectionInfo& AccessibilityNode::GetCollectionInfo() const
912 {
913 return collectionInfo_;
914 }
915
SetCollectionInfo(const AceCollectionInfo & collectionInfo)916 void AccessibilityNode::SetCollectionInfo(const AceCollectionInfo& collectionInfo)
917 {
918 collectionInfo_ = collectionInfo;
919 }
920
GetCollectionItemInfo() const921 const AceCollectionItemInfo& AccessibilityNode::GetCollectionItemInfo() const
922 {
923 return collectionItemInfo_;
924 }
925
SetCollectionItemInfo(const AceCollectionItemInfo & collectionItemInfo)926 void AccessibilityNode::SetCollectionItemInfo(const AceCollectionItemInfo& collectionItemInfo)
927 {
928 collectionItemInfo_ = collectionItemInfo;
929 }
930
GetShown() const931 bool AccessibilityNode::GetShown() const
932 {
933 return shown_;
934 }
935
GetVisible() const936 bool AccessibilityNode::GetVisible() const
937 {
938 return visible_;
939 }
940
SetVisible(bool visible)941 void AccessibilityNode::SetVisible(bool visible)
942 {
943 visible_ = visible;
944 }
945
GetRect() const946 const Rect& AccessibilityNode::GetRect() const
947 {
948 return rect_;
949 }
950
SetRect(const Rect & rect)951 void AccessibilityNode::SetRect(const Rect& rect)
952 {
953 isValidRect_ = rect.IsValid();
954 if (isValidRect_) {
955 rect_ = rect;
956 }
957 }
958 } // namespace OHOS::Ace
959