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