| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 "components/mus/ws/window_coordinate_conversions.h" | |
| 6 | |
| 7 #include "components/mus/ws/server_window.h" | |
| 8 #include "ui/gfx/geometry/point.h" | |
| 9 #include "ui/gfx/geometry/point_conversions.h" | |
| 10 #include "ui/gfx/geometry/point_f.h" | |
| 11 #include "ui/gfx/geometry/rect.h" | |
| 12 #include "ui/gfx/geometry/vector2d.h" | |
| 13 #include "ui/gfx/geometry/vector2d_f.h" | |
| 14 | |
| 15 namespace mus { | |
| 16 | |
| 17 namespace ws { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 gfx::Vector2dF CalculateOffsetToAncestor(const ServerWindow* window, | |
| 22 const ServerWindow* ancestor) { | |
| 23 DCHECK(ancestor->Contains(window)); | |
| 24 gfx::Vector2d result; | |
| 25 for (const ServerWindow* v = window; v != ancestor; v = v->parent()) | |
| 26 result += v->bounds().OffsetFromOrigin(); | |
| 27 return gfx::Vector2dF(result.x(), result.y()); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 gfx::Point ConvertPointBetweenWindows(const ServerWindow* from, | |
| 33 const ServerWindow* to, | |
| 34 const gfx::Point& point) { | |
| 35 return gfx::ToFlooredPoint( | |
| 36 ConvertPointFBetweenWindows(from, to, gfx::PointF(point.x(), point.y()))); | |
| 37 } | |
| 38 | |
| 39 gfx::PointF ConvertPointFBetweenWindows(const ServerWindow* from, | |
| 40 const ServerWindow* to, | |
| 41 const gfx::PointF& point) { | |
| 42 DCHECK(from); | |
| 43 DCHECK(to); | |
| 44 if (from == to) | |
| 45 return point; | |
| 46 | |
| 47 if (from->Contains(to)) { | |
| 48 const gfx::Vector2dF offset(CalculateOffsetToAncestor(to, from)); | |
| 49 return point - offset; | |
| 50 } | |
| 51 DCHECK(to->Contains(from)); | |
| 52 const gfx::Vector2dF offset(CalculateOffsetToAncestor(from, to)); | |
| 53 return point + offset; | |
| 54 } | |
| 55 | |
| 56 gfx::Rect ConvertRectBetweenWindows(const ServerWindow* from, | |
| 57 const ServerWindow* to, | |
| 58 const gfx::Rect& rect) { | |
| 59 DCHECK(from); | |
| 60 DCHECK(to); | |
| 61 if (from == to) | |
| 62 return rect; | |
| 63 | |
| 64 const gfx::Point top_left( | |
| 65 ConvertPointBetweenWindows(from, to, rect.origin())); | |
| 66 const gfx::Point bottom_right(gfx::ToCeiledPoint(ConvertPointFBetweenWindows( | |
| 67 from, to, gfx::PointF(rect.right(), rect.bottom())))); | |
| 68 return gfx::Rect(top_left.x(), top_left.y(), bottom_right.x() - top_left.x(), | |
| 69 bottom_right.y() - top_left.y()); | |
| 70 } | |
| 71 | |
| 72 } // namespace ws | |
| 73 | |
| 74 } // namespace mus | |
| OLD | NEW |