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 #ifndef COMPONENTS_MUS_WS_IDS_H_ | 5 #ifndef COMPONENTS_MUS_WS_IDS_H_ |
6 #define COMPONENTS_MUS_WS_IDS_H_ | 6 #define COMPONENTS_MUS_WS_IDS_H_ |
7 | 7 |
8 #include <tuple> | |
9 | |
10 #include "components/mus/common/types.h" | 8 #include "components/mus/common/types.h" |
11 #include "components/mus/common/util.h" | 9 #include "components/mus/common/util.h" |
12 | 10 |
13 namespace mus { | 11 namespace mus { |
14 | 12 |
15 namespace ws { | 13 namespace ws { |
16 | 14 |
17 // Connection id is used to indicate no connection. That is, no WindowTreeImpl | 15 // Connection id is used to indicate no connection. That is, no WindowTreeImpl |
18 // ever gets this id. | 16 // ever gets this id. |
19 const ConnectionSpecificId kInvalidConnectionId = 0; | 17 const ConnectionSpecificId kInvalidConnectionId = 0; |
20 | 18 |
21 // Adds a bit of type safety to window ids. | 19 // Adds a bit of type safety to window ids. |
22 struct WindowId { | 20 struct WindowId { |
23 WindowId(ConnectionSpecificId connection_id, ConnectionSpecificId window_id) | 21 WindowId(ConnectionSpecificId connection_id, ConnectionSpecificId window_id) |
24 : connection_id(connection_id), window_id(window_id) {} | 22 : connection_id(connection_id), window_id(window_id) {} |
25 WindowId() : connection_id(0), window_id(0) {} | 23 WindowId() : connection_id(0), window_id(0) {} |
26 | 24 |
27 bool operator==(const WindowId& other) const { | 25 bool operator==(const WindowId& other) const { |
28 return other.connection_id == connection_id && other.window_id == window_id; | 26 return other.connection_id == connection_id && other.window_id == window_id; |
29 } | 27 } |
30 | 28 |
31 bool operator!=(const WindowId& other) const { return !(*this == other); } | 29 bool operator!=(const WindowId& other) const { return !(*this == other); } |
32 | 30 |
33 bool operator<(const WindowId& other) const { | 31 bool operator<(const WindowId& other) const { |
34 return std::tie(connection_id, window_id) < | 32 if (connection_id == other.connection_id) |
35 std::tie(other.connection_id, other.window_id); | 33 return window_id < other.window_id; |
| 34 |
| 35 return connection_id < other.connection_id; |
36 } | 36 } |
37 | 37 |
38 ConnectionSpecificId connection_id; | 38 ConnectionSpecificId connection_id; |
39 ConnectionSpecificId window_id; | 39 ConnectionSpecificId window_id; |
40 }; | 40 }; |
41 | 41 |
42 inline WindowId WindowIdFromTransportId(Id id) { | 42 inline WindowId WindowIdFromTransportId(Id id) { |
43 return WindowId(HiWord(id), LoWord(id)); | 43 return WindowId(HiWord(id), LoWord(id)); |
44 } | 44 } |
45 | 45 |
(...skipping 10 matching lines...) Expand all Loading... |
56 // Returns a root window id with a given index offset. | 56 // Returns a root window id with a given index offset. |
57 inline WindowId RootWindowId(uint16_t index) { | 57 inline WindowId RootWindowId(uint16_t index) { |
58 return WindowId(kInvalidConnectionId, 2 + index); | 58 return WindowId(kInvalidConnectionId, 2 + index); |
59 } | 59 } |
60 | 60 |
61 } // namespace ws | 61 } // namespace ws |
62 | 62 |
63 } // namespace mus | 63 } // namespace mus |
64 | 64 |
65 #endif // COMPONENTS_MUS_WS_IDS_H_ | 65 #endif // COMPONENTS_MUS_WS_IDS_H_ |
OLD | NEW |