ax_action_handler_base.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_ACCESSIBILITY_AX_ACTION_HANDLER_BASE_H_
  5. #define UI_ACCESSIBILITY_AX_ACTION_HANDLER_BASE_H_
  6. #include "ui/accessibility/ax_base_export.h"
  7. #include "ui/accessibility/ax_tree_id.h"
  8. namespace ui {
  9. struct AXActionData;
  10. // Classes that host an accessibility tree in the browser process that also wish
  11. // to become visible to accessibility clients (e.g. for relaying targets to
  12. // source accessibility trees), can subclass this class. However, unless you
  13. // need to have more control over how |tree_id_| is set, most classes will want
  14. // to inherit from AXActionHandler instead, which manages it automatically.
  15. //
  16. // Subclasses can use |tree_id| when annotating their |AXNodeData| for clients
  17. // to respond with the appropriate target node id.
  18. class AX_BASE_EXPORT AXActionHandlerBase {
  19. public:
  20. virtual ~AXActionHandlerBase();
  21. // Handle an action from an accessibility client.
  22. virtual void PerformAction(const AXActionData& data) = 0;
  23. // Returns whether this handler expects points in pixels (true) or dips
  24. // (false) for data passed to |PerformAction|.
  25. virtual bool RequiresPerformActionPointInPixels() const;
  26. // A tree id appropriate for annotating events sent to an accessibility
  27. // client.
  28. const AXTreeID& ax_tree_id() const { return tree_id_; }
  29. protected:
  30. // Initializes the AXActionHandlerBase subclass with ui::AXTreeIDUnknown().
  31. AXActionHandlerBase();
  32. // Initializes the AXActionHandlerBase subclass with |ax_tree_id|. It is Ok to
  33. // pass ui::AXTreeIDUnknown() and then call SetAXTreeID() at a later point.
  34. explicit AXActionHandlerBase(const AXTreeID& ax_tree_id);
  35. // Change the AXTreeID.
  36. void SetAXTreeID(AXTreeID new_ax_tree_id);
  37. private:
  38. // Register or unregister this class with |AXActionHandlerRegistry|.
  39. void UpdateActiveState(bool active);
  40. // Manually set in this base class, but automatically set by instances of the
  41. // subclass AXActionHandler, which most classes inherit from.
  42. AXTreeID tree_id_;
  43. };
  44. } // namespace ui
  45. #endif // UI_ACCESSIBILITY_AX_ACTION_HANDLER_BASE_H_