Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Side by Side Diff: components/mus/ws/window_coordinate_conversions.cc

Issue 2119963002: Move mus to //services/ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW
« no previous file with comments | « components/mus/ws/window_coordinate_conversions.h ('k') | components/mus/ws/window_coordinate_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698