Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / mus / ids.h
blob7099a58fba56d4d2328ce6aa97fb086ce035766a
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_MUS_IDS_H_
6 #define COMPONENTS_MUS_IDS_H_
8 #include "components/mus/public/cpp/types.h"
9 #include "components/mus/public/cpp/util.h"
11 namespace mus {
13 // Connection id is used to indicate no connection. That is, no ViewTreeImpl
14 // ever gets this id.
15 const ConnectionSpecificId kInvalidConnectionId = 0;
17 // Adds a bit of type safety to view ids.
18 struct ViewId {
19 ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId view_id)
20 : connection_id(connection_id), view_id(view_id) {}
21 ViewId() : connection_id(0), view_id(0) {}
23 bool operator==(const ViewId& other) const {
24 return other.connection_id == connection_id && other.view_id == view_id;
27 bool operator!=(const ViewId& other) const { return !(*this == other); }
29 ConnectionSpecificId connection_id;
30 ConnectionSpecificId view_id;
33 inline ViewId ViewIdFromTransportId(Id id) {
34 return ViewId(HiWord(id), LoWord(id));
37 inline Id ViewIdToTransportId(const ViewId& id) {
38 return (id.connection_id << 16) | id.view_id;
41 // Returns a ViewId that is reserved to indicate no view. That is, no view will
42 // ever be created with this id.
43 inline ViewId InvalidViewId() {
44 return ViewId(kInvalidConnectionId, 0);
47 // Returns a root view id with a given index offset.
48 inline ViewId RootViewId(uint16_t index) {
49 return ViewId(kInvalidConnectionId, 2 + index);
52 } // namespace mus
54 #endif // COMPONENTS_MUS_IDS_H_