OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/mus/ws/test_change_tracker.h" | 5 #include "components/mus/ws/test_change_tracker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "components/mus/common/util.h" | 11 #include "components/mus/common/util.h" |
12 #include "mojo/common/common_type_converters.h" | 12 #include "mojo/common/common_type_converters.h" |
13 | 13 |
14 using mojo::Array; | 14 using mojo::Array; |
15 using mojo::String; | 15 using mojo::String; |
16 | 16 |
17 namespace mus { | 17 namespace mus { |
18 | 18 |
19 namespace ws { | 19 namespace ws { |
20 | 20 |
21 std::string WindowIdToString(Id id) { | 21 std::string WindowIdToString(Id id) { |
22 return (id == 0) ? "null" | 22 return (id == 0) ? "null" |
23 : base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); | 23 : base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); |
24 } | 24 } |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 std::string RectToString(const mojo::Rect& rect) { | |
29 return base::StringPrintf("%d,%d %dx%d", rect.x, rect.y, rect.width, | |
30 rect.height); | |
31 } | |
32 | |
33 std::string DirectionToString(mojom::OrderDirection direction) { | 28 std::string DirectionToString(mojom::OrderDirection direction) { |
34 return direction == mojom::OrderDirection::ABOVE ? "above" : "below"; | 29 return direction == mojom::OrderDirection::ABOVE ? "above" : "below"; |
35 } | 30 } |
36 | 31 |
37 enum class ChangeDescriptionType { | 32 enum class ChangeDescriptionType { |
38 ONE, | 33 ONE, |
39 TWO, | 34 TWO, |
40 }; | 35 }; |
41 | 36 |
42 std::string ChangeToDescription(const Change& change, | 37 std::string ChangeToDescription(const Change& change, |
(...skipping 19 matching lines...) Expand all Loading... |
62 | 57 |
63 case CHANGE_TYPE_NODE_ADD_TRANSIENT_WINDOW: | 58 case CHANGE_TYPE_NODE_ADD_TRANSIENT_WINDOW: |
64 return base::StringPrintf("AddTransientWindow parent = %s child = %s", | 59 return base::StringPrintf("AddTransientWindow parent = %s child = %s", |
65 WindowIdToString(change.window_id).c_str(), | 60 WindowIdToString(change.window_id).c_str(), |
66 WindowIdToString(change.window_id2).c_str()); | 61 WindowIdToString(change.window_id2).c_str()); |
67 | 62 |
68 case CHANGE_TYPE_NODE_BOUNDS_CHANGED: | 63 case CHANGE_TYPE_NODE_BOUNDS_CHANGED: |
69 return base::StringPrintf( | 64 return base::StringPrintf( |
70 "BoundsChanged window=%s old_bounds=%s new_bounds=%s", | 65 "BoundsChanged window=%s old_bounds=%s new_bounds=%s", |
71 WindowIdToString(change.window_id).c_str(), | 66 WindowIdToString(change.window_id).c_str(), |
72 RectToString(change.bounds).c_str(), | 67 change.bounds.ToString().c_str(), change.bounds2.ToString().c_str()); |
73 RectToString(change.bounds2).c_str()); | |
74 | 68 |
75 case CHANGE_TYPE_NODE_VIEWPORT_METRICS_CHANGED: | 69 case CHANGE_TYPE_NODE_VIEWPORT_METRICS_CHANGED: |
76 // TODO(sky): Not implemented. | 70 // TODO(sky): Not implemented. |
77 return "ViewportMetricsChanged"; | 71 return "ViewportMetricsChanged"; |
78 | 72 |
79 case CHANGE_TYPE_NODE_HIERARCHY_CHANGED: | 73 case CHANGE_TYPE_NODE_HIERARCHY_CHANGED: |
80 return base::StringPrintf( | 74 return base::StringPrintf( |
81 "HierarchyChanged window=%s old_parent=%s new_parent=%s", | 75 "HierarchyChanged window=%s old_parent=%s new_parent=%s", |
82 WindowIdToString(change.window_id).c_str(), | 76 WindowIdToString(change.window_id).c_str(), |
83 WindowIdToString(change.window_id2).c_str(), | 77 WindowIdToString(change.window_id2).c_str(), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 247 } |
254 | 248 |
255 void TestChangeTracker::OnEmbeddedAppDisconnected(Id window_id) { | 249 void TestChangeTracker::OnEmbeddedAppDisconnected(Id window_id) { |
256 Change change; | 250 Change change; |
257 change.type = CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED; | 251 change.type = CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED; |
258 change.window_id = window_id; | 252 change.window_id = window_id; |
259 AddChange(change); | 253 AddChange(change); |
260 } | 254 } |
261 | 255 |
262 void TestChangeTracker::OnWindowBoundsChanged(Id window_id, | 256 void TestChangeTracker::OnWindowBoundsChanged(Id window_id, |
263 mojo::RectPtr old_bounds, | 257 const gfx::Rect& old_bounds, |
264 mojo::RectPtr new_bounds) { | 258 const gfx::Rect& new_bounds) { |
265 Change change; | 259 Change change; |
266 change.type = CHANGE_TYPE_NODE_BOUNDS_CHANGED; | 260 change.type = CHANGE_TYPE_NODE_BOUNDS_CHANGED; |
267 change.window_id = window_id; | 261 change.window_id = window_id; |
268 change.bounds.x = old_bounds->x; | 262 change.bounds = old_bounds; |
269 change.bounds.y = old_bounds->y; | 263 change.bounds2 = new_bounds; |
270 change.bounds.width = old_bounds->width; | |
271 change.bounds.height = old_bounds->height; | |
272 change.bounds2.x = new_bounds->x; | |
273 change.bounds2.y = new_bounds->y; | |
274 change.bounds2.width = new_bounds->width; | |
275 change.bounds2.height = new_bounds->height; | |
276 AddChange(change); | 264 AddChange(change); |
277 } | 265 } |
278 | 266 |
279 void TestChangeTracker::OnUnembed(Id window_id) { | 267 void TestChangeTracker::OnUnembed(Id window_id) { |
280 Change change; | 268 Change change; |
281 change.type = CHANGE_TYPE_UNEMBED; | 269 change.type = CHANGE_TYPE_UNEMBED; |
282 change.window_id = window_id; | 270 change.window_id = window_id; |
283 AddChange(change); | 271 AddChange(change); |
284 } | 272 } |
285 | 273 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 452 |
465 std::string TestWindow::ToString2() const { | 453 std::string TestWindow::ToString2() const { |
466 return base::StringPrintf( | 454 return base::StringPrintf( |
467 "window=%s parent=%s visible=%s", WindowIdToString(window_id).c_str(), | 455 "window=%s parent=%s visible=%s", WindowIdToString(window_id).c_str(), |
468 WindowIdToString(parent_id).c_str(), visible ? "true" : "false"); | 456 WindowIdToString(parent_id).c_str(), visible ? "true" : "false"); |
469 } | 457 } |
470 | 458 |
471 } // namespace ws | 459 } // namespace ws |
472 | 460 |
473 } // namespace mus | 461 } // namespace mus |
OLD | NEW |