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 |
8 #include "components/mus/common/types.h" | 10 #include "components/mus/common/types.h" |
9 #include "components/mus/common/util.h" | 11 #include "components/mus/common/util.h" |
10 | 12 |
11 namespace mus { | 13 namespace mus { |
12 | 14 |
13 namespace ws { | 15 namespace ws { |
14 | 16 |
15 // Connection id is used to indicate no connection. That is, no WindowTreeImpl | 17 // Connection id is used to indicate no connection. That is, no WindowTreeImpl |
16 // ever gets this id. | 18 // ever gets this id. |
17 const ConnectionSpecificId kInvalidConnectionId = 0; | 19 const ConnectionSpecificId kInvalidConnectionId = 0; |
18 | 20 |
19 // Adds a bit of type safety to window ids. | 21 // Adds a bit of type safety to window ids. |
20 struct WindowId { | 22 struct WindowId { |
21 WindowId(ConnectionSpecificId connection_id, ConnectionSpecificId window_id) | 23 WindowId(ConnectionSpecificId connection_id, ConnectionSpecificId window_id) |
22 : connection_id(connection_id), window_id(window_id) {} | 24 : connection_id(connection_id), window_id(window_id) {} |
23 WindowId() : connection_id(0), window_id(0) {} | 25 WindowId() : connection_id(0), window_id(0) {} |
24 | 26 |
25 bool operator==(const WindowId& other) const { | 27 bool operator==(const WindowId& other) const { |
26 return other.connection_id == connection_id && other.window_id == window_id; | 28 return other.connection_id == connection_id && other.window_id == window_id; |
27 } | 29 } |
28 | 30 |
29 bool operator!=(const WindowId& other) const { return !(*this == other); } | 31 bool operator!=(const WindowId& other) const { return !(*this == other); } |
30 | 32 |
31 bool operator<(const WindowId& other) const { | 33 bool operator<(const WindowId& other) const { |
32 if (connection_id == other.connection_id) | 34 return std::tie(connection_id, window_id) < |
33 return window_id < other.window_id; | 35 std::tie(other.connection_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 |