File: accessibility_node_info_data_wrapper.h

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (109 lines) | stat: -rw-r--r-- 4,333 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_ACCESSIBILITY_ANDROID_ACCESSIBILITY_NODE_INFO_DATA_WRAPPER_H_
#define SERVICES_ACCESSIBILITY_ANDROID_ACCESSIBILITY_NODE_INFO_DATA_WRAPPER_H_

#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "services/accessibility/android/accessibility_info_data_wrapper.h"
#include "ui/accessibility/ax_enum_util.h"
#include "ui/accessibility/ax_node_data.h"

namespace ax::android {

class AXTreeSourceAndroid;

// Wrapper class for an AccessibilityWindowInfoData.
class AccessibilityNodeInfoDataWrapper : public AccessibilityInfoDataWrapper {
 public:
  AccessibilityNodeInfoDataWrapper(AXTreeSourceAndroid* tree_source,
                                   mojom::AccessibilityNodeInfoData* node);

  AccessibilityNodeInfoDataWrapper(const AccessibilityNodeInfoDataWrapper&) =
      delete;
  AccessibilityNodeInfoDataWrapper& operator=(
      const AccessibilityNodeInfoDataWrapper&) = delete;

  ~AccessibilityNodeInfoDataWrapper() override;

  // AccessibilityInfoDataWrapper overrides.
  bool IsNode() const override;
  mojom::AccessibilityNodeInfoData* GetNode() const override;
  mojom::AccessibilityWindowInfoData* GetWindow() const override;
  int32_t GetId() const override;
  const gfx::Rect GetBounds() const override;
  bool IsVisibleToUser() const override;
  bool IsWebNode() const override;
  bool IsIgnored() const override;
  bool IsImportantInAndroid() const override;
  bool IsFocusableInFullFocusMode() const override;
  bool IsAccessibilityFocusableContainer() const override;
  void PopulateAXRole(ui::AXNodeData* out_data) const override;
  void PopulateAXState(ui::AXNodeData* out_data) const override;
  void Serialize(ui::AXNodeData* out_data) const override;
  std::string ComputeAXName(bool do_recursive) const override;
  void GetChildren(
      std::vector<raw_ptr<AccessibilityInfoDataWrapper, VectorExperimental>>*
          children) const override;
  int32_t GetWindowId() const override;

  mojom::AccessibilityNodeInfoData* node() { return node_ptr_; }

 private:
  bool GetProperty(mojom::AccessibilityBooleanProperty prop) const;
  bool GetProperty(mojom::AccessibilityIntProperty prop,
                   int32_t* out_value) const;
  bool HasProperty(mojom::AccessibilityStringProperty prop) const;
  bool GetProperty(mojom::AccessibilityStringProperty prop,
                   std::string* out_value) const;
  bool GetProperty(mojom::AccessibilityIntListProperty prop,
                   std::vector<int32_t>* out_value) const;
  bool GetProperty(mojom::AccessibilityStringListProperty prop,
                   std::vector<std::string>* out_value) const;

  bool HasStandardAction(mojom::AccessibilityActionType action) const;

  bool HasCoveringSpan(mojom::AccessibilityStringProperty prop,
                       mojom::SpanType span_type) const;

  bool HasText() const;
  bool HasAccessibilityFocusableText() const;

  void ComputeNameFromContents(std::vector<std::string>* names) const;
  void ComputeNameFromContentsInternal(std::vector<std::string>* names) const;

  bool IsClickable() const;
  bool IsLongClickable() const;
  bool IsFocusable() const;

  bool IsScrollableContainer() const;
  bool IsToplevelScrollItem() const;

  bool HasImportantProperty() const;
  bool HasImportantPropertyInternal() const;

  ax::mojom::Role GetChromeRole() const;

  raw_ptr<mojom::AccessibilityNodeInfoData, DanglingUntriaged> node_ptr_ =
      nullptr;

  // Properties which should be checked for recursive text computation.
  // It's not clear whether labeled by should be taken into account here.
  static constexpr mojom::AccessibilityStringProperty text_properties_[3] = {
      mojom::AccessibilityStringProperty::TEXT,
      mojom::AccessibilityStringProperty::CONTENT_DESCRIPTION,
      mojom::AccessibilityStringProperty::STATE_DESCRIPTION};

  // These properties are a cached value so that we can avoid same computation.
  // mutable because once the value is computed it won't change.
  mutable std::optional<bool> has_important_property_cache_;
  mutable std::optional<bool> is_web_node_;
};

}  // namespace ax::android

#endif  // SERVICES_ACCESSIBILITY_ANDROID_ACCESSIBILITY_NODE_INFO_DATA_WRAPPER_H_