blob: ba8bc37fba83797ef32404901127501571298b24 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2020 The Chromium Authors
Mario Sanchez Prada1b559ffe2020-07-14 12:58:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_ACCESSIBILITY_AX_ACTION_HANDLER_BASE_H_
6#define UI_ACCESSIBILITY_AX_ACTION_HANDLER_BASE_H_
7
Dominic Mazzonic39830f2021-02-02 05:58:268#include "ui/accessibility/ax_base_export.h"
Mario Sanchez Prada1b559ffe2020-07-14 12:58:309#include "ui/accessibility/ax_tree_id.h"
10
11namespace ui {
12
13struct AXActionData;
14
15// Classes that host an accessibility tree in the browser process that also wish
16// to become visible to accessibility clients (e.g. for relaying targets to
17// source accessibility trees), can subclass this class. However, unless you
18// need to have more control over how |tree_id_| is set, most classes will want
19// to inherit from AXActionHandler instead, which manages it automatically.
20//
21// Subclasses can use |tree_id| when annotating their |AXNodeData| for clients
22// to respond with the appropriate target node id.
Dominic Mazzonic39830f2021-02-02 05:58:2623class AX_BASE_EXPORT AXActionHandlerBase {
Mario Sanchez Prada1b559ffe2020-07-14 12:58:3024 public:
25 virtual ~AXActionHandlerBase();
26
27 // Handle an action from an accessibility client.
28 virtual void PerformAction(const AXActionData& data) = 0;
29
30 // Returns whether this handler expects points in pixels (true) or dips
31 // (false) for data passed to |PerformAction|.
32 virtual bool RequiresPerformActionPointInPixels() const;
33
34 // A tree id appropriate for annotating events sent to an accessibility
35 // client.
36 const AXTreeID& ax_tree_id() const { return tree_id_; }
37
38 protected:
Jacques Newmana4149e852024-08-28 23:35:4239 // Initializes the AXActionHandlerBase subclass with AXTreeIDUnknown().
Mario Sanchez Prada1b559ffe2020-07-14 12:58:3040 AXActionHandlerBase();
41
42 // Initializes the AXActionHandlerBase subclass with |ax_tree_id|. It is Ok to
Jacques Newmana4149e852024-08-28 23:35:4243 // pass AXTreeIDUnknown() and then call SetAXTreeID() at a later point.
Mario Sanchez Prada1b559ffe2020-07-14 12:58:3044 explicit AXActionHandlerBase(const AXTreeID& ax_tree_id);
45
Mario Sanchez Prada1b559ffe2020-07-14 12:58:3046 void SetAXTreeID(AXTreeID new_ax_tree_id);
Nektarios Paisios85d68d8b2024-10-02 19:31:1147 void RemoveAXTreeID();
Mario Sanchez Prada1b559ffe2020-07-14 12:58:3048
49 private:
Erik Chen2ccece52021-03-18 01:59:1550 // Register or unregister this class with |AXActionHandlerRegistry|.
Mario Sanchez Prada1b559ffe2020-07-14 12:58:3051 void UpdateActiveState(bool active);
52
53 // Manually set in this base class, but automatically set by instances of the
54 // subclass AXActionHandler, which most classes inherit from.
55 AXTreeID tree_id_;
56};
57
58} // namespace ui
59
60#endif // UI_ACCESSIBILITY_AX_ACTION_HANDLER_BASE_H_