ax_relative_bounds.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2016 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/ax_relative_bounds.h"
  5. #include "base/memory/values_equivalent.h"
  6. #include "base/strings/string_number_conversions.h"
  7. #include "ui/accessibility/ax_enum_util.h"
  8. #include "ui/gfx/geometry/transform.h"
  9. using base::NumberToString;
  10. namespace ui {
  11. AXRelativeBounds::AXRelativeBounds()
  12. : offset_container_id(-1) {
  13. }
  14. AXRelativeBounds::~AXRelativeBounds() {
  15. }
  16. AXRelativeBounds::AXRelativeBounds(const AXRelativeBounds& other) {
  17. offset_container_id = other.offset_container_id;
  18. bounds = other.bounds;
  19. if (other.transform)
  20. transform = std::make_unique<gfx::Transform>(*other.transform);
  21. }
  22. AXRelativeBounds& AXRelativeBounds::operator=(AXRelativeBounds other) {
  23. offset_container_id = other.offset_container_id;
  24. bounds = other.bounds;
  25. if (other.transform)
  26. transform = std::make_unique<gfx::Transform>(*other.transform);
  27. else
  28. transform.reset(nullptr);
  29. return *this;
  30. }
  31. bool AXRelativeBounds::operator==(const AXRelativeBounds& other) const {
  32. if (offset_container_id != other.offset_container_id)
  33. return false;
  34. if (bounds != other.bounds)
  35. return false;
  36. return base::ValuesEquivalent(transform, other.transform);
  37. }
  38. bool AXRelativeBounds::operator!=(const AXRelativeBounds& other) const {
  39. return !operator==(other);
  40. }
  41. std::string AXRelativeBounds::ToString() const {
  42. std::string result;
  43. if (offset_container_id != -1)
  44. result +=
  45. "offset_container_id=" + NumberToString(offset_container_id) + " ";
  46. result += "(" + NumberToString(bounds.x()) + ", " +
  47. NumberToString(bounds.y()) + ")-(" +
  48. NumberToString(bounds.width()) + ", " +
  49. NumberToString(bounds.height()) + ")";
  50. if (transform && !transform->IsIdentity())
  51. result += " transform=" + transform->ToString();
  52. return result;
  53. }
  54. std::ostream& operator<<(std::ostream& stream, const AXRelativeBounds& bounds) {
  55. return stream << bounds.ToString();
  56. }
  57. } // namespace ui