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 "mojo/services/view_manager/view_coordinate_conversions.h" |
| 6 |
| 7 #include "mojo/services/view_manager/server_view.h" |
| 8 #include "ui/gfx/geometry/rect.h" |
| 9 #include "ui/gfx/geometry/vector2d.h" |
| 10 |
| 11 namespace view_manager { |
| 12 |
| 13 namespace { |
| 14 |
| 15 gfx::Vector2d CalculateOffsetToAncestor(const ServerView* view, |
| 16 const ServerView* ancestor) { |
| 17 DCHECK(ancestor->Contains(view)); |
| 18 gfx::Vector2d result; |
| 19 for (const ServerView* v = view; v != ancestor; v = v->parent()) |
| 20 result += v->bounds().OffsetFromOrigin(); |
| 21 return result; |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 gfx::Rect ConvertRectBetweenViews(const ServerView* from, |
| 27 const ServerView* to, |
| 28 const gfx::Rect& rect) { |
| 29 DCHECK(from); |
| 30 if (from == to) |
| 31 return rect; |
| 32 |
| 33 if (from->Contains(to)) { |
| 34 const gfx::Vector2d offset(CalculateOffsetToAncestor(to, from)); |
| 35 return gfx::Rect(rect.origin() - offset, rect.size()); |
| 36 } |
| 37 DCHECK(to->Contains(from)); |
| 38 const gfx::Vector2d offset(CalculateOffsetToAncestor(from, to)); |
| 39 return gfx::Rect(rect.origin() + offset, rect.size()); |
| 40 } |
| 41 |
| 42 } // namespace view_manager |
OLD | NEW |