dmazzoni | 051715a | 2016-08-15 21:36:58 | [diff] [blame] | 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/gfx/transform.h" |
| 9 | |
| 10 | using base::IntToString; |
| 11 | |
| 12 | namespace ui { |
| 13 | |
| 14 | AXRelativeBounds::AXRelativeBounds() |
| 15 | : offset_container_id(-1) { |
| 16 | } |
| 17 | |
| 18 | AXRelativeBounds::~AXRelativeBounds() { |
| 19 | } |
| 20 | |
| 21 | AXRelativeBounds::AXRelativeBounds(const AXRelativeBounds& other) { |
| 22 | offset_container_id = other.offset_container_id; |
| 23 | bounds = other.bounds; |
| 24 | if (other.transform) |
| 25 | transform.reset(new gfx::Transform(*other.transform)); |
| 26 | } |
| 27 | |
| 28 | AXRelativeBounds& AXRelativeBounds::operator=(AXRelativeBounds other) { |
| 29 | offset_container_id = other.offset_container_id; |
| 30 | bounds = other.bounds; |
| 31 | if (other.transform) |
| 32 | transform.reset(new gfx::Transform(*other.transform)); |
| 33 | return *this; |
| 34 | } |
| 35 | |
| 36 | bool AXRelativeBounds::operator==(const AXRelativeBounds& other) { |
| 37 | if (offset_container_id != other.offset_container_id) |
| 38 | return false; |
| 39 | if (bounds != other.bounds) |
| 40 | return false; |
| 41 | if (!transform && !other.transform) |
| 42 | return true; |
| 43 | if ((transform && !other.transform) || (!transform && other.transform)) |
| 44 | return false; |
| 45 | return *transform == *other.transform; |
| 46 | } |
| 47 | |
| 48 | bool AXRelativeBounds::operator!=(const AXRelativeBounds& other) { |
| 49 | return !operator==(other); |
| 50 | } |
| 51 | |
| 52 | std::string AXRelativeBounds::ToString() const { |
| 53 | std::string result; |
| 54 | |
| 55 | if (offset_container_id != -1) |
| 56 | result += "offset_container_id=" + IntToString(offset_container_id) + " "; |
| 57 | |
| 58 | result += "(" + IntToString(bounds.x()) + ", " + |
| 59 | IntToString(bounds.y()) + ")-(" + |
| 60 | IntToString(bounds.width()) + ", " + |
| 61 | IntToString(bounds.height()) + ")"; |
| 62 | |
| 63 | if (transform && !transform->IsIdentity()) |
| 64 | result += " transform=" + transform->ToString(); |
| 65 | |
| 66 | return result; |
| 67 | } |
| 68 | |
| 69 | } // namespace ui |