| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 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/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_GTK) | 11 #elif defined(TOOLKIT_GTK) | 
| 12 #include <gdk/gdk.h> | 12 #include <gdk/gdk.h> | 
| 13 #endif | 13 #endif | 
| 14 #if defined(USE_WAYLAND) |  | 
| 15 #include <cairo.h> |  | 
| 16 #endif |  | 
| 17 | 14 | 
| 18 #include "base/logging.h" | 15 #include "base/logging.h" | 
| 19 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" | 
| 20 #include "ui/gfx/insets.h" | 17 #include "ui/gfx/insets.h" | 
| 21 | 18 | 
| 22 namespace { | 19 namespace { | 
| 23 | 20 | 
| 24 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { | 21 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { | 
| 25   *size = std::min(dst_size, *size); | 22   *size = std::min(dst_size, *size); | 
| 26   if (*origin < dst_origin) | 23   if (*origin < dst_origin) | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 87   set_height(r.height); | 84   set_height(r.height); | 
| 88 } | 85 } | 
| 89 | 86 | 
| 90 Rect& Rect::operator=(const GdkRectangle& r) { | 87 Rect& Rect::operator=(const GdkRectangle& r) { | 
| 91   origin_.SetPoint(r.x, r.y); | 88   origin_.SetPoint(r.x, r.y); | 
| 92   set_width(r.width); | 89   set_width(r.width); | 
| 93   set_height(r.height); | 90   set_height(r.height); | 
| 94   return *this; | 91   return *this; | 
| 95 } | 92 } | 
| 96 #endif | 93 #endif | 
| 97 #if defined(USE_WAYLAND) |  | 
| 98 Rect::Rect(const cairo_rectangle_int_t& r) |  | 
| 99     : origin_(r.x, r.y) { |  | 
| 100   set_width(r.width); |  | 
| 101   set_height(r.height); |  | 
| 102 } |  | 
| 103 |  | 
| 104 Rect& Rect::operator=(const cairo_rectangle_int_t& r) { |  | 
| 105   origin_.SetPoint(r.x, r.y); |  | 
| 106   set_width(r.width); |  | 
| 107   set_height(r.height); |  | 
| 108   return *this; |  | 
| 109 } |  | 
| 110 #endif |  | 
| 111 | 94 | 
| 112 void Rect::SetRect(int x, int y, int width, int height) { | 95 void Rect::SetRect(int x, int y, int width, int height) { | 
| 113   origin_.SetPoint(x, y); | 96   origin_.SetPoint(x, y); | 
| 114   set_width(width); | 97   set_width(width); | 
| 115   set_height(height); | 98   set_height(height); | 
| 116 } | 99 } | 
| 117 | 100 | 
| 118 void Rect::Inset(const gfx::Insets& insets) { | 101 void Rect::Inset(const gfx::Insets& insets) { | 
| 119   Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); | 102   Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); | 
| 120 } | 103 } | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 157 #elif defined(OS_MACOSX) | 140 #elif defined(OS_MACOSX) | 
| 158 CGRect Rect::ToCGRect() const { | 141 CGRect Rect::ToCGRect() const { | 
| 159   return CGRectMake(x(), y(), width(), height()); | 142   return CGRectMake(x(), y(), width(), height()); | 
| 160 } | 143 } | 
| 161 #elif defined(TOOLKIT_GTK) | 144 #elif defined(TOOLKIT_GTK) | 
| 162 GdkRectangle Rect::ToGdkRectangle() const { | 145 GdkRectangle Rect::ToGdkRectangle() const { | 
| 163   GdkRectangle r = {x(), y(), width(), height()}; | 146   GdkRectangle r = {x(), y(), width(), height()}; | 
| 164   return r; | 147   return r; | 
| 165 } | 148 } | 
| 166 #endif | 149 #endif | 
| 167 #if defined(USE_WAYLAND) |  | 
| 168 cairo_rectangle_int_t Rect::ToCairoRectangle() const { |  | 
| 169   cairo_rectangle_int_t r = {x(), y(), width(), height()}; |  | 
| 170   return r; |  | 
| 171 } |  | 
| 172 #endif |  | 
| 173 | 150 | 
| 174 bool Rect::Contains(int point_x, int point_y) const { | 151 bool Rect::Contains(int point_x, int point_y) const { | 
| 175   return (point_x >= x()) && (point_x < right()) && | 152   return (point_x >= x()) && (point_x < right()) && | 
| 176          (point_y >= y()) && (point_y < bottom()); | 153          (point_y >= y()) && (point_y < bottom()); | 
| 177 } | 154 } | 
| 178 | 155 | 
| 179 bool Rect::Contains(const Rect& rect) const { | 156 bool Rect::Contains(const Rect& rect) const { | 
| 180   return (rect.x() >= x() && rect.right() <= right() && | 157   return (rect.x() >= x() && rect.right() <= right() && | 
| 181           rect.y() >= y() && rect.bottom() <= bottom()); | 158           rect.y() >= y() && rect.bottom() <= bottom()); | 
| 182 } | 159 } | 
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 283              (y() == rect.bottom() || bottom() == rect.y())); | 260              (y() == rect.bottom() || bottom() == rect.y())); | 
| 284 } | 261 } | 
| 285 | 262 | 
| 286 std::string Rect::ToString() const { | 263 std::string Rect::ToString() const { | 
| 287   return base::StringPrintf("%s %s", | 264   return base::StringPrintf("%s %s", | 
| 288                             origin_.ToString().c_str(), | 265                             origin_.ToString().c_str(), | 
| 289                             size_.ToString().c_str()); | 266                             size_.ToString().c_str()); | 
| 290 } | 267 } | 
| 291 | 268 | 
| 292 }  // namespace gfx | 269 }  // namespace gfx | 
| OLD | NEW | 
|---|