Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 2 | // 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 Mazzoni | c39830f | 2021-02-02 05:58:26 | [diff] [blame] | 8 | #include "ui/accessibility/ax_base_export.h" |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 9 | #include "ui/accessibility/ax_tree_id.h" |
| 10 | |
| 11 | namespace ui { |
| 12 | |
| 13 | struct 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 Mazzoni | c39830f | 2021-02-02 05:58:26 | [diff] [blame] | 23 | class AX_BASE_EXPORT AXActionHandlerBase { |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 24 | 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 Newman | a4149e85 | 2024-08-28 23:35:42 | [diff] [blame] | 39 | // Initializes the AXActionHandlerBase subclass with AXTreeIDUnknown(). |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 40 | AXActionHandlerBase(); |
| 41 | |
| 42 | // Initializes the AXActionHandlerBase subclass with |ax_tree_id|. It is Ok to |
Jacques Newman | a4149e85 | 2024-08-28 23:35:42 | [diff] [blame] | 43 | // pass AXTreeIDUnknown() and then call SetAXTreeID() at a later point. |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 44 | explicit AXActionHandlerBase(const AXTreeID& ax_tree_id); |
| 45 | |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 46 | void SetAXTreeID(AXTreeID new_ax_tree_id); |
Nektarios Paisios | 85d68d8b | 2024-10-02 19:31:11 | [diff] [blame] | 47 | void RemoveAXTreeID(); |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 48 | |
| 49 | private: |
Erik Chen | 2ccece5 | 2021-03-18 01:59:15 | [diff] [blame] | 50 | // Register or unregister this class with |AXActionHandlerRegistry|. |
Mario Sanchez Prada | 1b559ffe | 2020-07-14 12:58:30 | [diff] [blame] | 51 | 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_ |