File: accessibility_bridge_fuchsia_impl.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,459 bytes parent folder | download | duplicates (5)
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_FUCHSIA_ACCESSIBILITY_BRIDGE_FUCHSIA_IMPL_H_
#define UI_ACCESSIBILITY_PLATFORM_FUCHSIA_ACCESSIBILITY_BRIDGE_FUCHSIA_IMPL_H_

#include <fidl/fuchsia.accessibility.semantics/cpp/fidl.h>
#include <fuchsia/ui/views/cpp/fidl.h>
#include <lib/inspect/cpp/vmo/types.h>

#include <optional>

#include "base/component_export.h"
#include "base/containers/flat_map.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "ui/accessibility/platform/fuchsia/accessibility_bridge_fuchsia.h"
#include "ui/accessibility/platform/fuchsia/semantic_provider.h"
#include "ui/aura/window.h"

namespace ui {

class COMPONENT_EXPORT(AX_PLATFORM) AccessibilityBridgeFuchsiaImpl final
    : public AccessibilityBridgeFuchsia,
      public AXFuchsiaSemanticProvider::Delegate {
 public:
  using OnConnectionClosedCallback = base::RepeatingCallback<bool(zx_status_t)>;

  // Constructor args:
  //
  // |root_window|: Refers to the root aura::Window for which this accessibility
  // bridge instance is responsible. The pointer is NOT owned by this class.
  // The accessibility bridge instance's lifespan is not explicitly tied to the
  // window's, but they are expected to be deleted together.
  //
  // |view_ref|: The fuchsia ViewRef for the fuchsia view that corresponds to
  // |root_window|.
  //
  // |on_semantics_enabled|: Callback invoked when fuchsia's accessibility
  // platform component requests to enable/disable semantics (e.g. when the
  // screen reader is toggled on/off). The boolean argument to the callback
  // indicates whether semantics should be enabled or disabled (true => enable
  // semantics, false => disable semantics).
  //
  // |on_connection_closed|: Callback invoked when the FIDL connection to the
  // fuchsia accessibility platform component closes. The return value indicates
  // whether an attempt to reconnect should be made (true => reconnect, false =>
  // do not reconnect).
  AccessibilityBridgeFuchsiaImpl(
      aura::Window* root_window,
      fuchsia_ui_views::ViewRef view_ref,
      base::RepeatingCallback<void(bool)> on_semantics_enabled,
      OnConnectionClosedCallback on_connection_closed,
      inspect::Node inspect_node);
  ~AccessibilityBridgeFuchsiaImpl() override;

  // AccessibilityBridgeFuchsia overrides.
  void UpdateNode(fuchsia_accessibility_semantics::Node node) override;
  void DeleteNode(uint32_t node_id) override;
  void OnAccessibilityHitTestResult(int hit_test_request_id,
                                    std::optional<uint32_t> result) override;
  float GetDeviceScaleFactor() override;
  void SetRootID(uint32_t root_node_id) override;
  inspect::Node GetInspectNode() override;

  // SemanticProvider::Delegate overrides.
  bool OnSemanticsManagerConnectionClosed(zx_status_t status) override;
  bool OnAccessibilityAction(
      uint32_t node_id,
      fuchsia_accessibility_semantics::Action action) override;
  void OnHitTest(fuchsia_math::PointF point, HitTestCallback callback) override;
  void OnSemanticsEnabled(bool enabled) override;

  // Test-only method to set `semantic_provider_`.
  void set_semantic_provider_for_test(
      std::unique_ptr<AXFuchsiaSemanticProvider> semantic_provider);

  // Propagates new pixel scale to `semantic_provider_`.
  void SetPixelScale(float pixel_scale);

 private:
  // Returns kFuchsiaRootNodeId if node_id == *root_node_id_. Otherwise, returns
  // node_id.
  uint32_t MaybeToFuchsiaRootID(uint32_t node_id);

  // Root window for the fuchsia view for which this accessibility bridge
  // instance is responsible.
  raw_ptr<aura::Window> root_window_;

  // Manages connections with the fuchsia semantics APIs.
  std::unique_ptr<AXFuchsiaSemanticProvider> semantic_provider_;

  // Fuchsia semantic trees require that the root node ID == 0. The
  // AXUniqueId of the chrome node corresponding to the fuchsia root will NOT be
  // 0, so we need to store it here in order to map between the two.
  std::optional<uint32_t> root_node_id_;

  // Holds callbacks for hit tests that have not yet completed, keyed by a
  // request ID that this class generates.
  base::flat_map<int /* request_id */, HitTestCallback>
      pending_hit_test_completers_;

  // Next hit test request ID to use.
  int next_hittest_request_id_ = 1;

  // Callback invoked whenever the semantics enabled state changes.
  base::RepeatingCallback<void(bool)> on_semantics_enabled_;

  // Callback invoked whenever the semantics manager connection is closed.
  // We use a base::RepeatingCallback, because we may attempt to reconnect, in
  // which case it's possible that we may need to invoke the callback more than
  // once.
  OnConnectionClosedCallback on_connection_closed_;

  // The inspect output will have a node for each AXTree in this accessibility
  // bridge's window. Inspect node names are static, but AXTreeIDs can change.
  // It could be misleading for users to see an old AXTreeID in the inspect
  // output, so instead, we'll name each node "AXTree_#". The
  // next_inspect_tree_number_ member is used to generate these names.
  int next_inspect_tree_number_ = 1;

  // Inspect node for the accessibility bridge.
  inspect::Node inspect_node_;
};

}  // namespace ui
#endif  // UI_ACCESSIBILITY_PLATFORM_FUCHSIA_ACCESSIBILITY_BRIDGE_FUCHSIA_IMPL_H_