| 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 "components/mus/public/cpp/types.h" | 8 #include "components/mus/public/cpp/types.h" |
| 9 #include "components/mus/public/cpp/util.h" | 9 #include "components/mus/public/cpp/util.h" |
| 10 | 10 |
| 11 namespace mus { | 11 namespace mus { |
| 12 | 12 |
| 13 // Connection id is used to indicate no connection. That is, no ViewTreeImpl | 13 // Connection id is used to indicate no connection. That is, no ViewTreeImpl |
| 14 // ever gets this id. | 14 // ever gets this id. |
| 15 const ConnectionSpecificId kInvalidConnectionId = 0; | 15 const ConnectionSpecificId kInvalidConnectionId = 0; |
| 16 | 16 |
| 17 // Adds a bit of type safety to view ids. | 17 // Adds a bit of type safety to view ids. |
| 18 struct ViewId { | 18 struct ViewId { |
| 19 ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId view_id) | 19 ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId window_id) |
| 20 : connection_id(connection_id), view_id(view_id) {} | 20 : connection_id(connection_id), window_id(window_id) {} |
| 21 ViewId() : connection_id(0), view_id(0) {} | 21 ViewId() : connection_id(0), window_id(0) {} |
| 22 | 22 |
| 23 bool operator==(const ViewId& other) const { | 23 bool operator==(const ViewId& other) const { |
| 24 return other.connection_id == connection_id && other.view_id == view_id; | 24 return other.connection_id == connection_id && other.window_id == window_id; |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool operator!=(const ViewId& other) const { return !(*this == other); } | 27 bool operator!=(const ViewId& other) const { return !(*this == other); } |
| 28 | 28 |
| 29 bool operator<(const ViewId& other) const { | 29 bool operator<(const ViewId& other) const { |
| 30 if (connection_id == other.connection_id) | 30 if (connection_id == other.connection_id) |
| 31 return view_id < other.view_id; | 31 return window_id < other.window_id; |
| 32 | 32 |
| 33 return connection_id < other.connection_id; | 33 return connection_id < other.connection_id; |
| 34 } | 34 } |
| 35 | 35 |
| 36 ConnectionSpecificId connection_id; | 36 ConnectionSpecificId connection_id; |
| 37 ConnectionSpecificId view_id; | 37 ConnectionSpecificId window_id; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 inline ViewId ViewIdFromTransportId(Id id) { | 40 inline ViewId ViewIdFromTransportId(Id id) { |
| 41 return ViewId(HiWord(id), LoWord(id)); | 41 return ViewId(HiWord(id), LoWord(id)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 inline Id ViewIdToTransportId(const ViewId& id) { | 44 inline Id ViewIdToTransportId(const ViewId& id) { |
| 45 return (id.connection_id << 16) | id.view_id; | 45 return (id.connection_id << 16) | id.window_id; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Returns a ViewId that is reserved to indicate no view. That is, no view will | 48 // Returns a ViewId that is reserved to indicate no view. That is, no view will |
| 49 // ever be created with this id. | 49 // ever be created with this id. |
| 50 inline ViewId InvalidViewId() { | 50 inline ViewId InvalidViewId() { |
| 51 return ViewId(kInvalidConnectionId, 0); | 51 return ViewId(kInvalidConnectionId, 0); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Returns a root view id with a given index offset. | 54 // Returns a root view id with a given index offset. |
| 55 inline ViewId RootViewId(uint16_t index) { | 55 inline ViewId RootViewId(uint16_t index) { |
| 56 return ViewId(kInvalidConnectionId, 2 + index); | 56 return ViewId(kInvalidConnectionId, 2 + index); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace mus | 59 } // namespace mus |
| 60 | 60 |
| 61 #endif // COMPONENTS_MUS_WS_IDS_H_ | 61 #endif // COMPONENTS_MUS_WS_IDS_H_ |
| OLD | NEW |