File: ax_call_statement_invoker_win.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (128 lines) | stat: -rw-r--r-- 5,387 bytes parent folder | download | duplicates (4)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_ACCESSIBILITY_PLATFORM_INSPECT_AX_CALL_STATEMENT_INVOKER_WIN_H_
#define UI_ACCESSIBILITY_PLATFORM_INSPECT_AX_CALL_STATEMENT_INVOKER_WIN_H_

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "ui/accessibility/platform/iaccessible2/scoped_co_mem_array.h"
#include "ui/accessibility/platform/inspect/ax_optional.h"
#include "ui/accessibility/platform/inspect/ax_property_node.h"
#include "ui/accessibility/platform/inspect/ax_target_win.h"
#include "ui/accessibility/platform/inspect/ax_tree_indexer_win.h"

namespace ui {

// Optional tri-state object.
using AXOptionalObject = AXOptional<AXTargetWin>;

// Invokes a script instruction describing a call unit which represents
// a sequence of calls.
class COMPONENT_EXPORT(AX_PLATFORM) AXCallStatementInvokerWin final {
 public:
  using Target = AXTargetWin;

  // All calls are executed in the context of property nodes.
  // Note: both |indexer| and |storage| must outlive this object.
  AXCallStatementInvokerWin(const AXTreeIndexerWin* indexer,
                            std::map<std::string, Target>* storage);

  // Invokes an attribute matching a property filter.
  AXOptionalObject Invoke(const AXPropertyNode& property_node) const;

  static std::string ToString(const AXOptionalObject& optional);

 private:
  // Invokes a property node for a given target.
  AXOptionalObject InvokeFor(const Target& target,
                             const AXPropertyNode& property_node) const;

  // Invokes a property node for a given AXElement.
  AXOptionalObject InvokeForAXElement(
      const IAccessibleComPtr& target,
      const AXPropertyNode& property_node) const;

  // Invoke for a given interface.
  AXOptionalObject InvokeForIA2(const IA2ComPtr& target,
                                const AXPropertyNode& property_node) const;
  AXOptionalObject InvokeForIA2Hypertext(
      const IA2HypertextComPtr& target,
      const AXPropertyNode& property_node) const;
  AXOptionalObject InvokeForIA2Table(const IA2TableComPtr& target,
                                     const AXPropertyNode& property_node) const;
  AXOptionalObject InvokeForIA2TableCell(
      const IA2TableCellComPtr& target,
      const AXPropertyNode& property_node) const;
  AXOptionalObject InvokeForIA2TextSelectionContainer(
      const IA2TextSelectionContainerComPtr& target,
      const AXPropertyNode& property_node) const;
  AXOptionalObject InvokeForIA2Text(const IA2TextComPtr& target,
                                    const AXPropertyNode& property_node) const;
  AXOptionalObject InvokeForIA2Value(const IA2ValueComPtr& target,
                                     const AXPropertyNode& property_node) const;

  // IUnknown functionality.
  AXOptionalObject QueryInterface(const IAccessibleComPtr& target,
                                  std::string interface_name) const;

  // IAccessible functionality.
  AXOptionalObject GetRole(const IAccessibleComPtr& target) const;
  AXOptionalObject GetName(const IAccessibleComPtr& target) const;
  AXOptionalObject GetDescription(const IAccessibleComPtr& target) const;
  AXOptionalObject HasState(const IAccessibleComPtr& target,
                            std::string state) const;

  // IAccessible2 functionality.
  AXOptionalObject GetIA2Role(const IA2ComPtr& target) const;
  AXOptionalObject GetIA2Attribute(const IA2ComPtr& target,
                                   const AXPropertyNode& property_node) const;
  AXOptionalObject HasIA2State(const IA2ComPtr& target,
                               const AXPropertyNode& property_node) const;

  // AccessibleTable functionality
  AXOptionalObject GetSelectedColumns(const IA2TableComPtr& target) const;

  // IAccessibleSelectionContainer functionality.
  AXOptionalObject GetSelections(
      const IA2TextSelectionContainerComPtr& target) const;
  AXOptionalObject SetSelections(const IA2TextSelectionContainerComPtr& target,
                                 const AXPropertyNode& property_node) const;

  bool IsIAccessibleAndNotNull(const Target& target) const;

  // PropertyNode conversion methods.
  template <typename Interface>
  Microsoft::WRL::ComPtr<Interface> PropertyNodeToIAccessible(
      const AXPropertyNode& node) const {
    Microsoft::WRL::ComPtr<IAccessible> accessible =
        indexer_->NodeBy(node.name_or_value);
    if (!accessible) {
      return nullptr;
    }
    Microsoft::WRL::ComPtr<Interface> queried_accessible;
    HRESULT hr = accessible->QueryInterface(IID_PPV_ARGS(&queried_accessible));
    if (FAILED(hr)) {
      return nullptr;
    }
    return queried_accessible;
  }

  std::optional<IA2TextSelection> PropertyNodeToIA2TextSelection(
      const AXPropertyNode& node) const;

  ScopedCoMemArray<IA2TextSelection> PropertyNodeToIA2TextSelectionArray(
      const AXPropertyNode& node) const;

  // Map between IAccessible objects and their DOMIds/accessible tree
  // line numbers. Owned by the caller and outlives this object.
  const raw_ptr<const AXTreeIndexerWin> indexer_;

  // Variables storage. Owned by the caller and outlives this object.
  const raw_ptr<std::map<std::string, Target>> storage_;
};

}  // namespace ui

#endif  // UI_ACCESSIBILITY_PLATFORM_INSPECT_AX_CALL_STATEMENT_INVOKER_WIN_H_