ax_text_utils.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2012 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_TEXT_UTILS_H_
  5. #define UI_ACCESSIBILITY_AX_TEXT_UTILS_H_
  6. #include <stddef.h>
  7. #include <string>
  8. #include <vector>
  9. #include "ui/accessibility/ax_enums.mojom-forward.h"
  10. #include "ui/accessibility/ax_export.h"
  11. namespace ui {
  12. // Convenience method needed to implement platform-specific text
  13. // accessibility APIs like IAccessible2. Search forwards or backwards
  14. // (depending on |direction|) from the given |start_offset| until the
  15. // given boundary is found, and return the offset of that boundary,
  16. // using the vector of line break character offsets in |line_breaks|.
  17. AX_EXPORT size_t FindAccessibleTextBoundary(const std::u16string& text,
  18. const std::vector<int>& line_breaks,
  19. ax::mojom::TextBoundary boundary,
  20. size_t start_offset,
  21. ax::mojom::MoveDirection direction,
  22. ax::mojom::TextAffinity affinity);
  23. // Returns a string ID that corresponds to the name of the given action.
  24. AX_EXPORT std::u16string ActionVerbToLocalizedString(
  25. const ax::mojom::DefaultActionVerb action_verb);
  26. // Returns the non-localized string representation of a supported action.
  27. // Some APIs on Linux and Windows need to return non-localized action names.
  28. AX_EXPORT std::u16string ActionVerbToUnlocalizedString(
  29. const ax::mojom::DefaultActionVerb action_verb);
  30. // Returns indices of all word starts in |text|.
  31. AX_EXPORT std::vector<int> GetWordStartOffsets(const std::u16string& text);
  32. // Returns indices of all word ends in |text|.
  33. AX_EXPORT std::vector<int> GetWordEndOffsets(const std::u16string& text);
  34. // Returns indices of all sentence starts in |text|.
  35. AX_EXPORT std::vector<int> GetSentenceStartOffsets(const std::u16string& text);
  36. // Returns indices of all sentence ends in |text|.
  37. AX_EXPORT std::vector<int> GetSentenceEndOffsets(const std::u16string& text);
  38. } // namespace ui
  39. #endif // UI_ACCESSIBILITY_AX_TEXT_UTILS_H_