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 5 #include "ui/accessibility/ax_relative_bounds.h" 6 7 #include "base/strings/string_number_conversions.h" 8 #include "ui/accessibility/ax_enum_util.h" 9 #include "ui/gfx/transform.h" 10 11 using base::NumberToString; 12 13 namespace ui { 14 AXRelativeBounds()15AXRelativeBounds::AXRelativeBounds() 16 : offset_container_id(-1) { 17 } 18 ~AXRelativeBounds()19AXRelativeBounds::~AXRelativeBounds() { 20 } 21 AXRelativeBounds(const AXRelativeBounds & other)22AXRelativeBounds::AXRelativeBounds(const 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 } 28 operator =(AXRelativeBounds other)29AXRelativeBounds& AXRelativeBounds::operator=(AXRelativeBounds other) { 30 offset_container_id = other.offset_container_id; 31 bounds = other.bounds; 32 if (other.transform) 33 transform = std::make_unique<gfx::Transform>(*other.transform); 34 else 35 transform.reset(nullptr); 36 return *this; 37 } 38 operator ==(const AXRelativeBounds & other) const39bool AXRelativeBounds::operator==(const AXRelativeBounds& other) const { 40 if (offset_container_id != other.offset_container_id) 41 return false; 42 if (bounds != other.bounds) 43 return false; 44 if (!transform && !other.transform) 45 return true; 46 if ((transform && !other.transform) || (!transform && other.transform)) 47 return false; 48 return *transform == *other.transform; 49 } 50 operator !=(const AXRelativeBounds & other) const51bool AXRelativeBounds::operator!=(const AXRelativeBounds& other) const { 52 return !operator==(other); 53 } 54 ToString() const55std::string AXRelativeBounds::ToString() const { 56 std::string result; 57 58 if (offset_container_id != -1) 59 result += 60 "offset_container_id=" + NumberToString(offset_container_id) + " "; 61 62 result += "(" + NumberToString(bounds.x()) + ", " + 63 NumberToString(bounds.y()) + ")-(" + 64 NumberToString(bounds.width()) + ", " + 65 NumberToString(bounds.height()) + ")"; 66 67 if (transform && !transform->IsIdentity()) 68 result += " transform=" + transform->ToString(); 69 70 return result; 71 } 72 operator <<(std::ostream & stream,const AXRelativeBounds & bounds)73std::ostream& operator<<(std::ostream& stream, const AXRelativeBounds& bounds) { 74 return stream << bounds.ToString(); 75 } 76 77 } // namespace ui 78