1 // Copyright (c) 2012 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.
5 #include "ui/gfx/rect.h"
11 #elif defined(TOOLKIT_GTK)
15 #include "base/logging.h"
16 #include "base/strings/stringprintf.h"
17 #include "ui/gfx/insets.h"
18 #include "ui/gfx/rect_base_impl.h"
22 template class RectBase<Rect, Point, Size, Insets, Vector2d, int>;
24 typedef class RectBase<Rect, Point, Size, Insets, Vector2d, int> RectBaseT;
27 Rect::Rect(const RECT& r)
28 : RectBaseT(gfx::Point(r.left, r.top)) {
29 set_width(std::abs(r.right - r.left));
30 set_height(std::abs(r.bottom - r.top));
32 #elif defined(OS_MACOSX)
33 Rect::Rect(const CGRect& r)
34 : RectBaseT(gfx::Point(r.origin.x, r.origin.y)) {
35 set_width(r.size.width);
36 set_height(r.size.height);
38 #elif defined(TOOLKIT_GTK)
39 Rect::Rect(const GdkRectangle& r)
40 : RectBaseT(gfx::Point(r.x, r.y)) {
47 RECT Rect::ToRECT() const {
55 #elif defined(OS_MACOSX)
56 CGRect Rect::ToCGRect() const {
57 return CGRectMake(x(), y(), width(), height());
59 #elif defined(TOOLKIT_GTK)
60 GdkRectangle Rect::ToGdkRectangle() const {
61 GdkRectangle r = {x(), y(), width(), height()};
66 std::string Rect::ToString() const {
67 return base::StringPrintf("%s %s",
68 origin().ToString().c_str(),
69 size().ToString().c_str());
72 Rect operator+(const Rect& lhs, const Vector2d& rhs) {
78 Rect operator-(const Rect& lhs, const Vector2d& rhs) {
84 Rect IntersectRects(const Rect& a, const Rect& b) {
90 Rect UnionRects(const Rect& a, const Rect& b) {
96 Rect SubtractRects(const Rect& a, const Rect& b) {
102 Rect BoundingRect(const Point& p1, const Point& p2) {
103 int rx = std::min(p1.x(), p2.x());
104 int ry = std::min(p1.y(), p2.y());
105 int rr = std::max(p1.x(), p2.x());
106 int rb = std::max(p1.y(), p2.y());
107 return Rect(rx, ry, rr - rx, rb - ry);