ax_assistant_structure_mojom_traits.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2018 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. #include "ui/accessibility/mojom/ax_assistant_structure_mojom_traits.h"
  5. #include "mojo/public/cpp/base/string16_mojom_traits.h"
  6. #include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"
  7. #include "ui/gfx/range/mojom/range_mojom_traits.h"
  8. namespace mojo {
  9. // static
  10. bool StructTraits<ax::mojom::AssistantTreeDataView,
  11. std::unique_ptr<ui::AssistantTree>>::
  12. Read(ax::mojom::AssistantTreeDataView data,
  13. std::unique_ptr<ui::AssistantTree>* out) {
  14. DCHECK(!*out);
  15. *out = std::make_unique<ui::AssistantTree>();
  16. if (!data.ReadNodes(&(*out)->nodes))
  17. return false;
  18. for (size_t i = 0; i < (*out)->nodes.size(); i++) {
  19. // Each child's index should be greater than its parent and within the array
  20. // bounds. This implies that there is no circle in the tree.
  21. for (size_t child_index : (*out)->nodes[i]->children_indices) {
  22. if (child_index <= i || child_index >= (*out)->nodes.size())
  23. return false;
  24. }
  25. }
  26. return true;
  27. }
  28. // static
  29. bool StructTraits<ax::mojom::AssistantNodeDataView,
  30. std::unique_ptr<ui::AssistantNode>>::
  31. Read(ax::mojom::AssistantNodeDataView data,
  32. std::unique_ptr<ui::AssistantNode>* out) {
  33. DCHECK(!out->get());
  34. *out = std::make_unique<ui::AssistantNode>();
  35. (*out)->bgcolor = data.bgcolor();
  36. (*out)->bold = data.bold();
  37. (*out)->color = data.color();
  38. (*out)->italic = data.italic();
  39. (*out)->line_through = data.line_through();
  40. (*out)->underline = data.underline();
  41. if (!data.ReadRect(&(*out)->rect) || !data.ReadText(&(*out)->text) ||
  42. !data.ReadRole(&(*out)->role) ||
  43. !data.ReadSelection(&(*out)->selection) ||
  44. !data.ReadChildrenIndices(&(*out)->children_indices) ||
  45. !data.ReadClassName(&(*out)->class_name)) {
  46. return false;
  47. }
  48. return true;
  49. }
  50. } // namespace mojo