| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/rect.h" | 5 #include "ui/gfx/rect.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #elif defined(OS_MACOSX) | 9 #elif defined(OS_MACOSX) |
| 10 #include <CoreGraphics/CGGeometry.h> | 10 #include <CoreGraphics/CGGeometry.h> |
| 11 #elif defined(TOOLKIT_USES_GTK) | 11 #elif defined(TOOLKIT_USES_GTK) |
| 12 #include <gdk/gdk.h> | 12 #include <gdk/gdk.h> |
| 13 #endif | 13 #endif |
| 14 #if defined(USE_WAYLAND) | 14 #if defined(USE_WAYLAND) |
| 15 #include <cairo.h> | 15 #include <cairo.h> |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 #include <ostream> | 18 #include "base/stringprintf.h" |
| 19 | |
| 20 #include "ui/gfx/insets.h" | 19 #include "ui/gfx/insets.h" |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { | 23 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { |
| 25 if (*origin < dst_origin) { | 24 if (*origin < dst_origin) { |
| 26 *origin = dst_origin; | 25 *origin = dst_origin; |
| 27 *size = std::min(dst_size, *size); | 26 *size = std::min(dst_size, *size); |
| 28 } else { | 27 } else { |
| 29 *size = std::min(dst_size, *size); | 28 *size = std::min(dst_size, *size); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 47 } | 46 } |
| 48 | 47 |
| 49 Rect::Rect(const gfx::Size& size) | 48 Rect::Rect(const gfx::Size& size) |
| 50 : size_(size) { | 49 : size_(size) { |
| 51 } | 50 } |
| 52 | 51 |
| 53 Rect::Rect(const gfx::Point& origin, const gfx::Size& size) | 52 Rect::Rect(const gfx::Point& origin, const gfx::Size& size) |
| 54 : origin_(origin), size_(size) { | 53 : origin_(origin), size_(size) { |
| 55 } | 54 } |
| 56 | 55 |
| 56 Rect::~Rect() {} |
| 57 |
| 57 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 58 Rect::Rect(const RECT& r) | 59 Rect::Rect(const RECT& r) |
| 59 : origin_(r.left, r.top) { | 60 : origin_(r.left, r.top) { |
| 60 set_width(std::abs(r.right - r.left)); | 61 set_width(std::abs(r.right - r.left)); |
| 61 set_height(std::abs(r.bottom - r.top)); | 62 set_height(std::abs(r.bottom - r.top)); |
| 62 } | 63 } |
| 63 | 64 |
| 64 Rect& Rect::operator=(const RECT& r) { | 65 Rect& Rect::operator=(const RECT& r) { |
| 65 origin_.SetPoint(r.left, r.top); | 66 origin_.SetPoint(r.left, r.top); |
| 66 set_width(std::abs(r.right - r.left)); | 67 set_width(std::abs(r.right - r.left)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 103 } |
| 103 | 104 |
| 104 Rect& Rect::operator=(const cairo_rectangle_int_t& r) { | 105 Rect& Rect::operator=(const cairo_rectangle_int_t& r) { |
| 105 origin_.SetPoint(r.x, r.y); | 106 origin_.SetPoint(r.x, r.y); |
| 106 set_width(r.width); | 107 set_width(r.width); |
| 107 set_height(r.height); | 108 set_height(r.height); |
| 108 return *this; | 109 return *this; |
| 109 } | 110 } |
| 110 #endif | 111 #endif |
| 111 | 112 |
| 112 | |
| 113 void Rect::SetRect(int x, int y, int width, int height) { | 113 void Rect::SetRect(int x, int y, int width, int height) { |
| 114 origin_.SetPoint(x, y); | 114 origin_.SetPoint(x, y); |
| 115 set_width(width); | 115 set_width(width); |
| 116 set_height(height); | 116 set_height(height); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void Rect::Inset(const gfx::Insets& insets) { | 119 void Rect::Inset(const gfx::Insets& insets) { |
| 120 Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); | 120 Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); |
| 121 } | 121 } |
| 122 | 122 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 return Rect(new_x, new_y, new_width, new_height); | 266 return Rect(new_x, new_y, new_width, new_height); |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool Rect::SharesEdgeWith(const gfx::Rect& rect) const { | 269 bool Rect::SharesEdgeWith(const gfx::Rect& rect) const { |
| 270 return (y() == rect.y() && height() == rect.height() && | 270 return (y() == rect.y() && height() == rect.height() && |
| 271 (x() == rect.right() || right() == rect.x())) || | 271 (x() == rect.right() || right() == rect.x())) || |
| 272 (x() == rect.x() && width() == rect.width() && | 272 (x() == rect.x() && width() == rect.width() && |
| 273 (y() == rect.bottom() || bottom() == rect.y())); | 273 (y() == rect.bottom() || bottom() == rect.y())); |
| 274 } | 274 } |
| 275 | 275 |
| 276 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) { | 276 std::string Rect::ToString() const { |
| 277 return out << r.origin().ToString() << " " << r.size().ToString(); | 277 return base::StringPrintf("%s %s", |
| 278 origin_.ToString().c_str(), |
| 279 size_.ToString().c_str()); |
| 278 } | 280 } |
| 279 | 281 |
| 280 } // namespace gfx | 282 } // namespace gfx |
| OLD | NEW |