| 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_VIEW_MANAGER_IDS_H_ | 5 #ifndef COMPONENTS_MUS_IDS_H_ |
| 6 #define COMPONENTS_VIEW_MANAGER_IDS_H_ | 6 #define COMPONENTS_MUS_IDS_H_ |
| 7 | 7 |
| 8 #include "components/view_manager/public/cpp/types.h" | 8 #include "components/mus/public/cpp/types.h" |
| 9 #include "components/view_manager/public/cpp/util.h" | 9 #include "components/mus/public/cpp/util.h" |
| 10 | 10 |
| 11 namespace view_manager { | 11 namespace view_manager { |
| 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 mojo::ConnectionSpecificId kInvalidConnectionId = 0; | 15 const mojo::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(mojo::ConnectionSpecificId connection_id, | 19 ViewId(mojo::ConnectionSpecificId connection_id, |
| 20 mojo::ConnectionSpecificId view_id) | 20 mojo::ConnectionSpecificId view_id) |
| 21 : connection_id(connection_id), view_id(view_id) {} | 21 : connection_id(connection_id), view_id(view_id) {} |
| 22 ViewId() : connection_id(0), view_id(0) {} | 22 ViewId() : connection_id(0), view_id(0) {} |
| 23 | 23 |
| 24 bool operator==(const ViewId& other) const { | 24 bool operator==(const ViewId& other) const { |
| 25 return other.connection_id == connection_id && | 25 return other.connection_id == connection_id && other.view_id == view_id; |
| 26 other.view_id == view_id; | |
| 27 } | 26 } |
| 28 | 27 |
| 29 bool operator!=(const ViewId& other) const { | 28 bool operator!=(const ViewId& other) const { return !(*this == other); } |
| 30 return !(*this == other); | |
| 31 } | |
| 32 | 29 |
| 33 mojo::ConnectionSpecificId connection_id; | 30 mojo::ConnectionSpecificId connection_id; |
| 34 mojo::ConnectionSpecificId view_id; | 31 mojo::ConnectionSpecificId view_id; |
| 35 }; | 32 }; |
| 36 | 33 |
| 37 inline ViewId ViewIdFromTransportId(mojo::Id id) { | 34 inline ViewId ViewIdFromTransportId(mojo::Id id) { |
| 38 return ViewId(mojo::HiWord(id), mojo::LoWord(id)); | 35 return ViewId(mojo::HiWord(id), mojo::LoWord(id)); |
| 39 } | 36 } |
| 40 | 37 |
| 41 inline mojo::Id ViewIdToTransportId(const ViewId& id) { | 38 inline mojo::Id ViewIdToTransportId(const ViewId& id) { |
| 42 return (id.connection_id << 16) | id.view_id; | 39 return (id.connection_id << 16) | id.view_id; |
| 43 } | 40 } |
| 44 | 41 |
| 45 // Returns a ViewId that is reserved to indicate no view. That is, no view will | 42 // Returns a ViewId that is reserved to indicate no view. That is, no view will |
| 46 // ever be created with this id. | 43 // ever be created with this id. |
| 47 inline ViewId InvalidViewId() { | 44 inline ViewId InvalidViewId() { |
| 48 return ViewId(kInvalidConnectionId, 0); | 45 return ViewId(kInvalidConnectionId, 0); |
| 49 } | 46 } |
| 50 | 47 |
| 51 // Returns a root view id with a given index offset. | 48 // Returns a root view id with a given index offset. |
| 52 inline ViewId RootViewId(uint16_t index) { | 49 inline ViewId RootViewId(uint16_t index) { |
| 53 return ViewId(kInvalidConnectionId, 2 + index); | 50 return ViewId(kInvalidConnectionId, 2 + index); |
| 54 } | 51 } |
| 55 | 52 |
| 56 } // namespace view_manager | 53 } // namespace view_manager |
| 57 | 54 |
| 58 #endif // COMPONENTS_VIEW_MANAGER_IDS_H_ | 55 #endif // COMPONENTS_MUS_IDS_H_ |
| OLD | NEW |