OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/geometry/rect.h" | 5 #include "ui/gfx/geometry/rect.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #elif defined(TOOLKIT_GTK) | |
12 #include <gdk/gdk.h> | |
13 #endif | 11 #endif |
14 | 12 |
15 #include "base/logging.h" | 13 #include "base/logging.h" |
16 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
17 #include "ui/gfx/geometry/insets.h" | 15 #include "ui/gfx/geometry/insets.h" |
18 #include "ui/gfx/geometry/rect_base_impl.h" | 16 #include "ui/gfx/geometry/rect_base_impl.h" |
19 | 17 |
20 namespace gfx { | 18 namespace gfx { |
21 | 19 |
22 template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; | 20 template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; |
23 | 21 |
24 typedef class RectBase<Rect, Point, Size, Insets, Vector2d, int> RectBaseT; | 22 typedef class RectBase<Rect, Point, Size, Insets, Vector2d, int> RectBaseT; |
25 | 23 |
26 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
27 Rect::Rect(const RECT& r) | 25 Rect::Rect(const RECT& r) |
28 : RectBaseT(gfx::Point(r.left, r.top)) { | 26 : RectBaseT(gfx::Point(r.left, r.top)) { |
29 set_width(std::abs(r.right - r.left)); | 27 set_width(std::abs(r.right - r.left)); |
30 set_height(std::abs(r.bottom - r.top)); | 28 set_height(std::abs(r.bottom - r.top)); |
31 } | 29 } |
32 #elif defined(OS_MACOSX) | 30 #elif defined(OS_MACOSX) |
33 Rect::Rect(const CGRect& r) | 31 Rect::Rect(const CGRect& r) |
34 : RectBaseT(gfx::Point(r.origin.x, r.origin.y)) { | 32 : RectBaseT(gfx::Point(r.origin.x, r.origin.y)) { |
35 set_width(r.size.width); | 33 set_width(r.size.width); |
36 set_height(r.size.height); | 34 set_height(r.size.height); |
37 } | 35 } |
38 #elif defined(TOOLKIT_GTK) | |
39 Rect::Rect(const GdkRectangle& r) | |
40 : RectBaseT(gfx::Point(r.x, r.y)) { | |
41 set_width(r.width); | |
42 set_height(r.height); | |
43 } | |
44 #endif | 36 #endif |
45 | 37 |
46 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
47 RECT Rect::ToRECT() const { | 39 RECT Rect::ToRECT() const { |
48 RECT r; | 40 RECT r; |
49 r.left = x(); | 41 r.left = x(); |
50 r.right = right(); | 42 r.right = right(); |
51 r.top = y(); | 43 r.top = y(); |
52 r.bottom = bottom(); | 44 r.bottom = bottom(); |
53 return r; | 45 return r; |
54 } | 46 } |
55 #elif defined(OS_MACOSX) | 47 #elif defined(OS_MACOSX) |
56 CGRect Rect::ToCGRect() const { | 48 CGRect Rect::ToCGRect() const { |
57 return CGRectMake(x(), y(), width(), height()); | 49 return CGRectMake(x(), y(), width(), height()); |
58 } | 50 } |
59 #elif defined(TOOLKIT_GTK) | |
60 GdkRectangle Rect::ToGdkRectangle() const { | |
61 GdkRectangle r = {x(), y(), width(), height()}; | |
62 return r; | |
63 } | |
64 #endif | 51 #endif |
65 | 52 |
66 std::string Rect::ToString() const { | 53 std::string Rect::ToString() const { |
67 return base::StringPrintf("%s %s", | 54 return base::StringPrintf("%s %s", |
68 origin().ToString().c_str(), | 55 origin().ToString().c_str(), |
69 size().ToString().c_str()); | 56 size().ToString().c_str()); |
70 } | 57 } |
71 | 58 |
72 Rect operator+(const Rect& lhs, const Vector2d& rhs) { | 59 Rect operator+(const Rect& lhs, const Vector2d& rhs) { |
73 Rect result(lhs); | 60 Rect result(lhs); |
(...skipping 27 matching lines...) Expand all Loading... |
101 | 88 |
102 Rect BoundingRect(const Point& p1, const Point& p2) { | 89 Rect BoundingRect(const Point& p1, const Point& p2) { |
103 int rx = std::min(p1.x(), p2.x()); | 90 int rx = std::min(p1.x(), p2.x()); |
104 int ry = std::min(p1.y(), p2.y()); | 91 int ry = std::min(p1.y(), p2.y()); |
105 int rr = std::max(p1.x(), p2.x()); | 92 int rr = std::max(p1.x(), p2.x()); |
106 int rb = std::max(p1.y(), p2.y()); | 93 int rb = std::max(p1.y(), p2.y()); |
107 return Rect(rx, ry, rr - rx, rb - ry); | 94 return Rect(rx, ry, rr - rx, rb - ry); |
108 } | 95 } |
109 | 96 |
110 } // namespace gfx | 97 } // namespace gfx |
OLD | NEW |